diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-06-07 22:39:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-07 22:40:21 +0300 |
commit | 5bd9e832898221e5363150ee108655fd7f9c08a0 (patch) | |
tree | 80b71df4f7e358de302c304e04eb8708cbf2ee49 /source/blender/gpu/intern/gpu_basic_shader.c | |
parent | 91c146c42e51676c71eea39342be932c150d5d45 (diff) |
GPU: Fix triple buffer w/ basic glsl shader
Needed to add GL_TEXTURE_RECTANGLE support to basic-shader.
Diffstat (limited to 'source/blender/gpu/intern/gpu_basic_shader.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_basic_shader.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c index e4ec57d9cd3..b0669225a4d 100644 --- a/source/blender/gpu/intern/gpu_basic_shader.c +++ b/source/blender/gpu/intern/gpu_basic_shader.c @@ -324,6 +324,9 @@ static int detect_options() if (glIsEnabled(GL_TEXTURE_2D)) options |= GPU_SHADER_TEXTURE_2D; + if (glIsEnabled(GL_TEXTURE_RECTANGLE)) + options |= GPU_SHADER_TEXTURE_RECT; + GPU_SHADER_TEXTURE_RECT if (glIsEnabled(GL_COLOR_MATERIAL)) options |= GPU_SHADER_USE_COLOR; @@ -363,8 +366,10 @@ static GPUShader *gpu_basic_shader(int options) strcat(defines, "#define USE_COLOR\n"); if (options & GPU_SHADER_TWO_SIDED) strcat(defines, "#define USE_TWO_SIDED\n"); - if (options & GPU_SHADER_TEXTURE_2D) + if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT)) strcat(defines, "#define USE_TEXTURE\n"); + if (options & GPU_SHADER_TEXTURE_RECT) + strcat(defines, "#define USE_TEXTURE_RECTANGLE\n"); if (options & GPU_SHADER_STIPPLE) strcat(defines, "#define USE_STIPPLE\n"); if (options & GPU_SHADER_LINE) { @@ -385,7 +390,7 @@ static GPUShader *gpu_basic_shader(int options) if (shader) { /* set texture map to first texture unit */ - if (options & GPU_SHADER_TEXTURE_2D) { + if (options & (GPU_SHADER_TEXTURE_2D | GPU_SHADER_TEXTURE_RECT)) { GPU_shader_bind(shader); glUniform1i(GPU_shader_get_uniform(shader, "texture_map"), 0); GPU_shader_unbind(); @@ -415,6 +420,23 @@ void GPU_basic_shader_bind(int options) { if (USE_GLSL) { if (options) { + const int bound_options = GPU_MATERIAL_STATE.bound_options; + + /* texture options need to be set for basic shader too */ + if (options & GPU_SHADER_TEXTURE_2D) { + glEnable(GL_TEXTURE_2D); + } + else if (bound_options & GPU_SHADER_TEXTURE_2D) { + glDisable(GL_TEXTURE_2D); + } + + if (options & GPU_SHADER_TEXTURE_RECT) { + glEnable(GL_TEXTURE_RECTANGLE); + } + else if (bound_options & GPU_SHADER_TEXTURE_RECT) { + glDisable(GL_TEXTURE_RECTANGLE); + } + GPUShader *shader = gpu_basic_shader(options); if (shader) { @@ -427,7 +449,7 @@ void GPU_basic_shader_bind(int options) } } else { - int bound_options = GPU_MATERIAL_STATE.bound_options; + const int bound_options = GPU_MATERIAL_STATE.bound_options; if (options & GPU_SHADER_LIGHTING) { glEnable(GL_LIGHTING); @@ -454,10 +476,24 @@ void GPU_basic_shader_bind(int options) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode); } else if (bound_options & GPU_SHADER_TEXTURE_2D) { - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + if ((options & GPU_SHADER_TEXTURE_RECT) == 0) { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } glDisable(GL_TEXTURE_2D); } + if (options & GPU_SHADER_TEXTURE_RECT) { + GLint env_mode = (options & (GPU_SHADER_USE_COLOR | GPU_SHADER_LIGHTING)) ? GL_MODULATE : GL_REPLACE; + glEnable(GL_TEXTURE_RECTANGLE); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode); + } + else if (bound_options & GPU_SHADER_TEXTURE_RECT) { + if ((options & GPU_SHADER_TEXTURE_2D) == 0) { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + glDisable(GL_TEXTURE_RECTANGLE); + } + if ((options & GPU_SHADER_LINE) && (options & GPU_SHADER_STIPPLE)) { glEnable(GL_LINE_STIPPLE); } |