1 #ifndef _RRRENDERSTATE_HPP 2 #define _RRRENDERSTATE_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Reference Renderer 5 * ----------------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Reference renderer render state. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "rrDefs.hpp" 27 #include "rrMultisamplePixelBufferAccess.hpp" 28 #include "tcuTexture.hpp" 29 30 namespace rr 31 { 32 33 //! Horizontal fill rule 34 enum HorizontalFill 35 { 36 FILL_LEFT, 37 FILL_RIGHT 38 }; 39 40 //! Vertical fill rule 41 enum VerticalFill 42 { 43 FILL_TOP, 44 FILL_BOTTOM, 45 }; 46 47 //! Winding mode 48 enum Winding 49 { 50 WINDING_CCW = 0, //!< Counter-clockwise winding 51 WINDING_CW, //!< Clockwise winding 52 53 WINDING_LAST 54 }; 55 56 //! Triangle cull mode 57 enum CullMode 58 { 59 CULLMODE_NONE, 60 CULLMODE_BACK, 61 CULLMODE_FRONT, 62 63 CULLMODE_LAST 64 }; 65 66 //! Viewport Orientation of renderer this will be compared against 67 enum ViewportOrientation 68 { 69 VIEWPORTORIENTATION_LOWER_LEFT = 0, //<! Corresponds to GL 70 VIEWPORTORIENTATION_UPPER_LEFT, //<! Corresponds to Vulkan 71 72 VIEWPORTORIENTATION_LAST 73 }; 74 75 struct RasterizationState 76 { RasterizationStaterr::RasterizationState77 RasterizationState(void) 78 : winding(WINDING_CCW) 79 , horizontalFill(FILL_LEFT) 80 , verticalFill(FILL_BOTTOM) 81 , viewportOrientation(VIEWPORTORIENTATION_LAST) 82 { 83 } 84 85 Winding winding; 86 HorizontalFill horizontalFill; 87 VerticalFill verticalFill; 88 ViewportOrientation viewportOrientation; 89 }; 90 91 enum TestFunc 92 { 93 TESTFUNC_NEVER = 0, 94 TESTFUNC_ALWAYS, 95 TESTFUNC_LESS, 96 TESTFUNC_LEQUAL, 97 TESTFUNC_GREATER, 98 TESTFUNC_GEQUAL, 99 TESTFUNC_EQUAL, 100 TESTFUNC_NOTEQUAL, 101 102 TESTFUNC_LAST 103 }; 104 105 enum StencilOp 106 { 107 STENCILOP_KEEP = 0, 108 STENCILOP_ZERO, 109 STENCILOP_REPLACE, 110 STENCILOP_INCR, //!< Increment with saturation. 111 STENCILOP_DECR, //!< Decrement with saturation. 112 STENCILOP_INCR_WRAP, 113 STENCILOP_DECR_WRAP, 114 STENCILOP_INVERT, 115 116 STENCILOP_LAST 117 }; 118 119 enum BlendMode 120 { 121 BLENDMODE_NONE = 0, //!< No blending. 122 BLENDMODE_STANDARD, //!< Standard blending. 123 BLENDMODE_ADVANCED, //!< Advanced blending mode, as defined in GL_KHR_blend_equation_advanced. 124 125 BLENDMODE_LAST 126 }; 127 128 enum BlendEquation 129 { 130 BLENDEQUATION_ADD = 0, 131 BLENDEQUATION_SUBTRACT, 132 BLENDEQUATION_REVERSE_SUBTRACT, 133 BLENDEQUATION_MIN, 134 BLENDEQUATION_MAX, 135 136 BLENDEQUATION_LAST 137 }; 138 139 enum BlendEquationAdvanced 140 { 141 BLENDEQUATION_ADVANCED_MULTIPLY = 0, 142 BLENDEQUATION_ADVANCED_SCREEN, 143 BLENDEQUATION_ADVANCED_OVERLAY, 144 BLENDEQUATION_ADVANCED_DARKEN, 145 BLENDEQUATION_ADVANCED_LIGHTEN, 146 BLENDEQUATION_ADVANCED_COLORDODGE, 147 BLENDEQUATION_ADVANCED_COLORBURN, 148 BLENDEQUATION_ADVANCED_HARDLIGHT, 149 BLENDEQUATION_ADVANCED_SOFTLIGHT, 150 BLENDEQUATION_ADVANCED_DIFFERENCE, 151 BLENDEQUATION_ADVANCED_EXCLUSION, 152 BLENDEQUATION_ADVANCED_HSL_HUE, 153 BLENDEQUATION_ADVANCED_HSL_SATURATION, 154 BLENDEQUATION_ADVANCED_HSL_COLOR, 155 BLENDEQUATION_ADVANCED_HSL_LUMINOSITY, 156 157 BLENDEQUATION_ADVANCED_LAST 158 }; 159 160 enum BlendFunc 161 { 162 BLENDFUNC_ZERO = 0, 163 BLENDFUNC_ONE, 164 BLENDFUNC_SRC_COLOR, 165 BLENDFUNC_ONE_MINUS_SRC_COLOR, 166 BLENDFUNC_DST_COLOR, 167 BLENDFUNC_ONE_MINUS_DST_COLOR, 168 BLENDFUNC_SRC_ALPHA, 169 BLENDFUNC_ONE_MINUS_SRC_ALPHA, 170 BLENDFUNC_DST_ALPHA, 171 BLENDFUNC_ONE_MINUS_DST_ALPHA, 172 BLENDFUNC_CONSTANT_COLOR, 173 BLENDFUNC_ONE_MINUS_CONSTANT_COLOR, 174 BLENDFUNC_CONSTANT_ALPHA, 175 BLENDFUNC_ONE_MINUS_CONSTANT_ALPHA, 176 BLENDFUNC_SRC_ALPHA_SATURATE, 177 BLENDFUNC_SRC1_COLOR, 178 BLENDFUNC_ONE_MINUS_SRC1_COLOR, 179 BLENDFUNC_SRC1_ALPHA, 180 BLENDFUNC_ONE_MINUS_SRC1_ALPHA, 181 182 BLENDFUNC_LAST 183 }; 184 185 struct StencilState 186 { 187 TestFunc func; 188 int ref; 189 uint32_t compMask; 190 StencilOp sFail; 191 StencilOp dpFail; 192 StencilOp dpPass; 193 uint32_t writeMask; 194 StencilStaterr::StencilState195 StencilState(void) 196 : func(TESTFUNC_ALWAYS) 197 , ref(0) 198 , compMask(~0U) 199 , sFail(STENCILOP_KEEP) 200 , dpFail(STENCILOP_KEEP) 201 , dpPass(STENCILOP_KEEP) 202 , writeMask(~0U) 203 { 204 } 205 }; 206 207 struct BlendState 208 { 209 BlendEquation equation; 210 BlendFunc srcFunc; 211 BlendFunc dstFunc; 212 BlendStaterr::BlendState213 BlendState(void) : equation(BLENDEQUATION_ADD), srcFunc(BLENDFUNC_ONE), dstFunc(BLENDFUNC_ZERO) 214 { 215 } 216 }; 217 218 struct WindowRectangle 219 { 220 int left; 221 int bottom; 222 int width; 223 int height; 224 WindowRectanglerr::WindowRectangle225 WindowRectangle(int left_, int bottom_, int width_, int height_) 226 : left(left_) 227 , bottom(bottom_) 228 , width(width_) 229 , height(height_) 230 { 231 } 232 }; 233 234 struct FragmentOperationState 235 { 236 // Variables corresponding to GL state variables. 237 238 bool scissorTestEnabled; 239 WindowRectangle scissorRectangle; 240 241 bool stencilTestEnabled; 242 StencilState stencilStates[2]; //!< Indexed with FACETYPE_FRONT and FACETYPE_BACK. 243 244 bool depthTestEnabled; 245 TestFunc depthFunc; 246 bool depthMask; 247 248 bool depthBoundsTestEnabled; 249 float minDepthBound; 250 float maxDepthBound; 251 252 BlendMode blendMode; 253 254 // Standard blending state 255 BlendState blendRGBState; 256 BlendState blendAState; 257 tcu::Vec4 blendColor; //!< Components should be in range [0, 1]. 258 259 BlendEquationAdvanced blendEquationAdvaced; 260 261 bool sRGBEnabled; 262 263 bool depthClampEnabled; 264 265 bool polygonOffsetEnabled; 266 float polygonOffsetFactor; 267 float polygonOffsetUnits; 268 269 tcu::BVec4 colorMask; 270 271 // Variables not corresponding to configurable GL state, but other GL variables. 272 273 int numStencilBits; 274 FragmentOperationStaterr::FragmentOperationState275 FragmentOperationState(void) 276 : scissorTestEnabled(false) 277 , scissorRectangle(0, 0, 1, 1) 278 279 , stencilTestEnabled(false) 280 // \note stencilStates[] members get default-constructed. 281 282 , depthTestEnabled(false) 283 , depthFunc(TESTFUNC_LESS) 284 , depthMask(true) 285 286 , depthBoundsTestEnabled(false) 287 , minDepthBound(0.0f) 288 , maxDepthBound(1.0f) 289 290 , blendMode(BLENDMODE_NONE) 291 , blendRGBState() 292 , blendAState() 293 , blendColor(0.0f) 294 , blendEquationAdvaced(BLENDEQUATION_ADVANCED_LAST) 295 296 , sRGBEnabled(true) 297 298 , depthClampEnabled(false) 299 300 , polygonOffsetEnabled(false) 301 , polygonOffsetFactor(0.0f) 302 , polygonOffsetUnits(0.0f) 303 304 , colorMask(true) 305 306 , numStencilBits(8) 307 { 308 } 309 }; 310 311 struct PointState 312 { 313 float pointSize; 314 PointStaterr::PointState315 PointState(void) : pointSize(1.0f) 316 { 317 } 318 }; 319 320 struct LineState 321 { 322 float lineWidth; 323 LineStaterr::LineState324 LineState(void) : lineWidth(1.0f) 325 { 326 } 327 }; 328 329 struct ViewportState 330 { 331 WindowRectangle rect; 332 float zn; 333 float zf; 334 ViewportStaterr::ViewportState335 explicit ViewportState(const WindowRectangle &rect_) : rect(rect_), zn(0.0f), zf(1.0f) 336 { 337 } 338 ViewportStaterr::ViewportState339 explicit ViewportState(const rr::MultisampleConstPixelBufferAccess &multisampleBuffer) 340 : rect(0, 0, multisampleBuffer.raw().getHeight(), multisampleBuffer.raw().getDepth()) 341 , zn(0.0f) 342 , zf(1.0f) 343 { 344 } 345 }; 346 347 struct RestartState 348 { 349 bool enabled; 350 uint32_t restartIndex; 351 RestartStaterr::RestartState352 RestartState(void) : enabled(false), restartIndex(0xFFFFFFFFul) 353 { 354 } 355 }; 356 357 //! Rasterizer configuration 358 struct RenderState 359 { RenderStaterr::RenderState360 explicit RenderState(const ViewportState &viewport_, const int subpixelBits_, 361 ViewportOrientation viewportOrientation_ = VIEWPORTORIENTATION_LOWER_LEFT) 362 : cullMode(CULLMODE_NONE) 363 , provokingVertexConvention(PROVOKINGVERTEX_LAST) 364 , viewport(viewport_) 365 , viewportOrientation(viewportOrientation_) 366 , subpixelBits(subpixelBits_) 367 { 368 rasterization.viewportOrientation = viewportOrientation; 369 } 370 371 enum 372 { 373 DEFAULT_SUBPIXEL_BITS = 8 374 }; 375 376 CullMode cullMode; 377 ProvokingVertex provokingVertexConvention; 378 RasterizationState rasterization; 379 FragmentOperationState fragOps; 380 PointState point; 381 ViewportState viewport; 382 LineState line; 383 RestartState restart; 384 ViewportOrientation viewportOrientation; 385 const int subpixelBits; 386 }; 387 388 } // namespace rr 389 390 #endif // _RRRENDERSTATE_HPP 391