ecere/gfx: Fixes to build with Emscripten
authorJerome St-Louis <jerome@ecere.com>
Thu, 10 Mar 2016 16:41:01 +0000 (11:41 -0500)
committerJerome St-Louis <jerome@ecere.com>
Sat, 11 Jun 2016 07:07:09 +0000 (03:07 -0400)
ecere/ecere.epj
ecere/src/gfx/drivers/gl3/glab.ec
ecere/src/gfx/drivers/gl3/matrixStack.ec
ecere/src/gfx/newFonts/cc/cpuconfig.h
ecere/src/gfx/newFonts/cc/mmbitmap.c
ecere/src/gfx/newFonts/drawManager.ec
ecere/src/gfx/newFonts/fontRenderer.ec
ecere/src/gfx/newFonts/textureManager.ec
ecere/src/gui/GuiApplication.ec

index d489a3c..a2968ef 100644 (file)
@@ -1100,6 +1100,12 @@ if distributed with the Ecere SDK Windows installer.
                                        "Options" : {
                                           "ExcludeFromBuild" : false
                                        }
+                                    },
+                                    {
+                                       "Name" : "Emscripten",
+                                       "Options" : {
+                                          "ExcludeFromBuild" : false
+                                       }
                                     }
                                  ]
                               },
@@ -1122,7 +1128,7 @@ if distributed with the Ecere SDK Windows installer.
                                     {
                                        "Name" : "Emscripten",
                                        "Options" : {
-                                          "ExcludeFromBuild" : false
+                                          "ExcludeFromBuild" : true
                                        }
                                     }
                                  ]
index ef28267..dc913fe 100644 (file)
@@ -28,6 +28,7 @@
 
 import "immediate"
 import "Display"
+import "OpenGLDisplayDriver"
 
 // Kept public for now
 public void GLABDeleteBuffers(int count, GLAB * buffers)
index 27a45c8..355536e 100644 (file)
@@ -111,6 +111,7 @@ public void glmsLoadMatrix(Matrix matrix)
       (float)matrix.m[3][0], (float)matrix.m[3][1], (float)matrix.m[3][2], (float)matrix.m[3][3]
    };
 #ifdef SHADERS
+      memcpy(matrixStack[curStack][matrixIndex[curStack]].array, matrix.array, sizeof(Matrix));
       shader_LoadMatrixf((MatrixMode) (0x1700 + curStack), m);
 #else
       glLoadMatrixf(m);
@@ -141,6 +142,19 @@ public void glmsPopMatrix()
    }
 }
 
+public void glmsLoadMatrixf(float * i)
+{
+   double m[16] =
+   {
+      i[0*4+0], i[0*4+1], i[0*4+2], i[0*4+3],
+      i[1*4+0], i[1*4+1], i[1*4+2], i[1*4+3],
+      i[2*4+0], i[2*4+1], i[2*4+2], i[2*4+3],
+      i[3*4+0], i[3*4+1], i[3*4+2], i[3*4+3]
+   };
+   memcpy(matrixStack[curStack][matrixIndex[curStack]].array, i, 16*sizeof(double));
+   LoadCurMatrix();
+}
+
 public void glmsLoadMatrixd(double * i)
 {
    memcpy(matrixStack[curStack][matrixIndex[curStack]].array, i, sizeof(Matrix));
index 4d5b280..26f550a 100644 (file)
    #define CPUCONF_LONG_SIZESHIFT ((sizeof(long) == 2) ? 2 : 3)
    #define CPUCONF_LONG_BITS (sizeof(long) * 8)
 #else
+
+#if !defined(__EMSCRIPTEN__)
    #define CPUCONF_ARCH_IA32
+#endif
 
    #define CPUCONF_INTPTR_BITS (32)
    #define CPUCONF_POINTER_BITS (32)
index dcd2bf0..fb18510 100644 (file)
@@ -40,7 +40,11 @@ int mmBitMapInit( mmBitMap *bitmap, size_t entrycount, int initvalue )
   bitmap->map = 0;
   if( mapsize )
   {
+#ifdef MM_ATOMIC_SUPPORT
     if( !( bitmap->map = malloc( mapsize * sizeof(mmAtomicL) ) ) )
+#else
+    if( !( bitmap->map = malloc( mapsize * sizeof(long) ) ) )
+#endif
       return 0;
   }
   bitmap->mapsize = mapsize;
index 9e87e36..72bdcca 100644 (file)
@@ -10,6 +10,11 @@ import "OpenGLDisplayDriver"
    #define SHADERS
 #endif
 
+#if defined(__EMSCRIPTEN__)
+   #define ES2
+   #include <GLES2/gl2.h>
+#endif
+
 #if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
 #  if defined(SHADERS)
 //#     include "gl_core_3_3.h"
@@ -66,6 +71,7 @@ import "OpenGLDisplayDriver"
    #undef glVertex3fv
 
    #undef glLoadMatrixd
+   #undef glLoadMatrixf
    #undef glMultMatrixd
    #undef glFrustum
    #undef glOrtho
@@ -103,6 +109,7 @@ import "OpenGLDisplayDriver"
    #define glVertex3fv           glimtkVertex3fv
 
    #define glLoadMatrixd         glmsLoadMatrixd
+   #define glLoadMatrixf         glmsLoadMatrixf
    #define glMultMatrixd         glmsMultMatrixd
    #define glFrustum             glmsFrustum
    #define glOrtho               glmsOrtho
@@ -658,6 +665,7 @@ public class DrawManager
       return program;
    }
 
