GLES11RenderEngine.cpp revision 5cdc8994a0ecd751a6350b16a1bef8b6b0d09b11
1875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian/*
2875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Copyright 2013 The Android Open Source Project
3875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *
4875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * you may not use this file except in compliance with the License.
6875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * You may obtain a copy of the License at
7875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *
8875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *
10875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Unless required by applicable law or agreed to in writing, software
11875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * See the License for the specific language governing permissions and
14875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * limitations under the License.
15875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian */
16875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
17875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <GLES/gl.h>
18875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
19875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <utils/String8.h>
20875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <cutils/compiler.h>
21875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
22875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLES11RenderEngine.h"
23875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLExtensions.h"
243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "Mesh.h"
25875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
26875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
27875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android {
28875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
29875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianGLES11RenderEngine::GLES11RenderEngine() {
31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
33875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
34875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
35875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
36875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glPixelStorei(GL_PACK_ALIGNMENT, 4);
37875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glEnableClientState(GL_VERTEX_ARRAY);
38875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glShadeModel(GL_FLAT);
39875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_DITHER);
40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_CULL_FACE);
41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    struct pack565 {
43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        inline uint16_t operator() (int r, int g, int b) const {
44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            return (r<<11)|(g<<5)|b;
45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        }
46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    } pack565;
47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) };
49875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glGenTextures(1, &mProtectedTexName);
50875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
51875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
52875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData);
57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
59875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianGLES11RenderEngine::~GLES11RenderEngine() {
60875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
61875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
62875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
63875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiansize_t GLES11RenderEngine::getMaxTextureSize() const {
64875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return mMaxTextureSize;
65875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
66875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
67875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiansize_t GLES11RenderEngine::getMaxViewportDims() const {
68875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return
69875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        mMaxViewportDims[0] < mMaxViewportDims[1] ?
70875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            mMaxViewportDims[0] : mMaxViewportDims[1];
71875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
72875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::setViewportAndProjection(
743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        size_t vpw, size_t vph, size_t w, size_t h, bool yswap) {
753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glViewport(0, 0, vpw, vph);
76875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glMatrixMode(GL_PROJECTION);
77875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glLoadIdentity();
78875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // put the origin in the left-bottom corner
793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    if (yswap)  glOrthof(0, w, h, 0, 0, 1);
803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    else        glOrthof(0, w, 0, h, 0, 1);
81875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glMatrixMode(GL_MODELVIEW);
82875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
83875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
84875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupLayerBlending(
85875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    bool premultipliedAlpha, bool opaque, int alpha) {
86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLenum combineRGB;
87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLenum combineAlpha;
88875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLenum src0Alpha;
89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLfloat envColor[4];
90875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (CC_UNLIKELY(alpha < 0xFF)) {
92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        // Cv = premultiplied ? Cs*alpha : Cs
933f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        // Av = !opaque       ? As*alpha : As
94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        combineRGB   = premultipliedAlpha ? GL_MODULATE : GL_REPLACE;
95875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        combineAlpha = !opaque            ? GL_MODULATE : GL_REPLACE;
96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        src0Alpha    = GL_CONSTANT;
97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        envColor[0]  = alpha * (1.0f / 255.0f);
98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    } else {
99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        // Cv = Cs
100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        // Av = opaque ? 1.0 : As
101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        combineRGB   = GL_REPLACE;
102875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        combineAlpha = GL_REPLACE;
103875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        src0Alpha    = opaque ? GL_CONSTANT : GL_TEXTURE;
104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        envColor[0]  = 1.0f;
105875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
106875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, combineRGB);
109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (combineRGB == GL_MODULATE) {
112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, combineAlpha);
116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, src0Alpha);
117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (combineAlpha == GL_MODULATE) {
119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (combineRGB == GL_MODULATE || src0Alpha == GL_CONSTANT) {
123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        envColor[1] = envColor[0];
124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        envColor[2] = envColor[0];
125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        envColor[3] = envColor[0];
126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envColor);
127875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
128875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
129875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (alpha < 0xFF || !opaque) {
130875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glEnable(GL_BLEND);
131875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA,
132875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian                    GL_ONE_MINUS_SRC_ALPHA);
133875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    } else {
134875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glDisable(GL_BLEND);
135875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
136875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
137875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
138875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupDimLayerBlending(int alpha) {
139875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_EXTERNAL_OES);
140875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_2D);
141875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (alpha == 0xFF) {
142875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glDisable(GL_BLEND);
143875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    } else {
144875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glEnable(GL_BLEND);
145875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
146875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
147875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glColor4f(0, 0, 0, alpha/255.0f);
148875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
149875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
150875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupLayerTexturing(size_t textureName,
151875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    bool useFiltering, const float* textureMatrix) {
152875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureName);
153875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLenum filter = GL_NEAREST;
154875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (useFiltering) {
155875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        filter = GL_LINEAR;
156875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
157875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
158875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
159875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter);
160875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter);
161875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glMatrixMode(GL_TEXTURE);
162875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glLoadMatrixf(textureMatrix);
163875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glMatrixMode(GL_MODELVIEW);
164875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_2D);
165875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glEnable(GL_TEXTURE_EXTERNAL_OES);
166875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
167875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
168875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupLayerBlackedOut() {
169875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
170875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glMatrixMode(GL_TEXTURE);
171875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glLoadIdentity();
172875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glMatrixMode(GL_MODELVIEW);
173875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_EXTERNAL_OES);
174875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glEnable(GL_TEXTURE_2D);
175875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
176875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
177875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::disableTexturing() {
178875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_EXTERNAL_OES);
179875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_2D);
180875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
181875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
182875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::disableBlending() {
183875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_BLEND);
184875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
185875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
1863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::fillWithColor(const Mesh& mesh, float r, float g, float b, float a) {
1873f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glColor4f(r, g, b, a);
188875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_EXTERNAL_OES);
189875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_TEXTURE_2D);
190875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    glDisable(GL_BLEND);
1913f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
1923f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glVertexPointer(mesh.getVertexSize(),
1933f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            GL_FLOAT,
1943f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            mesh.getByteStride(),
1955cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian            mesh.getPositions());
1963f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
1973f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount());
198875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
199875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
2003f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::drawMesh(const Mesh& mesh) {
2013f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    if (mesh.getTexCoordsSize()) {
202875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2033f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        glTexCoordPointer(mesh.getTexCoordsSize(),
2043f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian                GL_FLOAT,
2053f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian                mesh.getByteStride(),
2063f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian                mesh.getTexCoords());
207875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
2083f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2093f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glVertexPointer(mesh.getVertexSize(),
2103f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            GL_FLOAT,
2113f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            mesh.getByteStride(),
2125cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian            mesh.getPositions());
2133f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2143f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount());
2153f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2163f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    if (mesh.getTexCoordsSize()) {
217875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
218875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
219875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
220875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
221875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::dump(String8& result) {
222875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    const GLExtensions& extensions(GLExtensions::getInstance());
223875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    result.appendFormat("GLES: %s, %s, %s\n",
224875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            extensions.getVendor(),
225875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            extensions.getRenderer(),
226875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            extensions.getVersion());
227875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    result.appendFormat("%s\n", extensions.getExtension());
228875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
229875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
230875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
231875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android
232875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
233