Patch from Degasus that removes the last of the the GL_TEXTURE_RECTANGLE usages. This is needed to have GLES3 support.

This commit is contained in:
Ryan Houdek
2013-07-13 17:24:23 -05:00
parent 52cb398804
commit 737df2a68c
15 changed files with 163 additions and 126 deletions

View File

@ -59,6 +59,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
// Create EFB target.
glGenFramebuffers(1, &m_efbFramebuffer);
glActiveTexture(GL_TEXTURE0 + 9);
if (m_msaaSamples <= 1)
{
@ -69,20 +70,20 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
m_efbColor = glObj[0];
m_efbDepth = glObj[1];
glBindTexture(GL_TEXTURE_RECTANGLE, m_efbColor);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, m_targetWidth, m_targetHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(getFbType(), m_efbColor);
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(getFbType(), 0, GL_RGBA8, m_targetWidth, m_targetHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE, m_efbDepth);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_DEPTH_COMPONENT24, m_targetWidth, m_targetHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE, 0);
glBindTexture(getFbType(), m_efbDepth);
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(getFbType(), 0, GL_DEPTH_COMPONENT24, m_targetWidth, m_targetHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
// Bind target textures to the EFB framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, m_efbColor, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, m_efbDepth, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, getFbType(), m_efbColor, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, getFbType(), m_efbDepth, 0);
GL_REPORT_FBO_ERROR();
}
@ -131,20 +132,20 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
m_resolvedColorTexture = glObj[0];
m_resolvedDepthTexture = glObj[1];
glBindTexture(GL_TEXTURE_RECTANGLE, m_resolvedColorTexture);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, m_targetWidth, m_targetHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(getFbType(), m_resolvedColorTexture);
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(getFbType(), 0, GL_RGBA8, m_targetWidth, m_targetHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE, m_resolvedDepthTexture);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_DEPTH_COMPONENT24, m_targetWidth, m_targetHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE, 0);
glBindTexture(getFbType(), m_resolvedDepthTexture);
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(getFbType(), 0, GL_DEPTH_COMPONENT24, m_targetWidth, m_targetHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
// Bind resolved textures to resolved framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, m_resolvedFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, m_resolvedColorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, m_resolvedDepthTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, getFbType(), m_resolvedColorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, getFbType(), m_resolvedDepthTexture, 0);
GL_REPORT_FBO_ERROR();

View File

@ -7,6 +7,7 @@
#include "GLUtil.h"
#include "FramebufferManagerBase.h"
#include "Render.h"
// On the GameCube, the game sends a request for the graphics processor to
// transfer its internal EFB (Embedded Framebuffer) to an area in GameCube RAM
@ -55,6 +56,17 @@ struct XFBSource : public XFBSourceBase
const GLuint renderbuf;
};
inline GLenum getFbType()
{
#ifndef USE_GLES3
if(g_ogl_config.eSupportedGLSLVersion == GLSL_120)
{
return GL_TEXTURE_RECTANGLE;
}
#endif
return GL_TEXTURE_2D;
}
class FramebufferManager : public FramebufferManagerBase
{
public:

View File

@ -23,12 +23,22 @@
#define TEXFUNC "texture2D"
#ifdef USE_GLES3
#include "GLFunctions.h"
#define GLAPIENTRY GL_APIENTRY
#define GL_SAMPLES_PASSED GL_ANY_SAMPLES_PASSED
#define GL_READ_ONLY 0x88B8
#define GL_WRITE_ONLY 0x88B9
#define GL_READ_WRITE 0x88BA
#define GL_SRC1_ALPHA 0
#define GL_BGRA GL_RGBA
#define glDrawElementsBaseVertex
#define GLRENDERBUFFERFORMAT 0x8058 /* RGBA8_OES */
#endif
#else
#define TEX2D GL_TEXTURE_RECTANGLE_ARB
#define PREC
#define TEXTYPE "sampler2DRect"
#define TEXFUNC "texture2DRect"
#define GLRENDERBUFFERFORMAT GL_RGBA
#endif

View File

@ -509,7 +509,6 @@ void ProgramShaderCache::CreateHeader ( void )
snprintf(s_glsl_header, sizeof(s_glsl_header),
"#version %s\n"
"%s\n" // default precision
"%s\n" // tex_rect
"%s\n" // ubo
"\n"// A few required defines and ones that will make our lives a lot easier
@ -534,10 +533,14 @@ void ProgramShaderCache::CreateHeader ( void )
"%s\n"
"%s\n"
"#define COLOROUT(name) %s\n"
// texture2d hack
"%s\n"
"%s\n"
"%s\n"
, v==GLSLES3 ? "300 es" : v==GLSL_120 ? "120" : v==GLSL_130 ? "130" : "140"
, v==GLSLES3 ? "precision highp float;" : ""
, v==GLSLES3 ? "" : v<=GLSL_130 ? "#extension GL_ARB_texture_rectangle : enable" : "#define texture2DRect texture"
, g_ActiveConfig.backend_info.bSupportsGLSLUBO && v<GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
, v==GLSL_120 ? "attribute" : "in"
, v==GLSL_120 ? "attribute" : "out"
@ -549,6 +552,9 @@ void ProgramShaderCache::CreateHeader ( void )
, v==GLSL_120 ? "#define ocol0 gl_FragColor" : ""
, v==GLSL_120 ? "#define ocol1 gl_FragColor" : "" //TODO: implement dual source blend
, v==GLSL_120 ? "" : "out vec4 name;"
, v==GLSL_120 ? "#extension GL_ARB_texture_rectangle : enable" : ""
, v==GLSL_120 ? "" : "#define texture2DRect(samp, uv) texelFetch(samp, ivec2(floor(uv)), 0)"
, v==GLSL_120 ? "" : "#define sampler2DRect sampler2D"
);
}

