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 #include "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLUniformHandle.h" | 10 #include "gl/GrGLUniformHandle.h" |
11 #include "gl/GrGpuGL.h" | 11 #include "gl/GrGpuGL.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 | 13 |
14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ | 14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
15 SkASSERT(arrayCount <= uni.fArrayCount || \ | 15 SkASSERT(arrayCount <= uni.fArrayCount || \ |
16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCoun
t)) | 16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCoun
t)) |
17 | 17 |
18 GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu) : fGpu(gpu) { | 18 GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu, |
19 // skbug.com/2056 | 19 GrGLProgram*, |
20 fUsingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation !=
NULL; | 20 const GrGLShaderBuilder& builder) |
21 } | 21 : fGpu(gpu) { |
| 22 int count = builder.getUniformInfos().count(); |
| 23 fUniforms.push_back_n(count); |
| 24 for (int i = 0; i < count; i++) { |
| 25 Uniform& uniform = fUniforms[i]; |
| 26 const GrGLShaderBuilder::UniformInfo& builderUniform = builder.getUnifor
mInfos()[i]; |
| 27 SkASSERT(GrGLShaderVar::kNonArray == builderUniform.fVariable.getArrayCo
unt() || |
| 28 builderUniform.fVariable.getArrayCount() > 0); |
| 29 SkDEBUGCODE( |
| 30 uniform.fArrayCount = builderUniform.fVariable.getArrayCount(); |
| 31 uniform.fType = builderUniform.fVariable.getType(); |
| 32 ); |
| 33 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he
re. |
22 | 34 |
23 GrGLProgramDataManager::UniformHandle GrGLProgramDataManager::appendUniform(GrSL
Type type, int arrayCount) { | 35 if (GrGLShaderBuilder::kVertex_Visibility & builderUniform.fVisibility)
{ |
24 int idx = fUniforms.count(); | 36 uniform.fVSLocation = builderUniform.fLocation; |
25 Uniform& uni = fUniforms.push_back(); | 37 } else { |
26 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); | 38 uniform.fVSLocation = kUnusedUniform; |
27 uni.fArrayCount = arrayCount; | 39 } |
28 uni.fType = type; | 40 if (GrGLShaderBuilder::kFragment_Visibility & builderUniform.fVisibility
) { |
29 uni.fVSLocation = kUnusedUniform; | 41 uniform.fFSLocation = builderUniform.fLocation; |
30 uni.fFSLocation = kUnusedUniform; | 42 } else { |
31 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(idx); | 43 uniform.fFSLocation = kUnusedUniform; |
| 44 } |
| 45 } |
32 } | 46 } |
33 | 47 |
34 void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const
{ | 48 void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const
{ |
35 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 49 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
36 SkASSERT(uni.fType == kSampler2D_GrSLType); | 50 SkASSERT(uni.fType == kSampler2D_GrSLType); |
37 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 51 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
38 // FIXME: We still insert a single sampler uniform for every stage. If the s
hader does not | 52 // FIXME: We still insert a single sampler uniform for every stage. If the s
hader does not |
39 // reference the sampler then the compiler may have optimized it out. Uncomm
ent this assert | 53 // reference the sampler then the compiler may have optimized it out. Uncomm
ent this assert |
40 // once stages insert their own samplers. | 54 // once stages insert their own samplers. |
41 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); | 55 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); |
42 if (kUnusedUniform != uni.fFSLocation) { | 56 if (kUnusedUniform != uni.fFSLocation) { |
43 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); | 57 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
44 } | 58 } |
45 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 59 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
46 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); | 60 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
47 } | 61 } |
48 } | 62 } |
49 | 63 |
50 void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { | 64 void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { |
51 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 65 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
52 SkASSERT(uni.fType == kFloat_GrSLType); | 66 SkASSERT(uni.fType == kFloat_GrSLType); |
53 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 67 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
54 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 68 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
55 if (kUnusedUniform != uni.fFSLocation) { | 69 if (kUnusedUniform != uni.fFSLocation) { |
56 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); | 70 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
57 } | 71 } |
58 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 72 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
59 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); | 73 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); |
60 } | 74 } |
61 } | 75 } |
62 | 76 |
63 void GrGLProgramDataManager::set1fv(UniformHandle u, | 77 void GrGLProgramDataManager::set1fv(UniformHandle u, |
64 int arrayCount, | 78 int arrayCount, |
65 const GrGLfloat v[]) const { | 79 const GrGLfloat v[]) const { |
66 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 80 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
67 SkASSERT(uni.fType == kFloat_GrSLType); | 81 SkASSERT(uni.fType == kFloat_GrSLType); |
68 SkASSERT(arrayCount > 0); | 82 SkASSERT(arrayCount > 0); |
69 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 83 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
70 // This assert fires in some instances of the two-pt gradient for its VSPara
ms. | 84 // This assert fires in some instances of the two-pt gradient for its VSPara
ms. |
71 // Once the uniform manager is responsible for inserting the duplicate unifo
rm | 85 // Once the uniform manager is responsible for inserting the duplicate unifo
rm |
72 // arrays in VS and FS driver bug workaround, this can be enabled. | 86 // arrays in VS and FS driver bug workaround, this can be enabled. |
73 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLoc
ation); | 87 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLoc
ation); |
74 if (kUnusedUniform != uni.fFSLocation) { | 88 if (kUnusedUniform != uni.fFSLocation) { |
75 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount,
v)); | 89 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount,
v)); |
76 } | 90 } |
77 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 91 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
78 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount,
v)); | 92 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount,
v)); |
79 } | 93 } |
80 } | 94 } |
81 | 95 |
82 void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1)
const { | 96 void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1)
const { |
83 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 97 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
84 SkASSERT(uni.fType == kVec2f_GrSLType); | 98 SkASSERT(uni.fType == kVec2f_GrSLType); |
85 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 99 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
86 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 100 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
87 if (kUnusedUniform != uni.fFSLocation) { | 101 if (kUnusedUniform != uni.fFSLocation) { |
88 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); | 102 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); |
89 } | 103 } |
90 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 104 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
91 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); | 105 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); |
92 } | 106 } |
93 } | 107 } |
94 | 108 |
95 void GrGLProgramDataManager::set2fv(UniformHandle u, | 109 void GrGLProgramDataManager::set2fv(UniformHandle u, |
96 int arrayCount, | 110 int arrayCount, |
97 const GrGLfloat v[]) const { | 111 const GrGLfloat v[]) const { |
98 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 112 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
99 SkASSERT(uni.fType == kVec2f_GrSLType); | 113 SkASSERT(uni.fType == kVec2f_GrSLType); |
100 SkASSERT(arrayCount > 0); | 114 SkASSERT(arrayCount > 0); |
101 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 115 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
102 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 116 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
103 if (kUnusedUniform != uni.fFSLocation) { | 117 if (kUnusedUniform != uni.fFSLocation) { |
104 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount,
v)); | 118 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount,
v)); |
105 } | 119 } |
106 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 120 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
107 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount,
v)); | 121 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount,
v)); |
108 } | 122 } |
109 } | 123 } |
110 | 124 |
111 void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1,
GrGLfloat v2) const { | 125 void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1,
GrGLfloat v2) const { |
112 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 126 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
113 SkASSERT(uni.fType == kVec3f_GrSLType); | 127 SkASSERT(uni.fType == kVec3f_GrSLType); |
114 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 128 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
115 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 129 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
116 if (kUnusedUniform != uni.fFSLocation) { | 130 if (kUnusedUniform != uni.fFSLocation) { |
117 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); | 131 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); |
118 } | 132 } |
119 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 133 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
120 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); | 134 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); |
121 } | 135 } |
122 } | 136 } |
123 | 137 |
124 void GrGLProgramDataManager::set3fv(UniformHandle u, | 138 void GrGLProgramDataManager::set3fv(UniformHandle u, |
125 int arrayCount, | 139 int arrayCount, |
126 const GrGLfloat v[]) const { | 140 const GrGLfloat v[]) const { |
127 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 141 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
128 SkASSERT(uni.fType == kVec3f_GrSLType); | 142 SkASSERT(uni.fType == kVec3f_GrSLType); |
129 SkASSERT(arrayCount > 0); | 143 SkASSERT(arrayCount > 0); |
130 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 144 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
131 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 145 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
132 if (kUnusedUniform != uni.fFSLocation) { | 146 if (kUnusedUniform != uni.fFSLocation) { |
133 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount,
v)); | 147 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount,
v)); |
134 } | 148 } |
135 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 149 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
136 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount,
v)); | 150 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount,
v)); |
137 } | 151 } |
138 } | 152 } |
139 | 153 |
140 void GrGLProgramDataManager::set4f(UniformHandle u, | 154 void GrGLProgramDataManager::set4f(UniformHandle u, |
141 GrGLfloat v0, | 155 GrGLfloat v0, |
142 GrGLfloat v1, | 156 GrGLfloat v1, |
143 GrGLfloat v2, | 157 GrGLfloat v2, |
144 GrGLfloat v3) const { | 158 GrGLfloat v3) const { |
145 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 159 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
146 SkASSERT(uni.fType == kVec4f_GrSLType); | 160 SkASSERT(uni.fType == kVec4f_GrSLType); |
147 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 161 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
148 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 162 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
149 if (kUnusedUniform != uni.fFSLocation) { | 163 if (kUnusedUniform != uni.fFSLocation) { |
150 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v
3)); | 164 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v
3)); |
151 } | 165 } |
152 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 166 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
153 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v
3)); | 167 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v
3)); |
154 } | 168 } |
155 } | 169 } |
156 | 170 |
157 void GrGLProgramDataManager::set4fv(UniformHandle u, | 171 void GrGLProgramDataManager::set4fv(UniformHandle u, |
158 int arrayCount, | 172 int arrayCount, |
159 const GrGLfloat v[]) const { | 173 const GrGLfloat v[]) const { |
160 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 174 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
161 SkASSERT(uni.fType == kVec4f_GrSLType); | 175 SkASSERT(uni.fType == kVec4f_GrSLType); |
162 SkASSERT(arrayCount > 0); | 176 SkASSERT(arrayCount > 0); |
163 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 177 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
164 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 178 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
165 if (kUnusedUniform != uni.fFSLocation) { | 179 if (kUnusedUniform != uni.fFSLocation) { |
166 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount,
v)); | 180 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount,
v)); |
167 } | 181 } |
168 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 182 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
169 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount,
v)); | 183 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount,
v)); |
170 } | 184 } |
171 } | 185 } |
172 | 186 |
173 void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix
[]) const { | 187 void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix
[]) const { |
174 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 188 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
175 SkASSERT(uni.fType == kMat33f_GrSLType); | 189 SkASSERT(uni.fType == kMat33f_GrSLType); |
176 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 190 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
177 // TODO: Re-enable this assert once texture matrices aren't forced on all ef
fects | 191 // TODO: Re-enable this assert once texture matrices aren't forced on all ef
fects |
178 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); | 192 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); |
179 if (kUnusedUniform != uni.fFSLocation) { | 193 if (kUnusedUniform != uni.fFSLocation) { |
180 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, fal
se, matrix)); | 194 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, fal
se, matrix)); |
181 } | 195 } |
182 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 196 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
183 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, fal
se, matrix)); | 197 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, fal
se, matrix)); |
184 } | 198 } |
185 } | 199 } |
186 | 200 |
187 void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix
[]) const { | 201 void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix
[]) const { |
188 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 202 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
189 SkASSERT(uni.fType == kMat44f_GrSLType); | 203 SkASSERT(uni.fType == kMat44f_GrSLType); |
190 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 204 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
191 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 205 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
192 if (kUnusedUniform != uni.fFSLocation) { | 206 if (kUnusedUniform != uni.fFSLocation) { |
193 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, fal
se, matrix)); | 207 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, fal
se, matrix)); |
194 } | 208 } |
195 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 209 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
196 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, fal
se, matrix)); | 210 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, fal
se, matrix)); |
197 } | 211 } |
198 } | 212 } |
199 | 213 |
200 void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, | 214 void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, |
201 int arrayCount, | 215 int arrayCount, |
202 const GrGLfloat matrices[]) const { | 216 const GrGLfloat matrices[]) const { |
203 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 217 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
204 SkASSERT(uni.fType == kMat33f_GrSLType); | 218 SkASSERT(uni.fType == kMat33f_GrSLType); |
205 SkASSERT(arrayCount > 0); | 219 SkASSERT(arrayCount > 0); |
206 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 220 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
207 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 221 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
208 if (kUnusedUniform != uni.fFSLocation) { | 222 if (kUnusedUniform != uni.fFSLocation) { |
209 GR_GL_CALL(fGpu->glInterface(), | 223 GR_GL_CALL(fGpu->glInterface(), |
210 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices
)); | 224 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices
)); |
211 } | 225 } |
212 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 226 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
213 GR_GL_CALL(fGpu->glInterface(), | 227 GR_GL_CALL(fGpu->glInterface(), |
214 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices
)); | 228 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices
)); |
215 } | 229 } |
216 } | 230 } |
217 | 231 |
218 void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, | 232 void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, |
219 int arrayCount, | 233 int arrayCount, |
220 const GrGLfloat matrices[]) const { | 234 const GrGLfloat matrices[]) const { |
221 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 235 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
222 SkASSERT(uni.fType == kMat44f_GrSLType); | 236 SkASSERT(uni.fType == kMat44f_GrSLType); |
223 SkASSERT(arrayCount > 0); | 237 SkASSERT(arrayCount > 0); |
224 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 238 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
225 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 239 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
226 if (kUnusedUniform != uni.fFSLocation) { | 240 if (kUnusedUniform != uni.fFSLocation) { |
227 GR_GL_CALL(fGpu->glInterface(), | 241 GR_GL_CALL(fGpu->glInterface(), |
228 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices
)); | 242 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices
)); |
229 } | 243 } |
230 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 244 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
231 GR_GL_CALL(fGpu->glInterface(), | 245 GR_GL_CALL(fGpu->glInterface(), |
232 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices
)); | 246 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices
)); |
233 } | 247 } |
234 } | 248 } |
235 | 249 |
236 void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix
) const { | 250 void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix
) const { |
237 GrGLfloat mt[] = { | 251 GrGLfloat mt[] = { |
238 matrix.get(SkMatrix::kMScaleX), | 252 matrix.get(SkMatrix::kMScaleX), |
239 matrix.get(SkMatrix::kMSkewY), | 253 matrix.get(SkMatrix::kMSkewY), |
240 matrix.get(SkMatrix::kMPersp0), | 254 matrix.get(SkMatrix::kMPersp0), |
241 matrix.get(SkMatrix::kMSkewX), | 255 matrix.get(SkMatrix::kMSkewX), |
242 matrix.get(SkMatrix::kMScaleY), | 256 matrix.get(SkMatrix::kMScaleY), |
243 matrix.get(SkMatrix::kMPersp1), | 257 matrix.get(SkMatrix::kMPersp1), |
244 matrix.get(SkMatrix::kMTransX), | 258 matrix.get(SkMatrix::kMTransX), |
245 matrix.get(SkMatrix::kMTransY), | 259 matrix.get(SkMatrix::kMTransY), |
246 matrix.get(SkMatrix::kMPersp2), | 260 matrix.get(SkMatrix::kMPersp2), |
247 }; | 261 }; |
248 this->setMatrix3f(u, mt); | 262 this->setMatrix3f(u, mt); |
249 } | 263 } |
250 | |
251 | |
252 void GrGLProgramDataManager::getUniformLocations(GrGLuint programID, const Build
erUniformArray& uniforms) { | |
253 SkASSERT(uniforms.count() == fUniforms.count()); | |
254 int count = fUniforms.count(); | |
255 for (int i = 0; i < count; ++i) { | |
256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); | |
257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCou
nt); | |
258 GrGLint location; | |
259 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he
re. | |
260 if (fUsingBindUniform) { | |
261 location = i; | |
262 GR_GL_CALL(fGpu->glInterface(), | |
263 BindUniformLocation(programID, location, uniforms[i].fVar
iable.c_str())); | |
264 } else { | |
265 GR_GL_CALL_RET(fGpu->glInterface(), location, | |
266 GetUniformLocation(programID, uniforms[i].fVariable.c_str
())); | |
267 } | |
268 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { | |
269 fUniforms[i].fVSLocation = location; | |
270 } | |
271 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { | |
272 fUniforms[i].fFSLocation = location; | |
273 } | |
274 } | |
275 } | |
276 | |
277 const GrGLProgramDataManager::BuilderUniform& | |
278 GrGLProgramDataManager::getBuilderUniform(const BuilderUniformArray& array, Unif
ormHandle handle) const { | |
279 return array[handle.toUniformIndex()]; | |
280 } | |
OLD | NEW |