GLES11RenderEngine.cpp revision a8c386f1c36e916c1df18d41a22104d655a89817
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" 2549457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian#include "Texture.h" 26875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 27875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 28875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android { 29875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianGLES11RenderEngine::GLES11RenderEngine() { 32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 33875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); 34875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); 35875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 36875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glPixelStorei(GL_UNPACK_ALIGNMENT, 4); 37875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glPixelStorei(GL_PACK_ALIGNMENT, 4); 38875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnableClientState(GL_VERTEX_ARRAY); 39875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glShadeModel(GL_FLAT); 40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_DITHER); 41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_CULL_FACE); 42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian struct pack565 { 44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian inline uint16_t operator() (int r, int g, int b) const { 45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return (r<<11)|(g<<5)|b; 46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } pack565; 48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 49875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) }; 50875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGenTextures(1, &mProtectedTexName); 51875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glBindTexture(GL_TEXTURE_2D, mProtectedTexName); 52875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, 57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData); 58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 59875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 60875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianGLES11RenderEngine::~GLES11RenderEngine() { 61875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 62875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 63875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 64875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiansize_t GLES11RenderEngine::getMaxTextureSize() const { 65875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return mMaxTextureSize; 66875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 67875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 68875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiansize_t GLES11RenderEngine::getMaxViewportDims() const { 69875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return 70875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian mMaxViewportDims[0] < mMaxViewportDims[1] ? 71875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian mMaxViewportDims[0] : mMaxViewportDims[1]; 72875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 73875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::setViewportAndProjection( 753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian size_t vpw, size_t vph, size_t w, size_t h, bool yswap) { 763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glViewport(0, 0, vpw, vph); 77875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glMatrixMode(GL_PROJECTION); 78875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glLoadIdentity(); 79875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // put the origin in the left-bottom corner 803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian if (yswap) glOrthof(0, w, h, 0, 0, 1); 813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian else glOrthof(0, w, 0, h, 0, 1); 82875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glMatrixMode(GL_MODELVIEW); 83875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 84875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 85875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupLayerBlending( 86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian bool premultipliedAlpha, bool opaque, int alpha) { 87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLenum combineRGB; 88875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLenum combineAlpha; 89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLenum src0Alpha; 90875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLfloat envColor[4]; 91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (CC_UNLIKELY(alpha < 0xFF)) { 93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // Cv = premultiplied ? Cs*alpha : Cs 943f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // Av = !opaque ? As*alpha : As 95875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian combineRGB = premultipliedAlpha ? GL_MODULATE : GL_REPLACE; 96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian combineAlpha = !opaque ? GL_MODULATE : GL_REPLACE; 97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian src0Alpha = GL_CONSTANT; 98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian envColor[0] = alpha * (1.0f / 255.0f); 99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } else { 100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // Cv = Cs 101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // Av = opaque ? 1.0 : As 102875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian combineRGB = GL_REPLACE; 103875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian combineAlpha = GL_REPLACE; 104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian src0Alpha = opaque ? GL_CONSTANT : GL_TEXTURE; 105875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian envColor[0] = 1.0f; 106875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); 109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, combineRGB); 110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); 111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); 112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (combineRGB == GL_MODULATE) { 113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT); 114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); 115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, combineAlpha); 117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, src0Alpha); 118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); 119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (combineAlpha == GL_MODULATE) { 120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE); 121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); 122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (combineRGB == GL_MODULATE || src0Alpha == GL_CONSTANT) { 124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian envColor[1] = envColor[0]; 125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian envColor[2] = envColor[0]; 126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian envColor[3] = envColor[0]; 127875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envColor); 128875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 129875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 130875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (alpha < 0xFF || !opaque) { 131875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnable(GL_BLEND); 132875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA, 133875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GL_ONE_MINUS_SRC_ALPHA); 134875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } else { 135875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_BLEND); 136875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 137875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 138875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 139875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupDimLayerBlending(int alpha) { 140875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_EXTERNAL_OES); 141875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_2D); 142875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (alpha == 0xFF) { 143875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_BLEND); 144875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } else { 145875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnable(GL_BLEND); 146875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 147875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 148875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glColor4f(0, 0, 0, alpha/255.0f); 149875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 150875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 15149457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopianvoid GLES11RenderEngine::setupLayerTexturing(const Texture& texture) { 15249457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian GLuint target = texture.getTextureTarget(); 15349457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian glBindTexture(target, texture.getTextureName()); 154875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLenum filter = GL_NEAREST; 15549457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian if (texture.getFiltering()) { 156875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian filter = GL_LINEAR; 157875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 15849457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian glTexParameterx(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 15949457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian glTexParameterx(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 16049457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian glTexParameterx(target, GL_TEXTURE_MAG_FILTER, filter); 16149457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian glTexParameterx(target, GL_TEXTURE_MIN_FILTER, filter); 162875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glMatrixMode(GL_TEXTURE); 163a8c386f1c36e916c1df18d41a22104d655a89817Mathias Agopian glLoadMatrixf(texture.getMatrix().asArray()); 164875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glMatrixMode(GL_MODELVIEW); 165875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_2D); 166875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnable(GL_TEXTURE_EXTERNAL_OES); 167875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 168875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 169875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::setupLayerBlackedOut() { 170875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glBindTexture(GL_TEXTURE_2D, mProtectedTexName); 171875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glMatrixMode(GL_TEXTURE); 172875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glLoadIdentity(); 173875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glMatrixMode(GL_MODELVIEW); 174875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_EXTERNAL_OES); 175875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnable(GL_TEXTURE_2D); 176875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 177875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 178875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::disableTexturing() { 179875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_EXTERNAL_OES); 180875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_2D); 181875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 182875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 183875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::disableBlending() { 184875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_BLEND); 185875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 186875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 187458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid GLES11RenderEngine::bindImageAsFramebuffer(EGLImageKHR image, 188458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t* texName, uint32_t* fbName, uint32_t* status) { 189458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian GLuint tname, name; 190458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // turn our EGLImage into a texture 191458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glGenTextures(1, &tname); 192458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glBindTexture(GL_TEXTURE_2D, tname); 193458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image); 194458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 195458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // create a Framebuffer Object to render into 196458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glGenFramebuffersOES(1, &name); 197458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glBindFramebufferOES(GL_FRAMEBUFFER_OES, name); 198458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, 199458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0); 200458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 201458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian *status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); 202458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian *texName = tname; 203458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian *fbName = name; 204458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian} 205458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 206458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid GLES11RenderEngine::unbindFramebuffer(uint32_t texName, uint32_t fbName) { 207458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); 208458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glDeleteFramebuffersOES(1, &fbName); 209458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian glDeleteTextures(1, &texName); 210458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian} 211458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 2123f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::fillWithColor(const Mesh& mesh, float r, float g, float b, float a) { 2133f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glColor4f(r, g, b, a); 214875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_EXTERNAL_OES); 215875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_TEXTURE_2D); 216875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisable(GL_BLEND); 2173f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glVertexPointer(mesh.getVertexSize(), 2193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GL_FLOAT, 2203f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getByteStride(), 2215cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian mesh.getPositions()); 2223f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2233f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount()); 224875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 225875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 2263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid GLES11RenderEngine::drawMesh(const Mesh& mesh) { 2273f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian if (mesh.getTexCoordsSize()) { 228875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glEnableClientState(GL_TEXTURE_COORD_ARRAY); 2293f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glTexCoordPointer(mesh.getTexCoordsSize(), 2303f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GL_FLOAT, 2313f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getByteStride(), 2323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getTexCoords()); 233875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 2343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glVertexPointer(mesh.getVertexSize(), 2363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GL_FLOAT, 2373f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian mesh.getByteStride(), 2385cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian mesh.getPositions()); 2393f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2403f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount()); 2413f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2423f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian if (mesh.getTexCoordsSize()) { 243875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glDisableClientState(GL_TEXTURE_COORD_ARRAY); 244875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 245875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 246875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 247875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid GLES11RenderEngine::dump(String8& result) { 248458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian RenderEngine::dump(result); 249875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 250875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 251875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 252875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 253875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 254458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 255458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#if defined(__gl2_h_) 256458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#error "don't include gl2/gl2.h in this file" 257458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian#endif 258