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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGLEffectMatrix_DEFINED 8 #ifndef GrGLEffectMatrix_DEFINED
9 #define GrGLEffectMatrix_DEFINED 9 #define GrGLEffectMatrix_DEFINED
10 10
11 #include "GrGLEffect.h" 11 #include "GrGLEffect.h"
12 #include "SkMatrix.h" 12 #include "SkMatrix.h"
13 13
14 class GrTexture; 14 class GrTexture;
15 15
16 /** 16 /**
17 * This is a helper to implement a texture matrix in a GrGLEffect. 17 * This is a helper to implement a matrix in a GrGLEffect that operates on incom ing coords in the
18 * vertex shader and writes them to an attribute to be used in the fragment shad er. When the input
19 * coords in the vertex shader are local coordinates this class accounts for the coord change matrix
20 * communicated via GrDrawEffect. The input coords may also be positions and in this case the coord
21 * change matrix is ignored. The GrGLEffectMatrix will emit different code based on the type of
22 * matrix and thus must contribute to the effect's key.
23 *
24 * This class cannot be used to apply a matrix to coordinates that come in the f orm of custom vertex
25 * attributes.
18 */ 26 */
19 class GrGLEffectMatrix { 27 class GrGLEffectMatrix {
20 public: 28 public:
29
30 typedef GrEffect::CoordsType CoordsType;
31
21 typedef GrGLEffect::EffectKey EffectKey; 32 typedef GrGLEffect::EffectKey EffectKey;
22 /** 33 /**
23 * The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may plac e these bits at an 34 * The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may plac e these bits at an
24 * arbitrary shift in its final key. However, when GrGLEffectMatrix::emitCod e*() code is called 35 * arbitrary shift in its final key. However, when GrGLEffectMatrix::emitCod e*() code is called
25 * the relevant bits must be in the lower kKeyBits of the key parameter. 36 * the relevant bits must be in the lower kKeyBits of the key parameter.
26 */ 37 */
27 enum { 38 enum {
28 kKeyBits = 2, 39 kKeyBits = 3,
29 kKeyMask = (1 << kKeyBits) - 1, 40 kKeyMask = (1 << kKeyBits) - 1,
30 }; 41 };
31 42
32 GrGLEffectMatrix() : fUni(GrGLUniformManager::kInvalidUniformHandle) { 43 GrGLEffectMatrix(CoordsType coordsType)
44 : fUni(GrGLUniformManager::kInvalidUniformHandle)
45 , fCoordsType(coordsType) {
46 GrAssert(GrEffect::kLocal_CoordsType == coordsType ||
47 GrEffect::kPosition_CoordsType == coordsType);
33 fPrevMatrix = SkMatrix::InvalidMatrix(); 48 fPrevMatrix = SkMatrix::InvalidMatrix();
34 } 49 }
35 50
36 /** 51 /**
37 * Generates the key for the portion of the code emitted by this class's emi tCode() function. 52 * Generates the key for the portion of the code emitted by this class's emi tCode() function.
38 * Pass a texture to make GrGLEffectMatrix automatically adjust for the text ure's origin. Pass 53 * Pass a texture to make GrGLEffectMatrix automatically adjust for the text ure's origin. Pass
39 * NULL when not using the EffectMatrix for a texture lookups, or if the GrG LEffect subclass 54 * NULL when not using the EffectMatrix for a texture lookup, or if the GrGL Effect subclass
40 * wants to handle origin adjustments in some other manner. coordChangeMatri x is the matrix 55 * wants to handle origin adjustments in some other manner. The coords type param must match the
41 * from GrEffectStage. 56 * param that would be used to initialize GrGLEffectMatrix for the generatin g GrEffect.
42 */ 57 */
43 static EffectKey GenKey(const SkMatrix& effectMatrix, 58 static EffectKey GenKey(const SkMatrix& effectMatrix,
44 const SkMatrix& coordChangeMatrix, 59 const GrDrawEffect&,
60 CoordsType,
45 const GrTexture*); 61 const GrTexture*);
46 62
47 /** 63 /**
48 * Emits code to implement the matrix in the VS. A varying is added as an ou tput of the VS and 64 * Emits code to implement the matrix in the VS. A varying is added as an ou tput of the VS and
49 * input to the FS. The varying may be either a vec2f or vec3f depending upo n whether 65 * input to the FS. The varying may be either a vec2f or vec3f depending upo n whether
50 * perspective interpolation is required or not. The names of the varying in the VS and FS are 66 * perspective interpolation is required or not. The names of the varying in the VS and FS are
51 * are returned as output parameters and the type of the varying is the retu rn value. The suffix 67 * are returned as output parameters and the type of the varying is the retu rn value. The suffix
52 * is an optional parameter that can be used to make all variables emitted b y the object 68 * is an optional parameter that can be used to make all variables emitted b y the object
53 * unique within a stage. It is only necessary if multiple GrGLEffectMatrix objects are used by 69 * unique within a stage. It is only necessary if multiple GrGLEffectMatrix objects are used by
54 * a GrGLEffect. 70 * a GrGLEffect.
55 */ 71 */
56 GrSLType emitCode(GrGLShaderBuilder*, 72 GrSLType emitCode(GrGLShaderBuilder*,
57 EffectKey, 73 EffectKey,
58 const char* vertexCoords,
59 const char** fsCoordName, /* optional */ 74 const char** fsCoordName, /* optional */
60 const char** vsCoordName = NULL, 75 const char** vsCoordName = NULL,
61 const char* suffix = NULL); 76 const char* suffix = NULL);
62 77
63 /** 78 /**
64 * This is similar to emitCode except that it performs perspective division in the FS if the 79 * This is similar to emitCode except that it performs perspective division in the FS if the
65 * texture coordinates have a w coordinate. The fsCoordName always refers to a vec2f. 80 * texture coordinates have a w coordinate. The fsCoordName always refers to a vec2f.
66 */ 81 */
67 void emitCodeMakeFSCoords2D(GrGLShaderBuilder*, 82 void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
68 EffectKey, 83 EffectKey,
69 const char* vertexCoords,
70 const char** fsCoordName, /* optional */ 84 const char** fsCoordName, /* optional */
71 const char** vsVaryingName = NULL, 85 const char** vsVaryingName = NULL,
72 GrSLType* vsVaryingType = NULL, 86 GrSLType* vsVaryingType = NULL,
73 const char* suffix = NULL); 87 const char* suffix = NULL);
74 /** 88 /**
75 * Call from a GrGLEffect's subclass to update the texture matrix. The matri x, 89 * Call from a GrGLEffect's subclass to update the texture matrix. The effec tMatrix and texture
76 * coordChangeMatrix, and texture params should match those used with GenKey . 90 * params should match those used with GenKey.
77 */ 91 */
78 void setData(const GrGLUniformManager& uniformManager, 92 void setData(const GrGLUniformManager& uniformManager,
79 const SkMatrix& effectMatrix, 93 const SkMatrix& effectMatrix,
80 const SkMatrix& coordChangeMatrix, 94 const GrDrawEffect& drawEffect,
81 const GrTexture*); 95 const GrTexture*);
82 96
83 private: 97 private:
84 enum { 98 enum {
85 kIdentity_Key = 0, 99 kIdentity_Key = 0x0,
86 kTrans_Key = 1, 100 kTrans_Key = 0x1,
87 kNoPersp_Key = 2, 101 kNoPersp_Key = 0x2,
88 kGeneral_Key = 3, 102 kGeneral_Key = 0x3,
103
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
104 kMatrixTypeMask = 0x3,
105
106 // this bit indicates that the matrix is applied to positions rather tha n local coords
107 kPositionCoords_Key = 0x4,
89 }; 108 };
90 109
91 GrGLUniformManager::UniformHandle fUni; 110 GrGLUniformManager::UniformHandle fUni;
92 GrSLType fUniType; 111 GrSLType fUniType;
93 SkMatrix fPrevMatrix; 112 SkMatrix fPrevMatrix;
113 CoordsType fCoordsType;
94 }; 114 };
95 115
96 #endif 116 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698