mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Remove Image Texture requirement for some shaders
This commit is contained in:
parent
af6460ff4f
commit
9c73fb27b1
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<ContextImpl> m_impl;
|
||||
std::unique_ptr<FramebufferTextureFormats> m_fbTexFormats;
|
||||
|
|
|
@ -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"
|
||||
;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -74,8 +74,6 @@ namespace graphics {
|
|||
}
|
||||
|
||||
namespace textureImageUnits {
|
||||
ImageUnitParam Zlut(0U);
|
||||
ImageUnitParam Tlut(1U);
|
||||
ImageUnitParam DepthZ(2U);
|
||||
ImageUnitParam DepthDeltaZ(3U);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user