diff --git a/src/pse-sdl/sdl_interface.cpp b/src/pse-sdl/sdl_interface.cpp index 1dc63f3fe..337a87b92 100644 --- a/src/pse-sdl/sdl_interface.cpp +++ b/src/pse-sdl/sdl_interface.cpp @@ -289,7 +289,7 @@ void SDLInterface::RenderDisplay() if (!m_display_texture) return; - glViewport(0, 0, m_window_width, m_window_height); + glViewport(0, 0, m_window_width, m_window_height - 20); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); diff --git a/src/pse/gpu.cpp b/src/pse/gpu.cpp index 7091dc0f9..4a2b336c6 100644 --- a/src/pse/gpu.cpp +++ b/src/pse/gpu.cpp @@ -409,6 +409,8 @@ bool GPU::HandleRenderCommand() ZeroExtend32(words_per_vertex)); DispatchRenderCommand(rc, num_vertices); + FlushRender(); + UpdateDisplay(); return true; } diff --git a/src/pse/gpu.h b/src/pse/gpu.h index c2631b756..5dac6f547 100644 --- a/src/pse/gpu.h +++ b/src/pse/gpu.h @@ -83,7 +83,7 @@ protected: u32 bits; BitField color_for_first_vertex; - BitField texture_blending_raw; // not valid for lines + BitField texture_blend_disable; // not valid for lines BitField transparency_enable; BitField texture_enable; BitField rectangle_size; // only for rectangles @@ -91,6 +91,10 @@ protected: BitField polyline; // only for lines BitField shading_enable; // 0 - flat, 1 = gouroud BitField primitive; + + // Helper functions. + bool IsTextureEnabled() const { return (primitive != Primitive::Line && texture_enable); } + bool IsTextureBlendingEnabled() const { return (IsTextureEnabled() && !texture_blend_disable); } }; // TODO: Use BitField to do sign extending instead diff --git a/src/pse/gpu_hw.cpp b/src/pse/gpu_hw.cpp index a1599df6a..d64e7dda1 100644 --- a/src/pse/gpu_hw.cpp +++ b/src/pse/gpu_hw.cpp @@ -166,6 +166,7 @@ in vec2 a_tex0; out vec4 v_col0; #if TEXTURED + uniform vec2 u_tex_scale; out vec2 v_tex0; #endif @@ -178,7 +179,7 @@ void main() v_col0 = a_col0; #if TEXTURED - v_tex0 = vec2(a_tex0.x / 4, a_tex0.y); + v_tex0 = vec2(a_tex0 * u_tex_scale); #endif } )"; diff --git a/src/pse/gpu_hw_opengl.cpp b/src/pse/gpu_hw_opengl.cpp index ea4c1d206..0b05c27b3 100644 --- a/src/pse/gpu_hw_opengl.cpp +++ b/src/pse/gpu_hw_opengl.cpp @@ -148,12 +148,12 @@ bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, bool textured, bool blendi if (!prog.Link()) return false; - prog.Bind(); - if (textured) { + prog.Bind(); + prog.RegisterUniform("u_tex_scale"); prog.RegisterUniform("samp0"); - prog.Uniform1i(0, 0); + prog.Uniform1i(1, 0); } return true; @@ -163,6 +163,29 @@ void GPU_HW_OpenGL::SetProgram(bool textured, bool blending) { const GL::Program& prog = textured ? (blending ? m_blended_texture_program : m_texture_program) : m_color_program; prog.Bind(); + + if (textured) + { + switch (m_texture_config.color_mode) + { + case GPU::TextureColorMode::Palette4Bit: + prog.Uniform2f(0, 1.0f / 4, 1.0f); + break; + + case GPU::TextureColorMode::Palette8Bit: + prog.Uniform2f(0, 1.0f / 2, 1.0f); + break; + + case GPU::TextureColorMode::Direct16Bit: + prog.Uniform2f(0, 1.0f, 1.0f); + break; + + default: + break; + } + + m_texture_page_texture->Bind(); + } } void GPU_HW_OpenGL::SetViewport() @@ -337,13 +360,10 @@ void GPU_HW_OpenGL::FlushRender() glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glDepthMask(GL_FALSE); - SetProgram(m_batch_command.texture_enable, m_batch_command.texture_blending_raw); + SetProgram(m_batch_command.IsTextureEnabled(), m_batch_command.IsTextureBlendingEnabled()); SetViewport(); SetScissor(); - if (m_batch_command.texture_enable) - m_texture_page_texture->Bind(); - glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer_fbo_id); glBindVertexArray(m_vao_id);