OpenGL: More changes in preparation of OpenGL ES.

- Slightly change the names of attachment defines so that they can be distinguished from the native OpenGL attachment defines.
- The minimum version driver check now accounts for OpenGL ES.
- OpenGLRendererCreate() can now handle any possible OpenGL variant, as declared in the OpenGLVariantID enum.
- Framebuffer read backs may now assigned their format and data type. (Legacy OpenGL assigns the format as GL_BGRA, while 3.2 Core Profile assigns the format as GL_RGBA.)
This commit is contained in:
rogerman 2024-07-03 16:55:47 -07:00
parent ba56bbc7c2
commit 76fe5f758c
3 changed files with 320 additions and 189 deletions

View File

@ -105,14 +105,14 @@ const GLfloat PostprocessVtxBuffer[16] = {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f}; 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
const GLenum GeometryDrawBuffersEnum[8][4] = { const GLenum GeometryDrawBuffersEnum[8][4] = {
{ GL_COLOROUT_ATTACHMENT_ID, GL_NONE, GL_NONE, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, GL_NONE, GL_NONE, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_NONE, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_NONE, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_POLYID_ATTACHMENT_ID, GL_NONE, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, OGL_POLYID_ATTACHMENT_ID, GL_NONE, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_POLYID_ATTACHMENT_ID, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, OGL_POLYID_ATTACHMENT_ID, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_WORKING_ATTACHMENT_ID, GL_NONE, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, OGL_WORKING_ATTACHMENT_ID, GL_NONE, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_WORKING_ATTACHMENT_ID, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, OGL_WORKING_ATTACHMENT_ID, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_WORKING_ATTACHMENT_ID, GL_POLYID_ATTACHMENT_ID, GL_NONE }, { OGL_COLOROUT_ATTACHMENT_ID, OGL_WORKING_ATTACHMENT_ID, OGL_POLYID_ATTACHMENT_ID, GL_NONE },
{ GL_COLOROUT_ATTACHMENT_ID, GL_WORKING_ATTACHMENT_ID, GL_POLYID_ATTACHMENT_ID, GL_FOGATTRIBUTES_ATTACHMENT_ID } { OGL_COLOROUT_ATTACHMENT_ID, OGL_WORKING_ATTACHMENT_ID, OGL_POLYID_ATTACHMENT_ID, OGL_FOGATTRIBUTES_ATTACHMENT_ID }
}; };
const GLint GeometryAttachmentWorkingBuffer[8] = { const GLint GeometryAttachmentWorkingBuffer[8] = {
@ -161,13 +161,17 @@ void ENDGL()
oglrender_endOpenGL(); oglrender_endOpenGL();
} }
// Function Pointers // OPENGL CLIENT CONTEXT FUNCTION POINTERS
bool (*oglrender_init)() = NULL; bool (*oglrender_init)() = NULL;
bool (*oglrender_beginOpenGL)() = NULL; bool (*oglrender_beginOpenGL)() = NULL;
void (*oglrender_endOpenGL)() = NULL; void (*oglrender_endOpenGL)() = NULL;
bool (*oglrender_framebufferDidResizeCallback)(const bool isFBOSupported, size_t w, size_t h) = NULL; bool (*oglrender_framebufferDidResizeCallback)(const bool isFBOSupported, size_t w, size_t h) = NULL;
// OPENGL RENDERER OBJECT CREATION FUNCTION POINTERS
void (*OGLLoadEntryPoints_3_2_Func)() = NULL; void (*OGLLoadEntryPoints_3_2_Func)() = NULL;
void (*OGLCreateRenderer_3_2_Func)(OpenGLRenderer **rendererPtr) = NULL; void (*OGLCreateRenderer_3_2_Func)(OpenGLRenderer **rendererPtr) = NULL;
void (*OGLLoadEntryPoints_ES_3_0_Func)() = NULL;
void (*OGLCreateRenderer_ES_3_0_Func)(OpenGLRenderer **rendererPtr) = NULL;
//------------------------------------------------------------ //------------------------------------------------------------
@ -942,7 +946,7 @@ void OpenGLTexture::SetUpscalingBuffer(void *upscaleBuffer)
this->_upscaleBuffer = (u32 *)upscaleBuffer; this->_upscaleBuffer = (u32 *)upscaleBuffer;
} }
template<bool require_profile, bool enable_3_2> template <OpenGLVariantID VARIANTID>
static Render3D* OpenGLRendererCreate() static Render3D* OpenGLRendererCreate()
{ {
OpenGLRenderer *newRenderer = NULL; OpenGLRenderer *newRenderer = NULL;
@ -950,18 +954,64 @@ static Render3D* OpenGLRendererCreate()
if (oglrender_init == NULL) if (oglrender_init == NULL)
{ {
return NULL; INFO("OpenGL: oglrender_init is unassigned. Clients must assign this function pointer and have a working context before running OpenGL.\n");
return newRenderer;
}
if (oglrender_beginOpenGL == NULL)
{
INFO("OpenGL: oglrender_beginOpenGL is unassigned. Clients must assign this function pointer before running OpenGL.\n");
return newRenderer;
}
if (oglrender_endOpenGL == NULL)
{
INFO("OpenGL: oglrender_endOpenGL is unassigned. Clients must assign this function pointer before running OpenGL.\n");
return newRenderer;
} }
if (!oglrender_init()) if (!oglrender_init())
{ {
return NULL; return newRenderer;
} }
if (!BEGINGL()) if (!BEGINGL())
{ {
INFO("OpenGL<%s,%s>: Could not initialize -- BEGINGL() failed.\n", require_profile?"force":"auto", enable_3_2?"3_2":"old"); char variantString[32] = {0};
return NULL;
switch (VARIANTID)
{
case OpenGLVariantID_Legacy_1_2:
strncpy(variantString, "Open GL 1.2 (forced)", sizeof(variantString));
break;
case OpenGLVariantID_Legacy_2_0:
strncpy(variantString, "Open GL 2.0 (forced)", sizeof(variantString));
break;
case OpenGLVariantID_Legacy_2_1:
strncpy(variantString, "Open GL 2.1 (forced)", sizeof(variantString));
break;
case OpenGLVariantID_CoreProfile_3_2:
strncpy(variantString, "Open GL 3.2 (forced)", sizeof(variantString));
break;
case OpenGLVariantID_LegacyAuto:
case OpenGLVariantID_StandardAuto:
strncpy(variantString, "Open GL (auto)", sizeof(variantString));
break;
case OpenGLVariantID_ES_3_0:
strncpy(variantString, "Open GL ES 3.0", sizeof(variantString));
break;
default:
break;
}
INFO("%s: Could not initialize -- BEGINGL() failed.\n", variantString);
return newRenderer;
} }
// Get OpenGL info // Get OpenGL info
@ -986,59 +1036,102 @@ static Render3D* OpenGLRendererCreate()
if (!IsOpenGLDriverVersionSupported(OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION)) if (!IsOpenGLDriverVersionSupported(OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION))
{ {
INFO("OpenGL: Driver does not support OpenGL v%u.%u.%u or later. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: Driver does not support OpenGL v%u.%u.%u or later. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR, OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION,
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
ENDGL(); ENDGL();
return newRenderer; return newRenderer;
} }
// Create new OpenGL rendering object // Create new OpenGL rendering object
if (enable_3_2) if (VARIANTID == OpenGLVariantID_ES_3_0)
{ {
if (OGLLoadEntryPoints_3_2_Func != NULL && OGLCreateRenderer_3_2_Func != NULL) if ( (OGLLoadEntryPoints_ES_3_0_Func != NULL) && (OGLCreateRenderer_ES_3_0_Func != NULL) )
{ {
OGLLoadEntryPoints_3_2_Func(); OGLLoadEntryPoints_ES_3_0_Func();
OGLLoadEntryPoints_Legacy(); //zero 04-feb-2013 - this seems to be necessary as well OGLLoadEntryPoints_Legacy();
OGLCreateRenderer_3_2_Func(&newRenderer); OGLCreateRenderer_ES_3_0_Func(&newRenderer);
} }
else else
{ {
if(require_profile) ENDGL();
return newRenderer;
}
}
else
{
if ( (VARIANTID == OpenGLVariantID_StandardAuto) || (VARIANTID == OpenGLVariantID_CoreProfile_3_2) )
{
if ( (OGLLoadEntryPoints_3_2_Func != NULL) && (OGLCreateRenderer_3_2_Func != NULL) )
{
OGLLoadEntryPoints_3_2_Func();
OGLLoadEntryPoints_Legacy(); //zero 04-feb-2013 - this seems to be necessary as well
OGLCreateRenderer_3_2_Func(&newRenderer);
}
else if (VARIANTID == OpenGLVariantID_CoreProfile_3_2)
{ {
ENDGL(); ENDGL();
return newRenderer; return newRenderer;
} }
} }
}
// If the renderer doesn't initialize with OpenGL v3.2 or higher, fall back
// to one of the lower versions.
if (newRenderer == NULL)
{
OGLLoadEntryPoints_Legacy();
if (IsOpenGLDriverVersionSupported(2, 1, 0)) if ( (VARIANTID == OpenGLVariantID_StandardAuto) || (VARIANTID == OpenGLVariantID_LegacyAuto) )
{ {
newRenderer = new OpenGLRenderer_2_1; // If the renderer doesn't initialize with OpenGL v3.2 or higher, fall back
newRenderer->SetVersion(2, 1, 0); // to one of the lower versions.
if (newRenderer == NULL)
{
OGLLoadEntryPoints_Legacy();
if (IsOpenGLDriverVersionSupported(2, 1, 0))
{
newRenderer = new OpenGLRenderer_2_1;
newRenderer->SetVersion(2, 1, 0);
}
else if (IsOpenGLDriverVersionSupported(2, 0, 0))
{
newRenderer = new OpenGLRenderer_2_0;
newRenderer->SetVersion(2, 0, 0);
}
else if (IsOpenGLDriverVersionSupported(1, 2, 0))
{
newRenderer = new OpenGLRenderer_1_2;
newRenderer->SetVersion(1, 2, 0);
}
}
} }
else if (IsOpenGLDriverVersionSupported(2, 0, 0)) else if (VARIANTID == OpenGLVariantID_Legacy_2_1)
{ {
newRenderer = new OpenGLRenderer_2_0; OGLLoadEntryPoints_Legacy();
newRenderer->SetVersion(2, 0, 0); if (IsOpenGLDriverVersionSupported(2, 1, 0))
{
newRenderer = new OpenGLRenderer_2_1;
newRenderer->SetVersion(2, 1, 0);
}
} }
else if (IsOpenGLDriverVersionSupported(1, 2, 0)) else if (VARIANTID == OpenGLVariantID_Legacy_2_0)
{ {
newRenderer = new OpenGLRenderer_1_2; OGLLoadEntryPoints_Legacy();
newRenderer->SetVersion(1, 2, 0); if (IsOpenGLDriverVersionSupported(2, 0, 0))
{
newRenderer = new OpenGLRenderer_2_0;
newRenderer->SetVersion(2, 0, 0);
}
}
else if (VARIANTID == OpenGLVariantID_Legacy_1_2)
{
OGLLoadEntryPoints_Legacy();
if (IsOpenGLDriverVersionSupported(1, 2, 0))
{
newRenderer = new OpenGLRenderer_1_2;
newRenderer->SetVersion(1, 2, 0);
}
} }
} }
if (newRenderer == NULL) if (newRenderer == NULL)
{ {
INFO("OpenGL: Renderer did not initialize. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: Renderer did not initialize. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
ENDGL(); ENDGL();
return newRenderer; return newRenderer;
@ -1051,30 +1144,30 @@ static Render3D* OpenGLRendererCreate()
if (error == OGLERROR_DRIVER_VERSION_TOO_OLD) if (error == OGLERROR_DRIVER_VERSION_TOO_OLD)
{ {
INFO("OpenGL: This driver does not support the minimum feature set required to run this renderer. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: This driver does not support the minimum feature set required to run this renderer. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
} }
else if (newRenderer->IsVersionSupported(1, 5, 0) && (error == OGLERROR_VBO_UNSUPPORTED)) else if (newRenderer->IsVersionSupported(1, 5, 0) && (error == OGLERROR_VBO_UNSUPPORTED))
{ {
INFO("OpenGL: VBOs are not available, even though this version of OpenGL requires them. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: VBOs are not available, even though this version of OpenGL requires them. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
} }
else if ( newRenderer->IsVersionSupported(2, 0, 0) && else if ( newRenderer->IsVersionSupported(2, 0, 0) &&
(error == OGLERROR_SHADER_CREATE_ERROR || (error == OGLERROR_SHADER_CREATE_ERROR ||
error == OGLERROR_VERTEX_SHADER_PROGRAM_LOAD_ERROR || error == OGLERROR_VERTEX_SHADER_PROGRAM_LOAD_ERROR ||
error == OGLERROR_FRAGMENT_SHADER_PROGRAM_LOAD_ERROR) ) error == OGLERROR_FRAGMENT_SHADER_PROGRAM_LOAD_ERROR) )
{ {
INFO("OpenGL: Shaders are not working, even though they should be on this version of OpenGL. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: Shaders are not working, even though they should be on this version of OpenGL. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
} }
else if (newRenderer->IsVersionSupported(2, 1, 0) && (error == OGLERROR_PBO_UNSUPPORTED)) else if (newRenderer->IsVersionSupported(2, 1, 0) && (error == OGLERROR_PBO_UNSUPPORTED))
{ {
INFO("OpenGL: PBOs are not available, even though this version of OpenGL requires them. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: PBOs are not available, even though this version of OpenGL requires them. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
} }
else if (newRenderer->IsVersionSupported(3, 0, 0) && (error == OGLERROR_FBO_CREATE_ERROR) && (OGLLoadEntryPoints_3_2_Func != NULL)) else if (newRenderer->IsVersionSupported(3, 0, 0) && (error == OGLERROR_FBO_CREATE_ERROR) && (OGLLoadEntryPoints_3_2_Func != NULL))
{ {
INFO("OpenGL: FBOs are not available, even though this version of OpenGL requires them. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: FBOs are not available, even though this version of OpenGL requires them. Disabling 3D renderer.\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
oglVersionString, oglVendorString, oglRendererString); oglVersionString, oglVendorString, oglRendererString);
} }
delete newRenderer; delete newRenderer;
@ -1095,7 +1188,7 @@ static Render3D* OpenGLRendererCreate()
newRenderer->GetVersion(&major, &minor, &revision); newRenderer->GetVersion(&major, &minor, &revision);
INFO("OpenGL: Renderer initialized successfully (v%u.%u.%u).\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n", INFO("OpenGL: Renderer initialized successfully (v%u.%u.%u).\n[ Driver Info -\n Version: %s\n Vendor: %s\n Renderer: %s ]\n",
major, minor, revision, oglVersionString, oglVendorString, oglRendererString); major, minor, revision, oglVersionString, oglVendorString, oglRendererString);
return newRenderer; return newRenderer;
} }
@ -1118,27 +1211,34 @@ static void OpenGLRendererDestroy()
//automatically select 3.2 or old profile depending on whether 3.2 is available //automatically select 3.2 or old profile depending on whether 3.2 is available
GPU3DInterface gpu3Dgl = { GPU3DInterface gpu3Dgl = {
"OpenGL", "OpenGL",
OpenGLRendererCreate<false,true>, OpenGLRendererCreate<OpenGLVariantID_StandardAuto>,
OpenGLRendererDestroy OpenGLRendererDestroy
}; };
//forcibly use old profile //forcibly use old profile
GPU3DInterface gpu3DglOld = { GPU3DInterface gpu3DglOld = {
"OpenGL Old", "OpenGL Old",
OpenGLRendererCreate<true,false>, OpenGLRendererCreate<OpenGLVariantID_LegacyAuto>,
OpenGLRendererDestroy OpenGLRendererDestroy
}; };
//forcibly use new profile //forcibly use new profile
GPU3DInterface gpu3Dgl_3_2 = { GPU3DInterface gpu3Dgl_3_2 = {
"OpenGL 3.2", "OpenGL 3.2",
OpenGLRendererCreate<true,true>, OpenGLRendererCreate<OpenGLVariantID_CoreProfile_3_2>,
OpenGLRendererDestroy
};
// OpenGL ES 3.0 (this is the only version of ES that is supported right now)
GPU3DInterface gpu3Dgl_ES_3_0 = {
"OpenGL ES 3.0",
OpenGLRendererCreate<OpenGLVariantID_ES_3_0>,
OpenGLRendererDestroy OpenGLRendererDestroy
}; };
OpenGLRenderer::OpenGLRenderer() OpenGLRenderer::OpenGLRenderer()
{ {
_variantID = OpenGLVariantID_Legacy; _variantID = OpenGLVariantID_LegacyAuto;
_deviceInfo.renderID = RENDERID_OPENGL_AUTO; _deviceInfo.renderID = RENDERID_OPENGL_AUTO;
_deviceInfo.renderName = "OpenGL"; _deviceInfo.renderName = "OpenGL";
@ -2433,6 +2533,10 @@ Render3DError OpenGLRenderer_1_2::InitExtensions()
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropyOGL); glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropyOGL);
this->_deviceInfo.maxAnisotropy = maxAnisotropyOGL; this->_deviceInfo.maxAnisotropy = maxAnisotropyOGL;
// This is traditionally the fastest format and data type for glReadPixels in legacy mode.
OGLRef.readPixelsBestFormat = GL_BGRA;
OGLRef.readPixelsBestDataType = GL_UNSIGNED_BYTE;
// Need to generate this texture first because FBO creation needs it. // Need to generate this texture first because FBO creation needs it.
// This texture is only required by shaders, and so if shader creation // This texture is only required by shaders, and so if shader creation
// fails, then we can immediately delete this texture if an error occurs. // fails, then we can immediately delete this texture if an error occurs.
@ -2873,8 +2977,8 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
glGenFramebuffersEXT(1, &OGLRef.fboRenderID); glGenFramebuffersEXT(1, &OGLRef.fboRenderID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboClearImageID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboClearImageID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIColorID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIColorID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0);
@ -2887,8 +2991,8 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
} }
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboFramebufferFlipID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboFramebufferFlipID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGColorID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGColorID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texFinalColorID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texFinalColorID, 0);
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
{ {
@ -2899,10 +3003,10 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
} }
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGColorID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGColorID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_POLYID_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGPolyID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_POLYID_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGPolyID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texFinalColorID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, OGL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texFinalColorID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0);
@ -2914,8 +3018,8 @@ Render3DError OpenGLRenderer_1_2::CreateFBOs()
return OGLERROR_FBO_CREATE_ERROR; return OGLERROR_FBO_CREATE_ERROR;
} }
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
OGLRef.selectedRenderingFBO = OGLRef.fboRenderID; OGLRef.selectedRenderingFBO = OGLRef.fboRenderID;
INFO("OpenGL: Successfully created FBOs.\n"); INFO("OpenGL: Successfully created FBOs.\n");
@ -2976,10 +3080,10 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO(GLsizei numSamples)
// Set up multisampled rendering FBO // Set up multisampled rendering FBO
glGenFramebuffersEXT(1, &OGLRef.fboMSIntermediateRenderID); glGenFramebuffersEXT(1, &OGLRef.fboMSIntermediateRenderID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOROUT_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGColorID); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, OGL_COLOROUT_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGColorID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_POLYID_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGPolyID); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, OGL_POLYID_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGPolyID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGFogAttrID); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGFogAttrID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_WORKING_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGWorkingID); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, OGL_WORKING_ATTACHMENT_ID, GL_RENDERBUFFER_EXT, OGLRef.rboMSGWorkingID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthStencilID); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthStencilID);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthStencilID); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, OGLRef.rboMSGDepthStencilID);
@ -2991,8 +3095,8 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO(GLsizei numSamples)
return OGLERROR_FBO_CREATE_ERROR; return OGLERROR_FBO_CREATE_ERROR;
} }
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
INFO("OpenGL: Successfully created multisampled FBO.\n"); INFO("OpenGL: Successfully created multisampled FBO.\n");
@ -3853,7 +3957,7 @@ void OpenGLRenderer_1_2::_SetupGeometryShaders(const OGLGeometryFlags flags)
{ {
if (this->isFBOSupported) if (this->isFBOSupported)
{ {
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
return; return;
} }
@ -3954,7 +4058,7 @@ Render3DError OpenGLRenderer_1_2::ZeroDstAlphaPass(const POLY *rawPolyList, cons
// Just downsample the color buffer now so that we have some texture data to sample from in the non-multisample shader. // Just downsample the color buffer now so that we have some texture data to sample from in the non-multisample shader.
// This is not perfectly pixel accurate, but it's better than nothing. // This is not perfectly pixel accurate, but it's better than nothing.
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]); glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
@ -4003,7 +4107,7 @@ Render3DError OpenGLRenderer_1_2::ZeroDstAlphaPass(const POLY *rawPolyList, cons
this->_geometryProgramFlags.EnableEdgeMark = 0; this->_geometryProgramFlags.EnableEdgeMark = 0;
this->_geometryProgramFlags.EnableFog = 0; this->_geometryProgramFlags.EnableFog = 0;
this->_SetupGeometryShaders(this->_geometryProgramFlags); this->_SetupGeometryShaders(this->_geometryProgramFlags);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboGeometryVtxID); glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboGeometryVtxID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboGeometryIndexID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboGeometryIndexID);
@ -4048,12 +4152,12 @@ void OpenGLRenderer_1_2::_ResolveWorkingBackFacing()
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID); glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glReadBuffer(GL_WORKING_ATTACHMENT_ID); glReadBuffer(OGL_WORKING_ATTACHMENT_ID);
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Reset framebuffer targets // Reset framebuffer targets
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]); glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboMSIntermediateRenderID);
@ -4076,21 +4180,21 @@ void OpenGLRenderer_1_2::_ResolveGeometry()
{ {
if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported) if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported)
{ {
glReadBuffer(GL_POLYID_ATTACHMENT_ID); glReadBuffer(OGL_POLYID_ATTACHMENT_ID);
glDrawBuffer(GL_POLYID_ATTACHMENT_ID); glDrawBuffer(OGL_POLYID_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
if (this->_enableFog && this->_deviceInfo.isFogSupported) if (this->_enableFog && this->_deviceInfo.isFogSupported)
{ {
glReadBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glReadBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
// Blit the color and depth buffers // Blit the color and depth buffers
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
// Reset framebuffer targets // Reset framebuffer targets
@ -4103,8 +4207,8 @@ void OpenGLRenderer_1_2::_ResolveGeometry()
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
} }
@ -4122,16 +4226,16 @@ Render3DError OpenGLRenderer_1_2::ReadBackPixels()
{ {
const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[1] : OGLRef.programFramebufferRGBA8888OutputID[1]; const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[1] : OGLRef.programFramebufferRGBA8888OutputID[1];
glUseProgram(convertProgramID); glUseProgram(convertProgramID);
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glReadBuffer(GL_WORKING_ATTACHMENT_ID); glReadBuffer(OGL_WORKING_ATTACHMENT_ID);
this->_lastTextureDrawTarget = OGLTextureUnitID_FinalColor; this->_lastTextureDrawTarget = OGLTextureUnitID_FinalColor;
} }
else else
{ {
const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[0] : OGLRef.programFramebufferRGBA8888OutputID[0]; const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[0] : OGLRef.programFramebufferRGBA8888OutputID[0];
glUseProgram(convertProgramID); glUseProgram(convertProgramID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
this->_lastTextureDrawTarget = OGLTextureUnitID_GColor; this->_lastTextureDrawTarget = OGLTextureUnitID_GColor;
} }
} }
@ -4181,7 +4285,7 @@ Render3DError OpenGLRenderer_1_2::ReadBackPixels()
// Just flips the framebuffer in Y to match the coordinates of OpenGL and the NDS hardware. // Just flips the framebuffer in Y to match the coordinates of OpenGL and the NDS hardware.
// Further colorspace conversion will need to be done in a later step. // Further colorspace conversion will need to be done in a later step.
const GLenum flipTarget = (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor) ? GL_WORKING_ATTACHMENT_ID : GL_COLOROUT_ATTACHMENT_ID; const GLenum flipTarget = (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor) ? OGL_WORKING_ATTACHMENT_ID : OGL_COLOROUT_ATTACHMENT_ID;
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboFramebufferFlipID); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboFramebufferFlipID);
glDrawBuffer(flipTarget); glDrawBuffer(flipTarget);
@ -4202,7 +4306,7 @@ Render3DError OpenGLRenderer_1_2::ReadBackPixels()
this->_mappedFramebuffer = NULL; this->_mappedFramebuffer = NULL;
} }
glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0); glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, OGLRef.readPixelsBestFormat, OGLRef.readPixelsBestDataType, 0);
} }
this->_pixelReadNeedsFinish = true; this->_pixelReadNeedsFinish = true;
@ -4417,12 +4521,12 @@ Render3DError OpenGLRenderer_1_2::BeginRender(const GFX3D_State &renderState, co
if (this->isFBOSupported) if (this->isFBOSupported)
{ {
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
} }
#endif #endif
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@ -4573,7 +4677,7 @@ Render3DError OpenGLRenderer_1_2::PostprocessFramebuffer()
glBindTexture(GL_TEXTURE_1D, OGLRef.texEdgeColorTableID); glBindTexture(GL_TEXTURE_1D, OGLRef.texEdgeColorTableID);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glUseProgram(OGLRef.programEdgeMarkID); glUseProgram(OGLRef.programEdgeMarkID);
glUniform1i(OGLRef.uniformStateClearPolyID, this->_pendingRenderStates.clearPolyID); glUniform1i(OGLRef.uniformStateClearPolyID, this->_pendingRenderStates.clearPolyID);
glUniform1f(OGLRef.uniformStateClearDepth, this->_pendingRenderStates.clearDepth); glUniform1f(OGLRef.uniformStateClearDepth, this->_pendingRenderStates.clearDepth);
@ -4596,7 +4700,7 @@ Render3DError OpenGLRenderer_1_2::PostprocessFramebuffer()
glUseProgram(OGLRef.programEdgeMarkID); glUseProgram(OGLRef.programEdgeMarkID);
glUniform1i(OGLRef.uniformStateClearPolyID, this->_pendingRenderStates.clearPolyID); glUniform1i(OGLRef.uniformStateClearPolyID, this->_pendingRenderStates.clearPolyID);
glUniform1f(OGLRef.uniformStateClearDepth, this->_pendingRenderStates.clearDepth); glUniform1f(OGLRef.uniformStateClearDepth, this->_pendingRenderStates.clearDepth);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@ -4622,7 +4726,7 @@ Render3DError OpenGLRenderer_1_2::PostprocessFramebuffer()
OGLFogShaderID shaderID = this->_fogProgramMap[this->_fogProgramKey.key]; OGLFogShaderID shaderID = this->_fogProgramMap[this->_fogProgramKey.key];
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glUseProgram(shaderID.program); glUseProgram(shaderID.program);
glUniform1i(OGLRef.uniformStateEnableFogAlphaOnly, this->_pendingRenderStates.enableFogAlphaOnly); glUniform1i(OGLRef.uniformStateEnableFogAlphaOnly, this->_pendingRenderStates.enableFogAlphaOnly);
glUniform4fv(OGLRef.uniformStateFogColor, 1, (const GLfloat *)&this->_pendingRenderStates.fogColor); glUniform4fv(OGLRef.uniformStateFogColor, 1, (const GLfloat *)&this->_pendingRenderStates.fogColor);
@ -4686,28 +4790,28 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
{ {
if (this->_emulateDepthLEqualPolygonFacing && this->_isDepthLEqualPolygonFacingSupported) if (this->_emulateDepthLEqualPolygonFacing && this->_isDepthLEqualPolygonFacingSupported)
{ {
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported) if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported)
{ {
glDrawBuffer(GL_POLYID_ATTACHMENT_ID); glDrawBuffer(OGL_POLYID_ATTACHMENT_ID);
glClearColor((GLfloat)opaquePolyID/63.0f, 0.0, 0.0, 1.0); glClearColor((GLfloat)opaquePolyID/63.0f, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
if (this->_enableFog && this->_deviceInfo.isFogSupported) if (this->_enableFog && this->_deviceInfo.isFogSupported)
{ {
glReadBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glReadBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
// Blit the color buffer. Do this last so that color attachment 0 is set to the read FBO. // Blit the color buffer. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
@ -4717,8 +4821,8 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
{ {
glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
if (this->isMultisampledFBOSupported) if (this->isMultisampledFBOSupported)
@ -4737,28 +4841,28 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
{ {
if (this->_emulateDepthLEqualPolygonFacing && this->_isDepthLEqualPolygonFacingSupported) if (this->_emulateDepthLEqualPolygonFacing && this->_isDepthLEqualPolygonFacingSupported)
{ {
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported) if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported)
{ {
glDrawBuffer(GL_POLYID_ATTACHMENT_ID); glDrawBuffer(OGL_POLYID_ATTACHMENT_ID);
glClearColor((GLfloat)opaquePolyID/63.0f, 0.0, 0.0, 1.0); glClearColor((GLfloat)opaquePolyID/63.0f, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
if (this->_enableFog && this->_deviceInfo.isFogSupported) if (this->_enableFog && this->_deviceInfo.isFogSupported)
{ {
glReadBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glReadBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
// Blit the color and depth buffers. Do this last so that color attachment 0 is set to the read FBO. // Blit the color and depth buffers. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
@ -4770,8 +4874,8 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf
glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBlitFramebufferEXT(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
} }
} }
@ -4791,7 +4895,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const Color4u8 &clearColor666
if (this->isShaderSupported && this->isFBOSupported) if (this->isShaderSupported && this->isFBOSupported)
{ {
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glClearColor(divide6bitBy63_LUT[clearColor6665.r], divide6bitBy63_LUT[clearColor6665.g], divide6bitBy63_LUT[clearColor6665.b], divide5bitBy31_LUT[clearColor6665.a]); glClearColor(divide6bitBy63_LUT[clearColor6665.r], divide6bitBy63_LUT[clearColor6665.g], divide6bitBy63_LUT[clearColor6665.b], divide5bitBy31_LUT[clearColor6665.a]);
glClearDepth((GLclampd)clearAttributes.depth / (GLclampd)0x00FFFFFF); glClearDepth((GLclampd)clearAttributes.depth / (GLclampd)0x00FFFFFF);
glClearStencil(clearAttributes.opaquePolyID); glClearStencil(clearAttributes.opaquePolyID);
@ -4799,21 +4903,21 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const Color4u8 &clearColor666
if (this->_emulateDepthLEqualPolygonFacing && this->_isDepthLEqualPolygonFacingSupported) if (this->_emulateDepthLEqualPolygonFacing && this->_isDepthLEqualPolygonFacingSupported)
{ {
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported) if (this->_enableEdgeMark && this->_deviceInfo.isEdgeMarkSupported)
{ {
glDrawBuffer(GL_POLYID_ATTACHMENT_ID); glDrawBuffer(OGL_POLYID_ATTACHMENT_ID);
glClearColor((GLfloat)clearAttributes.opaquePolyID/63.0f, 0.0, 0.0, 1.0); glClearColor((GLfloat)clearAttributes.opaquePolyID/63.0f, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
if (this->_enableFog && this->_deviceInfo.isFogSupported) if (this->_enableFog && this->_deviceInfo.isFogSupported)
{ {
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glClearColor(clearAttributes.isFogged, 0.0, 0.0, 1.0); glClearColor(clearAttributes.isFogged, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
@ -4825,8 +4929,8 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const Color4u8 &clearColor666
{ {
if (this->isFBOSupported) if (this->isFBOSupported)
{ {
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
glClearColor(divide6bitBy63_LUT[clearColor6665.r], divide6bitBy63_LUT[clearColor6665.g], divide6bitBy63_LUT[clearColor6665.b], divide5bitBy31_LUT[clearColor6665.a]); glClearColor(divide6bitBy63_LUT[clearColor6665.r], divide6bitBy63_LUT[clearColor6665.g], divide6bitBy63_LUT[clearColor6665.b], divide5bitBy31_LUT[clearColor6665.a]);
@ -5233,8 +5337,8 @@ Render3DError OpenGLRenderer_1_2::RenderPowerOff()
if (this->isFBOSupported) if (this->isFBOSupported)
{ {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@ -5248,7 +5352,7 @@ Render3DError OpenGLRenderer_1_2::RenderPowerOff()
this->_mappedFramebuffer = NULL; this->_mappedFramebuffer = NULL;
} }
glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0); glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, OGLRef.readPixelsBestFormat, OGLRef.readPixelsBestDataType, 0);
} }
ENDGL(); ENDGL();
@ -5259,6 +5363,8 @@ Render3DError OpenGLRenderer_1_2::RenderPowerOff()
Render3DError OpenGLRenderer_1_2::RenderFinish() Render3DError OpenGLRenderer_1_2::RenderFinish()
{ {
OGLRenderRef &OGLRef = *this->ref;
if (!this->_renderNeedsFinish) if (!this->_renderNeedsFinish)
{ {
return OGLERROR_NOERR; return OGLERROR_NOERR;
@ -5281,7 +5387,7 @@ Render3DError OpenGLRenderer_1_2::RenderFinish()
} }
else else
{ {
glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, this->_framebufferColor); glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, OGLRef.readPixelsBestFormat, OGLRef.readPixelsBestDataType, this->_framebufferColor);
} }
ENDGL(); ENDGL();
@ -5622,7 +5728,7 @@ Render3DError OpenGLRenderer_2_0::BeginRender(const GFX3D_State &renderState, co
glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 32, GL_RGBA, OGL_TEXTURE_SRC_TOON_TABLE, renderState.toonTable16); glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 32, GL_RGBA, OGL_TEXTURE_SRC_TOON_TABLE, renderState.toonTable16);
} }
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);

View File

@ -305,31 +305,43 @@ EXTERNOGLEXT(PFNGLDELETERENDERBUFFERSEXTPROC, glDeleteRenderbuffersEXT)
#endif // GL_EXT_framebuffer_object #endif // GL_EXT_framebuffer_object
// Define the minimum required OpenGL version for the driver to support // Define the minimum required OpenGL version for the driver to support
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR 1 #if defined(OPENGL_VARIANT_STANDARD)
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR 2 #define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR 1
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION 0 #define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR 2
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION 0
#elif defined(OPENGL_VARIANT_ES)
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MAJOR 3
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_MINOR 0
#define OGLRENDER_MINIMUM_DRIVER_VERSION_REQUIRED_REVISION 0
#else
#error Unknown OpenGL variant.
#endif
#define OGLRENDER_VERT_INDEX_BUFFER_COUNT (CLIPPED_POLYLIST_SIZE * 6) #define OGLRENDER_VERT_INDEX_BUFFER_COUNT (CLIPPED_POLYLIST_SIZE * 6)
// Assign the FBO attachments for the main geometry render // Assign the FBO attachments for the main geometry render
#if defined(GL_VERSION_3_0) || defined(GL_ES_VERSION_3_0) #if defined(GL_VERSION_3_0) || defined(GL_ES_VERSION_3_0)
#define GL_COLOROUT_ATTACHMENT_ID GL_COLOR_ATTACHMENT0 #define OGL_COLOROUT_ATTACHMENT_ID GL_COLOR_ATTACHMENT0
#define GL_WORKING_ATTACHMENT_ID GL_COLOR_ATTACHMENT3 #define OGL_WORKING_ATTACHMENT_ID GL_COLOR_ATTACHMENT3
#define GL_POLYID_ATTACHMENT_ID GL_COLOR_ATTACHMENT1 #define OGL_POLYID_ATTACHMENT_ID GL_COLOR_ATTACHMENT1
#define GL_FOGATTRIBUTES_ATTACHMENT_ID GL_COLOR_ATTACHMENT2 #define OGL_FOGATTRIBUTES_ATTACHMENT_ID GL_COLOR_ATTACHMENT2
#else #else
#define GL_COLOROUT_ATTACHMENT_ID GL_COLOR_ATTACHMENT0_EXT #define OGL_COLOROUT_ATTACHMENT_ID GL_COLOR_ATTACHMENT0_EXT
#define GL_WORKING_ATTACHMENT_ID GL_COLOR_ATTACHMENT3_EXT #define OGL_WORKING_ATTACHMENT_ID GL_COLOR_ATTACHMENT3_EXT
#define GL_POLYID_ATTACHMENT_ID GL_COLOR_ATTACHMENT1_EXT #define OGL_POLYID_ATTACHMENT_ID GL_COLOR_ATTACHMENT1_EXT
#define GL_FOGATTRIBUTES_ATTACHMENT_ID GL_COLOR_ATTACHMENT2_EXT #define OGL_FOGATTRIBUTES_ATTACHMENT_ID GL_COLOR_ATTACHMENT2_EXT
#endif #endif
enum OpenGLVariantID enum OpenGLVariantID
{ {
OpenGLVariantID_Unknown = 0, OpenGLVariantID_Unknown = 0,
OpenGLVariantID_Legacy = 1, OpenGLVariantID_LegacyAuto = 0x1000,
OpenGLVariantID_CoreProfile_3_2 = 2, OpenGLVariantID_Legacy_1_2 = 0x1012,
OpenGLVariantID_ES_3_0 = 3 OpenGLVariantID_Legacy_2_0 = 0x1020,
OpenGLVariantID_Legacy_2_1 = 0x1021,
OpenGLVariantID_CoreProfile_3_2 = 0x2032,
OpenGLVariantID_StandardAuto = 0x3000,
OpenGLVariantID_ES_3_0 = 0x4030
}; };
enum OGLVertexAttributeID enum OGLVertexAttributeID
@ -528,6 +540,8 @@ struct OGLRenderRef
{ {
// OpenGL Feature Support // OpenGL Feature Support
GLint stateTexMirroredRepeat; GLint stateTexMirroredRepeat;
GLint readPixelsBestDataType;
GLint readPixelsBestFormat;
// VBO // VBO
GLuint vboGeometryVtxID; GLuint vboGeometryVtxID;
@ -681,6 +695,15 @@ void ENDGL();
extern void (*OGLLoadEntryPoints_3_2_Func)(); extern void (*OGLLoadEntryPoints_3_2_Func)();
extern void (*OGLCreateRenderer_3_2_Func)(OpenGLRenderer **rendererPtr); extern void (*OGLCreateRenderer_3_2_Func)(OpenGLRenderer **rendererPtr);
// These functions need to be assigned by ports that support using an
// OpenGL ES 3.0 context. The OGLRender_ES3.cpp file includes the corresponding
// functions to assign to each function pointer.
//
// If any of these functions are unassigned, then the renderer object
// creation will fail.
extern void (*OGLLoadEntryPoints_ES_3_0_Func)();
extern void (*OGLCreateRenderer_ES_3_0_Func)(OpenGLRenderer **rendererPtr);
bool IsOpenGLDriverVersionSupported(unsigned int checkVersionMajor, unsigned int checkVersionMinor, unsigned int checkVersionRevision); bool IsOpenGLDriverVersionSupported(unsigned int checkVersionMajor, unsigned int checkVersionMinor, unsigned int checkVersionRevision);
class OpenGLTexture : public Render3DTexture class OpenGLTexture : public Render3DTexture

View File

@ -593,9 +593,7 @@ out vec4 outFragColor6665;\n\
\n\ \n\
void main()\n\ void main()\n\
{\n\ {\n\
// Note that we swap B and R since pixel readbacks are done in BGRA format for fastest\n\ outFragColor6665 = texelFetch(texInFragColor, ivec2(gl_FragCoord.x, FRAMEBUFFER_SIZE_Y - gl_FragCoord.y), 0);\n\
// performance. The final color is still in RGBA format.\n\
outFragColor6665 = texelFetch(texInFragColor, ivec2(gl_FragCoord.x, FRAMEBUFFER_SIZE_Y - gl_FragCoord.y), 0).bgra;\n\
outFragColor6665 = floor((outFragColor6665 * 255.0) + 0.5);\n\ outFragColor6665 = floor((outFragColor6665 * 255.0) + 0.5);\n\
outFragColor6665.rgb = floor(outFragColor6665.rgb / 4.0);\n\ outFragColor6665.rgb = floor(outFragColor6665.rgb / 4.0);\n\
outFragColor6665.a = floor(outFragColor6665.a / 8.0);\n\ outFragColor6665.a = floor(outFragColor6665.a / 8.0);\n\
@ -654,6 +652,10 @@ Render3DError OpenGLRenderer_3_2::InitExtensions()
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropyOGL); glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropyOGL);
this->_deviceInfo.maxAnisotropy = (float)maxAnisotropyOGL; this->_deviceInfo.maxAnisotropy = (float)maxAnisotropyOGL;
// OpenGL 3.2 should be able to handle the GL_RGBA format in glReadPixels without any performance penalty.
OGLRef.readPixelsBestFormat = GL_RGBA;
OGLRef.readPixelsBestDataType = GL_UNSIGNED_BYTE;
this->_deviceInfo.isEdgeMarkSupported = true; this->_deviceInfo.isEdgeMarkSupported = true;
this->_deviceInfo.isFogSupported = true; this->_deviceInfo.isFogSupported = true;
@ -893,8 +895,8 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glGenFramebuffers(1, &OGLRef.fboRenderID); glGenFramebuffers(1, &OGLRef.fboRenderID);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboClearImageID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboClearImageID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIColorID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIColorID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texCIFogAttrID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, OGLRef.texCIDepthStencilID, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@ -906,10 +908,10 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
} }
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGColorID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGColorID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_POLYID_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGPolyID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_POLYID_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGPolyID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texGFogAttrID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texFinalColorID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D, OGLRef.texFinalColorID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, OGLRef.texGDepthStencilID, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@ -1008,17 +1010,17 @@ Render3DError OpenGLRenderer_3_2::CreateMultisampledFBO(GLsizei numSamples)
if (this->willUsePerSampleZeroDstPass) if (this->willUsePerSampleZeroDstPass)
{ {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D_MULTISAMPLE, OGLRef.texMSGColorID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_COLOROUT_ATTACHMENT_ID, GL_TEXTURE_2D_MULTISAMPLE, OGLRef.texMSGColorID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D_MULTISAMPLE, OGLRef.texMSGWorkingID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, OGL_WORKING_ATTACHMENT_ID, GL_TEXTURE_2D_MULTISAMPLE, OGLRef.texMSGWorkingID, 0);
} }
else else
{ {
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOROUT_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGColorID); glFramebufferRenderbuffer(GL_FRAMEBUFFER, OGL_COLOROUT_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGColorID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_WORKING_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGWorkingID); glFramebufferRenderbuffer(GL_FRAMEBUFFER, OGL_WORKING_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGWorkingID);
} }
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_POLYID_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGPolyID); glFramebufferRenderbuffer(GL_FRAMEBUFFER, OGL_POLYID_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGPolyID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_FOGATTRIBUTES_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGFogAttrID); glFramebufferRenderbuffer(GL_FRAMEBUFFER, OGL_FOGATTRIBUTES_ATTACHMENT_ID, GL_RENDERBUFFER, OGLRef.rboMSGFogAttrID);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, OGLRef.rboMSGDepthStencilID); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, OGLRef.rboMSGDepthStencilID);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@ -1794,7 +1796,7 @@ Render3DError OpenGLRenderer_3_2::ZeroDstAlphaPass(const POLY *rawPolyList, cons
// Just downsample the color buffer now so that we have some texture data to sample from in the non-multisample shader. // Just downsample the color buffer now so that we have some texture data to sample from in the non-multisample shader.
// This is not perfectly pixel accurate, but it's better than nothing. // This is not perfectly pixel accurate, but it's better than nothing.
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.fboRenderID); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.fboRenderID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]); glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
@ -1822,7 +1824,7 @@ Render3DError OpenGLRenderer_3_2::ZeroDstAlphaPass(const POLY *rawPolyList, cons
this->_geometryProgramFlags.EnableEdgeMark = 0; this->_geometryProgramFlags.EnableEdgeMark = 0;
this->_geometryProgramFlags.EnableFog = 0; this->_geometryProgramFlags.EnableFog = 0;
this->_SetupGeometryShaders(this->_geometryProgramFlags); this->_SetupGeometryShaders(this->_geometryProgramFlags);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboGeometryVtxID); glBindBuffer(GL_ARRAY_BUFFER, OGLRef.vboGeometryVtxID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboGeometryIndexID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OGLRef.iboGeometryIndexID);
@ -1867,12 +1869,12 @@ void OpenGLRenderer_3_2::_ResolveWorkingBackFacing()
glBindFramebuffer(GL_READ_FRAMEBUFFER, OGLRef.fboMSIntermediateRenderID); glBindFramebuffer(GL_READ_FRAMEBUFFER, OGLRef.fboMSIntermediateRenderID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.fboRenderID); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.fboRenderID);
glReadBuffer(GL_WORKING_ATTACHMENT_ID); glReadBuffer(OGL_WORKING_ATTACHMENT_ID);
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
// Reset framebuffer targets // Reset framebuffer targets
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]); glDrawBuffers(4, GeometryDrawBuffersEnum[this->_geometryProgramFlags.DrawBuffersMode]);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboMSIntermediateRenderID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboMSIntermediateRenderID);
@ -1893,21 +1895,21 @@ void OpenGLRenderer_3_2::_ResolveGeometry()
if (this->_enableEdgeMark) if (this->_enableEdgeMark)
{ {
glReadBuffer(GL_POLYID_ATTACHMENT_ID); glReadBuffer(OGL_POLYID_ATTACHMENT_ID);
glDrawBuffer(GL_POLYID_ATTACHMENT_ID); glDrawBuffer(OGL_POLYID_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
if (this->_enableFog) if (this->_enableFog)
{ {
glReadBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glReadBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
// Blit the color and depth buffers // Blit the color and depth buffers
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
// Reset framebuffer targets // Reset framebuffer targets
@ -1927,15 +1929,15 @@ Render3DError OpenGLRenderer_3_2::ReadBackPixels()
{ {
// Use the alternate program where the output color is not at index 0. // Use the alternate program where the output color is not at index 0.
glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[1]); glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[1]);
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glReadBuffer(GL_WORKING_ATTACHMENT_ID); glReadBuffer(OGL_WORKING_ATTACHMENT_ID);
} }
else else
{ {
// Use the program where the output color is from index 0. // Use the program where the output color is from index 0.
glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[0]); glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[0]);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
glViewport(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight); glViewport(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight);
@ -1954,24 +1956,24 @@ Render3DError OpenGLRenderer_3_2::ReadBackPixels()
this->_mappedFramebuffer = NULL; this->_mappedFramebuffer = NULL;
} }
glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0); glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, OGLRef.readPixelsBestFormat, OGLRef.readPixelsBestDataType, 0);
} }
else else
{ {
// Just flips the framebuffer in Y to match the coordinates of OpenGL and the NDS hardware. // Just flips the framebuffer in Y to match the coordinates of OpenGL and the NDS hardware.
if (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor) if (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor)
{ {
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glReadBuffer(GL_WORKING_ATTACHMENT_ID); glReadBuffer(OGL_WORKING_ATTACHMENT_ID);
} }
else else
{ {
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glReadBuffer(GL_WORKING_ATTACHMENT_ID); glReadBuffer(OGL_WORKING_ATTACHMENT_ID);
glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
} }
// Read back the pixels in RGBA format, since an OpenGL 3.2 device should be able to read back this // Read back the pixels in RGBA format, since an OpenGL 3.2 device should be able to read back this
@ -1982,7 +1984,7 @@ Render3DError OpenGLRenderer_3_2::ReadBackPixels()
this->_mappedFramebuffer = NULL; this->_mappedFramebuffer = NULL;
} }
glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, OGLRef.readPixelsBestFormat, OGLRef.readPixelsBestDataType, 0);
} }
this->_pixelReadNeedsFinish = true; this->_pixelReadNeedsFinish = true;
@ -2186,7 +2188,7 @@ Render3DError OpenGLRenderer_3_2::BeginRender(const GFX3D_State &renderState, co
this->_geometryProgramFlags.OpaqueDrawMode = 1; this->_geometryProgramFlags.OpaqueDrawMode = 1;
this->_SetupGeometryShaders(this->_geometryProgramFlags); this->_SetupGeometryShaders(this->_geometryProgramFlags);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@ -2230,7 +2232,7 @@ Render3DError OpenGLRenderer_3_2::PostprocessFramebuffer()
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Pass 2: Unblended edge mark colors to zero-alpha pixels // Pass 2: Unblended edge mark colors to zero-alpha pixels
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glUseProgram(OGLRef.programEdgeMarkID); glUseProgram(OGLRef.programEdgeMarkID);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
glStencilFunc(GL_NOTEQUAL, 0x40, 0x40); glStencilFunc(GL_NOTEQUAL, 0x40, 0x40);
@ -2245,7 +2247,7 @@ Render3DError OpenGLRenderer_3_2::PostprocessFramebuffer()
else else
{ {
glUseProgram(OGLRef.programEdgeMarkID); glUseProgram(OGLRef.programEdgeMarkID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@ -2272,7 +2274,7 @@ Render3DError OpenGLRenderer_3_2::PostprocessFramebuffer()
#ifdef GL_VERSION_3_3 #ifdef GL_VERSION_3_3
if (this->_isDualSourceBlendingSupported) if (this->_isDualSourceBlendingSupported)
{ {
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR); glBlendFunc(GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR);
glBlendEquation(GL_FUNC_ADD); glBlendEquation(GL_FUNC_ADD);
@ -2285,7 +2287,7 @@ Render3DError OpenGLRenderer_3_2::PostprocessFramebuffer()
else else
#endif #endif
{ {
glDrawBuffer(GL_WORKING_ATTACHMENT_ID); glDrawBuffer(OGL_WORKING_ATTACHMENT_ID);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@ -2324,14 +2326,14 @@ Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuf
if (this->_enableFog) if (this->_enableFog)
{ {
// Blit the fog buffer // Blit the fog buffer
glReadBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glReadBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
// Blit the color and depth/stencil buffers. Do this last so that color attachment 0 is set to the read FBO. // Blit the color and depth/stencil buffers. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, GPU_FRAMEBUFFER_NATIVE_WIDTH, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
@ -2358,14 +2360,14 @@ Render3DError OpenGLRenderer_3_2::ClearUsingImage(const u16 *__restrict colorBuf
if (this->_enableFog) if (this->_enableFog)
{ {
glReadBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glReadBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glDrawBuffer(GL_FOGATTRIBUTES_ATTACHMENT_ID); glDrawBuffer(OGL_FOGATTRIBUTES_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
// Blit the color and depth/stencil buffers. Do this last so that color attachment 0 is set to the read FBO. // Blit the color and depth/stencil buffers. Do this last so that color attachment 0 is set to the read FBO.
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); glBlitFramebuffer(0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
@ -2640,8 +2642,8 @@ Render3DError OpenGLRenderer_3_2::RenderPowerOff()
} }
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID);
glReadBuffer(GL_COLOROUT_ATTACHMENT_ID); glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glDrawBuffer(GL_COLOROUT_ATTACHMENT_ID); glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID);
glClearBufferfv(GL_COLOR, 0, oglColor); glClearBufferfv(GL_COLOR, 0, oglColor);
if (this->_mappedFramebuffer != NULL) if (this->_mappedFramebuffer != NULL)
@ -2650,7 +2652,7 @@ Render3DError OpenGLRenderer_3_2::RenderPowerOff()
this->_mappedFramebuffer = NULL; this->_mappedFramebuffer = NULL;
} }
glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0); glReadPixels(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight, OGLRef.readPixelsBestFormat, OGLRef.readPixelsBestDataType, 0);
ENDGL(); ENDGL();