diff options
author | 2012-11-01 15:40:47 +0000 | |
---|---|---|
committer | 2012-11-01 15:40:47 +0000 | |
commit | c3a58f345de16c185db3a20578c7ddf52bc89d38 (patch) | |
tree | 90b83991981cce5a6e19e212911122f240aa8470 /src/gpu/gl/GrGLProgram.cpp | |
parent | 66e534da8e2b3de928f7ce132da61947a73ab7cb (diff) |
Reland r6233 with fix for config conversion texture matrices.
git-svn-id: http://skia.googlecode.com/svn/trunk@6238 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl/GrGLProgram.cpp')
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index cd16d9e24f..120bd1e3ad 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -909,57 +909,64 @@ GrGLEffect* GrGLProgram::GenStageCode(const GrEffectStage& stage, /// Vertex Shader Stuff - // decide whether we need a matrix to transform texture coords and whether the varying needs a - // perspective coord. - const char* matName = NULL; - GrSLType texCoordVaryingType; - if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) { - texCoordVaryingType = kVec2f_GrSLType; - } else { - uniforms->fTextureMatrixUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType, - kMat33f_GrSLType, "TexM", &matName); - builder->getUniformVariable(uniforms->fTextureMatrixUni); - - if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) { + const char* vertexCoords; + + // Has the effect not yet been updated to insert its own texture matrix if necessary. + if (glEffect->requiresTextureMatrix()) { + // Decide whether we need a matrix to transform texture coords and whether the varying needs + // a perspective coord. + const char* matName = NULL; + GrSLType texCoordVaryingType; + if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) { texCoordVaryingType = kVec2f_GrSLType; } else { - texCoordVaryingType = kVec3f_GrSLType; + uniforms->fTextureMatrixUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType, + kMat33f_GrSLType, "TexM", &matName); + builder->getUniformVariable(uniforms->fTextureMatrixUni); + + if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) { + texCoordVaryingType = kVec2f_GrSLType; + } else { + texCoordVaryingType = kVec3f_GrSLType; + } + } + const char *varyingVSName, *varyingFSName; + builder->addVarying(texCoordVaryingType, + "Stage", + &varyingVSName, + &varyingFSName); + builder->setupTextureAccess(varyingFSName, texCoordVaryingType); + + if (!matName) { + GrAssert(kVec2f_GrSLType == texCoordVaryingType); + builder->fVSCode.appendf("\t%s = %s;\n", varyingVSName, vsInCoord); + } else { + // varying = texMatrix * texCoord + builder->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n", + varyingVSName, matName, vsInCoord, + vector_all_coords(GrSLTypeToVecLength(texCoordVaryingType))); } + vertexCoords = varyingVSName; + } else { + vertexCoords = vsInCoord; } - const char *varyingVSName, *varyingFSName; - builder->addVarying(texCoordVaryingType, - "Stage", - &varyingVSName, - &varyingFSName); - builder->setupTextureAccess(varyingFSName, texCoordVaryingType); + // setup texture samplers for gl effect int numTextures = effect->numTextures(); SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers; - textureSamplers.push_back_n(numTextures); - for (int i = 0; i < numTextures; ++i) { textureSamplers[i].init(builder, &effect->textureAccess(i)); uniforms->fSamplerUniforms.push_back(textureSamplers[i].fSamplerUniform); } - if (!matName) { - GrAssert(kVec2f_GrSLType == texCoordVaryingType); - builder->fVSCode.appendf("\t%s = %s;\n", varyingVSName, vsInCoord); - } else { - // varying = texMatrix * texCoord - builder->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n", - varyingVSName, matName, vsInCoord, - vector_all_coords(GrSLTypeToVecLength(texCoordVaryingType))); - } - // Enclose custom code in a block to avoid namespace conflicts builder->fVSCode.appendf("\t{ // %s\n", glEffect->name()); builder->fFSCode.appendf("\t{ // %s \n", glEffect->name()); glEffect->emitCode(builder, stage, desc.fEffectKey, - varyingVSName, + vertexCoords, fsOutColor, fsInColor, textureSamplers); |