OPENGL: Support GLSL based CLUT8 look up for GLES2+.

This commit is contained in:
Johannes Schickel 2016-01-03 14:06:02 +01:00
parent bf2735cd53
commit 08553a09cf
6 changed files with 14 additions and 19 deletions

View file

@ -36,7 +36,6 @@ void Context::reset() {
shadersSupported = false; shadersSupported = false;
multitextureSupported = false; multitextureSupported = false;
framebufferObjectSupported = false; framebufferObjectSupported = false;
textureRGSupported = false;
#define GL_FUNC_DEF(ret, name, param) name = nullptr; #define GL_FUNC_DEF(ret, name, param) name = nullptr;
#include "backends/graphics/opengl/opengl-func.h" #include "backends/graphics/opengl/opengl-func.h"
@ -206,8 +205,6 @@ void OpenGLGraphicsManager::initializeGLContext() {
ARBFragmentShader = true; ARBFragmentShader = true;
} else if (token == "GL_ARB_multitexture") { } else if (token == "GL_ARB_multitexture") {
g_context.multitextureSupported = true; g_context.multitextureSupported = true;
} else if (token == "GL_ARB_texture_rg") {
g_context.textureRGSupported = true;
} else if (token == "GL_EXT_framebuffer_object") { } else if (token == "GL_EXT_framebuffer_object") {
g_context.framebufferObjectSupported = true; g_context.framebufferObjectSupported = true;
} }
@ -248,7 +245,6 @@ void OpenGLGraphicsManager::initializeGLContext() {
debug(5, "OpenGL: NPOT texture support: %d", g_context.NPOTSupported); debug(5, "OpenGL: NPOT texture support: %d", g_context.NPOTSupported);
debug(5, "OpenGL: Shader support: %d", g_context.shadersSupported); debug(5, "OpenGL: Shader support: %d", g_context.shadersSupported);
debug(5, "OpenGL: Multitexture support: %d", g_context.multitextureSupported); debug(5, "OpenGL: Multitexture support: %d", g_context.multitextureSupported);
debug(5, "OpenGL: Texture RG support: %d", g_context.textureRGSupported);
debug(5, "OpenGL: FBO support: %d", g_context.framebufferObjectSupported); debug(5, "OpenGL: FBO support: %d", g_context.framebufferObjectSupported);
} }

View file

@ -130,13 +130,11 @@ GL_FUNC_2_DEF(void, glGetShaderInfoLog, glGetInfoLogARB, (GLshader shader, GLsiz
GL_FUNC_2_DEF(void, glShaderSource, glShaderSourceARB, (GLshader shader, GLsizei count, const GLchar *const *string, const GLint *length)); GL_FUNC_2_DEF(void, glShaderSource, glShaderSourceARB, (GLshader shader, GLsizei count, const GLchar *const *string, const GLint *length));
GL_FUNC_2_DEF(void, glCompileShader, glCompileShaderARB, (GLshader shader)); GL_FUNC_2_DEF(void, glCompileShader, glCompileShaderARB, (GLshader shader));
#if !USE_FORCED_GLES2
GL_FUNC_2_DEF(void, glBindFramebuffer, glBindFramebufferEXT, (GLenum target, GLuint renderbuffer)); GL_FUNC_2_DEF(void, glBindFramebuffer, glBindFramebufferEXT, (GLenum target, GLuint renderbuffer));
GL_FUNC_2_DEF(void, glDeleteFramebuffers, glDeleteFramebuffersEXT, (GLsizei n, const GLuint *framebuffers)); GL_FUNC_2_DEF(void, glDeleteFramebuffers, glDeleteFramebuffersEXT, (GLsizei n, const GLuint *framebuffers));
GL_FUNC_2_DEF(void, glGenFramebuffers, glGenFramebuffersEXT, (GLsizei n, GLuint *renderbuffers)); GL_FUNC_2_DEF(void, glGenFramebuffers, glGenFramebuffersEXT, (GLsizei n, GLuint *renderbuffers));
GL_FUNC_2_DEF(void, glFramebufferTexture2D, glFramebufferTexture2DEXT, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)); GL_FUNC_2_DEF(void, glFramebufferTexture2D, glFramebufferTexture2DEXT, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level));
GL_FUNC_2_DEF(GLenum, glCheckFramebufferStatus, glCheckFramebufferStatusEXT, (GLenum target)); GL_FUNC_2_DEF(GLenum, glCheckFramebufferStatus, glCheckFramebufferStatusEXT, (GLenum target));
#endif
GL_FUNC_2_DEF(void, glActiveTexture, glActiveTextureARB, (GLenum texture)); GL_FUNC_2_DEF(void, glActiveTexture, glActiveTextureARB, (GLenum texture));
#endif #endif

View file

