int iUseMask=0;\r
int iSetMask=0;\r
unsigned short sSetMask=0;\r
-unsigned long lSetMask=0;\r
+unsigned int lSetMask=0;\r
\r
// drawing/coord vars\r
\r
int use_fsaa = 0;\r
\r
EGLDisplay display;\r
-EGLConfig config;\r
-EGLContext context;\r
EGLSurface surface;\r
+static EGLConfig config;\r
+static EGLContext context;\r
\r
#if defined(USE_X11)\r
#include "X11/Xlib.h"\r
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, (int)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
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
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
\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
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
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
- printf("error eglMakeCurrent");\r
- else\r
- printf("GLES Window Opened\n");\r
+ eglMakeCurrent( display, surface, surface, context );\r
+ if (!TestEGLError("eglMakeCurrent"))\r
+ return -1;\r
+\r
+ printf("GLES init ok\n");\r
+ return 0;\r
}\r
\r
-int GLinitialize() \r
+static int created_gles_context;\r
+\r
+int GLinitialize(void *ext_gles_display, void *ext_gles_surface)\r
{\r
- initEGL();\r
+ if(ext_gles_display != NULL && ext_gles_surface != NULL) { \r
+ display = (EGLDisplay)ext_gles_display;\r
+ surface = (EGLSurface)ext_gles_surface;\r
+ }\r
+ else {\r
+ if(initEGL()!=0)\r
+ return -1;\r
+ created_gles_context=1;\r
+ }\r
\r
//----------------------------------------------------// \r
\r
+ glDepthRangef(0.0f, 1.0f);glError();\r
+\r
glViewport(rRatioRect.left, // init viewport by ratio rect\r
iResY-(rRatioRect.top+rRatioRect.bottom),\r
rRatioRect.right, \r
rRatioRect.bottom); glError();\r
- \r
+\r
glScissor(0, 0, iResX, iResY); glError(); // init clipping (fullscreen)\r
glEnable(GL_SCISSOR_TEST); glError();\r
\r
glLoadIdentity();\r
glScalef(1.0f/255.99f,1.0f/255.99f,1.0f); // geforce precision hack\r
#endif \r
- glDepthRangef(0.0f, 1.0f);glError();\r
\r
- glPolygonOffset( -0.2f, -0.2f );glError();\r
+ //glPolygonOffset( -0.2f, -0.2f );glError();\r
\r
glMatrixMode(GL_PROJECTION); glError(); // init projection with psx resolution\r
glLoadIdentity(); glError();\r
{ \r
CleanupTextureStore(); // bye textures\r
\r
- eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );\r
- eglDestroySurface( display, surface );\r
- eglDestroyContext( display, context );\r
- eglTerminate( display );\r
+ if(created_gles_context) {\r
+ eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );\r
+ eglDestroySurface( display, surface );\r
+ eglDestroyContext( display, context );\r
+ eglTerminate( display );\r
\r
#if defined(USE_X11)\r
if (x11Window) XDestroyWindow(x11Display, x11Window);\r
if (x11Colormap) XFreeColormap( x11Display, x11Colormap );\r
if (x11Display) XCloseDisplay(x11Display);\r
#endif\r
+ created_gles_context=0;\r
+ }\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
// real psx polygon coord mapping right... the following\r
// works not to bad with many games, though\r
\r
-__inline BOOL CheckCoord4()\r
+static __inline BOOL CheckCoord4()\r
{\r
if(lx0<0)\r
{\r
return FALSE;\r
}\r
\r
-__inline BOOL CheckCoord3()\r
+static __inline BOOL CheckCoord3()\r
{\r
if(lx0<0)\r
{\r
}\r
\r
\r
-__inline BOOL CheckCoord2()\r
+static __inline BOOL CheckCoord2()\r
{\r
if(lx0<0)\r
{\r
\r
///////////////////////////////////////////////////////// \r
\r
-void offsetScreenUpload(long Position)\r
+void offsetScreenUpload(int Position)\r
{\r
if(bDisplayNotSet)\r
SetOGLDisplaySettings(1);\r
\r
if(Position==-1)\r
{\r
- long lmdx,lmdy;\r
+ int lmdx,lmdy;\r
\r
lmdx=xrUploadArea.x0;\r
lmdy=xrUploadArea.y0;\r