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

Side by Side Diff: src/gpu/gl/GrGLEffectMatrix.h

Issue 24853002: Make GPU coord transforms automatic (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrGLEffectMatrix_DEFINED
9 #define GrGLEffectMatrix_DEFINED
10
11 #include "GrGLEffect.h"
12 #include "SkMatrix.h"
13
14 class GrTexture;
15
16 /**
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.
26 */
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
45 public:
46
47 typedef GrEffect::CoordsType CoordsType;
48
49 typedef GrGLEffect::EffectKey EffectKey;
50
51 /**
52 * The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may plac e these bits at an
53 * arbitrary shift in its final key. However, when GrGLEffectMatrix::emitCod e*() code is called
54 * the relevant bits must be in the lower kKeyBits of the key parameter.
55 */
56 enum {
57 kKeyBits = kKeyBitsPrivate,
58 kKeyMask = (1 << kKeyBits) - 1,
59 };
60
61 GrGLEffectMatrix(CoordsType coordsType)
62 : fCoordsType(coordsType) {
63 fPrevMatrix = SkMatrix::InvalidMatrix();
64 }
65
66 /**
67 * Generates the key for the portion of the code emitted by this class's emi tCode() function.
68 * Pass a texture to make GrGLEffectMatrix automatically adjust for the text ure's origin. Pass
69 * NULL when not using the EffectMatrix for a texture lookup, or if the GrGL Effect subclass
70 * wants to handle origin adjustments in some other manner. The coords type param must match the
71 * param that would be used to initialize GrGLEffectMatrix for the generatin g GrEffect.
72 */
73 static EffectKey GenKey(const SkMatrix& effectMatrix,
74 const GrDrawEffect&,
75 CoordsType,
76 const GrTexture*);
77
78 /**
79 * Emits code to implement the matrix in the VS. A varying is added as an ou tput of the VS and
80 * input to the FS. The varying may be either a vec2f or vec3f depending upo n whether
81 * perspective interpolation is required or not. The names of the varying in the VS and FS are
82 * are returned as output parameters and the type of the varying is the retu rn value. The suffix
83 * is an optional parameter that can be used to make all variables emitted b y the object
84 * unique within a stage. It is only necessary if multiple GrGLEffectMatrix objects are used by
85 * a single GrGLEffect.
86 */
87 GrSLType emitCode(GrGLShaderBuilder*,
88 EffectKey,
89 SkString* fsCoordName, /* optional */
90 SkString* vsCoordName = NULL,
91 const char* suffix = NULL);
92
93 /**
94 * This is similar to emitCode except that it performs perspective division in the FS if the
95 * texture coordinates have a w coordinate. The fsCoordName always refers to a vec2f.
96 */
97 void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
98 EffectKey,
99 SkString* fsCoordName, /* optional */
100 SkString* vsVaryingName = NULL,
101 GrSLType* vsVaryingType = NULL,
102 const char* suffix = NULL);
103 /**
104 * Call from a GrGLEffect's subclass to update the texture matrix. The effec tMatrix and texture
105 * params should match those used with GenKey.
106 */
107 void setData(const GrGLUniformManager& uniformManager,
108 const SkMatrix& effectMatrix,
109 const GrDrawEffect& drawEffect,
110 const GrTexture*);
111
112 GrGLUniformManager::UniformHandle fUni;
113 GrSLType fUniType;
114 SkMatrix fPrevMatrix;
115 CoordsType fCoordsType;
116 };
117
118 #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