forked from mirrors/principia
Cleanup TMS_USE_GLES usage
Now that we use GLAD on both GL and GLES, we can rely on GL-only functions and constants existing when building, while remaining unused for GLES. The end goal would be making switching between GL and GLES a runtime setting on relevant platforms Also cleanup some commented out GL code and sprinkled glGetError asserts
This commit is contained in:
parent
91695dafe7
commit
c4e0a1ee01
8 changed files with 32 additions and 269 deletions
75
src/game.cc
75
src/game.cc
|
|
@ -1207,10 +1207,8 @@ game::init_framebuffers()
|
|||
#ifndef TMS_USE_GLES
|
||||
if (settings["postprocess"]->v.b) {
|
||||
tms_infof("Postprocess time");
|
||||
//this->main_fb = tms_fb_alloc(_tms.window_width/2., _tms.window_height/2., 0);
|
||||
this->main_fb = tms_fb_alloc(_tms.window_width, _tms.window_height, 0);
|
||||
tms_fb_add_texture(this->main_fb, GL_RGBA, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST);
|
||||
//tms_fb_add_texture(this->main_fb, GL_RGB, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR);
|
||||
tms_fb_enable_depth(this->main_fb, GL_DEPTH_COMPONENT16);
|
||||
|
||||
this->bloom_fb = tms_fb_alloc(_tms.window_width, _tms.window_height, 1);
|
||||
|
|
@ -1269,7 +1267,6 @@ game::init_graphs()
|
|||
this->gi_graph = this->get_scene()->create_graph(1);
|
||||
this->gi_graph->sorting[0] = TMS_SORT_PRIO;
|
||||
this->gi_graph->sorting[1] = TMS_SORT_SHADER;
|
||||
//this->gi_graph->sorting[2] = TMS_SORT_TEXTURE0;
|
||||
this->gi_graph->sorting[2] = TMS_SORT_VARRAY;
|
||||
this->gi_graph->sorting[3] = TMS_SORT_MESH;
|
||||
this->gi_graph->sort_depth = 4;
|
||||
|
|
@ -2516,9 +2513,8 @@ game::render()
|
|||
|
||||
int ierr;
|
||||
|
||||
if ((ierr = glGetError()) != 0) {
|
||||
if ((ierr = glGetError()) != 0)
|
||||
tms_errorf("gl error %d in game::render begin", ierr);
|
||||
}
|
||||
|
||||
#ifdef PROFILING
|
||||
Uint32 ss = SDL_GetTicks();
|
||||
|
|
@ -2528,18 +2524,13 @@ game::render()
|
|||
|
||||
display::reset();
|
||||
ledbuffer::reset();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d after led reset", ierr);
|
||||
spritebuffer::reset();
|
||||
fluidbuffer::reset();
|
||||
linebuffer::reset();
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d after linebuffer reset", ierr);
|
||||
textbuffer::reset();
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d after textbuffer reset", ierr);
|
||||
cable::reset_counter();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d after cable reset", ierr);
|
||||
rope::reset_counter();
|
||||
plant::reset_counter();
|
||||
//
|
||||
|
||||
if (gui_spritesheet::tmp_atlas_modified) {
|
||||
tms_texture_upload(&gui_spritesheet::tmp_atlas->texture);
|
||||
|
|
@ -2559,7 +2550,6 @@ game::render()
|
|||
vdist.x -= this->last_static_update.x;
|
||||
vdist.y -= this->last_static_update.y;
|
||||
vdist.z -= this->last_static_update.z;
|
||||
//vdist.z =0;
|
||||
|
||||
float dist = tvec3_magnitude(&vdist);
|
||||
|
||||
|
|
@ -2820,32 +2810,24 @@ game::render()
|
|||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render before upload", ierr);
|
||||
display::upload();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after display::upload", ierr);
|
||||
ledbuffer::upload();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after ledbuffer::upload", ierr);
|
||||
spritebuffer::upload();
|
||||
fluidbuffer::upload();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after spritebuffer::upload", ierr);
|
||||
linebuffer::upload();
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after linebuffer::upload", ierr);
|
||||
textbuffer::upload();
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after textbuffer::upload", ierr);
|
||||
rope::upload_buffers();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after rope::upload", ierr);
|
||||
cable::upload_buffers();
|
||||
//tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after cable::upload", ierr);
|
||||
pixel::upload_buffers();
|
||||
tpixel::upload_buffers();
|
||||
polygon::upload_buffers();
|
||||
plant::upload_buffers();
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after plant::upload_buffers", ierr);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after upload", ierr);
|
||||
|
||||
GLenum err;
|
||||
do {
|
||||
err = glGetError();
|
||||
} while (err != GL_NO_ERROR);
|
||||
|
||||
|
||||
#ifdef PROFILING
|
||||
tms_infof("upload: %d", SDL_GetTicks() - ss);
|
||||
ss = SDL_GetTicks();
|
||||
|
|
@ -2863,17 +2845,8 @@ game::render()
|
|||
# endif
|
||||
#endif
|
||||
|
||||
//glClear(GL_COLOR_BUFFER_BIT);
|
||||
//return T_OK;
|
||||
//tms_infof("RENDER");
|
||||
|
||||
glViewport(0,0,_tms.opengl_width, _tms.opengl_height);
|
||||
|
||||
|
||||
//glFinish();
|
||||
//tms_infof("buffer shit %u", SDL_GetTicks() - start_time);
|
||||
|
||||
//tms_assertf(glGetError() == 0, "error before gi render");
|
||||
/* create shadow map */
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
|
@ -2889,7 +2862,6 @@ game::render()
|
|||
tms_fb_unbind(tms_pipeline_get_framebuffer(1));
|
||||
}
|
||||
}
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after shadow render", ierr);
|
||||
|
||||
//tms_debugf("cam before render ao %f", this->cam->_position.z);
|
||||
|
|
@ -2897,19 +2869,17 @@ game::render()
|
|||
glDisable(GL_BLEND);
|
||||
this->ao_graph->render(this->ao_cam, this);
|
||||
|
||||
if (tms_pipeline_get_framebuffer(3)->width == 512) {
|
||||
if (tms_pipeline_get_framebuffer(3)->width == 512)
|
||||
tms_fb_swap_blur5x5(tms_pipeline_get_framebuffer(3));
|
||||
} else {
|
||||
else
|
||||
tms_fb_swap_blur3x3(tms_pipeline_get_framebuffer(3));
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (settings["postprocess"]->v.b) {
|
||||
//tms_assertf(glGetError() == 0, "error before main fb bind");
|
||||
if (settings["postprocess"]->v.b)
|
||||
tms_fb_bind(this->main_fb);
|
||||
//tms_assertf(glGetError() == 0, "error after main fb bind");
|
||||
}
|
||||
#endif
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render after shadow/ao", ierr);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
|
@ -2918,9 +2888,8 @@ game::render()
|
|||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in game::render before bg", ierr);
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (settings["gamma_correct"]->v.b && !settings["postprocess"]->v.b) {
|
||||
if (settings["gamma_correct"]->v.b && !settings["postprocess"]->v.b)
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (this->state.abo_architect_mode) {
|
||||
|
|
@ -3061,34 +3030,27 @@ game::render()
|
|||
glDisable(GL_BLEND);
|
||||
|
||||
#if 0
|
||||
if (settings["gamma_correct"]->v.b) {
|
||||
if (settings["gamma_correct"]->v.b)
|
||||
tms_fb_render(this->main_fb, prg_output);
|
||||
} else {
|
||||
else
|
||||
tms_fb_render(this->main_fb, _tms_fb_copy_program);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (settings["gamma_correct"]->v.b) {
|
||||
if (settings["gamma_correct"]->v.b)
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
|
||||
tms_fb_render(this->main_fb, _tms_fb_copy_program);
|
||||
|
||||
if (settings["gamma_correct"]->v.b) {
|
||||
if (settings["gamma_correct"]->v.b)
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, this->main_fb->fb_texture[0][0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glGenerateMipmap)
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
else
|
||||
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
||||
#else
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
#endif
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
|
@ -3099,14 +3061,10 @@ game::render()
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, this->bloom_fb->fb_texture[this->bloom_fb->toggle][0]);
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glGenerateMipmap)
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
else
|
||||
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
||||
#else
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
#endif
|
||||
|
||||
for (int x=0; x<7; x++) {
|
||||
glBlendColor(1.f, 1.f, 1.f, .05f);
|
||||
|
|
@ -3154,18 +3112,15 @@ game::render()
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
if (W->is_paused() || W->level.type == LCAT_ADVENTURE) {
|
||||
if (this->get_mode() == GAME_MODE_SELECT_CONN_TYPE) {
|
||||
if (this->get_mode() == GAME_MODE_SELECT_CONN_TYPE)
|
||||
this->render_conn_types();
|
||||
} else {
|
||||
else
|
||||
this->render_connections();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (W->is_paused()) {
|
||||
if (this->get_mode() == GAME_MODE_CONN_EDIT) {
|
||||
if (this->get_mode() == GAME_MODE_CONN_EDIT)
|
||||
this->render_existing_connections();
|
||||
}
|
||||
|
||||
this->render_selected_connection();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,11 +244,6 @@ begin(void)
|
|||
glDepthMask(0xff);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
//glActiveTexture(GL_TEXTURE3);
|
||||
//glBindTexture(GL_TEXTURE_2D, gi_fb->fb_texture[gi_fb->toggle][0]);
|
||||
//glBindTexture(GL_TEXTURE_2D, gi_fb->fb_texture[gi_fb->toggle][0]);
|
||||
//tms_fb_bind_current_textures(gi_fb, GL_TEXTURE3);
|
||||
|
||||
if (gi_fb) {
|
||||
if (settings["shadow_map_depth_texture"]->is_true()) {
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
|
|
@ -258,7 +253,6 @@ begin(void)
|
|||
}
|
||||
}
|
||||
if (ao_fb) tms_fb_bind_current_textures(ao_fb, GL_TEXTURE4);
|
||||
//glBindTexture(GL_TEXTURE_2D, gi_fb->fb_texture[gi_fb->toggle][0]);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
//glFinish();
|
||||
|
|
|
|||
|
|
@ -114,11 +114,6 @@ namespace tms
|
|||
return tms_texture_upload(this);
|
||||
}
|
||||
|
||||
inline int download()
|
||||
{
|
||||
return tms_texture_download(this);
|
||||
}
|
||||
|
||||
inline int bind()
|
||||
{
|
||||
return tms_texture_bind(this);
|
||||
|
|
|
|||
|
|
@ -543,16 +543,10 @@ tms_fb_init(struct tms_fb* fb)
|
|||
{
|
||||
int ierr;
|
||||
fb->toggle = 0;
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d before tms_fb_init", ierr);
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glGenFramebuffers)
|
||||
glGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o);
|
||||
else
|
||||
glGenFramebuffersEXT(fb->double_buffering ? 2 : 1, fb->fb_o);
|
||||
#else
|
||||
glGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o);
|
||||
#endif
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d after tms_fb_init", ierr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -571,51 +565,6 @@ tms_fb_free(struct tms_fb *fb)
|
|||
free(fb);
|
||||
}
|
||||
|
||||
void
|
||||
tms_fb_attach_depth(struct tms_fb *fb, int attachment, int name)
|
||||
{
|
||||
//if (fb->double_buffering)
|
||||
//tms_fatalf("tms_fb_attach functions not compatible with double buffered fb's");
|
||||
|
||||
tms_fatalf("not implemented");
|
||||
|
||||
/*
|
||||
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
fb->fb_depth[x] = name;
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
tms_fatalf("JSDAKLJDKLASKDJKLAJ");
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
tms_fb_enable_depth_and_stencil(struct tms_fb *fb)
|
||||
{
|
||||
tms_fatalf("not implemented");
|
||||
/*
|
||||
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
|
||||
glGenRenderbuffers(1, &fb->fb_depth[x]);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, fb->width, fb->height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
tms_fb_enable_depth(struct tms_fb *fb, int format)
|
||||
{
|
||||
|
|
@ -623,20 +572,11 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
|
|||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth (begin)", ierr);
|
||||
|
||||
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
else
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
#endif
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 1", ierr, x);
|
||||
|
||||
//tms_infof("enable depth after bind %d", glGetError());
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glGenRenderbuffers) {
|
||||
glGenRenderbuffers(1, &fb->fb_depth[x]);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
|
|
@ -644,58 +584,29 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
|
|||
glGenRenderbuffersEXT(1, &fb->fb_depth[x]);
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
}
|
||||
#else
|
||||
glGenRenderbuffers(1, &fb->fb_depth[x]);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
#endif
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 2-3", ierr, x);
|
||||
//tms_infof("enable depth after bindrender %d", glGetError());
|
||||
//glRenderbufferStorage(GL_RENDERBUFFER, format, fb->width, fb->height);
|
||||
//
|
||||
|
||||
#ifdef TMS_USE_GLES
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, fb->width, fb->height);
|
||||
#else
|
||||
if (glad_glRenderbufferStorage)
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, format, fb->width, fb->height);
|
||||
else
|
||||
glRenderbufferStorageEXT(GL_RENDERBUFFER, format, fb->width, fb->height);
|
||||
#endif
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 4", ierr, x);
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glFramebufferRenderbuffer)
|
||||
glad_glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
else
|
||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
#else
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
|
||||
#endif
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 5", ierr, x);
|
||||
//tms_infof("enable depth after hello %d", glGetError());
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindRenderbuffer) {
|
||||
if (glad_glBindRenderbuffer)
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
} else {
|
||||
else
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
#else
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
#endif
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 6", ierr, x);
|
||||
|
||||
}
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
else
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth 7 (end)", ierr);
|
||||
}
|
||||
|
||||
|
|
@ -703,14 +614,10 @@ void
|
|||
tms_fb_enable_depth_texture(struct tms_fb *fb, int format)
|
||||
{
|
||||
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glad_glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
else
|
||||
glad_glBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
#endif
|
||||
|
||||
glGenTextures(1, &fb->fb_depth[x]);
|
||||
glBindTexture(GL_TEXTURE_2D, fb->fb_depth[x]);
|
||||
|
|
@ -725,23 +632,15 @@ tms_fb_enable_depth_texture(struct tms_fb *fb, int format)
|
|||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fb->fb_depth[x], 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glad_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
else
|
||||
glad_glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -756,83 +655,43 @@ tms_fb_add_texture(struct tms_fb *fb, int format,
|
|||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture (begin)", ierr);
|
||||
|
||||
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
|
||||
//tms_infof("add texture before bind %d", glGetError());
|
||||
#ifndef TMS_USE_GLES
|
||||
|
||||
if (glad_glBindFramebuffer)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
else
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
|
||||
#endif
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 1", ierr, x);
|
||||
|
||||
glGenTextures(1, &fb->fb_texture[x][fb->num_textures]);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 2", ierr, x);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures]);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 3", ierr, x);
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (format == GL_R32F) {
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
// Note: GL_R32F, GL_RGB16F and GL_RGB32F aren't supported in OpenGL ES 2.0
|
||||
if (format == GL_R32F)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RED, GL_FLOAT, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 4", ierr, x);
|
||||
} else
|
||||
if (format == GL_RGB16F) {
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
else if (format == GL_RGB16F)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGB, GL_FLOAT, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 4", ierr, x);
|
||||
} else
|
||||
if (format == GL_RGB32F) {
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
else if (format == GL_RGB32F)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGB, GL_FLOAT, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 4", ierr, x);
|
||||
} else
|
||||
#endif
|
||||
if (format == GL_ALPHA) {
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
else if (format == GL_ALPHA)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 5", ierr, x);
|
||||
} else if (format == GL_RGBA4) {
|
||||
else if (format == GL_RGBA4)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 6", ierr, x);
|
||||
} else if (format == GL_RGB565) {
|
||||
else if (format == GL_RGB565)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 7", ierr, x);
|
||||
} else {
|
||||
else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, fb->width, fb->height, 0, format, GL_UNSIGNED_BYTE, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 8", ierr, x);
|
||||
}
|
||||
|
||||
//tms_infof("add texture after teximage2d %d", glGetError());
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 9", ierr, x);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 10", ierr, x);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_min);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 11", ierr, x);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_mag);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 12", ierr, x);
|
||||
|
||||
//tms_infof("add texture after parameters %d", glGetError());
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glFramebufferTexture2D)
|
||||
glad_glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures, GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
|
||||
else
|
||||
glad_glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures, GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
|
||||
#else
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures,
|
||||
GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
|
||||
#endif
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 13", ierr, x);
|
||||
|
||||
//tms_infof("add texture after fbtex2d %d", glGetError());
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 14", ierr, x);
|
||||
|
||||
/* update draw buffers */
|
||||
GLenum bufs[fb->num_textures+1];
|
||||
|
|
@ -849,14 +708,11 @@ tms_fb_add_texture(struct tms_fb *fb, int format,
|
|||
|
||||
fb->num_textures ++;
|
||||
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
else
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
|
||||
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture 16 (end)", ierr);
|
||||
}
|
||||
|
||||
|
|
@ -890,9 +746,6 @@ tms_fb_swap_blur3x3(struct tms_fb *f)
|
|||
|
||||
tms_program_bind(prg);
|
||||
tms_fb_swap(f, prg);
|
||||
/*
|
||||
tms_program_bind(blur3x3v_program);
|
||||
tms_fb_swap(f, blur3x3v_program);*/
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
|
@ -966,24 +819,18 @@ tms_fb_bind_last_textures(struct tms_fb *fb, int first_unit)
|
|||
static int _bind(struct tms_fb *f)
|
||||
{
|
||||
if (f != 0) {
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
|
||||
else
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
|
||||
#endif
|
||||
|
||||
glViewport(0, 0, f->width, f->height);
|
||||
} else {
|
||||
#ifndef TMS_USE_GLES
|
||||
if (glad_glBindFramebuffer)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
else
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
|
||||
glViewport(0, 0, tms.opengl_width, tms.opengl_height);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,13 +59,10 @@ tms_program_load_uniforms(struct tms_program *p)
|
|||
}
|
||||
|
||||
switch (type) {
|
||||
#ifndef TMS_USE_GLES
|
||||
case GL_SAMPLER_1D:
|
||||
case GL_SAMPLER_3D:
|
||||
case GL_SAMPLER_1D_SHADOW:
|
||||
case GL_SAMPLER_2D_SHADOW:
|
||||
#endif
|
||||
|
||||
case GL_SAMPLER_2D:
|
||||
case GL_SAMPLER_CUBE:
|
||||
/* bind samplers with names like tex_N to texture unit N,
|
||||
|
|
|
|||
|
|
@ -125,11 +125,9 @@ static GLint compile(struct tms_shader *sh, GLenum st, const char *src)
|
|||
GLint s = glCreateShader(st);
|
||||
GLint success;
|
||||
const char *type = st == GL_VERTEX_SHADER ? "vertex shader"
|
||||
#ifndef TMS_USE_GLES
|
||||
: st == GL_TESS_CONTROL_SHADER ? "tessellation control shader"
|
||||
: st == GL_TESS_EVALUATION_SHADER ? "tessellation evaluation shader"
|
||||
: st == GL_GEOMETRY_SHADER ? "geometry shader"
|
||||
#endif
|
||||
: "fragment shader";
|
||||
|
||||
int num_src = sh->num_defines + _tms_global_shader.num_defines + 1;
|
||||
|
|
@ -239,11 +237,9 @@ tms_shader_get_program(struct tms_shader *s, int pipeline)
|
|||
glAttachShader(p->id, s->vertex);
|
||||
tms_assertf(glGetError() == 0, "vafan 2 ");
|
||||
glAttachShader(p->id, s->fragment);
|
||||
#ifndef TMS_USE_GLES
|
||||
if (s->tess_control) glAttachShader(p->id, s->tess_control);
|
||||
if (s->tess_eval) glAttachShader(p->id, s->tess_eval);
|
||||
if (s->geometry) glAttachShader(p->id, s->geometry);
|
||||
#endif
|
||||
|
||||
glLinkProgram(p->id);
|
||||
tms_assertf(glGetError() == 0, "vafan 3");
|
||||
|
|
@ -293,11 +289,9 @@ tms_shader_compile(struct tms_shader *s,
|
|||
switch (shader_type) {
|
||||
case GL_VERTEX_SHADER: s->vertex = shader; break;
|
||||
case GL_FRAGMENT_SHADER: s->fragment = shader; break;
|
||||
#ifndef TMS_USE_GLES
|
||||
case GL_TESS_CONTROL_SHADER: s->tess_control = shader; break;
|
||||
case GL_TESS_EVALUATION_SHADER: s->tess_eval = shader; break;
|
||||
case GL_GEOMETRY_SHADER: s->geometry = shader; break;
|
||||
#endif
|
||||
default: tms_fatalf("unknown shader type %d, recognized by OpenGL but not TMS :(", shader_type); break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -481,14 +481,11 @@ tms_texture_set_filtering(struct tms_texture *tex, int filter)
|
|||
glEnable(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
#ifndef TMS_USE_GLES
|
||||
|
||||
if (glad_glGenerateMipmap)
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
else
|
||||
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
||||
#else
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
#endif
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
|
|
@ -498,21 +495,6 @@ tms_texture_set_filtering(struct tms_texture *tex, int filter)
|
|||
tex->filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @relates tms_texture
|
||||
**/
|
||||
int
|
||||
tms_texture_download(struct tms_texture *tex)
|
||||
{
|
||||
/* XXX */
|
||||
/*
|
||||
glBindTexture(GL_TEXTURE_2D, tex->gl_texture);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED, GL_UNSIGNED_BYTE, tex->data);
|
||||
tms_infof("err: %d", glGetError());
|
||||
*/
|
||||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the texture to the currently active opengl
|
||||
* texture unit.
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ int tms_texture_load(struct tms_texture *tex, const char *filename);
|
|||
int tms_texture_load_mem(struct tms_texture *tex, const char *buf, int width, int height, int num_channels);
|
||||
int tms_texture_load_mem2(struct tms_texture *tex, const char *buf, size_t size, int freesrc);
|
||||
int tms_texture_upload(struct tms_texture *tex);
|
||||
int tms_texture_download(struct tms_texture *tex);
|
||||
int tms_texture_bind(struct tms_texture *tex);
|
||||
int tms_texture_flip_y(struct tms_texture *tex);
|
||||
int tms_texture_flip_x(struct tms_texture *tex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue