ecere: Fixed strict aliasing warnings
[sdk] / ecere / src / gfx / drivers / OpenGLDisplayDriver.ec
index 454d114..53a3b35 100644 (file)
@@ -531,7 +531,7 @@ static void egl_term_display()
 {
    if(stippleTexture)
    {
-      glDeleteTextures(1, (int *)&stippleTexture);
+      glDeleteTextures(1, &stippleTexture);
       stippleTexture = 0;
    }
    if(eglDisplay != EGL_NO_DISPLAY)
@@ -1036,7 +1036,7 @@ void glesTerminate()
    shortBDSize = 0;
 }
 
-static int stippleTexture;
+static GLuint stippleTexture;
 static bool stippleEnabled;
 
 void glesLineStipple( int i, unsigned short j )
@@ -1139,17 +1139,21 @@ void GLGenBuffers(int count, uint * buffer)
 #ifdef __ANDROID__
    glGenBuffers(count, buffer);
 #else
+#if defined(__WIN32__)
    if(glGenBuffersARB)
+#endif
       glGenBuffersARB(count, buffer);
 #endif
 }
 
-void GLDeleteBuffers(int count, uint * buffer)
+void GLDeleteBuffers(int count, GLuint * buffer)
 {
 #ifdef __ANDROID__
    glDeleteBuffers(count, buffer);
 #else
+#if defined(__WIN32__)
    if(glDeleteBuffersARB)
+#endif
       glDeleteBuffersARB(count, buffer);
 #endif
 }
@@ -1159,7 +1163,9 @@ void GLBindBuffer(int target, uint buffer)
 #ifdef __ANDROID__
    glBindBuffer(target, buffer);
 #else
+#if defined(__WIN32__)
    if(glBindBufferARB)
+#endif
       glBindBufferARB(target, buffer);
 #endif
 }
