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 struct RasterizationState 67 { RasterizationStaterr::RasterizationState68 RasterizationState (void) 69 : winding (WINDING_CCW) 70 , horizontalFill (FILL_LEFT) 71 , verticalFill (FILL_BOTTOM) 72 { 73 } 74 75 Winding winding; 76 HorizontalFill horizontalFill; 77 VerticalFill verticalFill; 78 }; 79 80 enum TestFunc 81 { 82 TESTFUNC_NEVER = 0, 83 TESTFUNC_ALWAYS, 84 TESTFUNC_LESS, 85 TESTFUNC_LEQUAL, 86 TESTFUNC_GREATER, 87 TESTFUNC_GEQUAL, 88 TESTFUNC_EQUAL, 89 TESTFUNC_NOTEQUAL, 90 91 TESTFUNC_LAST 92 }; 93 94 enum StencilOp 95 { 96 STENCILOP_KEEP = 0, 97 STENCILOP_ZERO, 98 STENCILOP_REPLACE, 99 STENCILOP_INCR, //!< Increment with saturation. 100 STENCILOP_DECR, //!< Decrement with saturation. 101 STENCILOP_INCR_WRAP, 102 STENCILOP_DECR_WRAP, 103 STENCILOP_INVERT, 104 105 STENCILOP_LAST 106 }; 107 108 enum BlendMode 109 { 110 BLENDMODE_NONE = 0, //!< No blending. 111 BLENDMODE_STANDARD, //!< Standard blending. 112 BLENDMODE_ADVANCED, //!< Advanced blending mode, as defined in GL_KHR_blend_equation_advanced. 113 114 BLENDMODE_LAST 115 }; 116 117 enum BlendEquation 118 { 119 BLENDEQUATION_ADD = 0, 120 BLENDEQUATION_SUBTRACT, 121 BLENDEQUATION_REVERSE_SUBTRACT, 122 BLENDEQUATION_MIN, 123 BLENDEQUATION_MAX, 124 125 BLENDEQUATION_LAST 126 }; 127 128 enum BlendEquationAdvanced 129 { 130 BLENDEQUATION_ADVANCED_MULTIPLY = 0, 131 BLENDEQUATION_ADVANCED_SCREEN, 132 BLENDEQUATION_ADVANCED_OVERLAY, 133 BLENDEQUATION_ADVANCED_DARKEN, 134 BLENDEQUATION_ADVANCED_LIGHTEN, 135 BLENDEQUATION_ADVANCED_COLORDODGE, 136 BLENDEQUATION_ADVANCED_COLORBURN, 137 BLENDEQUATION_ADVANCED_HARDLIGHT, 138 BLENDEQUATION_ADVANCED_SOFTLIGHT, 139 BLENDEQUATION_ADVANCED_DIFFERENCE, 140 BLENDEQUATION_ADVANCED_EXCLUSION, 141 BLENDEQUATION_ADVANCED_HSL_HUE, 142 BLENDEQUATION_ADVANCED_HSL_SATURATION, 143 BLENDEQUATION_ADVANCED_HSL_COLOR, 144 BLENDEQUATION_ADVANCED_HSL_LUMINOSITY, 145 146 BLENDEQUATION_ADVANCED_LAST 147 }; 148 149 enum BlendFunc 150 { 151 BLENDFUNC_ZERO = 0, 152 BLENDFUNC_ONE, 153 BLENDFUNC_SRC_COLOR, 154 BLENDFUNC_ONE_MINUS_SRC_COLOR, 155 BLENDFUNC_DST_COLOR, 156 BLENDFUNC_ONE_MINUS_DST_COLOR, 157 BLENDFUNC_SRC_ALPHA, 158 BLENDFUNC_ONE_MINUS_SRC_ALPHA, 159 BLENDFUNC_DST_ALPHA, 160 BLENDFUNC_ONE_MINUS_DST_ALPHA, 161 BLENDFUNC_CONSTANT_COLOR, 162 BLENDFUNC_ONE_MINUS_CONSTANT_COLOR, 163 BLENDFUNC_CONSTANT_ALPHA, 164 BLENDFUNC_ONE_MINUS_CONSTANT_ALPHA, 165 BLENDFUNC_SRC_ALPHA_SATURATE, 166 BLENDFUNC_SRC1_COLOR, 167 BLENDFUNC_ONE_MINUS_SRC1_COLOR, 168 BLENDFUNC_SRC1_ALPHA, 169 BLENDFUNC_ONE_MINUS_SRC1_ALPHA, 170 171 BLENDFUNC_LAST 172 }; 173 174 struct StencilState 175 { 176 TestFunc func; 177 int ref; 178 deUint32 compMask; 179 StencilOp sFail; 180 StencilOp dpFail; 181 StencilOp dpPass; 182 deUint32 writeMask; 183 StencilStaterr::StencilState184 StencilState (void) 185 : func (TESTFUNC_ALWAYS) 186 , ref (0) 187 , compMask (~0U) 188 , sFail (STENCILOP_KEEP) 189 , dpFail (STENCILOP_KEEP) 190 , dpPass (STENCILOP_KEEP) 191 , writeMask (~0U) 192 { 193 } 194 }; 195 196 struct BlendState 197 { 198 BlendEquation equation; 199 BlendFunc srcFunc; 200 BlendFunc dstFunc; 201 BlendStaterr::BlendState202 BlendState (void) 203 : equation (BLENDEQUATION_ADD) 204 , srcFunc (BLENDFUNC_ONE) 205 , dstFunc (BLENDFUNC_ZERO) 206 { 207 } 208 }; 209 210 struct WindowRectangle 211 { 212 int left; 213 int bottom; 214 int width; 215 int height; 216 WindowRectanglerr::WindowRectangle217 WindowRectangle (int left_, int bottom_, int width_, int height_) 218 : left (left_) 219 , bottom (bottom_) 220 , width (width_) 221 , height (height_) 222 { 223 } 224 }; 225 226 struct FragmentOperationState 227 { 228 // Variables corresponding to GL state variables. 229 230 bool scissorTestEnabled; 231 WindowRectangle scissorRectangle; 232 233 bool stencilTestEnabled; 234 StencilState stencilStates[2]; //!< Indexed with FACETYPE_FRONT and FACETYPE_BACK. 235 236 bool depthTestEnabled; 237 TestFunc depthFunc; 238 bool depthMask; 239 240 BlendMode blendMode; 241 242 // Standard blending state 243 BlendState blendRGBState; 244 BlendState blendAState; 245 tcu::Vec4 blendColor; //!< Components should be in range [0, 1]. 246 247 BlendEquationAdvanced blendEquationAdvaced; 248 249 bool sRGBEnabled; 250 251 bool depthClampEnabled; 252 253 bool polygonOffsetEnabled; 254 float polygonOffsetFactor; 255 float polygonOffsetUnits; 256 257 tcu::BVec4 colorMask; 258 259 // Variables not corresponding to configurable GL state, but other GL variables. 260 261 int numStencilBits; 262 FragmentOperationStaterr::FragmentOperationState263 FragmentOperationState (void) 264 : scissorTestEnabled (false) 265 , scissorRectangle (0, 0, 1, 1) 266 267 , stencilTestEnabled (false) 268 // \note stencilStates[] members get default-constructed. 269 270 , depthTestEnabled (false) 271 , depthFunc (TESTFUNC_LESS) 272 , depthMask (true) 273 274 , blendMode (BLENDMODE_NONE) 275 , blendRGBState () 276 , blendAState () 277 , blendColor (0.0f) 278 , blendEquationAdvaced (BLENDEQUATION_ADVANCED_LAST) 279 280 , sRGBEnabled (true) 281 282 , depthClampEnabled (false) 283 284 , polygonOffsetEnabled (false) 285 , polygonOffsetFactor (0.0f) 286 , polygonOffsetUnits (0.0f) 287 288 , colorMask (true) 289 290 , numStencilBits (8) 291 { 292 } 293 }; 294 295 struct PointState 296 { 297 float pointSize; 298 PointStaterr::PointState299 PointState (void) 300 : pointSize(1.0f) 301 { 302 } 303 }; 304 305 struct LineState 306 { 307 float lineWidth; 308 LineStaterr::LineState309 LineState (void) 310 : lineWidth(1.0f) 311 { 312 } 313 }; 314 315 316 struct ViewportState 317 { 318 WindowRectangle rect; 319 float zn; 320 float zf; 321 ViewportStaterr::ViewportState322 explicit ViewportState (const WindowRectangle& rect_) 323 : rect (rect_) 324 , zn (0.0f) 325 , zf (1.0f) 326 { 327 } 328 ViewportStaterr::ViewportState329 explicit ViewportState (const rr::MultisampleConstPixelBufferAccess& multisampleBuffer) 330 : rect (0, 0, multisampleBuffer.raw().getHeight(), multisampleBuffer.raw().getDepth()) 331 , zn (0.0f) 332 , zf (1.0f) 333 { 334 } 335 }; 336 337 struct RestartState 338 { 339 bool enabled; 340 deUint32 restartIndex; 341 RestartStaterr::RestartState342 RestartState (void) 343 : enabled (false) 344 , restartIndex (0xFFFFFFFFul) 345 { 346 } 347 }; 348 349 struct RenderState 350 { RenderStaterr::RenderState351 explicit RenderState (const ViewportState& viewport_) 352 : cullMode (CULLMODE_NONE) 353 , provokingVertexConvention (PROVOKINGVERTEX_LAST) 354 , viewport (viewport_) 355 { 356 } 357 358 CullMode cullMode; 359 ProvokingVertex provokingVertexConvention; 360 RasterizationState rasterization; 361 FragmentOperationState fragOps; 362 PointState point; 363 ViewportState viewport; 364 LineState line; 365 RestartState restart; 366 }; 367 368 } // rr 369 370 #endif // _RRRENDERSTATE_HPP 371