1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Correct FBO texture formats for different GL versions.

This commit is contained in:
Sergey Lipskiy 2015-06-02 18:57:24 +06:00
parent 9a991ba550
commit 1653069329
5 changed files with 130 additions and 39 deletions

View File

@ -117,7 +117,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
_pTexture->mirrorT = 0;
_pTexture->realWidth = _pTexture->width;
_pTexture->realHeight = _pTexture->height;
_pTexture->textureBytes = _pTexture->realWidth * _pTexture->realHeight * sizeof(float);
_pTexture->textureBytes = _pTexture->realWidth * _pTexture->realHeight * fboFormats.depthFormatBytes;
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
#ifdef GL_MULTISAMPLING_SUPPORT
@ -140,9 +140,9 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
{
glBindTexture(GL_TEXTURE_2D, _pTexture->glName);
if (_pBuffer != NULL)
glTexImage2D(GL_TEXTURE_2D, 0, DEPTH_COMPONENT_FORMAT, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, 0, GL_DEPTH_COMPONENT, DEPTH_COMPONENT_TYPE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);
else
glTexImage2D(GL_TEXTURE_2D, 0, DEPTH_COMPONENT_FORMAT, video().getWidth(), video().getHeight(), 0, GL_DEPTH_COMPONENT, DEPTH_COMPONENT_TYPE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, video().getWidth(), video().getHeight(), 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

View File

@ -72,15 +72,4 @@ extern const GLuint depthImageUnit;
void DepthBuffer_Init();
void DepthBuffer_Destroy();
#ifdef GLES2
#define DEPTH_COMPONENT_FORMAT GL_DEPTH_COMPONENT
#define DEPTH_COMPONENT_TYPE GL_UNSIGNED_INT
#elif defined (GLES3) || defined (GLES3_1)
#define DEPTH_COMPONENT_FORMAT GL_DEPTH_COMPONENT32F
#define DEPTH_COMPONENT_TYPE GL_FLOAT
#else
#define DEPTH_COMPONENT_FORMAT GL_DEPTH_COMPONENT
#define DEPTH_COMPONENT_TYPE GL_FLOAT
#endif
#endif

View File

@ -18,14 +18,6 @@
using namespace std;
#ifndef GLES2
const GLint monohromeInternalformat = GL_R8;
const GLenum monohromeformat = GL_RED;
#else
const GLint monohromeInternalformat = GL_LUMINANCE;
const GLenum monohromeformat = GL_LUMINANCE;
#endif // GLES2
#ifndef GLES2
class FrameBufferToRDRAM
{
@ -155,24 +147,19 @@ void FrameBuffer::_initTexture(u16 _format, u16 _size, CachedTexture *_pTexture)
_pTexture->realHeight = _pTexture->height;
_pTexture->textureBytes = _pTexture->realWidth * _pTexture->realHeight;
if (_size > G_IM_SIZ_8b)
_pTexture->textureBytes *= 4;
_pTexture->textureBytes *= fboFormats.colorFormatBytes;
else
_pTexture->textureBytes *= fboFormats.monochromeFormatBytes;
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
}
void FrameBuffer::_setAndAttachTexture(u16 _size, CachedTexture *_pTexture)
{
glBindTexture(GL_TEXTURE_2D, _pTexture->glName);
#ifdef GLES2
if (_size > G_IM_SIZ_8b)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _pTexture->realWidth, _pTexture->realHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.colorInternalFormat, _pTexture->realWidth, _pTexture->realHeight, 0, fboFormats.colorFormat, fboFormats.colorType, NULL);
else
glTexImage2D(GL_TEXTURE_2D, 0, monohromeInternalformat, _pTexture->realWidth, _pTexture->realHeight, 0, monohromeformat, GL_UNSIGNED_BYTE, NULL);
#else
if (_size > G_IM_SIZ_8b)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _pTexture->realWidth, _pTexture->realHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
else
glTexImage2D(GL_TEXTURE_2D, 0, monohromeInternalformat, _pTexture->realWidth, _pTexture->realHeight, 0, monohromeformat, GL_UNSIGNED_BYTE, NULL);
#endif
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.monochromeInternalFormat, _pTexture->realWidth, _pTexture->realHeight, 0, fboFormats.monochromeFormat, fboFormats.monochromeType, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -215,12 +202,12 @@ void FrameBuffer::init(u32 _address, u32 _endAddress, u16 _format, u16 _size, u1
if (_size > G_IM_SIZ_8b)
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_RGBA8, m_pTexture->realWidth, m_pTexture->realHeight, false);
else
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, monohromeInternalformat, m_pTexture->realWidth, m_pTexture->realHeight, false);
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, fboFormats.monochromeInternalFormat, m_pTexture->realWidth, m_pTexture->realHeight, false);
#else
if (_size > G_IM_SIZ_8b)
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_RGBA8, m_pTexture->realWidth, m_pTexture->realHeight, false);
else
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, monohromeInternalformat, m_pTexture->realWidth, m_pTexture->realHeight, false);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, fboFormats.monochromeInternalFormat, m_pTexture->realWidth, m_pTexture->realHeight, false);
#endif
m_pTexture->frameBufferTexture = CachedTexture::fbMultiSample;
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_pTexture->glName, 0);
@ -876,7 +863,7 @@ void FrameBufferToRDRAM::Init()
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * 4;
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
glBindTexture( GL_TEXTURE_2D, m_pTexture->glName );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_pTexture->realWidth, m_pTexture->realHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.colorInternalFormat, m_pTexture->realWidth, m_pTexture->realHeight, 0, fboFormats.colorFormat, fboFormats.colorType, NULL);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glBindTexture(GL_TEXTURE_2D, 0);
@ -1061,12 +1048,12 @@ void DepthBufferToRDRAM::Init()
textureCache().addFrameBufferTextureSize(m_pDepthTexture->textureBytes);
glBindTexture( GL_TEXTURE_2D, m_pColorTexture->glName );
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_pColorTexture->realWidth, m_pColorTexture->realHeight, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.monochromeInternalFormat, m_pColorTexture->realWidth, m_pColorTexture->realHeight, 0, fboFormats.monochromeFormat, fboFormats.monochromeType, NULL);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glBindTexture( GL_TEXTURE_2D, m_pDepthTexture->glName );
glTexImage2D(GL_TEXTURE_2D, 0, DEPTH_COMPONENT_FORMAT, m_pDepthTexture->realWidth, m_pDepthTexture->realHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, m_pDepthTexture->realWidth, m_pDepthTexture->realHeight, 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
@ -1193,7 +1180,7 @@ void RDRAMtoFrameBuffer::Init()
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * 4;
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
glBindTexture( GL_TEXTURE_2D, m_pTexture->glName );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_pTexture->realWidth, m_pTexture->realHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.colorInternalFormat, m_pTexture->realWidth, m_pTexture->realHeight, 0, fboFormats.colorFormat, fboFormats.colorType, NULL);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glBindTexture(GL_TEXTURE_2D, 0);

