OLD | NEW |
| (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 GrGLCoordTransform_DEFINED | |
9 #define GrGLCoordTransform_DEFINED | |
10 | |
11 #include "GrBackendEffectFactory.h" | |
12 #include "GrCoordTransform.h" | |
13 #include "GrGLUniformManager.h" | |
14 | |
15 class GrTexture; | |
16 class GrGLShaderBuilder; | |
17 | |
18 /** | |
19 * This is a helper class used by the framework to implement a coordinate transf
orm that operates on | |
20 * incoming coords in the vertex shader and writes them to a varying to be used
in the fragment | |
21 * shader. Effects should not use this class directly, but instead call GrEffect
::addCoordTransform. | |
22 * When the input coords are local coordinates this class accounts for the coord
change matrix | |
23 * communicated via GrDrawEffect. The input coords may also be positions and in
this case the coord | |
24 * change matrix is ignored. The GrGLCoordTransform may emit different code base
d on the type of | |
25 * matrix and thus must contribute to the effect's key. | |
26 * | |
27 * This class cannot be used to apply a matrix to coordinates that come in the f
orm of custom vertex | |
28 * attributes. | |
29 */ | |
30 class GrGLCoordTransform { | |
31 private: | |
32 // We specialize the generated code for each of these matrix types. | |
33 enum MatrixTypes { | |
34 kIdentity_MatrixType = 0, | |
35 kTrans_MatrixType = 1, | |
36 kNoPersp_MatrixType = 2, | |
37 kGeneral_MatrixType = 3, | |
38 }; | |
39 // The key for is made up of a matrix type and a bit that indicates the sour
ce of the input | |
40 // coords. | |
41 enum { | |
42 kMatrixTypeKeyBits = 2, | |
43 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, | |
44 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits), | |
45 kKeyBitsPrivate = kMatrixTypeKeyBits + 1, | |
46 }; | |
47 | |
48 public: | |
49 | |
50 typedef GrBackendEffectFactory::EffectKey EffectKey; | |
51 | |
52 /** | |
53 * A GrGLCoordTransform key is kKeyBits long. The framework automatically ge
nerates and includes | |
54 * these in EffectKeys. | |
55 */ | |
56 enum { | |
57 kKeyBits = kKeyBitsPrivate, | |
58 kKeyMask = (1 << kKeyBits) - 1, | |
59 }; | |
60 | |
61 GrGLCoordTransform() { fPrevMatrix = SkMatrix::InvalidMatrix(); } | |
62 | |
63 /** | |
64 * Generates the key for the portion of the code emitted by this class's emi
tCode() function. | |
65 */ | |
66 static EffectKey GenKey(const GrDrawEffect&, int transformIdx); | |
67 | |
68 /** | |
69 * Stores the name and type of a transformed set of coordinates. This class
is passed to | |
70 * GrGLEffect::emitCode. | |
71 */ | |
72 class TransformedCoords { | |
73 public: | |
74 const char* c_str() const { return fName.c_str(); } | |
75 GrSLType type() const { return fType; } | |
76 const SkString& getName() const { return fName; } | |
77 // TODO: Remove the VS name when we have vertexless shaders, and gradien
ts are reworked. | |
78 const SkString& getVSName() const { return fVSName; } | |
79 | |
80 private: | |
81 friend class GrGLCoordTransform; | |
82 | |
83 SkString fName; | |
84 GrSLType fType; | |
85 SkString fVSName; | |
86 }; | |
87 | |
88 /** | |
89 * Emits code to implement the matrix in the VS. A varying is added as an ou
tput of the VS and | |
90 * input to the FS. The varying may be either a vec2f or vec3f depending upo
n whether | |
91 * perspective interpolation is required or not. The names of the varying in
the VS and FS as | |
92 * well as its type are written to the TransformedCoords* object. The suffix
is an optional | |
93 * parameter that can be used to make all variables emitted by the object un
ique within a stage. | |
94 * It is only necessary if multiple GrGLCoordTransform objects are used by a
single GrGLEffect. | |
95 */ | |
96 void emitCode(GrGLShaderBuilder*, EffectKey, TransformedCoords*, int suffix
= 0); | |
97 | |
98 /** | |
99 * Call from a GrGLEffect's subclass to update the texture matrix. The matri
x and reverseY value | |
100 * should match those used with GenKey. | |
101 */ | |
102 void setData(const GrGLUniformManager&, const GrDrawEffect&, int transformId
x); | |
103 | |
104 GrGLUniformManager::UniformHandle fUni; | |
105 GrSLType fUniType; | |
106 SkMatrix fPrevMatrix; | |
107 }; | |
108 | |
109 #endif | |
OLD | NEW |