Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 19 | #include <utils/Log.h> |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 20 | #include <utils/String8.h> |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 21 | |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 22 | #include "Caches.h" |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 23 | #include "Properties.h" |
Romain Guy | 09b7c91 | 2011-02-02 20:28:09 -0800 | [diff] [blame] | 24 | #include "LayerRenderer.h" |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | #ifdef USE_OPENGL_RENDERER |
| 29 | using namespace uirenderer; |
| 30 | ANDROID_SINGLETON_STATIC_INSTANCE(Caches); |
| 31 | #endif |
| 32 | |
| 33 | namespace uirenderer { |
| 34 | |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 36 | // Macros |
| 37 | /////////////////////////////////////////////////////////////////////////////// |
| 38 | |
| 39 | #if DEBUG_CACHE_FLUSH |
| 40 | #define FLUSH_LOGD(...) LOGD(__VA_ARGS__) |
| 41 | #else |
| 42 | #define FLUSH_LOGD(...) |
| 43 | #endif |
| 44 | |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 46 | // Constructors/destructor |
| 47 | /////////////////////////////////////////////////////////////////////////////// |
| 48 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 49 | Caches::Caches(): Singleton<Caches>(), mInitialized(false) { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 50 | GLint maxTextureUnits; |
| 51 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); |
| 52 | if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) { |
| 53 | LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT); |
| 54 | } |
| 55 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 56 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); |
| 57 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 58 | init(); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 59 | |
| 60 | mDebugLevel = readDebugLevel(); |
| 61 | LOGD("Enabling debug mode %d", mDebugLevel); |
Romain Guy | 7230a74 | 2011-01-10 22:26:16 -0800 | [diff] [blame] | 62 | |
| 63 | #if RENDER_LAYERS_AS_REGIONS |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 64 | INIT_LOGD("Layers will be composited as regions"); |
Romain Guy | 7230a74 | 2011-01-10 22:26:16 -0800 | [diff] [blame] | 65 | #endif |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 68 | void Caches::init() { |
| 69 | if (mInitialized) return; |
| 70 | |
| 71 | glGenBuffers(1, &meshBuffer); |
| 72 | glBindBuffer(GL_ARRAY_BUFFER, meshBuffer); |
| 73 | glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW); |
| 74 | |
| 75 | mCurrentBuffer = meshBuffer; |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 76 | mCurrentIndicesBuffer = 0; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 77 | mCurrentPositionPointer = this; |
| 78 | mCurrentTexCoordsPointer = this; |
| 79 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 80 | mTexCoordsArrayEnabled = false; |
| 81 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame^] | 82 | glActiveTexture(gTextureUnits[0]); |
| 83 | mTextureUnit = 0; |
| 84 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 85 | mRegionMesh = NULL; |
| 86 | |
| 87 | blend = false; |
| 88 | lastSrcMode = GL_ZERO; |
| 89 | lastDstMode = GL_ZERO; |
| 90 | currentProgram = NULL; |
| 91 | |
| 92 | mInitialized = true; |
| 93 | } |
| 94 | |
| 95 | void Caches::terminate() { |
| 96 | if (!mInitialized) return; |
| 97 | |
| 98 | glDeleteBuffers(1, &meshBuffer); |
| 99 | mCurrentBuffer = 0; |
| 100 | |
| 101 | glDeleteBuffers(1, &mRegionMeshIndices); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 102 | delete[] mRegionMesh; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 103 | mRegionMesh = NULL; |
| 104 | |
| 105 | fboCache.clear(); |
| 106 | |
| 107 | programCache.clear(); |
| 108 | currentProgram = NULL; |
| 109 | |
| 110 | mInitialized = false; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 114 | // Debug |
| 115 | /////////////////////////////////////////////////////////////////////////////// |
| 116 | |
| 117 | void Caches::dumpMemoryUsage() { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 118 | String8 stringLog; |
| 119 | dumpMemoryUsage(stringLog); |
| 120 | LOGD("%s", stringLog.string()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void Caches::dumpMemoryUsage(String8 &log) { |
| 124 | log.appendFormat("Current memory usage / total memory usage (bytes):\n"); |
| 125 | log.appendFormat(" TextureCache %8d / %8d\n", |
| 126 | textureCache.getSize(), textureCache.getMaxSize()); |
| 127 | log.appendFormat(" LayerCache %8d / %8d\n", |
| 128 | layerCache.getSize(), layerCache.getMaxSize()); |
| 129 | log.appendFormat(" GradientCache %8d / %8d\n", |
| 130 | gradientCache.getSize(), gradientCache.getMaxSize()); |
| 131 | log.appendFormat(" PathCache %8d / %8d\n", |
| 132 | pathCache.getSize(), pathCache.getMaxSize()); |
| 133 | log.appendFormat(" CircleShapeCache %8d / %8d\n", |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 134 | circleShapeCache.getSize(), circleShapeCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 135 | log.appendFormat(" OvalShapeCache %8d / %8d\n", |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 136 | ovalShapeCache.getSize(), ovalShapeCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 137 | log.appendFormat(" RoundRectShapeCache %8d / %8d\n", |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 138 | roundRectShapeCache.getSize(), roundRectShapeCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 139 | log.appendFormat(" RectShapeCache %8d / %8d\n", |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 140 | rectShapeCache.getSize(), rectShapeCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 141 | log.appendFormat(" ArcShapeCache %8d / %8d\n", |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 142 | arcShapeCache.getSize(), arcShapeCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 143 | log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(), |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 144 | dropShadowCache.getMaxSize()); |
| 145 | for (uint32_t i = 0; i < fontRenderer.getFontRendererCount(); i++) { |
| 146 | const uint32_t size = fontRenderer.getFontRendererSize(i); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 147 | log.appendFormat(" FontRenderer %d %8d / %8d\n", i, size, size); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 148 | } |
Romain Guy | d2ba50a | 2011-05-27 10:21:07 -0700 | [diff] [blame] | 149 | log.appendFormat("Other:\n"); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 150 | log.appendFormat(" FboCache %8d / %8d\n", |
| 151 | fboCache.getSize(), fboCache.getMaxSize()); |
| 152 | log.appendFormat(" PatchCache %8d / %8d\n", |
| 153 | patchCache.getSize(), patchCache.getMaxSize()); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 154 | |
| 155 | uint32_t total = 0; |
| 156 | total += textureCache.getSize(); |
| 157 | total += layerCache.getSize(); |
| 158 | total += gradientCache.getSize(); |
| 159 | total += pathCache.getSize(); |
| 160 | total += dropShadowCache.getSize(); |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 161 | total += roundRectShapeCache.getSize(); |
| 162 | total += circleShapeCache.getSize(); |
| 163 | total += ovalShapeCache.getSize(); |
| 164 | total += rectShapeCache.getSize(); |
| 165 | total += arcShapeCache.getSize(); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 166 | for (uint32_t i = 0; i < fontRenderer.getFontRendererCount(); i++) { |
| 167 | total += fontRenderer.getFontRendererSize(i); |
| 168 | } |
| 169 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 170 | log.appendFormat("Total memory usage:\n"); |
| 171 | log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 175 | // Memory management |
| 176 | /////////////////////////////////////////////////////////////////////////////// |
| 177 | |
| 178 | void Caches::clearGarbage() { |
| 179 | textureCache.clearGarbage(); |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 180 | pathCache.clearGarbage(); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 181 | |
| 182 | Mutex::Autolock _l(mGarbageLock); |
| 183 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 184 | size_t count = mLayerGarbage.size(); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 185 | for (size_t i = 0; i < count; i++) { |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 186 | Layer* layer = mLayerGarbage.itemAt(i); |
Romain Guy | 09b7c91 | 2011-02-02 20:28:09 -0800 | [diff] [blame] | 187 | LayerRenderer::destroyLayer(layer); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 188 | } |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 189 | mLayerGarbage.clear(); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 192 | void Caches::deleteLayerDeferred(Layer* layer) { |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 193 | Mutex::Autolock _l(mGarbageLock); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 194 | mLayerGarbage.push(layer); |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 197 | void Caches::flush(FlushMode mode) { |
| 198 | FLUSH_LOGD("Flushing caches (mode %d)", mode); |
| 199 | |
| 200 | clearGarbage(); |
| 201 | |
| 202 | switch (mode) { |
| 203 | case kFlushMode_Full: |
| 204 | textureCache.clear(); |
| 205 | patchCache.clear(); |
| 206 | dropShadowCache.clear(); |
| 207 | gradientCache.clear(); |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 208 | fontRenderer.clear(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 209 | // fall through |
| 210 | case kFlushMode_Moderate: |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 211 | fontRenderer.flush(); |
| 212 | textureCache.flush(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 213 | pathCache.clear(); |
| 214 | roundRectShapeCache.clear(); |
| 215 | circleShapeCache.clear(); |
| 216 | ovalShapeCache.clear(); |
| 217 | rectShapeCache.clear(); |
| 218 | arcShapeCache.clear(); |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 219 | // fall through |
| 220 | case kFlushMode_Layers: |
| 221 | layerCache.clear(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 226 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 227 | // VBO |
| 228 | /////////////////////////////////////////////////////////////////////////////// |
| 229 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 230 | bool Caches::bindMeshBuffer() { |
| 231 | return bindMeshBuffer(meshBuffer); |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 234 | bool Caches::bindMeshBuffer(const GLuint buffer) { |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 235 | if (mCurrentBuffer != buffer) { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 236 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 237 | mCurrentBuffer = buffer; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 238 | return true; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 239 | } |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 240 | return false; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 243 | bool Caches::unbindMeshBuffer() { |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 244 | if (mCurrentBuffer) { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 245 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 246 | mCurrentBuffer = 0; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 247 | return true; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 248 | } |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 249 | return false; |
| 250 | } |
| 251 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 252 | bool Caches::bindIndicesBuffer(const GLuint buffer) { |
| 253 | if (mCurrentIndicesBuffer != buffer) { |
| 254 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); |
| 255 | mCurrentIndicesBuffer = buffer; |
| 256 | return true; |
| 257 | } |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | bool Caches::unbindIndicesBuffer() { |
| 262 | if (mCurrentIndicesBuffer) { |
| 263 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 264 | mCurrentIndicesBuffer = 0; |
| 265 | return true; |
| 266 | } |
| 267 | return false; |
| 268 | } |
| 269 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 270 | void Caches::bindPositionVertexPointer(bool force, GLuint slot, GLvoid* vertices, GLsizei stride) { |
| 271 | if (force || vertices != mCurrentPositionPointer) { |
| 272 | glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices); |
| 273 | mCurrentPositionPointer = vertices; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void Caches::bindTexCoordsVertexPointer(bool force, GLuint slot, GLvoid* vertices) { |
| 278 | if (force || vertices != mCurrentTexCoordsPointer) { |
| 279 | glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, gMeshStride, vertices); |
| 280 | mCurrentTexCoordsPointer = vertices; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | void Caches::resetVertexPointers() { |
| 285 | mCurrentPositionPointer = this; |
| 286 | mCurrentTexCoordsPointer = this; |
| 287 | } |
| 288 | |
| 289 | void Caches::resetTexCoordsVertexPointer() { |
| 290 | mCurrentTexCoordsPointer = this; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 293 | void Caches::enableTexCoordsVertexArray() { |
| 294 | if (!mTexCoordsArrayEnabled) { |
| 295 | glEnableVertexAttribArray(Program::kBindingTexCoords); |
| 296 | mTexCoordsArrayEnabled = true; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void Caches::disbaleTexCoordsVertexArray() { |
| 301 | if (mTexCoordsArrayEnabled) { |
| 302 | glDisableVertexAttribArray(Program::kBindingTexCoords); |
| 303 | mTexCoordsArrayEnabled = false; |
| 304 | } |
| 305 | } |
| 306 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame^] | 307 | void Caches::activeTexture(GLuint textureUnit) { |
| 308 | if (mTextureUnit != textureUnit) { |
| 309 | glActiveTexture(gTextureUnits[textureUnit]); |
| 310 | mTextureUnit = textureUnit; |
| 311 | } |
| 312 | } |
| 313 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 314 | TextureVertex* Caches::getRegionMesh() { |
| 315 | // Create the mesh, 2 triangles and 4 vertices per rectangle in the region |
| 316 | if (!mRegionMesh) { |
| 317 | mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4]; |
| 318 | |
| 319 | uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6]; |
| 320 | for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) { |
| 321 | uint16_t quad = i * 4; |
| 322 | int index = i * 6; |
| 323 | regionIndices[index ] = quad; // top-left |
| 324 | regionIndices[index + 1] = quad + 1; // top-right |
| 325 | regionIndices[index + 2] = quad + 2; // bottom-left |
| 326 | regionIndices[index + 3] = quad + 2; // bottom-left |
| 327 | regionIndices[index + 4] = quad + 1; // top-right |
| 328 | regionIndices[index + 5] = quad + 3; // bottom-right |
| 329 | } |
| 330 | |
| 331 | glGenBuffers(1, &mRegionMeshIndices); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 332 | bindIndicesBuffer(mRegionMeshIndices); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 333 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t), |
| 334 | regionIndices, GL_STATIC_DRAW); |
| 335 | |
| 336 | delete[] regionIndices; |
| 337 | } else { |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 338 | bindIndicesBuffer(mRegionMeshIndices); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | return mRegionMesh; |
| 342 | } |
| 343 | |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 344 | }; // namespace uirenderer |
| 345 | }; // namespace android |