GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGpuGL* gpu, GrGLUniformManager& uniformManager, const GrGLProgramDesc& desc) : INHERITED(gpu, uniformManager, desc) , fDesc(desc) , fVSAttrs(kVarsPerBlock) , fVSOutputs(kVarsPerBlock) , fGSInputs(kVarsPerBlock) , fGSOutputs(kVarsPerBlock) { const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); fPositionVar = &fVSAttrs.push_back(); fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aPosition"); if (-1 != header.fLocalCoordAttributeIndex) { fLocalCoordsVar = &fVSAttrs.push_back(); fLocalCoordsVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aLocalCoords"); } else { fLocalCoordsVar = fPositionVar; } const char* viewMName; fViewMatrixUniform = this->addUniform(GrGLShaderBuilder::kVertex_Visibility, kMat33f_GrSLType, "ViewM", &viewMName); this->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n", viewMName, fPositionVar->c_str()); // we output point size in the GS if present if (header.fEmitsPointSize #if GR_GL_EXPERIMENTAL_GS && !header.fExperimentalGS #endif ) { this->vsCodeAppend("\tgl_PointSize = 1.0;\n"); } if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) { this->addAttribute(kVec4f_GrSLType, color_attribute_name()); const char *vsName, *fsName; this->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); this->vsCodeAppendf("\t%s = %s;\n", vsName, color_attribute_name()); this->setInputColor(fsName); } if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) { this->addAttribute(kVec4f_GrSLType, coverage_attribute_name()); const char *vsName, *fsName; this->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); this->vsCodeAppendf("\t%s = %s;\n", vsName, coverage_attribute_name()); this->setInputCoverage(fsName); } }
void GrGLVertexShaderBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage) { const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader(); fPositionVar = &fInputs.push_back(); fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "inPosition"); if (-1 != header.fLocalCoordAttributeIndex) { fLocalCoordsVar = &fInputs.push_back(); fLocalCoordsVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "inLocalCoords"); } else { fLocalCoordsVar = fPositionVar; } const char* viewMName; fProgramBuilder->fUniformHandles.fViewMatrixUni = fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, kMat33f_GrSLType, "ViewM", &viewMName); // Transform the position into Skia's device coords. this->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", viewMName, fPositionVar->c_str()); // we output point size in the GS if present if (header.fEmitsPointSize #if GR_GL_EXPERIMENTAL_GS && !header.fExperimentalGS #endif ) { this->codeAppend("gl_PointSize = 1.0;"); } if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) { this->addAttribute(GrShaderVar(color_attribute_name(), kVec4f_GrSLType, GrShaderVar::kAttribute_TypeModifier)); const char *vsName, *fsName; fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); this->codeAppendf("%s = %s;", vsName, color_attribute_name()); *color = fsName; } if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) { this->addAttribute(GrShaderVar(coverage_attribute_name(), kVec4f_GrSLType, GrShaderVar::kAttribute_TypeModifier)); const char *vsName, *fsName; fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); this->codeAppendf("%s = %s;", vsName, coverage_attribute_name()); *coverage = fsName; } fEffectAttribOffset = fInputs.count(); }
void GrGLFullShaderBuilder::bindProgramLocations(GrGLuint programId) { this->INHERITED::bindProgramLocations(programId); const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); // Bind the attrib locations to same values for all shaders SkASSERT(-1 != header.fPositionAttributeIndex); GL_CALL(BindAttribLocation(programId, header.fPositionAttributeIndex, fPositionVar->c_str())); if (-1 != header.fLocalCoordAttributeIndex) { GL_CALL(BindAttribLocation(programId, header.fLocalCoordAttributeIndex, fLocalCoordsVar->c_str())); } if (-1 != header.fColorAttributeIndex) { GL_CALL(BindAttribLocation(programId, header.fColorAttributeIndex, color_attribute_name())); } if (-1 != header.fCoverageAttributeIndex) { GL_CALL(BindAttribLocation(programId, header.fCoverageAttributeIndex, coverage_attribute_name())); } const AttributePair* attribEnd = fEffectAttributes.end(); for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attribEnd; ++attrib) { GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_str())); } }
void GrGLVertexShaderBuilder::bindProgramLocations(GrGLuint programId) { const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader(); GrGpuGL* gpu = fProgramBuilder->gpu(); // Bind the attrib locations to same values for all shaders SkASSERT(-1 != header.fPositionAttributeIndex); GL_CALL(BindAttribLocation(programId, header.fPositionAttributeIndex, fPositionVar->c_str())); if (-1 != header.fLocalCoordAttributeIndex) { GL_CALL(BindAttribLocation(programId, header.fLocalCoordAttributeIndex, fLocalCoordsVar->c_str())); } if (-1 != header.fColorAttributeIndex) { GL_CALL(BindAttribLocation(programId, header.fColorAttributeIndex, color_attribute_name())); } if (-1 != header.fCoverageAttributeIndex) { GL_CALL(BindAttribLocation(programId, header.fCoverageAttributeIndex, coverage_attribute_name())); } // We pull the current state of attributes off of drawstate's optimized state and bind them in // order. This assumes that the drawState has not changed since we called flushGraphicsState() // higher up in the stack. const GrDrawTargetCaps* caps = fProgramBuilder->gpu()->caps(); const GrDrawState& drawState = *fProgramBuilder->gpu()->drawState(); SkAutoTUnref<GrOptDrawState> optState(drawState.createOptState(*caps)); const GrVertexAttrib* vaPtr = optState->getVertexAttribs(); const int vaCount = optState->getVertexAttribCount(); int i = fEffectAttribOffset; for (int index = 0; index < vaCount; index++) { if (kGeometryProcessor_GrVertexAttribBinding != vaPtr[index].fBinding) { continue; } SkASSERT(index != header.fPositionAttributeIndex && index != header.fLocalCoordAttributeIndex && index != header.fColorAttributeIndex && index != header.fCoverageAttributeIndex); // We should never find another effect attribute if we have bound everything SkASSERT(i < fInputs.count()); GL_CALL(BindAttribLocation(programId, index, fInputs[i].c_str())); i++; } // Make sure we bound everything SkASSERT(fInputs.count() == i); }