aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-07 17:36:29 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-07 17:36:29 +0000
commita1bf0fffff821d9c11809c89bd98d4ced480421a (patch)
tree4a89b6a6684bfcf55dfea3f9cb84ddb6a574201e /src/gpu
parent2972bb5fd2441709026b350c6b9b66eecd80f868 (diff)
uniquely name FS functions, add lighting effects to unit test
Review URL: http://codereview.appspot.com/6458080/ git-svn-id: http://skia.googlecode.com/svn/trunk@4992 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/gl/GrGLSL.cpp10
-rw-r--r--src/gpu/gl/GrGLSL.h1
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.cpp28
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.h12
-rw-r--r--src/gpu/gl/GrGLShaderVar.h21
5 files changed, 64 insertions, 8 deletions
diff --git a/src/gpu/gl/GrGLSL.cpp b/src/gpu/gl/GrGLSL.cpp
index 759a17c39a..ff4d498eaf 100644
--- a/src/gpu/gl/GrGLSL.cpp
+++ b/src/gpu/gl/GrGLSL.cpp
@@ -66,12 +66,12 @@ bool GrGLSLSetupFSColorOuput(GrGLSLGeneration gen,
}
GrSLType GrSLFloatVectorType (int count) {
- GR_STATIC_ASSERT(kFloat_GrSLType == 0);
- GR_STATIC_ASSERT(kVec2f_GrSLType == 1);
- GR_STATIC_ASSERT(kVec3f_GrSLType == 2);
- GR_STATIC_ASSERT(kVec4f_GrSLType == 3);
+ GR_STATIC_ASSERT(kFloat_GrSLType == 1);
+ GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
+ GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
+ GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
GrAssert(count > 0 && count <= 4);
- return (GrSLType)(count - 1);
+ return (GrSLType)(count);
}
const char* GrGLSLVectorHomogCoord(int count) {
diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h
index 7b92c23434..a58f7e8e75 100644
--- a/src/gpu/gl/GrGLSL.h
+++ b/src/gpu/gl/GrGLSL.h
@@ -35,6 +35,7 @@ enum GrGLSLGeneration {
* langauges.)
*/
enum GrSLType {
+ kVoid_GrSLType,
kFloat_GrSLType,
kVec2f_GrSLType,
kVec3f_GrSLType,
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index 3ca408618c..167eb78bcc 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -291,6 +291,32 @@ void GrGLShaderBuilder::addVarying(GrSLType type,
}
}
+void GrGLShaderBuilder::emitFunction(ShaderType shader,
+ GrSLType returnType,
+ const char* name,
+ int argCnt,
+ const GrGLShaderVar* args,
+ const char* body,
+ SkString* outName) {
+ GrAssert(kFragment_ShaderType == shader);
+ fFSFunctions.append(GrGLShaderVar::TypeString(returnType));
+ if (kNonStageIdx != fCurrentStage) {
+ outName->printf(" %s_%d", name, fCurrentStage);
+ } else {
+ *outName = name;
+ }
+ fFSFunctions.append(*outName);
+ fFSFunctions.append("(");
+ for (int i = 0; i < argCnt; ++i) {
+ args[i].appendDecl(fContext, &fFSFunctions);
+ if (i < argCnt - 1) {
+ fFSFunctions.append(", ");
+ }
+ }
+ fFSFunctions.append(") {\n");
+ fFSFunctions.append(body);
+ fFSFunctions.append("}\n\n");
+}
namespace {
@@ -321,6 +347,7 @@ inline void append_default_precision_qualifier(GrGLShaderVar::Precision p,
void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
for (int i = 0; i < vars.count(); ++i) {
vars[i].appendDecl(fContext, out);
+ out->append(";\n");
}
}
@@ -328,6 +355,7 @@ void GrGLShaderBuilder::appendUniformDecls(ShaderType stype, SkString* out) cons
for (int i = 0; i < fUniforms.count(); ++i) {
if (fUniforms[i].fVisibility & stype) {
fUniforms[i].fVariable.appendDecl(fContext, out);
+ out->append(";\n");
}
}
}
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index ab0792b0cf..31d603a8d2 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -66,6 +66,16 @@ public:
const char* samplerName,
const char* coordName);
+ /** Emits a helper function outside of main(). Currently ShaderType must be
+ kFragment_ShaderType. */
+ void emitFunction(ShaderType shader,
+ GrSLType returnType,
+ const char* name,
+ int argCnt,
+ const GrGLShaderVar* args,
+ const char* body,
+ SkString* outName);
+
/** Generates a StageKey for the shader code based on the texture access parameters and the
capabilities of the GL context. This is useful for keying the shader programs that may
have multiple representations, based on the type/format of textures used. */
@@ -144,7 +154,6 @@ public:
VarArray fFSInputs;
SkString fGSHeader; // layout qualifiers specific to GS
VarArray fFSOutputs;
- SkString fFSFunctions;
SkString fVSCode;
SkString fGSCode;
SkString fFSCode;
@@ -176,6 +185,7 @@ private:
const GrGLContextInfo& fContext;
GrGLUniformManager& fUniformManager;
int fCurrentStage;
+ SkString fFSFunctions;
};
#endif
diff --git a/src/gpu/gl/GrGLShaderVar.h b/src/gpu/gl/GrGLShaderVar.h
index 0231d214d3..92d7ee07fd 100644
--- a/src/gpu/gl/GrGLShaderVar.h
+++ b/src/gpu/gl/GrGLShaderVar.h
@@ -55,13 +55,25 @@ public:
fUseUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS;
}
+ GrGLShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray) {
+ GrAssert(kVoid_GrSLType != type);
+ fType = type;
+ fTypeModifier = kNone_TypeModifier;
+ fCount = arrayCount;
+ fPrecision = kDefault_Precision;
+ fUseUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS;
+ fName = name;
+ }
+
GrGLShaderVar(const GrGLShaderVar& var)
: fType(var.fType)
, fTypeModifier(var.fTypeModifier)
, fName(var.fName)
, fCount(var.fCount)
, fPrecision(var.fPrecision)
- , fUseUniformFloatArrays(var.fUseUniformFloatArrays) {}
+ , fUseUniformFloatArrays(var.fUseUniformFloatArrays) {
+ GrAssert(kVoid_GrSLType != var.fType);
+ }
/**
* Values for array count that have special meaning. We allow 1-sized arrays.
@@ -79,6 +91,7 @@ public:
const SkString& name,
Precision precision = kDefault_Precision,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
+ GrAssert(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
fName = name;
@@ -95,6 +108,7 @@ public:
const char* name,
Precision precision = kDefault_Precision,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
+ GrAssert(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
fName = name;
@@ -112,6 +126,7 @@ public:
int count,
Precision precision = kDefault_Precision,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
+ GrAssert(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
fName = name;
@@ -129,6 +144,7 @@ public:
int count,
Precision precision = kDefault_Precision,
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
+ GrAssert(kVoid_GrSLType != type);
fType = type;
fTypeModifier = typeModifier;
fName = name;
@@ -232,11 +248,12 @@ public:
TypeString(effectiveType),
this->getName().c_str());
}
- out->append(";\n");
}
static const char* TypeString(GrSLType t) {
switch (t) {
+ case kVoid_GrSLType:
+ return "void";
case kFloat_GrSLType:
return "float";
case kVec2f_GrSLType: