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