blob: 1de0f9daaffe89322f981018ccd6f8e4af26c30b [file] [log] [blame]
Chet Haasedd78cca2010-10-22 18:59:26 -07001/*
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 Guyc15008e2010-11-10 11:59:15 -080019#include <utils/Log.h>
Chet Haase9c1e23b2011-03-24 10:51:31 -070020#include <utils/String8.h>
Romain Guyc15008e2010-11-10 11:59:15 -080021
Chet Haasedd78cca2010-10-22 18:59:26 -070022#include "Caches.h"
Romain Guybb0acdf2012-03-05 13:44:35 -080023#include "DisplayListRenderer.h"
Romain Guye190aa62010-11-10 19:01:29 -080024#include "Properties.h"
Romain Guy09b7c912011-02-02 20:28:09 -080025#include "LayerRenderer.h"
Chet Haasedd78cca2010-10-22 18:59:26 -070026
27namespace android {
28
29#ifdef USE_OPENGL_RENDERER
30using namespace uirenderer;
31ANDROID_SINGLETON_STATIC_INSTANCE(Caches);
32#endif
33
34namespace uirenderer {
35
36///////////////////////////////////////////////////////////////////////////////
Romain Guybdf76092011-07-18 15:00:43 -070037// Macros
38///////////////////////////////////////////////////////////////////////////////
39
40#if DEBUG_CACHE_FLUSH
Steve Block5baa3a62011-12-20 16:23:08 +000041 #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guybdf76092011-07-18 15:00:43 -070042#else
43 #define FLUSH_LOGD(...)
44#endif
45
46///////////////////////////////////////////////////////////////////////////////
Chet Haasedd78cca2010-10-22 18:59:26 -070047// Constructors/destructor
48///////////////////////////////////////////////////////////////////////////////
49
Romain Guy8ff6b9e2011-11-09 20:10:18 -080050Caches::Caches(): Singleton<Caches>(), mInitialized(false) {
Romain Guy8ff6b9e2011-11-09 20:10:18 -080051 init();
Romain Guyb1d0a4e2012-07-13 18:25:35 -070052 initFont();
Romain Guydfa10462012-05-12 16:18:58 -070053 initExtensions();
54 initConstraints();
Romain Guy4ff0cf42012-08-06 14:51:10 -070055 initProperties();
Romain Guye190aa62010-11-10 19:01:29 -080056
57 mDebugLevel = readDebugLevel();
Steve Block5baa3a62011-12-20 16:23:08 +000058 ALOGD("Enabling debug mode %d", mDebugLevel);
Chet Haasedd78cca2010-10-22 18:59:26 -070059}
60
Romain Guy8ff6b9e2011-11-09 20:10:18 -080061void Caches::init() {
62 if (mInitialized) return;
63
64 glGenBuffers(1, &meshBuffer);
65 glBindBuffer(GL_ARRAY_BUFFER, meshBuffer);
66 glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);
67
68 mCurrentBuffer = meshBuffer;
Romain Guy15bc6432011-12-13 13:11:32 -080069 mCurrentIndicesBuffer = 0;
Romain Guyf3a910b42011-12-12 20:35:21 -080070 mCurrentPositionPointer = this;
71 mCurrentTexCoordsPointer = this;
72
Romain Guy15bc6432011-12-13 13:11:32 -080073 mTexCoordsArrayEnabled = false;
74
Romain Guyb1d0a4e2012-07-13 18:25:35 -070075 glDisable(GL_SCISSOR_TEST);
Romain Guy586cae32012-07-13 15:28:31 -070076 scissorEnabled = false;
Romain Guy8f85e802011-12-14 19:23:32 -080077 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
78
Romain Guya1d3c912011-12-13 14:55:06 -080079 glActiveTexture(gTextureUnits[0]);
80 mTextureUnit = 0;
81
Romain Guy8ff6b9e2011-11-09 20:10:18 -080082 mRegionMesh = NULL;
83
84 blend = false;
85 lastSrcMode = GL_ZERO;
86 lastDstMode = GL_ZERO;
87 currentProgram = NULL;
88
89 mInitialized = true;
90}
91
Romain Guyb1d0a4e2012-07-13 18:25:35 -070092void Caches::initFont() {
93 fontRenderer = GammaFontRenderer::createRenderer();
94}
95
Romain Guydfa10462012-05-12 16:18:58 -070096void Caches::initExtensions() {
97 if (extensions.hasDebugMarker()) {
98 eventMark = glInsertEventMarkerEXT;
99 startMark = glPushGroupMarkerEXT;
100 endMark = glPopGroupMarkerEXT;
101 } else {
102 eventMark = eventMarkNull;
103 startMark = startMarkNull;
104 endMark = endMarkNull;
105 }
106
107 if (extensions.hasDebugLabel()) {
108 setLabel = glLabelObjectEXT;
109 getLabel = glGetObjectLabelEXT;
110 } else {
111 setLabel = setLabelNull;
112 getLabel = getLabelNull;
113 }
114}
115
116void Caches::initConstraints() {
117 GLint maxTextureUnits;
118 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
119 if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
120 ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
121 }
122
123 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
124}
125
Romain Guy4ff0cf42012-08-06 14:51:10 -0700126void Caches::initProperties() {
127 char property[PROPERTY_VALUE_MAX];
128 if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, NULL) > 0) {
129 INIT_LOGD(" Layers updates debug enabled: %s", property);
130 debugLayersUpdates = !strcmp(property, "true");
131 } else {
132 debugLayersUpdates = false;
133 }
134}
135
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800136void Caches::terminate() {
137 if (!mInitialized) return;
138
139 glDeleteBuffers(1, &meshBuffer);
140 mCurrentBuffer = 0;
141
142 glDeleteBuffers(1, &mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700143 delete[] mRegionMesh;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800144 mRegionMesh = NULL;
145
146 fboCache.clear();
147
148 programCache.clear();
149 currentProgram = NULL;
150
151 mInitialized = false;
Romain Guy5b3b3522010-10-27 18:57:51 -0700152}
153
154///////////////////////////////////////////////////////////////////////////////
Romain Guyc15008e2010-11-10 11:59:15 -0800155// Debug
156///////////////////////////////////////////////////////////////////////////////
157
158void Caches::dumpMemoryUsage() {
Chet Haase9c1e23b2011-03-24 10:51:31 -0700159 String8 stringLog;
160 dumpMemoryUsage(stringLog);
Steve Block5baa3a62011-12-20 16:23:08 +0000161 ALOGD("%s", stringLog.string());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700162}
163
164void Caches::dumpMemoryUsage(String8 &log) {
165 log.appendFormat("Current memory usage / total memory usage (bytes):\n");
166 log.appendFormat(" TextureCache %8d / %8d\n",
167 textureCache.getSize(), textureCache.getMaxSize());
168 log.appendFormat(" LayerCache %8d / %8d\n",
169 layerCache.getSize(), layerCache.getMaxSize());
170 log.appendFormat(" GradientCache %8d / %8d\n",
171 gradientCache.getSize(), gradientCache.getMaxSize());
172 log.appendFormat(" PathCache %8d / %8d\n",
173 pathCache.getSize(), pathCache.getMaxSize());
174 log.appendFormat(" CircleShapeCache %8d / %8d\n",
Romain Guy01d58e42011-01-19 21:54:02 -0800175 circleShapeCache.getSize(), circleShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700176 log.appendFormat(" OvalShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800177 ovalShapeCache.getSize(), ovalShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700178 log.appendFormat(" RoundRectShapeCache %8d / %8d\n",
Romain Guy01d58e42011-01-19 21:54:02 -0800179 roundRectShapeCache.getSize(), roundRectShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700180 log.appendFormat(" RectShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800181 rectShapeCache.getSize(), rectShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700182 log.appendFormat(" ArcShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800183 arcShapeCache.getSize(), arcShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700184 log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(),
Romain Guyc15008e2010-11-10 11:59:15 -0800185 dropShadowCache.getMaxSize());
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700186 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
187 const uint32_t size = fontRenderer->getFontRendererSize(i);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700188 log.appendFormat(" FontRenderer %d %8d / %8d\n", i, size, size);
Romain Guyc15008e2010-11-10 11:59:15 -0800189 }
Romain Guyd2ba50a2011-05-27 10:21:07 -0700190 log.appendFormat("Other:\n");
Chet Haase9c1e23b2011-03-24 10:51:31 -0700191 log.appendFormat(" FboCache %8d / %8d\n",
192 fboCache.getSize(), fboCache.getMaxSize());
193 log.appendFormat(" PatchCache %8d / %8d\n",
194 patchCache.getSize(), patchCache.getMaxSize());
Romain Guyc15008e2010-11-10 11:59:15 -0800195
196 uint32_t total = 0;
197 total += textureCache.getSize();
198 total += layerCache.getSize();
199 total += gradientCache.getSize();
200 total += pathCache.getSize();
201 total += dropShadowCache.getSize();
Romain Guy2fc941e2011-02-03 15:06:05 -0800202 total += roundRectShapeCache.getSize();
203 total += circleShapeCache.getSize();
204 total += ovalShapeCache.getSize();
205 total += rectShapeCache.getSize();
206 total += arcShapeCache.getSize();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700207 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
208 total += fontRenderer->getFontRendererSize(i);
Romain Guyc15008e2010-11-10 11:59:15 -0800209 }
210
Chet Haase9c1e23b2011-03-24 10:51:31 -0700211 log.appendFormat("Total memory usage:\n");
212 log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
Romain Guyc15008e2010-11-10 11:59:15 -0800213}
214
215///////////////////////////////////////////////////////////////////////////////
Romain Guyfe48f652010-11-11 15:36:56 -0800216// Memory management
217///////////////////////////////////////////////////////////////////////////////
218
219void Caches::clearGarbage() {
220 textureCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800221 pathCache.clearGarbage();
Romain Guy57066eb2011-01-12 12:53:32 -0800222
223 Mutex::Autolock _l(mGarbageLock);
224
Romain Guyada830f2011-01-13 12:13:20 -0800225 size_t count = mLayerGarbage.size();
Romain Guy57066eb2011-01-12 12:53:32 -0800226 for (size_t i = 0; i < count; i++) {
Romain Guyada830f2011-01-13 12:13:20 -0800227 Layer* layer = mLayerGarbage.itemAt(i);
Romain Guy09b7c912011-02-02 20:28:09 -0800228 LayerRenderer::destroyLayer(layer);
Romain Guy57066eb2011-01-12 12:53:32 -0800229 }
Romain Guyada830f2011-01-13 12:13:20 -0800230 mLayerGarbage.clear();
Romain Guybb0acdf2012-03-05 13:44:35 -0800231
232 count = mDisplayListGarbage.size();
233 for (size_t i = 0; i < count; i++) {
234 DisplayList* displayList = mDisplayListGarbage.itemAt(i);
235 delete displayList;
236 }
237 mDisplayListGarbage.clear();
Romain Guy57066eb2011-01-12 12:53:32 -0800238}
239
Romain Guyada830f2011-01-13 12:13:20 -0800240void Caches::deleteLayerDeferred(Layer* layer) {
Romain Guy57066eb2011-01-12 12:53:32 -0800241 Mutex::Autolock _l(mGarbageLock);
Romain Guyada830f2011-01-13 12:13:20 -0800242 mLayerGarbage.push(layer);
Romain Guyfe48f652010-11-11 15:36:56 -0800243}
244
Romain Guybb0acdf2012-03-05 13:44:35 -0800245void Caches::deleteDisplayListDeferred(DisplayList* displayList) {
246 Mutex::Autolock _l(mGarbageLock);
247 mDisplayListGarbage.push(displayList);
248}
249
Romain Guybdf76092011-07-18 15:00:43 -0700250void Caches::flush(FlushMode mode) {
251 FLUSH_LOGD("Flushing caches (mode %d)", mode);
252
253 clearGarbage();
254
255 switch (mode) {
256 case kFlushMode_Full:
257 textureCache.clear();
258 patchCache.clear();
259 dropShadowCache.clear();
260 gradientCache.clear();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700261 fontRenderer->clear();
Romain Guy211efea2012-07-31 21:16:07 -0700262 dither.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700263 // fall through
264 case kFlushMode_Moderate:
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700265 fontRenderer->flush();
Romain Guyeca0ca22011-11-04 15:12:29 -0700266 textureCache.flush();
Romain Guybdf76092011-07-18 15:00:43 -0700267 pathCache.clear();
268 roundRectShapeCache.clear();
269 circleShapeCache.clear();
270 ovalShapeCache.clear();
271 rectShapeCache.clear();
272 arcShapeCache.clear();
Romain Guy6d7475d2011-07-27 16:28:21 -0700273 // fall through
274 case kFlushMode_Layers:
275 layerCache.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700276 break;
277 }
278}
279
Romain Guyfe48f652010-11-11 15:36:56 -0800280///////////////////////////////////////////////////////////////////////////////
Romain Guy5b3b3522010-10-27 18:57:51 -0700281// VBO
282///////////////////////////////////////////////////////////////////////////////
283
Romain Guyf3a910b42011-12-12 20:35:21 -0800284bool Caches::bindMeshBuffer() {
285 return bindMeshBuffer(meshBuffer);
Chet Haasedd78cca2010-10-22 18:59:26 -0700286}
287
Romain Guyf3a910b42011-12-12 20:35:21 -0800288bool Caches::bindMeshBuffer(const GLuint buffer) {
Romain Guy9bca4792010-10-25 18:42:25 -0700289 if (mCurrentBuffer != buffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -0700290 glBindBuffer(GL_ARRAY_BUFFER, buffer);
Romain Guy9bca4792010-10-25 18:42:25 -0700291 mCurrentBuffer = buffer;
Romain Guyf3a910b42011-12-12 20:35:21 -0800292 return true;
Chet Haasedd78cca2010-10-22 18:59:26 -0700293 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800294 return false;
Chet Haasedd78cca2010-10-22 18:59:26 -0700295}
296
Romain Guyf3a910b42011-12-12 20:35:21 -0800297bool Caches::unbindMeshBuffer() {
Romain Guy9bca4792010-10-25 18:42:25 -0700298 if (mCurrentBuffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -0700299 glBindBuffer(GL_ARRAY_BUFFER, 0);
Romain Guy9bca4792010-10-25 18:42:25 -0700300 mCurrentBuffer = 0;
Romain Guyf3a910b42011-12-12 20:35:21 -0800301 return true;
Chet Haasedd78cca2010-10-22 18:59:26 -0700302 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800303 return false;
304}
305
Romain Guy15bc6432011-12-13 13:11:32 -0800306bool Caches::bindIndicesBuffer(const GLuint buffer) {
307 if (mCurrentIndicesBuffer != buffer) {
308 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
309 mCurrentIndicesBuffer = buffer;
310 return true;
311 }
312 return false;
313}
314
315bool Caches::unbindIndicesBuffer() {
316 if (mCurrentIndicesBuffer) {
317 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
318 mCurrentIndicesBuffer = 0;
319 return true;
320 }
321 return false;
322}
323
Romain Guy85ef80d2012-09-13 20:26:50 -0700324///////////////////////////////////////////////////////////////////////////////
325// Meshes and textures
326///////////////////////////////////////////////////////////////////////////////
327
Romain Guyf3a910b42011-12-12 20:35:21 -0800328void Caches::bindPositionVertexPointer(bool force, GLuint slot, GLvoid* vertices, GLsizei stride) {
329 if (force || vertices != mCurrentPositionPointer) {
330 glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
331 mCurrentPositionPointer = vertices;
332 }
333}
334
335void Caches::bindTexCoordsVertexPointer(bool force, GLuint slot, GLvoid* vertices) {
336 if (force || vertices != mCurrentTexCoordsPointer) {
337 glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, gMeshStride, vertices);
338 mCurrentTexCoordsPointer = vertices;
339 }
340}
341
342void Caches::resetVertexPointers() {
343 mCurrentPositionPointer = this;
344 mCurrentTexCoordsPointer = this;
345}
346
347void Caches::resetTexCoordsVertexPointer() {
348 mCurrentTexCoordsPointer = this;
Chet Haasedd78cca2010-10-22 18:59:26 -0700349}
350
Romain Guy15bc6432011-12-13 13:11:32 -0800351void Caches::enableTexCoordsVertexArray() {
352 if (!mTexCoordsArrayEnabled) {
353 glEnableVertexAttribArray(Program::kBindingTexCoords);
Romain Guyec31f832011-12-13 18:39:19 -0800354 mCurrentTexCoordsPointer = this;
Romain Guy15bc6432011-12-13 13:11:32 -0800355 mTexCoordsArrayEnabled = true;
356 }
357}
358
359void Caches::disbaleTexCoordsVertexArray() {
360 if (mTexCoordsArrayEnabled) {
361 glDisableVertexAttribArray(Program::kBindingTexCoords);
362 mTexCoordsArrayEnabled = false;
363 }
364}
365
Romain Guya1d3c912011-12-13 14:55:06 -0800366void Caches::activeTexture(GLuint textureUnit) {
367 if (mTextureUnit != textureUnit) {
368 glActiveTexture(gTextureUnits[textureUnit]);
369 mTextureUnit = textureUnit;
370 }
371}
372
Romain Guy85ef80d2012-09-13 20:26:50 -0700373///////////////////////////////////////////////////////////////////////////////
374// Scissor
375///////////////////////////////////////////////////////////////////////////////
376
Romain Guy8a4ac612012-07-17 17:32:48 -0700377bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
Romain Guy586cae32012-07-13 15:28:31 -0700378 if (scissorEnabled && (x != mScissorX || y != mScissorY ||
379 width != mScissorWidth || height != mScissorHeight)) {
380
Romain Guy8f85e802011-12-14 19:23:32 -0800381 glScissor(x, y, width, height);
382
383 mScissorX = x;
384 mScissorY = y;
385 mScissorWidth = width;
386 mScissorHeight = height;
Romain Guy8a4ac612012-07-17 17:32:48 -0700387
388 return true;
Romain Guy8f85e802011-12-14 19:23:32 -0800389 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700390 return false;
Romain Guy8f85e802011-12-14 19:23:32 -0800391}
392
Romain Guy8a4ac612012-07-17 17:32:48 -0700393bool Caches::enableScissor() {
Romain Guy586cae32012-07-13 15:28:31 -0700394 if (!scissorEnabled) {
395 glEnable(GL_SCISSOR_TEST);
396 scissorEnabled = true;
Romain Guy8a4ac612012-07-17 17:32:48 -0700397 return true;
Romain Guy586cae32012-07-13 15:28:31 -0700398 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700399 return false;
Romain Guy586cae32012-07-13 15:28:31 -0700400}
401
Romain Guy8a4ac612012-07-17 17:32:48 -0700402bool Caches::disableScissor() {
Romain Guy586cae32012-07-13 15:28:31 -0700403 if (scissorEnabled) {
404 glDisable(GL_SCISSOR_TEST);
405 scissorEnabled = false;
Romain Guy8a4ac612012-07-17 17:32:48 -0700406 return true;
Romain Guy586cae32012-07-13 15:28:31 -0700407 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700408 return false;
Romain Guy586cae32012-07-13 15:28:31 -0700409}
410
411void Caches::setScissorEnabled(bool enabled) {
412 if (scissorEnabled != enabled) {
413 if (enabled) glEnable(GL_SCISSOR_TEST);
414 else glDisable(GL_SCISSOR_TEST);
415 scissorEnabled = enabled;
416 }
417}
418
Romain Guy82bc7a72012-01-03 14:13:39 -0800419void Caches::resetScissor() {
420 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
421}
422
Romain Guy85ef80d2012-09-13 20:26:50 -0700423///////////////////////////////////////////////////////////////////////////////
424// Tiling
425///////////////////////////////////////////////////////////////////////////////
426
427void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool opaque) {
428 if (extensions.hasTiledRendering()) {
429
430 }
431}
432
433void Caches::endTiling() {
434 if (extensions.hasTiledRendering()) {
435
436 }
437}
438
439///////////////////////////////////////////////////////////////////////////////
440// Regions
441///////////////////////////////////////////////////////////////////////////////
442
Romain Guy5b3b3522010-10-27 18:57:51 -0700443TextureVertex* Caches::getRegionMesh() {
444 // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
445 if (!mRegionMesh) {
446 mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4];
447
448 uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6];
449 for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) {
450 uint16_t quad = i * 4;
451 int index = i * 6;
452 regionIndices[index ] = quad; // top-left
453 regionIndices[index + 1] = quad + 1; // top-right
454 regionIndices[index + 2] = quad + 2; // bottom-left
455 regionIndices[index + 3] = quad + 2; // bottom-left
456 regionIndices[index + 4] = quad + 1; // top-right
457 regionIndices[index + 5] = quad + 3; // bottom-right
458 }
459
460 glGenBuffers(1, &mRegionMeshIndices);
Romain Guy15bc6432011-12-13 13:11:32 -0800461 bindIndicesBuffer(mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700462 glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
463 regionIndices, GL_STATIC_DRAW);
464
465 delete[] regionIndices;
466 } else {
Romain Guy15bc6432011-12-13 13:11:32 -0800467 bindIndicesBuffer(mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700468 }
469
470 return mRegionMesh;
471}
472
Chet Haasedd78cca2010-10-22 18:59:26 -0700473}; // namespace uirenderer
474}; // namespace android