add premultiplied alpha blend mode (#2342)

This commit is contained in:
megagrump 2022-02-13 18:42:24 +01:00 committed by GitHub
parent 4bc6e0d7de
commit f40eed5adf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -839,6 +839,7 @@ typedef enum {
BLEND_MULTIPLIED, // Blend textures multiplying colors BLEND_MULTIPLIED, // Blend textures multiplying colors
BLEND_ADD_COLORS, // Blend textures adding colors (alternative) BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative) BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
BLEND_ALPHA_PREMUL, // Blend premultiplied textures considering alpha
BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendMode()) BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendMode())
} BlendMode; } BlendMode;

View file

@ -433,6 +433,7 @@ typedef enum {
RL_BLEND_MULTIPLIED, // Blend textures multiplying colors RL_BLEND_MULTIPLIED, // Blend textures multiplying colors
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative) RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative) RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
RL_BLEND_ALPHA_PREMUL, // Blend premultiplied textures considering alpha
RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors()) RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors())
} rlBlendMode; } rlBlendMode;
@ -1778,10 +1779,11 @@ void rlSetBlendMode(int mode)
case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break; case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break; case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break; case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break;
case RL_BLEND_CUSTOM: case RL_BLEND_ALPHA_PREMUL: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_CUSTOM:
{ {
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors() // NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()
glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation); glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation);
} break; } break;
default: break; default: break;
} }
@ -3911,7 +3913,7 @@ void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned
unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint) unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint)
{ {
unsigned int ssbo = 0; unsigned int ssbo = 0;
#if defined(GRAPHICS_API_OPENGL_43) #if defined(GRAPHICS_API_OPENGL_43)
glGenBuffers(1, &ssbo); glGenBuffers(1, &ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo); glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
@ -3944,7 +3946,7 @@ void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned lo
unsigned long long rlGetShaderBufferSize(unsigned int id) unsigned long long rlGetShaderBufferSize(unsigned int id)
{ {
long long size = 0; long long size = 0;
#if defined(GRAPHICS_API_OPENGL_43) #if defined(GRAPHICS_API_OPENGL_43)
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id); glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
glGetInteger64v(GL_SHADER_STORAGE_BUFFER_SIZE, &size); glGetInteger64v(GL_SHADER_STORAGE_BUFFER_SIZE, &size);