ecere/gfx/OpenGL: Standardized on _GLES for ES 1.1 and _GLES2 for ES 2.0
authorJerome St-Louis <jerome@ecere.com>
Fri, 1 Apr 2016 22:10:47 +0000 (18:10 -0400)
committerJerome St-Louis <jerome@ecere.com>
Sun, 3 Jul 2016 08:29:50 +0000 (04:29 -0400)
- Fixed bug in matrixStack's glLoadMatrix
- Fixed shading.ec compilation with ECERE_NO3D

ecere/src/gfx/3D/models/Object3DSFormat.ec
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/gfx/drivers/gl3/glab.ec
ecere/src/gfx/drivers/gl3/matrixStack.ec
ecere/src/gfx/drivers/gl3/shading.ec
samples/guiAndGfx/mandelbrot/mandelbrot.epj

index a5e6834..80ccae2 100644 (file)
@@ -3,14 +3,16 @@ namespace gfx3D::models;
 import "Object"
 
 #if defined(__EMSCRIPTEN__)
-#define ES2
+#if !defined(_GLES2)
+#define _GLES2
+#endif
 #endif
 
 #if defined(__ANDROID__) || defined(__ODROID__)
-#define ES1_1
+#define _GLES
 #endif
 
-#if !defined(ES1_1) && !defined(ES2)
+#if !defined(_GLES) && !defined(_GLES2)
 #define USE_32_BIT_INDICES true
 #define indicesMember indices32
 #define uintindex uint32
index 5baefff..7d5d170 100644 (file)
@@ -2,9 +2,7 @@
 
 namespace gfx::drivers;
 
-#if defined(_GLES)
-   #define ES1_1
-#else
+#if !defined(_GLES)  // OpenGL ES 1
    #define SHADERS
 #endif
 
@@ -112,8 +110,8 @@ import "shading"
    #endif
 
    #if defined(__ANDROID__) || defined(__ODROID__)
-      #if defined(__ODROID__) && !defined(ES1_1)
-         #define ES1_1
+      #if defined(__ODROID__) && !defined(_GLES)
+         #define _GLES
       #endif
 
       #define uint _uint
@@ -145,8 +143,10 @@ import "shading"
       #undef class
 
    #elif defined(__EMSCRIPTEN__)
-      #define ES2
-      // #define ES1_1
+#if !defined(_GLES2)
+      #define _GLES2
+#endif
+      // #define _GLES
 
       #define property _property
       #define uint _uint
@@ -307,7 +307,7 @@ private:
    #define APIENTRY
 #endif
 
-#if defined(ES1_1) || defined(ES2) || defined(SHADERS)
+#if defined(_GLES) || defined(_GLES2) || defined(SHADERS)
 
    #undef glRecti
    #undef glBegin
@@ -391,7 +391,7 @@ public void glesColorMaterial(int a, int b)
 }
 
 static GLuint stippleTexture;
-#if defined(ES1_1) || defined(ES2) || defined(SHADERS)
+#if defined(_GLES) || defined(_GLES2) || defined(SHADERS)
 static bool stippleEnabled;
 #endif
 
