OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLSLProgramBuilder_DEFINED | 8 #ifndef GrGLSLProgramBuilder_DEFINED |
9 #define GrGLSLProgramBuilder_DEFINED | 9 #define GrGLSLProgramBuilder_DEFINED |
10 | 10 |
11 #include "GrGeometryProcessor.h" | 11 #include "GrGeometryProcessor.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
14 #include "glsl/GrGLSLGeometryShaderBuilder.h" | 14 #include "glsl/GrGLSLGeometryShaderBuilder.h" |
15 #include "glsl/GrGLSLProgramDataManager.h" | 15 #include "glsl/GrGLSLProgramDataManager.h" |
| 16 #include "glsl/GrGLSLUniformHandler.h" |
16 #include "glsl/GrGLSLVertexShaderBuilder.h" | 17 #include "glsl/GrGLSLVertexShaderBuilder.h" |
17 | 18 |
18 class GrGLSLCaps; | 19 class GrGLSLCaps; |
19 class GrGLSLShaderVar; | 20 class GrGLSLShaderVar; |
20 class GrGLSLVaryingHandler; | 21 class GrGLSLVaryingHandler; |
21 | 22 |
22 // Enough precision to represent 1 / 2048 accurately in printf | 23 class GrGLSLProgramBuilder { |
23 #define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11 | |
24 | |
25 class GrGLSLUniformBuilder { | |
26 public: | |
27 enum ShaderVisibility { | |
28 kVertex_Visibility = 1 << kVertex_GrShaderType, | |
29 kGeometry_Visibility = 1 << kGeometry_GrShaderType, | |
30 kFragment_Visibility = 1 << kFragment_GrShaderType, | |
31 }; | |
32 | |
33 virtual ~GrGLSLUniformBuilder() {} | |
34 | |
35 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | |
36 | |
37 /** Add a uniform variable to the current program, that has visibility in on
e or more shaders. | |
38 visibility is a bitfield of ShaderVisibility values indicating from whic
h shaders the | |
39 uniform should be accessible. At least one bit must be set. Geometry sha
der uniforms are not | |
40 supported at this time. The actual uniform name will be mangled. If outN
ame is not nullptr | |
41 then it will refer to the final uniform name after return. Use the addUn
iformArray variant | |
42 to add an array of uniforms. */ | |
43 UniformHandle addUniform(uint32_t visibility, | |
44 GrSLType type, | |
45 GrSLPrecision precision, | |
46 const char* name, | |
47 const char** outName = nullptr) { | |
48 return this->addUniformArray(visibility, type, precision, name, 0, outNa
me); | |
49 } | |
50 | |
51 UniformHandle addUniformArray(uint32_t visibility, | |
52 GrSLType type, | |
53 GrSLPrecision precision, | |
54 const char* name, | |
55 int arrayCount, | |
56 const char** outName = nullptr) { | |
57 return this->internalAddUniformArray(visibility, type, precision, name,
true, arrayCount, | |
58 outName); | |
59 } | |
60 | |
61 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0
; | |
62 | |
63 /** | |
64 * Shortcut for getUniformVariable(u).c_str() | |
65 */ | |
66 virtual const char* getUniformCStr(UniformHandle u) const = 0; | |
67 | |
68 /* | |
69 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | |
70 */ | |
71 protected: | |
72 virtual UniformHandle internalAddUniformArray( | |
73 uint32_t visibility, | |
74 GrSLType type, | |
75 GrSLPrecision precision, | |
76 const char* name, | |
77 bool mangleName, | |
78 int arrayCount, | |
79 const char** outName) = 0; | |
80 }; | |
81 | |
82 /* a specialization of the above for GPs. Lets the user add uniforms, varyings,
and VS / FS code */ | |
83 class GrGLSLGPBuilder : public virtual GrGLSLUniformBuilder { | |
84 public: | |
85 /* | |
86 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | |
87 */ | |
88 }; | |
89 | |
90 | |
91 /* a specializations for FPs. Lets the user add uniforms and FS code */ | |
92 class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder { | |
93 public: | |
94 /* | |
95 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | |
96 */ | |
97 }; | |
98 | |
99 /* a specializations for XPs. Lets the user add uniforms and FS code */ | |
100 class GrGLSLXPBuilder : public virtual GrGLSLUniformBuilder { | |
101 public: | |
102 /* | |
103 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | |
104 */ | |
105 }; | |
106 | |
107 class GrGLSLProgramBuilder : public GrGLSLGPBuilder, | |
108 public GrGLSLFPBuilder, | |
109 public GrGLSLXPBuilder { | |
110 public: | 24 public: |
111 typedef GrGpu::DrawArgs DrawArgs; | 25 typedef GrGpu::DrawArgs DrawArgs; |
| 26 typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility; |
| 27 |
| 28 virtual ~GrGLSLProgramBuilder() {} |
112 | 29 |
113 virtual const GrGLSLCaps* glslCaps() const = 0; | 30 virtual const GrGLSLCaps* glslCaps() const = 0; |
114 | 31 |
115 // Handles for program uniforms (other than per-effect uniforms) | |
116 struct BuiltinUniformHandles { | |
117 UniformHandle fRTAdjustmentUni; | |
118 | |
119 // We use the render target height to provide a y-down frag coord when s
pecifying | |
120 // origin_upper_left is not supported. | |
121 UniformHandle fRTHeightUni; | |
122 }; | |
123 | |
124 protected: | |
125 explicit GrGLSLProgramBuilder(const DrawArgs& args); | |
126 | |
127 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim
itiveProcessor; } | 32 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim
itiveProcessor; } |
128 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } | 33 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } |
129 const GrProgramDesc& desc() const { return *fArgs.fDesc; } | 34 const GrProgramDesc& desc() const { return *fArgs.fDesc; } |
130 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(
); } | 35 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(
); } |
131 | 36 |
132 void appendUniformDecls(ShaderVisibility, SkString*) const; | 37 void appendUniformDecls(ShaderVisibility, SkString*) const; |
133 | 38 |
134 // Used to add a uniform for frag position without mangling the name of the
uniform inside of a | |
135 // stage. | |
136 UniformHandle addFragPosUniform(uint32_t visibility, | |
137 GrSLType type, | |
138 GrSLPrecision precision, | |
139 const char* name, | |
140 const char** outName) { | |
141 return this->internalAddUniformArray(visibility, type, precision, name,
false, 0, outName); | |
142 } | |
143 | |
144 const char* rtAdjustment() const { return "rtAdjustment"; } | 39 const char* rtAdjustment() const { return "rtAdjustment"; } |
145 | 40 |
146 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 41 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
147 // char (unless the prefix is '\0'). It also will mangle the name to be stag
e-specific unless | 42 // char (unless the prefix is '\0'). It also will mangle the name to be stag
e-specific unless |
148 // explicitly asked not to. | 43 // explicitly asked not to. |
149 void nameVariable(SkString* out, char prefix, const char* name, bool mangle
= true); | 44 void nameVariable(SkString* out, char prefix, const char* name, bool mangle
= true); |
150 | 45 |
| 46 virtual GrGLSLUniformHandler* uniformHandler() = 0; |
| 47 virtual const GrGLSLUniformHandler* uniformHandler() const = 0; |
151 virtual GrGLSLVaryingHandler* varyingHandler() = 0; | 48 virtual GrGLSLVaryingHandler* varyingHandler() = 0; |
152 | 49 |
153 // number of each input/output type in a single allocation block, used by ma
ny builders | 50 // number of each input/output type in a single allocation block, used by ma
ny builders |
154 static const int kVarsPerBlock; | 51 static const int kVarsPerBlock; |
155 | 52 |
156 GrGLSLVertexBuilder fVS; | 53 GrGLSLVertexBuilder fVS; |
157 GrGLSLGeometryBuilder fGS; | 54 GrGLSLGeometryBuilder fGS; |
158 GrGLSLFragmentShaderBuilder fFS; | 55 GrGLSLFragmentShaderBuilder fFS; |
159 | 56 |
160 int fStageIndex; | 57 int fStageIndex; |
161 | 58 |
162 BuiltinUniformHandles fUniformHandles; | |
163 | |
164 const DrawArgs& fArgs; | 59 const DrawArgs& fArgs; |
165 | 60 |
166 private: | 61 protected: |
167 virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out
) const = 0; | 62 explicit GrGLSLProgramBuilder(const DrawArgs& args); |
168 | |
169 friend class GrGLSLShaderBuilder; | |
170 friend class GrGLSLVertexBuilder; | |
171 friend class GrGLSLFragmentShaderBuilder; | |
172 friend class GrGLSLGeometryBuilder; | |
173 friend class GrGLSLVaryingHandler; | |
174 }; | 63 }; |
175 | 64 |
176 #endif | 65 #endif |
OLD | NEW |