Index: src/gpu/glsl/GrGLSLUniformHandler.h |
diff --git a/src/gpu/glsl/GrGLSLUniformHandler.h b/src/gpu/glsl/GrGLSLUniformHandler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d38951d0c26e102876b5159fb6e3e5a25288df15 |
--- /dev/null |
+++ b/src/gpu/glsl/GrGLSLUniformHandler.h |
@@ -0,0 +1,111 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef GrGLSLUniformHandler_DEFINED |
+#define GrGLSLUniformHandler_DEFINED |
+ |
+#include "GrGLSLProgramDataManager.h" |
+#include "GrGLSLShaderVar.h" |
+ |
+class GrGLSLProgramBuilder; |
+ |
+class GrGLSLUniformHandler { |
+public: |
+ enum ShaderVisibility { |
+ kVertex_Visibility = 1 << kVertex_GrShaderType, |
+ kGeometry_Visibility = 1 << kGeometry_GrShaderType, |
+ kFragment_Visibility = 1 << kFragment_GrShaderType, |
+ }; |
+ |
+ virtual ~GrGLSLUniformHandler() {} |
+ |
+ typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
+ |
+ /** Add a uniform variable to the current program, that has visibility in one or more shaders. |
+ visibility is a bitfield of ShaderVisibility values indicating from which shaders the |
+ uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not |
+ supported at this time. The actual uniform name will be mangled. If outName is not nullptr |
+ then it will refer to the final uniform name after return. Use the addUniformArray variant |
+ to add an array of uniforms. */ |
+ UniformHandle addUniform(uint32_t visibility, |
+ GrSLType type, |
+ GrSLPrecision precision, |
+ const char* name, |
+ const char** outName = nullptr) { |
+ return this->addUniformArray(visibility, type, precision, name, 0, outName); |
+ } |
+ |
+ UniformHandle addUniformArray(uint32_t visibility, |
+ GrSLType type, |
+ GrSLPrecision precision, |
+ const char* name, |
+ int arrayCount, |
+ const char** outName = nullptr) { |
+ return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount, |
+ outName); |
+ } |
+ |
+ // Handles for program uniforms (other than per-effect uniforms) |
+ struct BuiltinUniformHandles { |
+ UniformHandle fRTAdjustmentUni; |
+ |
+ // We use the render target height to provide a y-down frag coord when specifying |
+ // origin_upper_left is not supported. |
+ UniformHandle fRTHeightUni; |
+ }; |
+ |
+ // Used to add a uniform in the vertex shader for transforming into normalized device space. |
+ 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
|
+ SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); |
+ fUniformHandles.fRTAdjustmentUni = |
+ this->internalAddUniformArray(kVertex_Visibility, |
+ kVec4f_GrSLType, precision, name, false, 0, outName); |
+ } |
+ |
+ // Used to add a uniform for the RenderTarget height (used for frag position) without mangling |
+ // the name of the uniform inside of a stage. |
+ void addRTHeightUniform(const char* name, const char** outName) { |
+ SkASSERT(!fUniformHandles.fRTHeightUni.isValid()); |
+ fUniformHandles.fRTHeightUni = |
+ this->internalAddUniformArray(kFragment_Visibility, |
+ kFloat_GrSLType, kDefault_GrSLPrecision, |
+ name, false, 0, outName); |
+ } |
+ |
+ virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0; |
+ |
+ /** |
+ * Shortcut for getUniformVariable(u).c_str() |
+ */ |
+ virtual const char* getUniformCStr(UniformHandle u) const = 0; |
+ |
+ const BuiltinUniformHandles& builtinUniformHandles() const { return fUniformHandles; } |
bsalomon
2015/12/03 14:23:19
this as well
|
+ |
+protected: |
+ explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {} |
+ |
+ // This is not owned by the class |
+ GrGLSLProgramBuilder* fProgramBuilder; |
+ |
+private: |
+ virtual UniformHandle internalAddUniformArray(uint32_t visibility, |
+ GrSLType type, |
+ GrSLPrecision precision, |
+ const char* name, |
+ bool mangleName, |
+ int arrayCount, |
+ const char** outName) = 0; |
+ |
+ virtual void appendUniformDecls(ShaderVisibility, SkString*) const = 0; |
+ |
+ BuiltinUniformHandles fUniformHandles; |
+ |
+ friend class GrGLSLProgramBuilder; |
+}; |
+ |
+#endif |
+ |