OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 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 GrGLSLUniformHandler_DEFINED | |
9 #define GrGLSLUniformHandler_DEFINED | |
10 | |
11 #include "GrGLSLProgramDataManager.h" | |
12 #include "GrGLSLShaderVar.h" | |
13 | |
14 class GrGLSLProgramBuilder; | |
15 | |
16 class GrGLSLUniformHandler { | |
17 public: | |
18 enum ShaderVisibility { | |
19 kVertex_Visibility = 1 << kVertex_GrShaderType, | |
20 kGeometry_Visibility = 1 << kGeometry_GrShaderType, | |
21 kFragment_Visibility = 1 << kFragment_GrShaderType, | |
22 }; | |
23 | |
24 virtual ~GrGLSLUniformHandler() {} | |
25 | |
26 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | |
27 | |
28 /** Add a uniform variable to the current program, that has visibility in on e or more shaders. | |
29 visibility is a bitfield of ShaderVisibility values indicating from whic h shaders the | |
30 uniform should be accessible. At least one bit must be set. Geometry sha der uniforms are not | |
31 supported at this time. The actual uniform name will be mangled. If outN ame is not nullptr | |
32 then it will refer to the final uniform name after return. Use the addUn iformArray variant | |
33 to add an array of uniforms. */ | |
34 UniformHandle addUniform(uint32_t visibility, | |
35 GrSLType type, | |
36 GrSLPrecision precision, | |
37 const char* name, | |
38 const char** outName = nullptr) { | |
39 return this->addUniformArray(visibility, type, precision, name, 0, outNa me); | |
40 } | |
41 | |
42 UniformHandle addUniformArray(uint32_t visibility, | |
43 GrSLType type, | |
44 GrSLPrecision precision, | |
45 const char* name, | |
46 int arrayCount, | |
47 const char** outName = nullptr) { | |
48 return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount, | |
49 outName); | |
50 } | |
51 | |
52 // Handles for program uniforms (other than per-effect uniforms) | |
53 struct BuiltinUniformHandles { | |
54 UniformHandle fRTAdjustmentUni; | |
55 | |
56 // We use the render target height to provide a y-down frag coord when s pecifying | |
57 // origin_upper_left is not supported. | |
58 UniformHandle fRTHeightUni; | |
59 }; | |
60 | |
61 // Used to add a uniform in the vertex shader for transforming into normaliz ed device space. | |
62 void addRTAdjustmentUniform(GrSLPrecision precision, const char* name, const char** outName) { | |
bsalomon
2015/12/03 14:23:19
I'm ok with not wrapping this or doing a priv exte
| |
63 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); | |
64 fUniformHandles.fRTAdjustmentUni = | |
65 this->internalAddUniformArray(kVertex_Visibility, | |
66 kVec4f_GrSLType, precision, name, fals e, 0, outName); | |
67 } | |
68 | |
69 // Used to add a uniform for the RenderTarget height (used for frag position ) without mangling | |
70 // the name of the uniform inside of a stage. | |
71 void addRTHeightUniform(const char* name, const char** outName) { | |
72 SkASSERT(!fUniformHandles.fRTHeightUni.isValid()); | |
73 fUniformHandles.fRTHeightUni = | |
74 this->internalAddUniformArray(kFragment_Visibility, | |
75 kFloat_GrSLType, kDefault_GrSLPrecisio n, | |
76 name, false, 0, outName); | |
77 } | |
78 | |
79 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0 ; | |
80 | |
81 /** | |
82 * Shortcut for getUniformVariable(u).c_str() | |
83 */ | |
84 virtual const char* getUniformCStr(UniformHandle u) const = 0; | |
85 | |
86 const BuiltinUniformHandles& builtinUniformHandles() const { return fUniform Handles; } | |
bsalomon
2015/12/03 14:23:19
this as well
| |
87 | |
88 protected: | |
89 explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuild er(program) {} | |
90 | |
91 // This is not owned by the class | |
92 GrGLSLProgramBuilder* fProgramBuilder; | |
93 | |
94 private: | |
95 virtual UniformHandle internalAddUniformArray(uint32_t visibility, | |
96 GrSLType type, | |
97 GrSLPrecision precision, | |
98 const char* name, | |
99 bool mangleName, | |
100 int arrayCount, | |
101 const char** outName) = 0; | |
102 | |
103 virtual void appendUniformDecls(ShaderVisibility, SkString*) const = 0; | |
104 | |
105 BuiltinUniformHandles fUniformHandles; | |
106 | |
107 friend class GrGLSLProgramBuilder; | |
108 }; | |
109 | |
110 #endif | |
111 | |
OLD | NEW |