spu: fix saving bug
[pcsx_rearmed.git] / plugins / gpu-gles / gpuPlugin.c
index fcc8f8b..9d749a5 100644 (file)
@@ -149,10 +149,10 @@ void ResizeWindow()
  glViewport(rRatioRect.left,                           // init viewport by ratio rect\r
             iResY-(rRatioRect.top+rRatioRect.bottom),\r
             rRatioRect.right, \r
-            rRatioRect.bottom);         \r
+            rRatioRect.bottom); glError();\r
                                                       \r
- glScissor(0, 0, iResX, iResY);                        // init clipping (fullscreen)\r
- glEnable(GL_SCISSOR_TEST);                       \r
+ glScissor(0, 0, iResX, iResY); glError();             // init clipping (fullscreen)\r
+ glEnable(GL_SCISSOR_TEST); glError();\r
 \r
 #ifndef OWNSCALE\r
  glMatrixMode(GL_TEXTURE);                             // init psx tex sow and tow if not "ownscale"\r
@@ -160,10 +160,10 @@ void ResizeWindow()
  glScalef(1.0f/255.99f,1.0f/255.99f,1.0f);             // geforce precision hack\r
 #endif \r
 \r
- glMatrixMode(GL_PROJECTION);                          // init projection with psx resolution\r
- glLoadIdentity();\r
+ glMatrixMode(GL_PROJECTION); glError();               // init projection with psx resolution\r
+ glLoadIdentity(); glError();\r
  glOrtho(0,PSXDisplay.DisplayMode.x,\r
-         PSXDisplay.DisplayMode.y, 0, -1, 1);\r
+         PSXDisplay.DisplayMode.y, 0, -1, 1); glError();\r
  if (bKeepRatio)\r
  SetAspectRatio();\r
 }\r
@@ -506,6 +506,8 @@ long CALLBACK GPUopen(int hwndGPU)
 \r
  InitializeTextureStore();                             // init texture mem\r
 \r
+ CSTEXTURE = CSVERTEX = CSCOLOR = 0;\r
+\r
 // lGPUstatusRet = 0x74000000;\r
 \r
 // with some emus, we could do the OGL init right here... oh my\r
@@ -550,15 +552,15 @@ long CALLBACK GPUshutdown()
 void PaintBlackBorders(void)\r
 {\r
  short s;\r
+ glDisable(GL_SCISSOR_TEST); glError();\r
+ if(bTexEnabled) {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;} glError();\r
+ if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;} glError();\r
+ if(bBlendEnable)     {glDisable(GL_BLEND);bBlendEnable=FALSE;} glError();\r
+ glDisable(GL_ALPHA_TEST); glError();\r
 \r
- glDisable(GL_SCISSOR_TEST);\r
- if(bTexEnabled) {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;}\r
- if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}\r
- if(bBlendEnable)     {glDisable(GL_BLEND);bBlendEnable=FALSE;}\r
- glDisable(GL_ALPHA_TEST);\r
+ glEnable(GL_ALPHA_TEST); glError();\r
+ glEnable(GL_SCISSOR_TEST); glError();\r
 \r
- glEnable(GL_ALPHA_TEST);\r
- glEnable(GL_SCISSOR_TEST);\r
 }\r
 \r
 ////////////////////////////////////////////////////////////////////////\r
