ecere/gfx/newFonts: 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>
Wed, 2 Nov 2016 16:32:45 +0000 (12:32 -0400)
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

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 330a022..4801546 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
@@ -654,6 +661,7 @@ public class DrawManager
       return program;
    }
 
+#if !defined(__EMSCRIPTEN__)
    static void flushRenderDrawBufferArchaic( DMDrawBuffer drawBuffer, DMProgram program, int vertexCount )
    {
       glEnable( GL_TEXTURE_2D );
@@ -882,6 +890,7 @@ public class DrawManager
 
      }
    }
+#endif
 
    void flushRenderDrawBuffer( DMDrawBuffer drawBuffer, DMProgram program, int vertexCount )
    {
@@ -952,7 +961,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 );
@@ -989,7 +1001,9 @@ public class DrawManager
           {
             if( vertexcount )
             {
+#if !defined(__EMSCRIPTEN__)
               glUnmapBuffer( GL_ARRAY_BUFFER );
+#endif
               // Flush font manager texture updates
               flush();
 
@@ -998,7 +1012,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;
             }
 
@@ -1105,7 +1121,9 @@ public class DrawManager
           vertexcount += 6;
         }
 
+#if !defined(__EMSCRIPTEN__)
         glUnmapBuffer( GL_ARRAY_BUFFER );
+#endif
         // Flush font manager texture updates
         flush();
         // Render buffered images
@@ -1210,10 +1228,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 );
@@ -1232,10 +1250,10 @@ public:
 
       if(flags.prehistoricOpenGL)
       {
-         glMatrixMode(GL_PROJECTION);
+         glMatrixMode(MatrixMode::projection);
          glLoadMatrixf(matrix);
 
-         glMatrixMode(GL_MODELVIEW);
+         glMatrixMode(MatrixMode::modelView);
          glLoadIdentity();
          glScalef(4,4,4);
       }
@@ -1385,9 +1403,11 @@ public:
 
    void flushImages( )
    {
+#if !defined(__EMSCRIPTEN__)
      if( flags.prehistoricOpenGL )
        flushDrawImagesArchaic( );
      else
+#endif
        flushDrawImages( );
 
      if(vboAvailable)
@@ -1397,10 +1417,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 )