1/* 2* Copyright (C) 2011 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*/ 16#ifndef _LIBRENDER_COLORBUFFER_H 17#define _LIBRENDER_COLORBUFFER_H 18 19#include <EGL/egl.h> 20#include <EGL/eglext.h> 21#include <GLES/gl.h> 22#include "emugl/common/smart_ptr.h" 23 24class ColorBuffer 25{ 26public: 27 static ColorBuffer *create(int p_width, int p_height, 28 GLenum p_internalFormat); 29 ~ColorBuffer(); 30 31 GLuint getGLTextureName() const { return m_tex; } 32 GLuint getWidth() const { return m_width; } 33 GLuint getHeight() const { return m_height; } 34 35 void subUpdate(int x, int y, int width, int height, GLenum p_format, GLenum p_type, void *pixels); 36 bool post(); 37 bool bindToTexture(); 38 bool bindToRenderbuffer(); 39 bool blitFromCurrentReadBuffer(); 40 void readback(unsigned char* img); 41 42private: 43 ColorBuffer(); 44 void drawTexQuad(); 45 bool bind_fbo(); // binds a fbo which have this texture as render target 46 47private: 48 GLuint m_tex; 49 GLuint m_blitTex; 50 EGLImageKHR m_eglImage; 51 EGLImageKHR m_blitEGLImage; 52 GLuint m_width; 53 GLuint m_height; 54 GLuint m_fbo; 55 GLenum m_internalFormat; 56}; 57 58typedef emugl::SmartPtr<ColorBuffer> ColorBufferPtr; 59 60#endif 61