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=4f639c10002426acafc59fa0015861b428fdbb6b;hb=6f6fe96900374d8744473ce240279e66d1260191;hpb=677ea10304049d6f7aae48317fe32cfea060d209 diff --git a/plugins/gpu-gles/gpuDraw.c b/plugins/gpu-gles/gpuDraw.c index 4f639c10..b6191046 100644 --- a/plugins/gpu-gles/gpuDraw.c +++ b/plugins/gpu-gles/gpuDraw.c @@ -27,17 +27,7 @@ #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 "gpuDraw.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) @@ -216,11 +156,7 @@ void GetExtInfos(void) 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,15 +242,9 @@ void CreateScanLines(void) // Initialize OGL //////////////////////////////////////////////////////////////////////// -#ifdef _WINDOWS -HGLRC GLCONTEXT=NULL; -#endif - -#ifdef MAEMO_CHANGES #define MODE_RAW 0 #define MODE_X11 1 #define MODE_SDL 2 -int pandora_driver_mode = MODE_RAW; int use_fsaa = 0; EGLDisplay display; @@ -345,9 +277,7 @@ EGLint attrib_list_fsaa[] = EGLint attrib_list[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_BUFFER_SIZE, 0, - EGL_DEPTH_SIZE, 16, +// EGL_DEPTH_SIZE, 16, EGL_NONE }; @@ -361,14 +291,17 @@ bool TestEGLError(const char* pszLocation) EGLint iErr = eglGetError(); if (iErr != EGL_SUCCESS) { - printf("%s failed (%d).\n", pszLocation, iErr); + printf("%s failed (0x%x).\n", pszLocation, iErr); return FALSE; } return TRUE; } -void maemoGLinit(){ +static int initEGL(void) +{ + NativeWindowType window = 0; + printf ("GL init\n"); EGLint numConfigs; @@ -400,23 +333,15 @@ void maemoGLinit(){ } #if defined(USE_X11) - pandora_driver_mode = MODE_X11; // TODO make configurable -#else - pandora_driver_mode = MODE_RAW; // TODO make configurable -#endif - - switch(pandora_driver_mode) - { -#if defined(USE_X11) - case MODE_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); @@ -425,7 +350,8 @@ void maemoGLinit(){ 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; @@ -435,7 +361,7 @@ void maemoGLinit(){ // 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); @@ -463,117 +389,107 @@ void maemoGLinit(){ XSendEvent(x11Display, DefaultRootWindow(x11Display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); display = eglGetDisplay( (EGLNativeDisplayType)x11Display ); - break; -#endif - case MODE_RAW: - default: + window = x11Window; +#else display = eglGetDisplay( (EGLNativeDisplayType)0 ); - break; - } +#endif if( display == EGL_NO_DISPLAY ) { printf( "GLES EGL Error: GL No Display\n" ); + return -1; } if( !eglInitialize( display, &majorVersion, &minorVersion ) ) { printf( "GLES EGL Error: eglInitialize failed\n" ); + return -1; } if( !eglChooseConfig( display, attribList, &config, 1, &numConfigs ) ) { printf( "GLES EGL Error: eglChooseConfig failed\n" ); + return -1; } context = eglCreateContext( display, config, NULL, NULL ); if( context==0 ) { printf( "GLES EGL Error: eglCreateContext failed\n" ); + return -1; } - switch(pandora_driver_mode) - { -#if defined(USE_X11) - case MODE_X11: - surface = eglCreateWindowSurface( display, config, (EGLNativeDisplayType)x11Window, NULL ); - break; +#ifdef FAKE_WINDOW + // broken Caanoo libs won't accept NULL window + window = (NativeWindowType)1; #endif - case MODE_RAW: - default: - surface = eglCreateWindowSurface( display, config, (EGLNativeDisplayType)0, NULL ); - break; - } + surface = eglCreateWindowSurface( display, config, window, NULL ); + if (!TestEGLError("eglCreateWindowSurface")) + return -1; - eglMakeCurrent( display, surface, surface, context ); - if (!TestEGLError("eglMakeCurrent")) - printf("error eglMakeCurrent"); - else - printf("GLES Window Opened\n"); + eglMakeCurrent( display, surface, surface, context ); + if (!TestEGLError("eglMakeCurrent")) + return -1; + + printf("GLES init ok\n"); + return 0; } -#endif 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 @@ -586,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) @@ -616,25 +532,15 @@ void GLcleanup() { CleanupTextureStore(); // bye textures -#ifdef _WINDOWS - wglMakeCurrent(NULL, NULL); // bye context - if(GLCONTEXT) wglDeleteContext(GLCONTEXT); - if(!bWindowMode && dcGlobal) - ReleaseDC(hWWindow,dcGlobal); -#endif - eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); eglDestroySurface( display, surface ); eglDestroyContext( display, context ); eglTerminate( display ); #if defined(USE_X11) - if (pandora_driver_mode == MODE_X11) - { if (x11Window) XDestroyWindow(x11Display, x11Window); if (x11Colormap) XFreeColormap( x11Display, x11Colormap ); if (x11Display) XCloseDisplay(x11Display); - } #endif } @@ -1169,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; } } @@ -1229,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; } } @@ -1299,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; } } @@ -1335,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 @@ -1373,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; @@ -1464,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; }