diff options
author | bunnei <bunneidev@gmail.com> | 2015-11-19 04:20:12 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2015-11-19 04:20:12 +0100 |
commit | ac829f87e0d32c693b333a35be823878a9b7d178 (patch) | |
tree | f14c20303507dbf6e3606761a077c699cbe26b74 /src/video_core/renderer_opengl/gl_rasterizer.cpp | |
parent | Merge pull request #1239 from wwylele/silent-vec-warning (diff) | |
parent | FragShader: Use an UBO instead of several individual uniforms (diff) | |
download | yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.tar yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.tar.gz yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.tar.bz2 yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.tar.lz yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.tar.xz yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.tar.zst yuzu-ac829f87e0d32c693b333a35be823878a9b7d178.zip |
Diffstat (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp')
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index d1def2f3b..9b4bddabd 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -46,14 +46,21 @@ void RasterizerOpenGL::InitObjects() { state.texture_units[i].sampler = texture_samplers[i].sampler.handle; } - // Generate VBO and VAO + // Generate VBO, VAO and UBO vertex_buffer.Create(); vertex_array.Create(); + uniform_buffer.Create(); state.draw.vertex_array = vertex_array.handle; state.draw.vertex_buffer = vertex_buffer.handle; + state.draw.uniform_buffer = uniform_buffer.handle; state.Apply(); + // Bind the UBO to binding point 0 + glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniform_buffer.handle); + + uniform_block_data.dirty = true; + // Set vertex attributes glVertexAttribPointer(GLShader::ATTRIBUTE_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, position)); glEnableVertexAttribArray(GLShader::ATTRIBUTE_POSITION); @@ -148,6 +155,11 @@ void RasterizerOpenGL::DrawTriangles() { state.draw.shader_dirty = false; } + if (uniform_block_data.dirty) { + glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformData), &uniform_block_data.data, GL_STATIC_DRAW); + uniform_block_data.dirty = false; + } + glBufferData(GL_ARRAY_BUFFER, vertex_batch.size() * sizeof(HardwareVertex), vertex_batch.data(), GL_STREAM_DRAW); glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertex_batch.size()); @@ -485,6 +497,9 @@ void RasterizerOpenGL::SetShader() { glUniform1i(PicaShader::Uniform::Texture2, 2); current_shader = shader_cache.emplace(config, std::move(shader)).first->second.get(); + + unsigned int block_index = glGetUniformBlockIndex(current_shader->shader.handle, "shader_data"); + glUniformBlockBinding(current_shader->shader.handle, block_index, 0); } // Update uniforms @@ -615,7 +630,10 @@ void RasterizerOpenGL::SyncBlendColor() { void RasterizerOpenGL::SyncAlphaTest() { const auto& regs = Pica::g_state.regs; - glUniform1i(PicaShader::Uniform::AlphaTestRef, regs.output_merger.alpha_test.ref); + if (regs.output_merger.alpha_test.ref != uniform_block_data.data.alphatest_ref) { + uniform_block_data.data.alphatest_ref = regs.output_merger.alpha_test.ref; + uniform_block_data.dirty = true; + } } void RasterizerOpenGL::SyncLogicOp() { @@ -647,12 +665,18 @@ void RasterizerOpenGL::SyncDepthTest() { void RasterizerOpenGL::SyncCombinerColor() { auto combiner_color = PicaToGL::ColorRGBA8(Pica::g_state.regs.tev_combiner_buffer_color.raw); - glUniform4fv(PicaShader::Uniform::TevCombinerBufferColor, 1, combiner_color.data()); + if (combiner_color != uniform_block_data.data.tev_combiner_buffer_color) { + uniform_block_data.data.tev_combiner_buffer_color = combiner_color; + uniform_block_data.dirty = true; + } } void RasterizerOpenGL::SyncTevConstColor(int stage_index, const Pica::Regs::TevStageConfig& tev_stage) { auto const_color = PicaToGL::ColorRGBA8(tev_stage.const_color); - glUniform4fv(PicaShader::Uniform::TevConstColors + stage_index, 1, const_color.data()); + if (const_color != uniform_block_data.data.const_color[stage_index]) { + uniform_block_data.data.const_color[stage_index] = const_color; + uniform_block_data.dirty = true; + } } void RasterizerOpenGL::SyncDrawState() { @@ -683,6 +707,7 @@ void RasterizerOpenGL::SyncDrawState() { } } + state.draw.uniform_buffer = uniform_buffer.handle; state.Apply(); } |