@@ -462,7 +462,7 @@ void glDrawPixels(int a, int b, int c, int d, void * e) { }
 static int primitiveTypes[RenderPrimitiveType] =
 {
    GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN,
-#if defined(SHADERS) || defined(ES1_1) || defined(ES2)
+#if defined(SHADERS) || defined(_GLES) || defined(_GLES2)
    GL_TRIANGLE_FAN,     // NOTE: This will only work for single quads
 #else
    GLIMTKMode::quads,
@@ -501,7 +501,7 @@ public void GLSetupLighting(bool enable)
 
 // Non OpenGL ES friendly stuff
 
-#if defined(ES1_1) || defined(ES2)
+#if defined(_GLES) || defined(_GLES2)
 
 //#undef GL_UNSIGNED_INT
 //#undef GL_DOUBLE
@@ -1689,7 +1689,7 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          oglDisplay.flipBufW = width;
          oglDisplay.flipBufH = height;
-#if defined(ES1_1) || defined(ES2)
+#if defined(_GLES) || defined(_GLES2)
          result = true;
 #else
          oglDisplay.flippingBuffer = renew oglDisplay.flippingBuffer ColorAlpha [width * height];
@@ -2228,7 +2228,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
       glColor4fv(oglSurface.foreground);
       glBegin(GL_LINES);
-#if defined(ES1_1) || defined(ES2) || defined(SHADERS)
+#if defined(_GLES) || defined(_GLES2) || defined(SHADERS)
       if(stippleEnabled)
       {
          glTexCoord2f(0.5f, 0);
@@ -2261,7 +2261,7 @@ class OpenGLDisplayDriver : DisplayDriver
       //Logf("Rectangle\n");
 
       glColor4fv(oglSurface.foreground);
-#if defined(ES1_1) || defined(ES2) || defined(SHADERS)
+#if defined(_GLES) || defined(_GLES2) || defined(SHADERS)
       if(stippleEnabled)
       {
          glBegin(GL_LINES);
@@ -2723,7 +2723,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
       if(stipple)
       {
-#if defined(ES1_1) || defined(ES2) || defined(SHADERS)
+#if defined(_GLES) || defined(_GLES2) || defined(SHADERS)
          stippleEnabled = true;
          glesLineStipple(1, (uint16)stipple);
 #else
@@ -2733,7 +2733,7 @@ class OpenGLDisplayDriver : DisplayDriver
       }
       else
       {
-#if defined(ES1_1) || defined(ES2) || defined(SHADERS)
+#if defined(_GLES) || defined(_GLES2) || defined(SHADERS)
          stippleEnabled = false;
          glMatrixMode(GL_TEXTURE);
          glLoadIdentity();
@@ -2762,7 +2762,7 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
             break;
          case fillMode:
-#if !defined(ES1_1) && !defined(ES2)
+#if !defined(_GLES) && !defined(_GLES2)
             glPolygonMode(GL_FRONT_AND_BACK, ((FillModeValue)value == solid) ? GL_FILL : GL_LINE);
 #endif
             break;
@@ -3351,7 +3351,7 @@ class OpenGLDisplayDriver : DisplayDriver
    {
       if(vboAvailable)
       {
-#if defined(ES1_1) || defined(ES2)
+#if defined(_GLES) || defined(_GLES2)
          if(indices32bit)
          {
             if(!oglIndices.buffer.buffer)
@@ -3499,7 +3499,7 @@ class OpenGLDisplayDriver : DisplayDriver
          {
             OGLIndices oglIndices = primitive->data;
             GLEAB eab = ((!display.display3D.collectingHits && oglIndices && vboAvailable) ? oglIndices.buffer : noEAB);
-#if defined(ES1_1) || defined(ES2)
+#if defined(_GLES) || defined(_GLES2)
             if(!vboAvailable && primitive->type.indices32bit)
             {
                uint16 * temp = new uint16[primitive->nIndices];
index dc913fe..b304700 100644 (file)
@@ -1,8 +1,6 @@
 // GL Array Buffer Manipulation
 
-#if defined(_GLES)
- #define ES1_1
-#else
+#if !defined(_GLES)
  #define SHADERS
 #endif
 
@@ -14,7 +12,9 @@
 #elif defined(__EMSCRIPTEN__)
    #include <GLES2/gl2.h>
 
-   #define ES2
+#if !defined(_GLES2)
+   #define _GLES2
+#endif
 
    #define GL_INT    0x1404
    #define GL_DOUBLE 0x140A
@@ -120,7 +120,7 @@ public struct GLAB
 
    void useVertTrans(uint count, int n, int type, uint stride, void * pointer)
    {
-#if defined(_GLES) || defined(ES1_1) || defined(ES2)
+#if defined(_GLES) || defined(_GLES2)
       if(glabCurArrayBuffer != ((this != null) ? buffer : 0) && vboAvailable)
          GLABBindBuffer(GL_ARRAY_BUFFER, ((this != null) ? buffer : 0));
       if(type == GL_INT)
@@ -184,7 +184,7 @@ public struct GLEAB
       {
          if(glabCurElementBuffer != ((this != null) ? buffer : 0))
             GLABBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ((this != null) ? buffer : 0));
-#if defined(_GLES) || defined(ES1_1) || defined(ES2)
+#if defined(_GLES) || defined(_GLES2)
          type = GL_UNSIGNED_SHORT;
 #endif
          glDrawElements(primType, count, type, indices);
index 355536e..6dd68fe 100644 (file)
@@ -31,6 +31,28 @@ public union Matrix
       m[0][0]=m[1][1]=m[2][2]=m[3][3]=1;
    }
 
+   void Translate(double tx, double ty, double tz)
+   {
+      Matrix tmat;
+      Matrix mat1;
+
+      FillBytesBy4(tmat, 0, sizeof(Matrix) >> 2);
+      tmat.m[0][0]=tmat.m[1][1]=tmat.m[2][2]=tmat.m[3][3]=1;
+      tmat.m[3][0]=tx; tmat.m[3][1]=ty; tmat.m[3][2]=tz;
+      mat1.Multiply(this, tmat);
+      this = mat1;
+   }
+
+   void Scale(double sx, double sy, double sz)
+   {
+      Matrix smat;
+      Matrix mat1;
+      FillBytesBy4(smat, 0, sizeof(Matrix) >> 2);
+      smat.m[0][0]=sx; smat.m[1][1]=sy; smat.m[2][2]=sz; smat.m[3][3]=1;
+      mat1.Multiply(this, smat);
+      this = mat1;
+   }
+
    void Transpose(Matrix source)
    {
       int i,j;
@@ -151,7 +173,7 @@ public void glmsLoadMatrixf(float * i)
       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));
+   memcpy(matrixStack[curStack][matrixIndex[curStack]].array, m, 16*sizeof(double));
    LoadCurMatrix();
 }
 
@@ -176,6 +198,29 @@ public void glmsOrtho( double l, double r, double b, double t, double n, double
    LoadCurMatrix();
 }
 
+public void glmsScaled( double a, double b, double c )
+{
+   Matrix m, r;
+
+   m.Identity();
+   m.Scale(a,b,c);
+   r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
+   matrixStack[curStack][matrixIndex[curStack]] = r;
+   LoadCurMatrix();
+}
+
+public void glmsTranslated( double a, double b, double c )
+{
+   Matrix m, r;
+
+   m.Identity();
+   m.Translate(a,b,c);
+   r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
+   matrixStack[curStack][matrixIndex[curStack]] = r;
+   LoadCurMatrix();
+}
+
+#if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
 public void glmsFrustum( double l, double r, double b, double t, double n, double f )
 {
    nearPlane = n;
@@ -204,7 +249,6 @@ public void glmsFrustum( double l, double r, double b, double t, double n, doubl
    }
 }
 
-#if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
 public void glmsRotated( double a, double b, double c, double d )
 {
    Quaternion q;
@@ -216,27 +260,6 @@ public void glmsRotated( double a, double b, double c, double d )
    matrixStack[curStack][matrixIndex[curStack]] = r;
    LoadCurMatrix();
 }
-public void glmsScaled( double a, double b, double c )
-{
-   Matrix m, r;
-
-   m.Identity();
-   m.Scale(a,b,c);
-   r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
-   matrixStack[curStack][matrixIndex[curStack]] = r;
-   LoadCurMatrix();
-}
-
-public void glmsTranslated( double a, double b, double c )
-{
-   Matrix m, r;
-
-   m.Identity();
-   m.Translate(a,b,c);
-   r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
-   matrixStack[curStack][matrixIndex[curStack]] = r;
-   LoadCurMatrix();
-}
 
 public void glmsMultMatrixd( double * i )
 {
index 688df00..e87a038 100644 (file)
@@ -95,6 +95,7 @@ void shader_texturing(bool on)
    glUniform1i(uTexturingOn, on);
 }
 
+#if !defined(ECERE_NO3D)
 public void shader_setMaterial(Material material, bool perVertexColor)
 {
    glUniform1i(uPerVertexColor, perVertexColor);
@@ -106,6 +107,7 @@ public void shader_setMaterial(Material material, bool perVertexColor)
    glUniform1f(uMatPower, material.power);
    glUniform1f(uMatOpacity, material.opacity);
 }
+#endif
 
 public void shader_setSimpleMaterial(ColorAlpha color)
 {
@@ -128,6 +130,7 @@ public void shader_setPerVertexColor(bool perVertexColor)
    glUniform1i(uPerVertexColor, perVertexColor);
 }
 
+#if !defined(ECERE_NO3D)
 void shader_setLight(Display display, uint id, Light light)
 {
    if(light != null)
@@ -237,6 +240,7 @@ void shader_setLight(Display display, uint id, Light light)
    else
       glUniform1i(uLightsOn[id], 0);
 }
+#endif
 
 bool loadShaders(const String vertexShaderFile, const String fragmentShaderFile)
 {
index ae8686b..b241dd3 100644 (file)
             "TargetFileName" : "mandelbrot.html",
             "Libraries" : [
                "ecereStatic",
-               "z",
-               "jpeg",
-               "png",
-               "freetype"
+               "z"
             ],
             "LibraryDirs" : [
-               "../../../ecere/obj/emscripten.linux.emscripten"
+               "../../../ecere/obj/minEmscripten.linux.emscripten"
             ],
             "FastMath" : true
          }