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(); return ss.str();
} }
std::string GPU_HW::GenerateFragmentShader(bool textured, bool blending, bool transparent, std::string GPU_HW::GenerateFragmentShader(bool transparent, bool textured, TextureColorMode texture_color_mode,
TextureColorMode texture_color_mode) bool blending)
{ {
std::stringstream ss; std::stringstream ss;
GenerateShaderHeader(ss); GenerateShaderHeader(ss);
DefineMacro(ss, "TRANSPARENT", transparent);
DefineMacro(ss, "TEXTURED", textured); DefineMacro(ss, "TEXTURED", textured);
DefineMacro(ss, "BLENDING", blending);
DefineMacro(ss, "PALETTE", DefineMacro(ss, "PALETTE",
textured && (texture_color_mode == GPU::TextureColorMode::Palette4Bit || textured && (texture_color_mode == GPU::TextureColorMode::Palette4Bit ||
texture_color_mode == GPU::TextureColorMode::Palette8Bit)); texture_color_mode == GPU::TextureColorMode::Palette8Bit));
DefineMacro(ss, "PALETTE_4_BIT", textured && texture_color_mode == GPU::TextureColorMode::Palette4Bit); 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, "PALETTE_8_BIT", textured && texture_color_mode == GPU::TextureColorMode::Palette8Bit);
DefineMacro(ss, "BLENDING", blending);
ss << R"( ss << R"(
in vec3 v_col0; in vec3 v_col0;

View File

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

View File

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

View File

@ -51,8 +51,8 @@ private:
void CreateVertexBuffer(); void CreateVertexBuffer();
bool CompilePrograms(); 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(); void SetDrawState();
// downsample texture - used for readbacks at >1xIR. // downsample texture - used for readbacks at >1xIR.
@ -74,7 +74,7 @@ private:
bool m_last_transparency_enable = false; bool m_last_transparency_enable = false;
TransparencyMode m_last_transparency_mode = TransparencyMode::BackgroundMinusForeground; 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; std::array<GL::Program, 3> m_texture_page_programs;
GLStats m_stats = {}; GLStats m_stats = {};