Index: src/gpu/gl/GrGLEffectMatrix.h |
=================================================================== |
--- src/gpu/gl/GrGLEffectMatrix.h (revision 8216) |
+++ src/gpu/gl/GrGLEffectMatrix.h (working copy) |
@@ -14,10 +14,21 @@ |
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 { |
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 |
@@ -25,23 +36,28 @@ |
* the relevant bits must be in the lower kKeyBits of the key parameter. |
*/ |
enum { |
- kKeyBits = 2, |
+ kKeyBits = 3, |
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 +71,6 @@ |
*/ |
GrSLType emitCode(GrGLShaderBuilder*, |
EffectKey, |
- const char* vertexCoords, |
const char** fsCoordName, /* optional */ |
const char** vsCoordName = NULL, |
const char* suffix = NULL); |
@@ -66,31 +81,36 @@ |
*/ |
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, |
+ kIdentity_Key = 0x0, |
+ kTrans_Key = 0x1, |
+ kNoPersp_Key = 0x2, |
+ kGeneral_Key = 0x3, |
+ |
robertphillips
2013/03/19 15:09:38
kMatrixFlagsMask? I misunderstood kMatrixTypeMask
jvanverth1
2013/03/19 15:36:51
Does kGeneral_Key mean (kTrans_Key | kNoPersp_Key)
robertphillips
2013/03/19 15:41:35
How about kMatrixKeys? Jim is right should kGenera
bsalomon
2013/03/19 19:34:43
They aren't meant to be OR'ed together, but rather
|
+ kMatrixTypeMask = 0x3, |
+ |
+ // this bit indicates that the matrix is applied to positions rather than local coords |
+ kPositionCoords_Key = 0x4, |
}; |
GrGLUniformManager::UniformHandle fUni; |
GrSLType fUniType; |
SkMatrix fPrevMatrix; |
+ CoordsType fCoordsType; |
}; |
#endif |