• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // GLES1State.h: Defines the GLES1State class holding the state of
8 // a GLES1 context.
9 
10 #ifndef LIBANGLE_GLES1STATE_H_
11 #define LIBANGLE_GLES1STATE_H_
12 
13 #include <unordered_set>
14 
15 #include "common/FixedVector.h"
16 #include "common/angleutils.h"
17 #include "common/bitset_utils.h"
18 #include "common/matrix_utils.h"
19 #include "common/vector_utils.h"
20 #include "libANGLE/Caps.h"
21 #include "libANGLE/angletypes.h"
22 
23 namespace gl
24 {
25 
26 // State types specific to GLES1 contexts, from the OpenGL ES 1.1 spec "State Tables" section
27 struct TextureCoordF
28 {
29     TextureCoordF();
30     TextureCoordF(float _s, float _t, float _r, float _q);
31     bool operator==(const TextureCoordF &other) const;
32 
33     GLfloat s = 0.0f;
34     GLfloat t = 0.0f;
35     GLfloat r = 0.0f;
36     GLfloat q = 0.0f;
37 };
38 
39 struct MaterialParameters
40 {
41     MaterialParameters();
42 
43     ColorF ambient;
44     ColorF diffuse;
45     ColorF specular;
46     ColorF emissive;
47     GLfloat specularExponent;
48 };
49 
50 struct LightModelParameters
51 {
52     LightModelParameters();
53 
54     ColorF color;
55     bool twoSided;
56 };
57 
58 struct LightParameters
59 {
60     LightParameters();
61     LightParameters(const LightParameters &other);
62 
63     bool enabled                 = false;
64     ColorF ambient               = {0.0f, 0.0f, 0.0f, 1.0f};
65     ColorF diffuse               = {0.0f, 0.0f, 0.0f, 1.0f};
66     ColorF specular              = {0.0f, 0.0f, 0.0f, 1.0f};
67     angle::Vector4 position      = {0.0f, 0.0f, 1.0f, 0.0f};
68     angle::Vector3 direction     = {0.0f, 0.0f, -1.0f};
69     GLfloat spotlightExponent    = 0.0f;
70     GLfloat spotlightCutoffAngle = 180.0f;
71     GLfloat attenuationConst     = 1.0f;
72     GLfloat attenuationLinear    = 0.0f;
73     GLfloat attenuationQuadratic = 0.0f;
74 };
75 
76 struct FogParameters
77 {
78     FogParameters();
79 
80     FogMode mode;
81     GLfloat density;
82     GLfloat start;
83     GLfloat end;
84     ColorF color;
85 };
86 
87 struct AlphaTestParameters
88 {
89     AlphaTestParameters();
90     bool operator!=(const AlphaTestParameters &other) const;
91 
92     AlphaTestFunc func = AlphaTestFunc::AlwaysPass;
93     GLfloat ref        = 0.0f;
94 };
95 
96 struct TextureEnvironmentParameters
97 {
98     TextureEnvironmentParameters();
99     TextureEnvironmentParameters(const TextureEnvironmentParameters &other);
100 
101     TextureEnvMode mode         = TextureEnvMode::Modulate;
102     TextureCombine combineRgb   = TextureCombine::Modulate;
103     TextureCombine combineAlpha = TextureCombine::Modulate;
104 
105     TextureSrc src0Rgb   = TextureSrc::Texture;
106     TextureSrc src0Alpha = TextureSrc::Texture;
107 
108     TextureSrc src1Rgb   = TextureSrc::Previous;
109     TextureSrc src1Alpha = TextureSrc::Previous;
110 
111     TextureSrc src2Rgb   = TextureSrc::Constant;
112     TextureSrc src2Alpha = TextureSrc::Constant;
113 
114     TextureOp op0Rgb   = TextureOp::SrcColor;
115     TextureOp op0Alpha = TextureOp::SrcAlpha;
116 
117     TextureOp op1Rgb   = TextureOp::SrcColor;
118     TextureOp op1Alpha = TextureOp::SrcAlpha;
119 
120     TextureOp op2Rgb   = TextureOp::SrcAlpha;
121     TextureOp op2Alpha = TextureOp::SrcAlpha;
122 
123     ColorF color       = {0.0f, 0.0f, 0.0f, 0.0f};
124     GLfloat rgbScale   = 1.0f;
125     GLfloat alphaScale = 1.0f;
126 
127     bool pointSpriteCoordReplace = false;
128 
tieTextureEnvironmentParameters129     auto tie() const
130     {
131         return std::tie(mode, combineRgb, combineAlpha, src0Rgb, src0Alpha, src1Rgb, src1Alpha,
132                         src2Rgb, src2Alpha, op0Rgb, op0Alpha, op1Rgb, op1Alpha, op2Rgb, op2Alpha,
133                         color, rgbScale, alphaScale, pointSpriteCoordReplace);
134     }
135 };
136 
137 bool operator==(const TextureEnvironmentParameters &a, const TextureEnvironmentParameters &b);
138 bool operator!=(const TextureEnvironmentParameters &a, const TextureEnvironmentParameters &b);
139 
140 struct PointParameters
141 {
142     PointParameters();
143     PointParameters(const PointParameters &other);
144 
145     GLfloat pointSizeMin                    = 0.0f;
146     GLfloat pointSizeMax                    = 1.0f;
147     GLfloat pointFadeThresholdSize          = 1.0f;
148     angle::Vector3 pointDistanceAttenuation = {1.0f, 0.0f, 0.0f};
149     GLfloat pointSize                       = 1.0f;
150 };
151 
152 struct ClipPlaneParameters
153 {
154     ClipPlaneParameters();
155     ClipPlaneParameters(bool enabled, const angle::Vector4 &equation);
156     ClipPlaneParameters(const ClipPlaneParameters &other);
157     ClipPlaneParameters &operator=(const ClipPlaneParameters &other);
158 
159     bool enabled;
160     angle::Vector4 equation;
161 };
162 
163 class Context;
164 class GLES1Renderer;
165 class PrivateState;
166 
167 class GLES1State final : angle::NonCopyable
168 {
169   public:
170     GLES1State();
171     ~GLES1State();
172 
173     void initialize(const Context *context, const PrivateState *state);
174 
175     void setAlphaTestParameters(AlphaTestFunc func, GLfloat ref);
176     const AlphaTestParameters &getAlphaTestParameters() const;
177 
178     void setClientTextureUnit(unsigned int unit);
179     unsigned int getClientTextureUnit() const;
180 
181     void setCurrentColor(const ColorF &color);
182     const ColorF &getCurrentColor() const;
183 
184     void setCurrentNormal(const angle::Vector3 &normal);
185     const angle::Vector3 &getCurrentNormal() const;
186 
187     void setCurrentTextureCoords(unsigned int unit, const TextureCoordF &coords);
188     const TextureCoordF &getCurrentTextureCoords(unsigned int unit) const;
189 
190     void setMatrixMode(MatrixType mode);
191     MatrixType getMatrixMode() const;
192 
193     GLint getCurrentMatrixStackDepth(GLenum param) const;
194 
195     void pushMatrix();
196     void popMatrix();
197 
198     using MatrixStack = angle::FixedVector<angle::Mat4, Caps::GlobalMatrixStackDepth>;
199     MatrixStack &currentMatrixStack();
200     const MatrixStack &currentMatrixStack() const;
201     const MatrixStack &getMatrixStack(MatrixType mode) const;
202 
203     const angle::Mat4 &getModelviewMatrix() const;
204 
205     void loadMatrix(const angle::Mat4 &m);
206     void multMatrix(const angle::Mat4 &m);
207 
208     void setLogicOpEnabled(bool enabled);
209     void setLogicOp(LogicalOperation opcodePacked);
210 
211     void setClientStateEnabled(ClientVertexArrayType clientState, bool enable);
212     void setTexCoordArrayEnabled(unsigned int unit, bool enable);
213     bool isClientStateEnabled(ClientVertexArrayType clientState) const;
214     bool isTexCoordArrayEnabled(unsigned int unit) const;
215     bool isTextureTargetEnabled(unsigned int unit, const TextureType type) const;
216 
217     LightModelParameters &lightModelParameters();
218     const LightModelParameters &lightModelParameters() const;
219 
220     LightParameters &lightParameters(unsigned int light);
221     const LightParameters &lightParameters(unsigned int light) const;
222 
223     MaterialParameters &materialParameters();
224     const MaterialParameters &materialParameters() const;
225     bool isColorMaterialEnabled() const;
226 
227     void setShadeModel(ShadingModel model);
228 
229     void setClipPlane(unsigned int plane, const GLfloat *equation);
230     void getClipPlane(unsigned int plane, GLfloat *equation) const;
231 
232     FogParameters &fogParameters();
233     const FogParameters &fogParameters() const;
234 
235     TextureEnvironmentParameters &textureEnvironment(unsigned int unit);
236     const TextureEnvironmentParameters &textureEnvironment(unsigned int unit) const;
237 
238     PointParameters &pointParameters();
239     const PointParameters &pointParameters() const;
240 
241     AttributesMask getVertexArraysAttributeMask() const;
242     AttributesMask getActiveAttributesMask() const;
243 
244     bool shouldHandleDirtyProgram();
245 
246     void setHint(GLenum target, GLenum mode);
247     GLenum getHint(GLenum target) const;
248 
249     enum DirtyGles1Type
250     {
251         DIRTY_GLES1_TEXTURE_UNIT_ENABLE = 0,
252         DIRTY_GLES1_CLIENT_STATE_ENABLE,
253         DIRTY_GLES1_FEATURE_ENABLE,
254         DIRTY_GLES1_CURRENT_VECTOR,
255         DIRTY_GLES1_CLIENT_ACTIVE_TEXTURE,
256         DIRTY_GLES1_MATRICES,
257         DIRTY_GLES1_TEXTURE_ENVIRONMENT,
258         DIRTY_GLES1_MATERIAL,
259         DIRTY_GLES1_LIGHTS,
260         DIRTY_GLES1_FOG,
261         DIRTY_GLES1_SHADE_MODEL,
262         DIRTY_GLES1_POINT_PARAMETERS,
263         DIRTY_GLES1_ALPHA_TEST,
264         DIRTY_GLES1_LOGIC_OP,
265         DIRTY_GLES1_CLIP_PLANES,
266         DIRTY_GLES1_HINT_SETTING,
267         DIRTY_GLES1_PROGRAM,
268         DIRTY_GLES1_MAX,
269     };
270 
setAllDirty()271     void setAllDirty() { mDirtyBits.set(); }
272 
273   private:
274     friend class PrivateState;
275     friend class GLES1Renderer;
276 
277     // Back pointer for reading from State.
278     const PrivateState *mGLState;
279 
280     using DirtyBits = angle::BitSet<DIRTY_GLES1_MAX>;
281     DirtyBits mDirtyBits;
282 
setDirty(DirtyGles1Type type)283     void setDirty(DirtyGles1Type type) { mDirtyBits.set(type); }
clearDirty()284     void clearDirty() { mDirtyBits.reset(); }
clearDirtyBits(const DirtyGles1Type & bitset)285     void clearDirtyBits(const DirtyGles1Type &bitset) { mDirtyBits &= ~bitset; }
isDirty(DirtyGles1Type type)286     bool isDirty(DirtyGles1Type type) const { return mDirtyBits.test(type); }
287 
288     // All initial state values come from the
289     // OpenGL ES 1.1 spec.
290     std::vector<angle::PackedEnumBitSet<TextureType>> mTexUnitEnables;
291 
292     // Table 6.4, 6.5 (IsEnabled)
293     bool mVertexArrayEnabled;
294     bool mNormalArrayEnabled;
295     bool mColorArrayEnabled;
296     bool mPointSizeArrayEnabled;
297     std::vector<bool> mTexCoordArrayEnabled;
298 
299     // Table 6.7-6.16 (IsEnabled)
300     bool mLineSmoothEnabled;
301     bool mPointSmoothEnabled;
302     bool mPointSpriteEnabled;
303     bool mAlphaTestEnabled;
304     bool mLogicOpEnabled;
305     bool mLightingEnabled;
306     bool mFogEnabled;
307     bool mRescaleNormalEnabled;
308     bool mNormalizeEnabled;
309     bool mColorMaterialEnabled;
310     bool mReflectionMapEnabled;
311 
312     // Table 6.3
313     ColorF mCurrentColor;
314     angle::Vector3 mCurrentNormal;
315     // Invariant: mCurrentTextureCoords size is == GL_MAX_TEXTURE_UNITS.
316     std::vector<TextureCoordF> mCurrentTextureCoords;
317 
318     // Table 6.4
319     unsigned int mClientActiveTexture;
320 
321     // Table 6.7
322     MatrixType mMatrixMode;
323     MatrixStack mProjectionMatrices;
324     MatrixStack mModelviewMatrices;
325     std::vector<MatrixStack> mTextureMatrices;
326 
327     // Table 6.15
328     using TextureEnvironments = std::vector<TextureEnvironmentParameters>;
329     TextureEnvironments mTextureEnvironments;
330 
331     // Table 6.9, 2.8
332     MaterialParameters mMaterial;
333     LightModelParameters mLightModel;
334 
335     // Table 6.10
336     std::vector<LightParameters> mLights;
337 
338     // Table 6.8
339     FogParameters mFog;
340     ShadingModel mShadeModel;
341 
342     // Table 6.11
343     PointParameters mPointParameters;
344 
345     // Table 6.16
346     AlphaTestParameters mAlphaTestParameters;
347     LogicalOperation mLogicOp;
348 
349     // Table 6.7
350     std::vector<ClipPlaneParameters> mClipPlanes;
351 
352     // Table 6.19
353     HintSetting mLineSmoothHint;
354     HintSetting mPointSmoothHint;
355     HintSetting mPerspectiveCorrectionHint;
356     HintSetting mFogHint;
357 };
358 
359 }  // namespace gl
360 
361 #endif  // LIBANGLE_GLES1STATE_H_
362