summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/Render.cpp
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2018-12-04 08:47:46 +0100
committerGitHub <noreply@github.com>2018-12-04 08:47:46 +0100
commit59de8ea50338b39f604fde738229aaeb791cc459 (patch)
tree17f445fc7a686cd28859e6c46fb1a32d64a56123 /Source/Core/VideoBackends/OGL/Render.cpp
parentc675ef148e6872115bd46cca5b5c51826c75b373 (diff)
parent7afd5cc2fb7e45f2c497e5aed007a017b8461335 (diff)
Merge pull request #7592 from stenzek/imgui-prereq
VideoBackends: Share GX vertex/index/uniform buffers with utility draws
Diffstat (limited to 'Source/Core/VideoBackends/OGL/Render.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/Render.cpp99
1 files changed, 39 insertions, 60 deletions
diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp
index 120774b4f7..55de5ec0dc 100644
--- a/Source/Core/VideoBackends/OGL/Render.cpp
+++ b/Source/Core/VideoBackends/OGL/Render.cpp
@@ -355,7 +355,8 @@ static void InitDriverInfo()
// Init functions
Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context)
: ::Renderer(static_cast<int>(std::max(main_gl_context->GetBackBufferWidth(), 1u)),
- static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u))),
+ static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u)),
+ AbstractTextureFormat::RGBA8),
m_main_gl_context(std::move(main_gl_context))
{
bool bSuccess = true;
@@ -811,19 +812,11 @@ bool Renderer::IsHeadless() const
return m_main_gl_context->IsHeadless();
}
-void Renderer::Shutdown()
+bool Renderer::Initialize()
{
- ::Renderer::Shutdown();
- g_framebuffer_manager.reset();
+ if (!::Renderer::Initialize())
+ return false;
- UpdateActiveConfig();
-
- s_raster_font.reset();
- m_post_processor.reset();
-}
-
-void Renderer::Init()
-{
// Initialize the FramebufferManager
g_framebuffer_manager = std::make_unique<FramebufferManager>(
m_target_width, m_target_height, s_MSAASamples, BoundingBox::NeedsStencilBuffer());
@@ -832,6 +825,19 @@ void Renderer::Init()
m_post_processor = std::make_unique<OpenGLPostProcessing>();
s_raster_font = std::make_unique<RasterFont>();
+
+ return true;
+}
+
+void Renderer::Shutdown()
+{
+ ::Renderer::Shutdown();
+ g_framebuffer_manager.reset();
+
+ UpdateActiveConfig();
+
+ s_raster_font.reset();
+ m_post_processor.reset();
}
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
@@ -1178,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<const OGLPipeline*>(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<const OGLPipeline*>(m_graphics_pipeline)->GetGLPrimitive(),
+ num_indices, GL_UNSIGNED_SHORT,
+ static_cast<u16*>(nullptr) + base_index, base_vertex);
+ }
+ else
+ {
+ glDrawElements(static_cast<const OGLPipeline*>(m_graphics_pipeline)->GetGLPrimitive(),
+ num_indices, GL_UNSIGNED_SHORT, static_cast<u16*>(nullptr) + base_index);
+ }
+}
+
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
u32 color, u32 z)
{
@@ -1669,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<VertexManager*>(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<const OGLShader*>(shader)->GetGLComputeProgramID());
- if (uniforms_size > 0)
- UploadUtilityUniforms(uniforms, uniforms_size);
-
- glDispatchCompute(groups_x, groups_y, groups_z);
- ProgramShaderCache::InvalidateLastProgram();
-}
-
std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCompiler()
{
return std::make_unique<SharedContextAsyncShaderCompiler>();