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