OPENGL: Support GLSL based CLUT8 look up for GLES2+.
This commit is contained in:
parent
bf2735cd53
commit
08553a09cf
6 changed files with 14 additions and 19 deletions
|
@ -36,7 +36,6 @@ void Context::reset() {
|
|||
shadersSupported = false;
|
||||
multitextureSupported = false;
|
||||
framebufferObjectSupported = false;
|
||||
textureRGSupported = false;
|
||||
|
||||
#define GL_FUNC_DEF(ret, name, param) name = nullptr;
|
||||
#include "backends/graphics/opengl/opengl-func.h"
|
||||
|
@ -206,8 +205,6 @@ void OpenGLGraphicsManager::initializeGLContext() {
|
|||
ARBFragmentShader = true;
|
||||
} else if (token == "GL_ARB_multitexture") {
|
||||
g_context.multitextureSupported = true;
|
||||
} else if (token == "GL_ARB_texture_rg") {
|
||||
g_context.textureRGSupported = true;
|
||||
} else if (token == "GL_EXT_framebuffer_object") {
|
||||
g_context.framebufferObjectSupported = true;
|
||||
}
|
||||
|
@ -248,7 +245,6 @@ void OpenGLGraphicsManager::initializeGLContext() {
|
|||
debug(5, "OpenGL: NPOT texture support: %d", g_context.NPOTSupported);
|
||||
debug(5, "OpenGL: Shader support: %d", g_context.shadersSupported);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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, glCompileShader, glCompileShaderARB, (GLshader shader));
|
||||
|
||||
#if !USE_FORCED_GLES2
|
||||
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, 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(GLenum, glCheckFramebufferStatus, glCheckFramebufferStatusEXT, (GLenum target));
|
||||
#endif
|
||||
|
||||
GL_FUNC_2_DEF(void, glActiveTexture, glActiveTextureARB, (GLenum texture));
|
||||
#endif
|
||||
|
|
|
@ -1016,7 +1016,7 @@ void OpenGLGraphicsManager::setMousePosition(int x, int y) {
|
|||
Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &format, bool wantAlpha) {
|
||||
GLenum glIntFormat, glFormat, glType;
|
||||
if (format.bytesPerPixel == 1) {
|
||||
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
|
||||
#if !USE_FORCED_GLES
|
||||
if (TextureCLUT8GPU::isSupportedByContext()) {
|
||||
return new TextureCLUT8GPU();
|
||||
}
|
||||
|
|
|
@ -114,9 +114,6 @@ struct Context {
|
|||
/** Whether multi texture support is available or not. */
|
||||
bool multitextureSupported;
|
||||
|
||||
/** Whether (GLES2) RG texture formats are supported. */
|
||||
bool textureRGSupported;
|
||||
|
||||
/** Whether FBO support is available or not. */
|
||||
bool framebufferObjectSupported;
|
||||
|
||||
|
|
|
@ -504,9 +504,9 @@ void TextureRGB555::updateTexture() {
|
|||
}
|
||||
#endif // !USE_FORCED_GL
|
||||
|
||||
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
|
||||
#if !USE_FORCED_GLES
|
||||
namespace {
|
||||
const char *const g_lookUpFragmentShaderGL =
|
||||
const char *const g_lookUpFragmentShader =
|
||||
"varying vec2 texCoord;\n"
|
||||
"varying vec4 blendColor;\n"
|
||||
"\n"
|
||||
|
@ -517,12 +517,17 @@ const char *const g_lookUpFragmentShaderGL =
|
|||
"\n"
|
||||
"void main(void) {\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";
|
||||
} // 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()
|
||||
: _clut8Texture(GL_R8, GL_RED, GL_UNSIGNED_BYTE),
|
||||
: _clut8Texture(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE),
|
||||
_paletteTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
|
||||
_glTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
|
||||
_glFBO(0), _clut8Vertices(), _projectionMatrix(),
|
||||
|
@ -531,7 +536,7 @@ TextureCLUT8GPU::TextureCLUT8GPU()
|
|||
// Allocate space for 256 colors.
|
||||
_paletteTexture.setSize(256, 1);
|
||||
|
||||
_lookUpShader = new Shader(g_defaultVertexShader, g_lookUpFragmentShaderGL);
|
||||
_lookUpShader = new Shader(g_defaultVertexShader, g_lookUpFragmentShader);
|
||||
_lookUpShader->recreate();
|
||||
_paletteLocation = _lookUpShader->getUniformLocation("palette");
|
||||
|
||||
|
@ -772,6 +777,6 @@ void TextureCLUT8GPU::setupFBO() {
|
|||
// Restore old FBO.
|
||||
GL_CALL(glBindFramebuffer(GL_FRAMEBUFFER, oldFBO));
|
||||
}
|
||||
#endif // !USE_FORCED_GLES && !USE_FORCED_GLES2
|
||||
#endif // !USE_FORCED_GLES
|
||||
|
||||
} // End of namespace OpenGL
|
||||
|
|
|
@ -317,7 +317,7 @@ private:
|
|||
};
|
||||
#endif // !USE_FORCED_GL
|
||||
|
||||
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
|
||||
#if !USE_FORCED_GLES
|
||||
class TextureCLUT8GPU : public Surface {
|
||||
public:
|
||||
TextureCLUT8GPU();
|
||||
|
@ -351,7 +351,6 @@ public:
|
|||
static bool isSupportedByContext() {
|
||||
return g_context.shadersSupported
|
||||
&& g_context.multitextureSupported
|
||||
&& g_context.textureRGSupported
|
||||
&& g_context.framebufferObjectSupported;
|
||||
}
|
||||
private:
|
||||
|
@ -376,7 +375,7 @@ private:
|
|||
byte _palette[4 * 256];
|
||||
bool _paletteDirty;
|
||||
};
|
||||
#endif // !USE_FORCED_GLES && !USE_FORCED_GLES2
|
||||
#endif // !USE_FORCED_GLES
|
||||
|
||||
} // End of namespace OpenGL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue