Skip to content

Commit

Permalink
Don't use buffer for element array
Browse files Browse the repository at this point in the history
  • Loading branch information
loganmc10 committed Feb 26, 2018
1 parent cb90bb9 commit 6527537
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
18 changes: 5 additions & 13 deletions src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ BufferedDrawer::BufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray *
glGenVertexArrays(1, &m_trisBuffers.vao);
glBindVertexArray(m_trisBuffers.vao);
_initBuffer(m_trisBuffers.vbo, m_bufMaxSize);
_initBuffer(m_trisBuffers.ebo, m_bufMaxSize);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::position, true);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::color, true);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, true);
Expand Down Expand Up @@ -66,8 +65,8 @@ BufferedDrawer::~BufferedDrawer()
{
m_bindBuffer->bind(Parameter(GL_ARRAY_BUFFER), ObjectHandle::null);
m_bindBuffer->bind(Parameter(GL_ELEMENT_ARRAY_BUFFER), ObjectHandle::null);
GLuint buffers[3] = { m_rectsBuffers.vbo.handle, m_trisBuffers.vbo.handle, m_trisBuffers.ebo.handle };
glDeleteBuffers(3, buffers);
GLuint buffers[2] = { m_rectsBuffers.vbo.handle, m_trisBuffers.vbo.handle };
glDeleteBuffers(2, buffers);
glBindVertexArray(0);
GLuint arrays[2] = { m_rectsBuffers.vao, m_trisBuffers.vao };
glDeleteVertexArrays(2, arrays);
Expand Down Expand Up @@ -182,13 +181,6 @@ void BufferedDrawer::_updateTrianglesBuffers(const graphics::Context::DrawTriang
const GLsizeiptr vboDataSize = _params.verticesCount * sizeof(Vertex);
Buffer & vboBuffer = m_trisBuffers.vbo;
_updateBuffer(vboBuffer, _params.verticesCount, vboDataSize, m_vertices.data());

if (_params.elements == nullptr)
return;

const GLsizeiptr eboDataSize = sizeof(GLubyte) * _params.elementsCount;
Buffer & eboBuffer = m_trisBuffers.ebo;
_updateBuffer(eboBuffer, _params.elementsCount, eboDataSize, _params.elements);
}

void BufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParameters & _params)
Expand All @@ -205,17 +197,17 @@ void BufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParamete

if (config.frameBufferEmulation.N64DepthCompare == 0) {
glDrawElementsBaseVertex(GLenum(_params.mode), _params.elementsCount, GL_UNSIGNED_BYTE,
(char*)nullptr + m_trisBuffers.ebo.pos - _params.elementsCount, m_trisBuffers.vbo.pos - _params.verticesCount);
_params.elements, m_trisBuffers.vbo.pos - _params.verticesCount);
return;
}

// Draw polygons one by one
const GLint eboStartPos = m_trisBuffers.ebo.pos - _params.elementsCount;
GLubyte * elements = (GLubyte*)_params.elements;
const GLint vboStartPos = m_trisBuffers.vbo.pos - _params.verticesCount;
for (GLuint i = 0; i < _params.elementsCount; i += 3) {
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
glDrawElementsBaseVertex(GLenum(_params.mode), 3, GL_UNSIGNED_BYTE,
(char*)nullptr + eboStartPos + i, vboStartPos);
&elements[i], vboStartPos);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Graphics/OpenGLContext/opengl_BufferedDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace opengl {
struct TrisBuffers {
GLuint vao = 0;
Buffer vbo = Buffer(GL_ARRAY_BUFFER);
Buffer ebo = Buffer(GL_ELEMENT_ARRAY_BUFFER);
};

struct Vertex
Expand Down

0 comments on commit 6527537

Please sign in to comment.