Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: src/gpu/gl/GrGLShaderBuilder.h

Issue 23754003: Isolate VertexBuilder from GrGLShaderBuilder (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: comment fix Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/gl/GrGLShaderBuilder.h
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index ad0d87ef31bffd8c5e3cc45a1ec491f313c75412..6cb12c3748ae57f2a36dcdcb5d8dda649b7a4950 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -96,6 +96,7 @@ public:
};
typedef SkTArray<TextureSampler> TextureSamplerArray;
+ typedef GrTAllocator<GrGLShaderVar> VarArray;
enum ShaderVisibility {
kVertex_Visibility = 0x1,
@@ -103,7 +104,10 @@ public:
kFragment_Visibility = 0x4,
};
- GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&, const GrGLProgramDesc&);
+ GrGLShaderBuilder(const GrGLContextInfo&,
+ GrGLUniformManager&,
+ const GrGLProgramDesc&,
+ bool needsVertexShader);
/**
* Use of these features may require a GLSL extension to be enabled. Shaders may not compile
@@ -122,22 +126,8 @@ public:
bool enableFeature(GLSLFeature);
/**
- * Called by GrGLEffects to add code to one of the shaders.
+ * Called by GrGLEffects to add code the fragment shader.
*/
- void vsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
- va_list args;
- va_start(args, format);
- fVSCode.appendf(format, args);
- va_end(args);
- }
-
- void gsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
- va_list args;
- va_start(args, format);
- fGSCode.appendf(format, args);
- va_end(args);
- }
-
void fsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
va_list args;
va_start(args, format);
@@ -145,8 +135,6 @@ public:
va_end(args);
}
- void vsCodeAppend(const char* str) { fVSCode.append(str); }
- void gsCodeAppend(const char* str) { fGSCode.append(str); }
void fsCodeAppend(const char* str) { fFSCode.append(str); }
/** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
@@ -180,6 +168,12 @@ public:
const char* body,
SkString* outName);
+ /** Add input/output variable declarations (i.e. 'varying') to the fragment shader. */
+ GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); }
+ GrGLShaderVar& fsOutputAppend() { return fFSOutputs.push_back(); }
+ GrGLShaderVar& fsInputAppend(const GrGLShaderVar& var) { return fFSInputs.push_back(var); }
+ GrGLShaderVar& fsOutputAppend(const GrGLShaderVar& var) { return fFSOutputs.push_back(var); }
+
/** Generates a EffectKey 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. */
@@ -233,50 +227,22 @@ public:
return this->getUniformVariable(u).c_str();
}
- /** Add a vertex attribute to the current program that is passed in from the vertex data.
- Returns false if the attribute was already there, true otherwise. */
- bool addAttribute(GrSLType type, const char* name);
-
- /** 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);
-
/** Returns a variable name that represents the position of the fragment in the FS. The position
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; }
-
- /** Returns a vertex attribute that represents the local coords in the VS. This may be the same
- as positionAttribute() or it may not be. It depends upon whether the rendering code
- specified explicit local coords or not in the GrDrawState. */
- const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
-
/** Returns the color of the destination pixel. This may be NULL if no effect advertised
that it will read the destination. */
const char* dstColor();
/**
- * Are explicit local coordinates provided as input to the vertex shader.
- */
- bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
-
- /**
* Interfaces used by GrGLProgram.
* TODO: Hide these from the GrEffects using friend or splitting this into two related classes.
* Also, GrGLProgram's shader string construction should be moved to this class.
*/
- /** Called after building is complete to get the final shader string. */
- void vsGetShader(SkString*) const;
- void gsGetShader(SkString*) const;
+ /** Called after building is complete to get the final shader string. To acces the vertex
+ and geometry shaders, use the VertexBuilder. */
void fsGetShader(SkString*) const;
/**
@@ -309,17 +275,97 @@ public:
return fDstCopySampler.fSamplerUniform;
}
- struct AttributePair {
- void set(int index, const SkString& name) {
- fIndex = index; fName = name;
+ class VertexBuilder {
bsalomon 2013/08/30 17:59:17 /** Helper class used to build the vertex shader..
Chris Dalton 2013/08/30 19:10:30 Done.
+ public:
+ VertexBuilder(GrGLShaderBuilder* parent, const GrGLProgramDesc&);
+
+ /**
+ * Called by GrGLEffects to add code to one of the shaders.
+ */
+ void vsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
+ va_list args;
+ va_start(args, format);
+ fVSCode.appendf(format, args);
+ va_end(args);
+ }
+
+ void gsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
+ va_list args;
+ va_start(args, format);
+ fGSCode.appendf(format, args);
+ va_end(args);
}
- int fIndex;
- SkString fName;
+
+ void vsCodeAppend(const char* str) { fVSCode.append(str); }
+ void gsCodeAppend(const char* str) { fGSCode.append(str); }
+
+ /** Add a vertex attribute to the current program that is passed in from the vertex data.
+ Returns false if the attribute was already there, true otherwise. */
+ bool addAttribute(GrSLType type, const char* name);
+
+ /** 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);
+
+ /** 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; }
+
+ /** Returns a vertex attribute that represents the local coords in the VS. This may be the same
+ as positionAttribute() or it may not be. It depends upon whether the rendering code
+ specified explicit local coords or not in the GrDrawState. */
+ const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
+
+ /**
+ * Are explicit local coordinates provided as input to the vertex shader.
+ */
+ bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
+
+ /** Called after building is complete to get the final shader string. */
+ void vsGetShader(SkString*) const;
+ void gsGetShader(SkString*) const;
+
+ struct AttributePair {
+ void set(int index, const SkString& name) {
+ fIndex = index; fName = name;
+ }
+ int fIndex;
+ SkString fName;
+ };
+ const SkTArray<AttributePair, true>& getEffectAttributes() const {
+ return fEffectAttributes;
+ }
+ bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& name);
+ const SkString* getEffectAttributeName(int attributeIndex) const;
+
+ // TODO: Everything below here private.
+ public:
+
+ VarArray fVSAttrs;
+ VarArray fVSOutputs;
+ VarArray fGSInputs;
+ VarArray fGSOutputs;
+ SkString fGSHeader; // layout qualifiers specific to GS
+
+ private:
+ GrGLShaderBuilder* fParent;
+
+ bool fUsesGS;
+
+ SkString fVSCode;
+ SkString fGSCode;
+
+ SkSTArray<10, AttributePair, true> fEffectAttributes;
+
+ GrGLShaderVar* fPositionVar;
+ GrGLShaderVar* fLocalCoordsVar;
};
- const SkTArray<AttributePair, true>& getEffectAttributes() const {
- return fEffectAttributes;
- }
- const SkString* getEffectAttributeName(int attributeIndex) const;
+ VertexBuilder* getVertexBuilder() const { return fVertexBuilder.get(); }
bsalomon 2013/08/30 17:59:17 \n /** Gets the vertex builder that is used to con
// TODO: Make this do all the compiling, linking, etc.
void finished(GrGLuint programID);
@@ -327,25 +373,12 @@ public:
const GrGLContextInfo& ctxInfo() const { return fCtxInfo; }
private:
- typedef GrTAllocator<GrGLShaderVar> VarArray;
-
void appendDecls(const VarArray&, SkString*) const;
void appendUniformDecls(ShaderVisibility, SkString*) const;
typedef GrGLUniformManager::BuilderUniform BuilderUniform;
GrGLUniformManager::BuilderUniformArray fUniforms;
- // TODO: Everything below here private.
-public:
-
- VarArray fVSAttrs;
- VarArray fVSOutputs;
- VarArray fGSInputs;
- VarArray fGSOutputs;
- VarArray fFSInputs;
- SkString fGSHeader; // layout qualifiers specific to GS
- VarArray fFSOutputs;
-
private:
class CodeStage : GrNoncopyable {
public:
@@ -436,12 +469,10 @@ private:
uint32_t fFSFeaturesAddedMask;
SkString fFSFunctions;
SkString fFSExtensions;
-
- bool fUsesGS;
+ VarArray fFSInputs;
+ VarArray fFSOutputs;
SkString fFSCode;
- SkString fVSCode;
- SkString fGSCode;
bool fSetupFragPosition;
TextureSampler fDstCopySampler;
@@ -452,11 +483,7 @@ private:
bool fTopLeftFragPosRead;
- SkSTArray<10, AttributePair, true> fEffectAttributes;
-
- GrGLShaderVar* fPositionVar;
- GrGLShaderVar* fLocalCoordsVar;
-
+ SkAutoTDelete<VertexBuilder> fVertexBuilder;
};
#endif

Powered by Google App Engine
This is Rietveld 408576698