aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-30 12:34:25 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-30 12:34:25 +0000
commit17504f5d5ea2550d29d2118193627129beb7f8b2 (patch)
tree003627530db39f4f78588b33096781fea5838b35
parent4b2e1c8807fd1eb8b42e71ec7e29b6fc189d3476 (diff)
Expose vertex position to GrGLEffect via GrGLShaderBuilder.
R=robertphillips@google.com Review URL: https://codereview.appspot.com/6814054 git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6195 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/gpu/gl/GrGLProgram.cpp24
-rw-r--r--src/gpu/gl/GrGLProgram.h3
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.cpp3
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.h7
4 files changed, 24 insertions, 13 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index f9912aafb6..44502095d1 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -25,7 +25,6 @@ SK_DEFINE_INST_COUNT(GrGLProgram)
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"
@@ -567,13 +566,10 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
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;
@@ -616,7 +612,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
// 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());
@@ -713,7 +709,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
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.
@@ -801,7 +797,8 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
return false;
}
- if (!this->bindOutputsAttribsAndLinkProgram(texCoordAttrs,
+ if (!this->bindOutputsAttribsAndLinkProgram(builder,
+ texCoordAttrs,
isColorDeclared,
dualSourceOutputWritten)) {
return false;
@@ -814,7 +811,8 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
return true;
}
-bool GrGLProgram::bindOutputsAttribsAndLinkProgram(SkString texCoordAttrNames[],
+bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
+ SkString texCoordAttrNames[],
bool bindColorOut,
bool bindDualSrcOut) {
GL_CALL_RET(fProgramID, CreateProgram());
@@ -836,7 +834,9 @@ bool GrGLProgram::bindOutputsAttribsAndLinkProgram(SkString texCoordAttrNames[],
}
// 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,
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 000ebe8f19..a023de79d1 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -194,7 +194,8 @@ private:
bool genEdgeCoverage(SkString* coverageVar, GrGLShaderBuilder* builder) const;
// Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program
- bool bindOutputsAttribsAndLinkProgram(SkString texCoordAttrNames[GrDrawState::kMaxTexCoords],
+ bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
+ SkString texCoordAttrNames[GrDrawState::kMaxTexCoords],
bool bindColorOut,
bool bindDualSrcOut);
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index ec7199b782..463c0363eb 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -96,6 +96,9 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctx, GrGLUniformMana
, fSetupFragPosition(false)
, fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
, fTexCoordVaryingType(kVoid_GrSLType) {
+
+ fPositionVar = &fVSAttrs.push_back();
+ fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aPosition");
}
void GrGLShaderBuilder::setupTextureAccess(const char* varyingFSName, GrSLType varyingType) {
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index 8f5d6956ac..6fdec63e36 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -170,6 +170,11 @@ public:
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;
@@ -227,6 +232,8 @@ private:
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