GPU: Various fixes (textures, blending)

This commit is contained in:
Connor McLaughlin 2019-09-26 00:15:21 +10:00
parent 767e8f08e0
commit ea3ba8b342
6 changed files with 181 additions and 124 deletions

View File

@ -83,7 +83,8 @@ int main(int argc, char* argv[])
{
// set log flags
// g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_DEBUG);
g_pLog->SetConsoleOutputParams(true, "GPU GPU_HW_OpenGL SPU Pad DigitalController", LOGLEVEL_DEBUG);
// g_pLog->SetConsoleOutputParams(true, "GPU GPU_HW_OpenGL SPU Pad DigitalController", LOGLEVEL_DEBUG);
g_pLog->SetConsoleOutputParams(true, "CDROM DMA SPU Pad DigitalController", LOGLEVEL_DEBUG);
#ifdef Y_BUILD_CONFIG_RELEASE
g_pLog->SetFilterLevel(LOGLEVEL_INFO);

View File

@ -38,6 +38,9 @@ void GPU::SoftReset()
m_crtc_state.regs.display_address_start = 0;
m_crtc_state.regs.horizontal_display_range = 0xC60260;
m_crtc_state.regs.vertical_display_range = 0x3FC10;
m_render_state = {};
m_render_state.texture_changed = true;
m_render_state.transparency_mode_changed = true;
UpdateGPUSTAT();
UpdateCRTCConfig();
}
@ -48,20 +51,24 @@ bool GPU::DoState(StateWrapper& sw)
FlushRender();
sw.Do(&m_GPUSTAT.bits);
sw.Do(&m_texture_config.base_x);
sw.Do(&m_texture_config.base_y);
sw.Do(&m_texture_config.palette_x);
sw.Do(&m_texture_config.palette_y);
sw.Do(&m_texture_config.page_attribute);
sw.Do(&m_texture_config.palette_attribute);
sw.Do(&m_texture_config.color_mode);
sw.Do(&m_texture_config.page_changed);
sw.Do(&m_texture_config.window_mask_x);
sw.Do(&m_texture_config.window_mask_y);
sw.Do(&m_texture_config.window_offset_x);
sw.Do(&m_texture_config.window_offset_y);
sw.Do(&m_texture_config.x_flip);
sw.Do(&m_texture_config.y_flip);
sw.Do(&m_render_state.texture_base_x);
sw.Do(&m_render_state.texture_base_y);
sw.Do(&m_render_state.texture_palette_x);
sw.Do(&m_render_state.texture_palette_y);
sw.Do(&m_render_state.texture_color_mode);
sw.Do(&m_render_state.transparency_mode);
sw.Do(&m_render_state.texture_window_mask_x);
sw.Do(&m_render_state.texture_window_mask_y);
sw.Do(&m_render_state.texture_window_offset_x);
sw.Do(&m_render_state.texture_window_offset_y);
sw.Do(&m_render_state.texture_x_flip);
sw.Do(&m_render_state.texture_y_flip);
sw.Do(&m_render_state.texpage_attribute);
sw.Do(&m_render_state.texlut_attribute);
sw.Do(&m_render_state.texture_changed);
sw.Do(&m_render_state.transparency_mode_changed);
sw.Do(&m_drawing_area.top_left_x);
sw.Do(&m_drawing_area.top_left_y);
sw.Do(&m_drawing_area.bottom_right_x);
@ -95,7 +102,8 @@ bool GPU::DoState(StateWrapper& sw)
if (sw.IsReading())
{
m_texture_config.page_changed = true;
m_render_state.texture_changed = true;
m_render_state.transparency_mode_changed = true;
UpdateGPUSTAT();
}
@ -399,21 +407,21 @@ void GPU::WriteGP0(u32 value)
const u32 MASK = ((UINT32_C(1) << 11) - 1);
m_GPUSTAT.bits = (m_GPUSTAT.bits & ~MASK) | param & MASK;
m_GPUSTAT.texture_disable = (param & (UINT32_C(1) << 11)) != 0;
m_texture_config.x_flip = (param & (UINT32_C(1) << 12)) != 0;
m_texture_config.y_flip = (param & (UINT32_C(1) << 13)) != 0;
m_render_state.texture_x_flip = (param & (UINT32_C(1) << 12)) != 0;
m_render_state.texture_y_flip = (param & (UINT32_C(1) << 13)) != 0;
Log_DebugPrintf("Set draw mode %08X", param);
}
break;
case 0xE2: // set texture window
{
m_texture_config.window_mask_x = param & UINT32_C(0x1F);
m_texture_config.window_mask_y = (param >> 5) & UINT32_C(0x1F);
m_texture_config.window_offset_x = (param >> 10) & UINT32_C(0x1F);
m_texture_config.window_offset_y = (param >> 15) & UINT32_C(0x1F);
Log_DebugPrintf("Set texture window %02X %02X %02X %02X", m_texture_config.window_mask_x,
m_texture_config.window_mask_y, m_texture_config.window_offset_x,
m_texture_config.window_offset_y);
m_render_state.texture_window_mask_x = param & UINT32_C(0x1F);
m_render_state.texture_window_mask_y = (param >> 5) & UINT32_C(0x1F);
m_render_state.texture_window_offset_x = (param >> 10) & UINT32_C(0x1F);
m_render_state.texture_window_offset_y = (param >> 15) & UINT32_C(0x1F);
Log_DebugPrintf("Set texture window %02X %02X %02X %02X", m_render_state.texture_window_mask_x,
m_render_state.texture_window_mask_y, m_render_state.texture_window_offset_x,
m_render_state.texture_window_offset_y);
}
break;
@ -745,7 +753,7 @@ bool GPU::HandleCopyRectangleVRAMToVRAMCommand()
void GPU::UpdateDisplay()
{
m_texture_config.page_changed = true;
m_render_state.texture_changed = true;
m_system->IncrementFrameNumber();
}
@ -761,45 +769,48 @@ void GPU::DispatchRenderCommand(RenderCommand rc, u32 num_vertices) {}
void GPU::FlushRender() {}
void GPU::TextureConfig::SetFromPolygonTexcoord(u32 texcoord0, u32 texcoord1)
void GPU::RenderState::SetFromPolygonTexcoord(u32 texcoord0, u32 texcoord1)
{
SetFromPaletteAttribute(Truncate16(texcoord0 >> 16));
SetFromPageAttribute(Truncate16(texcoord1 >> 16));
}
void GPU::TextureConfig::SetFromRectangleTexcoord(u32 texcoord)
void GPU::RenderState::SetFromRectangleTexcoord(u32 texcoord)
{
SetFromPaletteAttribute(Truncate16(texcoord >> 16));
}
void GPU::TextureConfig::SetFromPageAttribute(u16 value)
void GPU::RenderState::SetFromPageAttribute(u16 value)
{
const u16 old_page_attribute = texpage_attribute;
value &= PAGE_ATTRIBUTE_MASK;
if (page_attribute == value)
if (texpage_attribute == value)
return;
page_attribute = value;
page_changed = true;
texture_base_x = static_cast<s32>(ZeroExtend32(value & UINT16_C(0x0F)) * UINT32_C(64));
texture_base_y = static_cast<s32>(ZeroExtend32((value >> 4) & UINT16_C(1)) * UINT32_C(256));
texture_color_mode = (static_cast<TextureColorMode>((value >> 7) & UINT16_C(0x03)));
if (texture_color_mode == TextureColorMode::Reserved_Direct16Bit)
texture_color_mode = TextureColorMode::Direct16Bit;
base_x = static_cast<s32>(ZeroExtend32(value & UINT16_C(0x0F)) * UINT32_C(64));
base_y = static_cast<s32>(ZeroExtend32((value >> 11) & UINT16_C(1)) * UINT32_C(512));
color_mode = (static_cast<TextureColorMode>((value >> 7) & UINT16_C(0x03)));
if (color_mode == TextureColorMode::Reserved_Direct16Bit)
color_mode = TextureColorMode::Direct16Bit;
texpage_attribute = value;
texture_changed = (old_page_attribute & PAGE_ATTRIBUTE_TEXTURE_MASK) != (value & PAGE_ATTRIBUTE_TEXTURE_MASK);
const TransparencyMode old_transparency_mode = transparency_mode;
transparency_mode = (static_cast<TransparencyMode>((value >> 5) & UINT16_C(0x03)));
transparency_mode_changed = old_transparency_mode != transparency_mode;
}
void GPU::TextureConfig::SetFromPaletteAttribute(u16 value)
void GPU::RenderState::SetFromPaletteAttribute(u16 value)
{
value &= PALETTE_ATTRIBUTE_MASK;
if (palette_attribute == value)
if (texlut_attribute == value)
return;
palette_x = static_cast<s32>(ZeroExtend32(value & UINT16_C(0x3F)) * UINT32_C(16));
palette_y = static_cast<s32>(ZeroExtend32((value >> 6) & UINT16_C(0x1FF)));
palette_attribute = value;
page_changed = true;
texture_palette_x = static_cast<s32>(ZeroExtend32(value & UINT16_C(0x3F)) * UINT32_C(16));
texture_palette_y = static_cast<s32>(ZeroExtend32((value >> 6) & UINT16_C(0x1FF)));
texlut_attribute = value;
texture_changed = true;
}
bool GPU::DumpVRAMToFile(const char* filename, u32 width, u32 height, u32 stride, const void* buffer, bool remove_alpha)

