Condense setupFSUnis, setupVSUnis, setupVaryings into

GrGLProgramStage::setupVariables().
Rename appendVarying() to addVarying(), matching addUniform().

http://codereview.appspot.com/6262046/



git-svn-id: http://skia.googlecode.com/svn/trunk@4083 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
tomhudson@google.com 2012-05-30 18:26:03 +00:00
Родитель 02154c7390
Коммит 23cb2299dd
6 изменённых файлов: 104 добавлений и 136 удалений

Просмотреть файл

@ -19,8 +19,8 @@ public:
GrGLConvolutionEffect(const GrProgramStageFactory& factory,
const GrCustomStage* stage);
virtual void setupVSUnis(VarArray* vsUnis, int stage) SK_OVERRIDE;
virtual void setupFSUnis(VarArray* fsUnis, int stage) SK_OVERRIDE;
virtual void setupVariables(GrGLShaderBuilder* state,
int stage) SK_OVERRIDE;
virtual void emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) SK_OVERRIDE;
virtual void emitFS(GrGLShaderBuilder* state,
@ -38,12 +38,12 @@ public:
protected:
unsigned int fKernelWidth;
GrGLShaderVar* fKernelVar;
GrGLShaderVar* fImageIncrementVar;
unsigned int fKernelWidth;
const GrGLShaderVar* fKernelVar;
const GrGLShaderVar* fImageIncrementVar;
GrGLint fKernelLocation;
GrGLint fImageIncrementLocation;
GrGLint fKernelLocation;
GrGLint fImageIncrementLocation;
private:
@ -61,33 +61,17 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(
fKernelWidth = static_cast<const GrConvolutionEffect*>(data)->width();
}
void GrGLConvolutionEffect::setupVSUnis(VarArray* vsUnis,
int stage) {
fImageIncrementVar = &vsUnis->push_back();
fImageIncrementVar->setType(kVec2f_GrSLType);
fImageIncrementVar->setTypeModifier(
GrGLShaderVar::kUniform_TypeModifier);
(*fImageIncrementVar->accessName()) = "uImageIncrement";
fImageIncrementVar->accessName()->appendS32(stage);
fImageIncrementVar->setEmitPrecision(true);
void GrGLConvolutionEffect::setupVariables(GrGLShaderBuilder* state,
int stage) {
fImageIncrementVar = &state->addUniform(
GrGLShaderBuilder::kBoth_VariableLifetime,
kVec2f_GrSLType, "uImageIncrement", stage);
fKernelVar = &state->addUniform(
GrGLShaderBuilder::kFragment_VariableLifetime,
kFloat_GrSLType, "uKernel", stage, fKernelWidth);
fImageIncrementLocation = kUseUniform;
}
void GrGLConvolutionEffect::setupFSUnis(VarArray* fsUnis,
int stage) {
fKernelVar = &fsUnis->push_back();
fKernelVar->setType(kFloat_GrSLType);
fKernelVar->setTypeModifier(
GrGLShaderVar::kUniform_TypeModifier);
fKernelVar->setArrayCount(fKernelWidth);
(*fKernelVar->accessName()) = "uKernel";
fKernelVar->accessName()->appendS32(stage);
fKernelLocation = kUseUniform;
// Image increment is used in both vertex & fragment shaders.
fsUnis->push_back(*fImageIncrementVar).setEmitPrecision(false);
}
void GrGLConvolutionEffect::emitVS(GrGLShaderBuilder* state,

Просмотреть файл

@ -309,7 +309,7 @@ void GrGLProgram::genEdgeCoverage(const GrGLContextInfo& gl,
GrGLShaderBuilder* segments) const {
if (layout & GrDrawTarget::kEdge_VertexLayoutBit) {
const char *vsName, *fsName;
segments->appendVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName);
segments->addVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName);
segments->fVSAttrs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier, EDGE_ATTR_NAME);
segments->fVSCode.appendf("\t%s = " EDGE_ATTR_NAME ";\n", vsName);
@ -379,7 +379,7 @@ void genInputColor(GrGLProgram::ProgramDesc::ColorInput colorInput,
GrGLShaderVar::kAttribute_TypeModifier,
COL_ATTR_NAME);
const char *vsName, *fsName;
segments->appendVarying(kVec4f_GrSLType, "Color", &vsName, &fsName);
segments->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName);
segments->fVSCode.appendf("\t%s = " COL_ATTR_NAME ";\n", vsName);
*inColor = fsName;
} break;
@ -406,7 +406,7 @@ void genAttributeCoverage(GrGLShaderBuilder* segments,
GrGLShaderVar::kAttribute_TypeModifier,
COV_ATTR_NAME);
const char *vsName, *fsName;
segments->appendVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName);
segments->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName);
segments->fVSCode.appendf("\t%s = " COV_ATTR_NAME ";\n", vsName);
if (inOutCoverage->size()) {
segments->fFSCode.appendf("\tvec4 attrCoverage = %s * %s;\n",
@ -1256,11 +1256,11 @@ const GrGLShaderVar* genRadialVS(int stageNum,
// part of the quadratic as a varying.
if (segments->fVaryingDims == segments->fCoordDims) {
GrAssert(2 == segments->fCoordDims);
segments->appendVarying(kFloat_GrSLType,
"Radial2BCoeff",
stageNum,
radial2VaryingVSName,
radial2VaryingFSName);
segments->addVarying(kFloat_GrSLType,
"Radial2BCoeff",
stageNum,
radial2VaryingVSName,
radial2VaryingFSName);
GrStringBuilder radial2p2;
GrStringBuilder radial2p3;
@ -1486,12 +1486,12 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
GrAssert((desc.fInConfigFlags & StageDesc::kInConfigBitMask) ==
desc.fInConfigFlags);
/// Vertex Shader Stuff
if (NULL != customStage) {
customStage->setupVSUnis(&segments->fVSUnis, stageNum);
customStage->setupVariables(segments, stageNum);
}
/// 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;
@ -1532,11 +1532,11 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
}
const char *varyingVSName, *varyingFSName;
segments->appendVarying(GrSLFloatVectorType(segments->fVaryingDims),
"Stage",
stageNum,
&varyingVSName,
&varyingFSName);
segments->addVarying(GrSLFloatVectorType(segments->fVaryingDims),
"Stage",
stageNum,
&varyingVSName,
&varyingFSName);
if (!matName) {
GrAssert(segments->fVaryingDims == segments->fCoordDims);
@ -1577,10 +1577,6 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
/// Fragment Shader Stuff
if (NULL != customStage) {
customStage->setupFSUnis(&segments->fFSUnis, stageNum);
}
// Function used to access the shader, may be made projective.
GrStringBuilder texFunc("texture2D");
if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit |

Просмотреть файл

@ -17,15 +17,7 @@ GrGLProgramStage::~GrGLProgramStage() {
///////////////////////////////////////////////////////////////////////////////
void GrGLProgramStage::setupVSUnis(VarArray* vsUnis, int stage) {
}
void GrGLProgramStage::setupFSUnis(VarArray* fsUnis, int stage) {
}
void GrGLProgramStage::setupVaryings(GrGLShaderBuilder* state, int stage) {
void GrGLProgramStage::setupVariables(GrGLShaderBuilder* state, int stage) {
}

Просмотреть файл

@ -43,22 +43,8 @@ public:
virtual ~GrGLProgramStage();
/** Creates any uniform variables the vertex shader requires
and appends them to vsUnis;
must guarantee they are unique (typically done by
appending the stage number). */
virtual void setupVSUnis(VarArray* vsUnis, int stage);
/** Creates any uniform variables the fragment shader requires
and appends them to fsUnis;
must guarantee they are unique (typically done by
appending the stage number). */
virtual void setupFSUnis(VarArray* fsUnis, int stage);
/** Creates any varying variables shared between the shaders;
must guarantee they are unique (typically done by
appending the stage number). */
virtual void setupVaryings(GrGLShaderBuilder* state, int stage);
/** Create any uniforms or varyings the vertex shader requires. */
virtual void setupVariables(GrGLShaderBuilder* state, int stage);
/** Appends vertex code to the appropriate GrStringBuilder
on the state.

Просмотреть файл

@ -39,55 +39,6 @@ GrGLShaderBuilder::GrGLShaderBuilder()
}
void GrGLShaderBuilder::appendVarying(GrSLType type,
const char* name,
const char** vsOutName,
const char** fsInName) {
fVSOutputs.push_back();
fVSOutputs.back().setType(type);
fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
fVSOutputs.back().accessName()->printf("v%s", name);
if (vsOutName) {
*vsOutName = fVSOutputs.back().getName().c_str();
}
// input to FS comes either from VS or GS
const GrStringBuilder* fsName;
if (fUsesGS) {
// if we have a GS take each varying in as an array
// and output as non-array.
fGSInputs.push_back();
fGSInputs.back().setType(type);
fGSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier);
fGSInputs.back().setUnsizedArray();
*fGSInputs.back().accessName() = fVSOutputs.back().getName();
fGSOutputs.push_back();
fGSOutputs.back().setType(type);
fGSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
fGSOutputs.back().accessName()->printf("g%s", name);
fsName = fGSOutputs.back().accessName();
} else {
fsName = fVSOutputs.back().accessName();
}
fFSInputs.push_back();
fFSInputs.back().setType(type);
fFSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier);
fFSInputs.back().setName(*fsName);
if (fsInName) {
*fsInName = fsName->c_str();
}
}
void GrGLShaderBuilder::appendVarying(GrSLType type,
const char* name,
int stageNum,
const char** vsOutName,
const char** fsInName) {
GrStringBuilder nameWithStage(name);
nameWithStage.appendS32(stageNum);
this->appendVarying(type, nameWithStage.c_str(), vsOutName, fsInName);
}
void GrGLShaderBuilder::computeSwizzle(uint32_t configFlags) {
static const uint32_t kMulByAlphaMask =
(GrGLProgram::StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag |
@ -205,3 +156,53 @@ const GrGLShaderVar& GrGLShaderBuilder::addUniform(VariableLifetime lifetime,
return *var;
}
void GrGLShaderBuilder::addVarying(GrSLType type,
const char* name,
const char** vsOutName,
const char** fsInName) {
fVSOutputs.push_back();
fVSOutputs.back().setType(type);
fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
fVSOutputs.back().accessName()->printf("v%s", name);
if (vsOutName) {
*vsOutName = fVSOutputs.back().getName().c_str();
}
// input to FS comes either from VS or GS
const GrStringBuilder* fsName;
if (fUsesGS) {
// if we have a GS take each varying in as an array
// and output as non-array.
fGSInputs.push_back();
fGSInputs.back().setType(type);
fGSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier);
fGSInputs.back().setUnsizedArray();
*fGSInputs.back().accessName() = fVSOutputs.back().getName();
fGSOutputs.push_back();
fGSOutputs.back().setType(type);
fGSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
fGSOutputs.back().accessName()->printf("g%s", name);
fsName = fGSOutputs.back().accessName();
} else {
fsName = fVSOutputs.back().accessName();
}
fFSInputs.push_back();
fFSInputs.back().setType(type);
fFSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier);
fFSInputs.back().setName(*fsName);
if (fsInName) {
*fsInName = fsName->c_str();
}
}
void GrGLShaderBuilder::addVarying(GrSLType type,
const char* name,
int stageNum,
const char** vsOutName,
const char** fsInName) {
GrStringBuilder nameWithStage(name);
nameWithStage.appendS32(stageNum);
this->addVarying(type, nameWithStage.c_str(), vsOutName, fsInName);
}

Просмотреть файл

@ -26,17 +26,6 @@ public:
GrGLShaderBuilder();
void appendVarying(GrSLType type,
const char* name,
const char** vsOutName = NULL,
const char** fsInName = NULL);
void appendVarying(GrSLType type,
const char* name,
int stageNum,
const char** vsOutName = NULL,
const char** fsInName = NULL);
void computeSwizzle(uint32_t configFlags);
void computeModulate(const char* fsInColor);
@ -73,6 +62,26 @@ public:
int stageNum = -1,
int count = GrGLShaderVar::kNonArray);
/** Add a varying variable to the current program to pass
values between vertex and fragment shaders.
If the last two parameters are non-NULL, they are filled
in with the name generated. */
void addVarying(GrSLType type,
const char* name,
const char** vsOutName = NULL,
const char** fsInName = NULL);
/** Add a varying variable to the current program to pass
values between vertex and fragment shaders;
stageNum is appended to the name to guarantee uniqueness.
If the last two parameters are non-NULL, they are filled
in with the name generated. */
void addVarying(GrSLType type,
const char* name,
int stageNum,
const char** vsOutName = NULL,
const char** fsInName = NULL);
// TODO: needs a better name
enum SamplerMode {
kDefault_SamplerMode,