diff --git a/src/DepthBuffer.cpp b/src/DepthBuffer.cpp index b36b27e9..2607061f 100644 --- a/src/DepthBuffer.cpp +++ b/src/DepthBuffer.cpp @@ -318,7 +318,7 @@ void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer) void DepthBuffer::bindDepthImageTexture() { - if (!Context::imageTextures) + if (!gfxContext.isSupported(graphics::SpecialFeatures::ImageTextures)) return; Context::BindImageTextureParameters bindParams; diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 9b480e19..20a899ea 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -310,7 +310,7 @@ bool FrameBuffer::isValid(bool _forceCheck) const void FrameBuffer::resolveMultisampledTexture(bool _bForce) { - if (!Context::multisampling) + if (!gfxContext.isSupported(SpecialFeatures::Multisampling)) return; if (m_resolved && !_bForce) diff --git a/src/Graphics/Context.cpp b/src/Graphics/Context.cpp index c69ae5a6..1dc599d1 100644 --- a/src/Graphics/Context.cpp +++ b/src/Graphics/Context.cpp @@ -5,9 +5,6 @@ using namespace graphics; Context gfxContext; -bool Context::imageTextures = false; -bool Context::multisampling = false; - Context::Context() {} Context::~Context() { @@ -20,8 +17,6 @@ void Context::init() m_impl.reset(new opengl::ContextImpl); m_impl->init(); m_fbTexFormats.reset(m_impl->getFramebufferTextureFormats()); - imageTextures = isSupported(SpecialFeatures::ImageTextures); - multisampling = isSupported(SpecialFeatures::Multisampling); } void Context::destroy() diff --git a/src/Graphics/Context.h b/src/Graphics/Context.h index 8c8052ca..d7d6bb71 100644 --- a/src/Graphics/Context.h +++ b/src/Graphics/Context.h @@ -22,7 +22,8 @@ namespace graphics { WeakBlitFramebuffer, DepthFramebufferTextures, ShaderProgramBinary, - ImageTextures + ImageTextures, + LUTTextures }; enum class ClampMode { @@ -274,9 +275,6 @@ namespace graphics { bool isFramebufferError() const; - static bool imageTextures; - static bool multisampling; - private: std::unique_ptr m_impl; std::unique_ptr m_fbTexFormats; diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 070d39d0..0ba8d2e6 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -236,10 +236,6 @@ public: else { std::stringstream ss; ss << "#version " << Utils::to_string(_glinfo.majorVersion) << Utils::to_string(_glinfo.minorVersion) << "0 core " << std::endl; - if (_glinfo.imageTextures && _glinfo.majorVersion * 10 + _glinfo.minorVersion < 42) { - ss << "#extension GL_ARB_shader_image_load_store : enable" << std::endl - << "#extension GL_ARB_shading_language_420pack : enable" << std::endl; - } ss << "# define IN in" << std::endl << "# define OUT out" << std::endl; m_part = ss.str(); } @@ -1444,9 +1440,9 @@ public: "} \n" ; } else { - if (_glinfo.imageTextures && (config.generalEmulation.hacks & hack_RE2) != 0) { + if ((config.generalEmulation.hacks & hack_RE2) != 0) { m_part = - "layout(binding = 0, r32ui) highp uniform readonly uimage2D uZlutImage;\n" + "uniform lowp usampler2D uZlutImage;\n" "highp float writeDepth() \n" "{ \n" ; @@ -1464,7 +1460,7 @@ public: " highp int iZ = FragDepth > 0.999 ? 262143 : int(floor(FragDepth * 262143.0)); \n" " mediump int y0 = clamp(iZ/512, 0, 511); \n" " mediump int x0 = iZ - 512*y0; \n" - " highp uint iN64z = imageLoad(uZlutImage,ivec2(x0,y0)).r; \n" + " highp uint iN64z = texelFetch(uZlutImage,ivec2(x0,y0), 0).r; \n" " return clamp(float(iN64z)/65532.0, 0.0, 1.0); \n" "} \n" ; diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp index a97b3cc1..683a80b7 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp @@ -141,6 +141,22 @@ private: iUniform uDepthTex; }; +class UZLutTexture : public UniformGroup +{ +public: + UZLutTexture(GLuint _program) { + LocateUniform(uZlutImage); + } + + void update(bool _force) override + { + uZlutImage.set(int(graphics::textureIndices::ZLUTTex), _force); + } + +private: + iUniform uZlutImage; +}; + class UTextures : public UniformGroup { public: @@ -962,6 +978,9 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program, _uniforms.emplace_back(new UAlphaTestInfo(_program)); + if ((config.generalEmulation.hacks & hack_RE2) != 0 && config.generalEmulation.enableFragmentDepthWrite != 0) + _uniforms.emplace_back(new UZLutTexture(_program)); + if (config.frameBufferEmulation.N64DepthCompare != 0) _uniforms.emplace_back(new UDepthInfo(_program)); else diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h index 2d37ae92..9a987bed 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h +++ b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h @@ -20,7 +20,7 @@ namespace glsl { bool _saveCombinerKeys(const graphics::Combiners & _combiners) const; bool _loadFromCombinerKeys(graphics::Combiners & _combiners); - const u32 m_formatVersion = 0x1DU; + const u32 m_formatVersion = 0x1EU; const u32 m_keysFormatVersion = 0x04; const opengl::GLInfo & m_glinfo; opengl::CachedUseProgram * m_useProgram; diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp index 603dfad0..84889831 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp @@ -56,9 +56,9 @@ namespace glsl { ShadowMapFragmentShader(const opengl::GLInfo & _glinfo) { m_part = - "layout(binding = 0, r32ui) highp uniform readonly uimage2D uZlutImage;\n" - "layout(binding = 1, r32ui) highp uniform readonly uimage2D uTlutImage;\n" - "layout(binding = 0) uniform sampler2D uDepthImage; \n" + "uniform lowp usampler2D uZlutImage;\n" + "uniform lowp usampler2D uTlutImage;\n" + "uniform sampler2D uDepthImage; \n" "uniform lowp vec4 uFogColor; \n" "OUT lowp vec4 fragColor; \n" "lowp float get_alpha() \n" @@ -68,10 +68,10 @@ namespace glsl { " highp int iZ = bufZ > 0.999 ? 262143 : int(floor(bufZ * 262143.0));\n" " mediump int y0 = clamp(iZ/512, 0, 511); \n" " mediump int x0 = iZ - 512*y0; \n" - " highp uint iN64z = imageLoad(uZlutImage,ivec2(x0,y0)).r; \n" + " highp uint iN64z = texelFetch(uZlutImage,ivec2(x0,y0), 0).r; \n" " highp float n64z = clamp(float(iN64z)/65532.0, 0.0, 1.0);\n" " highp int index = min(255, int(n64z*255.0)); \n" - " highp uint iAlpha = imageLoad(uTlutImage,ivec2(index,0)).r;\n" + " highp uint iAlpha = texelFetch(uTlutImage,ivec2(index,0), 0).r;\n" " return float(iAlpha>>8)/255.0; \n" "} \n" "void main() \n" @@ -426,22 +426,34 @@ namespace glsl { const ShaderPart * _vertexHeader, const ShaderPart * _fragmentHeader) : ShadowMapShaderBase(_glinfo, _useProgram, _vertexHeader, _fragmentHeader) - , m_loc(-1) + , m_locFog(-1) + , m_locZlut(-1) + , m_locTlut(-1) + , m_locDepthImage(-1) { m_useProgram->useProgram(m_program); - m_loc = glGetUniformLocation(GLuint(m_program), "uFogColor"); + m_locFog = glGetUniformLocation(GLuint(m_program), "uFogColor"); + m_locZlut = glGetUniformLocation(GLuint(m_program), "uZlutImage"); + m_locTlut = glGetUniformLocation(GLuint(m_program), "uTlutImage"); + m_locDepthImage = glGetUniformLocation(GLuint(m_program), "uDepthImage"); m_useProgram->useProgram(graphics::ObjectHandle::null); } void activate() override { ShadowMapShaderBase::activate(); - glUniform4fv(m_loc, 1, &gDP.fogColor.r); + glUniform4fv(m_locFog, 1, &gDP.fogColor.r); + glUniform1i(m_locZlut, int(graphics::textureIndices::ZLUTTex)); + glUniform1i(m_locTlut, int(graphics::textureIndices::PaletteTex)); + glUniform1i(m_locDepthImage, 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); g_paletteTexture.update(); } private: - int m_loc; + int m_locFog; + int m_locZlut; + int m_locTlut; + int m_locDepthImage; }; /*---------------TexrectDrawerShader-------------*/ @@ -638,7 +650,7 @@ namespace glsl { graphics::ShaderProgram * SpecialShadersFactory::createShadowMapShader() const { - if (!m_glinfo.imageTextures) + if (m_glinfo.isGLES2) return nullptr; return new ShadowMapShader(m_glinfo, m_useProgram, m_vertexHeader, m_fragmentHeader); diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp index cd92903d..7bc87a9b 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp @@ -469,6 +469,8 @@ bool ContextImpl::isSupported(graphics::SpecialFeatures _feature) const return m_glInfo.shaderStorage; case graphics::SpecialFeatures::DepthFramebufferTextures: return m_glInfo.depthTexture; + case graphics::SpecialFeatures::LUTTextures: + return !m_glInfo.isGLES2; } return false; } diff --git a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp index 5fa55251..607cf0a0 100644 --- a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp +++ b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp @@ -56,7 +56,7 @@ void GLInfo::init() { } if (!imageTextures && config.frameBufferEmulation.N64DepthCompare != 0) { config.frameBufferEmulation.N64DepthCompare = 0; - LOG(LOG_WARNING, "N64 depth compare and depth based fog will not work without Image Textures support provided in OpenGL >= 4.3 or GLES >= 3.1\n"); + LOG(LOG_WARNING, "N64 depth compare will not work without Image Textures support provided in OpenGL >= 4.3 or GLES >= 3.1\n"); } if (isGLES2) config.generalEmulation.enableFragmentDepthWrite = 0; diff --git a/src/Graphics/OpenGLContext/opengl_Parameters.cpp b/src/Graphics/OpenGLContext/opengl_Parameters.cpp index 7b659cd9..c176199d 100644 --- a/src/Graphics/OpenGLContext/opengl_Parameters.cpp +++ b/src/Graphics/OpenGLContext/opengl_Parameters.cpp @@ -74,8 +74,6 @@ namespace graphics { } namespace textureImageUnits { - ImageUnitParam Zlut(0U); - ImageUnitParam Tlut(1U); ImageUnitParam DepthZ(2U); ImageUnitParam DepthDeltaZ(3U); } diff --git a/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp b/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp index be166b3c..160cfb5e 100644 --- a/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp +++ b/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp @@ -191,7 +191,6 @@ namespace opengl { } if (_params.ImageUnit.isValid()) { - assert(IS_GL_FUNCTION_VALID(glBindImageTexture)); glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle), 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat)); } @@ -273,7 +272,6 @@ namespace opengl { _params.data); if (_params.ImageUnit.isValid() && _params.internalFormat.isValid()) { - assert(IS_GL_FUNCTION_VALID(glBindImageTexture)); glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle), 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat)); } diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index 22bebbe3..61a8f260 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -31,7 +31,6 @@ GraphicsDrawer::GraphicsDrawer() , m_dmaVerticesNum(0) , m_modifyVertices(0) , m_maxLineWidth(1.0f) -, m_bImageTexture(false) , m_bFlatColors(false) { memset(m_rect, 0, sizeof(m_rect)); @@ -991,7 +990,7 @@ bool texturedRectShadowMap(const GraphicsDrawer::TexturedRectParams &) if (gDP.textureImage.size == 2 && gDP.textureImage.address >= gDP.depthImageAddress && gDP.textureImage.address < (gDP.depthImageAddress + gDP.colorImage.width*gDP.colorImage.width * 6 / 4)) { - if (!Context::imageTextures) + if (!gfxContext.isSupported(SpecialFeatures::LUTTextures)) return true; pCurrentBuffer->m_pDepthBuffer->activateDepthBufferTexture(pCurrentBuffer); @@ -1721,7 +1720,6 @@ void GraphicsDrawer::_initData() FBInfo::fbInfo.reset(); m_texrectDrawer.init(); m_drawingState = DrawingState::Non; - m_bImageTexture = gfxContext.isSupported(SpecialFeatures::ImageTextures); m_maxLineWidth = gfxContext.getMaxLineWidth(); gSP.changed = gDP.changed = 0xFFFFFFFF; diff --git a/src/GraphicsDrawer.h b/src/GraphicsDrawer.h index d166ffc0..023ad1be 100644 --- a/src/GraphicsDrawer.h +++ b/src/GraphicsDrawer.h @@ -132,8 +132,6 @@ public: return (triangles.vertices[_v0].clip & triangles.vertices[_v1].clip & triangles.vertices[_v2].clip) != 0; } - bool isImageTexturesSupported() const { return m_bImageTexture; } - SPVertex & getVertex(u32 _v) { return triangles.vertices[_v]; } SPVertex * getVertexPtr(u32 _v) { return triangles.vertices.data() + _v; } @@ -205,7 +203,6 @@ private: u32 m_modifyVertices; f32 m_maxLineWidth; - bool m_bImageTexture; bool m_bFlatColors; TexrectDrawer m_texrectDrawer; OSDMessages m_osdMessages; diff --git a/src/PaletteTexture.cpp b/src/PaletteTexture.cpp index 64cd96d1..3a169af0 100644 --- a/src/PaletteTexture.cpp +++ b/src/PaletteTexture.cpp @@ -19,7 +19,7 @@ PaletteTexture::PaletteTexture() void PaletteTexture::init() { - if (!Context::imageTextures) + if (!gfxContext.isSupported(SpecialFeatures::LUTTextures)) return; const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); @@ -40,7 +40,6 @@ void PaletteTexture::init() Context::InitTextureParams initParams; initParams.handle = m_pTexture->name; - initParams.ImageUnit = textureImageUnits::Tlut; initParams.width = m_pTexture->realWidth; initParams.height = m_pTexture->realHeight; initParams.internalFormat = fbTexFormats.lutInternalFormat; @@ -64,19 +63,11 @@ void PaletteTexture::init() void PaletteTexture::destroy() { - if (!Context::imageTextures) + if (!gfxContext.isSupported(SpecialFeatures::LUTTextures)) return; const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); - Context::BindImageTextureParameters bindParams; - bindParams.imageUnit = textureImageUnits::Tlut; - bindParams.texture = ObjectHandle::null; - bindParams.accessMode = textureImageAccessMode::READ_ONLY; - bindParams.textureFormat = fbTexFormats.lutInternalFormat; - - gfxContext.bindImageTexture(bindParams); - textureCache().removeFrameBufferTexture(m_pTexture); m_pTexture = nullptr; free(m_pbuf); @@ -84,7 +75,7 @@ void PaletteTexture::destroy() void PaletteTexture::update() { - if (!Context::imageTextures) + if (!gfxContext.isSupported(SpecialFeatures::LUTTextures)) return; if (m_paletteCRC256 == gDP.paletteCRC256) @@ -100,7 +91,6 @@ void PaletteTexture::update() const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); Context::UpdateTextureDataParams params; params.handle = m_pTexture->name; - params.ImageUnit = textureImageUnits::Tlut; params.textureUnitIndex = textureIndices::PaletteTex; params.width = m_pTexture->realWidth; params.height = m_pTexture->realHeight; diff --git a/src/ZlutTexture.cpp b/src/ZlutTexture.cpp index 0a4ca3e8..e2cf9786 100644 --- a/src/ZlutTexture.cpp +++ b/src/ZlutTexture.cpp @@ -16,7 +16,7 @@ ZlutTexture::ZlutTexture() void ZlutTexture::init() { - if (!Context::imageTextures) + if (!gfxContext.isSupported(SpecialFeatures::LUTTextures)) return; const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); @@ -41,7 +41,6 @@ void ZlutTexture::init() Context::InitTextureParams initParams; initParams.handle = m_pTexture->name; - initParams.ImageUnit = textureImageUnits::Zlut; initParams.width = m_pTexture->realWidth; initParams.height = m_pTexture->realHeight; initParams.internalFormat = fbTexFormats.lutInternalFormat; @@ -61,20 +60,13 @@ void ZlutTexture::init() gfxContext.setTextureParameters(setParams); } -void ZlutTexture::destroy() { - if (!Context::imageTextures) +void ZlutTexture::destroy() +{ + if (!gfxContext.isSupported(SpecialFeatures::LUTTextures)) return; const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); - Context::BindImageTextureParameters bindParams; - bindParams.imageUnit = textureImageUnits::Zlut; - bindParams.texture = ObjectHandle::null; - bindParams.accessMode = textureImageAccessMode::READ_ONLY; - bindParams.textureFormat = fbTexFormats.lutInternalFormat; - - gfxContext.bindImageTexture(bindParams); - textureCache().removeFrameBufferTexture(m_pTexture); m_pTexture = nullptr; }