aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGpuGLShaders.h
blob: c7cdd2b5f581817ac8e99c2984f4c7b4e9bf41f2 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */



#ifndef GrGpuGLShaders_DEFINED
#define GrGpuGLShaders_DEFINED

#include "GrGpuGL.h"
#include "GrGLProgram.h"

class GrCustomStage;
class GrGpuGLProgram;

// Programmable OpenGL or OpenGL ES 2.0
class GrGpuGLShaders : public GrGpuGL {
public:
             GrGpuGLShaders(const GrGLContextInfo& ctxInfo);
    virtual ~GrGpuGLShaders();

    virtual void abandonResources() SK_OVERRIDE;

    bool programUnitTest();

protected:
    // overrides from GrGpu
    virtual void onResetContext() SK_OVERRIDE;
    virtual bool flushGraphicsState(GrPrimitiveType type) SK_OVERRIDE;
    virtual void setupGeometry(int* startVertex,
                               int* startIndex,
                               int vertexCount,
                               int indexCount) SK_OVERRIDE;

private:

    // for readability of function impls
    typedef GrGLProgram::ProgramDesc ProgramDesc;
    typedef ProgramDesc::StageDesc   StageDesc;
    typedef GrGLProgram::CachedData  CachedData;

    class ProgramCache;

    // sets the texture matrix uniform for currently bound program
    void flushTextureMatrix(int stage);

    // sets the texture domain uniform for currently bound program
    void flushTextureDomain(int stage);

    // sets the color specified by GrDrawState::setColor()
    void flushColor(GrColor color);

    // sets the color specified by GrDrawState::setCoverage()
    void flushCoverage(GrColor color);

    // sets the MVP matrix uniform for currently bound program
    void flushViewMatrix();

    // flushes the parameters to two point radial gradient
    void flushRadial2(int stage);

    // flushes the parameters for convolution
    void flushConvolution(int stage);

    // flushes the normalized texel size
    void flushTexelSize(int stage);

    // flushes the color matrix
    void flushColorMatrix();

    static void DeleteProgram(const GrGLInterface* gl,
                              CachedData* programData);

    void buildProgram(GrPrimitiveType typeBlend,
                      BlendOptFlags blendOpts,
                      GrBlendCoeff dstCoeff,
                      GrCustomStage** customStages);

    ProgramCache*               fProgramCache;
    CachedData*                 fProgramData;

    GrGLuint                    fHWProgramID;
    GrColor                     fHWConstAttribColor;
    GrColor                     fHWConstAttribCoverage;

    GrGLProgram                 fCurrentProgram;
    // If we get rid of fixed function subclass this should move
    // to the GLCaps struct in parent class
    GrGLint                     fMaxVertexAttribs;

    typedef GrGpuGL INHERITED;
};

#endif