Loading libs/hwui/renderstate/MeshState.cpp +20 −35 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ MeshState::MeshState() glGenBuffers(1, &mUnitQuadBuffer); glBindBuffer(GL_ARRAY_BUFFER, mUnitQuadBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(kUnitQuadVertices), kUnitQuadVertices, GL_STATIC_DRAW); mCurrentBuffer = mUnitQuadBuffer; uint16_t regionIndices[kMaxNumberOfQuads * 6]; Loading Loading @@ -78,26 +77,18 @@ void MeshState::dump() { // Buffer Objects /////////////////////////////////////////////////////////////////////////////// bool MeshState::bindMeshBuffer() { return bindMeshBuffer(mUnitQuadBuffer); } bool MeshState::bindMeshBuffer(GLuint buffer) { if (!buffer) buffer = mUnitQuadBuffer; return bindMeshBufferInternal(buffer); } bool MeshState::unbindMeshBuffer() { return bindMeshBufferInternal(0); } bool MeshState::bindMeshBufferInternal(GLuint buffer) { void MeshState::bindMeshBuffer(GLuint buffer) { if (mCurrentBuffer != buffer) { glBindBuffer(GL_ARRAY_BUFFER, buffer); mCurrentBuffer = buffer; return true; // buffer has changed, so invalidate cached vertex pos/texcoord pointers resetVertexPointers(); } return false; } void MeshState::unbindMeshBuffer() { return bindMeshBuffer(0); } void MeshState::genOrUpdateMeshBuffer(GLuint* buffer, GLsizeiptr size, Loading @@ -122,16 +113,22 @@ void MeshState::deleteMeshBuffer(GLuint buffer) { // Vertices /////////////////////////////////////////////////////////////////////////////// void MeshState::bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) { void MeshState::bindPositionVertexPointer(const GLvoid* vertices, GLsizei stride) { // update pos coords if !current vbo, since vertices may point into mutable memory (e.g. stack) if (mCurrentBuffer == 0 || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) { glVertexAttribPointer(Program::kBindingPosition, 2, GL_FLOAT, GL_FALSE, stride, vertices); mCurrentPositionPointer = vertices; mCurrentPositionStride = stride; } } void MeshState::bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) { void MeshState::bindTexCoordsVertexPointer(const GLvoid* vertices, GLsizei stride) { // update tex coords if !current vbo, since vertices may point into mutable memory (e.g. stack) if (mCurrentBuffer == 0 || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) { glVertexAttribPointer(Program::kBindingTexCoords, 2, GL_FLOAT, GL_FALSE, stride, vertices); mCurrentTexCoordsPointer = vertices; mCurrentTexCoordsStride = stride; Loading @@ -143,10 +140,6 @@ void MeshState::resetVertexPointers() { mCurrentTexCoordsPointer = this; } void MeshState::resetTexCoordsVertexPointer() { mCurrentTexCoordsPointer = this; } void MeshState::enableTexCoordsVertexArray() { if (!mTexCoordsArrayEnabled) { glEnableVertexAttribArray(Program::kBindingTexCoords); Loading @@ -166,26 +159,18 @@ void MeshState::disableTexCoordsVertexArray() { // Indices /////////////////////////////////////////////////////////////////////////////// bool MeshState::bindIndicesBufferInternal(const GLuint buffer) { void MeshState::bindIndicesBuffer(const GLuint buffer) { if (mCurrentIndicesBuffer != buffer) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); mCurrentIndicesBuffer = buffer; return true; } return false; } bool MeshState::bindQuadIndicesBuffer() { return bindIndicesBufferInternal(mQuadListIndices); } bool MeshState::unbindIndicesBuffer() { void MeshState::unbindIndicesBuffer() { if (mCurrentIndicesBuffer) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); mCurrentIndicesBuffer = 0; return true; } return false; } } /* namespace uirenderer */ Loading libs/hwui/renderstate/MeshState.h +7 −18 Original line number Diff line number Diff line Loading @@ -60,20 +60,16 @@ public: /////////////////////////////////////////////////////////////////////////////// // Buffer objects /////////////////////////////////////////////////////////////////////////////// /** * Binds the VBO used to render simple textured quads. */ bool bindMeshBuffer(); /** * Binds the specified VBO if needed. If buffer == 0, binds default simple textured quad. */ bool bindMeshBuffer(GLuint buffer); void bindMeshBuffer(GLuint buffer); /** * Unbinds the VBO used to render simple textured quads. * Unbinds the current VBO if active. */ bool unbindMeshBuffer(); void unbindMeshBuffer(); void genOrUpdateMeshBuffer(GLuint* buffer, GLsizeiptr size, const void* data, GLenum usage); void deleteMeshBuffer(GLuint); Loading @@ -85,21 +81,20 @@ public: * Binds an attrib to the specified float vertex pointer. * Assumes a stride of gTextureVertexStride and a size of 2. */ void bindPositionVertexPointer(bool force, const GLvoid* vertices, void bindPositionVertexPointer(const GLvoid* vertices, GLsizei stride = kTextureVertexStride); /** * Binds an attrib to the specified float vertex pointer. * Assumes a stride of gTextureVertexStride and a size of 2. */ void bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, void bindTexCoordsVertexPointer(const GLvoid* vertices, GLsizei stride = kTextureVertexStride); /** * Resets the vertex pointers. */ void resetVertexPointers(); void resetTexCoordsVertexPointer(); void enableTexCoordsVertexArray(); void disableTexCoordsVertexArray(); Loading @@ -107,12 +102,8 @@ public: /////////////////////////////////////////////////////////////////////////////// // Indices /////////////////////////////////////////////////////////////////////////////// /** * Binds a global indices buffer that can draw up to * gMaxNumberOfQuads quads. */ bool bindQuadIndicesBuffer(); bool unbindIndicesBuffer(); void bindIndicesBuffer(const GLuint buffer); void unbindIndicesBuffer(); /////////////////////////////////////////////////////////////////////////////// // Getters - for use in Glop building Loading @@ -121,8 +112,6 @@ public: GLuint getQuadListIBO() { return mQuadListIndices; } private: MeshState(); bool bindMeshBufferInternal(const GLuint buffer); bool bindIndicesBufferInternal(const GLuint buffer); GLuint mUnitQuadBuffer; Loading libs/hwui/renderstate/RenderState.cpp +9 −12 Original line number Diff line number Diff line Loading @@ -292,28 +292,27 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) { // ---------- Mesh setup ---------- // -------------------------------- // vertices const bool force = meshState().bindMeshBufferInternal(vertices.bufferObject) || (vertices.position != nullptr); meshState().bindPositionVertexPointer(force, vertices.position, vertices.stride); meshState().bindMeshBuffer(vertices.bufferObject); meshState().bindPositionVertexPointer(vertices.position, vertices.stride); // indices meshState().bindIndicesBufferInternal(indices.bufferObject); meshState().bindIndicesBuffer(indices.bufferObject); if (vertices.attribFlags & VertexAttribFlags::TextureCoord) { const Glop::Fill::TextureData& texture = fill.texture; // texture always takes slot 0, shader samplers increment from there mCaches->textureState().activateTexture(0); mCaches->textureState().bindTexture(texture.target, texture.texture->id()); if (texture.clamp != GL_INVALID_ENUM) { texture.texture->setWrap(texture.clamp, true, false, texture.target); texture.texture->setWrap(texture.clamp, false, false, texture.target); } if (texture.filter != GL_INVALID_ENUM) { texture.texture->setFilter(texture.filter, true, false, texture.target); texture.texture->setFilter(texture.filter, false, false, texture.target); } mCaches->textureState().bindTexture(texture.target, texture.texture->id()); meshState().enableTexCoordsVertexArray(); meshState().bindTexCoordsVertexPointer(force, vertices.texCoord, vertices.stride); meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride); if (texture.textureTransform) { glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1, Loading Loading @@ -361,11 +360,9 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) { const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position); while (elementsCount > 0) { GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6); // rebind pointers without forcing, since initial bind handled above meshState().bindPositionVertexPointer(false, vertexData, vertices.stride); meshState().bindPositionVertexPointer(vertexData, vertices.stride); if (vertices.attribFlags & VertexAttribFlags::TextureCoord) { meshState().bindTexCoordsVertexPointer(false, meshState().bindTexCoordsVertexPointer( vertexData + kMeshTextureOffset, vertices.stride); } Loading Loading
libs/hwui/renderstate/MeshState.cpp +20 −35 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ MeshState::MeshState() glGenBuffers(1, &mUnitQuadBuffer); glBindBuffer(GL_ARRAY_BUFFER, mUnitQuadBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(kUnitQuadVertices), kUnitQuadVertices, GL_STATIC_DRAW); mCurrentBuffer = mUnitQuadBuffer; uint16_t regionIndices[kMaxNumberOfQuads * 6]; Loading Loading @@ -78,26 +77,18 @@ void MeshState::dump() { // Buffer Objects /////////////////////////////////////////////////////////////////////////////// bool MeshState::bindMeshBuffer() { return bindMeshBuffer(mUnitQuadBuffer); } bool MeshState::bindMeshBuffer(GLuint buffer) { if (!buffer) buffer = mUnitQuadBuffer; return bindMeshBufferInternal(buffer); } bool MeshState::unbindMeshBuffer() { return bindMeshBufferInternal(0); } bool MeshState::bindMeshBufferInternal(GLuint buffer) { void MeshState::bindMeshBuffer(GLuint buffer) { if (mCurrentBuffer != buffer) { glBindBuffer(GL_ARRAY_BUFFER, buffer); mCurrentBuffer = buffer; return true; // buffer has changed, so invalidate cached vertex pos/texcoord pointers resetVertexPointers(); } return false; } void MeshState::unbindMeshBuffer() { return bindMeshBuffer(0); } void MeshState::genOrUpdateMeshBuffer(GLuint* buffer, GLsizeiptr size, Loading @@ -122,16 +113,22 @@ void MeshState::deleteMeshBuffer(GLuint buffer) { // Vertices /////////////////////////////////////////////////////////////////////////////// void MeshState::bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) { void MeshState::bindPositionVertexPointer(const GLvoid* vertices, GLsizei stride) { // update pos coords if !current vbo, since vertices may point into mutable memory (e.g. stack) if (mCurrentBuffer == 0 || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) { glVertexAttribPointer(Program::kBindingPosition, 2, GL_FLOAT, GL_FALSE, stride, vertices); mCurrentPositionPointer = vertices; mCurrentPositionStride = stride; } } void MeshState::bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) { void MeshState::bindTexCoordsVertexPointer(const GLvoid* vertices, GLsizei stride) { // update tex coords if !current vbo, since vertices may point into mutable memory (e.g. stack) if (mCurrentBuffer == 0 || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) { glVertexAttribPointer(Program::kBindingTexCoords, 2, GL_FLOAT, GL_FALSE, stride, vertices); mCurrentTexCoordsPointer = vertices; mCurrentTexCoordsStride = stride; Loading @@ -143,10 +140,6 @@ void MeshState::resetVertexPointers() { mCurrentTexCoordsPointer = this; } void MeshState::resetTexCoordsVertexPointer() { mCurrentTexCoordsPointer = this; } void MeshState::enableTexCoordsVertexArray() { if (!mTexCoordsArrayEnabled) { glEnableVertexAttribArray(Program::kBindingTexCoords); Loading @@ -166,26 +159,18 @@ void MeshState::disableTexCoordsVertexArray() { // Indices /////////////////////////////////////////////////////////////////////////////// bool MeshState::bindIndicesBufferInternal(const GLuint buffer) { void MeshState::bindIndicesBuffer(const GLuint buffer) { if (mCurrentIndicesBuffer != buffer) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); mCurrentIndicesBuffer = buffer; return true; } return false; } bool MeshState::bindQuadIndicesBuffer() { return bindIndicesBufferInternal(mQuadListIndices); } bool MeshState::unbindIndicesBuffer() { void MeshState::unbindIndicesBuffer() { if (mCurrentIndicesBuffer) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); mCurrentIndicesBuffer = 0; return true; } return false; } } /* namespace uirenderer */ Loading
libs/hwui/renderstate/MeshState.h +7 −18 Original line number Diff line number Diff line Loading @@ -60,20 +60,16 @@ public: /////////////////////////////////////////////////////////////////////////////// // Buffer objects /////////////////////////////////////////////////////////////////////////////// /** * Binds the VBO used to render simple textured quads. */ bool bindMeshBuffer(); /** * Binds the specified VBO if needed. If buffer == 0, binds default simple textured quad. */ bool bindMeshBuffer(GLuint buffer); void bindMeshBuffer(GLuint buffer); /** * Unbinds the VBO used to render simple textured quads. * Unbinds the current VBO if active. */ bool unbindMeshBuffer(); void unbindMeshBuffer(); void genOrUpdateMeshBuffer(GLuint* buffer, GLsizeiptr size, const void* data, GLenum usage); void deleteMeshBuffer(GLuint); Loading @@ -85,21 +81,20 @@ public: * Binds an attrib to the specified float vertex pointer. * Assumes a stride of gTextureVertexStride and a size of 2. */ void bindPositionVertexPointer(bool force, const GLvoid* vertices, void bindPositionVertexPointer(const GLvoid* vertices, GLsizei stride = kTextureVertexStride); /** * Binds an attrib to the specified float vertex pointer. * Assumes a stride of gTextureVertexStride and a size of 2. */ void bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, void bindTexCoordsVertexPointer(const GLvoid* vertices, GLsizei stride = kTextureVertexStride); /** * Resets the vertex pointers. */ void resetVertexPointers(); void resetTexCoordsVertexPointer(); void enableTexCoordsVertexArray(); void disableTexCoordsVertexArray(); Loading @@ -107,12 +102,8 @@ public: /////////////////////////////////////////////////////////////////////////////// // Indices /////////////////////////////////////////////////////////////////////////////// /** * Binds a global indices buffer that can draw up to * gMaxNumberOfQuads quads. */ bool bindQuadIndicesBuffer(); bool unbindIndicesBuffer(); void bindIndicesBuffer(const GLuint buffer); void unbindIndicesBuffer(); /////////////////////////////////////////////////////////////////////////////// // Getters - for use in Glop building Loading @@ -121,8 +112,6 @@ public: GLuint getQuadListIBO() { return mQuadListIndices; } private: MeshState(); bool bindMeshBufferInternal(const GLuint buffer); bool bindIndicesBufferInternal(const GLuint buffer); GLuint mUnitQuadBuffer; Loading
libs/hwui/renderstate/RenderState.cpp +9 −12 Original line number Diff line number Diff line Loading @@ -292,28 +292,27 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) { // ---------- Mesh setup ---------- // -------------------------------- // vertices const bool force = meshState().bindMeshBufferInternal(vertices.bufferObject) || (vertices.position != nullptr); meshState().bindPositionVertexPointer(force, vertices.position, vertices.stride); meshState().bindMeshBuffer(vertices.bufferObject); meshState().bindPositionVertexPointer(vertices.position, vertices.stride); // indices meshState().bindIndicesBufferInternal(indices.bufferObject); meshState().bindIndicesBuffer(indices.bufferObject); if (vertices.attribFlags & VertexAttribFlags::TextureCoord) { const Glop::Fill::TextureData& texture = fill.texture; // texture always takes slot 0, shader samplers increment from there mCaches->textureState().activateTexture(0); mCaches->textureState().bindTexture(texture.target, texture.texture->id()); if (texture.clamp != GL_INVALID_ENUM) { texture.texture->setWrap(texture.clamp, true, false, texture.target); texture.texture->setWrap(texture.clamp, false, false, texture.target); } if (texture.filter != GL_INVALID_ENUM) { texture.texture->setFilter(texture.filter, true, false, texture.target); texture.texture->setFilter(texture.filter, false, false, texture.target); } mCaches->textureState().bindTexture(texture.target, texture.texture->id()); meshState().enableTexCoordsVertexArray(); meshState().bindTexCoordsVertexPointer(force, vertices.texCoord, vertices.stride); meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride); if (texture.textureTransform) { glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1, Loading Loading @@ -361,11 +360,9 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) { const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position); while (elementsCount > 0) { GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6); // rebind pointers without forcing, since initial bind handled above meshState().bindPositionVertexPointer(false, vertexData, vertices.stride); meshState().bindPositionVertexPointer(vertexData, vertices.stride); if (vertices.attribFlags & VertexAttribFlags::TextureCoord) { meshState().bindTexCoordsVertexPointer(false, meshState().bindTexCoordsVertexPointer( vertexData + kMeshTextureOffset, vertices.stride); } Loading