DEADSOFTWARE

Add clang format
[nanogl.git] / nanoWrap.cpp
index bfeee743ba0b13f521a55ef3b620f276997348ef..8ded7b86f1619add94d252b5bf12c40064dab835 100644 (file)
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "gl.h"
 #include "glesinterface.h"
+#include "nanogl.h"
 
 #define GL_TEXTURE0_ARB                     0x84C0
 #define GL_TEXTURE1_ARB                     0x84C1
@@ -145,6 +146,8 @@ struct nanotmuState
     struct ptrstate vertex_array;                                       
     struct ptrstate color_array;
     struct ptrstate texture_coord_array;
+    struct ptrstate normal_array;
+
     };
 
 static struct nanotmuState tmuState0;
@@ -158,6 +161,7 @@ static struct nanotmuState tmuInitState =
     {4,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
     {4,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
     {4,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
+    {3,GL_FLOAT,0, NULL, GL_FALSE, GL_FALSE},
     };   
 
 static struct nanotmuState* activetmuState = &tmuState0;
@@ -205,9 +209,9 @@ struct VertexAttrib
 #endif
     };
 
-static VertexAttrib vertexattribs[8000];
+static VertexAttrib vertexattribs[60000];
 
-static GLushort indexArray[30000];
+static GLushort indexArray[50000];
 
 static GLuint vertexCount = 0;
 static GLuint indexCount = 0;
@@ -259,13 +263,87 @@ void InitGLStructs()
     arraysValid = GL_FALSE;
     }
 
+void ResetNanoState()
+{
+
+       if (tmuState0.color_array.enabled)
+       {
+               glEsImpl->glEnableClientState(GL_COLOR_ARRAY);
+       }
+       else
+       {
+               glEsImpl->glDisableClientState(GL_COLOR_ARRAY);
+       }
+
+       if (tmuState0.vertex_array.enabled)
+       {
+               glEsImpl->glEnableClientState(GL_VERTEX_ARRAY);
+       }
+       else
+       {
+               glEsImpl->glDisableClientState(GL_VERTEX_ARRAY);
+       }
+
+       if (tmuState0.texture_coord_array.enabled)
+       {
+               glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+       }
+       else
+       {
+               glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+       }
+
+    if (tmuState0.normal_array.enabled)
+    {
+        glEsImpl->glEnableClientState(GL_NORMAL_ARRAY);
+    }
+    else
+    {
+        glEsImpl->glDisableClientState(GL_NORMAL_ARRAY);
+    }
+       glEsImpl->glVertexPointer(tmuState0.vertex_array.size,
+                       tmuState0.vertex_array.type,
+                       tmuState0.vertex_array.stride,
+                       tmuState0.vertex_array.ptr);
+
+       glEsImpl->glTexCoordPointer(tmuState0.texture_coord_array.size,
+                       tmuState0.texture_coord_array.type,
+                       tmuState0.texture_coord_array.stride,
+                       tmuState0.texture_coord_array.ptr);
+
+       glEsImpl->glColorPointer(tmuState0.color_array.size,
+                       tmuState0.color_array.type,
+                       tmuState0.color_array.stride,
+                       tmuState0.color_array.ptr);
+
+    glEsImpl->glNormalPointer(
+            tmuState0.normal_array.type,
+            tmuState0.normal_array.stride,
+            tmuState0.normal_array.ptr);
+
+       glEsImpl->glMatrixMode(nanoglState.matrixmode);
+
+
+
+       glEsImpl->glColor4f (currentVertexAttrib.red, currentVertexAttrib.green, currentVertexAttrib.blue, currentVertexAttrib.alpha);
+
+       glEsImpl->glBlendFunc(nanoglState.sfactor, nanoglState.dfactor);
+
+       //glEsImpl->glBindTexture(GL_TEXTURE_2D, stackTextureState);
+
+       glEsImpl->glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, activetmuState->texture_env_mode.value);
+
+       arraysValid = GL_FALSE;
+}
 
 void FlushOnStateChange()
     {
     if (delayedttmuchange)
         {
         delayedttmuchange = GL_FALSE;
+#ifndef USE_CORE_PROFILE
         glEsImpl->glActiveTexture(delayedtmutarget);
+#endif
         }
 
     if (!vertexCount)
@@ -302,7 +380,14 @@ void FlushOnStateChange()
     ptrIndexArray = indexArray;
     useTexCoordArray = GL_FALSE;
     }
