| Index: src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
|
| diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
|
| index 76026b7a25005509701e91a874837d72555fe81f..55ce7d14587b5d9045440fa51e54f7c0b5868aa1 100644
|
| --- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
|
| +++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
|
| @@ -6,25 +6,46 @@
|
| */
|
|
|
| #include "GrGLVertexShaderBuilder.h"
|
| -#include "GrGLProgramBuilder.h"
|
| +#include "GrGLFullProgramBuilder.h"
|
| #include "GrGLShaderStringBuilder.h"
|
| #include "../GrGpuGL.h"
|
| +#include "../../GrOptDrawState.h"
|
|
|
| -#define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X)
|
| -#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X)
|
| +#define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
|
| +#define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X)
|
|
|
| -static const char* color_attribute_name() { return "inColor"; }
|
| -static const char* coverage_attribute_name() { return "inCoverage"; }
|
| +namespace {
|
| +inline const char* color_attribute_name() { return "inColor"; }
|
| +inline const char* coverage_attribute_name() { return "inCoverage"; }
|
| +}
|
|
|
| -GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program)
|
| +GrGLVertexShaderBuilder::GrGLVertexShaderBuilder(GrGLFullProgramBuilder* program)
|
| : INHERITED(program)
|
| , fPositionVar(NULL)
|
| - , fLocalCoordsVar(NULL)
|
| - , fEffectAttribOffset(0) {
|
| + , fLocalCoordsVar(NULL) {
|
| +}
|
| +bool GrGLVertexShaderBuilder::addAttribute(const GrShaderVar& var) {
|
| + SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
|
| + for (int i = 0; i < fInputs.count(); ++i) {
|
| + const GrGLShaderVar& attr = fInputs[i];
|
| + // if attribute already added, don't add it again
|
| + if (attr.getName().equals(var.getName())) {
|
| + return false;
|
| + }
|
| + }
|
| + fInputs.push_back(var);
|
| + return true;
|
| }
|
|
|
| -SkString* GrGLVertexBuilder::addVarying(GrSLType type, const char* name,
|
| - const char** vsOutName) {
|
| +void GrGLVertexShaderBuilder::emitAttributes(const GrGeometryProcessor& gp) {
|
| + const GrGeometryProcessor::VertexAttribArray& vars = gp.getVertexAttribs();
|
| + int numAttributes = vars.count();
|
| + for (int a = 0; a < numAttributes; ++a) {
|
| + this->addAttribute(vars[a]);
|
| + }
|
| +}
|
| +
|
| +void GrGLVertexShaderBuilder::addVarying(GrSLType type, const char* name, const char** vsOutName) {
|
| fOutputs.push_back();
|
| fOutputs.back().setType(type);
|
| fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier);
|
| @@ -33,88 +54,30 @@
|
| if (vsOutName) {
|
| *vsOutName = fOutputs.back().getName().c_str();
|
| }
|
| - return fOutputs.back().accessName();
|
| }
|
|
|
| -void GrGLVertexBuilder::setupLocalCoords() {
|
| - fPositionVar = &fInputs.push_back();
|
| - fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "inPosition");
|
| - if (-1 != fProgramBuilder->header().fLocalCoordAttributeIndex) {
|
| - fLocalCoordsVar = &fInputs.push_back();
|
| - fLocalCoordsVar->set(kVec2f_GrSLType,
|
| - GrGLShaderVar::kAttribute_TypeModifier,
|
| - "inLocalCoords");
|
| - } else {
|
| - fLocalCoordsVar = fPositionVar;
|
| - }
|
| - fEffectAttribOffset = fInputs.count();
|
| -}
|
|
|
| -void GrGLVertexBuilder::transformGLToSkiaCoords() {
|
| - const char* viewMName;
|
| - fProgramBuilder->fUniformHandles.fViewMatrixUni =
|
| - fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
|
| - kMat33f_GrSLType,
|
| - "ViewM",
|
| - &viewMName);
|
| +void GrGLVertexShaderBuilder::bindProgramLocations(GrGLuint programId) {
|
| + const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader();
|
| + GrGpuGL* gpu = fProgramBuilder->gpu();
|
|
|
| - // Transform the position into Skia's device coords.
|
| - this->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", viewMName, fPositionVar->c_str());
|
| -}
|
| -
|
| -void GrGLVertexBuilder::setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr4* out) {
|
| - SkString name(inName);
|
| - const char *vsName, *fsName;
|
| - fProgramBuilder->addVarying(kVec4f_GrSLType, name.c_str(), &vsName, &fsName);
|
| - name.prepend("in");
|
| - this->addAttribute(GrShaderVar(name.c_str(),
|
| - kVec4f_GrSLType,
|
| - GrShaderVar::kAttribute_TypeModifier));
|
| - this->codeAppendf("%s = %s;", vsName, name.c_str());
|
| - *out = fsName;
|
| - fEffectAttribOffset++;
|
| -}
|
| -
|
| -void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
|
| - const GrGeometryProcessor::VertexAttribArray& vars = gp.getVertexAttribs();
|
| - int numAttributes = vars.count();
|
| - for (int a = 0; a < numAttributes; ++a) {
|
| - this->addAttribute(vars[a]);
|
| - }
|
| -}
|
| -
|
| -void GrGLVertexBuilder::transformSkiaToGLCoords() {
|
| - const char* rtAdjustName;
|
| - fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
|
| - fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
|
| - kVec4f_GrSLType,
|
| - "rtAdjustment",
|
| - &rtAdjustName);
|
| -
|
| - // Transform from Skia's device coords to GL's normalized device coords.
|
| - this->codeAppendf("gl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3.z);",
|
| - rtAdjustName, rtAdjustName);
|
| -}
|
| -
|
| -void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) {
|
| // Bind the attrib locations to same values for all shaders
|
| - const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->header();
|
| SkASSERT(-1 != header.fPositionAttributeIndex);
|
| - GL_CALL(BindAttribLocation(programID,
|
| + GL_CALL(BindAttribLocation(programId,
|
| header.fPositionAttributeIndex,
|
| fPositionVar->c_str()));
|
| if (-1 != header.fLocalCoordAttributeIndex) {
|
| - GL_CALL(BindAttribLocation(programID,
|
| + GL_CALL(BindAttribLocation(programId,
|
| header.fLocalCoordAttributeIndex,
|
| fLocalCoordsVar->c_str()));
|
| }
|
| if (-1 != header.fColorAttributeIndex) {
|
| - GL_CALL(BindAttribLocation(programID,
|
| + GL_CALL(BindAttribLocation(programId,
|
| header.fColorAttributeIndex,
|
| color_attribute_name()));
|
| }
|
| if (-1 != header.fCoverageAttributeIndex) {
|
| - GL_CALL(BindAttribLocation(programID,
|
| + GL_CALL(BindAttribLocation(programId,
|
| header.fCoverageAttributeIndex,
|
| coverage_attribute_name()));
|
| }
|
| @@ -123,7 +86,6 @@
|
| const GrVertexAttrib* vaPtr = optState.getVertexAttribs();
|
| const int vaCount = optState.getVertexAttribCount();
|
|
|
| - // We start binding attributes after builtins
|
| int i = fEffectAttribOffset;
|
| for (int index = 0; index < vaCount; index++) {
|
| if (kGeometryProcessor_GrVertexAttribBinding != vaPtr[index].fBinding) {
|
| @@ -135,22 +97,22 @@
|
| 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()));
|
| + GL_CALL(BindAttribLocation(programId, index, fInputs[i].c_str()));
|
| i++;
|
| }
|
| // Make sure we bound everything
|
| SkASSERT(fInputs.count() == i);
|
| }
|
|
|
| -bool GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId,
|
| +bool GrGLVertexShaderBuilder::compileAndAttachShaders(GrGLuint programId,
|
| SkTDArray<GrGLuint>* shaderIds) const {
|
| GrGpuGL* gpu = fProgramBuilder->gpu();
|
| const GrGLContext& glCtx = gpu->glContext();
|
| const GrGLContextInfo& ctxInfo = gpu->ctxInfo();
|
| SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo));
|
| fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility, &vertShaderSrc);
|
| - this->appendDecls(fInputs, &vertShaderSrc);
|
| - this->appendDecls(fOutputs, &vertShaderSrc);
|
| + fProgramBuilder->appendDecls(fInputs, &vertShaderSrc);
|
| + fProgramBuilder->appendDecls(fOutputs, &vertShaderSrc);
|
| vertShaderSrc.append("void main() {");
|
| vertShaderSrc.append(fCode);
|
| vertShaderSrc.append("}\n");
|
| @@ -164,15 +126,72 @@
|
| return true;
|
| }
|
|
|
| -bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) {
|
| - SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
|
| - for (int i = 0; i < fInputs.count(); ++i) {
|
| - const GrGLShaderVar& attr = fInputs[i];
|
| - // if attribute already added, don't add it again
|
| - if (attr.getName().equals(var.getName())) {
|
| - return false;
|
| - }
|
| +void GrGLVertexShaderBuilder::emitCodeAfterEffects() {
|
| + const char* rtAdjustName;
|
| + fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
|
| + fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
|
| + kVec4f_GrSLType,
|
| + "rtAdjustment",
|
| + &rtAdjustName);
|
| +
|
| + // Transform from Skia's device coords to GL's normalized device coords.
|
| + this->codeAppendf(
|
| + "gl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3.z);",
|
| + rtAdjustName, rtAdjustName);
|
| +}
|
| +
|
| +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;
|
| }
|
| - fInputs.push_back(var);
|
| - return true;
|
| +
|
| + 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();
|
| }
|
|
|