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 TextureEnvironmentParameters 88 { 89 TextureEnvironmentParameters(); 90 TextureEnvironmentParameters(const TextureEnvironmentParameters &other); 91 92 TextureEnvMode mode = TextureEnvMode::Modulate; 93 TextureCombine combineRgb = TextureCombine::Modulate; 94 TextureCombine combineAlpha = TextureCombine::Modulate; 95 96 TextureSrc src0Rgb = TextureSrc::Texture; 97 TextureSrc src0Alpha = TextureSrc::Texture; 98 99 TextureSrc src1Rgb = TextureSrc::Previous; 100 TextureSrc src1Alpha = TextureSrc::Previous; 101 102 TextureSrc src2Rgb = TextureSrc::Constant; 103 TextureSrc src2Alpha = TextureSrc::Constant; 104 105 TextureOp op0Rgb = TextureOp::SrcColor; 106 TextureOp op0Alpha = TextureOp::SrcAlpha; 107 108 TextureOp op1Rgb = TextureOp::SrcColor; 109 TextureOp op1Alpha = TextureOp::SrcAlpha; 110 111 TextureOp op2Rgb = TextureOp::SrcAlpha; 112 TextureOp op2Alpha = TextureOp::SrcAlpha; 113 114 ColorF color = {0.0f, 0.0f, 0.0f, 0.0f}; 115 GLfloat rgbScale = 1.0f; 116 GLfloat alphaScale = 1.0f; 117 118 bool pointSpriteCoordReplace = false; 119 }; 120 121 struct PointParameters 122 { 123 PointParameters(); 124 PointParameters(const PointParameters &other); 125 126 GLfloat pointSizeMin = 0.0f; 127 GLfloat pointSizeMax = 1.0f; 128 GLfloat pointFadeThresholdSize = 1.0f; 129 angle::Vector3 pointDistanceAttenuation = {1.0f, 0.0f, 0.0f}; 130 GLfloat pointSize = 1.0f; 131 }; 132 133 struct ClipPlaneParameters 134 { 135 ClipPlaneParameters(); 136 ClipPlaneParameters(bool enabled, const angle::Vector4 &equation); 137 ClipPlaneParameters(const ClipPlaneParameters &other); 138 139 bool enabled; 140 angle::Vector4 equation; 141 }; 142 143 class Context; 144 class GLES1Renderer; 145 class State; 146 147 class GLES1State final : angle::NonCopyable 148 { 149 public: 150 GLES1State(); 151 ~GLES1State(); 152 153 void initialize(const Context *context, const State *state); 154 155 void setAlphaFunc(AlphaTestFunc func, GLfloat ref); 156 void setClientTextureUnit(unsigned int unit); 157 unsigned int getClientTextureUnit() const; 158 159 void setCurrentColor(const ColorF &color); 160 const ColorF &getCurrentColor() const; 161 162 void setCurrentNormal(const angle::Vector3 &normal); 163 const angle::Vector3 &getCurrentNormal() const; 164 165 void setCurrentTextureCoords(unsigned int unit, const TextureCoordF &coords); 166 const TextureCoordF &getCurrentTextureCoords(unsigned int unit) const; 167 168 void setMatrixMode(MatrixType mode); 169 MatrixType getMatrixMode() const; 170 171 GLint getCurrentMatrixStackDepth(GLenum param) const; 172 173 void pushMatrix(); 174 void popMatrix(); 175 176 using MatrixStack = angle::FixedVector<angle::Mat4, Caps::GlobalMatrixStackDepth>; 177 MatrixStack ¤tMatrixStack(); 178 const MatrixStack ¤tMatrixStack() const; 179 180 const angle::Mat4 &getModelviewMatrix() const; 181 182 void loadMatrix(const angle::Mat4 &m); 183 void multMatrix(const angle::Mat4 &m); 184 185 void setLogicOp(LogicalOperation opcodePacked); 186 187 void setClientStateEnabled(ClientVertexArrayType clientState, bool enable); 188 void setTexCoordArrayEnabled(unsigned int unit, bool enable); 189 bool isClientStateEnabled(ClientVertexArrayType clientState) const; 190 bool isTexCoordArrayEnabled(unsigned int unit) const; 191 bool isTextureTargetEnabled(unsigned int unit, const TextureType type) const; 192 193 LightModelParameters &lightModelParameters(); 194 const LightModelParameters &lightModelParameters() const; 195 196 LightParameters &lightParameters(unsigned int light); 197 const LightParameters &lightParameters(unsigned int light) const; 198 199 MaterialParameters &materialParameters(); 200 const MaterialParameters &materialParameters() const; 201 bool isColorMaterialEnabled() const; 202 203 void setShadeModel(ShadingModel model); 204 205 void setClipPlane(unsigned int plane, const GLfloat *equation); 206 void getClipPlane(unsigned int plane, GLfloat *equation) const; 207 208 FogParameters &fogParameters(); 209 const FogParameters &fogParameters() const; 210 211 TextureEnvironmentParameters &textureEnvironment(unsigned int unit); 212 const TextureEnvironmentParameters &textureEnvironment(unsigned int unit) const; 213 214 PointParameters &pointParameters(); 215 const PointParameters &pointParameters() const; 216 217 AttributesMask getVertexArraysAttributeMask() const; 218 219 void setHint(GLenum target, GLenum mode); 220 GLenum getHint(GLenum target); 221 222 private: 223 friend class State; 224 friend class GLES1Renderer; 225 226 // Back pointer for reading from State. 227 const State *mGLState; 228 229 enum DirtyGles1Type 230 { 231 DIRTY_GLES1_TEXTURE_UNIT_ENABLE = 0, 232 DIRTY_GLES1_CLIENT_STATE_ENABLE, 233 DIRTY_GLES1_FEATURE_ENABLE, 234 DIRTY_GLES1_CURRENT_VECTOR, 235 DIRTY_GLES1_CLIENT_ACTIVE_TEXTURE, 236 DIRTY_GLES1_MATRICES, 237 DIRTY_GLES1_TEXTURE_ENVIRONMENT, 238 DIRTY_GLES1_MATERIAL, 239 DIRTY_GLES1_LIGHTS, 240 DIRTY_GLES1_FOG, 241 DIRTY_GLES1_SHADE_MODEL, 242 DIRTY_GLES1_POINT_PARAMETERS, 243 DIRTY_GLES1_ALPHA_TEST, 244 DIRTY_GLES1_LOGIC_OP, 245 DIRTY_GLES1_CLIP_PLANES, 246 DIRTY_GLES1_HINT_SETTING, 247 DIRTY_GLES1_MAX, 248 }; 249 using DirtyBits = angle::BitSet<DIRTY_GLES1_MAX>; 250 DirtyBits mDirtyBits; 251 252 void setDirty(DirtyGles1Type type); 253 void setAllDirty(); 254 void clearDirty(); 255 bool isDirty(DirtyGles1Type type) const; 256 257 // All initial state values come from the 258 // OpenGL ES 1.1 spec. 259 std::vector<angle::PackedEnumBitSet<TextureType>> mTexUnitEnables; 260 261 // Table 6.4, 6.5 (IsEnabled) 262 bool mVertexArrayEnabled; 263 bool mNormalArrayEnabled; 264 bool mColorArrayEnabled; 265 bool mPointSizeArrayEnabled; 266 std::vector<bool> mTexCoordArrayEnabled; 267 268 // Table 6.7-6.16 (IsEnabled) 269 bool mLineSmoothEnabled; 270 bool mPointSmoothEnabled; 271 bool mPointSpriteEnabled; 272 bool mAlphaTestEnabled; 273 bool mLogicOpEnabled; 274 bool mLightingEnabled; 275 bool mFogEnabled; 276 bool mRescaleNormalEnabled; 277 bool mNormalizeEnabled; 278 bool mColorMaterialEnabled; 279 bool mReflectionMapEnabled; 280 281 // Table 6.3 282 ColorF mCurrentColor; 283 angle::Vector3 mCurrentNormal; 284 // Invariant: mCurrentTextureCoords size is == GL_MAX_TEXTURE_UNITS. 285 std::vector<TextureCoordF> mCurrentTextureCoords; 286 287 // Table 6.4 288 unsigned int mClientActiveTexture; 289 290 // Table 6.7 291 MatrixType mMatrixMode; 292 MatrixStack mProjectionMatrices; 293 MatrixStack mModelviewMatrices; 294 std::vector<MatrixStack> mTextureMatrices; 295 296 // Table 6.15 297 using TextureEnvironments = std::vector<TextureEnvironmentParameters>; 298 TextureEnvironments mTextureEnvironments; 299 300 // Table 6.9, 2.8 301 MaterialParameters mMaterial; 302 LightModelParameters mLightModel; 303 304 // Table 6.10 305 std::vector<LightParameters> mLights; 306 307 // Table 6.8 308 FogParameters mFog; 309 ShadingModel mShadeModel; 310 311 // Table 6.11 312 PointParameters mPointParameters; 313 314 // Table 6.16 315 AlphaTestFunc mAlphaTestFunc; 316 GLfloat mAlphaTestRef; 317 LogicalOperation mLogicOp; 318 319 // Table 6.7 320 std::vector<ClipPlaneParameters> mClipPlanes; 321 322 // Table 6.19 323 HintSetting mLineSmoothHint; 324 HintSetting mPointSmoothHint; 325 HintSetting mPerspectiveCorrectionHint; 326 HintSetting mFogHint; 327 }; 328 329 } // namespace gl 330 331 #endif // LIBANGLE_GLES1STATE_H_ 332