diff options
| author | 2011-12-13 13:11:32 -0800 | |
|---|---|---|
| committer | 2011-12-13 13:11:32 -0800 | |
| commit | 15bc6437f8b4cf10dba55c7638d349e7b9563f4f (patch) | |
| tree | 18e054e26a43a757fec54387571ae2d1aadbea1c /libs/hwui/Caches.cpp | |
| parent | 5009f65c9a676b64869e638e08ec0294e20d7e6e (diff) | |
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
Diffstat (limited to 'libs/hwui/Caches.cpp')
| -rw-r--r-- | libs/hwui/Caches.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
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; |