View File

@ -427,7 +427,7 @@ void OGLRender::_setBlendMode() const
default:
LOG(LOG_VERBOSE, "Unhandled blend mode=%x", gDP.otherMode.l >> 16);
//LOG(LOG_VERBOSE, "Unhandled blend mode=%x", gDP.otherMode.l >> 16);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
break;
}
@ -1153,12 +1153,103 @@ void OGLRender::clearColorBuffer(float *_pColor )
glEnable( GL_SCISSOR_TEST );
}
FBOTextureFormats fboFormats;
void FBOTextureFormats::init()
{
#ifdef GLES2
monochromeInternalFormat = GL_RGB;
monochromeFormat = GL_RGB;
monochromeType = GL_UNSIGNED_SHORT_5_6_5;
monochromeFormatBytes = 2;
const char * extensions = (const char *)glGetString(GL_EXTENSIONS);
if (strstr((const char *)glGetString(GL_RENDERER), "Mali-400") != NULL)
{
if (strstr(extensions, "GL_OES_rgb8_rgba8") != NULL) {
colorInternalFormat = GL_RGBA;
colorFormat = GL_RGBA;
colorType = GL_UNSIGNED_BYTE;
colorFormatBytes = 4;
} else {
colorInternalFormat = GL_RGB;
colorFormat = GL_RGB;
colorType = GL_UNSIGNED_SHORT_5_6_5;
colorFormatBytes = 2;
}
depthInternalFormat = GL_DEPTH_COMPONENT;
depthFormat = GL_DEPTH_COMPONENT;
depthType = GL_UNSIGNED_INT;
depthFormatBytes = 2;
return;
}
if (strstr(extensions, "GL_OES_rgb8_rgba8") != NULL) {
colorInternalFormat = GL_RGBA8_OES;
colorFormat = GL_RGBA;
colorType = GL_UNSIGNED_BYTE;
colorFormatBytes = 4;
} else {
colorInternalFormat = GL_RGB5_A1;
colorFormat = GL_RGBA;
colorType = GL_UNSIGNED_SHORT_5_5_5_1;
colorFormatBytes = 2;
}
if (strstr(extensions, "GL_OES_depth24") != NULL) {
depthInternalFormat = GL_DEPTH_COMPONENT24_OES;
depthFormat = GL_DEPTH_COMPONENT;
depthType = GL_UNSIGNED_INT;
depthFormatBytes = 3;
} else {
depthInternalFormat = GL_DEPTH_COMPONENT16;
depthFormat = GL_DEPTH_COMPONENT;
depthType = GL_UNSIGNED_INT;
depthFormatBytes = 2;
}
#elif defined(GLES3) || defined (GLES3_1)
colorInternalFormat = GL_RGBA;
colorFormat = GL_RGBA;
colorType = GL_UNSIGNED_BYTE;
colorFormatBytes = 4;
monochromeInternalFormat = GL_RED;
monochromeFormat = GL_RED;
monochromeType = GL_UNSIGNED_BYTE;
monochromeFormatBytes = 1;
depthInternalFormat = GL_DEPTH_COMPONENT32F;
depthFormat = GL_DEPTH_COMPONENT;
depthType = GL_FLOAT;
depthFormatBytes = 4;
#else
colorInternalFormat = GL_RGBA;
colorFormat = GL_RGBA;
colorType = GL_UNSIGNED_BYTE;
colorFormatBytes = 4;
monochromeInternalFormat = GL_RED;
monochromeFormat = GL_RED;
monochromeType = GL_UNSIGNED_BYTE;
monochromeFormatBytes = 1;
depthInternalFormat = GL_DEPTH_COMPONENT;
depthFormat = GL_DEPTH_COMPONENT;
depthType = GL_FLOAT;
depthFormatBytes = 4;
#endif
}
void OGLRender::_initExtensions()
{
LOG(LOG_VERBOSE, "OpenGL version string: %s\n", glGetString(GL_VERSION));
LOG(LOG_VERBOSE, "OpenGL vendor: %s\n", glGetString(GL_VENDOR));
LOG(LOG_VERBOSE, "OpenGL renderer: %s\n", glGetString(GL_RENDERER));
fboFormats.init();
#ifndef GLES2
GLint majorVersion = 0;
glGetIntegerv(GL_MAJOR_VERSION, &majorVersion);

View File

@ -219,6 +219,30 @@ private:
virtual bool _resizeWindow() = 0;
};
struct FBOTextureFormats
{
GLint colorInternalFormat;
GLenum colorFormat;
GLenum colorType;
u32 colorFormatBytes;
GLint monochromeInternalFormat;
GLenum monochromeFormat;
GLenum monochromeType;
u32 monochromeFormatBytes;
GLint depthInternalFormat;
GLenum depthFormat;
GLenum depthType;
u32 depthFormatBytes;
u32 pad[4];
void init();
};
extern FBOTextureFormats fboFormats;
inline
OGLVideo & video()
{