summaryrefslogtreecommitdiffstats
path: root/jni/feature_mos/src/mosaic_renderer/SurfaceTextureRenderer.h
blob: e74bd64a7b16c1a68b2e3280068bcaad1b7080d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include "FrameBuffer.h"

#include <GLES2/gl2.h>

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

//TODO: Add a base class Renderer for WarpRenderer and SurfaceTextureRenderer.
class SurfaceTextureRenderer {
  public:
    SurfaceTextureRenderer();
    virtual ~SurfaceTextureRenderer();

    // Initialize OpenGL resources
    // @return true if successful
    bool InitializeGLProgram();

    bool SetupGraphics(FrameBuffer* buffer);
    bool SetupGraphics(int width, int height);

    bool Clear(float r, float g, float b, float a);

    void SetViewportMatrix(int w, int h, int W, int H);
    void SetScalingMatrix(float xscale, float yscale);
    bool DrawTexture(GLfloat *affine);

    int GetTextureName();
    void SetInputTextureName(GLuint textureName);
    void SetInputTextureDimensions(int width, int height);
    void SetInputTextureType(GLenum textureType);

    void InitializeGLContext();

    void SetSTMatrix(float *stmat);

  protected:

    GLuint loadShader(GLenum shaderType, const char* pSource);
    GLuint createProgram(const char*, const char* );

    int SurfaceWidth() const { return mSurfaceWidth; }
    int SurfaceHeight() const { return mSurfaceHeight; }

 private:
    // Source code for shaders.
    virtual const char* VertexShaderSource() const;
    virtual const char* FragmentShaderSource() const;

    // Redefine this to use special texture types such as
    // GL_TEXTURE_EXTERNAL_OES.
    virtual GLenum InputTextureType() const { return mInputTextureType; }

    GLuint mGlProgram;
    GLuint mInputTextureName;
    GLenum mInputTextureType;
    int mInputTextureWidth;
    int mInputTextureHeight;

    // Attribute locations
    GLint  mScalingtransLoc;
    GLint muSTMatrixHandle;
    GLint maPositionHandle;
    GLint maTextureHandle;

    GLfloat mViewportMatrix[16];
    GLfloat mScalingMatrix[16];
    GLfloat mSTMatrix[16];

    int mSurfaceWidth;      // Width of target surface.
    int mSurfaceHeight;     // Height of target surface.

    FrameBuffer *mFrameBuffer;
};