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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 63 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint |
64 * equivalents are set to default values with the exception of vertex attrib
ute state which | 64 * equivalents are set to default values with the exception of vertex attrib
ute state which |
65 * is unmodified by this function and clipping which will be enabled. | 65 * is unmodified by this function and clipping which will be enabled. |
66 */ | 66 */ |
67 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); | 67 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); |
68 | 68 |
69 /////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////// |
70 /// @name Vertex Attributes | 70 /// @name Vertex Attributes |
71 //// | 71 //// |
72 | 72 |
73 enum { | 73 // TODO when we move this info off of GrGeometryProcessor, delete these |
74 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, | |
75 }; | |
76 | |
77 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } | |
78 int getVertexAttribCount() const { return fVACount; } | |
79 | |
80 size_t getVertexStride() const { return fVAStride; } | |
81 | |
82 bool hasLocalCoordAttribute() const { | 74 bool hasLocalCoordAttribute() const { |
83 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri
bBinding]; | 75 return this->hasGeometryProcessor() && this->getGeometryProcessor()->has
LocalCoords(); |
84 } | 76 } |
85 bool hasColorVertexAttribute() const { | 77 bool hasColorVertexAttribute() const { |
86 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind
ing]; | 78 return this->hasGeometryProcessor() && this->getGeometryProcessor()->has
VertexColor(); |
87 } | 79 } |
88 bool hasCoverageVertexAttribute() const { | 80 bool hasCoverageVertexAttribute() const { |
89 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB
inding]; | 81 return this->hasGeometryProcessor() && this->getGeometryProcessor()->has
VertexCoverage(); |
90 } | 82 } |
91 | 83 |
92 const int* getFixedFunctionVertexAttribIndices() const { | |
93 return fFixedFunctionVertexAttribIndices; | |
94 } | |
95 | |
96 bool validateVertexAttribs() const; | |
97 | |
98 /** | |
99 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing | |
100 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in | |
101 * GrTypesPriv.h). | |
102 * | |
103 * The mapping of attributes with kEffect bindings to GrProcessor inputs is
specified when | |
104 * setEffect is called. | |
105 */ | |
106 | |
107 /** | |
108 * Sets vertex attributes for next draw. The object driving the templatizat
ion | |
109 * should be a global GrVertexAttrib array that is never changed. | |
110 * | |
111 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | |
112 * @param stride the number of bytes between successive vertex data. | |
113 */ | |
114 template <const GrVertexAttrib A[]> void setVertexAttribs(int count, size_t
stride) { | |
115 this->internalSetVertexAttribs(A, count, stride); | |
116 } | |
117 | |
118 /** | |
119 * Sets default vertex attributes for next draw. The default is a single at
tribute: | |
120 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} | |
121 */ | |
122 void setDefaultVertexAttribs(); | |
123 | |
124 /** | |
125 * Helper to save/restore vertex attribs | |
126 */ | |
127 class AutoVertexAttribRestore { | |
128 public: | |
129 AutoVertexAttribRestore(GrDrawState* drawState); | |
130 | |
131 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt
r, fVACount, | |
132 fVASt
ride); } | |
133 | |
134 private: | |
135 GrDrawState* fDrawState; | |
136 const GrVertexAttrib* fVAPtr; | |
137 int fVACount; | |
138 size_t fVAStride; | |
139 }; | |
140 | |
141 /// @} | 84 /// @} |
142 | 85 |
143 /** | 86 /** |
144 * Depending on features available in the underlying 3D API and the color bl
end mode requested | 87 * Depending on features available in the underlying 3D API and the color bl
end mode requested |
145 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by | 88 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by |
146 * the fragment shader. | 89 * the fragment shader. |
147 * | 90 * |
148 * This function considers the current draw state and the draw target's capa
bilities to | 91 * This function considers the current draw state and the draw target's capa
bilities to |
149 * determine whether coverage can be handled correctly. This function assume
s that the caller | 92 * determine whether coverage can be handled correctly. This function assume
s that the caller |
150 * intends to specify fractional pixel coverage (via setCoverage(), through
a coverage vertex | 93 * intends to specify fractional pixel coverage (via setCoverage(), through
a coverage vertex |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 * stages and results are stored in fCoverageProcInfo. | 701 * stages and results are stored in fCoverageProcInfo. |
759 */ | 702 */ |
760 void calcCoverageInvariantOutput() const; | 703 void calcCoverageInvariantOutput() const; |
761 | 704 |
762 void onReset(const SkMatrix* initialViewMatrix); | 705 void onReset(const SkMatrix* initialViewMatrix); |
763 | 706 |
764 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 707 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
765 // This is used to assert that this condition holds. | 708 // This is used to assert that this condition holds. |
766 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 709 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
767 | 710 |
768 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); | |
769 | |
770 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 711 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
771 | 712 |
772 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 713 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
773 GrColor fColor; | 714 GrColor fColor; |
774 SkMatrix fViewMatrix; | 715 SkMatrix fViewMatrix; |
775 GrColor fBlendConstant; | 716 GrColor fBlendConstant; |
776 uint32_t fFlagBits; | 717 uint32_t fFlagBits; |
777 const GrVertexAttrib* fVAPtr; | |
778 int fVACount; | |
779 size_t fVAStride; | |
780 GrStencilSettings fStencilSettings; | 718 GrStencilSettings fStencilSettings; |
781 uint8_t fCoverage; | 719 uint8_t fCoverage; |
782 DrawFace fDrawFace; | 720 DrawFace fDrawFace; |
783 GrBlendCoeff fSrcBlend; | 721 GrBlendCoeff fSrcBlend; |
784 GrBlendCoeff fDstBlend; | 722 GrBlendCoeff fDstBlend; |
785 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | 723 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
786 FragmentStageArray fColorStages; | 724 FragmentStageArray fColorStages; |
787 FragmentStageArray fCoverageStages; | 725 FragmentStageArray fCoverageStages; |
788 uint32_t fHints; | 726 uint32_t fHints; |
789 | 727 |
790 // This is simply a different representation of info in fVertexAttribs and t
hus does | |
791 // not need to be compared in op==. | |
792 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; | |
793 | |
794 mutable GrProcOptInfo fColorProcInfo; | 728 mutable GrProcOptInfo fColorProcInfo; |
795 mutable GrProcOptInfo fCoverageProcInfo; | 729 mutable GrProcOptInfo fCoverageProcInfo; |
796 mutable bool fColorProcInfoValid; | 730 mutable bool fColorProcInfoValid; |
797 mutable bool fCoverageProcInfoValid; | 731 mutable bool fCoverageProcInfoValid; |
798 | 732 |
799 friend class GrOptDrawState; | 733 friend class GrOptDrawState; |
800 }; | 734 }; |
801 | 735 |
802 #endif | 736 #endif |
OLD | NEW |