DEADSOFTWARE

glIsEnabled uses interanl structures, added glPushAttrib/glPopAttrib (not fully imple... master
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 20 Feb 2018 20:58:12 +0000 (23:58 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 20 Feb 2018 20:58:12 +0000 (23:58 +0300)
GL/gl.h
nanoWrap.cpp

diff --git a/GL/gl.h b/GL/gl.h
index 997814496bb4f1e111ed1300b752996e58977a0f..c8a34a008a437f09c8f0a78642b859c602c16ffd 100644 (file)
--- 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 );
 
 
 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
 }
 
 #ifdef __cplusplus
 }
index 9cf8c7c2055bc96645be154220b88f2da5c6119c..62e37ad3382b9be144ba24a03a1b5324629a60c9 100644 (file)
@@ -246,6 +246,64 @@ static GLboolean arraysValid = GL_FALSE;
 
 static GLboolean skipnanogl;
 
 
 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;
 void InitGLStructs( )
 {
        ptrVertexAttribArray     = vertexattribs;
@@ -269,6 +327,9 @@ void InitGLStructs( )
        vertexMark           = 0;
        indexbase            = 0;
        arraysValid          = GL_FALSE;
        vertexMark           = 0;
        indexbase            = 0;
        arraysValid          = GL_FALSE;
+
+       memset(attribStack, 0, sizeof( struct attribStore ));
+       attribStackCount = 0;
 }
 
 void ResetNanoState( )
 }
 
 void ResetNanoState( )
@@ -342,6 +403,9 @@ void ResetNanoState( )
 
        arraysValid = GL_FALSE;
        skipnanogl = GL_FALSE;
 
        arraysValid = GL_FALSE;
        skipnanogl = GL_FALSE;
+
+       memset(attribStack, 0, sizeof( struct attribStore ));
+       attribStackCount = 0;
 }
 
 void FlushOnStateChange( )
 }
 
 void FlushOnStateChange( )
@@ -2561,3 +2625,146 @@ void glBufferSubDataARB( GLuint target, GLsizei offset, GLsizei size, void *buff
 {
        glEsImpl->glBufferSubData( target, offset, size, buffer );
 }
 {
        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
+       }
+}