From 15bc6437f8b4cf10dba55c7638d349e7b9563f4f Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 13 Dec 2011 13:11:32 -0800 Subject: Reduce the number of GL commands generated by the UI This optimization along with the previous one lets us render an application like Gmail using only 30% of the number of GL commands previously required Change-Id: Ifee63edaf495e04490b5abd5433bb9a07bc327a8 --- libs/hwui/Caches.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'libs/hwui/Caches.cpp') diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index 4da576d51fa0..27039dd04311 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -73,9 +73,12 @@ void Caches::init() { glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW); mCurrentBuffer = meshBuffer; + mCurrentIndicesBuffer = 0; mCurrentPositionPointer = this; mCurrentTexCoordsPointer = this; + mTexCoordsArrayEnabled = false; + mRegionMesh = NULL; blend = false; @@ -243,6 +246,24 @@ bool Caches::unbindMeshBuffer() { return false; } +bool Caches::bindIndicesBuffer(const GLuint buffer) { + if (mCurrentIndicesBuffer != buffer) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); + mCurrentIndicesBuffer = buffer; + return true; + } + return false; +} + +bool Caches::unbindIndicesBuffer() { + if (mCurrentIndicesBuffer) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + mCurrentIndicesBuffer = 0; + return true; + } + return false; +} + void Caches::bindPositionVertexPointer(bool force, GLuint slot, GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentPositionPointer) { glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices); @@ -266,6 +287,20 @@ void Caches::resetTexCoordsVertexPointer() { mCurrentTexCoordsPointer = this; } +void Caches::enableTexCoordsVertexArray() { + if (!mTexCoordsArrayEnabled) { + glEnableVertexAttribArray(Program::kBindingTexCoords); + mTexCoordsArrayEnabled = true; + } +} + +void Caches::disbaleTexCoordsVertexArray() { + if (mTexCoordsArrayEnabled) { + glDisableVertexAttribArray(Program::kBindingTexCoords); + mTexCoordsArrayEnabled = false; + } +} + TextureVertex* Caches::getRegionMesh() { // Create the mesh, 2 triangles and 4 vertices per rectangle in the region if (!mRegionMesh) { @@ -284,13 +319,13 @@ TextureVertex* Caches::getRegionMesh() { } glGenBuffers(1, &mRegionMeshIndices); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices); + bindIndicesBuffer(mRegionMeshIndices); glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t), regionIndices, GL_STATIC_DRAW); delete[] regionIndices; } else { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices); + bindIndicesBuffer(mRegionMeshIndices); } return mRegionMesh; -- cgit v1.2.3-59-g8ed1b