Chromium Code Reviews| Index: src/gpu/gl/GrGLUniformManager.h |
| diff --git a/src/gpu/gl/GrGLUniformManager.h b/src/gpu/gl/GrGLUniformManager.h |
| index 6137bcd9cc88806769b63cf1139feab103707d07..e7490beb654548eceb9da9ace57f64e247dc0bbf 100644 |
| --- a/src/gpu/gl/GrGLUniformManager.h |
| +++ b/src/gpu/gl/GrGLUniformManager.h |
| @@ -17,35 +17,49 @@ |
| class GrGpuGL; |
| class SkMatrix; |
| -/** Manages a program's uniforms. |
| +/** Manages a program's uniforms and other shader resources. |
|
Kimmo Kinnunen
2014/07/01 13:01:21
I think this change sums up well the problem of th
|
| */ |
| class GrGLUniformManager : public SkRefCnt { |
| public: |
| // Opaque handle to a uniform |
| - class UniformHandle { |
| + class ShaderResourceHandle { |
| public: |
| - static UniformHandle CreateFromUniformIndex(int i); |
| - |
| bool isValid() const { return 0 != fValue; } |
| - |
| - bool operator==(const UniformHandle& other) const { return other.fValue == fValue; } |
| - |
| - UniformHandle() |
| + ShaderResourceHandle() |
| : fValue(0) { |
| } |
| - |
| - private: |
| - UniformHandle(int value) |
| + protected: |
| + ShaderResourceHandle(int value) |
| : fValue(~value) { |
| SkASSERT(isValid()); |
| } |
| + int fValue; |
| + }; |
| + class UniformHandle : public ShaderResourceHandle { |
| + public: |
| + static UniformHandle CreateFromUniformIndex(int i); |
| + UniformHandle() { } |
| + bool operator==(const UniformHandle& other) const { return other.fValue == fValue; } |
| + private: |
| + UniformHandle(int value) : ShaderResourceHandle(value) { } |
| int toUniformIndex() const { SkASSERT(isValid()); return ~fValue; } |
| - |
| - int fValue; |
| friend class GrGLUniformManager; // For accessing toUniformIndex(). |
| }; |
| + class FragmentInputHandle : public ShaderResourceHandle { |
| + public: |
| + static FragmentInputHandle CreateFromFragmentInputIndex(int i) { |
| + return FragmentInputHandle(i); |
| + } |
| + FragmentInputHandle() { } |
| + bool operator==(const FragmentInputHandle& other) const { return other.fValue == fValue; } |
| + private: |
| + FragmentInputHandle(int value) : ShaderResourceHandle(value) { } |
| + int toLocationIndex() const { SkASSERT(isValid()); return ~fValue; } |
| + friend class GrGLUniformManager; // For accessing toLocationIndex(). |
| + }; |
| + |
| GrGLUniformManager(GrGpuGL* gpu); |
| UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::kNonArray); |
| @@ -72,6 +86,9 @@ public: |
| // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
| void setSkMatrix(UniformHandle, const SkMatrix&) const; |
| + FragmentInputHandle appendFragmentInput(); |
| + void setFragmentInput(FragmentInputHandle i, size_t components, const SkMatrix& matrix) const; |
| + |
| struct BuilderUniform { |
| GrGLShaderVar fVariable; |
| uint32_t fVisibility; |
| @@ -81,17 +98,19 @@ public: |
| // name strings. Otherwise, we'd have to hand out copies. |
| typedef GrTAllocator<BuilderUniform> BuilderUniformArray; |
| + typedef GrTAllocator<GrGLShaderVar> BuilderFragmentInputArray; |
| + |
| /** |
| - * Called by the GrGLShaderBuilder to know if the manager is using |
| - * BindUniformLocation. In that case getUniformLocations must be called |
| - * before the program is linked. |
| + * Prepares the resolution of program resource locations. |
| + * This is to be called before program is linked. |
| */ |
| - bool isUsingBindUniform() const { return fUsingBindUniform; } |
| + void bindProgramResourceLocations(GrGLuint programID, const BuilderUniformArray& uniforms); |
| /** |
| - * Called by the GrGLShaderBuilder to get GL locations for all uniforms. |
| + * Resolves the program resource locations. |
| + * This is to be called after program is linked. |
| */ |
| - void getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms); |
| + void resolveProgramResourceLocations(GrGLuint programID, const BuilderUniformArray& uniforms, const BuilderFragmentInputArray& fragmentInputs); |
| /** |
| * Called by the GrGLShaderBuilder to access the array by the handle (index). |
| @@ -109,9 +128,13 @@ private: |
| GrSLType fType; |
| int fArrayCount; |
| }; |
| + struct FragmentInput { |
| + GrGLint fLocation; |
| + }; |
| bool fUsingBindUniform; |
| SkTArray<Uniform, true> fUniforms; |
| + SkTArray<FragmentInput, true> fFragmentInputs; |
| GrGpuGL* fGpu; |
| typedef SkRefCnt INHERITED; |