diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-10-25 08:02:41 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-10-25 08:02:41 +0300 |
commit | c5072941c3902bd91824a7d8756933dbf97f78cf (patch) | |
tree | 87491f54e59c99616b863041e7df5f71c2fe4bcf /source/blender/gpu/intern/gpu_texture.c | |
parent | 4d11b2fb9172789cd0171712ae88e6aa98eb3743 (diff) |
OpenGL: clean up glActiveTexture usage
Removed some of my earlier glActiveTexture calls. After reviewing the
code I now trust that GL_TEXTURE0 is active by default. Fewer GL calls,
same results.
Fixed some misuse of glActiveTexture & glUniformi, mostly my fault.
Caught by --debug-gpu on Windows. Don't know why this appeared to be
working previously!
Plus some easy cleanup nearby.
Diffstat (limited to 'source/blender/gpu/intern/gpu_texture.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index c6cf4dec22e..6956a815ac5 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -616,15 +616,18 @@ void GPU_texture_bind(GPUTexture *tex, int number) if (number < 0) return; - GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number); - if (number != 0) glActiveTexture(arbnumber); - if (tex->bindcode != 0) { + if (number != 0) + glActiveTexture(GL_TEXTURE0 + number); + + if (tex->bindcode != 0) glBindTexture(tex->target_base, tex->bindcode); - } else GPU_invalid_tex_bind(tex->target_base); - glEnable(tex->target_base); - if (number != 0) glActiveTexture(GL_TEXTURE0); + + glEnable(tex->target_base); /* TODO: remove this line once we're using GLSL everywhere */ + + if (number != 0) + glActiveTexture(GL_TEXTURE0); tex->number = number; } @@ -639,11 +642,14 @@ void GPU_texture_unbind(GPUTexture *tex) if (tex->number == -1) return; - GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); - if (tex->number != 0) glActiveTexture(arbnumber); + if (tex->number != 0) + glActiveTexture(GL_TEXTURE0 + tex->number); + glBindTexture(tex->target_base, 0); - glDisable(tex->target_base); - if (tex->number != 0) glActiveTexture(GL_TEXTURE0); + glDisable(tex->target_base); /* TODO: remove this line */ + + if (tex->number != 0) + glActiveTexture(GL_TEXTURE0); tex->number = -1; } @@ -663,25 +669,19 @@ void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter) if (tex->number == -1) return; - GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); - if (tex->number != 0) glActiveTexture(arbnumber); + if (tex->number != 0) + glActiveTexture(GL_TEXTURE0 + tex->number); if (tex->depth) { - if (compare) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); - else - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE); } - if (use_filter) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } - else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - if (tex->number != 0) glActiveTexture(GL_TEXTURE0); + GLenum filter = use_filter ? GL_LINEAR : GL_NEAREST; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + + if (tex->number != 0) + glActiveTexture(GL_TEXTURE0); } void GPU_texture_free(GPUTexture *tex) |