From 7afd5cc2fb7e45f2c497e5aed007a017b8461335 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 27 Nov 2018 17:16:53 +1000 Subject: Use main buffers for utility draws --- Source/Core/VideoBackends/OGL/Render.cpp | 69 ++++++++++---------------------- 1 file changed, 21 insertions(+), 48 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index c43bb0ac87..55de5ec0dc 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1184,6 +1184,27 @@ void Renderer::SetViewport(float x, float y, float width, float height, float ne glDepthRangef(near_depth, far_depth); } +void Renderer::Draw(u32 base_vertex, u32 num_vertices) +{ + glDrawArrays(static_cast(m_graphics_pipeline)->GetGLPrimitive(), base_vertex, + num_vertices); +} + +void Renderer::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) +{ + if (g_ogl_config.bSupportsGLBaseVertex) + { + glDrawElementsBaseVertex(static_cast(m_graphics_pipeline)->GetGLPrimitive(), + num_indices, GL_UNSIGNED_SHORT, + static_cast(nullptr) + base_index, base_vertex); + } + else + { + glDrawElements(static_cast(m_graphics_pipeline)->GetGLPrimitive(), + num_indices, GL_UNSIGNED_SHORT, static_cast(nullptr) + base_index); + } +} + void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) { @@ -1675,54 +1696,6 @@ void Renderer::SetInterlacingMode() // TODO } -void Renderer::DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices, - u32 vertex_stride, u32 num_vertices) -{ - // Copy in uniforms. - if (uniforms_size > 0) - UploadUtilityUniforms(uniforms, uniforms_size); - - // Draw from base index if there is vertex data. - if (vertices) - { - StreamBuffer* vbuf = static_cast(g_vertex_manager.get())->GetVertexBuffer(); - auto buf = vbuf->Map(vertex_stride * num_vertices, vertex_stride); - std::memcpy(buf.first, vertices, vertex_stride * num_vertices); - vbuf->Unmap(vertex_stride * num_vertices); - glDrawArrays(m_graphics_pipeline->GetGLPrimitive(), buf.second / vertex_stride, num_vertices); - } - else - { - glDrawArrays(m_graphics_pipeline->GetGLPrimitive(), 0, num_vertices); - } -} - -void Renderer::UploadUtilityUniforms(const void* uniforms, u32 uniforms_size) -{ - DEBUG_ASSERT(uniforms_size > 0); - - auto buf = ProgramShaderCache::GetUniformBuffer()->Map( - uniforms_size, ProgramShaderCache::GetUniformBufferAlignment()); - std::memcpy(buf.first, uniforms, uniforms_size); - ProgramShaderCache::GetUniformBuffer()->Unmap(uniforms_size); - glBindBufferRange(GL_UNIFORM_BUFFER, 1, ProgramShaderCache::GetUniformBuffer()->m_buffer, - buf.second, uniforms_size); - - // This is rather horrible, but because of how the UBOs are bound, this forces it to rebind. - ProgramShaderCache::InvalidateConstants(); -} - -void Renderer::DispatchComputeShader(const AbstractShader* shader, const void* uniforms, - u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z) -{ - glUseProgram(static_cast(shader)->GetGLComputeProgramID()); - if (uniforms_size > 0) - UploadUtilityUniforms(uniforms, uniforms_size); - - glDispatchCompute(groups_x, groups_y, groups_z); - ProgramShaderCache::InvalidateLastProgram(); -} - std::unique_ptr Renderer::CreateAsyncShaderCompiler() { return std::make_unique(); -- cgit v1.2.3