View File

@ -220,41 +220,47 @@ protected:
BitField<u32, bool, 31, 1> drawing_even_line;
} m_GPUSTAT = {};
struct TextureConfig
struct RenderState
{
static constexpr u16 PAGE_ATTRIBUTE_MASK = UINT16_C(0b0000100111111111);
static constexpr u16 PAGE_ATTRIBUTE_TEXTURE_MASK = UINT16_C(0b0000000110011111);
static constexpr u16 PAGE_ATTRIBUTE_MASK = UINT16_C(0b0000000111111111);
static constexpr u16 PALETTE_ATTRIBUTE_MASK = UINT16_C(0b0111111111111111);
// decoded values
s32 base_x;
s32 base_y;
s32 palette_x;
s32 palette_y;
s32 texture_base_x;
s32 texture_base_y;
s32 texture_palette_x;
s32 texture_palette_y;
TextureColorMode texture_color_mode;
TransparencyMode transparency_mode;
u8 texture_window_mask_x; // in 8 pixel steps
u8 texture_window_mask_y; // in 8 pixel steps
u8 texture_window_offset_x; // in 8 pixel steps
u8 texture_window_offset_y; // in 8 pixel steps
bool texture_x_flip;
bool texture_y_flip;
// original values
u16 page_attribute; // from register in rectangle modes/vertex in polygon modes
u16 palette_attribute; // from vertex
TextureColorMode color_mode; // from register/vertex in polygon modes
TransparencyMode transparency_mode;
u16 texpage_attribute; // from register in rectangle modes/vertex in polygon modes
u16 texlut_attribute; // from vertex
bool page_changed = false;
bool texture_changed = false;
bool transparency_mode_changed = false;
bool IsPageChanged() const { return page_changed; }
void ClearPageChangedFlag() { page_changed = false; }
bool IsChanged() const { return texture_changed || transparency_mode_changed; }
bool IsTextureChanged() const { return texture_changed; }
void ClearTextureChangedFlag() { texture_changed = false; }
bool IsTransparencyModeChanged() const { return transparency_mode_changed; }
void ClearTransparencyModeChangedFlag() { transparency_mode_changed = false; }
void SetFromPolygonTexcoord(u32 texcoord0, u32 texcoord1);
void SetFromRectangleTexcoord(u32 texcoord);
void SetFromPageAttribute(u16 value);
void SetFromPaletteAttribute(u16 value);
u8 window_mask_x; // in 8 pixel steps
u8 window_mask_y; // in 8 pixel steps
u8 window_offset_x; // in 8 pixel steps
u8 window_offset_y; // in 8 pixel steps
bool x_flip;
bool y_flip;
} m_texture_config = {};
} m_render_state = {};
struct DrawingArea
{

View File

@ -14,9 +14,9 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices)
case Primitive::Polygon:
{
// if we're drawing quads, we need to create a degenerate triangle to restart the triangle strip
bool restart_strip = (rc.quad_polygon && !m_batch_vertices.empty());
bool restart_strip = (rc.quad_polygon && !m_batch.vertices.empty());
if (restart_strip)
m_batch_vertices.push_back(m_batch_vertices.back());
m_batch.vertices.push_back(m_batch.vertices.back());
const u32 first_color = rc.color_for_first_vertex;
const bool shaded = rc.shading_enable;
@ -39,10 +39,10 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices)
hw_vert.padding = 0;
m_batch_vertices.push_back(hw_vert);
m_batch.vertices.push_back(hw_vert);
if (restart_strip)
{
m_batch_vertices.push_back(m_batch_vertices.back());
m_batch.vertices.push_back(m_batch.vertices.back());
restart_strip = false;
}
}
@ -52,9 +52,9 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices)
case Primitive::Rectangle:
{
// if we're drawing quads, we need to create a degenerate triangle to restart the triangle strip
const bool restart_strip = !m_batch_vertices.empty();
const bool restart_strip = !m_batch.vertices.empty();
if (restart_strip)
m_batch_vertices.push_back(m_batch_vertices.back());
m_batch.vertices.push_back(m_batch.vertices.back());
u32 buffer_pos = 1;
const bool textured = rc.texture_enable;
@ -92,12 +92,12 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices)
const u8 tex_right = static_cast<u8>(tex_left + (rectangle_width - 1));
const u8 tex_bottom = static_cast<u8>(tex_top + (rectangle_height - 1));
m_batch_vertices.push_back(HWVertex{pos_left, pos_top, color, HWVertex::EncodeTexcoord(tex_left, tex_top)});
m_batch.vertices.push_back(HWVertex{pos_left, pos_top, color, HWVertex::EncodeTexcoord(tex_left, tex_top)});
if (restart_strip)
m_batch_vertices.push_back(m_batch_vertices.back());
m_batch_vertices.push_back(HWVertex{pos_right, pos_top, color, HWVertex::EncodeTexcoord(tex_right, tex_top)});
m_batch_vertices.push_back(HWVertex{pos_left, pos_bottom, color, HWVertex::EncodeTexcoord(tex_left, tex_bottom)});
m_batch_vertices.push_back(
m_batch.vertices.push_back(m_batch.vertices.back());
m_batch.vertices.push_back(HWVertex{pos_right, pos_top, color, HWVertex::EncodeTexcoord(tex_right, tex_top)});
m_batch.vertices.push_back(HWVertex{pos_left, pos_bottom, color, HWVertex::EncodeTexcoord(tex_left, tex_bottom)});
m_batch.vertices.push_back(
HWVertex{pos_right, pos_bottom, color, HWVertex::EncodeTexcoord(tex_right, tex_bottom)});
}
break;
@ -108,14 +108,6 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices)
}
}
void GPU_HW::CalcViewport(int* x, int* y, int* width, int* height)
{
*x = m_drawing_offset.x;
*y = m_drawing_offset.y;
*width = std::max(static_cast<int>(VRAM_WIDTH - m_drawing_offset.x), 1);
*height = std::max(static_cast<int>(VRAM_HEIGHT - m_drawing_offset.y), 1);
}
void GPU_HW::CalcScissorRect(int* left, int* top, int* right, int* bottom)
{
*left = m_drawing_area.top_left_x;
@ -188,11 +180,13 @@ out vec4 v_col0;
out vec2 v_tex0;
#endif
uniform ivec2 u_pos_offset;
void main()
{
// 0..+1023 -> -1..1
float pos_x = (float(a_pos.x) / 512.0) - 1.0;
float pos_y = (float(a_pos.y) / -256.0) + 1.0;
float pos_x = (float(a_pos.x + u_pos_offset.x) / 512.0) - 1.0;
float pos_y = (float(a_pos.y + u_pos_offset.y) / -256.0) + 1.0;
gl_Position = vec4(pos_x, pos_y, 0.0, 1.0);
v_col0 = a_col0;
@ -229,7 +223,7 @@ void main()
discard;
#if BLENDING
o_col0 = v_col0 * texcol;
o_col0 = vec4((ivec4(v_col0 * 255.0) * ivec4(texcol * 255.0)) >> 7) / 255.0;
#else
o_col0 = texcol;
#endif
@ -339,6 +333,16 @@ void main()
void GPU_HW::UpdateTexturePageTexture() {}
GPU_HW::HWRenderBatch::Primitive GPU_HW::GetPrimitiveForCommand(RenderCommand rc)
{
if (rc.primitive == Primitive::Line)
return HWRenderBatch::Primitive::Lines;
else if ((rc.primitive == Primitive::Polygon && rc.quad_polygon) || rc.primitive == Primitive::Rectangle)
return HWRenderBatch::Primitive::TriangleStrip;
else
return HWRenderBatch::Primitive::Triangles;
}
void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices)
{
if (rc.texture_enable)
@ -349,16 +353,16 @@ void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices)
case Primitive::Polygon:
{
if (rc.shading_enable)
m_texture_config.SetFromPolygonTexcoord(m_GP0_command[2], m_GP0_command[5]);
m_render_state.SetFromPolygonTexcoord(m_GP0_command[2], m_GP0_command[5]);
else
m_texture_config.SetFromPolygonTexcoord(m_GP0_command[2], m_GP0_command[4]);
m_render_state.SetFromPolygonTexcoord(m_GP0_command[2], m_GP0_command[4]);
}
break;
case Primitive::Rectangle:
{
m_texture_config.SetFromRectangleTexcoord(m_GP0_command[2]);
m_texture_config.SetFromPageAttribute(Truncate16(m_GPUSTAT.bits));
m_render_state.SetFromRectangleTexcoord(m_GP0_command[2]);
m_render_state.SetFromPageAttribute(Truncate16(m_GPUSTAT.bits));
}
break;
@ -366,25 +370,43 @@ void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices)
break;
}
if (m_texture_config.IsPageChanged())
if (m_render_state.IsChanged())
{
if (!m_batch_vertices.empty())
if (m_render_state.IsTextureChanged())
{
if (!IsFlushed())
FlushRender();
UpdateTexturePageTexture();
m_render_state.ClearTextureChangedFlag();
}
if (m_batch.transparency_enable && m_render_state.IsTransparencyModeChanged() && !IsFlushed())
FlushRender();
UpdateTexturePageTexture();
m_texture_config.ClearPageChangedFlag();
m_batch.transparency_mode = m_render_state.transparency_mode;
m_render_state.ClearTransparencyModeChangedFlag();
}
}
// extract state
const bool rc_texture_enable = rc.texture_enable;
const bool rc_texture_blend_enable = !rc.texture_blend_disable;
const HWRenderBatch::Primitive rc_primitive = GetPrimitiveForCommand(rc);
// flush when the command changes
if (!m_batch_vertices.empty())
if (!m_batch.vertices.empty())
{
// including the degenerate triangles for strips
const u32 max_added_vertices = num_vertices + 2;
if ((m_batch_vertices.size() + max_added_vertices) >= MAX_BATCH_VERTEX_COUNT || m_batch_command.bits != rc.bits)
const bool params_changed =
(m_batch.texture_enable != rc_texture_enable || m_batch.texture_blending_enable != rc_texture_blend_enable ||
m_batch.primitive != rc_primitive);
if ((m_batch.vertices.size() + max_added_vertices) >= MAX_BATCH_VERTEX_COUNT || params_changed)
FlushRender();
}
m_batch_command = rc;
m_batch.texture_enable = rc_texture_enable;
m_batch.texture_blending_enable = rc_texture_blend_enable;
m_batch.primitive = rc_primitive;
LoadVertices(rc, num_vertices);
}

