-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor oslSetDrawBuffer function for improved readability and maint…
…enance - Added detailed comments explaining each step of the function, particularly focusing on the PSP vs non-PSP (Windows) differences. - Grouped condition checks to reduce redundancy and clarify the logic. - Improved code formatting with better indentation and line spacing. - Ensured that performance considerations are preserved, particularly for non-PSP platforms where the function is known to be slower.
- Loading branch information
Showing
1 changed file
with
30 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,55 @@ | ||
#include "oslib.h" | ||
|
||
/* | ||
Cette fonction est très lente sous windows. Sans les buffers auxiliaires, voici les opérations | ||
qu'elle effectue: | ||
Sauvegarde le contenu du drawbuffer courant vers l'image du drawbuffer courant | ||
Code spécial pour OSL_DEFAULT/OSL_SECONDARY_BUFFER | ||
Ecrit le contenu du nouveau drawbuffer sur la carte graphique | ||
This function is particularly slow on Windows. Without auxiliary buffers, it performs the following operations: | ||
1. Saves the content of the current draw buffer to the associated image. | ||
2. Handles special cases for OSL_DEFAULT/OSL_SECONDARY_BUFFER. | ||
3. Writes the content of the new draw buffer to the GPU. | ||
*/ | ||
void oslSetDrawBuffer(OSL_IMAGE *img) { | ||
void oslSetDrawBuffer(OSL_IMAGE *img) { | ||
#ifdef PSP | ||
// Set the current draw buffer on the PSP | ||
osl_curBuf = img; | ||
sceGuDrawBuffer(img->pixelFormat, oslRemoveVramPrefixPtr(img->data), img->sysSizeX); | ||
#else | ||
//Même image? Aucun intérêt | ||
// Check if the new buffer is the same as the current one; if so, no need to proceed. | ||
if (img == osl_curBuf) | ||
return; | ||
//On doit désactiver (temporairement) le texturage 2D | ||
|
||
// Temporarily disable 2D texturing for the transfer operation | ||
emuConfigure2DTransfer(1); | ||
//Lit les données du backbuffer dans l'image utilisée jusque là comme drawbuffer | ||
if ((osl_curBuf != OSL_SECONDARY_BUFFER && osl_curBuf != OSL_DEFAULT_BUFFER) || (img != OSL_DEFAULT_BUFFER && img != OSL_SECONDARY_BUFFER)) | ||
emuGlReadPixels(0, 272-osl_curBuf->sizeY, osl_curBuf->sysSizeX, osl_curBuf->sizeY, GL_RGBA, osl_curBuf->pixelFormat, osl_curBuf->data); | ||
//OPENGL SPECIFIC!!!! | ||
if (img == OSL_SECONDARY_BUFFER || OSL_DEFAULT_BUFFER->data == OSL_SECONDARY_BUFFER->data) { | ||
|
||
// If the current or new buffer is not a special buffer, read the backbuffer data into the current image. | ||
if ((osl_curBuf != OSL_SECONDARY_BUFFER && osl_curBuf != OSL_DEFAULT_BUFFER) || | ||
(img != OSL_DEFAULT_BUFFER && img != OSL_SECONDARY_BUFFER)) { | ||
emuGlReadPixels(0, 272 - osl_curBuf->sizeY, osl_curBuf->sysSizeX, osl_curBuf->sizeY, GL_RGBA, | ||
osl_curBuf->pixelFormat, osl_curBuf->data); | ||
} | ||
|
||
// Handle OpenGL specifics for buffer switching | ||
if (img == OSL_SECONDARY_BUFFER || OSL_DEFAULT_BUFFER->data == OSL_SECONDARY_BUFFER->data) { | ||
glReadBuffer(GL_FRONT); | ||
glDrawBuffer(GL_FRONT); | ||
} | ||
else { | ||
} else { | ||
glReadBuffer(GL_BACK); | ||
glDrawBuffer(GL_BACK); | ||
} | ||
//Ecrit la nouvelle image sur le backbuffer | ||
if ((osl_curBuf != OSL_SECONDARY_BUFFER && osl_curBuf != OSL_DEFAULT_BUFFER) || (img != OSL_DEFAULT_BUFFER && img != OSL_SECONDARY_BUFFER)) { | ||
|
||
// Draw the new image onto the backbuffer if it's not a special buffer | ||
if ((osl_curBuf != OSL_SECONDARY_BUFFER && osl_curBuf != OSL_DEFAULT_BUFFER) || | ||
(img != OSL_DEFAULT_BUFFER && img != OSL_SECONDARY_BUFFER)) { | ||
glRasterPos2i(0, 0); | ||
glPixelZoom(1, -1); | ||
glDrawPixels(img->sysSizeX, img->sizeY, GL_RGBA, emu_pixelPhysFormats[img->pixelFormat], img->data); | ||
} | ||
|
||
// Update the current draw buffer to the new one | ||
osl_curBuf = img; | ||
//Réactive si jamais | ||
|
||
// Re-enable 2D texturing after the transfer | ||
emuConfigure2DTransfer(0); | ||
#endif | ||
|
||
// Set the screen clipping to the new buffer's size | ||
oslSetScreenClipping(0, 0, img->sizeX, img->sizeY); | ||
} | ||
|