@@ -640,11 +642,13 @@ if(PreviousPSXDisplay.Range.x0||                      // paint black borders aro
 \r
 if(PSXDisplay.Disabled)                               // display disabled?\r
  {\r
+  //LOGE("PSXDisplay.Disabled");\r
+\r
   // moved here\r
-  glDisable(GL_SCISSOR_TEST);                       \r
-  glClearColor(0,0,0,128);                            // -> clear whole backbuffer\r
-  glClear(uiBufferBits);\r
-  glEnable(GL_SCISSOR_TEST);                       \r
+  glDisable(GL_SCISSOR_TEST); glError();                       \r
+  glClearColor(0,0,0,128); glError();                 // -> clear whole backbuffer\r
+  glClear(uiBufferBits); glError();\r
+  glEnable(GL_SCISSOR_TEST); glError();                       \r
   gl_z=0.0f;\r
   bDisplayNotSet = TRUE;\r
  }\r
@@ -712,11 +716,10 @@ if(lClearOnSwap)                                      // clear buffer after swap
   g=((GLclampf)GREEN(lClearOnSwapColor))/255.0f;      // -> get col\r
   b=((GLclampf)BLUE(lClearOnSwapColor))/255.0f;\r
   r=((GLclampf)RED(lClearOnSwapColor))/255.0f;\r
-  \r
-  glDisable(GL_SCISSOR_TEST);                       \r
-  glClearColor(r,g,b,128);                            // -> clear \r
-  glClear(uiBufferBits);\r
-  glEnable(GL_SCISSOR_TEST);                       \r
+  glDisable(GL_SCISSOR_TEST); glError();                       \r
+  glClearColor(r,g,b,128); glError();                 // -> clear \r
+  glClear(uiBufferBits); glError();\r
+  glEnable(GL_SCISSOR_TEST); glError();                       \r
   lClearOnSwap=0;                                     // -> done\r
  }\r
 else \r
@@ -725,11 +728,12 @@ else
 \r
   if(iZBufferDepth)                                   // clear zbuffer as well (if activated)\r
    {\r
-    glDisable(GL_SCISSOR_TEST);                       \r
-    glClear(GL_DEPTH_BUFFER_BIT);\r
-    glEnable(GL_SCISSOR_TEST);                       \r
+    glDisable(GL_SCISSOR_TEST); glError();\r
+    glClear(GL_DEPTH_BUFFER_BIT); glError();\r
+    glEnable(GL_SCISSOR_TEST); glError();\r
    }\r
  }\r
+\r
 gl_z=0.0f;\r
 \r
 //----------------------------------------------------//\r
@@ -776,7 +780,7 @@ if(iRumbleTime)                                       // shake screen by modifyi
   glViewport(rRatioRect.left+i1,                      \r
              iResY-(rRatioRect.top+rRatioRect.bottom)+i2,\r
              rRatioRect.right+i3, \r
-             rRatioRect.bottom+i4);            \r
+             rRatioRect.bottom+i4); glError();\r
  }\r
 \r
 //----------------------------------------------------//\r
@@ -915,12 +919,11 @@ if(r.bottom < 1)     r.bottom = 1;
 \r
 r.left = (iResX-r.right)/2;\r
 r.top  = (iResY-r.bottom)/2;\r
-\r
 if(r.bottom<rRatioRect.bottom ||\r
    r.right <rRatioRect.right)\r
  {\r
   RECT rC;\r
-  glClearColor(0,0,0,128);                         \r
+  glClearColor(0,0,0,128); glError();\r
 \r
   if(r.right <rRatioRect.right)\r
    {\r
@@ -928,11 +931,12 @@ if(r.bottom<rRatioRect.bottom ||
     rC.top=0;\r
     rC.right=r.left;\r
     rC.bottom=iResY;\r
-    glScissor(rC.left,rC.top,rC.right,rC.bottom);\r
-    glClear(uiBufferBits);\r
+    glScissor(rC.left,rC.top,rC.right,rC.bottom); glError();\r
+    glClear(uiBufferBits); glError();\r
     rC.left=iResX-rC.right;\r
-    glScissor(rC.left,rC.top,rC.right,rC.bottom);\r
-    glClear(uiBufferBits);\r
+    glScissor(rC.left,rC.top,rC.right,rC.bottom); glError();\r
+    \r
+    glClear(uiBufferBits); glError();\r
    }\r
 \r
   if(r.bottom <rRatioRect.bottom)\r
@@ -941,11 +945,12 @@ if(r.bottom<rRatioRect.bottom ||
     rC.top=0;\r
     rC.right=iResX;\r
     rC.bottom=r.top;\r
-    glScissor(rC.left,rC.top,rC.right,rC.bottom);\r
-    glClear(uiBufferBits);\r
+    glScissor(rC.left,rC.top,rC.right,rC.bottom); glError();\r
+\r
+    glClear(uiBufferBits); glError();\r
     rC.top=iResY-rC.bottom;\r
-    glScissor(rC.left,rC.top,rC.right,rC.bottom);\r
-    glClear(uiBufferBits);\r
+    glScissor(rC.left,rC.top,rC.right,rC.bottom); glError();\r
+    glClear(uiBufferBits); glError();\r
    }\r
   \r
   bSetClip=TRUE;\r
@@ -962,7 +967,7 @@ rRatioRect=r;
 glViewport(rRatioRect.left,\r
            iResY-(rRatioRect.top+rRatioRect.bottom),\r
            rRatioRect.right,\r
-           rRatioRect.bottom);                         // init viewport\r
+           rRatioRect.bottom); glError();              // init viewport\r
 }\r
 \r
 ////////////////////////////////////////////////////////////////////////\r