View File

@ -26,6 +26,24 @@ protected:
static constexpr u16 EncodeTexcoord(u8 x, u8 y) { return ZeroExtend16(x) | (ZeroExtend16(y) << 8); }
};
struct HWRenderBatch
{
enum class Primitive : u8
{
Lines = 0,
Triangles = 1,
TriangleStrip = 2
};
Primitive primitive;
bool transparency_enable;
bool texture_enable;
bool texture_blending_enable;
TransparencyMode transparency_mode;
std::vector<HWVertex> vertices;
};
static constexpr u32 VERTEX_BUFFER_SIZE = 1 * 1024 * 1024;
static constexpr u32 MAX_BATCH_VERTEX_COUNT = VERTEX_BUFFER_SIZE / sizeof(HWVertex);
@ -39,11 +57,10 @@ protected:
virtual void UpdateTexturePageTexture();
bool IsFlushed() const { return !m_batch_vertices.empty(); }
bool IsFlushed() const { return m_batch.vertices.empty(); }
void DispatchRenderCommand(RenderCommand rc, u32 num_vertices) override;
void CalcViewport(int* x, int* y, int* width, int* height);
void CalcScissorRect(int* left, int* top, int* right, int* bottom);
std::string GenerateVertexShader(bool textured);
@ -52,10 +69,11 @@ protected:
std::string GenerateTexturePageFragmentShader(TextureColorMode mode);
std::string GenerateFillFragmentShader();
std::vector<HWVertex> m_batch_vertices;
RenderCommand m_batch_command = {};
HWRenderBatch m_batch = {};
private:
static HWRenderBatch::Primitive GetPrimitiveForCommand(RenderCommand rc);
void GenerateShaderHeader(std::stringstream& ss);
void LoadVertices(RenderCommand rc, u32 num_vertices);

