typedef GrGLProgram::Desc::StageDesc StageDesc;
-#define POS_ATTR_NAME "aPosition"
#define COL_ATTR_NAME "aColor"
#define COV_ATTR_NAME "aCoverage"
#define EDGE_ATTR_NAME "aEdge"
fUniforms.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVertex_ShaderType,
kMat33f_GrSLType, "ViewM", &viewMName);
- builder.fVSAttrs.push_back().set(kVec2f_GrSLType,
- GrGLShaderVar::kAttribute_TypeModifier,
- POS_ATTR_NAME);
-
- builder.fVSCode.appendf("\tvec3 pos3 = %s * vec3("POS_ATTR_NAME", 1);\n"
+
+ builder.fVSCode.appendf("\tvec3 pos3 = %s * vec3(%s, 1);\n"
"\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n",
- viewMName);
+ viewMName, builder.positionAttribute().getName().c_str());
// incoming color to current stage being processed.
SkString inColor;
// figure out what our input coords are
int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout);
if (tcIdx < 0) {
- inCoords = POS_ATTR_NAME;
+ inCoords = builder.positionAttribute().c_str();
} else {
// must have input tex coordinates if stage is enabled.
GrAssert(texCoordAttrs[tcIdx].size());
int tcIdx =
GrDrawTarget::VertexTexCoordsForStage(s, layout);
if (tcIdx < 0) {
- inCoords = POS_ATTR_NAME;
+ inCoords = builder.positionAttribute().c_str();
} else {
// must have input tex coordinates if stage is
// enabled.
return false;
}
- if (!this->bindOutputsAttribsAndLinkProgram(texCoordAttrs,
+ if (!this->bindOutputsAttribsAndLinkProgram(builder,
+ texCoordAttrs,
isColorDeclared,
dualSourceOutputWritten)) {
return false;
return true;
}
-bool GrGLProgram::bindOutputsAttribsAndLinkProgram(SkString texCoordAttrNames[],
+bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
+ SkString texCoordAttrNames[],
bool bindColorOut,
bool bindDualSrcOut) {
GL_CALL_RET(fProgramID, CreateProgram());
}
// Bind the attrib locations to same values for all shaders
- GL_CALL(BindAttribLocation(fProgramID, PositionAttributeIdx(), POS_ATTR_NAME));
+ GL_CALL(BindAttribLocation(fProgramID,
+ PositionAttributeIdx(),
+ builder.positionAttribute().c_str()));
for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
if (texCoordAttrNames[t].size()) {
GL_CALL(BindAttribLocation(fProgramID,
is in device space (e.g. 0,0 is the top left and pixel centers are at half-integers). */
const char* fragmentPosition();
+ /** Returns a vertex attribute that represents the vertex position in the VS. This is the
+ pre-matrix position and is commonly used by effects to compute texture coords via a matrix.
+ */
+ const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
+
/** Called after building is complete to get the final shader string. */
void getShader(ShaderType, SkString*) const;
bool fSetupFragPosition;
GrGLUniformManager::UniformHandle fRTHeightUniform;
+ GrGLShaderVar* fPositionVar;
+
/// Per-stage settings - only valid while we're inside GrGLProgram::genStageCode().
//@{
GrSLType fTexCoordVaryingType; // the type, either Vec2f or Vec3f, of the coords passed