Skip to content

Commit

Permalink
Refactor oslSetDrawBuffer function for improved readability and maint…
Browse files Browse the repository at this point in the history
…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
dogo committed Sep 1, 2024
1 parent 3c28821 commit 49b20a1
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/image/oslSetDrawBuffer.c
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);
}

0 comments on commit 49b20a1

Please sign in to comment.