Chromium Code Reviews| Index: src/gpu/glsl/GrGLSLVarying.cpp |
| diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp |
| index 279dd5937e92a911b67891012a93cde96895b4f3..0e98c37013e479d5b2db94450db51a91d54219ff 100644 |
| --- a/src/gpu/glsl/GrGLSLVarying.cpp |
| +++ b/src/gpu/glsl/GrGLSLVarying.cpp |
| @@ -9,11 +9,47 @@ |
| #include "glsl/GrGLSLProgramBuilder.h" |
| +void GrGLSLVaryingHandler::setNoPerspective() { |
| + const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| + if (!caps.noperspectiveInterpolationSupport()) { |
| + return; |
| + } |
| + if (fNoPerspective) { |
| + return; // This method has already been called previously. |
| + } |
| + if (const char* extension = caps.noperspectiveInterpolationExtensionString()) { |
| + int bit = 1 << GrGLSLFragmentShaderBuilder::kNoPerspectiveInterpolation_GLSLPrivateFeature; |
| + fProgramBuilder->fVS.addFeature(bit, extension); |
| + fProgramBuilder->fGS.addFeature(bit, extension); |
| + fProgramBuilder->fFS.addFeature(bit, extension); |
| + } |
| + for (int i = 0; i < fVaryingShaderVars.count(); ++i) { |
| + if (!fVaryingShaderVars[i].fIsFlat) { |
| + fVaryingShaderVars[i].addModifier("noperspective"); |
|
egdaniel
2016/02/10 14:23:44
I recently added a finalize method to GrGLSLVaryin
Chris Dalton
2016/02/10 15:29:30
Ok that sounds great. onFinalize does sound like a
|
| + } |
| + } |
| + fNoPerspective = true; |
| +} |
| + |
| void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::Attribute* input, |
| - const char* output) { |
| + const char* output, GrSLPrecision precision) { |
| GrSLType type = GrVertexAttribTypeToSLType(input->fType); |
| GrGLSLVertToFrag v(type); |
| - this->addVarying(input->fName, &v); |
| + this->addVarying(input->fName, &v, precision); |
| + this->writePassThroughAttribute(input, output, v); |
| +} |
| + |
| +void GrGLSLVaryingHandler::addFlatPassThroughAttribute(const GrGeometryProcessor::Attribute* input, |
| + const char* output, |
| + GrSLPrecision precision) { |
| + GrSLType type = GrVertexAttribTypeToSLType(input->fType); |
| + GrGLSLVertToFrag v(type); |
| + this->addFlatVarying(input->fName, &v, precision); |
| + this->writePassThroughAttribute(input, output, v); |
| +} |
| + |
| +void GrGLSLVaryingHandler::writePassThroughAttribute(const GrGeometryProcessor::Attribute* input, |
| + const char* output, const GrGLSLVarying& v) { |
| fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName); |
| if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| @@ -23,64 +59,55 @@ void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::At |
| fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn()); |
| } |
| -void GrGLSLVaryingHandler::addVarying(const char* name, |
| - GrGLSLVarying* varying, |
| - GrSLPrecision precision) { |
| +void GrGLSLVaryingHandler::internalAddVarying(const char* name, |
| + GrGLSLVarying* varying, |
| + GrSLPrecision precision, |
| + bool flat) { |
| SkASSERT(varying); |
| + VaryingShaderVars& v = fVaryingShaderVars.push_back(); |
| + |
| if (varying->vsVarying()) { |
| - this->addVertexVarying(name, precision, varying); |
| - } |
| - if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| - this->addGeomVarying(name, precision, varying); |
| + v.fVertexOutput.setType(varying->fType); |
| + v.fVertexOutput.setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); |
| + v.fVertexOutput.setPrecision(precision); |
| + fProgramBuilder->nameVariable(v.fVertexOutput.accessName(), 'v', name); |
| + varying->fVsOut = v.fVertexOutput.getName().c_str(); |
| + |
| + if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| + v.fGeomInput.setType(varying->fType); |
| + v.fGeomInput.setTypeModifier(GrGLSLShaderVar::kVaryingIn_TypeModifier); |
| + v.fGeomInput.setPrecision(precision); |
| + v.fGeomInput.setUnsizedArray(); |
| + *v.fGeomInput.accessName() = varying->fVsOut; |
| + varying->fGsIn = varying->fVsOut; |
| + } |
| } |
| + |
| if (varying->fsVarying()) { |
| - this->addFragVarying(precision, varying); |
| - } |
| -} |
| + if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| + v.fGeomOutput.setType(varying->fType); |
| + v.fGeomOutput.setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); |
| + v.fGeomOutput.setPrecision(precision); |
| + fProgramBuilder->nameVariable(v.fGeomOutput.accessName(), 'g', name); |
| + varying->fFsIn = varying->fGsOut = v.fGeomOutput.getName().c_str(); |
| + } else { |
| + varying->fFsIn = varying->fVsOut; |
| + } |
| -void GrGLSLVaryingHandler::addVertexVarying(const char* name, |
| - GrSLPrecision precision, |
| - GrGLSLVarying* v) { |
| - fVertexOutputs.push_back(); |
| - fVertexOutputs.back().setType(v->fType); |
| - fVertexOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); |
| - fVertexOutputs.back().setPrecision(precision); |
| - fProgramBuilder->nameVariable(fVertexOutputs.back().accessName(), 'v', name); |
| - v->fVsOut = fVertexOutputs.back().getName().c_str(); |
| -} |
| -void GrGLSLVaryingHandler::addGeomVarying(const char* name, |
| - GrSLPrecision precision, |
| - GrGLSLVarying* v) { |
| - // if we have a GS take each varying in as an array |
| - // and output as non-array. |
| - if (v->vsVarying()) { |
| - fGeomInputs.push_back(); |
| - fGeomInputs.back().setType(v->fType); |
| - fGeomInputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingIn_TypeModifier); |
| - fGeomInputs.back().setPrecision(precision); |
| - fGeomInputs.back().setUnsizedArray(); |
| - *fGeomInputs.back().accessName() = v->fVsOut; |
| - v->fGsIn = v->fVsOut; |
| + v.fFragInput.set(varying->fType, |
| + GrGLSLShaderVar::kVaryingIn_TypeModifier, |
| + varying->fFsIn, |
| + precision); |
| } |
| - if (v->fsVarying()) { |
| - fGeomOutputs.push_back(); |
| - fGeomOutputs.back().setType(v->fType); |
| - fGeomOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); |
| - fGeomOutputs.back().setPrecision(precision); |
| - fProgramBuilder->nameVariable(fGeomOutputs.back().accessName(), 'g', name); |
| - v->fGsOut = fGeomOutputs.back().getName().c_str(); |
| + v.fIsFlat = flat; |
| + if (v.fIsFlat) { |
| + v.addModifier("flat"); |
| + } else if (fNoPerspective) { |
| + v.addModifier("noperspective"); |
| } |
| } |
| -void GrGLSLVaryingHandler::addFragVarying(GrSLPrecision precision, GrGLSLVarying* v) { |
| - v->fFsIn = v->fGsOut ? v->fGsOut : v->fVsOut; |
| - fFragInputs.push_back().set(v->fType, |
| - GrGLSLShaderVar::kVaryingIn_TypeModifier, |
| - v->fFsIn, |
| - precision); |
| -} |
| - |
| void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) { |
| int vaCount = gp.numAttribs(); |
| for (int i = 0; i < vaCount; i++) { |
| @@ -105,7 +132,7 @@ void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) { |
| fVertexInputs.push_back(var); |
| } |
| -void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) const { |
| +void GrGLSLVaryingHandler::appendDecls(const ShaderVarList& vars, SkString* out) const { |
| for (int i = 0; i < vars.count(); ++i) { |
| vars[i].appendDecl(fProgramBuilder->glslCaps(), out); |
| out->append(";"); |
| @@ -114,19 +141,29 @@ void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) cons |
| void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* outputDecls) const { |
| this->appendDecls(fVertexInputs, inputDecls); |
| - this->appendDecls(fVertexOutputs, outputDecls); |
| + for (int i = 0; i < fVaryingShaderVars.count(); ++i) { |
| + fVaryingShaderVars[i].fVertexOutput.appendDecl(fProgramBuilder->glslCaps(), outputDecls); |
| + outputDecls->append(";"); |
| + } |
| } |
| void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDecls) const { |
| - this->appendDecls(fGeomInputs, inputDecls); |
| - this->appendDecls(fGeomOutputs, outputDecls); |
| + for (int i = 0; i < fVaryingShaderVars.count(); ++i) { |
| + fVaryingShaderVars[i].fGeomInput.appendDecl(fProgramBuilder->glslCaps(), outputDecls); |
| + outputDecls->append(";"); |
| + fVaryingShaderVars[i].fGeomOutput.appendDecl(fProgramBuilder->glslCaps(), outputDecls); |
| + outputDecls->append(";"); |
| + } |
| } |
| void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDecls) const { |
| // We should not have any outputs in the fragment shader when using version 1.10 |
| SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() || |
| fFragOutputs.empty()); |
| - this->appendDecls(fFragInputs, inputDecls); |
| + for (int i = 0; i < fVaryingShaderVars.count(); ++i) { |
| + fVaryingShaderVars[i].fFragInput.appendDecl(fProgramBuilder->glslCaps(), outputDecls); |
| + outputDecls->append(";"); |
| + } |
| this->appendDecls(fFragOutputs, outputDecls); |
| } |