View File

@ -148,11 +148,14 @@ bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, bool textured, bool blendi
if (!prog.Link())
return false;
prog.Bind();
prog.RegisterUniform("u_pos_offset");
prog.Uniform2i(0, 0, 0);
if (textured)
{
prog.Bind();
prog.RegisterUniform("samp0");
prog.Uniform1i(0, 0);
prog.Uniform1i(1, 0);
}
return true;
@ -165,16 +168,13 @@ void GPU_HW_OpenGL::SetProgram(bool textured, bool blending)
if (textured)
m_texture_page_texture->Bind();
prog.Uniform2i(0, m_drawing_offset.x, m_drawing_offset.y);
}
void GPU_HW_OpenGL::SetViewport()
{
int x, y, width, height;
CalcViewport(&x, &y, &width, &height);
y = VRAM_HEIGHT - y - height;
Log_DebugPrintf("SetViewport: Offset (%d,%d) Size (%d, %d)", x, y, width, height);
glViewport(x, y, width, height);
glViewport(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
}
void GPU_HW_OpenGL::SetScissor()
@ -207,13 +207,13 @@ void GPU_HW_OpenGL::SetBlendState()
{GL_CONSTANT_COLOR, GL_FUNC_ADD, GL_ONE, 0.25f} // B + F/4
}};
if (!m_batch_command.IsTransparencyEnabled())
if (!m_batch.transparency_enable)
{
glDisable(GL_BLEND);
return;
}
const BlendVars& vars = blend_vars[static_cast<u8>(m_texture_config.transparency_mode)];
const BlendVars& vars = blend_vars[static_cast<u8>(m_batch.transparency_mode)];
glEnable(GL_BLEND);
glBlendFuncSeparate(vars.src_factor, vars.dst_factor, GL_ONE, GL_ZERO);
glBlendEquationSeparate(vars.func, GL_FUNC_ADD);
@ -327,12 +327,12 @@ void GPU_HW_OpenGL::UpdateTexturePageTexture()
glViewport(0, 0, TEXTURE_PAGE_WIDTH, TEXTURE_PAGE_HEIGHT);
glBindVertexArray(m_attributeless_vao_id);
const GL::Program& prog = m_texture_page_programs[static_cast<u8>(m_texture_config.color_mode)];
const GL::Program& prog = m_texture_page_programs[static_cast<u8>(m_render_state.texture_color_mode)];
prog.Bind();
prog.Uniform2i(1, m_texture_config.base_x, m_texture_config.base_y);
if (m_texture_config.color_mode >= GPU::TextureColorMode::Palette4Bit)
prog.Uniform2i(2, m_texture_config.palette_x, m_texture_config.palette_y);
prog.Uniform2i(1, m_render_state.texture_base_x, m_render_state.texture_base_y);
if (m_render_state.texture_color_mode >= GPU::TextureColorMode::Palette4Bit)
prog.Uniform2i(2, m_render_state.texture_palette_x, m_render_state.texture_palette_y);
glDrawArrays(GL_TRIANGLES, 0, 3);
@ -342,14 +342,14 @@ void GPU_HW_OpenGL::UpdateTexturePageTexture()
void GPU_HW_OpenGL::FlushRender()
{
if (m_batch_vertices.empty())
if (m_batch.vertices.empty())
return;
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
glDepthMask(GL_FALSE);
SetProgram(m_batch_command.IsTextureEnabled(), m_batch_command.IsTextureBlendingEnabled());
SetProgram(m_batch.texture_enable, m_batch.texture_blending_enable);
SetViewport();
SetScissor();
SetBlendState();
@ -357,16 +357,15 @@ void GPU_HW_OpenGL::FlushRender()
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer_fbo_id);
glBindVertexArray(m_vao_id);
Assert((m_batch_vertices.size() * sizeof(HWVertex)) <= VERTEX_BUFFER_SIZE);
Assert((m_batch.vertices.size() * sizeof(HWVertex)) <= VERTEX_BUFFER_SIZE);
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, static_cast<GLsizei>(sizeof(HWVertex) * m_batch_vertices.size()),
m_batch_vertices.data());
glBufferSubData(GL_ARRAY_BUFFER, 0, static_cast<GLsizei>(sizeof(HWVertex) * m_batch.vertices.size()),
m_batch.vertices.data());
const bool is_strip = ((m_batch_command.primitive == Primitive::Polygon && m_batch_command.quad_polygon) ||
m_batch_command.primitive == Primitive::Rectangle);
glDrawArrays(is_strip ? GL_TRIANGLE_STRIP : GL_TRIANGLES, 0, static_cast<GLsizei>(m_batch_vertices.size()));
static constexpr std::array<GLenum, 3> gl_primitives = {{GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP}};
glDrawArrays(gl_primitives[static_cast<u8>(m_batch.primitive)], 0, static_cast<GLsizei>(m_batch.vertices.size()));
m_batch_vertices.clear();
m_batch.vertices.clear();
}
std::unique_ptr<GPU> GPU::CreateHardwareOpenGLRenderer()