gpu-gles: refactor for caanoo/wiz support
[pcsx_rearmed.git] / plugins / gpu-gles / gpuDraw.c
index d7d6761..ebb3bf0 100644 (file)
@@ -291,15 +291,17 @@ bool TestEGLError(const char* pszLocation)
        EGLint iErr = eglGetError();\r
        if (iErr != EGL_SUCCESS)\r
        {\r
-               printf("%s failed (%d).\n", pszLocation, iErr);\r
+               printf("%s failed (0x%x).\n", pszLocation, iErr);\r
                return FALSE;\r
        }\r
 \r
        return TRUE;\r
 }\r
 \r
-static void initEGL(void)\r
+static int initEGL(void)\r
 {\r
+       NativeWindowType window = 0;\r
+\r
        printf ("GL init\n");\r
 \r
        EGLint numConfigs;\r
@@ -336,9 +338,10 @@ static void initEGL(void)
             if (!x11Display)\r
             {\r
                 printf("GLES Error: Unable to open X display\n");\r
+                return -1;\r
             }\r
             x11Screen = XDefaultScreen( x11Display );\r
-                               \r
+\r
             // Gets the display parameters so we can pass the same parameters to the window to be created.\r
             sRootWindow        = RootWindow(x11Display, x11Screen);\r
             i32Depth   = DefaultDepth(x11Display, x11Screen);\r
@@ -347,7 +350,8 @@ static void initEGL(void)
             if (!px11Visual)\r
             {\r
                 printf("GLES Error: Unable to acquire visual\n");\r
-                       }\r
+                return -1;\r
+            }\r
             // Colormap of the specified visual type for the display.\r
             x11Colormap = XCreateColormap( x11Display, sRootWindow, px11Visual->visual, AllocNone );\r
             sWA.colormap = x11Colormap;\r
@@ -357,7 +361,7 @@ static void initEGL(void)
 \r
             // Display capabilities list.\r
             ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;\r
-                                                          \r
+\r
             // Creates the X11 window\r
             x11Window = XCreateWindow( x11Display, RootWindow(x11Display, x11Screen), 0, 0, iResX, iResY,\r
                                         0, CopyFromParent, InputOutput, CopyFromParent, ui32Mask, &sWA);\r
@@ -385,6 +389,7 @@ static void initEGL(void)
             XSendEvent(x11Display, DefaultRootWindow(x11Display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);\r
 \r
             display = eglGetDisplay( (EGLNativeDisplayType)x11Display );\r
+            window = x11Window;\r
 #else\r
             display = eglGetDisplay( (EGLNativeDisplayType)0 );\r
 #endif\r
@@ -392,40 +397,48 @@ static void initEGL(void)
        if( display == EGL_NO_DISPLAY )\r
        {\r
                printf( "GLES EGL Error: GL No Display\n" );\r
+               return -1;\r
        }\r
 \r
        if( !eglInitialize( display, &majorVersion, &minorVersion ) )\r
        {\r
                printf( "GLES EGL Error: eglInitialize failed\n" );\r
+               return -1;\r
        }\r
 \r
        if( !eglChooseConfig( display, attribList, &config, 1, &numConfigs ) )\r
        {\r
                printf( "GLES EGL Error: eglChooseConfig failed\n" );\r
+               return -1;\r
        }\r
 \r
        context = eglCreateContext( display, config, NULL, NULL );\r
        if( context==0 )\r
        {\r
                printf( "GLES EGL Error: eglCreateContext failed\n" );\r
+               return -1;\r
        }\r
 \r
-#if defined(USE_X11)\r
-            surface = eglCreateWindowSurface( display, config, (EGLNativeDisplayType)x11Window, NULL );\r
-#else\r
-            surface = eglCreateWindowSurface( display, config, (EGLNativeDisplayType)0, NULL );\r
+#ifdef FAKE_WINDOW\r
+       // broken Caanoo libs won't accept NULL window\r
+       window = (NativeWindowType)1;\r
 #endif\r
+       surface = eglCreateWindowSurface( display, config, window, NULL );\r
+       if (!TestEGLError("eglCreateWindowSurface"))\r
+               return -1;\r
+\r
+       eglMakeCurrent( display, surface, surface, context );\r
+       if (!TestEGLError("eglMakeCurrent"))\r
+               return -1;\r
 \r
-    eglMakeCurrent( display, surface, surface, context );\r
-    if (!TestEGLError("eglMakeCurrent"))\r
-        printf("error eglMakeCurrent");\r
-    else\r
-        printf("GLES Window Opened\n");\r
+       printf("GLES init ok\n");\r
+       return 0;\r
 }\r
 \r
 int GLinitialize() \r
 {\r
- initEGL();\r
+ if(initEGL()!=0)\r
+  return -1;\r
 \r
  //----------------------------------------------------// \r
 \r