SurfaceTextureRenderer.h revision 41a2e9735136f372de95652d0828600282c8e967
1#pragma once 2 3#include "FrameBuffer.h" 4 5#include <GLES2/gl2.h> 6 7#include <stdint.h> 8#include <stdio.h> 9#include <stdlib.h> 10 11//TODO: Add a base class Renderer for WarpRenderer and SurfaceTextureRenderer. 12class SurfaceTextureRenderer { 13 public: 14 SurfaceTextureRenderer(); 15 virtual ~SurfaceTextureRenderer(); 16 17 // Initialize OpenGL resources 18 // @return true if successful 19 bool InitializeGLProgram(); 20 21 bool SetupGraphics(FrameBuffer* buffer); 22 bool SetupGraphics(int width, int height); 23 24 bool Clear(float r, float g, float b, float a); 25 26 void SetViewportMatrix(int w, int h, int W, int H); 27 void SetScalingMatrix(float xscale, float yscale); 28 bool DrawTexture(GLfloat *affine); 29 30 int GetTextureName(); 31 void SetInputTextureName(GLuint textureName); 32 void SetInputTextureDimensions(int width, int height); 33 void SetInputTextureType(GLenum textureType); 34 35 void InitializeGLContext(); 36 37 void SetSTMatrix(float *stmat); 38 39 protected: 40 41 GLuint loadShader(GLenum shaderType, const char* pSource); 42 GLuint createProgram(const char*, const char* ); 43 44 int SurfaceWidth() const { return mSurfaceWidth; } 45 int SurfaceHeight() const { return mSurfaceHeight; } 46 47 private: 48 // Source code for shaders. 49 virtual const char* VertexShaderSource() const; 50 virtual const char* FragmentShaderSource() const; 51 52 // Redefine this to use special texture types such as 53 // GL_TEXTURE_EXTERNAL_OES. 54 virtual GLenum InputTextureType() const { return mInputTextureType; } 55 56 GLuint mGlProgram; 57 GLuint mInputTextureName; 58 GLenum mInputTextureType; 59 int mInputTextureWidth; 60 int mInputTextureHeight; 61 62 // Attribute locations 63 GLint mScalingtransLoc; 64 GLint muSTMatrixHandle; 65 GLint maPositionHandle; 66 GLint maTextureHandle; 67 68 GLfloat mViewportMatrix[16]; 69 GLfloat mScalingMatrix[16]; 70 GLfloat mSTMatrix[16]; 71 72 int mSurfaceWidth; // Width of target surface. 73 int mSurfaceHeight; // Height of target surface. 74 75 FrameBuffer *mFrameBuffer; 76}; 77 78