1 | /* |
2 | * Copyright 2012 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef GrGLProgramDataManager_DEFINED |
9 | #define GrGLProgramDataManager_DEFINED |
10 | |
11 | #include "include/gpu/gl/GrGLTypes.h" |
12 | #include "src/gpu/GrShaderVar.h" |
13 | #include "src/gpu/GrTAllocator.h" |
14 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
15 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
16 | |
17 | #include "include/private/SkTArray.h" |
18 | |
19 | class GrGLGpu; |
20 | class SkMatrix; |
21 | class GrGLProgram; |
22 | |
23 | /** Manages the resources used by a shader program. |
24 | * The resources are objects the program uses to communicate with the |
25 | * application code. |
26 | */ |
27 | class GrGLProgramDataManager : public GrGLSLProgramDataManager { |
28 | public: |
29 | struct GLUniformInfo : public GrGLSLUniformHandler::UniformInfo { |
30 | GrGLint fLocation; |
31 | }; |
32 | |
33 | struct VaryingInfo { |
34 | GrShaderVar fVariable; |
35 | GrGLint fLocation; |
36 | }; |
37 | |
38 | // This uses an allocator rather than array so that the GrShaderVars don't move in memory |
39 | // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their |
40 | // name strings. Otherwise, we'd have to hand out copies. |
41 | typedef GrTAllocator<GLUniformInfo> UniformInfoArray; |
42 | typedef GrTAllocator<VaryingInfo> VaryingInfoArray; |
43 | |
44 | GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&, |
45 | const VaryingInfoArray&); |
46 | |
47 | void setSamplerUniforms(const UniformInfoArray& samplers, int startUnit) const; |
48 | |
49 | /** Functions for uploading uniform values. The varities ending in v can be used to upload to an |
50 | * array of uniforms. arrayCount must be <= the array count of the uniform. |
51 | */ |
52 | void set1i(UniformHandle, int32_t) const override; |
53 | void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
54 | void set1f(UniformHandle, float v0) const override; |
55 | void set1fv(UniformHandle, int arrayCount, const float v[]) const override; |
56 | void set2i(UniformHandle, int32_t, int32_t) const override; |
57 | void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
58 | void set2f(UniformHandle, float, float) const override; |
59 | void set2fv(UniformHandle, int arrayCount, const float v[]) const override; |
60 | void set3i(UniformHandle, int32_t, int32_t, int32_t) const override; |
61 | void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
62 | void set3f(UniformHandle, float, float, float) const override; |
63 | void set3fv(UniformHandle, int arrayCount, const float v[]) const override; |
64 | void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override; |
65 | void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
66 | void set4f(UniformHandle, float, float, float, float) const override; |
67 | void set4fv(UniformHandle, int arrayCount, const float v[]) const override; |
68 | // matrices are column-major, the first three upload a single matrix, the latter three upload |
69 | // arrayCount matrices into a uniform array. |
70 | void setMatrix2f(UniformHandle, const float matrix[]) const override; |
71 | void setMatrix3f(UniformHandle, const float matrix[]) const override; |
72 | void setMatrix4f(UniformHandle, const float matrix[]) const override; |
73 | void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
74 | void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
75 | void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
76 | |
77 | // for nvpr only |
78 | void setPathFragmentInputTransform(VaryingHandle u, int components, |
79 | const SkMatrix& matrix) const override; |
80 | |
81 | private: |
82 | enum { |
83 | kUnusedUniform = -1, |
84 | }; |
85 | |
86 | struct Uniform { |
87 | GrGLint fLocation; |
88 | #ifdef SK_DEBUG |
89 | GrSLType fType; |
90 | int fArrayCount; |
91 | #endif |
92 | }; |
93 | |
94 | enum { |
95 | kUnusedPathProcVarying = -1, |
96 | }; |
97 | struct PathProcVarying { |
98 | GrGLint fLocation; |
99 | SkDEBUGCODE( |
100 | GrSLType fType; |
101 | int fArrayCount; |
102 | ); |
103 | }; |
104 | |
105 | template<int N> inline void setMatrices(UniformHandle, int arrayCount, |
106 | const float matrices[]) const; |
107 | |
108 | SkTArray<Uniform, true> fUniforms; |
109 | SkTArray<PathProcVarying, true> fPathProcVaryings; |
110 | GrGLGpu* fGpu; |
111 | GrGLuint fProgramID; |
112 | |
113 | typedef GrGLSLProgramDataManager INHERITED; |
114 | }; |
115 | |
116 | #endif |
117 | |