@@ -1174,7 +1180,10 @@ void GLBufferData(int type, GLenum target, int size, const GLvoid *data, GLenum
    else
       glBufferData(target, size, data, usage);
 #else
+
+#if defined(__WIN32__)
    if(glBufferDataARB)
+#endif
       glBufferDataARB(target, size, data, usage);
 
 #endif
@@ -1255,18 +1264,18 @@ class OGLSurface : struct
 
 class OGLMesh : struct
 {
-   int vertices;
-   int normals;
-   int texCoords;
-   int texCoords2;
-   int colors;
+   uint vertices;
+   uint normals;
+   uint texCoords;
+   uint texCoords2;
+   uint colors;
 };
 
 class OGLIndices : struct
 {
    uint16 * indices;
-   int buffer;
-   int nIndices;
+   uint buffer;
+   uint nIndices;
 };
 
 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
@@ -1318,7 +1327,6 @@ class OpenGLDisplayDriver : DisplayDriver
    bool Lock(Display display)
    {
       OGLDisplay oglDisplay = display.driverData;
-      OGLSystem oglSystem = display.displaySystem.driverData;
 
       if(useSingleGLContext) return true;
    #if defined(__WIN32__)
@@ -1411,7 +1419,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void ::CheckExtensions(OGLSystem oglSystem)
    {
-      char * extensions = glGetString(GL_EXTENSIONS);
+      const char * extensions = (const char *)glGetString(GL_EXTENSIONS);
       if(extensions)
          oglSystem.pow2textures = strstr(extensions, "GL_ARB_texture_non_power_of_two") ? false : true;
       glGetIntegerv(GL_MAX_TEXTURE_SIZE, &oglSystem.maxTextureSize);
@@ -1703,12 +1711,18 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
       if(result)
       {
-#if !defined(__OLDX__)
+#if defined(__WIN32__)
          if(glBlendFuncSeparate)
             glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
          else
-#endif
             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#else
+#if !defined(__OLDX__)
+          glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+#else
+         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#endif
+#endif
          glEnable(GL_BLEND);
 
          glMatrixMode(GL_MODELVIEW);
@@ -1750,12 +1764,12 @@ class OpenGLDisplayDriver : DisplayDriver
    bool DisplaySize(Display display, int width, int height)
    {
       OGLDisplay oglDisplay = display.driverData;
-      OGLSystem oglSystem = display.displaySystem.driverData;
 
       bool result = false;
 
       //printf("Inside DisplaySize\n");
 #if defined(__WIN32__) || defined(USEPBUFFER)
+      OGLSystem oglSystem = display.displaySystem.driverData;
       if(display.alphaBlend)
       {
 #if defined(__WIN32__)
@@ -2145,7 +2159,9 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void Update(Display display, Box updateBox)
    {
+#if defined(__WIN32__) || defined(USEPBUFFER)
       OGLDisplay oglDisplay = display.driverData;
+#endif
       //Logf("DisplayScreen\n");
 
       glFlush();
@@ -2251,9 +2267,12 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
    {
-      glDeleteTextures(1, (int *)&bitmap.driverData);
-      bitmap.driverData = 0;
-
+      if(bitmap.driverData)
+      {
+         GLuint tex = (GLuint)(uintptr)bitmap.driverData;
+         glDeleteTextures(1, &tex);
+         bitmap.driverData = 0;
+      }
       bitmap.driver = ((subclass(DisplayDriver))class(LFBDisplayDriver));
    }
 
@@ -2262,7 +2281,7 @@ class OpenGLDisplayDriver : DisplayDriver
       OGLSystem oglSystem = displaySystem.driverData;
       bool result = false;
       Bitmap mipMap { };
-      int glBitmap = -1;
+      GLuint glBitmap = 0;
 
       uint w = width, h = height;
       if(oglSystem.pow2textures)
@@ -2293,7 +2312,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
       delete mipMap;
 
-      bitmap.driverData = (void *)glBitmap;
+      bitmap.driverData = (void *)(uintptr)glBitmap;
       bitmap.driver = displaySystem.driver;
       bitmap.width = w;
       bitmap.height = h;
@@ -2312,7 +2331,7 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          int c, level;
          uint w = bitmap.width, h = bitmap.height;
-         int glBitmap = -1;
+         GLuint glBitmap = 0;
          if(oglSystem.pow2textures)
          {
             w = pow2i(w);
@@ -2342,11 +2361,10 @@ class OpenGLDisplayDriver : DisplayDriver
 
          glGetError();
          glGenTextures(1, &glBitmap);
-         if(glBitmap == -1)
+         if(glBitmap == 0)
          {
-            int error = glGetError();
+            //int error = glGetError();
             return false;
-            //Print("");
          }
 
          glBindTexture(GL_TEXTURE_2D, glBitmap);
@@ -2411,7 +2429,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
          if(!bitmap.keepData)
             bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap);
-         bitmap.driverData = (void *)glBitmap;
+         bitmap.driverData = (void *)(uintptr)glBitmap;
          bitmap.driver = displaySystem.driver;
 
          if(!result)
@@ -2751,7 +2769,7 @@ class OpenGLDisplayDriver : DisplayDriver
       else if(oglSurface.xOffset)
          glTranslated(oglSurface.xOffset / 64.0/*-0.375*/, 0.0, 0.0);
 
-      glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
+      glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)bitmap.driverData);
       glBegin(GL_QUADS);
 
       if(h < 0)
@@ -2818,7 +2836,7 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
 
       glEnable(GL_TEXTURE_2D);
-      glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
+      glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)bitmap.driverData);
 
       glColor4fv(oglSurface.bitmapMult);
 
@@ -2873,7 +2891,7 @@ class OpenGLDisplayDriver : DisplayDriver
    void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
    {
       float s2dw,s2dh,d2sw,d2sh;
-      bool flipX = false, flipY = false;
+      //bool flipX = false, flipY = false;
 
       //Logf("StretchDI\n");
 
@@ -2881,13 +2899,13 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          w = Abs(w);
          sw = Abs(sw);
-         flipX = true;
+         //flipX = true;
       }
       if(Sgn(h) != Sgn(sh))
       {
          h = Abs(h);
          sh = Abs(sh);
-         flipY = true;
+         //flipY = true;
       }
 
       s2dw=(float)w / sw;
@@ -3044,7 +3062,7 @@ class OpenGLDisplayDriver : DisplayDriver
       ((subclass(DisplayDriver))class(LFBDisplayDriver)).UnloadFont(displaySystem, font);
    }
 
-   Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
+   Font LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
    {
       Font font;
       OGLSystem oglSystem = displaySystem.driverData;
@@ -3053,12 +3071,12 @@ class OpenGLDisplayDriver : DisplayDriver
       return font;
    }
 
-   void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height)
+   void FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
    {
       ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
    }
 
-   void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
+   void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
    {
       OGLSurface oglSurface = surface.driverData;
       OGLSystem oglSystem = display.displaySystem.driverData;
@@ -3100,7 +3118,7 @@ class OpenGLDisplayDriver : DisplayDriver
       oglSurface.opaqueText = opaque;
    }
 
-   void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
+   void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
    {
       OGLSurface oglSurface = surface.driverData;
       OGLSystem oglSystem = display.displaySystem.driverData;
@@ -3163,7 +3181,7 @@ class OpenGLDisplayDriver : DisplayDriver
             break;
          case depthWrite:
             if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false);
-            oglDisplay.depthWrite = value;
+            oglDisplay.depthWrite = (bool)value;
             break;
          case fogColor:
          {
@@ -3172,8 +3190,7 @@ class OpenGLDisplayDriver : DisplayDriver
             break;
          }
          case fogDensity:
-            value *= nearPlane;
-            glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
+            glFogf(GL_FOG_DENSITY, (float)(RenderStateFloat { value }.f * nearPlane));
             break;
          case blend:
             if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
@@ -3384,7 +3401,7 @@ class OpenGLDisplayDriver : DisplayDriver
          {
             float pickX = display.display3D.pickX + surface.offset.x;
             float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1;
-            Matrix pickMatrix =
+            Matrix pickMatrix
             {
                {
                   w / display.display3D.pickWidth, 0, 0, 0,
@@ -3482,7 +3499,7 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          Bitmap map = material.baseMap;
          glEnable(GL_TEXTURE_2D);
-         glBindTexture(GL_TEXTURE_2D, (uint)map.driverData);
+         glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)map.driverData);
 
          glMatrixMode(GL_TEXTURE);
          glLoadIdentity();
@@ -3714,12 +3731,14 @@ class OpenGLDisplayDriver : DisplayDriver
       //Logf("SelectMesh\n");
 
 #if !defined( __ANDROID__) && !defined(__APPLE__)
-      if(display.display3D.mesh && glUnlockArraysEXT)
-         glUnlockArraysEXT();
+#if defined(__WIN32__)
+      if(glUnlockArraysEXT)
+#endif
+         if(display.display3D.mesh)
+            glUnlockArraysEXT();
 #endif
       if(mesh)
       {
-         OGLDisplay oglDisplay = display.driverData;
          OGLMesh oglMesh = mesh.data;
 
          // *** Vertex Stream ***
@@ -3788,7 +3807,11 @@ class OpenGLDisplayDriver : DisplayDriver
          }
 
 #if !defined(__ANDROID__) && !defined(__APPLE__)
-         if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices);
+
+#if defined(__WIN32__)
+         if(glLockArraysEXT)
+#endif
+            glLockArraysEXT(0, mesh.nVertices);
 #endif
       }
       else
@@ -3797,7 +3820,6 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
    {
-      OGLDisplay oglDisplay = display.driverData;
       //Logf("DrawPrimitives\n");
 
       if(primitive->type.vertexRange)
@@ -3893,9 +3915,12 @@ public void UseSingleGLContext(bool useSingle)
    useSingleGLContext = useSingle;
 }
 
-default dllexport void * __attribute__((stdcall)) IS_GLGetContext(DisplaySystem displaySystem)
+default dllexport void *
+#if defined(__WIN32__)
+__attribute__((stdcall))
+#endif
+IS_GLGetContext(DisplaySystem displaySystem)
 {
-   void * context = null;
    if(displaySystem)
    {
       OGLSystem system = displaySystem.driverData;