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 "GrAllocator.h" | 10 #include "GrAllocator.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 : fGpu(gpu) | 39 : fGpu(gpu) |
| 40 , fUniformManager(gpu) | 40 , fUniformManager(gpu) |
| 41 , fHasVertexShader(false) | 41 , fHasVertexShader(false) |
| 42 , fNumTexCoordSets(0) { | 42 , fNumTexCoordSets(0) { |
| 43 fDesc = desc; | 43 fDesc = desc; |
| 44 fProgramID = 0; | 44 fProgramID = 0; |
| 45 | 45 |
| 46 fDstCopyTexUnit = -1; | 46 fDstCopyTexUnit = -1; |
| 47 | 47 |
| 48 fColor = GrColor_ILLEGAL; | 48 fColor = GrColor_ILLEGAL; |
| 49 | 49 |
|
robertphillips
2014/05/28 20:08:46
Does it make sense to have a GenProgramOutput in t
bsalomon
2014/05/28 20:09:50
Maybe... I'm working on the next cleanup CL now.
| |
| 50 if (fDesc.getHeader().fHasVertexCode || | 50 GrGLShaderBuilder::GenProgramOutput output; |
| 51 !fGpu->shouldUseFixedFunctionTexturing()) { | 51 |
| 52 GrGLFullShaderBuilder fullBuilder(fGpu, fUniformManager, fDesc); | 52 if (GrGLShaderBuilder::GenProgram(gpu, fUniformManager, desc, colorStages, c overageStages, |
| 53 if (this->genProgram(&fullBuilder, colorStages, coverageStages)) { | 53 &output)) { |
| 54 fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUniform(); | 54 fProgramID = output.fProgramID; |
| 55 fUniformHandles.fRTAdjustmentUni = fullBuilder.getRTAdjustmentVecUni form(); | 55 fUniformHandles = output.fUniformHandles; |
| 56 fHasVertexShader = true; | 56 fColorEffects.reset(output.fColorEffects); |
| 57 } | 57 fCoverageEffects.reset(output.fCoverageEffects); |
| 58 } else { | 58 fHasVertexShader = output.fHasVS; |
| 59 GrGLFragmentOnlyShaderBuilder fragmentOnlyBuilder(fGpu, fUniformManager, fDesc); | 59 fNumTexCoordSets = output.fNumTexCoordSets; |
| 60 if (this->genProgram(&fragmentOnlyBuilder, colorStages, coverageStages)) { | 60 fGpu = gpu; |
| 61 fNumTexCoordSets = fragmentOnlyBuilder.getNumTexCoordSets(); | 61 this->initSamplerUniforms(); |
| 62 } | |
| 63 } | 62 } |
| 64 } | 63 } |
| 65 | 64 |
| 66 GrGLProgram::~GrGLProgram() { | 65 GrGLProgram::~GrGLProgram() { |
| 67 if (fProgramID) { | 66 if (fProgramID) { |
| 68 GL_CALL(DeleteProgram(fProgramID)); | 67 GL_CALL(DeleteProgram(fProgramID)); |
| 69 } | 68 } |
| 70 } | 69 } |
| 71 | 70 |
| 72 void GrGLProgram::abandon() { | 71 void GrGLProgram::abandon() { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 88 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: | 87 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: |
| 89 // We should only have set this if the blend was specified as (1, 0) | 88 // We should only have set this if the blend was specified as (1, 0) |
| 90 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff); | 89 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff); |
| 91 break; | 90 break; |
| 92 default: | 91 default: |
| 93 SkFAIL("Unexpected coverage output"); | 92 SkFAIL("Unexpected coverage output"); |
| 94 break; | 93 break; |
| 95 } | 94 } |
| 96 } | 95 } |
| 97 | 96 |
| 98 bool GrGLProgram::genProgram(GrGLShaderBuilder* builder, | |
| 99 const GrEffectStage* colorStages[], | |
| 100 const GrEffectStage* coverageStages[]) { | |
| 101 SkASSERT(0 == fProgramID); | |
| 102 | |
| 103 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | |
| 104 | |
| 105 // incoming color to current stage being processed. | |
| 106 GrGLSLExpr4 inColor = builder->getInputColor(); | |
| 107 | |
| 108 fColorEffects.reset( | |
| 109 builder->createAndEmitEffects(colorStages, | |
| 110 fDesc.effectKeys(), | |
| 111 fDesc.numColorEffects(), | |
| 112 &inColor)); | |
| 113 | |
| 114 /////////////////////////////////////////////////////////////////////////// | |
| 115 // compute the partial coverage | |
| 116 GrGLSLExpr4 inCoverage = builder->getInputCoverage(); | |
| 117 | |
| 118 fCoverageEffects.reset( | |
| 119 builder->createAndEmitEffects(coverageStages, | |
| 120 fDesc.getEffectKeys() + fDesc.numColorEffe cts(), | |
| 121 fDesc.numCoverageEffects(), | |
| 122 &inCoverage)); | |
| 123 | |
| 124 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) { | |
| 125 const char* secondaryOutputName = builder->enableSecondaryOutput(); | |
| 126 | |
| 127 // default coeff to ones for kCoverage_DualSrcOutput | |
| 128 GrGLSLExpr4 coeff(1); | |
| 129 if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == header.fCov erageOutput) { | |
| 130 // Get (1-A) into coeff | |
| 131 coeff = GrGLSLExpr4::VectorCast(GrGLSLExpr1(1) - inColor.a()); | |
| 132 } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == head er.fCoverageOutput) { | |
| 133 // Get (1-RGBA) into coeff | |
| 134 coeff = GrGLSLExpr4(1) - inColor; | |
| 135 } | |
| 136 // Get coeff * coverage into modulate and then write that to the dual so urce output. | |
| 137 builder->fsCodeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inC overage).c_str()); | |
| 138 } | |
| 139 | |
| 140 /////////////////////////////////////////////////////////////////////////// | |
| 141 // combine color and coverage as frag color | |
| 142 | |
| 143 // Get "color * coverage" into fragColor | |
| 144 GrGLSLExpr4 fragColor = inColor * inCoverage; | |
| 145 // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so. | |
| 146 if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutpu t) { | |
| 147 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inCoverage; | |
| 148 | |
| 149 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(builder->dstColor() ); | |
| 150 | |
| 151 fragColor = fragColor + dstContribution; | |
| 152 } | |
| 153 builder->fsCodeAppendf("\t%s = %s;\n", builder->getColorOutputName(), fragCo lor.c_str()); | |
| 154 | |
| 155 if (!builder->finish(&fProgramID)) { | |
| 156 return false; | |
| 157 } | |
| 158 | |
| 159 fUniformHandles.fRTHeightUni = builder->getRTHeightUniform(); | |
| 160 fUniformHandles.fDstCopyTopLeftUni = builder->getDstCopyTopLeftUniform(); | |
| 161 fUniformHandles.fDstCopyScaleUni = builder->getDstCopyScaleUniform(); | |
| 162 fUniformHandles.fColorUni = builder->getColorUniform(); | |
| 163 fUniformHandles.fCoverageUni = builder->getCoverageUniform(); | |
| 164 fUniformHandles.fDstCopySamplerUni = builder->getDstCopySamplerUniform(); | |
| 165 // This must be called after we set fDstCopySamplerUni above. | |
| 166 this->initSamplerUniforms(); | |
| 167 | |
| 168 return true; | |
| 169 } | |
| 170 | |
| 171 void GrGLProgram::initSamplerUniforms() { | 97 void GrGLProgram::initSamplerUniforms() { |
| 172 GL_CALL(UseProgram(fProgramID)); | 98 GL_CALL(UseProgram(fProgramID)); |
| 173 GrGLint texUnitIdx = 0; | 99 GrGLint texUnitIdx = 0; |
| 174 if (fUniformHandles.fDstCopySamplerUni.isValid()) { | 100 if (fUniformHandles.fDstCopySamplerUni.isValid()) { |
| 175 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId x); | 101 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId x); |
| 176 fDstCopyTexUnit = texUnitIdx++; | 102 fDstCopyTexUnit = texUnitIdx++; |
| 177 } | 103 } |
| 178 fColorEffects->initSamplers(fUniformManager, &texUnitIdx); | 104 fColorEffects->initSamplers(fUniformManager, &texUnitIdx); |
| 179 fCoverageEffects->initSamplers(fUniformManager, &texUnitIdx); | 105 fCoverageEffects->initSamplers(fUniformManager, &texUnitIdx); |
| 180 } | 106 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 | 269 |
| 344 GrGLfloat viewMatrix[3 * 3]; | 270 GrGLfloat viewMatrix[3 * 3]; |
| 345 fMatrixState.getGLMatrix<3>(viewMatrix); | 271 fMatrixState.getGLMatrix<3>(viewMatrix); |
| 346 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); | 272 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); |
| 347 | 273 |
| 348 GrGLfloat rtAdjustmentVec[4]; | 274 GrGLfloat rtAdjustmentVec[4]; |
| 349 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 275 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
| 350 fUniformManager.set4fv(fUniformHandles.fRTAdjustmentUni, 1, rtAdjustment Vec); | 276 fUniformManager.set4fv(fUniformHandles.fRTAdjustmentUni, 1, rtAdjustment Vec); |
| 351 } | 277 } |
| 352 } | 278 } |
| OLD | NEW |