@@ -982,9 +987,9 @@ if ((PSXDisplay.DisplayMode.y == PSXDisplay.DisplayModeNew.y) &&
  }\r
 else                                                  // some res change?\r
  {\r
-  glLoadIdentity();\r
+  glLoadIdentity(); glError();\r
   glOrtho(0,PSXDisplay.DisplayModeNew.x,              // -> new psx resolution\r
-            PSXDisplay.DisplayModeNew.y, 0, -1, 1);\r
+            PSXDisplay.DisplayModeNew.y, 0, -1, 1); glError();\r
   if(bKeepRatio) SetAspectRatio();\r
  }\r
 \r
@@ -1581,7 +1586,7 @@ void CheckVRamReadEx(int x, int y, int dx, int dy)
 \r
  if(!pGfxCardScreen)\r
   {\r
-   glPixelStorei(GL_PACK_ALIGNMENT,1);\r
+   glPixelStorei(GL_PACK_ALIGNMENT,1); glError();\r
    pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);\r
   }\r
 \r
@@ -1589,8 +1594,7 @@ void CheckVRamReadEx(int x, int y, int dx, int dy)
  \r
  //if(!sArea) glReadBuffer(GL_FRONT);\r
 \r
- glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps);\r
-               \r
+ glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps); glError();\r
  //if(!sArea) glReadBuffer(GL_BACK);\r
 \r
  s=0;\r
@@ -1729,7 +1733,7 @@ void CheckVRamRead(int x, int y, int dx, int dy, bool bFront)
 \r
  if(!pGfxCardScreen)\r
   {\r
-   glPixelStorei(GL_PACK_ALIGNMENT,1);\r
+   glPixelStorei(GL_PACK_ALIGNMENT,1); glError();\r
    pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);\r
   }\r
 \r
@@ -1737,8 +1741,7 @@ void CheckVRamRead(int x, int y, int dx, int dy, bool bFront)
  \r
 // if(bFront) glReadBuffer(GL_FRONT);\r
 \r
- glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps);\r
-               \r
+ glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps); glError(); glError();\r
 // if(bFront) glReadBuffer(GL_BACK);\r
 \r
  XS=(float)dx/(float)(udx);\r
@@ -2532,7 +2535,7 @@ long CALLBACK GPUgetScreenPic(unsigned char * pMem)
 \r
  if(!pGfxCardScreen)\r
   {\r
-   glPixelStorei(GL_PACK_ALIGNMENT,1);\r
+   glPixelStorei(GL_PACK_ALIGNMENT,1); glError();\r
    pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);\r
   }\r
 \r
@@ -2540,7 +2543,7 @@ long CALLBACK GPUgetScreenPic(unsigned char * pMem)
 \r
 // glReadBuffer(GL_FRONT);\r
 \r
- glReadPixels(0,0,iResX,iResY,GL_RGB,GL_UNSIGNED_BYTE,ps);\r
+ glReadPixels(0,0,iResX,iResY,GL_RGB,GL_UNSIGNED_BYTE,ps); glError();\r
                \r
 // glReadBuffer(GL_BACK);\r
 \r