@ -1016,7 +1016,7 @@ void OpenGLGraphicsManager::setMousePosition(int x, int y) {
Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &format, bool wantAlpha) { Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &format, bool wantAlpha) {
GLenum glIntFormat, glFormat, glType; GLenum glIntFormat, glFormat, glType;
if (format.bytesPerPixel == 1) { if (format.bytesPerPixel == 1) {
#if !USE_FORCED_GLES && !USE_FORCED_GLES2 #if !USE_FORCED_GLES
if (TextureCLUT8GPU::isSupportedByContext()) { if (TextureCLUT8GPU::isSupportedByContext()) {
return new TextureCLUT8GPU(); return new TextureCLUT8GPU();
} }

View file

@ -114,9 +114,6 @@ struct Context {
/** Whether multi texture support is available or not. */ /** Whether multi texture support is available or not. */
bool multitextureSupported; bool multitextureSupported;
/** Whether (GLES2) RG texture formats are supported. */
bool textureRGSupported;
/** Whether FBO support is available or not. */ /** Whether FBO support is available or not. */
bool framebufferObjectSupported; bool framebufferObjectSupported;

View file

@ -504,9 +504,9 @@ void TextureRGB555::updateTexture() {
} }
#endif // !USE_FORCED_GL #endif // !USE_FORCED_GL
#if !USE_FORCED_GLES && !USE_FORCED_GLES2 #if !USE_FORCED_GLES
namespace { namespace {
const char *const g_lookUpFragmentShaderGL = const char *const g_lookUpFragmentShader =
"varying vec2 texCoord;\n" "varying vec2 texCoord;\n"
"varying vec4 blendColor;\n" "varying vec4 blendColor;\n"
"\n" "\n"
@ -517,12 +517,17 @@ const char *const g_lookUpFragmentShaderGL =
"\n" "\n"
"void main(void) {\n" "void main(void) {\n"
"\tvec4 index = texture2D(texture, texCoord);\n" "\tvec4 index = texture2D(texture, texCoord);\n"
"\tgl_FragColor = blendColor * texture2D(palette, vec2(index.x * adjustFactor, 0.0));\n" "\tgl_FragColor = blendColor * texture2D(palette, vec2(index.a * adjustFactor, 0.0));\n"
"}\n"; "}\n";
} // End of anonymous namespace } // End of anonymous namespace
// _clut8Texture needs 8 bits internal precision, otherwise graphics glitches
// can occur. GL_ALPHA does not have any internal precision requirements.
// However, in practice (according to fuzzie) it's 8bit. If we run into
// problems, we need to switch to GL_R8 and GL_RED, but that is only supported
// for ARB_texture_rg and GLES3+ (EXT_rexture_rg does not support GL_R8).
TextureCLUT8GPU::TextureCLUT8GPU() TextureCLUT8GPU::TextureCLUT8GPU()
: _clut8Texture(GL_R8, GL_RED, GL_UNSIGNED_BYTE), : _clut8Texture(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE),
_paletteTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), _paletteTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
_glTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE), _glTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
_glFBO(0), _clut8Vertices(), _projectionMatrix(), _glFBO(0), _clut8Vertices(), _projectionMatrix(),
@ -531,7 +536,7 @@ TextureCLUT8GPU::TextureCLUT8GPU()
// Allocate space for 256 colors. // Allocate space for 256 colors.
_paletteTexture.setSize(256, 1); _paletteTexture.setSize(256, 1);
_lookUpShader = new Shader(g_defaultVertexShader, g_lookUpFragmentShaderGL); _lookUpShader = new Shader(g_defaultVertexShader, g_lookUpFragmentShader);
_lookUpShader->recreate(); _lookUpShader->recreate();
_paletteLocation = _lookUpShader->getUniformLocation("palette"); _paletteLocation = _lookUpShader->getUniformLocation("palette");
@ -772,6 +777,6 @@ void TextureCLUT8GPU::setupFBO() {
// Restore old FBO. // Restore old FBO.
GL_CALL(glBindFramebuffer(GL_FRAMEBUFFER, oldFBO)); GL_CALL(glBindFramebuffer(GL_FRAMEBUFFER, oldFBO));
} }
#endif // !USE_FORCED_GLES && !USE_FORCED_GLES2 #endif // !USE_FORCED_GLES
} // End of namespace OpenGL } // End of namespace OpenGL

View file

@ -317,7 +317,7 @@ private:
}; };
#endif // !USE_FORCED_GL #endif // !USE_FORCED_GL
#if !USE_FORCED_GLES && !USE_FORCED_GLES2 #if !USE_FORCED_GLES
class TextureCLUT8GPU : public Surface { class TextureCLUT8GPU : public Surface {
public: public:
TextureCLUT8GPU(); TextureCLUT8GPU();
@ -351,7 +351,6 @@ public:
static bool isSupportedByContext() { static bool isSupportedByContext() {
return g_context.shadersSupported return g_context.shadersSupported
&& g_context.multitextureSupported && g_context.multitextureSupported
&& g_context.textureRGSupported
&& g_context.framebufferObjectSupported; && g_context.framebufferObjectSupported;
} }
private: private:
@ -376,7 +375,7 @@ private:
byte _palette[4 * 256]; byte _palette[4 * 256];
bool _paletteDirty; bool _paletteDirty;
}; };
#endif // !USE_FORCED_GLES && !USE_FORCED_GLES2 #endif // !USE_FORCED_GLES
} // End of namespace OpenGL } // End of namespace OpenGL