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 <cutils/log.h> 183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <ui/Rect.h> 193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <ui/Region.h> 20875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 21875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "RenderEngine.h" 22875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLES10RenderEngine.h" 23875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLES11RenderEngine.h" 243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "GLES20RenderEngine.h" 25875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLExtensions.h" 263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "Mesh.h" 27875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 28875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 29875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android { 30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine* RenderEngine::create(EGLDisplay display, EGLConfig config) { 332185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian EGLint renderableType = 0; 342185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian EGLint contextClientVersion = 0; 352185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian 362185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian // query the renderable type, setting the EGL_CONTEXT_CLIENT_VERSION accordingly 372185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian if (!eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType)) { 382185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian LOG_ALWAYS_FATAL("can't query EGLConfig RENDERABLE_TYPE"); 392185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian } 402185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian 412185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian if (renderableType & EGL_OPENGL_ES2_BIT) { 422185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian contextClientVersion = 2; 432185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian } else if (renderableType & EGL_OPENGL_ES_BIT) { 442185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian contextClientVersion = 1; 452185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian } else { 462185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian LOG_ALWAYS_FATAL("no supported EGL_RENDERABLE_TYPEs"); 472185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian } 482185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian 49875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // Also create our EGLContext 50875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLint contextAttributes[] = { 512185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian EGL_CONTEXT_CLIENT_VERSION, contextClientVersion, // MUST be first 52875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#ifdef EGL_IMG_context_priority 53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#ifdef HAS_CONTEXT_PRIORITY 54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#warning "using EGL_IMG_context_priority" 55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG, 56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif 57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif 58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGL_NONE, EGL_NONE 59875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian }; 60458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes); 61875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 62875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // if can't create a GL context, we can only abort. 63875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian LOG_ALWAYS_FATAL_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed"); 64875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 65875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 66875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // now figure out what version of GL did we actually get 67875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // NOTE: a dummy surface is not needed if KHR_create_context is supported 68875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 69875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLint attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE, EGL_NONE }; 70875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLSurface dummy = eglCreatePbufferSurface(display, config, attribs); 71875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian LOG_ALWAYS_FATAL_IF(dummy==EGL_NO_SURFACE, "can't create dummy pbuffer"); 72875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLBoolean success = eglMakeCurrent(display, dummy, dummy, ctxt); 73875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian LOG_ALWAYS_FATAL_IF(!success, "can't make dummy pbuffer current"); 74875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 75875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLExtensions& extensions(GLExtensions::getInstance()); 76875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian extensions.initWithGLStrings( 77875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGetString(GL_VENDOR), 78875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGetString(GL_RENDERER), 79875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGetString(GL_VERSION), 80875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian glGetString(GL_EXTENSIONS)); 81875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 82875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GlesVersion version = parseGlesVersion( extensions.getVersion() ); 83875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 84875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // initialize the renderer while GL is current 85875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian RenderEngine* engine = NULL; 87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian switch (version) { 88875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian case GLES_VERSION_1_0: 89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian engine = new GLES10RenderEngine(); 90875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian break; 91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian case GLES_VERSION_1_1: 92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian engine = new GLES11RenderEngine(); 93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian break; 94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian case GLES_VERSION_2_0: 95875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian case GLES_VERSION_3_0: 963f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian engine = new GLES20RenderEngine(); 97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian break; 98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian engine->setEGLContext(ctxt); 100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("OpenGL ES informations:"); 102875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("vendor : %s", extensions.getVendor()); 103875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("renderer : %s", extensions.getRenderer()); 104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("version : %s", extensions.getVersion()); 105875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("extensions: %s", extensions.getExtension()); 106875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("GL_MAX_TEXTURE_SIZE = %d", engine->getMaxTextureSize()); 107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGI("GL_MAX_VIEWPORT_DIMS = %d", engine->getMaxViewportDims()); 108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian eglDestroySurface(display, dummy); 111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return engine; 113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::RenderEngine() : mEGLContext(EGL_NO_CONTEXT) { 116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::~RenderEngine() { 119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid RenderEngine::setEGLContext(EGLContext ctxt) { 122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian mEGLContext = ctxt; 123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianEGLContext RenderEngine::getEGLContext() const { 126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return mEGLContext; 127875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 128875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 129875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid RenderEngine::checkErrors() const { 130875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian do { 131875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian // there could be more than one error flag 132875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLenum error = glGetError(); 133875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (error == GL_NO_ERROR) 134875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian break; 135875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGE("GL error 0x%04x", int(error)); 136875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } while (true); 137875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 138875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 139875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::GlesVersion RenderEngine::parseGlesVersion(const char* str) { 140875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian int major, minor; 141875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (sscanf(str, "OpenGL ES-CM %d.%d", &major, &minor) != 2) { 142875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (sscanf(str, "OpenGL ES %d.%d", &major, &minor) != 2) { 143875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGW("Unable to parse GL_VERSION string: \"%s\"", str); 144875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return GLES_VERSION_1_0; 145875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 146875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian } 147875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 148875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (major == 1 && minor == 0) return GLES_VERSION_1_0; 149875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (major == 1 && minor >= 1) return GLES_VERSION_1_1; 150875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (major == 2 && minor >= 0) return GLES_VERSION_2_0; 151875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian if (major == 3 && minor >= 0) return GLES_VERSION_3_0; 152875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 153875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian ALOGW("Unrecognized OpenGL ES version: %d.%d", major, minor); 154875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian return GLES_VERSION_1_0; 155875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian} 156875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 1573f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::fillRegionWithColor(const Region& region, uint32_t height, 1583f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian float red, float green, float blue, float alpha) { 1593f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian size_t c; 1603f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian Rect const* r = region.getArray(&c); 1613f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian Mesh mesh(Mesh::TRIANGLES, c*6, 2); 162ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>()); 1633f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian for (size_t i=0 ; i<c ; i++, r++) { 1645cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 0].x = r->left; 1655cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 0].y = height - r->top; 1665cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 1].x = r->left; 1675cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 1].y = height - r->bottom; 1685cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 2].x = r->right; 1695cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 2].y = height - r->bottom; 1705cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 3].x = r->left; 1715cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 3].y = height - r->top; 1725cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 4].x = r->right; 1735cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 4].y = height - r->bottom; 1745cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 5].x = r->right; 1755cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian position[i*6 + 5].y = height - r->top; 1763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian } 17719733a32799f792125913e746e8644d16f8dc223Mathias Agopian setupFillWithColor(red, green, blue, alpha); 17819733a32799f792125913e746e8644d16f8dc223Mathias Agopian drawMesh(mesh); 1793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 1803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 1813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::clearWithColor(float red, float green, float blue, float alpha) { 1823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glClearColor(red, green, blue, alpha); 1833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 1843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 1853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 1863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::setScissor( 1873f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) { 1883f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glScissor(left, bottom, right, top); 1893f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glEnable(GL_SCISSOR_TEST); 1903f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 1913f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 1923f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::disableScissor() { 1933f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glDisable(GL_SCISSOR_TEST); 1943f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 1953f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 1963f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::genTextures(size_t count, uint32_t* names) { 1973f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glGenTextures(count, names); 1983f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 1993f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2003f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::deleteTextures(size_t count, uint32_t const* names) { 2013f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian glDeleteTextures(count, names); 2023f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 2033f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 204d555684cb36dfb959694db76962e570184f98838Mathias Agopianvoid RenderEngine::readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) { 205d555684cb36dfb959694db76962e570184f98838Mathias Agopian glReadPixels(l, b, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 206d555684cb36dfb959694db76962e570184f98838Mathias Agopian} 207d555684cb36dfb959694db76962e570184f98838Mathias Agopian 208458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid RenderEngine::dump(String8& result) { 209458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian const GLExtensions& extensions(GLExtensions::getInstance()); 210458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian result.appendFormat("GLES: %s, %s, %s\n", 211458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian extensions.getVendor(), 212458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian extensions.getRenderer(), 213458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian extensions.getVersion()); 214458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian result.appendFormat("%s\n", extensions.getExtension()); 215458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian} 216458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 2173f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian// --------------------------------------------------------------------------- 2183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias AgopianRenderEngine::BindImageAsFramebuffer::BindImageAsFramebuffer( 2203f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian RenderEngine& engine, EGLImageKHR image) : mEngine(engine) 2213f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian{ 222458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian mEngine.bindImageAsFramebuffer(image, &mTexName, &mFbName, &mStatus); 223458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 2243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian ALOGE_IF(mStatus != GL_FRAMEBUFFER_COMPLETE_OES, 2253f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian "glCheckFramebufferStatusOES error %d", mStatus); 2263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 2273f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2283f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias AgopianRenderEngine::BindImageAsFramebuffer::~BindImageAsFramebuffer() { 2293f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // back to main framebuffer 230458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian mEngine.unbindFramebuffer(mTexName, mFbName); 2313f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 2323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 2333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianstatus_t RenderEngine::BindImageAsFramebuffer::getStatus() const { 2343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian return mStatus == GL_FRAMEBUFFER_COMPLETE_OES ? NO_ERROR : BAD_VALUE; 2353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} 2363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 237875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 238875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 239875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 240