Updated blend semantics so blending uses the following formula:

dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
    dstA = srcA + (dstA * (1-srcA))
This allows proper compositing semantics without requiring premultiplied alpha.

Needs full unit test coverage and bug fixes!
This commit is contained in:
Sam Lantinga 2013-07-23 08:06:49 -07:00
parent a99edf3519
commit 32188834b5
17 changed files with 362 additions and 1001 deletions

View file

@ -121,6 +121,7 @@ typedef struct
SDL_bool useDrawTexture;
SDL_bool GL_OES_draw_texture_supported;
SDL_bool GL_OES_blend_func_separate_supported;
} GLES_RenderData;
typedef struct
@ -376,6 +377,10 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
}
data->framebuffers = NULL;
if (SDL_GL_ExtensionSupported("GL_OES_blend_func_separate")) {
data->GL_OES_blend_func_separate_supported = SDL_TRUE;
}
/* Set up parameters for rendering */
GLES_ResetState(renderer);
@ -680,17 +685,29 @@ GLES_SetBlendMode(GLES_RenderData * data, int blendMode)
case SDL_BLENDMODE_BLEND:
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
data->glEnable(GL_BLEND);
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (data->GL_OES_blend_func_separate_supported) {
data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
} else {
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
break;
case SDL_BLENDMODE_ADD:
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
data->glEnable(GL_BLEND);
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
if (data->GL_OES_blend_func_separate_supported) {
data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
} else {
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
break;
case SDL_BLENDMODE_MOD:
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
data->glEnable(GL_BLEND);
data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
if (data->GL_OES_blend_func_separate_supported) {
data->glBlendFuncSeparateOES(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
} else {
data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
}
break;
}
data->current.blendMode = blendMode;