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

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

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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
« no previous file with comments | « src/gpu/gl/GrGLEffect.cpp ('k') | src/gpu/gl/GrGLEffectMatrix.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLEffectMatrix.h
===================================================================
--- src/gpu/gl/GrGLEffectMatrix.h (revision 8241)
+++ src/gpu/gl/GrGLEffectMatrix.h (working copy)
@@ -14,34 +14,68 @@
class GrTexture;
/**
- * This is a helper to implement a texture matrix in a GrGLEffect.
+ * This is a helper to implement a matrix in a GrGLEffect that operates on incoming coords in the
+ * vertex shader and writes them to an attribute to be used in the fragment shader. When the input
+ * coords in the vertex shader are local coordinates this class accounts for the coord change matrix
+ * communicated via GrDrawEffect. The input coords may also be positions and in this case the coord
+ * change matrix is ignored. The GrGLEffectMatrix will emit different code based on the type of
+ * matrix and thus must contribute to the effect's key.
+ *
+ * This class cannot be used to apply a matrix to coordinates that come in the form of custom vertex
+ * attributes.
*/
class GrGLEffectMatrix {
+private:
+ // We specialize the generated code for each of these matrix types.
+ enum MatrixTypes {
+ kIdentity_MatrixType = 0,
+ kTrans_MatrixType = 1,
+ kNoPersp_MatrixType = 2,
+ kGeneral_MatrixType = 3,
+ };
+ // The key for is made up of a matrix type and a bit that indicates the source of the input
+ // coords.
+ enum {
+ kMatrixTypeKeyBits = 2,
+ kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
+ kPositionCoords_Flag = (1 << kMatrixTypeKeyBits),
+ kKeyBitsPrivate = kMatrixTypeKeyBits + 1,
+ };
+
public:
+
+ typedef GrEffect::CoordsType CoordsType;
+
typedef GrGLEffect::EffectKey EffectKey;
+
/**
* The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may place these bits at an
* arbitrary shift in its final key. However, when GrGLEffectMatrix::emitCode*() code is called
* the relevant bits must be in the lower kKeyBits of the key parameter.
*/
enum {
- kKeyBits = 2,
+ kKeyBits = kKeyBitsPrivate,
kKeyMask = (1 << kKeyBits) - 1,
};
- GrGLEffectMatrix() : fUni(GrGLUniformManager::kInvalidUniformHandle) {
+ GrGLEffectMatrix(CoordsType coordsType)
+ : fUni(GrGLUniformManager::kInvalidUniformHandle)
+ , fCoordsType(coordsType) {
+ GrAssert(GrEffect::kLocal_CoordsType == coordsType ||
+ GrEffect::kPosition_CoordsType == coordsType);
fPrevMatrix = SkMatrix::InvalidMatrix();
}
/**
* Generates the key for the portion of the code emitted by this class's emitCode() function.
* Pass a texture to make GrGLEffectMatrix automatically adjust for the texture's origin. Pass
- * NULL when not using the EffectMatrix for a texture lookups, or if the GrGLEffect subclass
- * wants to handle origin adjustments in some other manner. coordChangeMatrix is the matrix
- * from GrEffectStage.
+ * NULL when not using the EffectMatrix for a texture lookup, or if the GrGLEffect subclass
+ * wants to handle origin adjustments in some other manner. The coords type param must match the
+ * param that would be used to initialize GrGLEffectMatrix for the generating GrEffect.
*/
static EffectKey GenKey(const SkMatrix& effectMatrix,
- const SkMatrix& coordChangeMatrix,
+ const GrDrawEffect&,
+ CoordsType,
const GrTexture*);
/**
@@ -55,7 +89,6 @@
*/
GrSLType emitCode(GrGLShaderBuilder*,
EffectKey,
- const char* vertexCoords,
const char** fsCoordName, /* optional */
const char** vsCoordName = NULL,
const char* suffix = NULL);
@@ -66,31 +99,23 @@
*/
void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
EffectKey,
- const char* vertexCoords,
const char** fsCoordName, /* optional */
const char** vsVaryingName = NULL,
GrSLType* vsVaryingType = NULL,
const char* suffix = NULL);
/**
- * Call from a GrGLEffect's subclass to update the texture matrix. The matrix,
- * coordChangeMatrix, and texture params should match those used with GenKey.
+ * Call from a GrGLEffect's subclass to update the texture matrix. The effectMatrix and texture
+ * params should match those used with GenKey.
*/
void setData(const GrGLUniformManager& uniformManager,
const SkMatrix& effectMatrix,
- const SkMatrix& coordChangeMatrix,
+ const GrDrawEffect& drawEffect,
const GrTexture*);
-private:
- enum {
- kIdentity_Key = 0,
- kTrans_Key = 1,
- kNoPersp_Key = 2,
- kGeneral_Key = 3,
- };
-
GrGLUniformManager::UniformHandle fUni;
GrSLType fUniType;
SkMatrix fPrevMatrix;
+ CoordsType fCoordsType;
};
#endif
« no previous file with comments | « src/gpu/gl/GrGLEffect.cpp ('k') | src/gpu/gl/GrGLEffectMatrix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698