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
11class Renderer {
12  public:
13    Renderer();
14    virtual ~Renderer();
15
16    // Initialize OpenGL resources
17    // @return true if successful
18    virtual bool InitializeGLProgram() = 0;
19
20    bool SetupGraphics(FrameBuffer* buffer);
21    bool SetupGraphics(int width, int height);
22
23    bool Clear(float r, float g, float b, float a);
24
25    int GetTextureName();
26    void SetInputTextureName(GLuint textureName);
27    void SetInputTextureDimensions(int width, int height);
28    void SetInputTextureType(GLenum textureType);
29
30    void InitializeGLContext();
31
32  protected:
33
34    GLuint loadShader(GLenum shaderType, const char* pSource);
35    GLuint createProgram(const char*, const char* );
36
37    int SurfaceWidth() const { return mSurfaceWidth; }
38    int SurfaceHeight() const { return mSurfaceHeight; }
39
40    // Source code for shaders.
41    virtual const char* VertexShaderSource() const = 0;
42    virtual const char* FragmentShaderSource() const = 0;
43
44    // Redefine this to use special texture types such as
45    // GL_TEXTURE_EXTERNAL_OES.
46    GLenum InputTextureType() const { return mInputTextureType; }
47
48    GLuint mGlProgram;
49    GLuint mInputTextureName;
50    GLenum mInputTextureType;
51    int mInputTextureWidth;
52    int mInputTextureHeight;
53
54    // Attribute locations
55    GLint  mScalingtransLoc;
56    GLint maPositionHandle;
57    GLint maTextureHandle;
58
59
60    int mSurfaceWidth;      // Width of target surface.
61    int mSurfaceHeight;     // Height of target surface.
62
63    FrameBuffer *mFrameBuffer;
64};
65
66