OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrGLProgramBuilder_DEFINED | 8 #ifndef GrGLProgramBuilder_DEFINED |
9 #define GrGLProgramBuilder_DEFINED | 9 #define GrGLProgramBuilder_DEFINED |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 }; | 119 }; |
120 | 120 |
121 struct GrGLGeoToFrag : public GrGLVarying { | 121 struct GrGLGeoToFrag : public GrGLVarying { |
122 GrGLGeoToFrag(GrSLType type) | 122 GrGLGeoToFrag(GrSLType type) |
123 : GrGLVarying(type, kGeoToFrag_Varying) {} | 123 : GrGLVarying(type, kGeoToFrag_Varying) {} |
124 }; | 124 }; |
125 | 125 |
126 /* a specialization of the above for GPs. Lets the user add uniforms, varyings,
and VS / FS code */ | 126 /* a specialization of the above for GPs. Lets the user add uniforms, varyings,
and VS / FS code */ |
127 class GrGLGPBuilder : public virtual GrGLUniformBuilder { | 127 class GrGLGPBuilder : public virtual GrGLUniformBuilder { |
128 public: | 128 public: |
| 129 /* |
| 130 * addVarying allows fine grained control for setting up varyings between st
ages. If you just |
| 131 * need to take an attribute and pass it through to an output value in a fra
gment shader, use |
| 132 * addPassThroughAttribute. |
| 133 * TODO convert most uses of addVarying to addPassThroughAttribute |
| 134 */ |
129 virtual void addVarying(const char* name, | 135 virtual void addVarying(const char* name, |
130 GrGLVarying*, | 136 GrGLVarying*, |
131 GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::
kDefault_Precision) = 0; | 137 GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::
kDefault_Precision) = 0; |
132 | 138 |
| 139 /* |
| 140 * This call can be used by GP to pass an attribute through all shaders dire
ctly to 'output' in |
| 141 * the fragment shader. Though this call effects both the vertex shader and
fragment shader, |
| 142 * it expects 'output' to be defined in the fragment shader before this call
is made. |
| 143 * TODO it might be nicer behavior to have a flag to declare output inside t
his call |
| 144 */ |
| 145 virtual void addPassThroughAttribute(const GrGeometryProcessor::GrAttribute*
, |
| 146 const char* output) = 0; |
| 147 |
133 // TODO rename getFragmentBuilder | 148 // TODO rename getFragmentBuilder |
134 virtual GrGLGPFragmentBuilder* getFragmentShaderBuilder() = 0; | 149 virtual GrGLGPFragmentBuilder* getFragmentShaderBuilder() = 0; |
135 virtual GrGLVertexBuilder* getVertexShaderBuilder() = 0; | 150 virtual GrGLVertexBuilder* getVertexShaderBuilder() = 0; |
136 | 151 |
137 /* | 152 /* |
138 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | 153 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE |
139 */ | 154 */ |
140 }; | 155 }; |
141 | 156 |
142 /* a specializations for FPs. Lets the user add uniforms and FS code */ | 157 /* a specializations for FPs. Lets the user add uniforms and FS code */ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 virtual GrGpuGL* gpu() const SK_OVERRIDE { return fGpu; } | 213 virtual GrGpuGL* gpu() const SK_OVERRIDE { return fGpu; } |
199 | 214 |
200 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() SK_OVERRIDE { retu
rn &fFS; } | 215 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() SK_OVERRIDE { retu
rn &fFS; } |
201 virtual GrGLVertexBuilder* getVertexShaderBuilder() SK_OVERRIDE { return &fV
S; } | 216 virtual GrGLVertexBuilder* getVertexShaderBuilder() SK_OVERRIDE { return &fV
S; } |
202 | 217 |
203 virtual void addVarying( | 218 virtual void addVarying( |
204 const char* name, | 219 const char* name, |
205 GrGLVarying*, | 220 GrGLVarying*, |
206 GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precisi
on) SK_OVERRIDE; | 221 GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precisi
on) SK_OVERRIDE; |
207 | 222 |
| 223 virtual void addPassThroughAttribute(const GrGeometryProcessor::GrAttribute*
, |
| 224 const char* output) SK_OVERRIDE; |
| 225 |
| 226 |
208 // Handles for program uniforms (other than per-effect uniforms) | 227 // Handles for program uniforms (other than per-effect uniforms) |
209 struct BuiltinUniformHandles { | 228 struct BuiltinUniformHandles { |
210 UniformHandle fViewMatrixUni; | 229 UniformHandle fViewMatrixUni; |
211 UniformHandle fRTAdjustmentUni; | 230 UniformHandle fRTAdjustmentUni; |
212 UniformHandle fColorUni; | 231 UniformHandle fColorUni; |
213 UniformHandle fCoverageUni; | 232 UniformHandle fCoverageUni; |
214 | 233 |
215 // We use the render target height to provide a y-down frag coord when s
pecifying | 234 // We use the render target height to provide a y-down frag coord when s
pecifying |
216 // origin_upper_left is not supported. | 235 // origin_upper_left is not supported. |
217 UniformHandle fRTHeightUni; | 236 UniformHandle fRTHeightUni; |
(...skipping 17 matching lines...) Expand all Loading... |
235 | 254 |
236 const GrOptDrawState& optState() const { return fOptState; } | 255 const GrOptDrawState& optState() const { return fOptState; } |
237 const GrProgramDesc& desc() const { return fDesc; } | 256 const GrProgramDesc& desc() const { return fDesc; } |
238 const GrProgramDesc::KeyHeader& header() const { return fDesc.header(); } | 257 const GrProgramDesc::KeyHeader& header() const { return fDesc.header(); } |
239 | 258 |
240 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 259 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
241 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | 260 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're |
242 // generating stage code. | 261 // generating stage code. |
243 void nameVariable(SkString* out, char prefix, const char* name); | 262 void nameVariable(SkString* out, char prefix, const char* name); |
244 void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExp
r1* inputCoverage); | 263 void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExp
r1* inputCoverage); |
| 264 // Generates a possibly mangled name for a stage variable and writes it to t
he fragment shader. |
| 265 // If GrGLSLExpr4 has a valid name then it will use that instead |
| 266 void nameExpression(GrGLSLExpr4*, const char* baseName); |
245 void emitAndInstallProcs(GrGLSLExpr4* inputColor, | 267 void emitAndInstallProcs(GrGLSLExpr4* inputColor, |
246 GrGLSLExpr4* inputCoverage); | 268 GrGLSLExpr4* inputCoverage); |
247 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); | 269 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); |
248 template <class Proc> | 270 void emitAndInstallProc(const GrPendingFragmentStage&, |
249 void emitAndInstallProc(const Proc&, | |
250 int index, | 271 int index, |
251 const GrGLSLExpr4& input, | 272 const GrGLSLExpr4& input, |
252 GrGLSLExpr4* output); | 273 GrGLSLExpr4* output); |
253 | 274 |
| 275 void emitAndInstallProc(const GrGeometryProcessor&, |
| 276 GrGLSLExpr4* outputColor, |
| 277 GrGLSLExpr4* outputCoverage); |
| 278 |
254 // these emit functions help to keep the createAndEmitProcessors template ge
neral | 279 // these emit functions help to keep the createAndEmitProcessors template ge
neral |
255 void emitAndInstallProc(const GrPendingFragmentStage&, | 280 void emitAndInstallProc(const GrPendingFragmentStage&, |
256 const char* outColor, | 281 const char* outColor, |
257 const char* inColor); | 282 const char* inColor); |
258 void emitAndInstallProc(const GrGeometryProcessor&, | 283 void emitAndInstallProc(const GrGeometryProcessor&, |
259 const char* outCoverage, | 284 const char* outColor, |
260 const char* inCoverage); | 285 const char* outCoverage); |
| 286 |
261 void verify(const GrGeometryProcessor&); | 287 void verify(const GrGeometryProcessor&); |
262 void verify(const GrFragmentProcessor&); | 288 void verify(const GrFragmentProcessor&); |
263 void emitSamplers(const GrProcessor&, | 289 void emitSamplers(const GrProcessor&, |
264 GrGLProcessor::TextureSamplerArray* outSamplers, | 290 GrGLProcessor::TextureSamplerArray* outSamplers, |
265 GrGLInstalledProc*); | 291 GrGLInstalledProc*); |
266 | 292 |
267 // each specific program builder has a distinct transform and must override
this function | 293 // each specific program builder has a distinct transform and must override
this function |
268 virtual void emitTransforms(const GrPendingFragmentStage&, | 294 virtual void emitTransforms(const GrPendingFragmentStage&, |
269 GrGLProcessor::TransformedCoordsArray* outCoords
, | 295 GrGLProcessor::TransformedCoordsArray* outCoords
, |
270 GrGLInstalledFragProc*); | 296 GrGLInstalledFragProc*); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 int fTextureUnit; | 391 int fTextureUnit; |
366 }; | 392 }; |
367 SkSTArray<4, Sampler, true> fSamplers; | 393 SkSTArray<4, Sampler, true> fSamplers; |
368 }; | 394 }; |
369 | 395 |
370 struct GrGLInstalledGeoProc : public GrGLInstalledProc { | 396 struct GrGLInstalledGeoProc : public GrGLInstalledProc { |
371 SkAutoTDelete<GrGLGeometryProcessor> fGLProc; | 397 SkAutoTDelete<GrGLGeometryProcessor> fGLProc; |
372 }; | 398 }; |
373 | 399 |
374 struct GrGLInstalledFragProc : public GrGLInstalledProc { | 400 struct GrGLInstalledFragProc : public GrGLInstalledProc { |
375 GrGLInstalledFragProc(bool useLocalCoords) : fGLProc(NULL), fLocalCoordAttri
b(useLocalCoords) {} | 401 GrGLInstalledFragProc() : fGLProc(NULL) {} |
376 class ShaderVarHandle { | 402 class ShaderVarHandle { |
377 public: | 403 public: |
378 bool isValid() const { return fHandle > -1; } | 404 bool isValid() const { return fHandle > -1; } |
379 ShaderVarHandle() : fHandle(-1) {} | 405 ShaderVarHandle() : fHandle(-1) {} |
380 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid());
} | 406 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid());
} |
381 int handle() const { SkASSERT(this->isValid()); return fHandle; } | 407 int handle() const { SkASSERT(this->isValid()); return fHandle; } |
382 UniformHandle convertToUniformHandle() { | 408 UniformHandle convertToUniformHandle() { |
383 SkASSERT(this->isValid()); | 409 SkASSERT(this->isValid()); |
384 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex
(fHandle); | 410 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex
(fHandle); |
385 } | 411 } |
386 | 412 |
387 private: | 413 private: |
388 int fHandle; | 414 int fHandle; |
389 }; | 415 }; |
390 | 416 |
391 struct Transform { | 417 struct Transform { |
392 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidM
atrix(); } | 418 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidM
atrix(); } |
393 ShaderVarHandle fHandle; | 419 ShaderVarHandle fHandle; |
394 SkMatrix fCurrentValue; | 420 SkMatrix fCurrentValue; |
395 GrSLType fType; | 421 GrSLType fType; |
396 }; | 422 }; |
397 | 423 |
398 SkAutoTDelete<GrGLFragmentProcessor> fGLProc; | 424 SkAutoTDelete<GrGLFragmentProcessor> fGLProc; |
399 SkSTArray<2, Transform, true> fTransforms; | 425 SkSTArray<2, Transform, true> fTransforms; |
400 bool fLocalCoordAttrib; | |
401 }; | 426 }; |
402 | 427 |
403 struct GrGLInstalledFragProcs : public SkRefCnt { | 428 struct GrGLInstalledFragProcs : public SkRefCnt { |
404 virtual ~GrGLInstalledFragProcs(); | 429 virtual ~GrGLInstalledFragProcs(); |
405 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; | 430 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; |
406 }; | 431 }; |
407 | 432 |
408 #endif | 433 #endif |
OLD | NEW |