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

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
« no previous file with comments | « src/gpu/gl/GrGLEffect.cpp ('k') | src/gpu/gl/GrGLEffectMatrix.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
28 private:
29 // We specialize the generated code for each of these matrix types.
30 enum MatrixTypes {
31 kIdentity_MatrixType = 0,
32 kTrans_MatrixType = 1,
33 kNoPersp_MatrixType = 2,
34 kGeneral_MatrixType = 3,
35 };
36 // The key for is made up of a matrix type and a bit that indicates the sour ce of the input
37 // coords.
38 enum {
39 kMatrixTypeKeyBits = 2,
40 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
41 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits),
42 kKeyBitsPrivate = kMatrixTypeKeyBits + 1,
43 };
44
20 public: 45 public:
46
47 typedef GrEffect::CoordsType CoordsType;
48
21 typedef GrGLEffect::EffectKey EffectKey; 49 typedef GrGLEffect::EffectKey EffectKey;
50
22 /** 51 /**
23 * The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may plac e these bits at an 52 * 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 53 * 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. 54 * the relevant bits must be in the lower kKeyBits of the key parameter.
26 */ 55 */
27 enum { 56 enum {
28 kKeyBits = 2, 57 kKeyBits = kKeyBitsPrivate,
29 kKeyMask = (1 << kKeyBits) - 1, 58 kKeyMask = (1 << kKeyBits) - 1,
30 }; 59 };
31 60
32 GrGLEffectMatrix() : fUni(GrGLUniformManager::kInvalidUniformHandle) { 61 GrGLEffectMatrix(CoordsType coordsType)
62 : fUni(GrGLUniformManager::kInvalidUniformHandle)
63 , fCoordsType(coordsType) {
64 GrAssert(GrEffect::kLocal_CoordsType == coordsType ||
65 GrEffect::kPosition_CoordsType == coordsType);
33 fPrevMatrix = SkMatrix::InvalidMatrix(); 66 fPrevMatrix = SkMatrix::InvalidMatrix();
34 } 67 }
35 68
36 /** 69 /**
37 * Generates the key for the portion of the code emitted by this class's emi tCode() function. 70 * 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 71 * 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 72 * 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 73 * wants to handle origin adjustments in some other manner. The coords type param must match the
41 * from GrEffectStage. 74 * param that would be used to initialize GrGLEffectMatrix for the generatin g GrEffect.
42 */ 75 */
43 static EffectKey GenKey(const SkMatrix& effectMatrix, 76 static EffectKey GenKey(const SkMatrix& effectMatrix,
44 const SkMatrix& coordChangeMatrix, 77 const GrDrawEffect&,
78 CoordsType,
45 const GrTexture*); 79 const GrTexture*);
46 80
47 /** 81 /**
48 * Emits code to implement the matrix in the VS. A varying is added as an ou tput of the VS and 82 * 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 83 * 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 84 * 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 85 * 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 86 * 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 87 * unique within a stage. It is only necessary if multiple GrGLEffectMatrix objects are used by
54 * a GrGLEffect. 88 * a GrGLEffect.
55 */ 89 */
56 GrSLType emitCode(GrGLShaderBuilder*, 90 GrSLType emitCode(GrGLShaderBuilder*,
57 EffectKey, 91 EffectKey,
58 const char* vertexCoords,
59 const char** fsCoordName, /* optional */ 92 const char** fsCoordName, /* optional */
60 const char** vsCoordName = NULL, 93 const char** vsCoordName = NULL,
61 const char* suffix = NULL); 94 const char* suffix = NULL);
62 95
63 /** 96 /**
64 * This is similar to emitCode except that it performs perspective division in the FS if the 97 * 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. 98 * texture coordinates have a w coordinate. The fsCoordName always refers to a vec2f.
66 */ 99 */
67 void emitCodeMakeFSCoords2D(GrGLShaderBuilder*, 100 void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
68 EffectKey, 101 EffectKey,
69 const char* vertexCoords,
70 const char** fsCoordName, /* optional */ 102 const char** fsCoordName, /* optional */
71 const char** vsVaryingName = NULL, 103 const char** vsVaryingName = NULL,
72 GrSLType* vsVaryingType = NULL, 104 GrSLType* vsVaryingType = NULL,
73 const char* suffix = NULL); 105 const char* suffix = NULL);
74 /** 106 /**
75 * Call from a GrGLEffect's subclass to update the texture matrix. The matri x, 107 * 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 . 108 * params should match those used with GenKey.
77 */ 109 */
78 void setData(const GrGLUniformManager& uniformManager, 110 void setData(const GrGLUniformManager& uniformManager,
79 const SkMatrix& effectMatrix, 111 const SkMatrix& effectMatrix,
80 const SkMatrix& coordChangeMatrix, 112 const GrDrawEffect& drawEffect,
81 const GrTexture*); 113 const GrTexture*);
82 114
83 private:
84 enum {
85 kIdentity_Key = 0,
86 kTrans_Key = 1,
87 kNoPersp_Key = 2,
88 kGeneral_Key = 3,
89 };
90
91 GrGLUniformManager::UniformHandle fUni; 115 GrGLUniformManager::UniformHandle fUni;
92 GrSLType fUniType; 116 GrSLType fUniType;
93 SkMatrix fPrevMatrix; 117 SkMatrix fPrevMatrix;
118 CoordsType fCoordsType;
94 }; 119 };
95 120
96 #endif 121 #endif
OLDNEW
« 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