blob: 4a1e8fcfedf287d73dafd7b36e997f84f6301fd8 [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
2 * Copyright (C) 2014 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 */
John Reck38e0c322015-11-10 12:19:17 -080016#include <GpuMemoryTracker.h>
Chris Craik96a5c4c2015-01-27 15:46:35 -080017#include "renderstate/RenderState.h"
John Reck3b202512014-06-23 13:13:08 -070018
John Reck443a7142014-09-04 17:40:05 -070019#include "renderthread/CanvasContext.h"
John Reck0e89e2b2014-10-31 14:49:06 -070020#include "renderthread/EglManager.h"
Chris Craik117bdbc2015-02-05 10:12:38 -080021#include "utils/GLUtils.h"
Chris Craik9db58c02015-08-19 15:19:18 -070022#include <algorithm>
23
John Reck3b202512014-06-23 13:13:08 -070024namespace android {
25namespace uirenderer {
26
John Reck0e89e2b2014-10-31 14:49:06 -070027RenderState::RenderState(renderthread::RenderThread& thread)
28 : mRenderThread(thread)
John Reck3b202512014-06-23 13:13:08 -070029 , mViewportWidth(0)
30 , mViewportHeight(0)
31 , mFramebuffer(0) {
John Reck0e89e2b2014-10-31 14:49:06 -070032 mThreadId = pthread_self();
John Reck3b202512014-06-23 13:13:08 -070033}
34
35RenderState::~RenderState() {
Chris Craik44eb2c02015-01-29 09:45:09 -080036 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080037 "State object lifecycle not managed correctly");
John Reck3b202512014-06-23 13:13:08 -070038}
39
40void RenderState::onGLContextCreated() {
Chris Craik44eb2c02015-01-29 09:45:09 -080041 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080042 "State object lifecycle not managed correctly");
John Reck38e0c322015-11-10 12:19:17 -080043 GpuMemoryTracker::onGLContextCreated();
44
Chris Craik44eb2c02015-01-29 09:45:09 -080045 mBlend = new Blend();
Chris Craik96a5c4c2015-01-27 15:46:35 -080046 mMeshState = new MeshState();
47 mScissor = new Scissor();
48 mStencil = new Stencil();
Chris Craik65fe5ee2015-01-26 18:06:29 -080049
Chris Craik96a5c4c2015-01-27 15:46:35 -080050 // This is delayed because the first access of Caches makes GL calls
Chris Craikff5c8e82015-01-30 09:46:18 -080051 if (!mCaches) {
52 mCaches = &Caches::createInstance(*this);
53 }
Chris Craik96a5c4c2015-01-27 15:46:35 -080054 mCaches->init();
55 mCaches->textureCache.setAssetAtlas(&mAssetAtlas);
John Reck3b202512014-06-23 13:13:08 -070056}
57
John Reck49bc4ac2015-01-29 12:53:38 -080058static void layerLostGlContext(Layer* layer) {
59 layer->onGlContextLost();
60}
61
Chris Craik1d477422014-08-26 17:30:15 -070062void RenderState::onGLContextDestroyed() {
Chris Craik21029ef2014-09-12 09:29:10 -070063/*
Chris Craikbfd1cd62014-09-10 13:04:31 -070064 size_t size = mActiveLayers.size();
65 if (CC_UNLIKELY(size != 0)) {
66 ALOGE("Crashing, have %d contexts and %d layers at context destruction. isempty %d",
67 mRegisteredContexts.size(), size, mActiveLayers.empty());
John Reck17035b02014-09-03 07:39:53 -070068 mCaches->dumpMemoryUsage();
John Reck443a7142014-09-04 17:40:05 -070069 for (std::set<renderthread::CanvasContext*>::iterator cit = mRegisteredContexts.begin();
70 cit != mRegisteredContexts.end(); cit++) {
71 renderthread::CanvasContext* context = *cit;
Chris Craikbfd1cd62014-09-10 13:04:31 -070072 ALOGE("Context: %p (root = %p)", context, context->mRootRenderNode.get());
73 ALOGE(" Prefeteched layers: %zu", context->mPrefetechedLayers.size());
John Reck443a7142014-09-04 17:40:05 -070074 for (std::set<RenderNode*>::iterator pit = context->mPrefetechedLayers.begin();
75 pit != context->mPrefetechedLayers.end(); pit++) {
76 (*pit)->debugDumpLayers(" ");
77 }
78 context->mRootRenderNode->debugDumpLayers(" ");
79 }
Chris Craik599e2542014-09-05 15:17:11 -070080
Chris Craikbfd1cd62014-09-10 13:04:31 -070081
82 if (mActiveLayers.begin() == mActiveLayers.end()) {
83 ALOGE("set has become empty. wat.");
84 }
Chris Craik599e2542014-09-05 15:17:11 -070085 for (std::set<const Layer*>::iterator lit = mActiveLayers.begin();
86 lit != mActiveLayers.end(); lit++) {
87 const Layer* layer = *(lit);
Chris Craikbfd1cd62014-09-10 13:04:31 -070088 ALOGE("Layer %p, state %d, texlayer %d, fbo %d, buildlayered %d",
89 layer, layer->state, layer->isTextureLayer(), layer->getFbo(), layer->wasBuildLayered);
Chris Craik599e2542014-09-05 15:17:11 -070090 }
Chris Craikbfd1cd62014-09-10 13:04:31 -070091 LOG_ALWAYS_FATAL("%d layers have survived gl context destruction", size);
John Reck17035b02014-09-03 07:39:53 -070092 }
Chris Craik21029ef2014-09-12 09:29:10 -070093*/
John Reck49bc4ac2015-01-29 12:53:38 -080094
Chris Craik9fded232015-11-11 16:42:34 -080095 mLayerPool.clear();
96
Chris Craik96a5c4c2015-01-27 15:46:35 -080097 // TODO: reset all cached state in state objects
John Reck49bc4ac2015-01-29 12:53:38 -080098 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
John Reckebd52612014-12-10 16:47:36 -080099 mAssetAtlas.terminate();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800100
Chris Craik44eb2c02015-01-29 09:45:09 -0800101 mCaches->terminate();
102
103 delete mBlend;
104 mBlend = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800105 delete mMeshState;
106 mMeshState = nullptr;
107 delete mScissor;
108 mScissor = nullptr;
109 delete mStencil;
110 mStencil = nullptr;
John Reck38e0c322015-11-10 12:19:17 -0800111
112 GpuMemoryTracker::onGLContextDestroyed();
Chris Craik1d477422014-08-26 17:30:15 -0700113}
114
Chris Craik9fded232015-11-11 16:42:34 -0800115void RenderState::flush(Caches::FlushMode mode) {
116 switch (mode) {
117 case Caches::FlushMode::Full:
118 // fall through
119 case Caches::FlushMode::Moderate:
120 // fall through
121 case Caches::FlushMode::Layers:
122 mLayerPool.clear();
123 break;
124 }
125 mCaches->flush(mode);
126}
127
John Reck3b202512014-06-23 13:13:08 -0700128void RenderState::setViewport(GLsizei width, GLsizei height) {
129 mViewportWidth = width;
130 mViewportHeight = height;
131 glViewport(0, 0, mViewportWidth, mViewportHeight);
132}
133
134
135void RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
136 *outWidth = mViewportWidth;
137 *outHeight = mViewportHeight;
138}
139
140void RenderState::bindFramebuffer(GLuint fbo) {
141 if (mFramebuffer != fbo) {
142 mFramebuffer = fbo;
143 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
144 }
145}
146
Chris Craik818c9fb2015-10-23 14:33:42 -0700147GLuint RenderState::genFramebuffer() {
148 GLuint ret;
149 glGenFramebuffers(1, &ret);
150 return ret;
151}
152
153void RenderState::deleteFramebuffer(GLuint fbo) {
154 if (mFramebuffer == fbo) {
155 // GL defines that deleting the currently bound FBO rebinds FBO 0.
156 // Reflect this in our cached value.
157 mFramebuffer = 0;
158 }
159 glDeleteFramebuffers(1, &fbo);
160}
161
John Reck3b202512014-06-23 13:13:08 -0700162void RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
John Reck95cd24b2015-08-04 11:17:39 -0700163 if (mode == DrawGlInfo::kModeProcessNoContext) {
164 // If there's no context we don't need to interrupt as there's
165 // no gl state to save/restore
166 (*functor)(mode, info);
167 } else {
168 interruptForFunctorInvoke();
169 (*functor)(mode, info);
170 resumeFromFunctorInvoke();
171 }
John Reck3b202512014-06-23 13:13:08 -0700172}
173
174void RenderState::interruptForFunctorInvoke() {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800175 mCaches->setProgram(nullptr);
Chris Craik44eb2c02015-01-29 09:45:09 -0800176 mCaches->textureState().resetActiveTexture();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800177 meshState().unbindMeshBuffer();
178 meshState().unbindIndicesBuffer();
179 meshState().resetVertexPointers();
180 meshState().disableTexCoordsVertexArray();
John Reck3b202512014-06-23 13:13:08 -0700181 debugOverdraw(false, false);
182}
183
184void RenderState::resumeFromFunctorInvoke() {
185 glViewport(0, 0, mViewportWidth, mViewportHeight);
186 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
187 debugOverdraw(false, false);
188
189 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
190
Chris Craik65fe5ee2015-01-26 18:06:29 -0800191 scissor().invalidate();
Chris Craik44eb2c02015-01-29 09:45:09 -0800192 blend().invalidate();
John Reck3b202512014-06-23 13:13:08 -0700193
Chris Craik44eb2c02015-01-29 09:45:09 -0800194 mCaches->textureState().activateTexture(0);
195 mCaches->textureState().resetBoundTextures();
John Reck3b202512014-06-23 13:13:08 -0700196}
197
198void RenderState::debugOverdraw(bool enable, bool clear) {
Chris Craik2507c342015-05-04 14:36:49 -0700199 if (Properties::debugOverdraw && mFramebuffer == 0) {
John Reck3b202512014-06-23 13:13:08 -0700200 if (clear) {
Chris Craik65fe5ee2015-01-26 18:06:29 -0800201 scissor().setEnabled(false);
Chris Craik96a5c4c2015-01-27 15:46:35 -0800202 stencil().clear();
John Reck3b202512014-06-23 13:13:08 -0700203 }
204 if (enable) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800205 stencil().enableDebugWrite();
John Reck3b202512014-06-23 13:13:08 -0700206 } else {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800207 stencil().disable();
John Reck3b202512014-06-23 13:13:08 -0700208 }
209 }
210}
211
John Reck0e89e2b2014-10-31 14:49:06 -0700212void RenderState::requireGLContext() {
213 assertOnGLThread();
John Reckd7db4d72015-05-20 07:18:55 -0700214 LOG_ALWAYS_FATAL_IF(!mRenderThread.eglManager().hasEglContext(),
215 "No GL context!");
John Reck0e89e2b2014-10-31 14:49:06 -0700216}
217
218void RenderState::assertOnGLThread() {
219 pthread_t curr = pthread_self();
220 LOG_ALWAYS_FATAL_IF(!pthread_equal(mThreadId, curr), "Wrong thread!");
221}
222
John Reck0e89e2b2014-10-31 14:49:06 -0700223class DecStrongTask : public renderthread::RenderTask {
224public:
225 DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
226
Chris Craikd41c4d82015-01-05 15:51:13 -0800227 virtual void run() override {
228 mObject->decStrong(nullptr);
229 mObject = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700230 delete this;
231 }
232
233private:
234 VirtualLightRefBase* mObject;
235};
236
237void RenderState::postDecStrong(VirtualLightRefBase* object) {
238 mRenderThread.queue(new DecStrongTask(object));
239}
240
Chris Craik6c15ffa2015-02-02 13:50:55 -0800241///////////////////////////////////////////////////////////////////////////////
242// Render
243///////////////////////////////////////////////////////////////////////////////
244
Chris Craik12efe642015-09-28 15:52:12 -0700245void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800246 const Glop::Mesh& mesh = glop.mesh;
Chris Craikef250742015-02-25 17:16:16 -0800247 const Glop::Mesh::Vertices& vertices = mesh.vertices;
248 const Glop::Mesh::Indices& indices = mesh.indices;
Chris Craik0519c812015-02-11 13:17:06 -0800249 const Glop::Fill& fill = glop.fill;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800250
Chris Craik0519c812015-02-11 13:17:06 -0800251 // ---------------------------------------------
252 // ---------- Program + uniform setup ----------
253 // ---------------------------------------------
254 mCaches->setProgram(fill.program);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800255
Chris Craik0519c812015-02-11 13:17:06 -0800256 if (fill.colorEnabled) {
257 fill.program->setColor(fill.color);
258 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800259
Chris Craik12efe642015-09-28 15:52:12 -0700260 fill.program->set(orthoMatrix,
Chris Craik6c15ffa2015-02-02 13:50:55 -0800261 glop.transform.modelView,
Chris Craik53e51e42015-06-01 10:35:35 -0700262 glop.transform.meshTransform(),
263 glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800264
Chris Craik0519c812015-02-11 13:17:06 -0800265 // Color filter uniforms
Chris Craikb9ce116d2015-08-20 15:14:06 -0700266 if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
Chris Craikef250742015-02-25 17:16:16 -0800267 const FloatColor& color = fill.filter.color;
Chris Craik117bdbc2015-02-05 10:12:38 -0800268 glUniform4f(mCaches->program().getUniform("colorBlend"),
269 color.r, color.g, color.b, color.a);
Chris Craikb9ce116d2015-08-20 15:14:06 -0700270 } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
Chris Craik117bdbc2015-02-05 10:12:38 -0800271 glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
Chris Craikef250742015-02-25 17:16:16 -0800272 fill.filter.matrix.matrix);
Chris Craik117bdbc2015-02-05 10:12:38 -0800273 glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
Chris Craikef250742015-02-25 17:16:16 -0800274 fill.filter.matrix.vector);
Chris Craik117bdbc2015-02-05 10:12:38 -0800275 }
276
Chris Craik0519c812015-02-11 13:17:06 -0800277 // Round rect clipping uniforms
278 if (glop.roundRectClipState) {
279 // TODO: avoid query, and cache values (or RRCS ptr) in program
280 const RoundRectClipState* state = glop.roundRectClipState;
281 const Rect& innerRect = state->innerRect;
282 glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
283 innerRect.left, innerRect.top,
284 innerRect.right, innerRect.bottom);
285 glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
286 1, GL_FALSE, &state->matrix.data[0]);
287
288 // add half pixel to round out integer rect space to cover pixel centers
289 float roundedOutRadius = state->radius + 0.5f;
290 glUniform1f(fill.program->getUniform("roundRectRadius"),
291 roundedOutRadius);
292 }
Chris Craikef250742015-02-25 17:16:16 -0800293
Chris Craik117bdbc2015-02-05 10:12:38 -0800294 // --------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800295 // ---------- Mesh setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800296 // --------------------------------
297 // vertices
Chris Craikef250742015-02-25 17:16:16 -0800298 const bool force = meshState().bindMeshBufferInternal(vertices.bufferObject)
299 || (vertices.position != nullptr);
300 meshState().bindPositionVertexPointer(force, vertices.position, vertices.stride);
Chris Craik117bdbc2015-02-05 10:12:38 -0800301
302 // indices
Chris Craikef250742015-02-25 17:16:16 -0800303 meshState().bindIndicesBufferInternal(indices.bufferObject);
Chris Craik117bdbc2015-02-05 10:12:38 -0800304
Chris Craik53e51e42015-06-01 10:35:35 -0700305 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craik26bf3422015-02-26 16:28:17 -0800306 const Glop::Fill::TextureData& texture = fill.texture;
307 // texture always takes slot 0, shader samplers increment from there
Chris Craik0519c812015-02-11 13:17:06 -0800308 mCaches->textureState().activateTexture(0);
309
Chris Craik26bf3422015-02-26 16:28:17 -0800310 if (texture.clamp != GL_INVALID_ENUM) {
Chris Craik5f1356c2015-05-27 11:06:21 -0700311 texture.texture->setWrap(texture.clamp, true, false, texture.target);
Chris Craik30036092015-02-12 10:41:39 -0800312 }
Chris Craik26bf3422015-02-26 16:28:17 -0800313 if (texture.filter != GL_INVALID_ENUM) {
Chris Craik5f1356c2015-05-27 11:06:21 -0700314 texture.texture->setFilter(texture.filter, true, false, texture.target);
Chris Craik30036092015-02-12 10:41:39 -0800315 }
Chris Craik0519c812015-02-11 13:17:06 -0800316
John Reck38e0c322015-11-10 12:19:17 -0800317 mCaches->textureState().bindTexture(texture.target, texture.texture->id());
Chris Craik0519c812015-02-11 13:17:06 -0800318 meshState().enableTexCoordsVertexArray();
Chris Craikef250742015-02-25 17:16:16 -0800319 meshState().bindTexCoordsVertexPointer(force, vertices.texCoord, vertices.stride);
Chris Craik26bf3422015-02-26 16:28:17 -0800320
321 if (texture.textureTransform) {
322 glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
323 GL_FALSE, &texture.textureTransform->data[0]);
324 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800325 } else {
326 meshState().disableTexCoordsVertexArray();
327 }
Chris Craikef250742015-02-25 17:16:16 -0800328 int colorLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700329 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800330 colorLocation = fill.program->getAttrib("colors");
331 glEnableVertexAttribArray(colorLocation);
332 glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800333 }
Chris Craikef250742015-02-25 17:16:16 -0800334 int alphaLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700335 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800336 // NOTE: alpha vertex position is computed assuming no VBO
337 const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
338 alphaLocation = fill.program->getAttrib("vtxAlpha");
339 glEnableVertexAttribArray(alphaLocation);
340 glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800341 }
Chris Craik922d3a72015-02-13 17:47:21 -0800342 // Shader uniforms
Chris Craikef250742015-02-25 17:16:16 -0800343 SkiaShader::apply(*mCaches, fill.skiaShaderData);
Chris Craik922d3a72015-02-13 17:47:21 -0800344
Chris Craik117bdbc2015-02-05 10:12:38 -0800345 // ------------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800346 // ---------- GL state setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800347 // ------------------------------------
Chris Craik03188872015-02-02 18:39:33 -0800348 blend().setFactors(glop.blend.src, glop.blend.dst);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800349
Chris Craik117bdbc2015-02-05 10:12:38 -0800350 // ------------------------------------
Chris Craik2ab95d72015-02-06 15:25:51 -0800351 // ---------- Actual drawing ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800352 // ------------------------------------
Chris Craikef250742015-02-25 17:16:16 -0800353 if (indices.bufferObject == meshState().getQuadListIBO()) {
Chris Craik2ab95d72015-02-06 15:25:51 -0800354 // Since the indexed quad list is of limited length, we loop over
355 // the glDrawXXX method while updating the vertex pointer
Chris Craik0519c812015-02-11 13:17:06 -0800356 GLsizei elementsCount = mesh.elementCount;
Chris Craikef250742015-02-25 17:16:16 -0800357 const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
Chris Craik2ab95d72015-02-06 15:25:51 -0800358 while (elementsCount > 0) {
Chris Craik9db58c02015-08-19 15:19:18 -0700359 GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
Chris Craik2ab95d72015-02-06 15:25:51 -0800360
Chris Craikf27133d2015-02-19 09:51:53 -0800361 // rebind pointers without forcing, since initial bind handled above
Chris Craikef250742015-02-25 17:16:16 -0800362 meshState().bindPositionVertexPointer(false, vertexData, vertices.stride);
Chris Craik53e51e42015-06-01 10:35:35 -0700363 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craikf27133d2015-02-19 09:51:53 -0800364 meshState().bindTexCoordsVertexPointer(false,
Chris Craikef250742015-02-25 17:16:16 -0800365 vertexData + kMeshTextureOffset, vertices.stride);
Chris Craikf27133d2015-02-19 09:51:53 -0800366 }
367
Chris Craik2ab95d72015-02-06 15:25:51 -0800368 glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
369 elementsCount -= drawCount;
Chris Craikef250742015-02-25 17:16:16 -0800370 vertexData += (drawCount / 6) * 4 * vertices.stride;
Chris Craik2ab95d72015-02-06 15:25:51 -0800371 }
Chris Craikef250742015-02-25 17:16:16 -0800372 } else if (indices.bufferObject || indices.indices) {
373 glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800374 } else {
Chris Craik0519c812015-02-11 13:17:06 -0800375 glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800376 }
Chris Craik117bdbc2015-02-05 10:12:38 -0800377
Chris Craik2ab95d72015-02-06 15:25:51 -0800378 // -----------------------------------
379 // ---------- Mesh teardown ----------
380 // -----------------------------------
Chris Craik53e51e42015-06-01 10:35:35 -0700381 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800382 glDisableVertexAttribArray(alphaLocation);
383 }
Chris Craik53e51e42015-06-01 10:35:35 -0700384 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800385 glDisableVertexAttribArray(colorLocation);
Chris Craik117bdbc2015-02-05 10:12:38 -0800386 }
387}
388
389void RenderState::dump() {
390 blend().dump();
391 meshState().dump();
392 scissor().dump();
393 stencil().dump();
Chris Craik6c15ffa2015-02-02 13:50:55 -0800394}
395
John Reck3b202512014-06-23 13:13:08 -0700396} /* namespace uirenderer */
397} /* namespace android */