GLES11RenderEngine.cpp revision 458197de008be8fe561286b09f4edddb2f5c540a
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> 18458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#include <GLES/glext.h> 19875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 20875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <utils/String8.h> 21875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <cutils/compiler.h> 22875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 23875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLES11RenderEngine.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 186458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid GLES11RenderEngine::bindImageAsFramebuffer(EGLImageKHR image, 187458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t* texName, uint32_t* fbName, uint32_t* status) { 188458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian GLuint tname, name; 189458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // turn our EGLImage into a texture 190458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glGenTextures(1, &tname); 191458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glBindTexture(GL_TEXTURE_2D, tname); 192458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image); 193458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 194458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // create a Framebuffer Object to render into 195458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glGenFramebuffersOES(1, &name); 196458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glBindFramebufferOES(GL_FRAMEBUFFER_OES, name); 197458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, 198458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0); 199458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 200458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian *status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); 201458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian *texName = tname; 202458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian *fbName = name; 203458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian} 204458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 205458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid GLES11RenderEngine::unbindFramebuffer(uint32_t texName, uint32_t fbName) { 206458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); 207458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glDeleteFramebuffersOES(1, &fbName); 208458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glDeleteTextures(1, &texName); 209458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian} 210458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 2113f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::fillWithColor(const Mesh& mesh, float r, float g, float b, float a) { 2123f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glColor4f(r, g, b, a); 213875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_EXTERNAL_OES); 214875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_2D); 215875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_BLEND); 2163f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2173f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glVertexPointer(mesh.getVertexSize(), 2183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GL_FLOAT, 2193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getByteStride(), 2205cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian mesh.getPositions()); 2213f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2223f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount()); 223875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 224875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 2253f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::drawMesh(const Mesh& mesh) { 2263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian if (mesh.getTexCoordsSize()) { 227875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnableClientState(GL_TEXTURE_COORD_ARRAY); 2283f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glTexCoordPointer(mesh.getTexCoordsSize(), 2293f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GL_FLOAT, 2303f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getByteStride(), 2313f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getTexCoords()); 232875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 2333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glVertexPointer(mesh.getVertexSize(), 2353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GL_FLOAT, 2363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getByteStride(), 2375cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian mesh.getPositions()); 2383f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2393f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount()); 2403f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2413f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian if (mesh.getTexCoordsSize()) { 242875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisableClientState(GL_TEXTURE_COORD_ARRAY); 243875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 244875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 245875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 246875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::dump(String8& result) { 247458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian RenderEngine::dump(result); 248875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 249875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 250875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 251875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 252875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 253458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 254458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#if defined(__gl2_h_) 255458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#error "don't include gl2/gl2.h in this file" 256458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#endif 257