MeshState.h revision 6c15ffa196fc9b7724c189d833c3435d8db12266
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#ifndef RENDERSTATE_MESHSTATE_H 17#define RENDERSTATE_MESHSTATE_H 18 19#include "Vertex.h" 20 21#include <GLES2/gl2.h> 22#include <GLES2/gl2ext.h> 23#include <memory> 24 25namespace android { 26namespace uirenderer { 27 28class Program; 29 30// Maximum number of quads that pre-allocated meshes can draw 31const uint32_t kMaxNumberOfQuads = 2048; 32 33// This array is never used directly but used as a memcpy source in the 34// OpenGLRenderer constructor 35const TextureVertex kMeshVertices[] = { 36 { 0, 0, 0, 0 }, 37 { 1, 0, 1, 0 }, 38 { 0, 1, 0, 1 }, 39 { 1, 1, 1, 1 }, 40}; 41 42const GLsizei kVertexStride = sizeof(Vertex); 43const GLsizei kAlphaVertexStride = sizeof(AlphaVertex); 44const GLsizei kTextureVertexStride = sizeof(TextureVertex); 45 46const GLsizei kMeshTextureOffset = 2 * sizeof(float); 47const GLsizei kVertexAlphaOffset = 2 * sizeof(float); 48const GLsizei kVertexAAWidthOffset = 2 * sizeof(float); 49const GLsizei kVertexAALengthOffset = 3 * sizeof(float); 50const GLsizei kMeshCount = 4; 51 52class MeshState { 53private: 54 friend class RenderState; 55 56public: 57 ~MeshState(); 58 /////////////////////////////////////////////////////////////////////////////// 59 // Buffer objects 60 /////////////////////////////////////////////////////////////////////////////// 61 /** 62 * Binds the VBO used to render simple textured quads. 63 */ 64 bool bindMeshBuffer(); 65 66 /** 67 * Binds the specified VBO if needed. If buffer == 0, binds default simple textured quad. 68 */ 69 bool bindMeshBuffer(GLuint buffer); 70 71 /** 72 * Unbinds the VBO used to render simple textured quads. 73 */ 74 bool unbindMeshBuffer(); 75 76 /////////////////////////////////////////////////////////////////////////////// 77 // Vertices 78 /////////////////////////////////////////////////////////////////////////////// 79 /** 80 * Binds an attrib to the specified float vertex pointer. 81 * Assumes a stride of gTextureVertexStride and a size of 2. 82 */ 83 void bindPositionVertexPointer(bool force, const GLvoid* vertices, 84 GLsizei stride = kTextureVertexStride); 85 86 /** 87 * Binds an attrib to the specified float vertex pointer. 88 * Assumes a stride of gTextureVertexStride and a size of 2. 89 */ 90 void bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, 91 GLsizei stride = kTextureVertexStride); 92 93 /** 94 * Resets the vertex pointers. 95 */ 96 void resetVertexPointers(); 97 void resetTexCoordsVertexPointer(); 98 99 void enableTexCoordsVertexArray(); 100 void disableTexCoordsVertexArray(); 101 102 /////////////////////////////////////////////////////////////////////////////// 103 // Indices 104 /////////////////////////////////////////////////////////////////////////////// 105 /** 106 * Binds a global indices buffer that can draw up to 107 * gMaxNumberOfQuads quads. 108 */ 109 bool bindQuadIndicesBuffer(); 110 bool bindShadowIndicesBuffer(); 111 bool unbindIndicesBuffer(); 112 113private: 114 MeshState(); 115 bool bindIndicesBufferInternal(const GLuint buffer); 116 117 // VBO to draw with 118 GLuint meshBuffer; 119 120 GLuint mCurrentBuffer; 121 GLuint mCurrentIndicesBuffer; 122 GLuint mCurrentPixelBuffer; 123 124 const void* mCurrentPositionPointer; 125 GLsizei mCurrentPositionStride; 126 const void* mCurrentTexCoordsPointer; 127 GLsizei mCurrentTexCoordsStride; 128 129 bool mTexCoordsArrayEnabled; 130 131 // Global index buffer 132 GLuint mQuadListIndices; 133 GLuint mShadowStripsIndices; 134}; 135 136} /* namespace uirenderer */ 137} /* namespace android */ 138 139#endif // RENDERSTATE_MESHSTATE_H 140