| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrGLProgramDataManager_DEFINED | 8 #ifndef GrGLProgramDataManager_DEFINED |
| 9 #define GrGLProgramDataManager_DEFINED | 9 #define GrGLProgramDataManager_DEFINED |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 bool operator==(const UniformHandle& other) const { return other.fValue
== fValue; } | 49 bool operator==(const UniformHandle& other) const { return other.fValue
== fValue; } |
| 50 private: | 50 private: |
| 51 UniformHandle(int value) : ShaderResourceHandle(value) { } | 51 UniformHandle(int value) : ShaderResourceHandle(value) { } |
| 52 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; } | 52 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; } |
| 53 int toShaderBuilderIndex() const { return toProgramDataIndex(); } | 53 int toShaderBuilderIndex() const { return toProgramDataIndex(); } |
| 54 | 54 |
| 55 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex
(). | 55 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex
(). |
| 56 friend class GrGLProgramBuilder; // For accessing toShaderBuilderIndex()
. | 56 friend class GrGLProgramBuilder; // For accessing toShaderBuilderIndex()
. |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class VaryingHandle : public ShaderResourceHandle { | 59 struct UniformInfo { |
| 60 public: | 60 GrGLShaderVar fVariable; |
| 61 /** Creates a reference to a varying in separable varyings of a GrGLShad
erBuilder. | 61 uint32_t fVisibility; |
| 62 * The ref can be used to set the varying with the corresponding GrGLPro
gramDataManager.*/ | 62 GrGLint fLocation; |
| 63 static VaryingHandle CreateFromSeparableVaryingIndex(int i) { | |
| 64 return VaryingHandle(i); | |
| 65 } | |
| 66 VaryingHandle() { } | |
| 67 bool operator==(const VaryingHandle& other) const { return other.fValue
== fValue; } | |
| 68 private: | |
| 69 VaryingHandle(int value) : ShaderResourceHandle(value) { } | |
| 70 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; } | |
| 71 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex
(). | |
| 72 }; | 63 }; |
| 73 | 64 |
| 74 GrGLProgramDataManager(GrGpuGL*, GrGLProgram*, const GrGLProgramBuilder&); | 65 // This uses an allocator rather than array so that the GrGLShaderVars don't
move in memory |
| 66 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their |
| 67 // name strings. Otherwise, we'd have to hand out copies. |
| 68 typedef GrTAllocator<UniformInfo> UniformInfoArray; |
| 69 |
| 70 GrGLProgramDataManager(GrGpuGL*, const UniformInfoArray&); |
| 75 | 71 |
| 76 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an | 72 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an |
| 77 * array of uniforms. arrayCount must be <= the array count of the uniform. | 73 * array of uniforms. arrayCount must be <= the array count of the uniform. |
| 78 */ | 74 */ |
| 79 void setSampler(UniformHandle, GrGLint texUnit) const; | 75 void setSampler(UniformHandle, GrGLint texUnit) const; |
| 80 void set1f(UniformHandle, GrGLfloat v0) const; | 76 void set1f(UniformHandle, GrGLfloat v0) const; |
| 81 void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 77 void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
| 82 void set2f(UniformHandle, GrGLfloat, GrGLfloat) const; | 78 void set2f(UniformHandle, GrGLfloat, GrGLfloat) const; |
| 83 void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 79 void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
| 84 void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const; | 80 void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const; |
| 85 void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 81 void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
| 86 void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const; | 82 void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const; |
| 87 void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 83 void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
| 88 // matrices are column-major, the first three upload a single matrix, the la
tter three upload | 84 // matrices are column-major, the first three upload a single matrix, the la
tter three upload |
| 89 // arrayCount matrices into a uniform array. | 85 // arrayCount matrices into a uniform array. |
| 90 void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const; | 86 void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const; |
| 91 void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const; | 87 void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const; |
| 92 void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[])
const; | 88 void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[])
const; |
| 93 void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[])
const; | 89 void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[])
const; |
| 94 | 90 |
| 95 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform | 91 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
| 96 void setSkMatrix(UniformHandle, const SkMatrix&) const; | 92 void setSkMatrix(UniformHandle, const SkMatrix&) const; |
| 97 | 93 |
| 98 void setProgramPathFragmentInputTransform(VaryingHandle i, | |
| 99 unsigned components, | |
| 100 const SkMatrix& matrix) const; | |
| 101 | |
| 102 private: | 94 private: |
| 103 enum { | 95 enum { |
| 104 kUnusedUniform = -1, | 96 kUnusedUniform = -1, |
| 105 }; | 97 }; |
| 106 | 98 |
| 107 struct Uniform { | 99 struct Uniform { |
| 108 GrGLint fVSLocation; | 100 GrGLint fVSLocation; |
| 109 GrGLint fFSLocation; | 101 GrGLint fFSLocation; |
| 110 SkDEBUGCODE( | 102 SkDEBUGCODE( |
| 111 GrSLType fType; | 103 GrSLType fType; |
| 112 int fArrayCount; | 104 int fArrayCount; |
| 113 ); | 105 ); |
| 114 }; | 106 }; |
| 115 struct Varying { | |
| 116 GrGLint fLocation; | |
| 117 SkDEBUGCODE( | |
| 118 GrSLType fType; | |
| 119 ); | |
| 120 }; | |
| 121 | 107 |
| 122 SkTArray<Uniform, true> fUniforms; | 108 SkTArray<Uniform, true> fUniforms; |
| 123 SkTArray<Varying, true> fVaryings; | |
| 124 GrGpuGL* fGpu; | 109 GrGpuGL* fGpu; |
| 125 GrGLProgram* fProgram; | |
| 126 | 110 |
| 127 typedef SkRefCnt INHERITED; | 111 typedef SkRefCnt INHERITED; |
| 128 }; | 112 }; |
| 129 | |
| 130 #endif | 113 #endif |
| OLD | NEW |