diff --git a/src/DepthBuffer.cpp b/src/DepthBuffer.cpp index 7d4ef1cb..9a75ffac 100644 --- a/src/DepthBuffer.cpp +++ b/src/DepthBuffer.cpp @@ -146,7 +146,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture if (_multisample) { glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _pTexture->glName); #if defined(GLES3_1) - glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pTexture->realWidth, _pTexture->realHeight, false); + glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT24, _pTexture->realWidth, _pTexture->realHeight, false); #else glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pTexture->realWidth, _pTexture->realHeight, false); #endif diff --git a/src/FBOTextureFormats.cpp b/src/FBOTextureFormats.cpp index 41bfd244..d07ce0c6 100644 --- a/src/FBOTextureFormats.cpp +++ b/src/FBOTextureFormats.cpp @@ -54,7 +54,7 @@ void FBOTextureFormats::init() depthImageFormatBytes = 16; lutInternalFormat = GL_R32UI; - lutFormat = GL_RED; + lutFormat = GL_RED_INTEGER; lutType = GL_UNSIGNED_INT; lutFormatBytes = 4; #else diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 70564e71..79d0f52a 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -736,7 +736,7 @@ void FrameBufferList::attachDepthBuffer() pDepthBuffer->initDepthImageTexture(m_pCurrent); pDepthBuffer->initDepthBufferTexture(m_pCurrent); #ifndef USE_DEPTH_RENDERBUFFER -#ifdef GLES2 +#ifdef GLESX if (pDepthBuffer->m_pDepthBufferTexture->realWidth == m_pCurrent->m_pTexture->realWidth) { #else if (pDepthBuffer->m_pDepthBufferTexture->realWidth >= m_pCurrent->m_pTexture->realWidth) { diff --git a/src/OGL3X/GLSLCombiner_ogl3x.cpp b/src/OGL3X/GLSLCombiner_ogl3x.cpp index 48c43ee0..10759a5e 100644 --- a/src/OGL3X/GLSLCombiner_ogl3x.cpp +++ b/src/OGL3X/GLSLCombiner_ogl3x.cpp @@ -142,10 +142,10 @@ void InitZlutTexture() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.lutInternalFormat, - 512, 512, 0, fboFormats.lutFormat, fboFormats.lutType, - zLUT); - glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat); + //glBindImageTexture requires an immutable texture object, glTexStorage2D does this + glTexStorage2D(GL_TEXTURE_2D, 1, fboFormats.lutInternalFormat, 512, 512); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, fboFormats.lutFormat, fboFormats.lutType, zLUT); + glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, fboFormats.lutInternalFormat); } static @@ -153,7 +153,8 @@ void DestroyZlutTexture() { if (!video().getRender().isImageTexturesSupported()) return; - glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat); + + glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, fboFormats.lutInternalFormat); if (g_zlut_tex > 0) { glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &g_zlut_tex); diff --git a/src/OGL3X/Shaders_ogl3x.h b/src/OGL3X/Shaders_ogl3x.h index 882f54bf..57fbee8c 100644 --- a/src/OGL3X/Shaders_ogl3x.h +++ b/src/OGL3X/Shaders_ogl3x.h @@ -743,53 +743,59 @@ MAIN_SHADER_VERSION // 3 point texture filtering. // Original author: ArthurCarvalho // GLSL implementation: twinaphex, mupen64plus-libretro project. -"#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize) \n" -"lowp vec4 texFilter(in sampler2D tex, in mediump vec2 texCoord) \n" -"{ \n" -" mediump vec2 texSize = vec2(textureSize(tex,0)); \n" -" mediump vec2 texelSize = vec2(1.0) / texSize; \n" -" lowp vec4 c = texture(tex, texCoord); \n" -" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x) return c; \n" -" if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y) return c; \n" -" \n" -" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \n" -" offset -= step(1.0, offset.x + offset.y); \n" -" lowp vec4 zero = vec4(0.0); \n" -" lowp vec4 c0 = TEX_OFFSET(offset); \n" -" lowp vec4 c1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y)); \n" -" lowp vec4 c2 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y))); \n" -" return c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); \n" -"} \n" +"#define TEX_OFFSET(off, tex, texCoord, texSize) texture(tex, texCoord - (off)/texSize) \n" +"#define TEX_FILTER(name, tex, texCoord) \\\n" +"{ \\\n" +" mediump vec2 texSize = vec2(textureSize(tex,0)); \\\n" +" mediump vec2 texelSize = vec2(1.0) / texSize; \\\n" +" lowp vec4 c = texture(tex, texCoord); \\\n" +" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x){ \\\n" +" name = c; \\\n" +" } else if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y){ \\\n" +" name = c; \\\n" +" } else { \\\n" +" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \\\n" +" offset -= step(1.0, offset.x + offset.y); \\\n" +" lowp vec4 zero = vec4(0.0); \\\n" +" lowp vec4 c0 = TEX_OFFSET(offset, tex, texCoord, texSize); \\\n" +" lowp vec4 c1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y), tex, texCoord, texSize); \\\n" +" lowp vec4 c2 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y)), tex, texCoord, texSize); \\\n" +" name = c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); \\\n" +" } \\\n" +"} \\\n" " \n" ; const char * strTexrectDrawerTexBilinearFilter = MAIN_SHADER_VERSION "uniform mediump vec4 uTextureBounds; \n" -"#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize) \n" -"lowp vec4 texFilter(in sampler2D tex, in mediump vec2 texCoord) \n" -"{ \n" -" mediump vec2 texSize = vec2(textureSize(tex,0)); \n" -" mediump vec2 texelSize = vec2(1.0) / texSize; \n" -" lowp vec4 c = texture(tex, texCoord); \n" -" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x) return c; \n" -" if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y) return c; \n" -" \n" -" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \n" -" offset -= step(1.0, offset.x + offset.y); \n" -" lowp vec4 zero = vec4(0.0); \n" -" \n" -" lowp vec4 p0q0 = TEX_OFFSET(offset); \n" -" lowp vec4 p1q0 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y)); \n" -" \n" -" lowp vec4 p0q1 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y))); \n" -" lowp vec4 p1q1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y - sign(offset.y))); \n" -" \n" -" mediump vec2 interpolationFactor = abs(offset); \n" -" lowp vec4 pInterp_q0 = mix( p0q0, p1q0, interpolationFactor.x ); // Interpolates top row in X direction. \n" -" lowp vec4 pInterp_q1 = mix( p0q1, p1q1, interpolationFactor.x ); // Interpolates bottom row in X direction. \n" -" return mix( pInterp_q0, pInterp_q1, interpolationFactor.y ); // Interpolate in Y direction. \n" -"} \n" +"#define TEX_OFFSET(off, tex, texCoord, texSize) texture(tex, texCoord - (off)/texSize) \n" +"#define TEX_FILTER(name, tex, texCoord) \\\n" +"{ \\\n" +" mediump vec2 texSize = vec2(textureSize(tex,0)); \\\n" +" mediump vec2 texelSize = vec2(1.0) / texSize; \\\n" +" lowp vec4 c = texture(tex, texCoord); \\\n" +" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x){ \\\n" +" name = c; \\\n" +" } else if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y){ \\\n" +" name = c; \\\n" +" } else { \\\n" +" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \\\n" +" offset -= step(1.0, offset.x + offset.y); \\\n" +" lowp vec4 zero = vec4(0.0); \\\n" +" \\\n" +" lowp vec4 p0q0 = TEX_OFFSET(offset, tex, texCoord, texSize); \\\n" +" lowp vec4 p1q0 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y), tex, texCoord, texSize); \\\n" +" \\\n" +" lowp vec4 p0q1 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y)), tex, texCoord, texSize); \\\n" +" lowp vec4 p1q1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y - sign(offset.y)), tex, texCoord, texSize); \\\n" +" \\\n" +" mediump vec2 interpolationFactor = abs(offset); \\\n" +" lowp vec4 pInterp_q0 = mix( p0q0, p1q0, interpolationFactor.x ); \\\n" // Interpolates top row in X direction. +" lowp vec4 pInterp_q1 = mix( p0q1, p1q1, interpolationFactor.x ); \\\n" // Interpolates bottom row in X direction. +" name = mix( pInterp_q0, pInterp_q1, interpolationFactor.y ); \\\n" // Interpolate in Y direction. +" } \\\n" +"} \\\n" " \n" ; @@ -801,7 +807,7 @@ const char * strTexrectDrawerFragmentShaderTex = "out lowp vec4 fragColor; \n" "void main() \n" "{ \n" -" fragColor = texFilter(uTex0, vTexCoord0); \n" +" TEX_FILTER(fragColor, uTex0, vTexCoord0); \n" " if (fragColor == uTestColor) discard; \n" " if (uEnableAlphaTest == 1 && !(fragColor.a > 0.0)) discard; \n" "} \n" diff --git a/src/ShaderUtils.cpp b/src/ShaderUtils.cpp index a61fdb4f..9ff2640c 100644 --- a/src/ShaderUtils.cpp +++ b/src/ShaderUtils.cpp @@ -63,11 +63,17 @@ GLuint createShaderProgram(const char * _strVertex, const char * _strFragment) glCompileShader(vertex_shader_object); assert(checkShaderCompileStatus(vertex_shader_object)); + if (!checkShaderCompileStatus(vertex_shader_object)) + logErrorShader(GL_VERTEX_SHADER, _strVertex); + GLuint fragment_shader_object = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment_shader_object, 1, &_strFragment, nullptr); glCompileShader(fragment_shader_object); assert(checkShaderCompileStatus(fragment_shader_object)); + if (!checkShaderCompileStatus(fragment_shader_object)) + logErrorShader(GL_VERTEX_SHADER, _strFragment); + GLuint program = glCreateProgram(); glBindAttribLocation(program, SC_POSITION, "aPosition"); glBindAttribLocation(program, SC_TEXCOORD0, "aTexCoord0"); diff --git a/src/TextDrawer.cpp b/src/TextDrawer.cpp index aa277050..d5219d5b 100644 --- a/src/TextDrawer.cpp +++ b/src/TextDrawer.cpp @@ -20,6 +20,8 @@ #include "Config.h" #include "GLSLCombiner.h" #include "ShaderUtils.h" +#include +#include "Log.h" struct point { GLfloat x; @@ -45,8 +47,10 @@ struct point { #ifdef GLES2 const GLenum monohromeformat = GL_LUMINANCE; +const GLenum monohromeInternalformat = GL_LUMINANCE; #else const GLenum monohromeformat = GL_RED; +const GLenum monohromeInternalformat = GL_R8; #endif // GLES2 static @@ -153,7 +157,7 @@ struct Atlas { glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); - glTexImage2D(GL_TEXTURE_2D, 0, monohromeformat, w, h, 0, monohromeformat, GL_UNSIGNED_BYTE, 0); + glTexImage2D(GL_TEXTURE_2D, 0, monohromeInternalformat, w, h, 0, monohromeformat, GL_UNSIGNED_BYTE, 0); /* We require 1 byte alignment when uploading texture data */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);