OGL: Use stream buffer for vertex data.

This commit is contained in:
Markus Wick 2018-03-14 23:36:54 +01:00
parent 50598fbbf4
commit ac92664aa7
2 changed files with 15 additions and 6 deletions

View file

@ -41,12 +41,13 @@ RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) {
}
// Generate VBO, VAO and UBO
vertex_buffer.Create();
vertex_buffer = OGLStreamBuffer::MakeBuffer(GLAD_GL_ARB_buffer_storage, GL_ARRAY_BUFFER);
vertex_buffer->Create(VERTEX_BUFFER_SIZE, VERTEX_BUFFER_SIZE / 2);
vertex_array.Create();
uniform_buffer.Create();
state.draw.vertex_array = vertex_array.handle;
state.draw.vertex_buffer = vertex_buffer.handle;
state.draw.vertex_buffer = vertex_buffer->GetHandle();
state.draw.uniform_buffer = uniform_buffer.handle;
state.Apply();
@ -434,9 +435,15 @@ void RasterizerOpenGL::DrawTriangles() {
state.Apply();
// Draw the vertex batch
glBufferData(GL_ARRAY_BUFFER, vertex_batch.size() * sizeof(HardwareVertex), vertex_batch.data(),
GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertex_batch.size());
size_t max_vertices = 3 * (VERTEX_BUFFER_SIZE / (3 * sizeof(HardwareVertex)));
for (size_t base_vertex = 0; base_vertex < vertex_batch.size(); base_vertex += max_vertices) {
size_t vertices = std::min(max_vertices, vertex_batch.size() - base_vertex);
size_t vertex_size = vertices * sizeof(HardwareVertex);
auto map = vertex_buffer->Map(vertex_size, 1);
memcpy(map.first, vertex_batch.data() + base_vertex, vertex_size);
vertex_buffer->Unmap();
glDrawArrays(GL_TRIANGLES, map.second / sizeof(HardwareVertex), (GLsizei)vertices);
}
// Disable scissor test
state.scissor.enabled = false;

View file

@ -27,6 +27,7 @@
#include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_gen.h"
#include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/gl_stream_buffer.h"
#include "video_core/renderer_opengl/pica_to_gl.h"
#include "video_core/shader/shader.h"
@ -283,7 +284,8 @@ private:
std::array<SamplerInfo, 3> texture_samplers;
OGLVertexArray vertex_array;
OGLBuffer vertex_buffer;
static constexpr size_t VERTEX_BUFFER_SIZE = 128 * 1024 * 1024;
std::unique_ptr<OGLStreamBuffer> vertex_buffer;
OGLBuffer uniform_buffer;
OGLFramebuffer framebuffer;