| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
| 9 | 9 |
| 10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 fGpu->bindTexture(samplers[s].fTextureUnit, | 124 fGpu->bindTexture(samplers[s].fTextureUnit, |
| 125 textureAccess.getParams(), | 125 textureAccess.getParams(), |
| 126 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; | 126 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 132 | 132 |
| 133 void GrGLProgram::setData(const GrOptDrawState& optState) { | 133 void GrGLProgram::setData(const GrOptDrawState& optState) { |
| 134 GrColor color = optState.getColor(); | |
| 135 uint8_t coverage = optState.getCoverage(); | |
| 136 | |
| 137 this->setColor(optState, color); | |
| 138 this->setCoverage(optState, coverage); | |
| 139 this->setMatrixAndRenderTargetHeight(optState); | 134 this->setMatrixAndRenderTargetHeight(optState); |
| 140 | 135 |
| 141 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); | 136 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); |
| 142 if (dstCopy) { | 137 if (dstCopy) { |
| 143 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 138 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
| 144 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 139 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
| 145 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 140 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
| 146 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 141 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
| 147 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 142 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
| 148 1.f / dstCopy->texture()->width(), | 143 1.f / dstCopy->texture()->width(), |
| 149 1.f / dstCopy->texture()->height()); | 144 1.f / dstCopy->texture()->height()); |
| 150 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 145 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
| 151 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. | 146 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. |
| 152 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); | 147 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
| 153 } else { | 148 } else { |
| 154 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 149 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
| 155 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 150 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
| 156 } | 151 } |
| 157 } else { | 152 } else { |
| 158 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); | 153 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
| 159 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 154 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
| 160 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 155 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
| 161 } | 156 } |
| 162 | 157 |
| 163 // we set the textures, and uniforms for installed processors in a generic w
ay, but subclasses | 158 // we set the textures, and uniforms for installed processors in a generic w
ay, but subclasses |
| 164 // of GLProgram determine how to set coord transforms | 159 // of GLProgram determine how to set coord transforms |
| 165 if (fGeometryProcessor.get()) { | 160 const GrPrimitiveProcessor& primProc = *optState.getPrimitiveProcessor(); |
| 166 SkASSERT(optState.hasGeometryProcessor()); | 161 const GrBatchTracker& bt = optState.getBatchTracker(); |
| 167 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); | 162 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, bt); |
| 168 const GrBatchTracker& bt = optState.getBatchTracker(); | 163 this->bindTextures(fGeometryProcessor, primProc); |
| 169 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp, bt); | 164 |
| 170 this->bindTextures(fGeometryProcessor, gp); | |
| 171 } | |
| 172 if (fXferProcessor.get()) { | 165 if (fXferProcessor.get()) { |
| 173 const GrXferProcessor& xp = *optState.getXferProcessor(); | 166 const GrXferProcessor& xp = *optState.getXferProcessor(); |
| 174 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); | 167 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); |
| 175 this->bindTextures(fXferProcessor, xp); | 168 this->bindTextures(fXferProcessor, xp); |
| 176 } | 169 } |
| 177 this->setFragmentData(optState); | 170 this->setFragmentData(optState); |
| 178 | 171 |
| 179 // Some of GrGLProgram subclasses need to update state here | 172 // Some of GrGLProgram subclasses need to update state here |
| 180 this->didSetData(optState.drawType()); | 173 this->didSetData(optState.drawType()); |
| 181 } | 174 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 202 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | 195 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); |
| 203 transforms[t].fCurrentValue = matrix; | 196 transforms[t].fCurrentValue = matrix; |
| 204 } | 197 } |
| 205 } | 198 } |
| 206 } | 199 } |
| 207 | 200 |
| 208 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 201 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
| 209 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 202 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
| 210 } | 203 } |
| 211 | 204 |
| 212 void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { | |
| 213 const GrProgramDesc::KeyHeader& header = fDesc.header(); | |
| 214 switch (header.fColorInput) { | |
| 215 case GrProgramDesc::kAttribute_ColorInput: | |
| 216 // Attribute case is handled in GrGpuGL::setupGeometry | |
| 217 break; | |
| 218 case GrProgramDesc::kUniform_ColorInput: | |
| 219 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { | |
| 220 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m | |
| 221 GrGLfloat c[4]; | |
| 222 GrColorToRGBAFloat(color, c); | |
| 223 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1,
c); | |
| 224 fColor = color; | |
| 225 } | |
| 226 break; | |
| 227 case GrProgramDesc::kAllOnes_ColorInput: | |
| 228 // Handled by shader creation | |
| 229 break; | |
| 230 default: | |
| 231 SkFAIL("Unexpected color type."); | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage)
{ | |
| 236 const GrProgramDesc::KeyHeader& header = fDesc.header(); | |
| 237 switch (header.fCoverageInput) { | |
| 238 case GrProgramDesc::kAttribute_ColorInput: | |
| 239 // Attribute case is handled in GrGpuGL::setupGeometry | |
| 240 break; | |
| 241 case GrProgramDesc::kUniform_ColorInput: | |
| 242 if (fCoverage != coverage) { | |
| 243 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m | |
| 244 GrGLfloat c = GrNormalizeByteToFloat(coverage); | |
| 245 fProgramDataManager.set1f(fBuiltinUniformHandles.fCoverageUni, c
); | |
| 246 fCoverage = coverage; | |
| 247 } | |
| 248 break; | |
| 249 case GrProgramDesc::kAllOnes_ColorInput: | |
| 250 // Handled by shader creation | |
| 251 break; | |
| 252 default: | |
| 253 SkFAIL("Unexpected coverage type."); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState)
{ | 205 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState)
{ |
| 258 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 206 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| 259 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 207 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
| 260 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { | 208 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { |
| 261 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 209 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
| 262 SkIntToScalar(optState.getRenderTarget()->hei
ght())); | 210 SkIntToScalar(optState.getRenderTarget()->hei
ght())); |
| 263 } | 211 } |
| 264 | 212 |
| 265 // call subclasses to set the actual view matrix | 213 // call subclasses to set the actual view matrix |
| 266 this->onSetMatrixAndRenderTargetHeight(optState); | 214 this->onSetMatrixAndRenderTargetHeight(optState); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 289 } | 237 } |
| 290 } | 238 } |
| 291 | 239 |
| 292 ////////////////////////////////////////////////////////////////////////////////
///////// | 240 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 293 | 241 |
| 294 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, | 242 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, |
| 295 const GrProgramDesc& desc, | 243 const GrProgramDesc& desc, |
| 296 const BuiltinUniformHandles& builtinUni
forms, | 244 const BuiltinUniformHandles& builtinUni
forms, |
| 297 GrGLuint programID, | 245 GrGLuint programID, |
| 298 const UniformInfoArray& uniforms, | 246 const UniformInfoArray& uniforms, |
| 247 GrGLInstalledGeoProc* primProc, |
| 299 GrGLInstalledXferProc* xferProcessor, | 248 GrGLInstalledXferProc* xferProcessor, |
| 300 GrGLInstalledFragProcs* fragmentProcess
ors) | 249 GrGLInstalledFragProcs* fragmentProcess
ors) |
| 301 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, | 250 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, |
| 302 xferProcessor, fragmentProcessors) { | 251 xferProcessor, fragmentProcessors) { |
| 303 } | 252 } |
| 304 | 253 |
| 305 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState&
optState) { | 254 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState&
optState) { |
| 306 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType())); | 255 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType())); |
| 307 const GrRenderTarget* rt = optState.getRenderTarget(); | 256 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 308 SkISize size; | 257 SkISize size; |
| 309 size.set(rt->width(), rt->height()); | 258 size.set(rt->width(), rt->height()); |
| 310 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); | 259 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); |
| 311 } | 260 } |
| 312 | 261 |
| 313 ////////////////////////////////////////////////////////////////////////////////
///////// | 262 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 314 | 263 |
| 315 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, | 264 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, |
| 316 const GrProgramDesc& desc, | 265 const GrProgramDesc& desc, |
| 317 const BuiltinUniformHandles& builtinUniforms, | 266 const BuiltinUniformHandles& builtinUniforms, |
| 318 GrGLuint programID, | 267 GrGLuint programID, |
| 319 const UniformInfoArray& uniforms, | 268 const UniformInfoArray& uniforms, |
| 269 GrGLInstalledGeoProc* primProc, |
| 320 GrGLInstalledXferProc* xferProcessor, | 270 GrGLInstalledXferProc* xferProcessor, |
| 321 GrGLInstalledFragProcs* fragmentProcessors, | 271 GrGLInstalledFragProcs* fragmentProcessors, |
| 322 const SeparableVaryingInfoArray& separableVaryi
ngs) | 272 const SeparableVaryingInfoArray& separableVaryi
ngs) |
| 323 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, | 273 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, |
| 324 xferProcessor, fragmentProcessors) { | 274 xferProcessor, fragmentProcessors) { |
| 325 int count = separableVaryings.count(); | 275 int count = separableVaryings.count(); |
| 326 fVaryings.push_back_n(count); | 276 fVaryings.push_back_n(count); |
| 327 for (int i = 0; i < count; i++) { | 277 for (int i = 0; i < count; i++) { |
| 328 Varying& varying = fVaryings[i]; | 278 Varying& varying = fVaryings[i]; |
| 329 const SeparableVaryingInfo& builderVarying = separableVaryings[i]; | 279 const SeparableVaryingInfo& builderVarying = separableVaryings[i]; |
| 330 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo
unt()); | 280 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo
unt()); |
| 331 SkDEBUGCODE( | 281 SkDEBUGCODE( |
| 332 varying.fType = builderVarying.fVariable.getType(); | 282 varying.fType = builderVarying.fVariable.getType(); |
| 333 ); | 283 ); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 362 } | 312 } |
| 363 } | 313 } |
| 364 | 314 |
| 365 ////////////////////////////////////////////////////////////////////////////////
////// | 315 ////////////////////////////////////////////////////////////////////////////////
////// |
| 366 | 316 |
| 367 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, | 317 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, |
| 368 const GrProgramDesc& desc, | 318 const GrProgramDesc& desc, |
| 369 const BuiltinUniformHandles& builti
nUniforms, | 319 const BuiltinUniformHandles& builti
nUniforms, |
| 370 GrGLuint programID, | 320 GrGLuint programID, |
| 371 const UniformInfoArray& uniforms, | 321 const UniformInfoArray& uniforms, |
| 322 GrGLInstalledGeoProc* primProc, |
| 372 GrGLInstalledXferProc* xp, | 323 GrGLInstalledXferProc* xp, |
| 373 GrGLInstalledFragProcs* fps, | 324 GrGLInstalledFragProcs* fps, |
| 374 int texCoordSetCnt) | 325 int texCoordSetCnt) |
| 375 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, xp, fps) | 326 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, xp, f
ps) |
| 376 , fTexCoordSetCnt(texCoordSetCnt) { | 327 , fTexCoordSetCnt(texCoordSetCnt) { |
| 377 } | 328 } |
| 378 | 329 |
| 379 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | 330 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 380 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 331 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 381 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 332 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 382 } | 333 } |
| 383 | 334 |
| 384 void | 335 void |
| 385 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, | 336 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 386 GrGLInstalledFragProc* ip) { | 337 GrGLInstalledFragProc* ip) { |
| 387 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | 338 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect |
| 388 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); | 339 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| 389 int numTransforms = proc.getProcessor()->numTransforms(); | 340 int numTransforms = proc.getProcessor()->numTransforms(); |
| 390 for (int t = 0; t < numTransforms; ++t) { | 341 for (int t = 0; t < numTransforms; ++t) { |
| 391 const SkMatrix& transform = get_transform_matrix(proc, t); | 342 const SkMatrix& transform = get_transform_matrix(proc, t); |
| 392 GrGLPathRendering::PathTexGenComponents components = | 343 GrGLPathRendering::PathTexGenComponents components = |
| 393 GrGLPathRendering::kST_PathTexGenComponents; | 344 GrGLPathRendering::kST_PathTexGenComponents; |
| 394 if (proc.isPerspectiveCoordTransform(t)) { | 345 if (proc.isPerspectiveCoordTransform(t)) { |
| 395 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 346 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 396 } | 347 } |
| 397 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 348 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
| 398 } | 349 } |
| 399 } | 350 } |
| OLD | NEW |