Review custom blend modes mechanism
rlBlendMode() has been added to rlgl to be used on BLEND_CUSTOM. This functionality is exposed to advance users. In any case, new blending modes could be added if required.
This commit is contained in:
parent
bfafb80cde
commit
a1422ba1c1
2 changed files with 29 additions and 31 deletions
|
@ -808,8 +808,9 @@ typedef enum {
|
||||||
BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
||||||
BLEND_ADDITIVE, // Blend textures adding colors
|
BLEND_ADDITIVE, // Blend textures adding colors
|
||||||
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_CUSTOM // Belnd textures using custom src/dst factors (use SetBlendModeCustom())
|
||||||
} BlendMode;
|
} BlendMode;
|
||||||
|
|
||||||
// Gestures type
|
// Gestures type
|
||||||
|
@ -1391,10 +1392,8 @@ RLAPI Texture2D GenTextureBRDF(Shader shader, int size); // Gen
|
||||||
RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing
|
RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing
|
||||||
RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader)
|
RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader)
|
||||||
RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
|
RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
|
||||||
RLAPI void BeginBlendModeEx(int sFactor, int dFactor, int equation); // Begin blending mode (full options)
|
|
||||||
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
||||||
|
|
||||||
|
|
||||||
// VR control functions
|
// VR control functions
|
||||||
RLAPI void InitVrSimulator(void); // Init VR simulator for selected device parameters
|
RLAPI void InitVrSimulator(void); // Init VR simulator for selected device parameters
|
||||||
RLAPI void CloseVrSimulator(void); // Close VR simulator for current device
|
RLAPI void CloseVrSimulator(void); // Close VR simulator for current device
|
||||||
|
|
53
src/rlgl.h
53
src/rlgl.h
|
@ -524,6 +524,7 @@ RLAPI void rlCheckErrors(void); // Check and log OpenGL er
|
||||||
RLAPI int rlGetVersion(void); // Returns current OpenGL version
|
RLAPI int rlGetVersion(void); // Returns current OpenGL version
|
||||||
RLAPI bool rlCheckBufferLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
RLAPI bool rlCheckBufferLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
||||||
RLAPI void rlSetDebugMarker(const char *text); // Set debug marker for analysis
|
RLAPI void rlSetDebugMarker(const char *text); // Set debug marker for analysis
|
||||||
|
RLAPI void rlSetBlendMode(int glSrcFactor, int glDstFactor, int glEquation); // // Set blending mode factor and equation (using OpenGL factors)
|
||||||
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions
|
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions
|
||||||
RLAPI Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
RLAPI Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
||||||
|
|
||||||
|
@ -589,7 +590,6 @@ RLAPI Texture2D GenTextureBRDF(Shader shader, int size); // Gen
|
||||||
RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing
|
RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing
|
||||||
RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader)
|
RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader)
|
||||||
RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
|
RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
|
||||||
RLAPI void BeginBlendModeEx(int sFactor, int dFactor, int equation); // Begin blending mode (full options)
|
|
||||||
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
||||||
|
|
||||||
// VR control functions
|
// VR control functions
|
||||||
|
@ -853,6 +853,11 @@ typedef struct rlglData {
|
||||||
Shader defaultShader; // Basic shader, support vertex color and diffuse texture
|
Shader defaultShader; // Basic shader, support vertex color and diffuse texture
|
||||||
Shader currentShader; // Shader to be used on rendering (by default, defaultShader)
|
Shader currentShader; // Shader to be used on rendering (by default, defaultShader)
|
||||||
|
|
||||||
|
int currentBlendMode; // Blending mode active
|
||||||
|
int glBlendSrcFactor; // Blending source factor
|
||||||
|
int glBlendDstFactor; // Blending destination factor
|
||||||
|
int glBlendEquation; // Blending equation
|
||||||
|
|
||||||
int framebufferWidth; // Default framebuffer width
|
int framebufferWidth; // Default framebuffer width
|
||||||
int framebufferHeight; // Default framebuffer height
|
int framebufferHeight; // Default framebuffer height
|
||||||
|
|
||||||
|
@ -1871,6 +1876,14 @@ void rlSetDebugMarker(const char *text)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set blending mode factor and equation
|
||||||
|
void rlSetBlendMode(int glSrcFactor, int glDstFactor, int glEquation)
|
||||||
|
{
|
||||||
|
RLGL.State.glBlendSrcFactor = glSrcFactor;
|
||||||
|
RLGL.State.glBlendDstFactor = glDstFactor;
|
||||||
|
RLGL.State.glBlendEquation = glEquation;
|
||||||
|
}
|
||||||
|
|
||||||
// Load OpenGL extensions
|
// Load OpenGL extensions
|
||||||
// NOTE: External loader function could be passed as a pointer
|
// NOTE: External loader function could be passed as a pointer
|
||||||
void rlLoadExtensions(void *loader)
|
void rlLoadExtensions(void *loader)
|
||||||
|
@ -3609,40 +3622,26 @@ Texture2D GenTextureBRDF(Shader shader, int size)
|
||||||
return brdf;
|
return brdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BeginBlendModeEx(int sFactor, int dFactor, int equation)
|
|
||||||
{
|
|
||||||
static int glSFactor = 0; // Track current blending mode
|
|
||||||
static int glDFactor = 0; // Track current blending mode
|
|
||||||
static int glEquation = 0; // Track current blending mode
|
|
||||||
|
|
||||||
if (glSFactor != sFactor || glDFactor != dFactor || glEquation != equation) {
|
|
||||||
|
|
||||||
rlglDraw();
|
|
||||||
glBlendFunc(sFactor, dFactor);
|
|
||||||
glBlendEquation(equation);
|
|
||||||
|
|
||||||
glSFactor = sFactor;
|
|
||||||
glDFactor = dFactor;
|
|
||||||
glEquation = equation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begin blending mode (alpha, additive, multiplied)
|
// Begin blending mode (alpha, additive, multiplied)
|
||||||
// NOTE: Only 3 blending modes supported, default blend mode is alpha
|
// NOTE: Only 3 blending modes supported, default blend mode is alpha
|
||||||
void BeginBlendMode(int mode)
|
void BeginBlendMode(int mode)
|
||||||
{
|
{
|
||||||
if (mode < 5)
|
if (RLGL.State.currentBlendMode != mode)
|
||||||
{
|
{
|
||||||
|
rlglDraw();
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case BLEND_ALPHA: BeginBlendModeEx(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD); break;
|
case BLEND_ALPHA: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
|
||||||
case BLEND_ADDITIVE: BeginBlendModeEx(GL_SRC_ALPHA, GL_ONE, GL_FUNC_ADD); break;
|
case BLEND_ADDITIVE: glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
|
||||||
case BLEND_MULTIPLIED: BeginBlendModeEx(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD); break;
|
case BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
|
||||||
case BLEND_ADD_COLORS: BeginBlendModeEx(GL_ONE, GL_ONE, GL_FUNC_ADD); break;
|
case BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
|
||||||
case BLEND_SUBTRACT_COLORS: BeginBlendModeEx(GL_ONE, GL_ONE, GL_FUNC_SUBTRACT); break;
|
case BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break;
|
||||||
default: break;
|
case BLEND_CUSTOM: glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation); break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RLGL.State.currentBlendMode = mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue