ecere: Fixes to build branch for Android
authorJerome St-Louis <jerome@ecere.com>
Sun, 20 Sep 2015 15:30:58 +0000 (00:30 +0900)
committerJerome St-Louis <jerome@ecere.com>
Sun, 3 Jul 2016 08:07:08 +0000 (04:07 -0400)
- Enabling SHADERS

ecere/ecere.epj
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/gfx/drivers/gl3/egl.ec
ecere/src/gfx/drivers/gl3/glab.ec
ecere/src/gfx/drivers/gl3/immediate.ec
ecere/src/gfx/drivers/gl3/matrixStack.ec
ecere/src/gfx/drivers/gl3/shading.ec

index 1aecc74..7c3c78d 100644 (file)
@@ -964,6 +964,12 @@ if distributed with the Ecere SDK Windows installer.
                                        "Options" : {
                                           "ExcludeFromBuild" : false
                                        }
+                                    },
+                                    {
+                                       "Name" : "Android",
+                                       "Options" : {
+                                          "ExcludeFromBuild" : false
+                                       }
                                     }
                                  ]
                               },
@@ -993,6 +999,12 @@ if distributed with the Ecere SDK Windows installer.
                                        "Options" : {
                                           "ExcludeFromBuild" : false
                                        }
+                                    },
+                                    {
+                                       "Name" : "Android",
+                                       "Options" : {
+                                          "ExcludeFromBuild" : false
+                                       }
                                     }
                                  ]
                               },
@@ -1022,11 +1034,27 @@ if distributed with the Ecere SDK Windows installer.
                                        "Options" : {
                                           "ExcludeFromBuild" : false
                                        }
+                                    },
+                                    {
+                                       "Name" : "Android",
+                                       "Options" : {
+                                          "ExcludeFromBuild" : false
+                                       }
                                     }
                                  ]
                               },
                               "wglDefs.h",
-                              "egl.ec",
+                              {
+                                 "FileName" : "egl.ec",
+                                 "Configurations" : [
+                                    {
+                                       "Name" : "Android",
+                                       "Options" : {
+                                          "ExcludeFromBuild" : false
+                                       }
+                                    }
+                                 ]
+                              },
                               {
                                  "FileName" : "shading.ec",
                                  "Configurations" : [
@@ -1053,6 +1081,12 @@ if distributed with the Ecere SDK Windows installer.
                                        "Options" : {
                                           "ExcludeFromBuild" : false
                                        }
+                                    },
+                                    {
+                                       "Name" : "Android",
+                                       "Options" : {
+                                          "ExcludeFromBuild" : false
+                                       }
                                     }
                                  ]
                               },
index e3d8bcc..80a3f66 100644 (file)
@@ -3,7 +3,7 @@ namespace gfx::drivers;
 #if defined(_GLES)
 #define ES1_1
 #else
-// #define SHADERS
+ #define SHADERS
 #endif
 
 #define GL_BGRA_EXT  0x80E1
@@ -16,6 +16,10 @@ namespace gfx::drivers;
 #  endif
 #endif
 
+#if defined(__ANDROID__) || defined(__ODROID__)
+import "egl"
+#endif
+
 import "glab"
 import "immediate"
 import "matrixStack"
@@ -143,12 +147,7 @@ import "shading"
    #include <GL/gl.h>
 
    //#include <GLES/gl.h>
-   //#include <EGL/egl.h>
-
    //#include <GLES2/gl.h>
-   //#include <EGL/egl.h>
-
-   //#include <GLES2/gl2.h>
    #include <GL/glfw.h>
    #include <emscripten/emscripten.h>
 
@@ -907,11 +906,53 @@ class OpenGLDisplayDriver : DisplayDriver
       }
    #elif defined(__unix__) || defined(__APPLE__)
       vboAvailable = true;
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__ODROID__)
+         #if defined(__ANDROID__)
          egl_init_display(guiApp.desktop.windowHandle);
-      #elif defined(__ODROID__)
+         #elif defined(__ODROID__)
          egl_init_display((uint)displaySystem.window);
          CheckExtensions(oglSystem);
+         #endif
+
+         // TODO: Clean this up? Needed here?
+         glEnableClientState(GL_VERTEX_ARRAY);
+         /*
+         // Initialize GL state.
+         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
+         glEnable(GL_CULL_FACE);
+         glShadeModel(GL_SMOOTH);
+         glDisable(GL_DEPTH_TEST);
+         */
+         glDisable(GL_CULL_FACE);
+         glDisable(GL_DEPTH_TEST);
+
+         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+         glEnable(GL_BLEND);
+
+         matrixStack[0][0].Identity();
+         matrixStack[1][0].Identity();
+         matrixStack[2][0].Identity();
+
+         glmsMatrixMode(GL_MODELVIEW);
+         glScaled(1.0, 1.0, -1.0);
+         glmsMatrixMode(GL_PROJECTION);
+         glShadeModel(GL_FLAT);
+
+         glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+         glFogi(GL_FOG_MODE, GL_EXP);
+         glFogf(GL_FOG_DENSITY, 0);
+         glEnable(GL_NORMALIZE);
+         glDepthFunc(GL_LESS);
+         glClearDepth(1.0);
+         glDisable(GL_MULTISAMPLE_ARB);
+
+         glViewport(0,0,eglWidth,eglHeight);
+         glmsLoadIdentity();
+         glOrtho(0,eglWidth,eglHeight,0,0.0,1.0);
+
+         glabCurArrayBuffer = 0;
+         glabCurElementBuffer = 0;
+
          result = true;
       #elif defined(__EMSCRIPTEN__)
          if(glfwInit() == GL_TRUE)
@@ -977,6 +1018,11 @@ class OpenGLDisplayDriver : DisplayDriver
    void DestroyDisplaySystem(DisplaySystem displaySystem)
    {
       OGLSystem oglSystem = displaySystem.driverData;
+      if(stippleTexture)
+      {
+         glDeleteTextures(1, &stippleTexture);
+         stippleTexture = 0;
+      }
 
    #if defined(__WIN32__)
       wglMakeCurrent( null, null );
@@ -1136,7 +1182,9 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
       if(result)
       {
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
          ogl_LoadFunctions();
+#endif
          CheckExtensions(oglSystem);
          vboAvailable = glBindBuffer != null;
          setupDebugging();
@@ -1672,7 +1720,7 @@ class OpenGLDisplayDriver : DisplayDriver
          SwapBuffers(oglDisplay.hdc);
 #elif defined(__unix__) || defined(__APPLE__)
       #if defined(__ANDROID__) || defined(__ODROID__)
-         eglSwapBuffers(eglDisplay, eglSurface);
+         egl_swap_buffers();
       #elif defined(__EMSCRIPTEN__)
          glfwSwapBuffers();
       #else
index 2624c26..48bbb35 100644 (file)
@@ -1,5 +1,7 @@
 #if defined(__ANDROID__) || defined(__ODROID__)
 
+import "instance"
+
 #include <EGL/egl.h>
 
 EGLDisplay eglDisplay;
@@ -8,9 +10,9 @@ EGLContext eglContext;
 int eglWidth, eglHeight;
 
 #if defined(__ANDROID__)
-static bool egl_init_display(ANativeWindow* window)
+bool egl_init_display(ANativeWindow* window)
 #else
-static bool egl_init_display(uint window)
+bool egl_init_display(uint window)
 #endif
 {
    const EGLint attribs[] =
@@ -50,53 +52,11 @@ static bool egl_init_display(uint window)
    eglWidth = w;
    eglHeight = h;
 
-   glEnableClientState(GL_VERTEX_ARRAY);
-   /*
-   // Initialize GL state.
-   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
-   glEnable(GL_CULL_FACE);
-   glShadeModel(GL_SMOOTH);
-   glDisable(GL_DEPTH_TEST);
-   */
-   glDisable(GL_CULL_FACE);
-   glDisable(GL_DEPTH_TEST);
-
-   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-   glEnable(GL_BLEND);
-
-   matrixStack[0][0].Identity();
-   matrixStack[1][0].Identity();
-   matrixStack[2][0].Identity();
-
-   glmsMatrixMode(GL_MODELVIEW);
-   glScaled(1.0, 1.0, -1.0);
-   glmsMatrixMode(GL_PROJECTION);
-   glShadeModel(GL_FLAT);
-
-   glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
-   glFogi(GL_FOG_MODE, GL_EXP);
-   glFogf(GL_FOG_DENSITY, 0);
-   glEnable(GL_NORMALIZE);
-   glDepthFunc(GL_LESS);
-   glClearDepth(1.0);
-   glDisable(GL_MULTISAMPLE_ARB);
-
-   glViewport(0,0,w,h);
-   glmsLoadIdentity();
-   glOrtho(0,w,h,0,0.0,1.0);
-
-   glabCurArrayBuffer = 0;
-   glabCurElementBuffer = 0;
    return true;
 }
 
-static void egl_term_display()
+void egl_term_display()
 {
-   if(stippleTexture)
-   {
-      glDeleteTextures(1, &stippleTexture);
-      stippleTexture = 0;
-   }
    if(eglDisplay != EGL_NO_DISPLAY)
    {
       eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -111,4 +71,9 @@ static void egl_term_display()
    eglSurface = EGL_NO_SURFACE;
 }
 
+void egl_swap_buffers()
+{
+   eglSwapBuffers(eglDisplay, eglSurface);
+}
+
 #endif
index a2e6735..0225467 100644 (file)
@@ -3,10 +3,15 @@
 #if defined(_GLES)
  #define ES1_1
 #else
-// #define SHADERS
+ #define SHADERS
 #endif
 
-#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__ODROID__)
+   #include <GLES/gl.h>
+
+   #define GL_INT    0x1404
+   #define GL_DOUBLE 0x140A
+#else
 #  if defined(SHADERS)
 #     include "gl_core_3_3.h"
 #  else
@@ -14,6 +19,7 @@
 #  endif
 #endif
 
+import "immediate"
 import "Display"
 
 // Kept public for now
index e6b67b6..c7ab495 100644 (file)
@@ -1,10 +1,12 @@
 // OpenGL Immediate Mode Transition Kit
 
 #ifndef _GLES
-// #define SHADERS
+ #define SHADERS
 #endif
 
-#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__ODROID__)
+   #include <GLES/gl.h>
+#else
 #  if defined(SHADERS)
 #     include "gl_core_3_3.h"
 #  else
@@ -12,7 +14,7 @@
 #  endif
 #endif
 
-import "Display"
+import "glab"
 
 #ifdef SHADERS
 
index c48eff1..e408bd9 100644 (file)
@@ -1,10 +1,12 @@
 // Matrix Stack Implementation
 
 #ifndef _GLES
-// #define SHADERS
+ #define SHADERS
 #endif
 
-#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__ODROID__)
+   #include <GLES/gl.h>
+#else
 #  if defined(SHADERS)
 #     include "gl_core_3_3.h"
 #  else
index 0ec7c4b..83ccb02 100644 (file)
@@ -1,6 +1,18 @@
 import "Display"
+import "matrixStack"
 
-#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__ODROID__)
+#ifndef _GLES
+#define SHADERS
+#endif
+
+#if defined(SHADERS)
+
+#if defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__ODROID__)
+   #include <GLES/gl.h>
+
+   #define GL_INT    0x1404
+   #define GL_DOUBLE 0x140A
+#else
 #  if defined(SHADERS)
 #     include "gl_core_3_3.h"
 #  else
@@ -331,3 +343,5 @@ void loadShaders(const String vertexShaderFile, const String fragmentShaderFile)
       shader_color(1.0, 1.0, 1.0, 1.0);
    }
 }
+
+#endif