-
+void nanoGL_Flush()
+       {
+       FlushOnStateChange();
+       }
+void nanoGL_Reset()
+{
+       ResetNanoState();
+}
 void glBegin(GLenum mode)
     {
     wrapperPrimitiveMode = mode;
@@ -426,6 +511,9 @@ void glEnd(void)
         default:
             break;
         }
+               if( ptrVertexAttribArray - vertexattribs > 20000 * sizeof(VertexAttrib) ||
+                               ptrIndexArray - indexArray > 15000 * sizeof(GLushort) )
+                       FlushOnStateChange();
     }
 
 void glEnable (GLenum cap)
@@ -928,7 +1016,11 @@ void glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
 void glOrtho (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
     {
     FlushOnStateChange();
+#ifdef USE_CORE_PROFILE
+       glEsImpl->glOrtho(left,right,bottom,top, zNear,zFar);
+#else
     glEsImpl->glOrthof(left,right,bottom,top, zNear,zFar);
+#endif
     }
 
 void glMatrixMode (GLenum mode)
@@ -1005,7 +1097,11 @@ void glDepthRange(GLclampf zNear, GLclampf zFar)
         nanoglState.depth_range_far = zFar;
         }
     FlushOnStateChange();
+#ifdef USE_CORE_PROFILE
+       glEsImpl->glDepthRange(zNear, zFar);
+#else
     glEsImpl->glDepthRangef(zNear, zFar);
+#endif
     }
 
 void glDepthFunc (GLenum func)
@@ -1354,7 +1450,7 @@ void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
 
 GLenum glGetError (void)
     {
-    FlushOnStateChange();
+    //FlushOnStateChange();
     return GL_NO_ERROR;//glEsImpl->glGetError();
     }
 
@@ -1448,7 +1544,7 @@ void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indi
     if (arraysValid || 
         tmuState0.vertex_array.changed ||
         tmuState0.color_array.changed ||
-        tmuState0.texture_coord_array.changed)
+        tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed)
         {
         glEsImpl->glClientActiveTexture(GL_TEXTURE0);
         }
@@ -1484,6 +1580,21 @@ void glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indi
                                  tmuState0.color_array.ptr);
         tmuState0.color_array.changed = GL_FALSE;
         }
