X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fgpu-gles%2FgpuDraw.c;h=b6191046aaa14a73bc213b899be2e7d7dc53c5e9;hp=3d09c333eef91b8571fc9699547ea6aef0cab3f6;hb=6f6fe96900374d8744473ce240279e66d1260191;hpb=ce879073e4f228deec8bec5db8a2ff640636c88f;ds=sidebyside diff --git a/plugins/gpu-gles/gpuDraw.c b/plugins/gpu-gles/gpuDraw.c index 3d09c333..b6191046 100644 --- a/plugins/gpu-gles/gpuDraw.c +++ b/plugins/gpu-gles/gpuDraw.c @@ -27,19 +27,9 @@ #define _IN_DRAW -#ifdef _WINDOWS -#include "stdafx.h" -#include -#include -#include -#include "externals.h" -#include "gpu.h" -#include "draw.h" -#include "prim.h" -#include "texture.h" -#else + #include "gpuExternals.h" -#include "GPUPlugin.h" +#include "gpuPlugin.h" #include "gpuDraw.h" #include "gpuPrim.h" #include "gpuTexture.h" @@ -48,7 +38,6 @@ #include #include #include -#endif //#include "menu.h" //////////////////////////////////////////////////////////////////////////////////// @@ -102,13 +91,8 @@ //////////////////////////////////////////////////////////////////////////////////// // draw globals -#ifdef _WINDOWS -HDC dcGlobal=NULL; -HWND hWWindow; -#else void glBlendEquationEXT(GLenum mode); void glColorTableEXT(GLenum target, GLenum internalFormat, GLsizei width, GLenum format,GLenum type, const GLvoid *data); -#endif // draw globals; most will be initialized again later (by config or checks) @@ -158,50 +142,6 @@ GLbitfield uiBufferBits=GL_COLOR_BUFFER_BIT; // Set OGL pixel format //////////////////////////////////////////////////////////////////////// -#ifdef _WINDOWS -BOOL bSetupPixelFormat(HDC hDC) -{ - int pixelformat; - static PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd - 1, // version number - PFD_DRAW_TO_WINDOW | // support window - PFD_SUPPORT_OPENGL | // support OpenGL - PFD_DOUBLEBUFFER, // double buffered - PFD_TYPE_RGBA, // RGBA type - 16, // 16-bit color depth (adjusted later) - 0, 0, 0, 0, 0, 0, // color bits ignored - 0, // no alpha buffer - 0, // shift bit ignored - 0, // no accumulation buffer - 0, 0, 0, 0, // accum bits ignored - 0, // z-buffer - 0, - 0, // no auxiliary buffer - PFD_MAIN_PLANE, // main layer - 0, // reserved - 0, 0, 0 // layer masks ignored - }; - - pfd.cColorBits=iColDepth; // set user color depth - pfd.cDepthBits=iZBufferDepth; // set user zbuffer (by psx mask) - - if((pixelformat=ChoosePixelFormat(hDC,&pfd))==0) - { - MessageBox(NULL,"ChoosePixelFormat failed","Error",MB_OK); - return FALSE; - } - - if(SetPixelFormat(hDC,pixelformat, &pfd)==FALSE) - { - MessageBox(NULL,"SetPixelFormat failed","Error",MB_OK); - return FALSE; - } - - return TRUE; -} -#endif //////////////////////////////////////////////////////////////////////// // Get extension infos (f.e. pal textures / packed pixels) @@ -211,16 +151,12 @@ void GetExtInfos(void) { BOOL bPacked=FALSE; // default: no packed pixel support - if(strstr((s8 *)glGetString(GL_EXTENSIONS), // packed pixels available? + if(strstr((char *)glGetString(GL_EXTENSIONS), // packed pixels available? "GL_EXT_packed_pixels")) bPacked=TRUE; // -> ok - #ifdef _WINDOWS - iClampType=GL_CLAMP; -#else iClampType=GL_CLAMP_TO_EDGE; -#endif } //////////////////////////////////////////////////////////////////////// @@ -239,8 +175,7 @@ void SetExtGLFuncs(void) if(bAdvancedBlend) bUseMultiPass=TRUE; // -> pseudo-advanced with 2 passes else bUseMultiPass=FALSE; // -> or simple 'bright color' mode // bGLBlend=FALSE; // -> no ext blending! - - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glError(); } if(bOpaquePass) // opaque mode? @@ -257,13 +192,15 @@ void SetExtGLFuncs(void) } TCF[1]=XP8RGBA_1; - glAlphaFuncx(GL_GREATER,0.49f); + glAlphaFuncx(GL_GREATER,0.49f); glError(); + } else // no opaque mode? { TCF[0]=TCF[1]=P8RGBA; PalTexturedColourFn=P8RGBA; // -> init col func - glAlphaFuncx(GL_NOTEQUAL,0); // --> set alpha func + glAlphaFuncx(GL_NOTEQUAL,0); glError(); // --> set alpha func + } //----------------------------------------------------// @@ -271,7 +208,8 @@ void SetExtGLFuncs(void) LoadSubTexFn=LoadSubTexturePageSort; // init load tex ptr bBlendEnable=FALSE; // init blending: off - glDisable(GL_BLEND); + glDisable(GL_BLEND); glError(); + SetScanTrans(); // init scan lines (if wanted) } @@ -304,11 +242,45 @@ void CreateScanLines(void) // Initialize OGL //////////////////////////////////////////////////////////////////////// -#ifdef _WINDOWS -HGLRC GLCONTEXT=NULL; +#define MODE_RAW 0 +#define MODE_X11 1 +#define MODE_SDL 2 +int use_fsaa = 0; + +EGLDisplay display; +EGLConfig config; +EGLContext context; +EGLSurface surface; + +#if defined(USE_X11) +#include "X11/Xlib.h" +#include "X11/Xutil.h" +#include "X11/Xatom.h" + +Window x11Window = 0; +Display* x11Display = 0; +long x11Screen = 0; +XVisualInfo x11Visual; +XVisualInfo* px11Visual = 0; +Colormap x11Colormap = 0; #endif -#ifdef MAEMO_CHANGES +EGLint attrib_list_fsaa[] = +{ + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_BUFFER_SIZE, 0, + EGL_DEPTH_SIZE, 16, + EGL_SAMPLE_BUFFERS, 1, + EGL_SAMPLES, 4, + EGL_NONE +}; + +EGLint attrib_list[] = +{ +// EGL_DEPTH_SIZE, 16, + EGL_NONE +}; + bool TestEGLError(const char* pszLocation) { /* @@ -319,144 +291,205 @@ bool TestEGLError(const char* pszLocation) EGLint iErr = eglGetError(); if (iErr != EGL_SUCCESS) { - printf("%s failed (%d).\n", pszLocation, iErr); - return false; + printf("%s failed (0x%x).\n", pszLocation, iErr); + return FALSE; } - return true; + return TRUE; } -void maemoGLinit(){ - iResX= 800; - iResY =480; +static int initEGL(void) +{ + NativeWindowType window = 0; + printf ("GL init\n"); + + EGLint numConfigs; + EGLint majorVersion; + EGLint minorVersion; +#if defined(USE_X11) + enum + { + _NET_WM_STATE_REMOVE =0, + _NET_WM_STATE_ADD = 1, + _NET_WM_STATE_TOGGLE =2 + }; - printf ("maemo GL init\n"); - long int winxid=GDK_WINDOW_XID(GTK_WIDGET(windowG)->window); - printf ("%d\n",winxid); - - EGLContext context = 0; - EGLConfig eglConfig = 0; - EGLContext eglContext = 0; - display = eglGetDisplay( EGL_DEFAULT_DISPLAY ); + Window sRootWindow; + XSetWindowAttributes sWA; + unsigned int ui32Mask; + int i32Depth; +#endif - if( eglInitialize( display, NULL, NULL ) == EGL_FALSE ) - { - printf( "EGL Initialize failed!\n" ); - - } - -const EGLint attributeList[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - /*EGL_BUFFER_SIZE, 32, */ - EGL_NONE - }; - - EGLint pi32ConfigAttribs[5]; - pi32ConfigAttribs[0] = EGL_SURFACE_TYPE; - pi32ConfigAttribs[1] = EGL_WINDOW_BIT; - pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE; - pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT; - pi32ConfigAttribs[4] = EGL_NONE; - - EGLint pi32ContextAttribs[3]; - pi32ContextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION; - pi32ContextAttribs[1] = 2; - pi32ContextAttribs[2] = EGL_NONE; - - int iConfigs; - if (!eglChooseConfig(display, attributeList, &eglConfig, 1, &iConfigs) || (iConfigs != 1)) + EGLint *attribList = NULL; + if (use_fsaa) + { + printf( "GLES: Using Full Scene Antialiasing\n" ); + attribList = attrib_list_fsaa; + } + else { - printf("Error: eglChooseConfig() failed.\n"); + attribList = attrib_list; } - printf ("%d\n",iConfigs); - surface = eglCreateWindowSurface(display, eglConfig, (void*)winxid, NULL); - printf ("%d\n",surface); - if (!TestEGLError("eglCreateWindowSurface")) + +#if defined(USE_X11) + // Initializes the display and screen + x11Display = XOpenDisplay( ":0" ); + if (!x11Display) + { + printf("GLES Error: Unable to open X display\n"); + return -1; + } + x11Screen = XDefaultScreen( x11Display ); + + // Gets the display parameters so we can pass the same parameters to the window to be created. + sRootWindow = RootWindow(x11Display, x11Screen); + i32Depth = DefaultDepth(x11Display, x11Screen); + px11Visual = &x11Visual; + XMatchVisualInfo( x11Display, x11Screen, i32Depth, TrueColor, px11Visual); + if (!px11Visual) + { + printf("GLES Error: Unable to acquire visual\n"); + return -1; + } + // Colormap of the specified visual type for the display. + x11Colormap = XCreateColormap( x11Display, sRootWindow, px11Visual->visual, AllocNone ); + sWA.colormap = x11Colormap; + + // List of events to be handled by the application. Add to these for handling other events. + sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; + + // Display capabilities list. + ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; + + // Creates the X11 window + x11Window = XCreateWindow( x11Display, RootWindow(x11Display, x11Screen), 0, 0, iResX, iResY, + 0, CopyFromParent, InputOutput, CopyFromParent, ui32Mask, &sWA); + + // Make the window viewable and flush the output buffer. + XMapWindow(x11Display, x11Window); + XFlush(x11Display); + + // Make the window fullscreen + unsigned char fullScreen = 1; + Atom wmState = XInternAtom(x11Display, "_NET_WM_STATE", False); + Atom wmFullScreen = XInternAtom(x11Display,"_NET_WM_STATE_FULLSCREEN", False); + + XEvent xev; + xev.xclient.type = ClientMessage; + xev.xclient.serial = 0; + xev.xclient.send_event = True; + xev.xclient.window = x11Window; + xev.xclient.message_type = wmState; + xev.xclient.format = 32; + xev.xclient.data.l[0] = (fullScreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE); + xev.xclient.data.l[1] = wmFullScreen; + xev.xclient.data.l[2] = 0; + + XSendEvent(x11Display, DefaultRootWindow(x11Display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); + + display = eglGetDisplay( (EGLNativeDisplayType)x11Display ); + window = x11Window; +#else + display = eglGetDisplay( (EGLNativeDisplayType)0 ); +#endif + + if( display == EGL_NO_DISPLAY ) { - printf ("eglCreateWindowSurface fail"); + printf( "GLES EGL Error: GL No Display\n" ); + return -1; } - //context = eglCreateContext(display, eglConfig, NULL, pi32ContextAttribs); - context =eglCreateContext( display, eglConfig, - EGL_NO_CONTEXT, NULL - ); -printf ("%d\n",context); - if (!TestEGLError("eglCreateContext")) + if( !eglInitialize( display, &majorVersion, &minorVersion ) ) { - printf("error eglCreateContext"); + printf( "GLES EGL Error: eglInitialize failed\n" ); + return -1; } - eglMakeCurrent(display, surface, surface, context); + if( !eglChooseConfig( display, attribList, &config, 1, &numConfigs ) ) + { + printf( "GLES EGL Error: eglChooseConfig failed\n" ); + return -1; + } - if (!TestEGLError("eglMakeCurrent")) + context = eglCreateContext( display, config, NULL, NULL ); + if( context==0 ) { - printf("error eglMakeCurrent"); + printf( "GLES EGL Error: eglCreateContext failed\n" ); + return -1; } -} + +#ifdef FAKE_WINDOW + // broken Caanoo libs won't accept NULL window + window = (NativeWindowType)1; #endif + surface = eglCreateWindowSurface( display, config, window, NULL ); + if (!TestEGLError("eglCreateWindowSurface")) + return -1; + + eglMakeCurrent( display, surface, surface, context ); + if (!TestEGLError("eglMakeCurrent")) + return -1; + + printf("GLES init ok\n"); + return 0; +} int GLinitialize() { - //----------------------------------------------------// -#ifdef _WINDOWS - HGLRC objectRC; - // init - dcGlobal = GetDC(hWWindow); // FIRST: dc/rc stuff - objectRC = wglCreateContext(dcGlobal); - GLCONTEXT=objectRC; - wglMakeCurrent(dcGlobal, objectRC); - // CheckWGLExtensions(dcGlobal); - if(bWindowMode) ReleaseDC(hWWindow,dcGlobal); // win mode: release dc again -#endif -#ifdef MAEMO_CHANGES - maemoGLinit(); -#endif + if(initEGL()!=0) + return -1; + //----------------------------------------------------// + glDepthRangef(0.0f, 1.0f);glError(); + glViewport(rRatioRect.left, // init viewport by ratio rect iResY-(rRatioRect.top+rRatioRect.bottom), rRatioRect.right, - rRatioRect.bottom); + rRatioRect.bottom); glError(); - glScissor(0, 0, iResX, iResY); // init clipping (fullscreen) - glEnable(GL_SCISSOR_TEST); + glScissor(0, 0, iResX, iResY); glError(); // init clipping (fullscreen) + glEnable(GL_SCISSOR_TEST); glError(); #ifndef OWNSCALE glMatrixMode(GL_TEXTURE); // init psx tex sow and tow if not "ownscale" glLoadIdentity(); glScalef(1.0f/255.99f,1.0f/255.99f,1.0f); // geforce precision hack #endif + + //glPolygonOffset( -0.2f, -0.2f );glError(); + + glMatrixMode(GL_PROJECTION); glError(); // init projection with psx resolution + glLoadIdentity(); glError(); - glMatrixMode(GL_PROJECTION); // init projection with psx resolution - glLoadIdentity(); glOrtho(0,PSXDisplay.DisplayMode.x, - PSXDisplay.DisplayMode.y, 0, -1, 1); + PSXDisplay.DisplayMode.y, 0, -1, 1); glError(); if(iZBufferDepth) // zbuffer? { uiBufferBits=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT; - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); + glEnable(GL_DEPTH_TEST); glError(); + glDepthFunc(GL_ALWAYS); glError(); iDepthFunc=1; } else // no zbuffer? { uiBufferBits=GL_COLOR_BUFFER_BIT; - glDisable(GL_DEPTH_TEST); + glDisable(GL_DEPTH_TEST); glError(); } - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // first buffer clear - glClear(uiBufferBits); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glError(); // first buffer clear + glClear(uiBufferBits); glError(); GetExtInfos(); // get ext infos SetExtGLFuncs(); // init all kind of stuff (tex function pointers) - glEnable(GL_ALPHA_TEST); // wanna alpha test + glEnable(GL_ALPHA_TEST); glError(); // wanna alpha test { - glDisable(GL_LINE_SMOOTH); - glDisable(GL_POINT_SMOOTH); + glDisable(GL_LINE_SMOOTH); glError(); + glDisable(GL_POINT_SMOOTH); glError(); } ubGloAlpha=127; // init some drawing vars @@ -469,15 +502,15 @@ int GLinitialize() if(bDrawDither) glEnable(GL_DITHER); // dither mode else glDisable(GL_DITHER); - - glDisable(GL_FOG); // turn all (currently) unused modes off - glDisable(GL_LIGHTING); - glDisable(GL_STENCIL_TEST); - glDisable(GL_TEXTURE_2D); + glError(); + glDisable(GL_FOG); glError(); // turn all (currently) unused modes off + glDisable(GL_LIGHTING); glError(); + glDisable(GL_STENCIL_TEST); glError(); + glDisable(GL_TEXTURE_2D); glError(); glDisable(GL_CULL_FACE); - glFlush(); // we are done... - glFinish(); + glFlush(); glError(); // we are done... + glFinish(); glError(); CreateScanLines(); // setup scanline stuff (if wanted) @@ -499,11 +532,15 @@ void GLcleanup() { CleanupTextureStore(); // bye textures -#ifdef _WINDOWS - wglMakeCurrent(NULL, NULL); // bye context - if(GLCONTEXT) wglDeleteContext(GLCONTEXT); - if(!bWindowMode && dcGlobal) - ReleaseDC(hWWindow,dcGlobal); + eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); + eglDestroySurface( display, surface ); + eglDestroyContext( display, context ); + eglTerminate( display ); + +#if defined(USE_X11) + if (x11Window) XDestroyWindow(x11Display, x11Window); + if (x11Colormap) XFreeColormap( x11Display, x11Colormap ); + if (x11Display) XCloseDisplay(x11Display); #endif } @@ -1038,8 +1075,8 @@ void assignTextureSprite(void) { if(gLastTex!=gTexName || gLastFMode!=0) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError(); gLastTex=gTexName;gLastFMode=0; } } @@ -1098,8 +1135,8 @@ void assignTexture3(void) { if(gLastTex!=gTexName || gLastFMode!=1) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError(); gLastTex=gTexName;gLastFMode=1; } } @@ -1168,8 +1205,8 @@ void assignTexture4(void) { if(gLastTex!=gTexName || gLastFMode!=1) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError(); gLastTex=gTexName;gLastFMode=1; } } @@ -1204,9 +1241,7 @@ void assignTexture4(void) // render pos / buffers //////////////////////////////////////////////////////////////////////// -#ifndef _WINDOWS #define EqualRect(pr1,pr2) ((pr1)->left==(pr2)->left && (pr1)->top==(pr2)->top && (pr1)->right==(pr2)->right && (pr1)->bottom==(pr2)->bottom) -#endif //////////////////////////////////////////////////////////////////////// // SetDisplaySettings: "simply" calcs the new drawing area and updates @@ -1242,7 +1277,8 @@ void SetOGLDisplaySettings(BOOL DisplaySet) if(bSetClip || !EqualRect(&rC,&rX)) { rC=rX; - glScissor(rC.left,rC.top,rC.right,rC.bottom); + glScissor(rC.left,rC.top,rC.right,rC.bottom); glError(); + //LOGE("glscissor:%d %d %d %d",rC.left,rC.top,rC.right,rC.bottom); bSetClip=FALSE; } return; @@ -1333,7 +1369,8 @@ void SetOGLDisplaySettings(BOOL DisplaySet) if(bSetClip || !EqualRect(&r,&rC)) { - glScissor(r.left,r.top,r.right,r.bottom); + glScissor(r.left,r.top,r.right,r.bottom); glError(); + rC=r; bSetClip=FALSE; }