diff options
author | 2014-08-03 23:19:46 -0700 | |
---|---|---|
committer | 2014-08-03 23:19:46 -0700 | |
commit | dddc18a6bba67ad43a65f4c244b95f76cefef617 (patch) | |
tree | 1b8d92d9ccf0f454f847797c5756e5f486478425 /src/gpu/gl/GrGLProgram.cpp | |
parent | 7883132a4e93c8b5e897e271603d3b7122655a51 (diff) |
Make GrGLProgram be available to GrGLProgramDataManager
GL APIs such as glProgramPathFragmentInputGenNV need the explicit program id in
order to set the program resources. For GrGLProgramDataManager to call the APIs,
the program id needs to be available to the GrGLProgramDataManager.
One GrGLProgramDataManager is used to explicitly manage the resources of one
GrGLProgram. Refactor the classes to reflect this: make GrGLProgram create and
own GrGLProgramDataManager. This way the program id can be made available through
GrGLProgram backpointer.
In order to do this, remove the population of the program link results
information for uniforms in GrGLProgramDataManager during shader generation.
Instead, accumulate the info to the uniform list of GrGLShaderBuilder. After the
generation, compilation and link is successful, this info can be used to
construct both GrGLProgram and GrGLProgramDataManager.
Changes names of functions to create UniformHandles and convert them to list
indices. This tries to highlight that they're different lists, even though at
the moment they match index-wise. E.g the contract is that handles can be
created based on the shader builder state, and the object can later be set with
the handle and the manager that was created with the builder.
This is needed to support NV_path_rendering for GLES.
R=bsalomon@google.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/426553011
Diffstat (limited to 'src/gpu/gl/GrGLProgram.cpp')
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 90 |
1 files changed, 49 insertions, 41 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 82b859e86d..0ad7a18756 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -24,38 +24,46 @@ GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, const GrGLProgramDesc& desc, const GrEffectStage* colorStages[], const GrEffectStage* coverageStages[]) { - GrGLShaderBuilder::GenProgramOutput output; - SkAutoTUnref<GrGLProgramDataManager> pdman(SkNEW_ARGS(GrGLProgramDataManager, (gpu))); - if (GrGLShaderBuilder::GenProgram(gpu, pdman, desc, colorStages, coverageStages, - &output)) { - SkASSERT(0 != output.fProgramID); - return SkNEW_ARGS(GrGLProgram, (gpu, desc, pdman, output)); + SkAutoTDelete<GrGLShaderBuilder> builder; + if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing()) { + builder.reset(SkNEW_ARGS(GrGLFullShaderBuilder, (gpu, desc))); + } else { + builder.reset(SkNEW_ARGS(GrGLFragmentOnlyShaderBuilder, (gpu, desc))); + } + + if (builder->genProgram(colorStages, coverageStages)) { + SkASSERT(0 != builder->getProgramID()); + return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder)); } return NULL; } GrGLProgram::GrGLProgram(GrGpuGL* gpu, const GrGLProgramDesc& desc, - GrGLProgramDataManager* pdman, - const GrGLShaderBuilder::GenProgramOutput& builderOutput) + const GrGLShaderBuilder& builder) : fColor(GrColor_ILLEGAL) , fCoverage(GrColor_ILLEGAL) , fDstCopyTexUnit(-1) - , fBuilderOutput(builderOutput) + , fBuiltinUniformHandles(builder.getBuiltinUniformHandles()) + , fColorEffects(SkRef(builder.getColorEffects())) + , fCoverageEffects(SkRef(builder.getCoverageEffects())) + , fProgramID(builder.getProgramID()) + , fHasVertexShader(builder.hasVertexShader()) + , fTexCoordSetCnt(builder.getTexCoordSetCount()) , fDesc(desc) , fGpu(gpu) - , fProgramDataManager(SkRef(pdman)) { + , fProgramDataManager(gpu, this, builder) { this->initSamplerUniforms(); } GrGLProgram::~GrGLProgram() { - if (fBuilderOutput.fProgramID) { - GL_CALL(DeleteProgram(fBuilderOutput.fProgramID)); + if (fProgramID) { + GL_CALL(DeleteProgram(fProgramID)); } } void GrGLProgram::abandon() { - fBuilderOutput.fProgramID = 0; + fProgramID = 0; } void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, @@ -81,14 +89,14 @@ void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, } void GrGLProgram::initSamplerUniforms() { - GL_CALL(UseProgram(fBuilderOutput.fProgramID)); + GL_CALL(UseProgram(fProgramID)); GrGLint texUnitIdx = 0; - if (fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { - fProgramDataManager->setSampler(fBuilderOutput.fUniformHandles.fDstCopySamplerUni, texUnitIdx); + if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { + fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni, texUnitIdx); fDstCopyTexUnit = texUnitIdx++; } - fBuilderOutput.fColorEffects->initSamplers(*fProgramDataManager, &texUnitIdx); - fBuilderOutput.fCoverageEffects->initSamplers(*fProgramDataManager, &texUnitIdx); + fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); + fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); } /////////////////////////////////////////////////////////////////////////////// @@ -118,35 +126,35 @@ void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, this->setMatrixAndRenderTargetHeight(drawState); if (NULL != dstCopy) { - if (fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid()) { - fProgramDataManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni, + if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { + fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, static_cast<GrGLfloat>(dstCopy->offset().fX), static_cast<GrGLfloat>(dstCopy->offset().fY)); - fProgramDataManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyScaleUni, + fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, 1.f / dstCopy->texture()->width(), 1.f / dstCopy->texture()->height()); GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()); static GrTextureParams kParams; // the default is clamp, nearest filtering. fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); } else { - SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid()); - SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()); + SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); + SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); } } else { - SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid()); - SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid()); - SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()); + SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); + SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); + SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); } - fBuilderOutput.fColorEffects->setData(fGpu, *fProgramDataManager, colorStages); - fBuilderOutput.fCoverageEffects->setData(fGpu, *fProgramDataManager, coverageStages); + fColorEffects->setData(fGpu, fProgramDataManager, colorStages); + fCoverageEffects->setData(fGpu, fProgramDataManager, coverageStages); // PathTexGen state applies to the the fixed function vertex shader. For // custom shaders, it's ignored, so we don't need to change the texgen // settings in that case. - if (!fBuilderOutput.fHasVertexShader) { - fGpu->flushPathTexGenSettings(fBuilderOutput.fTexCoordSetCnt); + if (!fHasVertexShader) { + fGpu->flushPathTexGenSettings(fTexCoordSetCnt); } } @@ -169,11 +177,11 @@ void GrGLProgram::setColor(const GrDrawState& drawState, } break; case GrGLProgramDesc::kUniform_ColorInput: - if (fColor != color && fBuilderOutput.fUniformHandles.fColorUni.isValid()) { + if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { // OpenGL ES doesn't support unsigned byte varieties of glUniform GrGLfloat c[4]; GrColorToRGBAFloat(color, c); - fProgramDataManager->set4fv(fBuilderOutput.fUniformHandles.fColorUni, 1, c); + fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c); fColor = color; } sharedState->fConstAttribColorIndex = -1; @@ -208,7 +216,7 @@ void GrGLProgram::setCoverage(const GrDrawState& drawState, // OpenGL ES doesn't support unsigned byte varieties of glUniform GrGLfloat c[4]; GrColorToRGBAFloat(coverage, c); - fProgramDataManager->set4fv(fBuilderOutput.fUniformHandles.fCoverageUni, 1, c); + fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni, 1, c); fCoverage = coverage; } sharedState->fConstAttribCoverageIndex = -1; @@ -230,20 +238,20 @@ void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { size.set(rt->width(), rt->height()); // Load the RT height uniform if it is needed to y-flip gl_FragCoord. - if (fBuilderOutput.fUniformHandles.fRTHeightUni.isValid() && + if (fBuiltinUniformHandles.fRTHeightUni.isValid() && fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { - fProgramDataManager->set1f(fBuilderOutput.fUniformHandles.fRTHeightUni, + fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, SkIntToScalar(size.fHeight)); } - if (!fBuilderOutput.fHasVertexShader) { - SkASSERT(!fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid()); - SkASSERT(!fBuilderOutput.fUniformHandles.fRTAdjustmentUni.isValid()); + if (!fHasVertexShader) { + SkASSERT(!fBuiltinUniformHandles.fViewMatrixUni.isValid()); + SkASSERT(!fBuiltinUniformHandles.fRTAdjustmentUni.isValid()); fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()); } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || fMatrixState.fRenderTargetSize != size || !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix())) { - SkASSERT(fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid()); + SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); fMatrixState.fViewMatrix = drawState.getViewMatrix(); fMatrixState.fRenderTargetSize = size; @@ -251,10 +259,10 @@ void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { GrGLfloat viewMatrix[3 * 3]; fMatrixState.getGLMatrix<3>(viewMatrix); - fProgramDataManager->setMatrix3f(fBuilderOutput.fUniformHandles.fViewMatrixUni, viewMatrix); + fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix); GrGLfloat rtAdjustmentVec[4]; fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); - fProgramDataManager->set4fv(fBuilderOutput.fUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); + fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); } } |