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 GrGLSLUniformHandler_DEFINED | 8 #ifndef GrGLSLUniformHandler_DEFINED |
9 #define GrGLSLUniformHandler_DEFINED | 9 #define GrGLSLUniformHandler_DEFINED |
10 | 10 |
11 #include "GrGLSLProgramDataManager.h" | 11 #include "GrGLSLProgramDataManager.h" |
12 #include "GrGLSLShaderVar.h" | 12 #include "GrGLSLShaderVar.h" |
13 | 13 |
14 class GrGLSLProgramBuilder; | 14 class GrGLSLProgramBuilder; |
15 class GrGLSLSampler; | |
16 | 15 |
17 class GrGLSLUniformHandler { | 16 class GrGLSLUniformHandler { |
18 public: | 17 public: |
19 virtual ~GrGLSLUniformHandler() {} | 18 virtual ~GrGLSLUniformHandler() {} |
20 | 19 |
21 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 20 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
22 typedef GrGLSLProgramDataManager::UniformHandle SamplerHandle; | |
23 | 21 |
24 /** Add a uniform variable to the current program, that has visibility in on
e or more shaders. | 22 /** Add a uniform variable to the current program, that has visibility in on
e or more shaders. |
25 visibility is a bitfield of GrShaderFlag values indicating from which sh
aders the uniform | 23 visibility is a bitfield of GrShaderFlag values indicating from which sh
aders the uniform |
26 should be accessible. At least one bit must be set. Geometry shader unif
orms are not | 24 should be accessible. At least one bit must be set. Geometry shader unif
orms are not |
27 supported at this time. The actual uniform name will be mangled. If outN
ame is not nullptr | 25 supported at this time. The actual uniform name will be mangled. If outN
ame is not nullptr |
28 then it will refer to the final uniform name after return. Use the addUn
iformArray variant | 26 then it will refer to the final uniform name after return. Use the addUn
iformArray variant |
29 to add an array of uniforms. */ | 27 to add an array of uniforms. */ |
30 UniformHandle addUniform(uint32_t visibility, | 28 UniformHandle addUniform(uint32_t visibility, |
31 GrSLType type, | 29 GrSLType type, |
32 GrSLPrecision precision, | 30 GrSLPrecision precision, |
33 const char* name, | 31 const char* name, |
34 const char** outName = nullptr) { | 32 const char** outName = nullptr) { |
35 SkASSERT(!GrSLTypeIsSamplerType(type)); | |
36 return this->addUniformArray(visibility, type, precision, name, 0, outNa
me); | 33 return this->addUniformArray(visibility, type, precision, name, 0, outNa
me); |
37 } | 34 } |
38 | 35 |
39 UniformHandle addUniformArray(uint32_t visibility, | 36 UniformHandle addUniformArray(uint32_t visibility, |
40 GrSLType type, | 37 GrSLType type, |
41 GrSLPrecision precision, | 38 GrSLPrecision precision, |
42 const char* name, | 39 const char* name, |
43 int arrayCount, | 40 int arrayCount, |
44 const char** outName = nullptr) { | 41 const char** outName = nullptr) { |
45 SkASSERT(!GrSLTypeIsSamplerType(type)); | |
46 return this->internalAddUniformArray(visibility, type, precision, name,
true, arrayCount, | 42 return this->internalAddUniformArray(visibility, type, precision, name,
true, arrayCount, |
47 outName); | 43 outName); |
48 } | 44 } |
49 | 45 |
50 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0
; | 46 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0
; |
51 | 47 |
52 /** | 48 /** |
53 * Shortcut for getUniformVariable(u).c_str() | 49 * Shortcut for getUniformVariable(u).c_str() |
54 */ | 50 */ |
55 virtual const char* getUniformCStr(UniformHandle u) const = 0; | 51 virtual const char* getUniformCStr(UniformHandle u) const = 0; |
56 | |
57 protected: | 52 protected: |
58 explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuild
er(program) {} | 53 explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuild
er(program) {} |
59 | 54 |
60 // This is not owned by the class | 55 // This is not owned by the class |
61 GrGLSLProgramBuilder* fProgramBuilder; | 56 GrGLSLProgramBuilder* fProgramBuilder; |
62 | 57 |
63 private: | 58 private: |
64 virtual int numSamplers() const = 0; | |
65 virtual const GrGLSLSampler& getSampler(SamplerHandle handle) const = 0; | |
66 | |
67 SamplerHandle addSampler(uint32_t visibility, | |
68 GrPixelConfig config, | |
69 GrSLType type, | |
70 GrSLPrecision precision, | |
71 const char* name) { | |
72 return this->internalAddSampler(visibility, config, type, precision, nam
e); | |
73 } | |
74 | |
75 virtual SamplerHandle internalAddSampler(uint32_t visibility, | |
76 GrPixelConfig config, | |
77 GrSLType type, | |
78 GrSLPrecision precision, | |
79 const char* name) = 0; | |
80 | |
81 virtual UniformHandle internalAddUniformArray(uint32_t visibility, | 59 virtual UniformHandle internalAddUniformArray(uint32_t visibility, |
82 GrSLType type, | 60 GrSLType type, |
83 GrSLPrecision precision, | 61 GrSLPrecision precision, |
84 const char* name, | 62 const char* name, |
85 bool mangleName, | 63 bool mangleName, |
86 int arrayCount, | 64 int arrayCount, |
87 const char** outName) = 0; | 65 const char** outName) = 0; |
88 | 66 |
89 virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const =
0; | 67 virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const =
0; |
90 | 68 |
91 friend class GrGLSLProgramBuilder; | 69 friend class GrGLSLProgramBuilder; |
92 }; | 70 }; |
93 | 71 |
94 #endif | 72 #endif |
OLD | NEW |