• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	deUint32	compMask;
190 	StencilOp	sFail;
191 	StencilOp	dpFail;
192 	StencilOp	dpPass;
193 	deUint32	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)
214 		: equation	(BLENDEQUATION_ADD)
215 		, srcFunc	(BLENDFUNC_ONE)
216 		, dstFunc	(BLENDFUNC_ZERO)
217 	{
218 	}
219 };
220 
221 struct WindowRectangle
222 {
223 	int left;
224 	int bottom;
225 	int width;
226 	int height;
227 
WindowRectanglerr::WindowRectangle228 	WindowRectangle (int left_, int bottom_, int width_, int height_)
229 		: left		(left_)
230 		, bottom	(bottom_)
231 		, width		(width_)
232 		, height	(height_)
233 	{
234 	}
235 };
236 
237 struct FragmentOperationState
238 {
239 	// Variables corresponding to GL state variables.
240 
241 	bool						scissorTestEnabled;
242 	WindowRectangle				scissorRectangle;
243 
244 	bool						stencilTestEnabled;
245 	StencilState				stencilStates[2];	//!< Indexed with FACETYPE_FRONT and FACETYPE_BACK.
246 
247 	bool						depthTestEnabled;
248 	TestFunc					depthFunc;
249 	bool						depthMask;
250 
251 	BlendMode					blendMode;
252 
253 	// Standard blending state
254 	BlendState					blendRGBState;
255 	BlendState					blendAState;
256 	tcu::Vec4					blendColor;			//!< Components should be in range [0, 1].
257 
258 	BlendEquationAdvanced		blendEquationAdvaced;
259 
260 	bool						sRGBEnabled;
261 
262 	bool						depthClampEnabled;
263 
264 	bool						polygonOffsetEnabled;
265 	float						polygonOffsetFactor;
266 	float						polygonOffsetUnits;
267 
268 	tcu::BVec4					colorMask;
269 
270 	// Variables not corresponding to configurable GL state, but other GL variables.
271 
272 	int							numStencilBits;
273 
FragmentOperationStaterr::FragmentOperationState274 	FragmentOperationState (void)
275 		: scissorTestEnabled	(false)
276 		, scissorRectangle		(0, 0, 1, 1)
277 
278 		, stencilTestEnabled	(false)
279 		// \note stencilStates[] members get default-constructed.
280 
281 		, depthTestEnabled		(false)
282 		, depthFunc				(TESTFUNC_LESS)
283 		, depthMask				(true)
284 
285 		, blendMode				(BLENDMODE_NONE)
286 		, blendRGBState			()
287 		, blendAState			()
288 		, blendColor			(0.0f)
289 		, blendEquationAdvaced	(BLENDEQUATION_ADVANCED_LAST)
290 
291 		, sRGBEnabled			(true)
292 
293 		, depthClampEnabled		(false)
294 
295 		, polygonOffsetEnabled	(false)
296 		, polygonOffsetFactor	(0.0f)
297 		, polygonOffsetUnits	(0.0f)
298 
299 		, colorMask				(true)
300 
301 		, numStencilBits		(8)
302 	{
303 	}
304 };
305 
306 struct PointState
307 {
308 	float	pointSize;
309 
PointStaterr::PointState310 	PointState (void)
311 		: pointSize(1.0f)
312 	{
313 	}
314 };
315 
316 struct LineState
317 {
318 	float	lineWidth;
319 
LineStaterr::LineState320 	LineState (void)
321 		: lineWidth(1.0f)
322 	{
323 	}
324 };
325 
326 
327 struct ViewportState
328 {
329 	WindowRectangle	rect;
330 	float			zn;
331 	float			zf;
332 
ViewportStaterr::ViewportState333 	explicit ViewportState (const WindowRectangle& rect_)
334 		: rect	(rect_)
335 		, zn	(0.0f)
336 		, zf	(1.0f)
337 	{
338 	}
339 
ViewportStaterr::ViewportState340 	explicit ViewportState (const rr::MultisampleConstPixelBufferAccess& multisampleBuffer)
341 		: rect	(0, 0, multisampleBuffer.raw().getHeight(), multisampleBuffer.raw().getDepth())
342 		, zn	(0.0f)
343 		, zf	(1.0f)
344 	{
345 	}
346 };
347 
348 struct RestartState
349 {
350 	bool		enabled;
351 	deUint32	restartIndex;
352 
RestartStaterr::RestartState353 	RestartState (void)
354 		: enabled		(false)
355 		, restartIndex	(0xFFFFFFFFul)
356 	{
357 	}
358 };
359 
360 struct RenderState
361 {
RenderStaterr::RenderState362 	explicit RenderState (const ViewportState& viewport_, ViewportOrientation viewportOrientation_ = VIEWPORTORIENTATION_LOWER_LEFT)
363 		: cullMode					(CULLMODE_NONE)
364 		, provokingVertexConvention	(PROVOKINGVERTEX_LAST)
365 		, viewport					(viewport_)
366 		, viewportOrientation		(viewportOrientation_)
367 	{
368 		rasterization.viewportOrientation = viewportOrientation;
369 	}
370 
371 	CullMode					cullMode;
372 	ProvokingVertex				provokingVertexConvention;
373 	RasterizationState			rasterization;
374 	FragmentOperationState		fragOps;
375 	PointState					point;
376 	ViewportState				viewport;
377 	LineState					line;
378 	RestartState				restart;
379 	ViewportOrientation			viewportOrientation;
380 };
381 
382 } // rr
383 
384 #endif // _RRRENDERSTATE_HPP
385