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