OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 /** | 113 /** |
114 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing | 114 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing |
115 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in | 115 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in |
116 * GrTypesPriv.h). | 116 * GrTypesPriv.h). |
117 * | 117 * |
118 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe
cified when | 118 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe
cified when |
119 * setEffect is called. | 119 * setEffect is called. |
120 */ | 120 */ |
121 | 121 |
122 /** | 122 /** |
123 * Sets vertex attributes for next draw. | 123 * Sets vertex attributes for next draw. The object driving the templatizat
ion |
124 * | 124 * should be a global GrVertexAttrib array that is never changed. |
125 * @param attribs the array of vertex attributes to set. | |
126 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | |
127 */ | 125 */ |
128 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 126 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { |
| 127 this->setVertexAttribs(A, count); |
| 128 } |
129 | 129 |
130 const GrVertexAttrib* getVertexAttribs() const { return fCommon.fVertexAttri
bs.begin(); } | 130 const GrVertexAttrib* getVertexAttribs() const { return fCommon.fVAPtr; } |
131 int getVertexAttribCount() const { return fCommon.fVertexAttribs.count(); } | 131 int getVertexAttribCount() const { return fCommon.fVACount; } |
132 | 132 |
133 size_t getVertexSize() const; | 133 size_t getVertexSize() const; |
134 | 134 |
135 /** | 135 /** |
136 * Sets default vertex attributes for next draw. The default is a single at
tribute: | 136 * Sets default vertex attributes for next draw. The default is a single at
tribute: |
137 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} | 137 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} |
138 */ | 138 */ |
139 void setDefaultVertexAttribs(); | 139 void setDefaultVertexAttribs(); |
140 | 140 |
141 /** | 141 /** |
(...skipping 28 matching lines...) Expand all Loading... |
170 bool validateVertexAttribs() const; | 170 bool validateVertexAttribs() const; |
171 | 171 |
172 /** | 172 /** |
173 * Helper to save/restore vertex attribs | 173 * Helper to save/restore vertex attribs |
174 */ | 174 */ |
175 class AutoVertexAttribRestore { | 175 class AutoVertexAttribRestore { |
176 public: | 176 public: |
177 AutoVertexAttribRestore(GrDrawState* drawState) { | 177 AutoVertexAttribRestore(GrDrawState* drawState) { |
178 GrAssert(NULL != drawState); | 178 GrAssert(NULL != drawState); |
179 fDrawState = drawState; | 179 fDrawState = drawState; |
180 fVertexAttribs = drawState->fCommon.fVertexAttribs; | 180 fVAPtr = drawState->fCommon.fVAPtr; |
| 181 fVACount = drawState->fCommon.fVACount; |
181 fDrawState->setDefaultVertexAttribs(); | 182 fDrawState->setDefaultVertexAttribs(); |
182 } | 183 } |
183 | 184 |
184 ~AutoVertexAttribRestore(){ | 185 ~AutoVertexAttribRestore(){ |
185 fDrawState->fCommon.fVertexAttribs = fVertexAttribs; | 186 fDrawState->fCommon.fVAPtr = fVAPtr; |
| 187 fDrawState->fCommon.fVACount = fVACount; |
186 } | 188 } |
187 | 189 |
188 private: | 190 private: |
189 GrDrawState* fDrawState; | 191 GrDrawState* fDrawState; |
190 GrVertexAttribArray<kMaxVertexAttribCnt> fVertexAttribs; | 192 const GrVertexAttrib* fVAPtr; |
| 193 int fVACount; |
191 }; | 194 }; |
192 | 195 |
193 /** | 196 /** |
194 * Accessing positions, local coords, or colors, of a vertex within an array
is a hassle | 197 * Accessing positions, local coords, or colors, of a vertex within an array
is a hassle |
195 * involving casts and simple math. These helpers exist to keep GrDrawTarget
clients' code a bit | 198 * involving casts and simple math. These helpers exist to keep GrDrawTarget
clients' code a bit |
196 * nicer looking. | 199 * nicer looking. |
197 */ | 200 */ |
198 | 201 |
199 /** | 202 /** |
200 * Gets a pointer to a GrPoint of a vertex's position or texture | 203 * Gets a pointer to a GrPoint of a vertex's position or texture |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 } | 1030 } |
1028 } | 1031 } |
1029 return *this; | 1032 return *this; |
1030 } | 1033 } |
1031 | 1034 |
1032 private: | 1035 private: |
1033 | 1036 |
1034 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ | 1037 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ |
1035 struct CommonState { | 1038 struct CommonState { |
1036 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== | 1039 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== |
1037 GrColor fColor; | 1040 GrColor fColor; |
1038 SkMatrix fViewMatrix; | 1041 SkMatrix fViewMatrix; |
1039 GrBlendCoeff fSrcBlend; | 1042 GrBlendCoeff fSrcBlend; |
1040 GrBlendCoeff fDstBlend; | 1043 GrBlendCoeff fDstBlend; |
1041 GrColor fBlendConstant; | 1044 GrColor fBlendConstant; |
1042 uint32_t fFlagBits; | 1045 uint32_t fFlagBits; |
1043 GrVertexAttribArray<kMaxVertexAttribCnt> fVertexAttribs; | 1046 const GrVertexAttrib* fVAPtr; |
1044 GrStencilSettings fStencilSettings; | 1047 int fVACount; |
1045 int fFirstCoverageStage; | 1048 GrStencilSettings fStencilSettings; |
1046 GrColor fCoverage; | 1049 int fFirstCoverageStage; |
1047 SkXfermode::Mode fColorFilterMode; | 1050 GrColor fCoverage; |
1048 GrColor fColorFilterColor; | 1051 SkXfermode::Mode fColorFilterMode; |
1049 DrawFace fDrawFace; | 1052 GrColor fColorFilterColor; |
| 1053 DrawFace fDrawFace; |
1050 | 1054 |
1051 // This is simply a different representation of info in fVertexAttribs a
nd thus does | 1055 // This is simply a different representation of info in fVertexAttribs a
nd thus does |
1052 // not need to be compared in op==. | 1056 // not need to be compared in op==. |
1053 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin
gCnt]; | 1057 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin
gCnt]; |
1054 | 1058 |
1055 bool operator== (const CommonState& other) const { | 1059 bool operator== (const CommonState& other) const { |
1056 bool result = fColor == other.fColor && | 1060 bool result = fColor == other.fColor && |
1057 fViewMatrix.cheapEqualTo(other.fViewMatrix) && | 1061 fViewMatrix.cheapEqualTo(other.fViewMatrix) && |
1058 fSrcBlend == other.fSrcBlend && | 1062 fSrcBlend == other.fSrcBlend && |
1059 fDstBlend == other.fDstBlend && | 1063 fDstBlend == other.fDstBlend && |
1060 fBlendConstant == other.fBlendConstant && | 1064 fBlendConstant == other.fBlendConstant && |
1061 fFlagBits == other.fFlagBits && | 1065 fFlagBits == other.fFlagBits && |
1062 fVertexAttribs == other.fVertexAttribs && | 1066 fVACount == other.fVACount && |
| 1067 !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVert
exAttrib)) && |
1063 fStencilSettings == other.fStencilSettings && | 1068 fStencilSettings == other.fStencilSettings && |
1064 fFirstCoverageStage == other.fFirstCoverageStage && | 1069 fFirstCoverageStage == other.fFirstCoverageStage && |
1065 fCoverage == other.fCoverage && | 1070 fCoverage == other.fCoverage && |
1066 fColorFilterMode == other.fColorFilterMode && | 1071 fColorFilterMode == other.fColorFilterMode && |
1067 fColorFilterColor == other.fColorFilterColor && | 1072 fColorFilterColor == other.fColorFilterColor && |
1068 fDrawFace == other.fDrawFace; | 1073 fDrawFace == other.fDrawFace; |
1069 GrAssert(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, | 1074 GrAssert(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, |
1070 other.fFixedFunctionVertexAttribIndi
ces, | 1075 other.fFixedFunctionVertexAttribIndi
ces, |
1071 sizeof(fFixedFunctionVertexAttribInd
ices))); | 1076 sizeof(fFixedFunctionVertexAttribInd
ices))); |
1072 return result; | 1077 return result; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 | 1144 |
1140 GR_DEBUGCODE(bool fInitialized;) | 1145 GR_DEBUGCODE(bool fInitialized;) |
1141 }; | 1146 }; |
1142 | 1147 |
1143 private: | 1148 private: |
1144 | 1149 |
1145 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 1150 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
1146 CommonState fCommon; | 1151 CommonState fCommon; |
1147 GrEffectStage fStages[kNumStages]; | 1152 GrEffectStage fStages[kNumStages]; |
1148 | 1153 |
| 1154 /** |
| 1155 * Sets vertex attributes for next draw. |
| 1156 * |
| 1157 * @param attribs the array of vertex attributes to set. |
| 1158 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
| 1159 */ |
| 1160 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
| 1161 |
1149 typedef GrRefCnt INHERITED; | 1162 typedef GrRefCnt INHERITED; |
1150 }; | 1163 }; |
1151 | 1164 |
1152 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1165 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1153 | 1166 |
1154 #endif | 1167 #endif |
OLD | NEW |