Fixed bug 3361 - Texture color modulation doesn't work with active NONE blend mode (opengl and opengles)
authorSam Lantinga
Sat, 01 Oct 2016 11:04:45 -0700
changeset 1040248b40c223503
parent 10401 5ceaeb95972e
child 10403 a0c76d344583
Fixed bug 3361 - Texture color modulation doesn't work with active NONE blend mode (opengl and opengles)

Simon Hug

The GL_SetBlendMode and GLES_SetBlendMode functions of the opengl and opengles renderers call the glTexEnvf to set the texture env mode to either GL_MODULATE (the default) or GL_REPLACE for the NONE blend mode. Using GL_REPLACE disables color and alpha modulation for textures.

These glTexEnv calls were put in the SetBlendMode function back in 2006 [1], but there the NONE code still used the GL_DECAL mode. The GL_REPLACE mode came in 2008 [2]. I'm a bit confused why that wasn't always GL_MODULATE and a bit surprised nobody reported that yet (unless I missed it). I guess only a few use the gles renderer and the newish shaders mask the issue.
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_render_gles.c
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Sat Oct 01 10:52:24 2016 -0700
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Sat Oct 01 11:04:45 2016 -0700
     1.3 @@ -1098,21 +1098,17 @@
     1.4      if (blendMode != data->current.blendMode) {
     1.5          switch (blendMode) {
     1.6          case SDL_BLENDMODE_NONE:
     1.7 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     1.8              data->glDisable(GL_BLEND);
     1.9              break;
    1.10          case SDL_BLENDMODE_BLEND:
    1.11 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    1.12              data->glEnable(GL_BLEND);
    1.13              data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    1.14              break;
    1.15          case SDL_BLENDMODE_ADD:
    1.16 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    1.17              data->glEnable(GL_BLEND);
    1.18              data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
    1.19              break;
    1.20          case SDL_BLENDMODE_MOD:
    1.21 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    1.22              data->glEnable(GL_BLEND);
    1.23              data->glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
    1.24              break;
     2.1 --- a/src/render/opengles/SDL_render_gles.c	Sat Oct 01 10:52:24 2016 -0700
     2.2 +++ b/src/render/opengles/SDL_render_gles.c	Sat Oct 01 11:04:45 2016 -0700
     2.3 @@ -734,11 +734,9 @@
     2.4      if (blendMode != data->current.blendMode) {
     2.5          switch (blendMode) {
     2.6          case SDL_BLENDMODE_NONE:
     2.7 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     2.8              data->glDisable(GL_BLEND);
     2.9              break;
    2.10          case SDL_BLENDMODE_BLEND:
    2.11 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    2.12              data->glEnable(GL_BLEND);
    2.13              if (data->GL_OES_blend_func_separate_supported) {
    2.14                  data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    2.15 @@ -747,7 +745,6 @@
    2.16              }
    2.17              break;
    2.18          case SDL_BLENDMODE_ADD:
    2.19 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    2.20              data->glEnable(GL_BLEND);
    2.21              if (data->GL_OES_blend_func_separate_supported) {
    2.22                  data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
    2.23 @@ -756,7 +753,6 @@
    2.24              }
    2.25              break;
    2.26          case SDL_BLENDMODE_MOD:
    2.27 -            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    2.28              data->glEnable(GL_BLEND);
    2.29              if (data->GL_OES_blend_func_separate_supported) {
    2.30                  data->glBlendFuncSeparateOES(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);