GPU: Fix transparency not being enabled in shader

This commit is contained in:
Connor McLaughlin 2019-10-04 23:31:26 +10:00
parent 27bc65fc2a
commit a9313b2958
4 changed files with 17 additions and 16 deletions

View File

@ -237,18 +237,19 @@ void main()
return ss.str();
}
std::string GPU_HW::GenerateFragmentShader(bool textured, bool blending, bool transparent,
TextureColorMode texture_color_mode)
std::string GPU_HW::GenerateFragmentShader(bool transparent, bool textured, TextureColorMode texture_color_mode,
bool blending)
{
std::stringstream ss;
GenerateShaderHeader(ss);
DefineMacro(ss, "TRANSPARENT", transparent);
DefineMacro(ss, "TEXTURED", textured);
DefineMacro(ss, "BLENDING", blending);
DefineMacro(ss, "PALETTE",
textured && (texture_color_mode == GPU::TextureColorMode::Palette4Bit ||
texture_color_mode == GPU::TextureColorMode::Palette8Bit));
DefineMacro(ss, "PALETTE_4_BIT", textured && texture_color_mode == GPU::TextureColorMode::Palette4Bit);
DefineMacro(ss, "PALETTE_8_BIT", textured && texture_color_mode == GPU::TextureColorMode::Palette8Bit);
DefineMacro(ss, "BLENDING", blending);
ss << R"(
in vec3 v_col0;

View File

@ -84,8 +84,8 @@ protected:
}
std::string GenerateVertexShader(bool textured);
std::string GenerateFragmentShader(bool textured, bool blending, bool transparent,
TextureColorMode texture_color_mode);
std::string GenerateFragmentShader(bool transparent, bool textured, TextureColorMode texture_color_mode,
bool blending);
std::string GenerateScreenQuadVertexShader();
std::string GenerateFillFragmentShader();

View File

@ -289,9 +289,9 @@ bool GPU_HW_OpenGL::CompilePrograms()
for (u32 format = 0; format < 3; format++)
{
// TODO: eliminate duplicate shaders here
if (!CompileProgram(m_render_programs[textured][blending][transparent][format],
ConvertToBoolUnchecked(textured), ConvertToBoolUnchecked(blending),
ConvertToBoolUnchecked(transparent), static_cast<TextureColorMode>(format)))
if (!CompileProgram(m_render_programs[transparent][textured][format][blending],
ConvertToBoolUnchecked(transparent), ConvertToBoolUnchecked(textured),
static_cast<TextureColorMode>(format), ConvertToBoolUnchecked(blending)))
{
return false;
}
@ -303,11 +303,11 @@ bool GPU_HW_OpenGL::CompilePrograms()
return true;
}
bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, bool textured, bool blending, bool transparent,
TextureColorMode texture_color_mode)
bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, bool transparent, bool textured,
TextureColorMode texture_color_mode, bool blending)
{
const std::string vs = GenerateVertexShader(textured);
const std::string fs = GenerateFragmentShader(textured, blending, transparent, texture_color_mode);
const std::string fs = GenerateFragmentShader(transparent, textured, texture_color_mode, blending);
if (!prog.Compile(vs.c_str(), fs.c_str()))
return false;
@ -342,8 +342,8 @@ bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, bool textured, bool blendi
void GPU_HW_OpenGL::SetDrawState()
{
const GL::Program& prog =
m_render_programs[BoolToUInt32(m_batch.texture_enable)][BoolToUInt32(m_batch.texture_blending_enable)]
[BoolToUInt32(m_batch.transparency_enable)][static_cast<u32>(m_batch.texture_color_mode)];
m_render_programs[BoolToUInt32(m_batch.transparency_enable)][BoolToUInt32(m_batch.texture_enable)]
[static_cast<u32>(m_batch.texture_color_mode)][BoolToUInt32(m_batch.texture_blending_enable)];
prog.Bind();
prog.Uniform2i(0, m_drawing_offset.x, m_drawing_offset.y);

View File

@ -51,8 +51,8 @@ private:
void CreateVertexBuffer();
bool CompilePrograms();
bool CompileProgram(GL::Program& prog, bool textured, bool blending, bool transparent, TextureColorMode texture_color_mode);
bool CompileProgram(GL::Program& prog, bool transparent, bool textured, TextureColorMode texture_color_mode,
bool blending);
void SetDrawState();
// downsample texture - used for readbacks at >1xIR.
@ -74,7 +74,7 @@ private:
bool m_last_transparency_enable = false;
TransparencyMode m_last_transparency_mode = TransparencyMode::BackgroundMinusForeground;
std::array<std::array<std::array<std::array<GL::Program, 3>, 2>, 2>, 2> m_render_programs;
std::array<std::array<std::array<std::array<GL::Program, 2>, 3>, 2>, 2> m_render_programs;
std::array<GL::Program, 3> m_texture_page_programs;
GLStats m_stats = {};