From 40ea889b6a130e1dc994bdea1520cfff71a37397 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Jan 2015 16:56:29 -0800 Subject: [PATCH] Cache the VBO/index buffer to avoid redundancy. Well, mostly just redundant unbinds. --- GPU/GLES/Framebuffer.cpp | 8 ++++---- GPU/GLES/TextureCache.cpp | 4 ++-- GPU/GLES/TransformPipeline.cpp | 24 ++++++++++++------------ native | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index f71ede95cf..33028db70f 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -536,8 +536,8 @@ void FramebufferManager::DrawPlainColor(u32 color) { glsl_bind(program); glUniform4fv(plainColorLoc_, 1, col); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glstate.arrayBuffer.unbind(); + glstate.elementArrayBuffer.unbind(); glEnableVertexAttribArray(program->a_position); glVertexAttribPointer(program->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); @@ -608,8 +608,8 @@ void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, flo float time[4] = {time_now(), (vCount % 60) * 1.0f/60.0f, (float)vCount, (float)(flipCount % 60)}; glUniform4fv(timeLoc_, 1, time); } - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glstate.arrayBuffer.unbind(); + glstate.elementArrayBuffer.unbind(); glEnableVertexAttribArray(program->a_position); glEnableVertexAttribArray(program->a_texcoord0); glVertexAttribPointer(program->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index a93ef17256..981bff06a4 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1103,8 +1103,8 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe GLint a_position = glGetAttribLocation(program, "a_position"); GLint a_texcoord0 = glGetAttribLocation(program, "a_texcoord0"); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glstate.arrayBuffer.unbind(); + glstate.elementArrayBuffer.unbind(); glEnableVertexAttribArray(a_position); glEnableVertexAttribArray(a_texcoord0); diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 0aeaf264fe..49d0a051aa 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -691,24 +691,24 @@ void TransformDrawEngine::DoFlush() { } vai->vbo = AllocateBuffer(); - glBindBuffer(GL_ARRAY_BUFFER, vai->vbo); + glstate.arrayBuffer.bind(vai->vbo); glBufferData(GL_ARRAY_BUFFER, dec_->GetDecVtxFmt().stride * indexGen.MaxIndex(), decoded, GL_STATIC_DRAW); // If there's only been one primitive type, and it's either TRIANGLES, LINES or POINTS, // there is no need for the index buffer we built. We can then use glDrawArrays instead // for a very minor speed boost. if (useElements) { vai->ebo = AllocateBuffer(); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vai->ebo); + glstate.elementArrayBuffer.bind(vai->ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short) * indexGen.VertexCount(), (GLvoid *)decIndex, GL_STATIC_DRAW); } else { vai->ebo = 0; - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glstate.elementArrayBuffer.bind(vai->ebo); } } else { gpuStats.numCachedDrawCalls++; - glBindBuffer(GL_ARRAY_BUFFER, vai->vbo); + glstate.arrayBuffer.bind(vai->vbo); if (vai->ebo) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vai->ebo); + glstate.elementArrayBuffer.bind(vai->ebo); useElements = vai->ebo ? true : false; gpuStats.numCachedVertsDrawn += vai->numVerts; gstate_c.vertexFullAlpha = vai->flags & VAI_FLAG_VERTEXFULLALPHA; @@ -732,9 +732,9 @@ void TransformDrawEngine::DoFlush() { gpuStats.numCachedVertsDrawn += vai->numVerts; vbo = vai->vbo; ebo = vai->ebo; - glBindBuffer(GL_ARRAY_BUFFER, vbo); + glstate.arrayBuffer.bind(vbo); if (ebo) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); + glstate.elementArrayBuffer.bind(ebo); vertexCount = vai->numVerts; maxIndex = vai->maxIndex; prim = static_cast(vai->prim); @@ -766,8 +766,8 @@ rotateVBO: if (!useElements && indexGen.PureCount()) { vertexCount = indexGen.PureCount(); } - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glstate.arrayBuffer.unbind(); + glstate.elementArrayBuffer.unbind(); prim = indexGen.Prim(); } @@ -791,12 +791,12 @@ rotateVBO: glDrawRangeElements(glprim[prim], 0, maxIndex, vertexCount, GL_UNSIGNED_SHORT, ebo ? 0 : (GLvoid*)decIndex); #endif if (ebo) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glstate.elementArrayBuffer.unbind(); } else { glDrawArrays(glprim[prim], 0, vertexCount); } if (vbo) - glBindBuffer(GL_ARRAY_BUFFER, 0); + glstate.arrayBuffer.unbind(); } else { DecodeVerts(); bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE; @@ -833,7 +833,7 @@ rotateVBO: const int vertexSize = sizeof(transformed[0]); bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX; - glBindBuffer(GL_ARRAY_BUFFER, 0); + glstate.arrayBuffer.unbind(); glVertexAttribPointer(ATTR_POSITION, 4, GL_FLOAT, GL_FALSE, vertexSize, drawBuffer); int attrMask = program->attrMask; if (attrMask & (1 << ATTR_TEXCOORD)) glVertexAttribPointer(ATTR_TEXCOORD, doTextureProjection ? 3 : 2, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + offsetof(TransformedVertex, u)); diff --git a/native b/native index 84ed01df53..7a5e182fd1 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 84ed01df53cd557eb126c1f6badef7d9201add5f +Subproject commit 7a5e182fd1383ac3ae63748d38c8405eceb6291e