View File

@ -149,8 +149,7 @@ RasterFont::RasterFont()
}
}
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, char_width*char_count, char_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
delete [] texture_data;

View File

@ -984,7 +984,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
#ifdef USE_GLES3
// XXX: Swap colours
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight,
GL_RGBA, GL_UNSIGNED_INT, colorMap);
GL_RGBA, GL_UNSIGNED_BYTE, colorMap);
#else
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, colorMap);
@ -1559,7 +1559,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
// For testing zbuffer targets.
// Renderer::SetZBufferRender();
// SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_FakeZTarget,
// SaveTexture("tex.tga", GL_TEXTURE_2D, s_FakeZTarget,
// GetTargetWidth(), GetTargetHeight());
Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
XFBWrited = false;

View File

@ -95,13 +95,15 @@ void SamplerCache::SetParameters(GLuint sampler_id, const Params& params)
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, wrap_settings[tm0.wrap_s]);
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, wrap_settings[tm0.wrap_t]);
glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, tm0.lod_bias / 32.f);
glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, tm1.min_lod / 16.f);
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, tm1.max_lod / 16.f);
#ifndef USE_GLES3
glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, tm0.lod_bias / 32.f);
if (g_ActiveConfig.iMaxAnisotropy > 0)
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)(1 << g_ActiveConfig.iMaxAnisotropy));
#endif
}
void SamplerCache::Clear()

View File

@ -63,6 +63,7 @@ static std::map<u64,VBOCache> s_VBO;
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level)
{
#ifndef USE_GLES3
int width = std::max(virtual_width >> level, 1);
int height = std::max(virtual_height >> level, 1);
std::vector<u32> data(width * height);
@ -80,6 +81,9 @@ bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width
}
return SaveTGA(filename, width, height, &data[0]);
#else
return false;
#endif
}
TextureCache::TCacheEntry::~TCacheEntry()
@ -158,7 +162,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
gl_iformat = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
break;
#ifndef USE_GLES3
case PC_TEX_FMT_I4_AS_I8:
gl_format = GL_LUMINANCE;
gl_iformat = GL_INTENSITY4;
@ -182,7 +186,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
gl_iformat = GL_LUMINANCE8_ALPHA8;
gl_type = GL_UNSIGNED_BYTE;
break;
#endif
case PC_TEX_FMT_RGB565:
gl_format = GL_RGB;
gl_iformat = GL_RGB;
@ -296,7 +300,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
GL_REPORT_ERRORD();
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_RECTANGLE, read_texture);
glBindTexture(getFbType(), read_texture);
glViewport(0, 0, virtual_width, virtual_height);
@ -360,8 +364,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glBindVertexArray(vbo_it->second.vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
GL_REPORT_ERRORD();
}

View File

@ -167,11 +167,10 @@ void Init()
s_srcTextureWidth = 0;
s_srcTextureHeight = 0;
glActiveTexture(GL_TEXTURE0 + 9);
glGenTextures(1, &s_srcTexture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
glBindTexture(getFbType(), s_srcTexture);
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);
CreatePrograms();
}
@ -213,17 +212,17 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc,
// set source texture
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_RECTANGLE, srcTexture);
glBindTexture(getFbType(), srcTexture);
if (linearFilter)
{
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(getFbType(), GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(getFbType(), GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(getFbType(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(getFbType(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
GL_REPORT_ERRORD();
@ -251,8 +250,6 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc,
glBindVertexArray( s_encode_VAO );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
GL_REPORT_ERRORD();
// .. and then read back the results.
@ -386,17 +383,17 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender
// activate source texture
// set srcAddr as data for source texture
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_RECTANGLE, s_srcTexture);
glBindTexture(getFbType(), s_srcTexture);
// TODO: make this less slow. (How?)
if ((GLsizei)s_srcTextureWidth == (GLsizei)srcFmtWidth && (GLsizei)s_srcTextureHeight == (GLsizei)srcHeight)
{
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0,0,0,s_srcTextureWidth, s_srcTextureHeight,
glTexSubImage2D(getFbType(), 0,0,0,s_srcTextureWidth, s_srcTextureHeight,
GL_BGRA, GL_UNSIGNED_BYTE, srcAddr);
}
else
{
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, (GLsizei)srcFmtWidth, (GLsizei)srcHeight,
glTexImage2D(getFbType(), 0, GL_RGBA8, (GLsizei)srcFmtWidth, (GLsizei)srcHeight,
0, GL_BGRA, GL_UNSIGNED_BYTE, srcAddr);
s_srcTextureWidth = (GLsizei)srcFmtWidth;
s_srcTextureHeight = (GLsizei)srcHeight;
@ -431,9 +428,6 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender
GL_REPORT_ERRORD();
// reset state
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
VertexShaderManager::SetViewportChanged();
FramebufferManager::SetFramebuffer(0);