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

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

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

Powered by Google App Engine
This is Rietveld 408576698