• 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 	bool						depthBoundsTestEnabled;
252 	float						minDepthBound;
253 	float						maxDepthBound;
254 
255 	BlendMode					blendMode;
256 
257 	// Standard blending state
258 	BlendState					blendRGBState;
259 	BlendState					blendAState;
260 	tcu::Vec4					blendColor;			//!< Components should be in range [0, 1].
261 
262 	BlendEquationAdvanced		blendEquationAdvaced;
263 
264 	bool						sRGBEnabled;
265 
266 	bool						depthClampEnabled;
267 
268 	bool						polygonOffsetEnabled;
269 	float						polygonOffsetFactor;
270 	float						polygonOffsetUnits;
271 
272 	tcu::BVec4					colorMask;
273 
274 	// Variables not corresponding to configurable GL state, but other GL variables.
275 
276 	int							numStencilBits;
277 
FragmentOperationStaterr::FragmentOperationState278 	FragmentOperationState (void)
279 		: scissorTestEnabled	(false)
280 		, scissorRectangle		(0, 0, 1, 1)
281 
282 		, stencilTestEnabled	(false)
283 		// \note stencilStates[] members get default-constructed.
284 
285 		, depthTestEnabled		(false)
286 		, depthFunc				(TESTFUNC_LESS)
287 		, depthMask				(true)
288 
289 		, depthBoundsTestEnabled(false)
290 		, minDepthBound			(0.0f)
291 		, maxDepthBound			(1.0f)
292 
293 		, blendMode				(BLENDMODE_NONE)
294 		, blendRGBState			()
295 		, blendAState			()
296 		, blendColor			(0.0f)
297 		, blendEquationAdvaced	(BLENDEQUATION_ADVANCED_LAST)
298 
299 		, sRGBEnabled			(true)
300 
301 		, depthClampEnabled		(false)
302 
303 		, polygonOffsetEnabled	(false)
304 		, polygonOffsetFactor	(0.0f)
305 		, polygonOffsetUnits	(0.0f)
306 
307 		, colorMask				(true)
308 
309 		, numStencilBits		(8)
310 	{
311 	}
312 };
313 
314 struct PointState
315 {
316 	float	pointSize;
317 
PointStaterr::PointState318 	PointState (void)
319 		: pointSize(1.0f)
320 	{
321 	}
322 };
323 
324 struct LineState
325 {
326 	float	lineWidth;
327 
LineStaterr::LineState328 	LineState (void)
329 		: lineWidth(1.0f)
330 	{
331 	}
332 };
333 
334 
335 struct ViewportState
336 {
337 	WindowRectangle	rect;
338 	float			zn;
339 	float			zf;
340 
ViewportStaterr::ViewportState341 	explicit ViewportState (const WindowRectangle& rect_)
342 		: rect	(rect_)
343 		, zn	(0.0f)
344 		, zf	(1.0f)
345 	{
346 	}
347 
ViewportStaterr::ViewportState348 	explicit ViewportState (const rr::MultisampleConstPixelBufferAccess& multisampleBuffer)
349 		: rect	(0, 0, multisampleBuffer.raw().getHeight(), multisampleBuffer.raw().getDepth())
350 		, zn	(0.0f)
351 		, zf	(1.0f)
352 	{
353 	}
354 };
355 
356 struct RestartState
357 {
358 	bool		enabled;
359 	deUint32	restartIndex;
360 
RestartStaterr::RestartState361 	RestartState (void)
362 		: enabled		(false)
363 		, restartIndex	(0xFFFFFFFFul)
364 	{
365 	}
366 };
367 
368 struct RenderState
369 {
RenderStaterr::RenderState370 	explicit RenderState (const ViewportState& viewport_, ViewportOrientation viewportOrientation_ = VIEWPORTORIENTATION_LOWER_LEFT)
371 		: cullMode					(CULLMODE_NONE)
372 		, provokingVertexConvention	(PROVOKINGVERTEX_LAST)
373 		, viewport					(viewport_)
374 		, viewportOrientation		(viewportOrientation_)
375 	{
376 		rasterization.viewportOrientation = viewportOrientation;
377 	}
378 
379 	CullMode					cullMode;
380 	ProvokingVertex				provokingVertexConvention;
381 	RasterizationState			rasterization;
382 	FragmentOperationState		fragOps;
383 	PointState					point;
384 	ViewportState				viewport;
385 	LineState					line;
386 	RestartState				restart;
387 	ViewportOrientation			viewportOrientation;
388 };
389 
390 } // rr
391 
392 #endif // _RRRENDERSTATE_HPP
393