+#if !defined(__EMSCRIPTEN__)
    static void flushRenderDrawBufferArchaic( DMDrawBuffer drawBuffer, DMProgram program, int vertexCount )
    {
       glEnable( GL_TEXTURE_2D );
@@ -886,6 +894,7 @@ public class DrawManager
 
      }
    }
+#endif
 
    void flushRenderDrawBuffer( DMDrawBuffer drawBuffer, DMProgram program, int vertexCount )
    {
@@ -956,7 +965,10 @@ public class DrawManager
          drawBuffer = &this.drawBuffer[this.drawBufferIndex];
          this.drawBufferIndex = ( this.drawBufferIndex + 1 ) % DM_CONTEXT_DRAW_BUFFER_COUNT;
          glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
+
+#if !defined(__EMSCRIPTEN__)
          vboVertex = glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
+#endif
          vertexcount = 0;
 
          glActiveTexture( GL_TEXTURE0 );
@@ -993,7 +1005,9 @@ public class DrawManager
           {
             if( vertexcount )
             {
+#if !defined(__EMSCRIPTEN__)
               glUnmapBuffer( GL_ARRAY_BUFFER );
+#endif
               // Flush font manager texture updates
               flush();
 
@@ -1002,7 +1016,9 @@ public class DrawManager
               drawBuffer = &this.drawBuffer[this.drawBufferIndex];
               this.drawBufferIndex = ( this.drawBufferIndex + 1 ) % DM_CONTEXT_DRAW_BUFFER_COUNT;
               glBindBuffer( GL_ARRAY_BUFFER, drawBuffer->vbo );
+#if !defined(__EMSCRIPTEN__)
               vboVertex = glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
+#endif
               vertexcount = 0;
             }
 
@@ -1109,7 +1125,9 @@ public class DrawManager
           vertexcount += 6;
         }
 
+#if !defined(__EMSCRIPTEN__)
         glUnmapBuffer( GL_ARRAY_BUFFER );
+#endif
         // Flush font manager texture updates
         flush();
         // Render buffered images
@@ -1214,10 +1232,10 @@ public:
 
       // Save OpenGL state
       // FIXME: no glPushAttrib() in core profile
-//#ifndef SHADERS
+#if !defined(__EMSCRIPTEN__)
       glPushClientAttrib( GL_CLIENT_ALL_ATTRIB_BITS );
       glPushAttrib( GL_ALL_ATTRIB_BITS );
-//#endif
+#endif
 
       // Prepare rendering pass
       matrixOrtho( matrix, 0.0, (float)viewportwidth, (float)viewportheight, 0.0, -1.0f, 1.0 );
@@ -1236,10 +1254,10 @@ public:
 
       if(flags.prehistoricOpenGL)
       {
-         glMatrixMode(GL_PROJECTION);
+         glMatrixMode(projection);
          glLoadMatrixf(matrix);
 
-         glMatrixMode(GL_MODELVIEW);
+         glMatrixMode(modelView);
          glLoadIdentity();
          glScalef(4,4,4);
       }
@@ -1389,9 +1407,11 @@ public:
 
    void flushImages( )
    {
+#if !defined(__EMSCRIPTEN__)
      if( flags.prehistoricOpenGL )
        flushDrawImagesArchaic( );
      else
+#endif
        flushDrawImages( );
 
      if(vboAvailable)
@@ -1401,10 +1421,10 @@ public:
          glUseProgram( prevProgram );
       // Restore OpenGL state
       // FIXME: no glPushAttrib() in core profile
-//#ifndef SHADERS
+#if !defined(__EMSCRIPTEN__)
       glPopAttrib();
       glPopClientAttrib();
-//#endif
+#endif
    }
 
    void drawBarrier( )
index 8acd718..77bba38 100644 (file)
@@ -23,6 +23,11 @@ import "Color"
 #  endif
 #endif
 
+#if defined(__EMSCRIPTEN__)
+   #define ES2
+   #include <GLES2/gl2.h>
+#endif
+
 #include "cc.h"
 #include "mm.h"
 
@@ -106,7 +111,7 @@ public:
    {
      if(texture)
      {
-#ifdef SHADERS
+#if defined(SHADERS) && !defined(__EMSCRIPTEN__)
         int glformat = GL_RED;
 #else
         int glformat = GL_ALPHA;
@@ -115,28 +120,32 @@ public:
         int h = rect[3] - rect[1];
 
         if( channelcount == 1 );
+#if !defined(__EMSCRIPTEN__)
         else if( channelcount == 2 )
           glformat = GL_RG;
+#endif
         else if( channelcount == 3 )
           glformat = GL_RGB;
         else if( channelcount == 4 )
           glformat = GL_RGBA;
 
         // FIXME: no glPushAttrib() in core profile
-//#ifndef SHADERS
+#if !defined(__EMSCRIPTEN__)
         glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
         glPushAttrib( GL_TEXTURE_BIT );
-//#endif
+#endif
         glBindTexture( GL_TEXTURE_2D, texture.glTex );
         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+#if !defined(__EMSCRIPTEN__)
         glPixelStorei( GL_UNPACK_ROW_LENGTH, textureWidth );
         glPixelStorei( GL_UNPACK_SKIP_PIXELS, rect[0] );
         glPixelStorei( GL_UNPACK_SKIP_ROWS, rect[1] );
+#endif
         glTexSubImage2D( GL_TEXTURE_2D, 0, rect[0], rect[1], w, h, glformat, GL_UNSIGNED_BYTE, data );
-//#ifndef SHADERS
+#if !defined(__EMSCRIPTEN__)
         glPopAttrib();
         glPopClientAttrib();
-//#endif
+#endif
 
       #if 0
         IMGImage image;
index a441b31..d485be9 100644 (file)
@@ -17,6 +17,11 @@ import "instance"
 #  endif
 #endif
 
+#if defined(__EMSCRIPTEN__)
+   #define ES2
+   #include <GLES2/gl2.h>
+#endif
+
 // TOFIX:
 int GL_ARB_texture_non_power_of_two = 1;
 int GL_EXT_texture_filter_anisotropic = 1;
@@ -65,14 +70,16 @@ public:
 
      if( image.format.bytesPerPixel == 1 )
      {
-#ifdef SHADERS
+#if defined(SHADERS) && !defined(__EMSCRIPTEN__)
        glformat = GL_RED;
 #else
        glformat = GL_ALPHA;
 #endif
      }
+#if defined(SHADERS) && !defined(__EMSCRIPTEN__)
      else if( image.format.bytesPerPixel == 2 )
        glformat = GL_RG;
+#endif
      else if( image.format.bytesPerPixel == 3 )
        glformat = GL_RGB;
      else if( image.format.bytesPerPixel == 4 )
index ddc23b6..e5676a3 100644 (file)
@@ -1221,7 +1221,7 @@ public:
          for(link = class(Interface).derivatives.first; link; link = link.next)
          {
             bool foundDriver = false;
-            int c, numDrivers;
+            int c, numDrivers = 0;
             const char ** graphicsDrivers;
             inter = link.data;
 
@@ -1491,9 +1491,10 @@ public:
 
    int UnlockEx(void)
    {
-      int count = lockMutex.owningThread == GetCurrentThreadID() ? lockMutex.lockCount : 0;
+      int count;
 #if !defined(__EMSCRIPTEN__)
       int i;
+      count = lockMutex.owningThread == GetCurrentThreadID() ? lockMutex.lockCount : 0
       for(i = 0; i < count; i++)
       {
 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)