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