diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2014-06-10 02:36:53 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2014-06-10 02:43:54 +0400 |
commit | e8c63caf77a1d3470556433065261a4ede3ebae2 (patch) | |
tree | 5984db4e13d1fb78fc14f8c1e037f3dab08bd806 /source/blender/gpu/intern/gpu_extensions.c | |
parent | 131d388d81a6c676498050e6905de8f7c6df8190 (diff) |
Fix T40498 invalid textures flickering.
Issue here is most likely sampler uniforms and textures not being
updated properly when zero binding is created. Solution for now is to
allow zero binding but when this happens use sexy pink invalid texture
instead :p.
Diffstat (limited to 'source/blender/gpu/intern/gpu_extensions.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index cd256a570d0..bad561d08c7 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -94,6 +94,9 @@ static struct GPUGlobal { GPUOSType os; GPUDriverType driver; GPUShaders shaders; + GPUTexture *invalid_tex_1D; /* texture used in place of invalid textures (not loaded correctly, missing) */ + GPUTexture *invalid_tex_2D; + GPUTexture *invalid_tex_3D; } GG = {1, 0}; /* GPU Types */ @@ -223,6 +226,8 @@ void GPU_extensions_init(void) GG.os = GPU_OS_UNIX; #endif + + GPU_invalid_tex_init(); GPU_simple_shaders_init(); } @@ -231,6 +236,7 @@ void GPU_extensions_exit(void) gpu_extensions_init = 0; GPU_codegen_exit(); GPU_simple_shaders_exit(); + GPU_invalid_tex_free(); } int GPU_glsl_support(void) @@ -572,11 +578,6 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, return ima->gputexture; } - if (!bindcode) { - glBindTexture(GL_TEXTURE_2D, lastbindcode); - return NULL; - } - tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = bindcode; tex->number = -1; @@ -587,7 +588,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, ima->gputexture= tex; if (!glIsTexture(tex->bindcode)) { - GPU_print_error("Blender Texture"); + GPU_print_error("Blender Texture Not Loaded"); } else { glBindTexture(GL_TEXTURE_2D, tex->bindcode); @@ -625,12 +626,6 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) return tex; } - /* error binding anything */ - if (!bindcode) { - glBindTexture(GL_TEXTURE_2D, lastbindcode); - return NULL; - } - tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = bindcode; tex->number = -1; @@ -640,7 +635,7 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) prv->gputexture[0]= tex; if (!glIsTexture(tex->bindcode)) { - GPU_print_error("Blender Texture"); + GPU_print_error("Blender Texture Not Loaded"); } else { glBindTexture(GL_TEXTURE_2D, tex->bindcode); @@ -706,6 +701,37 @@ GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]) return tex; } +void GPU_invalid_tex_init(void) +{ + float color[4] = {1.0f, 0.0f, 1.0f, 1.0}; + GG.invalid_tex_1D = GPU_texture_create_1D(1, color, NULL); + GG.invalid_tex_2D = GPU_texture_create_2D(1, 1, color, NULL); + GG.invalid_tex_3D = GPU_texture_create_3D(1, 1, 1, 4, color); +} + +void GPU_invalid_tex_bind(int mode) +{ + switch(mode) { + case GL_TEXTURE_1D: + glBindTexture(GL_TEXTURE_1D, GG.invalid_tex_1D->bindcode); + break; + case GL_TEXTURE_2D: + glBindTexture(GL_TEXTURE_2D, GG.invalid_tex_2D->bindcode); + break; + case GL_TEXTURE_3D: + glBindTexture(GL_TEXTURE_3D, GG.invalid_tex_3D->bindcode); + break; + } +} + +void GPU_invalid_tex_free(void) +{ + GPU_texture_free(GG.invalid_tex_1D); + GPU_texture_free(GG.invalid_tex_2D); + GPU_texture_free(GG.invalid_tex_3D); +} + + void GPU_texture_bind(GPUTexture *tex, int number) { GLenum arbnumber; @@ -722,7 +748,11 @@ void GPU_texture_bind(GPUTexture *tex, int number) arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + number); if (number != 0) glActiveTextureARB(arbnumber); - glBindTexture(tex->target, tex->bindcode); + if (tex->bindcode != 0) { + glBindTexture(tex->target, tex->bindcode); + } + else + GPU_invalid_tex_bind(tex->target); glEnable(tex->target); if (number != 0) glActiveTextureARB(GL_TEXTURE0_ARB); @@ -1397,7 +1427,10 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); if (tex->number != 0) glActiveTextureARB(arbnumber); - glBindTexture(tex->target, tex->bindcode); + if (tex->bindcode != 0) + glBindTexture(tex->target, tex->bindcode); + else + GPU_invalid_tex_bind(tex->target); glUniform1iARB(location, tex->number); glEnable(tex->target); if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB); |