diff --git a/src/image/oslLockImage.c b/src/image/oslLockImage.c index 8b6c236..baf1f70 100644 --- a/src/image/oslLockImage.c +++ b/src/image/oslLockImage.c @@ -1,56 +1,86 @@ #include "oslib.h" /* - Fonctions sp�ciales PC - Permet d'acc�der en soft � une image s�lectionn�e comme drawbuffer ou texture + Special PC Functions + Allows access to an image selected as a draw buffer or texture */ void oslLockImage(OSL_IMAGE *img) { - //Drawbuffer courant? - if (img == osl_curBuf) { - oslSyncDrawing(); - //Avec OpenGL, il faut copier le contenu du drawbuffer sur l'image (vu qu'on va l'utiliser) - #ifndef PSP - //On doit d�sactiver (temporairement) le texturage 2D - int bTextureEnabled = glIsEnabled(GL_TEXTURE_2D), bBlendingEnabled = glIsEnabled(GL_BLEND); - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - //Lit les donn�es du backbuffer dans l'image utilis�e jusque l� comme drawbuffer - emuGlReadPixels(0, 272-osl_curBuf->sizeY, osl_curBuf->sysSizeX, osl_curBuf->sizeY, GL_RGBA, osl_curBuf->pixelFormat, osl_curBuf->data); - //R�active si jamais - if (bTextureEnabled) - glEnable(GL_TEXTURE_2D); - if (bBlendingEnabled) - glEnable(GL_BLEND); - #endif - } + // Check if the image is the current draw buffer + if (img == osl_curBuf) { + // Synchronize drawing before accessing the draw buffer + oslSyncDrawing(); + + #ifndef PSP + // On non-PSP platforms, copy the contents of the draw buffer to the image + int textureEnabled = glIsEnabled(GL_TEXTURE_2D); + int blendingEnabled = glIsEnabled(GL_BLEND); + + // Temporarily disable 2D texturing and blending + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + // Read the pixels from the back buffer into the image data + emuGlReadPixels( + 0, + 272 - osl_curBuf->sizeY, + osl_curBuf->sysSizeX, + osl_curBuf->sizeY, + GL_RGBA, + osl_curBuf->pixelFormat, + osl_curBuf->data + ); + + // Re-enable texturing and blending if they were previously enabled + if (textureEnabled) { + glEnable(GL_TEXTURE_2D); + } + if (blendingEnabled) { + glEnable(GL_BLEND); + } + #endif + } } -//A appeler une fois termin� +// Call this function once the image operations are complete void oslUnlockImage(OSL_IMAGE *img) { -// if (img->location == OSL_IN_RAM) - oslUncacheImage(img); - //Texture courante? - if (img->data == osl_curTexture) - osl_curTexture = NULL; - //Avec OpenGL, on recopie le contenu de l'image (modifi�e) vers le framebuffer - #ifndef PSP - if (img == osl_curBuf) { - //On doit d�sactiver (temporairement) le texturage 2D - int bTextureEnabled = glIsEnabled(GL_TEXTURE_2D), bBlendingEnabled = glIsEnabled(GL_BLEND); - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - //Lit les donn�es du backbuffer dans l'image utilis�e jusque l� comme drawbuffer - glRasterPos2i(0, 0); - glPixelZoom(1, -1); - glDrawPixels(img->sysSizeX, img->sizeY, GL_RGBA, emu_pixelPhysFormats[img->pixelFormat], img->data); - //R�active si jamais - if (bTextureEnabled) - glEnable(GL_TEXTURE_2D); - if (bBlendingEnabled) - glEnable(GL_BLEND); - } - #endif -} + // Uncache the image if it is stored in RAM + oslUncacheImage(img); + + // Check if the image is the current texture + if (img->data == osl_curTexture) { + osl_curTexture = NULL; + } + #ifndef PSP + // On non-PSP platforms, copy the modified image data back to the framebuffer + if (img == osl_curBuf) { + int textureEnabled = glIsEnabled(GL_TEXTURE_2D); + int blendingEnabled = glIsEnabled(GL_BLEND); + + // Temporarily disable 2D texturing and blending + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + // Write the image data back to the framebuffer + glRasterPos2i(0, 0); + glPixelZoom(1, -1); + glDrawPixels( + img->sysSizeX, + img->sizeY, + GL_RGBA, + emu_pixelPhysFormats[img->pixelFormat], + img->data + ); + + // Re-enable texturing and blending if they were previously enabled + if (textureEnabled) { + glEnable(GL_TEXTURE_2D); + } + if (blendingEnabled) { + glEnable(GL_BLEND); + } + } + #endif +}