+    if (arraysValid || tmuState0.normal_array.changed)
+        {
+        if (tmuState0.normal_array.enabled)
+            {
+            glEsImpl->glEnableClientState(GL_NORMAL_ARRAY);
+            }
+        else
+            {
+            glEsImpl->glDisableClientState(GL_NORMAL_ARRAY);
+            }
+        glEsImpl->glNormalPointer(tmuState0.normal_array.type,
+                                 tmuState0.normal_array.stride,
+                                 tmuState0.normal_array.ptr);
+        tmuState0.normal_array.changed = GL_FALSE;
+        }
     if (arraysValid || tmuState0.texture_coord_array.changed)
         {
         tmuState0.texture_coord_array.changed = GL_FALSE;
@@ -1556,6 +1667,15 @@ void glEnableClientState(GLenum  array)
             clientstate->color_array.enabled = GL_TRUE;
             clientstate->color_array.changed = GL_TRUE;
 
+            break;
+        case GL_NORMAL_ARRAY:
+            if (clientstate->normal_array.enabled)
+                {
+                return;
+                }
+            clientstate->normal_array.enabled = GL_TRUE;
+            clientstate->normal_array.changed = GL_TRUE;
+
             break;
         case GL_TEXTURE_COORD_ARRAY:
             if (clientstate->texture_coord_array.enabled)
@@ -1602,6 +1722,15 @@ void glDisableClientState(GLenum  array)
             clientstate->color_array.enabled = GL_FALSE;
             clientstate->color_array.changed = GL_TRUE;
 
+            break;
+        case GL_NORMAL_ARRAY:
+            if (!clientstate->normal_array.enabled)
+                {
+                return;
+                }
+            clientstate->normal_array.enabled = GL_FALSE;
+            clientstate->normal_array.changed = GL_TRUE;
+
             break;
         case GL_TEXTURE_COORD_ARRAY:
             if (!clientstate->texture_coord_array.enabled)
@@ -1669,6 +1798,23 @@ void glColorPointer( GLint size,  GLenum type,  GLsizei stride,  const GLvoid *p
     tmuState0.color_array.ptr  = (GLvoid*)pointer;
     tmuState0.color_array.changed = GL_TRUE;
     }
+
+void glNormalPointer( GLenum type,  GLsizei stride,  const GLvoid *pointer )
+    {
+    int size = 0;
+    if (tmuState0.normal_array.size == size &&
+        tmuState0.normal_array.stride == stride &&
+        tmuState0.normal_array.type == type &&
+        tmuState0.normal_array.ptr == pointer)
+        {
+        return;
+        }
+    tmuState0.normal_array.size = size;
+    tmuState0.normal_array.stride = stride;
+    tmuState0.normal_array.type = type;
+    tmuState0.normal_array.ptr  = (GLvoid*)pointer;
+    tmuState0.normal_array.changed = GL_TRUE;
+    }
 void glPolygonOffset( GLfloat factor, GLfloat units ) 
     {
     FlushOnStateChange();
@@ -1696,11 +1842,11 @@ void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
 #endif
 
 /* Vladimir  */
-void glDrawArrays( GLenum mode, int first, int count)
+/*void glDrawArrays( GLenum mode, int first, int count)
 {
     FlushOnStateChange();
     glEsImpl->glDrawArrays(mode, first , count);
-}
+}*/
 void glMultMatrixf (const GLfloat *m)
 {
     FlushOnStateChange();
@@ -1774,10 +1920,203 @@ void glFrontFace (GLenum mode)
        FlushOnStateChange();
        glEsImpl->glFrontFace(mode);
 }
+// End Vladimir
+
+void glTexEnvi (GLenum target, GLenum pname, GLint param)
+    {
+    if (target == GL_TEXTURE_ENV)
+        {
+        if (pname == GL_TEXTURE_ENV_MODE)
+            {
+            if (param == activetmuState->texture_env_mode.value)
+                {
+                return;
+                }
+            else
+                {
+                FlushOnStateChange();
+                glEsImpl->glTexEnvi(target, pname, param);
+                activetmuState->texture_env_mode.value = param;
+                return;
+                }
+            }
+        }
+    FlushOnStateChange();
+    glEsImpl->glTexEnvi(target, pname, param);
+    }
+
+#ifdef __MULTITEXTURE_SUPPORT__
+void glMultiTexCoord3fARB(GLenum a, GLfloat b, GLfloat c, GLfloat)
+{
+       return glMultiTexCoord2fARB(a, b, c);
+}
+
+void glMultiTexCoord2f(GLenum, GLfloat, GLfloat)
+{
 
+}
+#endif
+void glDrawArrays( GLenum mode, GLint first, GLsizei count )
+       {
+       // ensure that all primitives specified between glBegin/glEnd pairs
+       // are rendered first, and that we have correct tmu in use..
+       if( mode == GL_QUADS ) mode = GL_TRIANGLE_FAN;
+       FlushOnStateChange();
+       // setup correct vertex/color/texcoord pointers
+       if (arraysValid ||
+               tmuState0.vertex_array.changed ||
+               tmuState0.color_array.changed ||
+               tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed)
+               {
+               glEsImpl->glClientActiveTexture(GL_TEXTURE0);
+               }
+       if (arraysValid || tmuState0.vertex_array.changed)
+               {
+               if (tmuState0.vertex_array.enabled)
+                       {
+                       glEsImpl->glEnableClientState(GL_VERTEX_ARRAY);
+                       }
+               else
+                       {
+                       glEsImpl->glDisableClientState(GL_VERTEX_ARRAY);
+                       }
+               glEsImpl->glVertexPointer(tmuState0.vertex_array.size,
+                                                                 tmuState0.vertex_array.type,
+                                                                 tmuState0.vertex_array.stride,
+                                                                 tmuState0.vertex_array.ptr);
+               tmuState0.vertex_array.changed = GL_FALSE;
+               }
+       if (arraysValid || tmuState0.color_array.changed)
+               {
+               if (tmuState0.color_array.enabled)
+                       {
+                       glEsImpl->glEnableClientState(GL_COLOR_ARRAY);
+                       }
+               else
+                       {
+                       glEsImpl->glDisableClientState(GL_COLOR_ARRAY);
+                       }
+               glEsImpl->glColorPointer(tmuState0.color_array.size,
+                                                                tmuState0.color_array.type,
+                                                                tmuState0.color_array.stride,
+                                                                tmuState0.color_array.ptr);
+               tmuState0.color_array.changed = GL_FALSE;
+               }
+       if (arraysValid || tmuState0.normal_array.changed)
+               {
+               if (tmuState0.normal_array.enabled)
+                       {
+                       glEsImpl->glEnableClientState(GL_NORMAL_ARRAY);
+                       }
+               else
+                       {
+                       glEsImpl->glDisableClientState(GL_NORMAL_ARRAY);
+                       }
+               glEsImpl->glNormalPointer(tmuState0.normal_array.type,
+                                                                tmuState0.normal_array.stride,
+                                                                tmuState0.normal_array.ptr);
+               tmuState0.normal_array.changed = GL_FALSE;
+               }
+       if (arraysValid || tmuState0.texture_coord_array.changed)
+               {
+               tmuState0.texture_coord_array.changed = GL_FALSE;
+               if (tmuState0.texture_coord_array.enabled)
+                       {
+                       glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+                       }
+               else
+                       {
+                       glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+                       }
+               glEsImpl->glTexCoordPointer(tmuState0.texture_coord_array.size,
+                                                                               tmuState0.texture_coord_array.type,
+                                                                               tmuState0.texture_coord_array.stride,
+                                                                               tmuState0.texture_coord_array.ptr);
+               }
+
+       if (arraysValid || tmuState1.texture_coord_array.changed)
+               {
+               tmuState1.texture_coord_array.changed = GL_FALSE;
+               glEsImpl->glClientActiveTexture(GL_TEXTURE1);
+               if (tmuState1.texture_coord_array.enabled)
+                       {
+                       glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+                       }
+               else
+                       {
+                       glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+                       }
+               glEsImpl->glTexCoordPointer(tmuState1.texture_coord_array.size,
+                                                                               tmuState1.texture_coord_array.type,
+                                                                               tmuState1.texture_coord_array.stride,
+                                                                               tmuState1.texture_coord_array.ptr);
+               }
+
+       arraysValid = GL_FALSE;
+       glEsImpl->glDrawArrays(mode, first, count);
+       }
+/*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr)
+{
+    glEsImpl->glNormalPointer( type, stride, ptr );
+}*/
 
+void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
+{
+    FlushOnStateChange();
+    glEsImpl->glCopyTexSubImage2D( target, level, xoffset, yoffset, x, y, width, height );
+}
 
-// End Vladimir
+void glGenFramebuffers (GLsizei n, GLuint* framebuffers)
+{
+    FlushOnStateChange();
+    glEsImpl->glGenFramebuffers( n, framebuffers );
+}
 
 
+void glGenRenderbuffers( GLsizei n, GLuint* renderbuffers )
+{
+    FlushOnStateChange();
+       glEsImpl->glGenRenderbuffers( n, renderbuffers );
+}
+
+void glBindRenderbuffer(GLenum target, GLuint renderbuffer)
+{
+    FlushOnStateChange();
+    glEsImpl->glBindRenderbuffer( target, renderbuffer );
+}
+
+void glBindFramebuffer(GLenum target, GLuint framebuffer)\
+{
+    FlushOnStateChange();
+    glEsImpl->glBindFramebuffer( target, framebuffer );
+}
+
+void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
+{
+    FlushOnStateChange();
+    glEsImpl->glFramebufferRenderbuffer( target, attachment, renderbuffertarget, renderbuffer );
+}
+
+void glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
+{
+    FlushOnStateChange();
+    glEsImpl->glDeleteFramebuffers(n, framebuffers);
+}
+
+void glDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
+{
+    FlushOnStateChange();
+    glEsImpl->glDeleteRenderbuffers( n, renderbuffers );
+}
+void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
+{
+    FlushOnStateChange();
+    glEsImpl->glFramebufferTexture2D(target, attachment,textarget,texture,level);
+}
+
+void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
+{
+    FlushOnStateChange();
+    glEsImpl->glRenderbufferStorage(target, internalformat, width, height );
+}