| 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 "builders/GrGLFullProgramBuilder.h" |
| 11 #include "builders/GrGLFragmentOnlyProgramBuilder.h" |
| 10 #include "GrAllocator.h" | 12 #include "GrAllocator.h" |
| 11 #include "GrProcessor.h" | 13 #include "GrProcessor.h" |
| 12 #include "GrCoordTransform.h" | 14 #include "GrCoordTransform.h" |
| 13 #include "GrGLProcessor.h" | 15 #include "GrGLProcessor.h" |
| 14 #include "GrGpuGL.h" | 16 #include "GrGpuGL.h" |
| 15 #include "GrGLPathRendering.h" | 17 #include "GrGLPathRendering.h" |
| 16 #include "GrGLShaderVar.h" | 18 #include "GrGLShaderVar.h" |
| 17 #include "GrGLSL.h" | 19 #include "GrGLSL.h" |
| 18 #include "GrOptDrawState.h" | 20 #include "GrOptDrawState.h" |
| 19 #include "SkXfermode.h" | 21 #include "SkXfermode.h" |
| 20 | 22 |
| 21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 23 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 24 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
| 23 | 25 |
| 24 /** | 26 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, |
| 25 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. | 27 const GrOptDrawState& optState, |
| 26 */ | 28 const GrGLProgramDesc& desc, |
| 27 static SkMatrix get_transform_matrix(const GrProcessorStage& processorStage, | 29 const GrGeometryStage* geometryProcessor, |
| 28 bool useExplicitLocalCoords, | 30 const GrFragmentStage* colorStages[], |
| 29 int transformIdx) { | 31 const GrFragmentStage* coverageStages[]) { |
| 30 const GrCoordTransform& coordTransform = | 32 SkAutoTDelete<GrGLProgramBuilder> builder; |
| 31 processorStage.getProcessor()->coordTransform(transformIdx); | 33 if (desc.getHeader().fUseFragShaderOnly) { |
| 32 SkMatrix combined; | 34 SkASSERT(gpu->glCaps().pathRenderingSupport()); |
| 33 | 35 SkASSERT(gpu->glPathRendering()->texturingMode() == |
| 34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 36 GrGLPathRendering::FixedFunction_TexturingMode); |
| 35 // If we have explicit local coords then we shouldn't need a coord chang
e. | 37 SkASSERT(NULL == geometryProcessor); |
| 36 const SkMatrix& ccm = | 38 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyProgramBuilder, (gpu, optState,
desc))); |
| 37 useExplicitLocalCoords ? SkMatrix::I() : processorStage.getCoord
ChangeMatrix(); | |
| 38 combined.setConcat(coordTransform.getMatrix(), ccm); | |
| 39 } else { | 39 } else { |
| 40 combined = coordTransform.getMatrix(); | 40 builder.reset(SkNEW_ARGS(GrGLFullProgramBuilder, (gpu, optState, desc)))
; |
| 41 } | 41 } |
| 42 if (coordTransform.reverseY()) { | 42 if (builder->genProgram(geometryProcessor, colorStages, coverageStages)) { |
| 43 // combined.postScale(1,-1); | 43 SkASSERT(0 != builder->getProgramID()); |
| 44 // combined.postTranslate(0,1); | 44 return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder)); |
| 45 combined.set(SkMatrix::kMSkewY, | |
| 46 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | |
| 47 combined.set(SkMatrix::kMScaleY, | |
| 48 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); | |
| 49 combined.set(SkMatrix::kMTransY, | |
| 50 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); | |
| 51 } | 45 } |
| 52 return combined; | 46 return NULL; |
| 53 } | 47 } |
| 54 | 48 |
| 55 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
| 56 | |
| 57 GrGLProgram::GrGLProgram(GrGpuGL* gpu, | 49 GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
| 58 const GrGLProgramDesc& desc, | 50 const GrGLProgramDesc& desc, |
| 59 const BuiltinUniformHandles& builtinUniforms, | 51 const GrGLProgramBuilder& builder) |
| 60 GrGLuint programID, | |
| 61 const UniformInfoArray& uniforms, | |
| 62 GrGLInstalledProcessors* geometryProcessor, | |
| 63 GrGLInstalledProcessors* colorProcessors, | |
| 64 GrGLInstalledProcessors* coverageProcessors) | |
| 65 : fColor(GrColor_ILLEGAL) | 52 : fColor(GrColor_ILLEGAL) |
| 66 , fCoverage(GrColor_ILLEGAL) | 53 , fCoverage(GrColor_ILLEGAL) |
| 67 , fDstCopyTexUnit(-1) | 54 , fDstCopyTexUnit(-1) |
| 68 , fBuiltinUniformHandles(builtinUniforms) | 55 , fBuiltinUniformHandles(builder.getBuiltinUniformHandles()) |
| 69 , fProgramID(programID) | 56 , fGeometryProcessor(SkSafeRef(builder.getGeometryProcessor())) |
| 70 , fGeometryProcessor(SkSafeRef(geometryProcessor)) | 57 , fColorEffects(SkRef(builder.getColorEffects())) |
| 71 , fColorEffects(SkRef(colorProcessors)) | 58 , fCoverageEffects(SkRef(builder.getCoverageEffects())) |
| 72 , fCoverageEffects(SkRef(coverageProcessors)) | 59 , fProgramID(builder.getProgramID()) |
| 60 , fHasVertexShader(builder.hasVertexShader()) |
| 61 , fTexCoordSetCnt(builder.getTexCoordSetCount()) |
| 73 , fDesc(desc) | 62 , fDesc(desc) |
| 74 , fGpu(gpu) | 63 , fGpu(gpu) |
| 75 , fProgramDataManager(gpu, uniforms) { | 64 , fProgramDataManager(gpu, this, builder) { |
| 76 this->initSamplerUniforms(); | 65 this->initSamplerUniforms(); |
| 77 } | 66 } |
| 78 | 67 |
| 79 GrGLProgram::~GrGLProgram() { | 68 GrGLProgram::~GrGLProgram() { |
| 80 if (fProgramID) { | 69 if (fProgramID) { |
| 81 GL_CALL(DeleteProgram(fProgramID)); | 70 GL_CALL(DeleteProgram(fProgramID)); |
| 82 } | 71 } |
| 83 } | 72 } |
| 84 | 73 |
| 85 void GrGLProgram::abandon() { | 74 void GrGLProgram::abandon() { |
| 86 fProgramID = 0; | 75 fProgramID = 0; |
| 87 } | 76 } |
| 88 | 77 |
| 89 void GrGLProgram::initSamplerUniforms() { | 78 void GrGLProgram::initSamplerUniforms() { |
| 90 GL_CALL(UseProgram(fProgramID)); | 79 GL_CALL(UseProgram(fProgramID)); |
| 91 GrGLint texUnitIdx = 0; | 80 GrGLint texUnitIdx = 0; |
| 92 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { | 81 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { |
| 93 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni
, texUnitIdx); | 82 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni
, texUnitIdx); |
| 94 fDstCopyTexUnit = texUnitIdx++; | 83 fDstCopyTexUnit = texUnitIdx++; |
| 95 } | 84 } |
| 96 if (fGeometryProcessor.get()) { | 85 if (fGeometryProcessor.get()) { |
| 97 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx); | 86 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); |
| 98 } | 87 } |
| 99 this->initSamplers(fColorEffects.get(), &texUnitIdx); | 88 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
| 100 this->initSamplers(fCoverageEffects.get(), &texUnitIdx); | 89 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
| 101 } | 90 } |
| 102 | 91 |
| 103 void GrGLProgram::initSamplers(GrGLInstalledProcessors* ip, int* texUnitIdx) { | |
| 104 int numEffects = ip->fGLProcessors.count(); | |
| 105 SkASSERT(numEffects == ip->fSamplers.count()); | |
| 106 for (int e = 0; e < numEffects; ++e) { | |
| 107 SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSample
rs[e]; | |
| 108 int numSamplers = samplers.count(); | |
| 109 for (int s = 0; s < numSamplers; ++s) { | |
| 110 SkASSERT(samplers[s].fUniform.isValid()); | |
| 111 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); | |
| 112 samplers[s].fTextureUnit = (*texUnitIdx)++; | |
| 113 } | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 void GrGLProgram::bindTextures(const GrGLInstalledProcessors* ip, | |
| 118 const GrProcessor& processor, | |
| 119 int effectIdx) { | |
| 120 const SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSamp
lers[effectIdx]; | |
| 121 int numSamplers = samplers.count(); | |
| 122 SkASSERT(numSamplers == processor.numTextures()); | |
| 123 for (int s = 0; s < numSamplers; ++s) { | |
| 124 SkASSERT(samplers[s].fTextureUnit >= 0); | |
| 125 const GrTextureAccess& textureAccess = processor.textureAccess(s); | |
| 126 fGpu->bindTexture(samplers[s].fTextureUnit, | |
| 127 textureAccess.getParams(), | |
| 128 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 | |
| 133 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
| 134 | 93 |
| 135 void GrGLProgram::setData(const GrOptDrawState& optState, | 94 void GrGLProgram::setData(const GrOptDrawState& optState, |
| 136 GrGpu::DrawType drawType, | 95 GrGpu::DrawType drawType, |
| 137 const GrGeometryStage* geometryProcessor, | 96 const GrGeometryStage* geometryProcessor, |
| 138 const GrFragmentStage* colorStages[], | 97 const GrFragmentStage* colorStages[], |
| 139 const GrFragmentStage* coverageStages[], | 98 const GrFragmentStage* coverageStages[], |
| 140 const GrDeviceCoordTexture* dstCopy, | 99 const GrDeviceCoordTexture* dstCopy, |
| 141 SharedGLState* sharedState) { | 100 SharedGLState* sharedState) { |
| 142 GrColor color = optState.getColor(); | 101 GrColor color = optState.getColor(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 160 } else { | 119 } else { |
| 161 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 120 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
| 162 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 121 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
| 163 } | 122 } |
| 164 } else { | 123 } else { |
| 165 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); | 124 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
| 166 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 125 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
| 167 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 126 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
| 168 } | 127 } |
| 169 | 128 |
| 170 // we set the textures, and uniforms for installed processors in a generic w
ay, but subclasses | |
| 171 // of GLProgram determine how to set coord transforms | |
| 172 if (fGeometryProcessor.get()) { | 129 if (fGeometryProcessor.get()) { |
| 173 SkASSERT(geometryProcessor); | 130 SkASSERT(geometryProcessor); |
| 174 this->setData<GrGeometryStage>(&geometryProcessor, fGeometryProcessor.ge
t()); | 131 fGeometryProcessor->setData(fGpu, drawType, fProgramDataManager, geometr
yProcessor); |
| 175 } | 132 } |
| 176 this->setData<GrFragmentStage>(colorStages, fColorEffects.get()); | 133 fColorEffects->setData(fGpu, drawType, fProgramDataManager, colorStages); |
| 177 this->setData<GrFragmentStage>(coverageStages, fCoverageEffects.get()); | 134 fCoverageEffects->setData(fGpu, drawType, fProgramDataManager, coverageStage
s); |
| 178 | 135 |
| 179 // Some of GrGLProgram subclasses need to update state here | 136 // PathTexGen state applies to the the fixed function vertex shader. For |
| 180 this->didSetData(drawType); | 137 // custom shaders, it's ignored, so we don't need to change the texgen |
| 181 } | 138 // settings in that case. |
| 182 | 139 if (!fHasVertexShader) { |
| 183 void GrGLProgram::setTransformData(const GrProcessorStage& processor, | 140 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 184 int effectIdx, | |
| 185 GrGLInstalledProcessors* ip) { | |
| 186 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf
orms[effectIdx]; | |
| 187 int numTransforms = transforms.count(); | |
| 188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | |
| 189 for (int t = 0; t < numTransforms; ++t) { | |
| 190 SkASSERT(transforms[t].fHandle.isValid()); | |
| 191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fHasExplici
tLocalCoords, t); | |
| 192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | |
| 193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | |
| 194 transforms[t].fCurrentValue = matrix; | |
| 195 } | |
| 196 } | 141 } |
| 197 } | 142 } |
| 198 | 143 |
| 199 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | |
| 200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | |
| 201 } | |
| 202 | |
| 203 void GrGLProgram::setColor(const GrOptDrawState& optState, | 144 void GrGLProgram::setColor(const GrOptDrawState& optState, |
| 204 GrColor color, | 145 GrColor color, |
| 205 SharedGLState* sharedState) { | 146 SharedGLState* sharedState) { |
| 206 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 147 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 207 if (!optState.hasColorVertexAttribute()) { | 148 if (!optState.hasColorVertexAttribute()) { |
| 208 switch (header.fColorInput) { | 149 switch (header.fColorInput) { |
| 209 case GrGLProgramDesc::kAttribute_ColorInput: | 150 case GrGLProgramDesc::kAttribute_ColorInput: |
| 210 SkASSERT(-1 != header.fColorAttributeIndex); | 151 SkASSERT(-1 != header.fColorAttributeIndex); |
| 211 if (sharedState->fConstAttribColor != color || | 152 if (sharedState->fConstAttribColor != color || |
| 212 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { | 153 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 default: | 213 default: |
| 273 SkFAIL("Unexpected coverage type."); | 214 SkFAIL("Unexpected coverage type."); |
| 274 } | 215 } |
| 275 } else { | 216 } else { |
| 276 sharedState->fConstAttribCoverageIndex = -1; | 217 sharedState->fConstAttribCoverageIndex = -1; |
| 277 } | 218 } |
| 278 } | 219 } |
| 279 | 220 |
| 280 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 221 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| 281 const GrOptDrawState& optState)
{ | 222 const GrOptDrawState& optState)
{ |
| 282 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | |
| 283 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | |
| 284 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->wi
dth()) { | |
| 285 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | |
| 286 SkIntToScalar(optState.getRenderTarget()->hei
ght())); | |
| 287 } | |
| 288 | |
| 289 // call subclasses to set the actual view matrix | |
| 290 this->onSetMatrixAndRenderTargetHeight(drawType, optState); | |
| 291 } | |
| 292 | |
| 293 void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | |
| 294 const GrOptDrawState& optStat
e) { | |
| 295 const GrRenderTarget* rt = optState.getRenderTarget(); | 223 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 296 SkISize size; | 224 SkISize size; |
| 297 size.set(rt->width(), rt->height()); | 225 size.set(rt->width(), rt->height()); |
| 298 if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 226 |
| 299 fMatrixState.fRenderTargetSize != size || | 227 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| 300 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) { | 228 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
| 229 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
| 230 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
| 231 SkIntToScalar(size.fHeight)); |
| 232 } |
| 233 |
| 234 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
| 235 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s
ize, rt->origin()); |
| 236 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
| 237 fMatrixState.fRenderTargetSize != size || |
| 238 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix()))
{ |
| 301 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); | 239 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); |
| 302 | 240 |
| 303 fMatrixState.fViewMatrix = optState.getViewMatrix(); | 241 fMatrixState.fViewMatrix = optState.getViewMatrix(); |
| 304 fMatrixState.fRenderTargetSize = size; | 242 fMatrixState.fRenderTargetSize = size; |
| 305 fMatrixState.fRenderTargetOrigin = rt->origin(); | 243 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 306 | 244 |
| 307 GrGLfloat viewMatrix[3 * 3]; | 245 GrGLfloat viewMatrix[3 * 3]; |
| 308 fMatrixState.getGLMatrix<3>(viewMatrix); | 246 fMatrixState.getGLMatrix<3>(viewMatrix); |
| 309 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); | 247 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); |
| 310 | 248 |
| 311 GrGLfloat rtAdjustmentVec[4]; | 249 GrGLfloat rtAdjustmentVec[4]; |
| 312 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 250 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
| 313 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 251 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
| 314 } | 252 } |
| 315 } | 253 } |
| 316 | |
| 317 ////////////////////////////////////////////////////////////////////////////////
///////// | |
| 318 | |
| 319 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, | |
| 320 const GrGLProgramDesc& desc, | |
| 321 const BuiltinUniformHandles& builtinUni
forms, | |
| 322 GrGLuint programID, | |
| 323 const UniformInfoArray& uniforms, | |
| 324 GrGLInstalledProcessors* colorProcessor
s, | |
| 325 GrGLInstalledProcessors* coverageProces
sors) | |
| 326 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, colorProc
essors, | |
| 327 coverageProcessors) { | |
| 328 } | |
| 329 | |
| 330 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT
ype, | |
| 331 const GrOptDrawState&
optState) { | |
| 332 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | |
| 333 const GrRenderTarget* rt = optState.getRenderTarget(); | |
| 334 SkISize size; | |
| 335 size.set(rt->width(), rt->height()); | |
| 336 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); | |
| 337 } | |
| 338 | |
| 339 ////////////////////////////////////////////////////////////////////////////////
///////// | |
| 340 | |
| 341 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, | |
| 342 const GrGLProgramDesc& desc, | |
| 343 const BuiltinUniformHandles& builtinUniforms, | |
| 344 GrGLuint programID, | |
| 345 const UniformInfoArray& uniforms, | |
| 346 GrGLInstalledProcessors* colorProcessors, | |
| 347 GrGLInstalledProcessors* coverageProcessors, | |
| 348 const SeparableVaryingInfoArray& separableVaryi
ngs) | |
| 349 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors
, | |
| 350 coverageProcessors) { | |
| 351 int count = separableVaryings.count(); | |
| 352 fVaryings.push_back_n(count); | |
| 353 for (int i = 0; i < count; i++) { | |
| 354 Varying& varying = fVaryings[i]; | |
| 355 const SeparableVaryingInfo& builderVarying = separableVaryings[i]; | |
| 356 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo
unt()); | |
| 357 SkDEBUGCODE( | |
| 358 varying.fType = builderVarying.fVariable.getType(); | |
| 359 ); | |
| 360 varying.fLocation = builderVarying.fLocation; | |
| 361 } | |
| 362 } | |
| 363 | |
| 364 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { | |
| 365 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | |
| 366 } | |
| 367 | |
| 368 void GrGLNvprProgram::setTransformData(const GrProcessorStage& processor, | |
| 369 int effectIdx, | |
| 370 GrGLInstalledProcessors* ip) { | |
| 371 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf
orms[effectIdx]; | |
| 372 int numTransforms = transforms.count(); | |
| 373 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | |
| 374 for (int t = 0; t < numTransforms; ++t) { | |
| 375 SkASSERT(transforms[t].fHandle.isValid()); | |
| 376 const SkMatrix& transform = get_transform_matrix(processor, ip->fHasExpl
icitLocalCoords, t); | |
| 377 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | |
| 378 continue; | |
| 379 } | |
| 380 transforms[t].fCurrentValue = transform; | |
| 381 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()]
; | |
| 382 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType =
= kVec3f_GrSLType); | |
| 383 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; | |
| 384 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID
, | |
| 385 fragmentIn
put.fLocation, | |
| 386 GR_GL_OBJE
CT_LINEAR, | |
| 387 components
, | |
| 388 transform)
; | |
| 389 } | |
| 390 } | |
| 391 | |
| 392 ////////////////////////////////////////////////////////////////////////////////
////// | |
| 393 | |
| 394 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, | |
| 395 const GrGLProgramDesc& desc, | |
| 396 const BuiltinUniformHandles& builtinUniforms, | |
| 397 GrGLuint programID, | |
| 398 const UniformInfoArray& uniforms, | |
| 399 GrGLInstalledProcessors* colorProcessors, | |
| 400 GrGLInstalledProcessors* coverageProcessors, | |
| 401 int texCoordSetCnt) | |
| 402 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors
, | |
| 403 coverageProcessors) | |
| 404 , fTexCoordSetCnt(texCoordSetCnt) { | |
| 405 } | |
| 406 | |
| 407 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | |
| 408 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | |
| 409 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | |
| 410 } | |
| 411 | |
| 412 void GrGLLegacyNvprProgram::setTransformData(const GrProcessorStage& processorSt
age, | |
| 413 int effectIdx, | |
| 414 GrGLInstalledProcessors* ip) { | |
| 415 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | |
| 416 int texCoordIndex = ip->fTransforms[effectIdx][0].fHandle.handle(); | |
| 417 int numTransforms = processorStage.getProcessor()->numTransforms(); | |
| 418 for (int t = 0; t < numTransforms; ++t) { | |
| 419 const SkMatrix& transform = get_transform_matrix(processorStage, false,
t); | |
| 420 GrGLPathRendering::PathTexGenComponents components = | |
| 421 GrGLPathRendering::kST_PathTexGenComponents; | |
| 422 if (processorStage.isPerspectiveCoordTransform(t, false)) { | |
| 423 components = GrGLPathRendering::kSTR_PathTexGenComponents; | |
| 424 } | |
| 425 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | |
| 426 } | |
| 427 } | |
| OLD | NEW |