From: DeaDDooMER Date: Tue, 20 Feb 2018 20:58:12 +0000 (+0300) Subject: glIsEnabled uses interanl structures, added glPushAttrib/glPopAttrib (not fully imple... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;ds=inline;p=nanogl.git glIsEnabled uses interanl structures, added glPushAttrib/glPopAttrib (not fully implemented) --- diff --git a/GL/gl.h b/GL/gl.h index 9978144..c8a34a0 100644 --- a/GL/gl.h +++ b/GL/gl.h @@ -736,7 +736,9 @@ void glBufferDataARB( GLuint target, GLuint size, void *buffer, GLuint type ); void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buffer ); -GLboolean glIsEnabled(GLenum cap); +GLboolean glIsEnabled( GLenum cap ); +void glPushAttrib( GLbitfield mask ); +void glPopAttrib( void ); #ifdef __cplusplus } diff --git a/nanoWrap.cpp b/nanoWrap.cpp index 9cf8c7c..62e37ad 100644 --- a/nanoWrap.cpp +++ b/nanoWrap.cpp @@ -246,6 +246,64 @@ static GLboolean arraysValid = GL_FALSE; static GLboolean skipnanogl; +#define STACK_ATTRIB_ENABLE_BIT_LEN (sizeof(stackAttribEnableBit) / sizeof(stackAttribEnableBit[0])) +static const GLenum stackAttribEnableBit[] = +{ + GL_ALPHA_TEST, + GL_BLEND, + GL_CLIP_PLANE0, + GL_CLIP_PLANE1, + GL_CLIP_PLANE2, + GL_CLIP_PLANE3, + GL_CLIP_PLANE4, + GL_CLIP_PLANE5, + GL_COLOR_MATERIAL, + GL_CULL_FACE, + GL_DEPTH_TEST, + GL_DITHER, + GL_FOG, + GL_LIGHT0, + GL_LIGHT1, + GL_LIGHT2, + GL_LIGHT3, + GL_LIGHT4, + GL_LIGHT5, + GL_LIGHT6, + GL_LIGHT7, + GL_LIGHTING, + GL_LINE_SMOOTH, + GL_COLOR_LOGIC_OP, + GL_MULTISAMPLE, + GL_NORMALIZE, + GL_POINT_SMOOTH, + GL_POLYGON_OFFSET_LINE, + GL_POLYGON_OFFSET_FILL, + GL_POLYGON_OFFSET_POINT, + GL_POLYGON_SMOOTH, + GL_POLYGON_STIPPLE, + GL_SAMPLE_ALPHA_TO_COVERAGE, + GL_SAMPLE_ALPHA_TO_ONE, + GL_SAMPLE_COVERAGE, + GL_SCISSOR_TEST, + GL_STENCIL_TEST, + GL_TEXTURE_1D, + GL_TEXTURE_2D, + GL_TEXTURE_GEN_S, + GL_TEXTURE_GEN_T, + GL_TEXTURE_GEN_R, + GL_TEXTURE_GEN_Q, +}; + +#define MAX_ATTRIB_STACK 16 +struct attribStore +{ + GLbitfield mask; + GLboolean enable[STACK_ATTRIB_ENABLE_BIT_LEN]; +}; + +static struct attribStore attribStack[MAX_ATTRIB_STACK]; +static int attribStackCount = 0; + void InitGLStructs( ) { ptrVertexAttribArray = vertexattribs; @@ -269,6 +327,9 @@ void InitGLStructs( ) vertexMark = 0; indexbase = 0; arraysValid = GL_FALSE; + + memset(attribStack, 0, sizeof( struct attribStore )); + attribStackCount = 0; } void ResetNanoState( ) @@ -342,6 +403,9 @@ void ResetNanoState( ) arraysValid = GL_FALSE; skipnanogl = GL_FALSE; + + memset(attribStack, 0, sizeof( struct attribStore )); + attribStackCount = 0; } void FlushOnStateChange( ) @@ -2561,3 +2625,146 @@ void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buff { glEsImpl->glBufferSubData( target, offset, size, buffer ); } + +GLboolean glIsEnabled(GLenum cap) +{ + FlushOnStateChange( ); + + if( skipnanogl ) + { + return glEsImpl->glIsEnabled(cap); + } + + switch ( cap ) + { + case GL_ALPHA_TEST: + return nanoglState.alpha_test; + case GL_BLEND: + return nanoglState.blend; + case GL_COLOR_LOGIC_OP: + return nanoglState.color_logic_op; + case GL_COLOR_MATERIAL: + return nanoglState.color_material; + case GL_CULL_FACE: + return nanoglState.cull_face; + case GL_DEPTH_TEST: + return nanoglState.depth_test; + case GL_DITHER: + return nanoglState.dither; + case GL_FOG: + return nanoglState.fog; + case GL_LIGHT0: + return nanoglState.light0; + case GL_LIGHT1: + return nanoglState.light1; + case GL_LIGHT2: + return nanoglState.light2; + case GL_LIGHT3: + return nanoglState.light3; + case GL_LIGHT4: + return nanoglState.light4; + case GL_LIGHT5: + return nanoglState.light5; + case GL_LIGHT6: + return nanoglState.light6; + case GL_LIGHT7: + return nanoglState.light7; + case GL_LIGHTING: + return nanoglState.lighting; + case GL_LINE_SMOOTH: + return nanoglState.line_smooth; + case GL_MULTISAMPLE: + return nanoglState.multisample; + case GL_NORMALIZE: + return nanoglState.normalize; + case GL_POLYGON_OFFSET_FILL: + return nanoglState.polygon_offset_fill; + case GL_RESCALE_NORMAL: + return nanoglState.rescale_normal; + case GL_SAMPLE_ALPHA_TO_COVERAGE: + return nanoglState.sample_alpha_to_coverage; + case GL_SAMPLE_ALPHA_TO_ONE: + return nanoglState.sample_alpha_to_one; + case GL_SAMPLE_COVERAGE: + return nanoglState.sample_coverage; + case GL_SCISSOR_TEST: + return nanoglState.scissor_test; + case GL_STENCIL_TEST: + return nanoglState.stencil_test; + case GL_TEXTURE_2D: + return activetmuState->texture_2d.value; + default: + return glIsEnabled(cap); + } +} + +void glPushAttrib(GLbitfield mask) +{ + FlushOnStateChange( ); + + if( (attribStackCount < 0) || (attribStackCount > MAX_ATTRIB_STACK) ) + { + return; + } + + attribStack[attribStackCount].mask = mask; + + if( mask & GL_ENABLE_BIT ) + { + for(int i = 0; i < STACK_ATTRIB_ENABLE_BIT_LEN; i++) + { + attribStack[attribStackCount].enable[i] = glIsEnabled(stackAttribEnableBit[i]); + } + } + + if( mask & GL_COLOR_BUFFER_BIT ) + { + // TODO + } + + if( mask & GL_CURRENT_BIT ) + { + // TODO + } + + attribStackCount += 1; +} + +void glPopAttrib() +{ + FlushOnStateChange( ); + + attribStackCount -= 1; + if((attribStackCount < 0) || (attribStackCount > MAX_ATTRIB_STACK)) + { + attribStackCount += 1; + return; + } + + GLbitfield mask = attribStack[attribStackCount].mask; + + if( mask & GL_ENABLE_BIT ) + { + for(int i = 0; i < STACK_ATTRIB_ENABLE_BIT_LEN; i++) + { + if( attribStack[attribStackCount].enable[i] ) + { + glEnable(stackAttribEnableBit[i]); + } + else + { + glDisable(stackAttribEnableBit[i]); + } + } + } + + if( mask & GL_COLOR_BUFFER_BIT ) + { + // TODO + } + + if( mask & GL_CURRENT_BIT ) + { + // TODO + } +}