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" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 matrix.get(SkMatrix::kMSkewX), | 241 matrix.get(SkMatrix::kMSkewX), |
242 matrix.get(SkMatrix::kMScaleY), | 242 matrix.get(SkMatrix::kMScaleY), |
243 matrix.get(SkMatrix::kMPersp1), | 243 matrix.get(SkMatrix::kMPersp1), |
244 matrix.get(SkMatrix::kMTransX), | 244 matrix.get(SkMatrix::kMTransX), |
245 matrix.get(SkMatrix::kMTransY), | 245 matrix.get(SkMatrix::kMTransY), |
246 matrix.get(SkMatrix::kMPersp2), | 246 matrix.get(SkMatrix::kMPersp2), |
247 }; | 247 }; |
248 this->setMatrix3f(u, mt); | 248 this->setMatrix3f(u, mt); |
249 } | 249 } |
250 | 250 |
| 251 void GrGLUniformManager::setFragmentInput(FragmentInputHandle i, size_t componen
ts, const SkMatrix& matrix) const { |
| 252 const FragmentInput& fragmentInput = fFragmentInputs[i.toLocationIndex()]; |
251 | 253 |
252 void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn
iformArray& uniforms) { | 254 GrGLfloat coefficients[3 * 3]; |
| 255 SkASSERT(components >= 1 && components <= 3); |
| 256 |
| 257 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
| 258 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
| 259 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
| 260 |
| 261 if (components >= 2) { |
| 262 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
| 263 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
| 264 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
| 265 } |
| 266 |
| 267 if (components >= 3) { |
| 268 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
| 269 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
| 270 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
| 271 } |
| 272 fGpu->setProgramPathFragmentInputGen(fragmentInput.fLocation, components, co
efficients); |
| 273 } |
| 274 |
| 275 |
| 276 void GrGLUniformManager::bindProgramResourceLocations( |
| 277 GrGLuint programID, |
| 278 const BuilderUniformArray& uniforms) { |
| 279 if (!fUsingBindUniform) { |
| 280 return; |
| 281 } |
253 SkASSERT(uniforms.count() == fUniforms.count()); | 282 SkASSERT(uniforms.count() == fUniforms.count()); |
254 int count = fUniforms.count(); | 283 int count = fUniforms.count(); |
255 for (int i = 0; i < count; ++i) { | 284 for (int i = 0; i < count; ++i) { |
256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); | 285 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); |
257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCou
nt); | 286 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. | 287 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he
re. |
260 if (fUsingBindUniform) { | 288 |
261 location = i; | 289 GR_GL_CALL(fGpu->glInterface(), |
262 GR_GL_CALL(fGpu->glInterface(), | 290 BindUniformLocation(programID, i, uniforms[i].fVariable.c_str
())); |
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) { | 291 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { |
269 fUniforms[i].fVSLocation = location; | 292 fUniforms[i].fVSLocation = i; |
270 } | 293 } |
271 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { | 294 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { |
272 fUniforms[i].fFSLocation = location; | 295 fUniforms[i].fFSLocation = i; |
273 } | 296 } |
274 } | 297 } |
275 } | 298 } |
| 299 |
| 300 void GrGLUniformManager::resolveProgramResourceLocations( |
| 301 GrGLuint programID, |
| 302 const BuilderUniformArray& uniforms, |
| 303 const BuilderFragmentInputArray& fragmentInputs) { |
| 304 if (!fUsingBindUniform) { |
| 305 SkASSERT(uniforms.count() == fUniforms.count()); |
| 306 int count = fUniforms.count(); |
| 307 for (int i = 0; i < count; ++i) { |
| 308 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); |
| 309 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArra
yCount); |
| 310 GrGLint location; |
| 311 // TODO: Move the Xoom uniform array in both FS and VS bug workaroun
d here. |
| 312 GR_GL_CALL_RET(fGpu->glInterface(), location, |
| 313 GetUniformLocation(programID, uniforms[i].fVariable.c
_str())); |
| 314 |
| 315 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility)
{ |
| 316 fUniforms[i].fVSLocation = location; |
| 317 } |
| 318 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibilit
y) { |
| 319 fUniforms[i].fFSLocation = location; |
| 320 } |
| 321 } |
| 322 } |
| 323 |
| 324 if (fGpu->glCaps().pathRenderingSupport()) { |
| 325 int count = fFragmentInputs.count(); |
| 326 SkASSERT(fragmentInputs.count() == fFragmentInputs.count()); |
| 327 for (int i = 0; i < count; ++i) { |
| 328 GrGLint location; |
| 329 GR_GL_CALL_RET(fGpu->glInterface(), location, |
| 330 GetProgramResourceLocation(programID, |
| 331 GR_GL_FRAGMENT_INPUT, |
| 332 fragmentInputs[i].c_str())
); |
| 333 fFragmentInputs[i].fLocation = location; |
| 334 } |
| 335 } |
| 336 } |
276 | 337 |
277 const GrGLUniformManager::BuilderUniform& | 338 const GrGLUniformManager::BuilderUniform& |
278 GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformH
andle handle) const { | 339 GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformH
andle handle) const { |
279 return array[handle.toUniformIndex()]; | 340 return array[handle.toUniformIndex()]; |
280 } | 341 } |
| 342 |
| 343 GrGLUniformManager::FragmentInputHandle GrGLUniformManager::appendFragmentInput(
) { |
| 344 int idx = fFragmentInputs.count(); |
| 345 fFragmentInputs.push_back(); |
| 346 return FragmentInputHandle::CreateFromFragmentInputIndex(idx); |
| 347 } |
OLD | NEW |