OpenGL Renderer:
- Copy read PBO pixels into our own buffer before unmapping the pointer. This is to help avoid tripping up certain drivers. - Do some minor code cleanup.
This commit is contained in:
parent
c7466bc4a1
commit
30ea51bce0
|
@ -61,11 +61,11 @@ static void ENDGL() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We're not exactly committing to OpenGL 3.2 Core Profile just yet, so redefine APPLE
|
// We're not exactly committing to OpenGL 3.2 Core Profile just yet, so redefine APPLE
|
||||||
// extensions for VAO as a temporary measure.
|
// extensions as a temporary measure.
|
||||||
#ifdef GL_APPLE_vertex_array_object
|
#if defined(GL_APPLE_vertex_array_object) && !defined(GL_ARB_vertex_array_object)
|
||||||
#define glGenVertexArrays(a, b) glGenVertexArraysAPPLE(a, b)
|
#define glGenVertexArrays(n, ids) glGenVertexArraysAPPLE(n, ids)
|
||||||
#define glBindVertexArray(a) glBindVertexArrayAPPLE(a)
|
#define glBindVertexArray(id) glBindVertexArrayAPPLE(id)
|
||||||
#define glDeleteVertexArrays(a, b) glDeleteVertexArraysAPPLE(a, b)
|
#define glDeleteVertexArrays(n, ids) glDeleteVertexArraysAPPLE(n, ids)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
@ -140,8 +140,6 @@ static GLuint vboVertexID;
|
||||||
// PBO
|
// PBO
|
||||||
static GLuint pboRenderDataID[2];
|
static GLuint pboRenderDataID[2];
|
||||||
static u8 *pboRenderBuffer[2] = {NULL, NULL};
|
static u8 *pboRenderBuffer[2] = {NULL, NULL};
|
||||||
static bool pboHasNewData[2] = {false, false};
|
|
||||||
static unsigned int pboBufferIndex = 0;
|
|
||||||
|
|
||||||
// Shader states
|
// Shader states
|
||||||
static GLuint vertexShaderID;
|
static GLuint vertexShaderID;
|
||||||
|
@ -172,8 +170,9 @@ static std::queue<GLuint> freeTextureIds;
|
||||||
static GLfloat *color4fBuffer = NULL;
|
static GLfloat *color4fBuffer = NULL;
|
||||||
static GLushort *vertIndexBuffer = NULL;
|
static GLushort *vertIndexBuffer = NULL;
|
||||||
|
|
||||||
static DS_ALIGN(16) u8 GPU_screen3D[256 * 192 * sizeof(u32)];
|
static DS_ALIGN(16) u8 GPU_screen3D[2][256 * 192 * sizeof(u32)];
|
||||||
static bool gpuScreen3DHasNewData = false;
|
static bool gpuScreen3DHasNewData[2] = {false, false};
|
||||||
|
static unsigned int gpuScreen3DBufferIndex = 0;
|
||||||
|
|
||||||
// Lookup Tables
|
// Lookup Tables
|
||||||
static CACHE_ALIGN GLfloat material_8bit_to_float[255] = {0};
|
static CACHE_ALIGN GLfloat material_8bit_to_float[255] = {0};
|
||||||
|
@ -254,7 +253,7 @@ OGLEXT(PFNGLBLITFRAMEBUFFEREXTPROC,glBlitFramebufferEXT);
|
||||||
OGLEXT(PFNGLACTIVETEXTUREPROC,glActiveTexture)
|
OGLEXT(PFNGLACTIVETEXTUREPROC,glActiveTexture)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void OGLConvertFramebuffer(u8 *pixBuffer)
|
static void OGLConvertFramebuffer(const u8 *pixBuffer)
|
||||||
{
|
{
|
||||||
if (pixBuffer == NULL)
|
if (pixBuffer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -289,35 +288,31 @@ static void OGLConvertFramebuffer(u8 *pixBuffer)
|
||||||
|
|
||||||
static void* execReadPixelsTask(void *arg)
|
static void* execReadPixelsTask(void *arg)
|
||||||
{
|
{
|
||||||
u8 *pixBuffer = NULL;
|
const unsigned int bufferIndex = *(unsigned int *)arg;
|
||||||
|
u8 *pixBuffer = GPU_screen3D[bufferIndex];
|
||||||
|
|
||||||
|
if(!BEGINGL()) return 0;
|
||||||
|
|
||||||
if (isPBOSupported)
|
if (isPBOSupported)
|
||||||
{
|
{
|
||||||
unsigned int bufferIndex = *(unsigned int *)arg;
|
|
||||||
|
|
||||||
if(!BEGINGL()) return 0;
|
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboRenderDataID[bufferIndex]);
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboRenderDataID[bufferIndex]);
|
||||||
|
|
||||||
pboRenderBuffer[bufferIndex] = (u8 *)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
|
pboRenderBuffer[bufferIndex] = (u8 *)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
|
||||||
if (pboRenderBuffer[bufferIndex] != NULL)
|
if (pboRenderBuffer[bufferIndex] != NULL)
|
||||||
{
|
{
|
||||||
|
memcpy(pixBuffer, pboRenderBuffer[bufferIndex], 256 * 192 * sizeof(u32));
|
||||||
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
|
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
||||||
ENDGL();
|
|
||||||
|
|
||||||
pixBuffer = pboRenderBuffer[bufferIndex];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!BEGINGL()) return 0;
|
glReadPixels(0, 0, 256, 192, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixBuffer);
|
||||||
glReadPixels(0, 0, 256, 192, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GPU_screen3D);
|
|
||||||
ENDGL();
|
|
||||||
|
|
||||||
pixBuffer = GPU_screen3D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ENDGL();
|
||||||
|
|
||||||
OGLConvertFramebuffer(pixBuffer);
|
OGLConvertFramebuffer(pixBuffer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -509,7 +504,11 @@ static void OGLReset()
|
||||||
delete currTexture;
|
delete currTexture;
|
||||||
currTexture = NULL;
|
currTexture = NULL;
|
||||||
|
|
||||||
memset(GPU_screen3D,0,sizeof(GPU_screen3D));
|
for (unsigned int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
memset(GPU_screen3D[i], 0, sizeof(GPU_screen3D[i]));
|
||||||
|
gpuScreen3DHasNewData[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isFBOSupported)
|
if (isFBOSupported)
|
||||||
{
|
{
|
||||||
|
@ -679,15 +678,10 @@ static char OGLInit(void)
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboRenderDataID[i]);
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboRenderDataID[i]);
|
||||||
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, 256 * 192 * sizeof(u32), NULL, GL_STREAM_READ_ARB);
|
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, 256 * 192 * sizeof(u32), NULL, GL_STREAM_READ_ARB);
|
||||||
pboRenderBuffer[i] = NULL;
|
pboRenderBuffer[i] = NULL;
|
||||||
pboHasNewData[i] = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
gpuScreen3DHasNewData = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render State Setup (common to both shaders and fixed-function pipeline)
|
// Render State Setup (common to both shaders and fixed-function pipeline)
|
||||||
xglEnable(GL_DEPTH_TEST);
|
xglEnable(GL_DEPTH_TEST);
|
||||||
|
@ -880,6 +874,9 @@ static void OGLClose()
|
||||||
isReadPixelsWorking = false;
|
isReadPixelsWorking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gpuScreen3DHasNewData[0] = false;
|
||||||
|
gpuScreen3DHasNewData[1] = false;
|
||||||
|
|
||||||
delete [] vertIndexBuffer;
|
delete [] vertIndexBuffer;
|
||||||
vertIndexBuffer = NULL;
|
vertIndexBuffer = NULL;
|
||||||
|
|
||||||
|
@ -933,12 +930,6 @@ static void OGLClose()
|
||||||
glDeleteBuffersARB(2, pboRenderDataID);
|
glDeleteBuffersARB(2, pboRenderDataID);
|
||||||
pboRenderBuffer[0] = NULL;
|
pboRenderBuffer[0] = NULL;
|
||||||
pboRenderBuffer[1] = NULL;
|
pboRenderBuffer[1] = NULL;
|
||||||
pboHasNewData[0] = false;
|
|
||||||
pboHasNewData[1] = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gpuScreen3DHasNewData = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FBO
|
// FBO
|
||||||
|
@ -983,7 +974,7 @@ static void texDeleteCallback(TexCacheItem* item)
|
||||||
currTexture = NULL;
|
currTexture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTexture(unsigned int format, unsigned int texpal)
|
static void setTexture(u32 format, u32 texpal)
|
||||||
{
|
{
|
||||||
if (format == 0 || currentTexParams.texFormat == TEXMODE_NONE)
|
if (format == 0 || currentTexParams.texFormat == TEXMODE_NONE)
|
||||||
{
|
{
|
||||||
|
@ -1236,6 +1227,20 @@ static void GL_ReadFramebuffer()
|
||||||
isReadPixelsWorking = false;
|
isReadPixelsWorking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bufferIndex = (bufferIndex + 1) & 0x01;
|
||||||
|
gpuScreen3DBufferIndex = bufferIndex;
|
||||||
|
|
||||||
|
if (isPBOSupported)
|
||||||
|
{
|
||||||
|
if(!BEGINGL()) return;
|
||||||
|
|
||||||
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboRenderDataID[bufferIndex]);
|
||||||
|
glReadPixels(0, 0, 256, 192, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 0);
|
||||||
|
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
||||||
|
|
||||||
|
ENDGL();
|
||||||
|
}
|
||||||
|
|
||||||
// If multithreading is ENABLED, call glReadPixels() on a separate thread
|
// If multithreading is ENABLED, call glReadPixels() on a separate thread
|
||||||
// (or glMapBuffer()/glUnmapBuffer() if PBOs are supported). This is a big
|
// (or glMapBuffer()/glUnmapBuffer() if PBOs are supported). This is a big
|
||||||
// deal, since these functions can cause the thread to block. If 3D rendering
|
// deal, since these functions can cause the thread to block. If 3D rendering
|
||||||
|
@ -1251,39 +1256,14 @@ static void GL_ReadFramebuffer()
|
||||||
// H-Blank, and let that logic determine whether a pixel read is needed or not.
|
// H-Blank, and let that logic determine whether a pixel read is needed or not.
|
||||||
// This can save us some time in cases where games don't require the 3D layer
|
// This can save us some time in cases where games don't require the 3D layer
|
||||||
// for this particular frame.
|
// for this particular frame.
|
||||||
if (isPBOSupported)
|
|
||||||
{
|
|
||||||
if(!BEGINGL()) return;
|
|
||||||
|
|
||||||
pboBufferIndex = (pboBufferIndex + 1) % 2;
|
|
||||||
bufferIndex = pboBufferIndex;
|
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboRenderDataID[pboBufferIndex]);
|
|
||||||
glReadPixels(0, 0, 256, 192, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 0);
|
|
||||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
|
||||||
|
|
||||||
ENDGL();
|
|
||||||
|
|
||||||
if (enableMultithreading)
|
if (enableMultithreading)
|
||||||
{
|
{
|
||||||
isReadPixelsWorking = true;
|
isReadPixelsWorking = true;
|
||||||
oglReadPixelsTask.execute(execReadPixelsTask, &bufferIndex);
|
oglReadPixelsTask.execute(&execReadPixelsTask, &bufferIndex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pboHasNewData[pboBufferIndex] = true;
|
gpuScreen3DHasNewData[bufferIndex] = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (enableMultithreading)
|
|
||||||
{
|
|
||||||
isReadPixelsWorking = true;
|
|
||||||
oglReadPixelsTask.execute(execReadPixelsTask, &bufferIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gpuScreen3DHasNewData = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1661,15 +1641,10 @@ static u8* OGLGetLineData(u8 lineNumber)
|
||||||
|
|
||||||
// If we're doing a pixel read on this thread and we have new rendered data,
|
// If we're doing a pixel read on this thread and we have new rendered data,
|
||||||
// then do the pixel read now.
|
// then do the pixel read now.
|
||||||
if (pboHasNewData[pboBufferIndex])
|
if (gpuScreen3DHasNewData[gpuScreen3DBufferIndex])
|
||||||
{
|
{
|
||||||
execReadPixelsTask(&pboBufferIndex);
|
execReadPixelsTask(&gpuScreen3DBufferIndex);
|
||||||
pboHasNewData[pboBufferIndex] = false;
|
gpuScreen3DHasNewData[gpuScreen3DBufferIndex] = false;
|
||||||
}
|
|
||||||
else if (gpuScreen3DHasNewData)
|
|
||||||
{
|
|
||||||
execReadPixelsTask(NULL);
|
|
||||||
gpuScreen3DHasNewData = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( gfx3d_convertedScreen + (lineNumber << (8+2)) );
|
return ( gfx3d_convertedScreen + (lineNumber << (8+2)) );
|
||||||
|
|
Loading…
Reference in New Issue