OpenGL Stencil management functions.

This commit is contained in:
jussi
2024-04-15 20:07:32 +03:00
parent 1d66edf4f2
commit 3aecd6dd99
7 changed files with 641 additions and 16 deletions

153
src/gl.c
View File

@@ -5,17 +5,17 @@
#include "lgl.h"
/*
## OpenGL - Framebuffer management
## OpenGL - Frame Buffers
*/
/*
> RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
Copy a block of pixels from one framebuffer object to another.
Use -1 RenderTexture for window framebuffer
Use nil RenderTexture for window framebuffer
*/
int lglBlitFramebuffer( lua_State* L ) {
#if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL )
// #if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL )
if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) {
TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" );
lua_pushnil( L );
@@ -53,5 +53,150 @@ int lglBlitFramebuffer( lua_State* L ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
return 1;
#endif
// #endif
}
/*
## OpenGL - State Management
*/
/*
> RL.glEnable( int cap )
Enable server-side GL capabilities
*/
int lglEnable( lua_State* L ) {
int cap = luaL_checkinteger( L, 1 );
glEnable( cap );
return 0;
}
/*
> RL.glDisable( int cap )
Disable server-side GL capabilities
*/
int lglDisable( lua_State* L ) {
int cap = luaL_checkinteger( L, 1 );
glDisable( cap );
return 0;
}
/*
> RL.glStencilFunc( int func, int ref, int mask )
Set front and back function and reference value for stencil testing
*/
int lglStencilFunc( lua_State* L ) {
int func = luaL_checkinteger( L, 1 );
int ref = luaL_checkinteger( L, 2 );
unsigned int mask = luaL_checkinteger( L, 3 );
glStencilFunc( func, ref, mask );
return 0;
}
/*
> RL.glStencilFuncSeparate( int face, int func, int ref, int mask )
Set front and/or back function and reference value for stencil testing
*/
int lglStencilFuncSeparate( lua_State* L ) {
int face = luaL_checkinteger( L, 1 );
int func = luaL_checkinteger( L, 2 );
int ref = luaL_checkinteger( L, 3 );
unsigned int mask = luaL_checkinteger( L, 4 );
glStencilFuncSeparate( face, func, ref, mask );
return 0;
}
/*
> RL.glStencilMask( int mask )
Control the front and back writing of individual bits in the stencil planes
*/
int lglStencilMask( lua_State* L ) {
unsigned int mask = luaL_checkinteger( L, 1 );
glStencilMask( mask );
return 0;
}
/*
> RL.glStencilMaskSeparate( int face, int mask )
Control the front and/or back writing of individual bits in the stencil planes
*/
int lglStencilMaskSeparate( lua_State* L ) {
int face = luaL_checkinteger( L, 1 );
unsigned int mask = luaL_checkinteger( L, 2 );
glStencilMaskSeparate( face, mask );
return 0;
}
/*
> RL.glStencilOp( int sfail, int dpfail, int dppass )
Set front and back stencil test actions
*/
int lglStencilOp( lua_State* L ) {
int sfail = luaL_checkinteger( L, 1 );
int dpfail = luaL_checkinteger( L, 2 );
int dppass = luaL_checkinteger( L, 3 );
glStencilOp( sfail, dpfail, dppass );
return 0;
}
/*
> RL.glStencilOpSeparate( int face, int sfail, int dpfail, int dppass )
Set front and back stencil test actions
*/
int lglStencilOpSeparate( lua_State* L ) {
int face = luaL_checkinteger( L, 1 );
int sfail = luaL_checkinteger( L, 2 );
int dpfail = luaL_checkinteger( L, 3 );
int dppass = luaL_checkinteger( L, 4 );
glStencilOpSeparate( face, sfail, dpfail, dppass );
return 0;
}
/*
## OpenGL - Utility
*/
/*
> connection = RL.glGetString( int name, int|nil index )
Return a string describing the current GL connection. GL_EXTENSIONS returns the extension string supported by the implementation at index
- Success return string
*/
int lglGetString( lua_State* L ) {
int name = luaL_checkinteger( L, 1 );
if ( uluaIsNil( L, 2 ) ) {
lua_pushstring( L, glGetString( name ) );
}
else {
int index = luaL_checkinteger( L, 2 );
lua_pushstring( L, glGetStringi( name, index ) );
}
return 1;
}

View File

@@ -968,13 +968,52 @@ static void defineGlobals() {
/* RLGL CullMode */
assignGlobalInt( RL_CULL_FACE_FRONT, "RL_CULL_FACE_FRONT" );
assignGlobalInt( RL_CULL_FACE_BACK, "RL_CULL_FACE_BACK" );
/* OpenGL */
/* OpenGL Bitfield mask */
assignGlobalInt( GL_COLOR_BUFFER_BIT, "GL_COLOR_BUFFER_BIT" );
assignGlobalInt( GL_DEPTH_BUFFER_BIT, "GL_DEPTH_BUFFER_BIT" );
assignGlobalInt( GL_STENCIL_BUFFER_BIT, "GL_STENCIL_BUFFER_BIT" );
/* OpenGL Texture parameter */
assignGlobalInt( GL_NEAREST, "GL_NEAREST" );
assignGlobalInt( GL_LINEAR, "GL_LINEAR" );
/* CBuffer Data types */
/* OpenGL Capability */
assignGlobalInt( GL_BLEND, "GL_BLEND" ); // If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc
assignGlobalInt( GL_CULL_FACE, "GL_CULL_FACE" ); // If enabled, cull polygons based on their winding in window coordinates. See glCullFace
assignGlobalInt( GL_DEPTH_TEST, "GL_DEPTH_TEST" ); // If enabled, do depth comparisons and update the depth buffer. Note that even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. See glDepthFunc and glDepthRangef
assignGlobalInt( GL_DITHER, "GL_DITHER" ); // If enabled, dither color components or indices before they are written to the color buffer
assignGlobalInt( GL_POLYGON_OFFSET_FILL, "GL_POLYGON_OFFSET_FILL" ); // If enabled, an offset is added to depth values of a polygon's fragments produced by rasterization. See glPolygonOffset
assignGlobalInt( GL_SAMPLE_ALPHA_TO_COVERAGE, "GL_SAMPLE_ALPHA_TO_COVERAGE" ); // If enabled, compute a temporary coverage value where each bit is determined by the alpha value at the corresponding sample location. The temporary coverage value is then ANDed with the fragment coverage value
assignGlobalInt( GL_SAMPLE_COVERAGE, "GL_SAMPLE_COVERAGE" ); // If enabled, the fragment's coverage is ANDed with the temporary coverage value. If GL_SAMPLE_COVERAGE_INVERT is set to GL_TRUE, invert the coverage value. See glSampleCoverage
assignGlobalInt( GL_SCISSOR_TEST, "GL_SCISSOR_TEST" ); // If enabled, discard fragments that are outside the scissor rectangle. See glScissor
assignGlobalInt( GL_STENCIL_TEST, "GL_STENCIL_TEST" ); // If enabled, do stencil testing and update the stencil buffer. See glStencilFunc and glStencilOp
/* OpenGL Test function */
assignGlobalInt( GL_NEVER, "GL_NEVER" ); // Always fails
assignGlobalInt( GL_LESS, "GL_LESS" ); // Passes if ( ref & mask ) < ( stencil & mask )
assignGlobalInt( GL_LEQUAL, "GL_LEQUAL" ); // Passes if ( ref & mask ) <= ( stencil & mask )
assignGlobalInt( GL_GREATER, "GL_GREATER" ); // Passes if ( ref & mask ) > ( stencil & mask )
assignGlobalInt( GL_GEQUAL, "GL_GEQUAL" ); // Passes if ( ref & mask ) >= ( stencil & mask )
assignGlobalInt( GL_EQUAL, "GL_EQUAL" ); // Passes if ( ref & mask ) = ( stencil & mask )
assignGlobalInt( GL_NOTEQUAL, "GL_NOTEQUAL" ); // Passes if ( ref & mask ) != ( stencil & mask )
assignGlobalInt( GL_ALWAYS, "GL_ALWAYS" ); // Always passes
/* OpenGL Face */
assignGlobalInt( GL_FRONT, "GL_FRONT" );
assignGlobalInt( GL_BACK, "GL_BACK" );
assignGlobalInt( GL_FRONT_AND_BACK, "GL_FRONT_AND_BACK" );
/* OpenGL Stencil test */
assignGlobalInt( GL_KEEP, "GL_KEEP" ); // Keeps the current value
assignGlobalInt( GL_ZERO, "GL_ZERO" ); // Sets the stencil buffer value to 0
assignGlobalInt( GL_REPLACE, "GL_REPLACE" ); // Sets the stencil buffer value to ref, as specified by glStencilFunc
assignGlobalInt( GL_INCR, "GL_INCR" ); // Increments the current stencil buffer value. Clamps to the maximum representable unsigned value
assignGlobalInt( GL_INCR_WRAP, "GL_INCR_WRAP" ); // Increments the current stencil buffer value. Wraps stencil buffer value to zero when incrementing the maximum representable unsigned value
assignGlobalInt( GL_DECR, "GL_DECR" ); // Decrements the current stencil buffer value. Clamps to 0
assignGlobalInt( GL_DECR_WRAP, "GL_DECR_WRAP" ); // Decrements the current stencil buffer value. Wraps stencil buffer value to the maximum representable unsigned value when decrementing a stencil buffer value of zero
assignGlobalInt( GL_INVERT, "GL_INVERT" ); // Bitwise inverts the current stencil buffer value
/* OpenGL Connection */
assignGlobalInt( GL_VENDOR, "GL_VENDOR" ); // Returns the company responsible for this GL implementation. This name does not change from release to release
assignGlobalInt( GL_RENDERER, "GL_RENDERER" ); // Returns the name of the renderer. This name is typically specific to a particular configuration of a hardware platform. It does not change from release to release
assignGlobalInt( GL_VERSION, "GL_VERSION" ); // Returns a version or release number of the form OpenGLES
assignGlobalInt( GL_SHADING_LANGUAGE_VERSION, "GL_SHADING_LANGUAGE_VERSION" ); // Returns a version or release number for the shading language of the form OpenGLESGLSLES
assignGlobalInt( GL_EXTENSIONS, "GL_EXTENSIONS" ); // Returns a space-separated list of supported extensions to GL
/* CBuffer Data type */
assignGlobalInt( BUFFER_UNSIGNED_CHAR, "BUFFER_UNSIGNED_CHAR" ); // C type unsigned char
assignGlobalInt( BUFFER_UNSIGNED_SHORT, "BUFFER_UNSIGNED_SHORT" ); // C type unsigned short
assignGlobalInt( BUFFER_UNSIGNED_INT, "BUFFER_UNSIGNED_INT" ); // C type unsigned int
@@ -2259,8 +2298,19 @@ void luaRegister() {
assingGlobalFunction( "rlSetMatrixViewOffsetStereo", lrlglSetMatrixViewOffsetStereo );
/* OpenGL */
/* Framebuffer management. */
/* Frame Buffers. */
assingGlobalFunction( "glBlitFramebuffer", lglBlitFramebuffer );
/* State Management. */
assingGlobalFunction( "glEnable", lglEnable );
assingGlobalFunction( "glDisable", lglDisable );
assingGlobalFunction( "glStencilFunc", lglStencilFunc );
assingGlobalFunction( "glStencilFuncSeparate", lglStencilFuncSeparate );
assingGlobalFunction( "glStencilMask", lglStencilMask );
assingGlobalFunction( "glStencilMaskSeparate", lglStencilMaskSeparate );
assingGlobalFunction( "glStencilOp", lglStencilOp );
assingGlobalFunction( "glStencilOpSeparate", lglStencilOpSeparate );
/* Utility. */
assingGlobalFunction( "glGetString", lglGetString );
/* Easings */
/* Linear Easing functions. */
@@ -3301,3 +3351,8 @@ int uluaGetTableLen( lua_State* L, int index ) {
}
return i;
}
/* Accepts no arg and nil. */
bool uluaIsNil( lua_State* L, int index ) {
return lua_type( L, index ) <= 0; /* -1 is no arg(nil) and 0 is nil. */
}