1 /*---------------------------------------------------------------------------*
2 
3   Copyright (C) Nintendo.  All rights reserved.
4 
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law.  They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 // gx2RenderStateReg.h
14 //
15 // Declares gx2RenderStateReg-related types & functions for gx2 library.
16 
17 #ifndef _CAFE_GX2_RENDERSTATE_REG_H_
18 #define _CAFE_GX2_RENDERSTATE_REG_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif // __cplusplus
24 
25 /// @addtogroup GX2RenderStateRegGroup
26 /// @{
27 
28 // -----------------
29 // GX2RenderStateReg.h
30 
31 /// \brief Structure for depth & stencil controls register.
32 ///
33 typedef struct{
34     u32 reg;
35 }GX2DepthStencilControlReg;
36 
37 /// \brief Structure for culling, front/back polygon modes, polygon offset controls register.
38 ///
39 typedef struct{
40     u32 reg;
41 }GX2PolygonControlReg;
42 
43 /// \brief Structure for stencil mask controls registers.
44 ///
45 typedef struct{
46     u32 reg[2];
47 }GX2StencilMaskReg;
48 
49 /// \brief Structure for alpha test controls registers.
50 ///
51 typedef struct{
52     u32 reg[2];
53 }GX2AlphaTestReg;
54 
55 /// \brief Structure for alpha to mask controls register.
56 ///
57 typedef struct{
58     u32 reg;
59 }GX2AlphaToMaskReg;
60 
61 /// \brief Structure for polygon offset controls registers.
62 ///
63 typedef struct{
64     union {
65         u32 u32All;
66         f32 f32All;
67     } reg[5];
68 }GX2PolygonOffsetReg;
69 
70 /// \brief Structure for target channel mask register.
71 ///
72 typedef struct{
73     u32 reg;
74 }GX2TargetChannelMaskReg;
75 
76 /// \brief Structure for AA mask register.
77 ///
78 typedef struct{
79     u32 reg;
80 }GX2AAMaskReg;
81 
82 /// \brief Structure for color control register.
83 ///
84 typedef struct{
85     u32 reg;
86 }GX2ColorControlReg;
87 
88 /// \brief Structure for blend control registers.
89 ///
90 typedef struct{
91     u32 reg[2];
92 }GX2BlendControlReg;
93 
94 /// \brief Structure for blend constant color registers.
95 ///
96 typedef struct{
97     union {
98         u32 u32All;
99         f32 f32All;
100     } reg[4];
101 }GX2BlendConstantColorReg;
102 
103 /// \brief Structure for point size register.
104 ///
105 typedef struct{
106     u32 reg;
107 }GX2PointSizeReg;
108 
109 /// \brief Structure for point limits register.
110 ///
111 typedef struct{
112     u32 reg;
113 }GX2PointLimitsReg;
114 
115 /// \brief Structure for line width register.
116 ///
117 typedef struct{
118     u32 reg;
119 }GX2LineWidthReg;
120 
121 /// \brief Structure for viewport registers.
122 ///
123 typedef struct{
124     union {
125         u32 u32All;
126         f32 f32All;
127     } reg[12];
128 }GX2ViewportReg;
129 
130 /// \brief Structure for scissor registers.
131 ///
132 typedef struct{
133     u32 reg[2];
134 }GX2ScissorReg;
135 
136 
137 /// \brief Function to update depth & stencil controls state.
138 ///
139 /// \param pState            Pointer to GX2DepthStencilControlReg structure to update.
140 /// \param depthEnable       enables depth testing. if depthEnable is false,
141 ///                          then all depth operations are disabled
142 ///                          (depthWriteEnable is ignored), and color writes
143 ///                          will not be impacted by the depth test.
144 /// \param depthWriteEnable  enables writing to the depth buffer
145 ///                          if the depth test passes.
146 /// \param depthFunc         function that compares the depth at each sample
147 ///                          in the fragment to the destination depth at the
148 ///                          corresponding sample point.
149 /// \param stencilTestEnable enables stencil testing. if disabled, all pixels
150 ///                          pass the stencil test. If there is no stencil
151 ///                          buffer this is treated as disabled.
152 /// \param backStencilEnable if false, forces all quads to be stencil tested
153 ///                          as frontface quads.
154 /// \param frontStencilFunc  function that compares stencil reference value to
155 ///                          the destination stencil value for frontface quads.
156 /// \param frontStencilZPass stencil operation for frontface quads if the
157 ///                          stencil and depth functions both pass.
158 /// \param frontStencilZFail stencil operation for frontface quads if the
159 ///                          stencil function passes and the depth function
160 ///                          fails.
161 /// \param frontStencilFail  stencil operation for frontface quads if the
162 ///                          stencil function fails.
163 /// \param backStencilFunc   function that compares backface stencil reference
164 ///                          value to the destination stencil value for
165 ///                          backface quads.
166 /// \param backStencilZPass  stencil operation for backface quads if the
167 ///                          stencil and depth functions both pass.
168 /// \param backStencilZFail  stencil operation for backface quads if the
169 ///                          stencil function passes and the depth function
170 ///                          fails.
171 /// \param backStencilFail   stencil operation for backface quads if the
172 ///                          stencil function fails.
173 ///
174 /// \donotcall \threadsafe \devonly \enddonotcall
175 ///
176 void GX2API GX2InitDepthStencilControlReg(GX2DepthStencilControlReg *pState,
177                                    GX2Boolean depthEnable,
178                                    GX2Boolean depthWriteEnable,
179                                    GX2CompareFunction depthFunc,
180                                    GX2Boolean stencilTestEnable,
181                                    GX2Boolean backStencilEnable,
182 
183                                    GX2CompareFunction frontStencilFunc,
184                                    GX2StencilFunction frontStencilZPass,
185                                    GX2StencilFunction frontStencilZFail,
186                                    GX2StencilFunction frontStencilFail,
187 
188                                    GX2CompareFunction backStencilFunc,
189                                    GX2StencilFunction backStencilZPass,
190                                    GX2StencilFunction backStencilZFail,
191                                    GX2StencilFunction backStencilFail);
192 
193 /// \brief Function to get depth & stencil controls state.
194 ///
195 /// \param pState             Pointer to GX2DepthStencilControlReg structure to unpack.
196 /// \param pDepthEnable       Pointer to store depth testing state.
197 /// \param pDepthWriteEnable  Pointer to store writing to the depth buffer state.
198 /// \param pDepthFunc         Pointer to store depth function state.
199 /// \param pStencilTestEnable Pointer to store stencil testing state.
200 /// \param pBackStencilEnable Pointer to store back stencil testing state.
201 /// \param pFrontStencilFunc  Pointer to store stencil func state.
202 /// \param pFrontStencilZPass Pointer to store stencil z pass state.
203 /// \param pFrontStencilZFail Pointer to store stencil z fail state.
204 /// \param pFrontStencilFail  Pointer to store stencil fail state.
205 /// \param pBackStencilFunc   Pointer to store back stencil func state.
206 /// \param pBackStencilZPass  Pointer to store back stencil z pass state.
207 /// \param pBackStencilZFail  Pointer to store back stencil z fail.
208 /// \param pBackStencilFail   Pointer to store back stencil fail state.
209 ///
210 /// \donotcall \threadsafe \devonly \enddonotcall
211 ///
212 void GX2API GX2GetDepthStencilControlReg(const GX2DepthStencilControlReg *pState,
213                                    GX2Boolean *pDepthEnable,
214                                    GX2Boolean *pDepthWriteEnable,
215                                    GX2CompareFunction *pDepthFunc,
216                                    GX2Boolean *pStencilTestEnable,
217                                    GX2Boolean *pBackStencilEnable,
218                                    GX2CompareFunction *pFrontStencilFunc,
219                                    GX2StencilFunction *pFrontStencilZPass,
220                                    GX2StencilFunction *pFrontStencilZFail,
221                                    GX2StencilFunction *pFrontStencilFail,
222                                    GX2CompareFunction *pBackStencilFunc,
223                                    GX2StencilFunction *pBackStencilZPass,
224                                    GX2StencilFunction *pBackStencilZFail,
225                                    GX2StencilFunction *pBackStencilFail);
226 
227 /// \brief Sets depth & stencil controls registers.
228 /// \param pState Pointer to GX2DepthStencilControlReg structure.
229 ///
230 /// \donotcall \gx2_typical \enddonotcall
231 ///
232 /// \writesgpu
233 /// \alwayswritesgpu
234 ///
235 void GX2API GX2SetDepthStencilControlReg(const GX2DepthStencilControlReg *pState);
236 
237 /// \brief Function to update culling, front/back polygon modes, polygon offset enables state.
238 ///
239 /// \param pState                Pointer to GX2PolygonControlReg structure to update.
240 /// \param frontFaceMode         front facing mode
241 /// \param cullFront             enables for front-face culling.
242 /// \param cullBack              enables for back-face culling.
243 /// \param enablePolygonModes    enables polygon mode.
244 /// \param polygonModeFront      mode to render front-facing polygons
245 /// \param polygonModeBack       mode to render back-facing polygons.
246 /// \param polyOffsetFrontEnable enables front facing polygon offset.
247 /// \param polyOffsetBackEnable  enables back facing polygon offset.
248 /// \param pointLineOffsetEnable enables polygon offset for non-triangle
249 ///                              primitives.
250 /// \donotcall \threadsafe \devonly \enddonotcall
251 ///
252 void GX2API GX2InitPolygonControlReg(GX2PolygonControlReg *pState,
253                                 GX2FrontFaceMode frontFaceMode,
254                                 GX2Boolean cullFront,
255                                 GX2Boolean cullBack,
256 
257                                 GX2Boolean     enablePolygonModes,
258                                 GX2PolygonMode polygonModeFront,
259                                 GX2PolygonMode polygonModeBack,
260 
261                                 GX2Boolean polyOffsetFrontEnable,
262                                 GX2Boolean polyOffsetBackEnable,
263                                 GX2Boolean pointLineOffsetEnable);
264 
265 /// \brief Function to get culling, front/back polygon modes, polygon offset enables state.
266 ///
267 /// \param pState                 Pointer to GX2PolygonControlReg structure to update.
268 /// \param pFrontFaceMode         Pointer to store front facing mode.
269 /// \param pCullFront             Pointer to store front-face culling state.
270 /// \param pCullBack              Pointer to store back-face culling state.
271 /// \param pEnablePolygonModes    Pointer to store polygon mode.
272 /// \param pPolygonModeFront      Pointer to store mode to render front-facing polygons
273 /// \param pPolygonModeBack       Pointer to store mode to render back-facing polygons.
274 /// \param pPolyOffsetFrontEnable Pointer to store facing polygon offset state.
275 /// \param pPolyOffsetBackEnable  Pointer to store back facing polygon offset state.
276 /// \param pPointLineOffsetEnable Pointer to store polygon offset for non-triangle
277 ///                               primitives state.
278 /// \donotcall \threadsafe \devonly \enddonotcall
279 ///
280 void GX2API GX2GetPolygonControlReg(const GX2PolygonControlReg *pState,
281                                 GX2FrontFaceMode *pFrontFaceMode,
282                                 GX2Boolean *pCullFront,
283                                 GX2Boolean *pCullBack,
284 
285                                 GX2Boolean     *pEnablePolygonModes,
286                                 GX2PolygonMode *pPolygonModeFront,
287                                 GX2PolygonMode *pPolygonModeBack,
288 
289                                 GX2Boolean *pPolyOffsetFrontEnable,
290                                 GX2Boolean *pPolyOffsetBackEnable,
291                                 GX2Boolean *pPointLineOffsetEnable);
292 
293 /// \brief Sets culling, front/back polygon modes, polygon offset enables registers.
294 /// \param pState Pointer to GX2PolygonControlReg structure.
295 ///
296 /// \donotcall \gx2_typical \enddonotcall
297 ///
298 /// \writesgpu
299 /// \alwayswritesgpu
300 ///
301 void GX2API GX2SetPolygonControlReg(const GX2PolygonControlReg *pState);
302 
303 /// \brief Function to update stencil mask state.
304 ///
305 /// \param pState          Pointer to GX2StencilMaskReg structure to update.
306 /// \param preMaskFront    mask used with the reference and current stencil values
307 ///                        prior to doing the stencil test for front-facing pixels
308 /// \param writeMaskFront  mask used when writing to the stencil buffer for
309 ///                        front-facing pixels
310 /// \param refFront        reference stencil value for front-facing pixels
311 /// \param preMaskBack     the mask used with the reference and current stencil values
312 ///                        prior to doing the stencil test for back-facing pixels
313 /// \param writeMaskBack   mask used when writing to the stencil buffer for
314 ///                        back-facing pixels
315 /// \param refBack         reference stencil value for back-facing pixels
316 ///
317 /// \donotcall \threadsafe \devonly \enddonotcall
318 ///
319 void GX2API GX2InitStencilMaskReg(GX2StencilMaskReg *pState,
320                            u8 preMaskFront,
321                            u8 writeMaskFront,
322                            u8 refFront,
323                            u8 preMaskBack,
324                            u8 writeMaskBack,
325                            u8 refBack);
326 
327 /// \brief Function to get stencil mask state.
328 ///
329 /// \param pState          Pointer to GX2StencilMaskReg structure to unpack.
330 /// \param pPreMaskFront   Pointer to store the stencil test state for front-facing pixels.
331 /// \param pWriteMaskFront Pointer to store mask state used when writing to the stencil buffer for
332 ///                        front-facing pixels
333 /// \param pRefFront       Pointer to store reference stencil value for front-facing pixels
334 /// \param pPreMaskBack    Pointer to store mask state used with the reference and current stencil values
335 ///                        prior to doing the stencil test for back-facing pixels
336 /// \param pWriteMaskBack  Pointer to store mask sate used when writing to the stencil buffer for
337 ///                        back-facing pixels
338 /// \param pRefBack        Pointer to store reference stencil value for back-facing pixels
339 ///
340 /// \donotcall \threadsafe \devonly \enddonotcall
341 ///
342 void GX2API GX2GetStencilMaskReg(const GX2StencilMaskReg *pState,
343                            u8 *pPreMaskFront,
344                            u8 *pWriteMaskFront,
345                            u8 *pRefFront,
346                            u8 *pPreMaskBack,
347                            u8 *pWriteMaskBack,
348                            u8 *pRefBack);
349 
350 /// \brief Set stencil mask registers.
351 /// \param pState Pointer to GX2StencilMaskReg structure.
352 ///
353 /// \donotcall \gx2_typical \enddonotcall
354 ///
355 /// \writesgpu
356 /// \alwayswritesgpu
357 ///
358 void GX2API GX2SetStencilMaskReg(const GX2StencilMaskReg *pState);
359 
360 /// \brief Function to update alpha-test-control state.
361 ///
362 /// \param pState Pointer to GX2AlphaTestReg structure to update
363 /// \param alphaTestEnable Enable if GX2_ENABLE, Disable if GX2_DISABLE
364 /// \param alphaFunc Compare Function for alpha testing
365 /// \param ref Reference value for alpha testing
366 ///
367 /// \donotcall \threadsafe \devonly \enddonotcall
368 ///
369 void GX2API GX2InitAlphaTestReg(GX2AlphaTestReg *pState,
370                          GX2Boolean alphaTestEnable,
371                          GX2CompareFunction alphaFunc,
372                          f32 ref);
373 
374 /// \brief Function to get alpha-test-control state.
375 ///
376 /// \param pState Pointer to GX2AlphaTestReg structure to unpack
377 /// \param pAlphaTestEnable   Pointer to store alpha test state,
378 /// \param pAlphaFunc Compare Pointer to store function for alpha testing
379 /// \param pRef               Pointer to store reference value for alpha testing
380 ///
381 /// \donotcall \threadsafe \devonly \enddonotcall
382 ///
383 void GX2API GX2GetAlphaTestReg(const GX2AlphaTestReg *pState,
384                          GX2Boolean *pAlphaTestEnable,
385                          GX2CompareFunction *pAlphaFunc,
386                          f32 *pRef);
387 
388 /// \brief Set alpha-test-control registers.
389 /// \param pState Pointer to GX2AlphaTestReg structure.
390 ///
391 /// \donotcall \gx2_typical \enddonotcall
392 ///
393 /// \writesgpu
394 /// \alwayswritesgpu
395 ///
396 void GX2API GX2SetAlphaTestReg(const GX2AlphaTestReg *pState);
397 
398 /// \brief Function to update screen-door transparency state.
399 ///
400 /// \param pState Pointer to GX2AlphaToMaskReg structure to update
401 /// \param alphaToMaskEnable if enabled, the sample mask is ANDed with a mask
402 ///                          produced from the alpha value.
403 /// \param mode Mode for the alpha mask.
404 ///
405 /// \donotcall \threadsafe \devonly \enddonotcall
406 ///
407 void GX2API GX2InitAlphaToMaskReg(GX2AlphaToMaskReg *pState,
408                            GX2Boolean alphaToMaskEnable,
409                            GX2AlphaToMaskMode mode);
410 
411 /// \brief Function to get screen-door transparency state.
412 ///
413 /// \param pState Pointer to GX2AlphaToMaskReg structure to unpack
414 /// \param pAlphaToMaskEnable Pointer to store mask state.
415 /// \param pMode Pointer to store mode for the alpha mask.
416 ///
417 /// \donotcall \threadsafe \devonly \enddonotcall
418 ///
419 void GX2API GX2GetAlphaToMaskReg(const GX2AlphaToMaskReg *pState,
420                            GX2Boolean *pAlphaToMaskEnable,
421                            GX2AlphaToMaskMode *pMode);
422 
423 /// \brief Set screen-door transparency registers.
424 /// \param pState Pointer to GX2AlphaToMaskReg structure.
425 ///
426 /// \donotcall \gx2_typical \enddonotcall
427 ///
428 /// \writesgpu
429 /// \alwayswritesgpu
430 ///
431 void GX2API GX2SetAlphaToMaskReg(const GX2AlphaToMaskReg *pState);
432 
433 /// \brief Function to update polygon-offset state.
434 ///
435 /// Please refer to \ref GX2PolygonOffsetInfo for more information.
436 ///
437 /// \param pState       Pointer to GX2PolygonOffsetReg structure to update.
438 /// \param frontOffset  offset value for front-facing polygons
439 /// \param frontSlopeScale  slope scale value for front-facing polygons
440 /// \param backOffset   offset value for back-facing polygons
441 /// \param backSlopeScale   slope scale value for back-facing polygons
442 /// \param clamp        maximum (if positive) or minimum
443 ///                         (if negative) value for the final offset, ignored if 0
444 ///
445 /// \donotcall \threadsafe \devonly \enddonotcall
446 ///
447 void GX2API GX2InitPolygonOffsetReg(GX2PolygonOffsetReg *pState,
448                              f32 frontOffset, f32 frontSlopeScale,
449                              f32 backOffset,  f32 backSlopeScale,  f32 clamp);
450 
451 /// \brief Function to get polygon-offset state.
452 ///
453 /// \param pState       Pointer to GX2PolygonOffsetReg structure to unpack.
454 /// \param pFrontOffset Pointer to store offset value for front-facing polygons
455 /// \param pFrontSlopeScale Pointer to store offset scale value for front-facing polygons
456 /// \param pBackOffset  Pointer to store offset value for back-facing polygons
457 /// \param pBackSlopeScale  Pointer to store offset scale value for back-facing polygons
458 /// \param pClamp       Pointer to store maximum (if positive) or minimum
459 ///                     (if negative) value for the final offset
460 ///
461 /// \donotcall \threadsafe \devonly \enddonotcall
462 ///
463 void GX2API GX2GetPolygonOffsetReg(const GX2PolygonOffsetReg *pState,
464                              f32 *pFrontOffset, f32 *pFrontSlopeScale,
465                              f32 *pBackOffset,  f32 *pBackSlopeScale,  f32 *pClamp);
466 
467 /// \brief Set polygon-offset registers.
468 /// \param pState Pointer to GX2PolygonOffsetReg structure.
469 ///
470 /// \donotcall \gx2_typical \enddonotcall
471 ///
472 /// \writesgpu
473 /// \alwayswritesgpu
474 ///
475 void GX2API GX2SetPolygonOffsetReg(const GX2PolygonOffsetReg *pState);
476 
477 /// \brief Function to update color channels state.
478 ///
479 /// \param pState  Pointer to GX2TargetChannelMaskReg structure to update.
480 /// \param target0 positive mask for writing to MRT 0 components.
481 /// \param target1 positive mask for writing to MRT 1 components.
482 /// \param target2 positive mask for writing to MRT 2 components.
483 /// \param target3 positive mask for writing to MRT 3 components.
484 /// \param target4 positive mask for writing to MRT 4 components.
485 /// \param target5 positive mask for writing to MRT 5 components.
486 /// \param target6 positive mask for writing to MRT 6 components.
487 /// \param target7 positive mask for writing to MRT 7 components.
488 ///
489 /// \donotcall \threadsafe \devonly \enddonotcall
490 ///
491 void GX2API GX2InitTargetChannelMasksReg(GX2TargetChannelMaskReg *pState,
492                                    GX2ChannelMask target0,
493                                    GX2ChannelMask target1,
494                                    GX2ChannelMask target2,
495                                    GX2ChannelMask target3,
496                                    GX2ChannelMask target4,
497                                    GX2ChannelMask target5,
498                                    GX2ChannelMask target6,
499                                    GX2ChannelMask target7);
500 
501 /// \brief Function to get color channels state.
502 ///
503 /// \param pState   Pointer to GX2TargetChannelMaskReg structure to unpack.
504 /// \param pTarget0 Pointer to store positive mask for writing to MRT 0 components.
505 /// \param pTarget1 Pointer to store positive mask for writing to MRT 1 components.
506 /// \param pTarget2 Pointer to store positive mask for writing to MRT 2 components.
507 /// \param pTarget3 Pointer to store positive mask for writing to MRT 3 components.
508 /// \param pTarget4 Pointer to store positive mask for writing to MRT 4 components.
509 /// \param pTarget5 Pointer to store positive mask for writing to MRT 5 components.
510 /// \param pTarget6 Pointer to store positive mask for writing to MRT 6 components.
511 /// \param pTarget7 Pointer to store positive mask for writing to MRT 7 components.
512 ///
513 /// \donotcall \threadsafe \devonly \enddonotcall
514 ///
515 void GX2API GX2GetTargetChannelMasksReg(const GX2TargetChannelMaskReg *pState,
516                                    GX2ChannelMask *pTarget0,
517                                    GX2ChannelMask *pTarget1,
518                                    GX2ChannelMask *pTarget2,
519                                    GX2ChannelMask *pTarget3,
520                                    GX2ChannelMask *pTarget4,
521                                    GX2ChannelMask *pTarget5,
522                                    GX2ChannelMask *pTarget6,
523                                    GX2ChannelMask *pTarget7);
524 
525 /// \brief Set which color channels will be written to for each render target registers.
526 ///
527 /// \note The set of enabled targets is controlled by both the number of
528 ///       shader outputs as well as these values (and by multiwriteEnable,
529 ///       \ref GX2SetColorControl).
530 ///       It's probably a good idea to disable unused targets here.
531 ///
532 /// \note Using MRTs is not compatible with dual-source blending
533 ///       (see \ref GX2SetBlendControl).  For dual-source blending,
534 ///       only target0 needs to be enabled.
535 ///
536 /// \param pState Pointer to GX2TargetChannelMaskReg structure.
537 ///
538 /// \donotcall \gx2_typical \enddonotcall
539 ///
540 /// \writesgpu
541 /// \alwayswritesgpu
542 ///
543 void GX2API GX2SetTargetChannelMasksReg(const GX2TargetChannelMaskReg *pState);
544 
545 /// \brief Function to update AA mask state.
546 ///
547 /// \param pState  Pointer to GX2AAMaskReg structure to update.
548 /// \param upperLeftMask contains an 8-bit mask, LSB is Sample0, MSB is Sample7
549 /// \param upperRightMask contains an 8-bit mask, LSB is Sample0, MSB is Sample7
550 /// \param lowerLeftMask contains an 8-bit mask, LSB is Sample0, MSB is Sample7
551 /// \param lowerRightMask contains an 8-bit mask, LSB is Sample0, MSB is Sample7
552 ///
553 /// \donotcall \threadsafe \devonly \enddonotcall
554 ///
555 void GX2API GX2InitAAMaskReg(GX2AAMaskReg *pState,
556                              u8 upperLeftMask,
557                              u8 upperRightMask,
558                              u8 lowerLeftMask,
559                              u8 lowerRightMask);
560 
561 /// \brief Function to get AA mask state.
562 ///
563 /// \param pState   Pointer to GX2AAMaskReg structure to unpack.
564 /// \param pUpperLeftMask Pointer to store 8-bit mask
565 /// \param pUpperRightMask Pointer to store 8-bit mask
566 /// \param pLowerLeftMask Pointer to store 8-bit mask
567 /// \param pLowerRightMask Pointer to store 8-bit mask
568 ///
569 /// \donotcall \threadsafe \devonly \enddonotcall
570 ///
571 void GX2API GX2GetAAMaskReg(const GX2AAMaskReg *pState,
572                             u8 *pUpperLeftMask,
573                             u8 *pUpperRightMask,
574                             u8 *pLowerLeftMask,
575                             u8 *pLowerRightMask);
576 
577 /// \brief Sets the 4 masks to be used for Multisample AA.  The masks are
578 /// applied to each set of 2x2 screen-aligned pixels.
579 ///
580 /// \param pState Pointer to GX2AAMaskReg structure.
581 ///
582 /// \donotcall \gx2_typical \enddonotcall
583 ///
584 /// \writesgpu
585 /// \alwayswritesgpu
586 ///
587 void GX2API GX2SetAAMaskReg(const GX2AAMaskReg *pState);
588 
589 /// \brief Function to update color-control state.
590 ///
591 /// \param pState Pointer to GX2ColorControlReg structure.
592 /// \param lop  a logical operation that describes how source & dest are combined.
593 ///      Logic op is mutually exclusive with blending.  The lop must be GX2_LOGIC_OP_COPY
594 ///      if ANY blending is enabled (if blendEnableMask is not 0).
595 /// \param blendEnableMask   an 8-bit mask that enables blending per render target.
596 /// \param multiwriteEnable  if true, the output of MRT 0 is sent to all MRTs.
597 /// \param colorBufferEnable enables drawing to the color buffer.
598 ///      The colorBufferEnable should be set to GX2_DISABLE for optimal performance when doing
599 ///      Z only rendering.
600 ///
601 /// \donotcall \threadsafe \devonly \enddonotcall
602 ///
603 void GX2API GX2InitColorControlReg(GX2ColorControlReg *pState,
604                              GX2LogicOp  lop,
605                              u8          blendEnableMask,
606                              GX2Boolean  multiwriteEnable,
607                              GX2Boolean  colorBufferEnable);
608 
609 /// \brief Function to get color-control state.
610 ///
611 /// \param pState Pointer to GX2ColorControlReg structure.
612 /// \param pLop   Pointer to store a logical operation that describes how source & dest are combined.
613 /// \param pBlendEnableMask   Pointer to store an 8-bit mask that enables blending per render target.
614 /// \param pMultiwriteEnable  Pointer to store state for multi write.
615 /// \param pColorBufferEnable Pointer to store state for drawing to color buffer.
616 ///
617 /// \donotcall \threadsafe \devonly \enddonotcall
618 ///
619 void GX2API GX2GetColorControlReg(const GX2ColorControlReg *pState,
620                              GX2LogicOp  *pLop,
621                              u8          *pBlendEnableMask,
622                              GX2Boolean  *pMultiwriteEnable,
623                              GX2Boolean  *pColorBufferEnable);
624 
625 /// \brief Set color-control registers.
626 ///
627 /// \note Enabling multiwriteEnable is not compatible with dual-source blending
628 ///       (see \ref GX2SetBlendControl).
629 ///
630 /// \param pState Pointer to GX2ColorControlReg structure.
631 ///
632 /// \donotcall \gx2_typical \enddonotcall
633 ///
634 /// \writesgpu
635 /// \alwayswritesgpu
636 ///
637 void GX2API GX2SetColorControlReg(const GX2ColorControlReg *pState);
638 
639 /// \brief Function to update blend-control state.
640 ///
641 /// \param pState         Pointer to GX2BlendControlReg structure to update.
642 /// \param target         render target to set blend controls for
643 /// \param colorSrcBlend  source blend function for color components
644 /// \param colorDstBlend  destination blend function for color components
645 /// \param colorCombine   source/dest combination function for color components
646 /// \param separateAlphaBlend  if true, use the following fields for alpha blend.
647 ///                            if false, use the color fields for alpha blend.
648 /// \param alphaSrcBlend  source blend function for alpha
649 /// \param alphaDstBlend  destination blend function for alpha
650 /// \param alphaCombine   source/dest combination function for alpha
651 ///
652 /// \donotcall \threadsafe \devonly \enddonotcall
653 ///
654 void GX2API GX2InitBlendControlReg(GX2BlendControlReg *pState,
655                              GX2RenderTarget target,
656                              GX2BlendFunction colorSrcBlend,
657                              GX2BlendFunction colorDstBlend,
658                              GX2BlendCombine  colorCombine,
659                              GX2Boolean       separateAlphaBlend,
660                              GX2BlendFunction alphaSrcBlend,
661                              GX2BlendFunction alphaDstBlend,
662                              GX2BlendCombine  alphaCombine);
663 
664 /// \brief Function to get blend-control state.
665 ///
666 /// \param pState          Pointer to GX2BlendControlReg structure to unpack.
667 /// \param pTarget         Pointer to store render target
668 /// \param pColorSrcBlend  Pointer to store source blend function for color components
669 /// \param pColorDstBlend  Pointer to store destination blend function for color components
670 /// \param pColorCombine   Pointer to store source/dest combination function for color components
671 /// \param pSeparateAlphaBlend  Pointer to store separate alpha blend state.
672 /// \param pAlphaSrcBlend  Pointer to store source blend function for alpha
673 /// \param pAlphaDstBlend  Pointer to store destination blend function for alpha
674 /// \param pAlphaCombine   Pointer to store source/dest combination function for alpha
675 ///
676 /// \donotcall \threadsafe \devonly \enddonotcall
677 ///
678 void GX2API GX2GetBlendControlReg(const GX2BlendControlReg *pState,
679                              GX2RenderTarget *pTarget,
680                              GX2BlendFunction *pColorSrcBlend,
681                              GX2BlendFunction *pColorDstBlend,
682                              GX2BlendCombine  *pColorCombine,
683                              GX2Boolean       *pSeparateAlphaBlend,
684                              GX2BlendFunction *pAlphaSrcBlend,
685                              GX2BlendFunction *pAlphaDstBlend,
686                              GX2BlendCombine  *pAlphaCombine);
687 
688 /// \brief Set blend-control registers.
689 ///
690 /// \note Using a blend function that includes source 1 implies dual-source blending.
691 ///       This is mutually exclusive with MRTs.  It is also not compatible
692 ///       with multiwriteEnable (\ref GX2SetColorControl).
693 ///       It requires a pixel shader with 2 color output channels
694 ///       (gl_FragData[0] and gl_FragData[1]).
695 ///
696 /// \param pState Pointer to GX2BlendControlReg structure.
697 ///
698 /// \donotcall \gx2_typical \enddonotcall
699 ///
700 /// \writesgpu
701 /// \alwayswritesgpu
702 ///
703 void GX2API GX2SetBlendControlReg(const GX2BlendControlReg *pState);
704 
705 /// \brief Function to update the components of the constant blend color.
706 ///
707 /// \param pState Pointer to GX2BlendConstantColorReg structure to update.
708 /// \param red   red
709 /// \param green green
710 /// \param blue  blue
711 /// \param alpha alpha
712 ///
713 /// \donotcall \threadsafe \devonly \enddonotcall
714 ///
715 void GX2API GX2InitBlendConstantColorReg(GX2BlendConstantColorReg *pState,
716                                    f32 red, f32 green, f32 blue, f32 alpha);
717 
718 /// \brief Function to get the components of the constant blend color.
719 ///
720 /// \param pState Pointer to GX2BlendConstantColorReg structure to unpack.
721 /// \param pRed   Pointer to store red value
722 /// \param pGreen Pointer to store green value
723 /// \param pBlue  Pointer to store blue value
724 /// \param pAlpha Pointer to store alpha value
725 ///
726 /// \donotcall \threadsafe \devonly \enddonotcall
727 ///
728 void GX2API GX2GetBlendConstantColorReg(const GX2BlendConstantColorReg *pState,
729                                    f32 *pRed, f32 *pGreen, f32 *pBlue, f32 *pAlpha);
730 
731 /// \brief Set the components of the constant blend color registers.
732 ///
733 /// \param pState Pointer to GX2BlendConstantColorReg structure.
734 ///
735 /// \donotcall \gx2_typical \enddonotcall
736 ///
737 /// \writesgpu
738 /// \alwayswritesgpu
739 ///
740 void GX2API GX2SetBlendConstantColorReg(const GX2BlendConstantColorReg *pState);
741 
742 /// \brief Function to update the point size.
743 ///
744 /// Width and height are specified in pixels, with a precision of 1/8 pixel.
745 ///
746 /// \param pState Pointer to GX2PointSizeReg structure to update.
747 /// \param width Width of points
748 /// \param height Height of points
749 ///
750 /// \donotcall \threadsafe \devonly \enddonotcall
751 ///
752 void GX2API GX2InitPointSizeReg(GX2PointSizeReg *pState,
753                           f32 width, f32 height);
754 
755 /// \brief Function to get the point size.
756 ///
757 /// \param pState Pointer to GX2PointSizeReg structure to unpack
758 /// \param pWidth Pointer to store width of points
759 /// \param pHeight Pointer to store height of points
760 ///
761 /// \donotcall \threadsafe \devonly \enddonotcall
762 ///
763 void GX2API GX2GetPointSizeReg(const GX2PointSizeReg *pState,
764                           f32 *pWidth, f32 *pHeight);
765 
766 /// \brief Set the "diameter" of rasterized points registers.
767 ///
768 /// \param pState Pointer to GX2PointSizeReg structure.
769 ///
770 /// \donotcall \gx2_typical \enddonotcall
771 ///
772 /// \writesgpu
773 /// \alwayswritesgpu
774 ///
775 void GX2API GX2SetPointSizeReg(const GX2PointSizeReg *pState);
776 
777 /// \brief Function to update the minimum & maximum point sizes
778 /// (when specified by a shader, for instance).
779 ///
780 /// Width and height are specified in pixels, with a precision of 1/8 pixel.
781 ///
782 /// \param pState Pointer to GX2PointLimitsReg structure to update.
783 /// \param min limit min size of points
784 /// \param max limit max size of points
785 ///
786 /// \donotcall \threadsafe \devonly \enddonotcall
787 ///
788 void GX2API GX2InitPointLimitsReg(GX2PointLimitsReg *pState,
789                             f32 min, f32 max);
790 
791 /// \brief Function to get the minimum & maximum point sizes
792 ///
793 /// \param pState Pointer to GX2PointLimitsReg structure to unpack.
794 /// \param pMin Pointer to store limit min size of points
795 /// \param pMax Pointer to store limit max size of points
796 ///
797 /// \donotcall \threadsafe \devonly \enddonotcall
798 ///
799 void GX2API GX2GetPointLimitsReg(const GX2PointLimitsReg *pState,
800                             f32 *pMin, f32 *pMax);
801 
802 /// \brief Set the minimum & maximum point sizes registers.
803 ///
804 /// \param pState Pointer to GX2PointLimitsReg structure.
805 ///
806 /// \donotcall \gx2_typical \enddonotcall
807 ///
808 /// \writesgpu
809 /// \alwayswritesgpu
810 ///
811 void GX2API GX2SetPointLimitsReg(const GX2PointLimitsReg *pState);
812 
813 /// \brief Function to update the width of rasterized lines.
814 ///
815 /// Width is specified in pixels, with a precision of 1/8 pixel.
816 ///
817 /// \param pState Pointer to GX2LineWidthReg structure to update.
818 /// \param width Width of lines.
819 ///
820 /// \donotcall \threadsafe \devonly \enddonotcall
821 ///
822 void GX2API GX2InitLineWidthReg(GX2LineWidthReg *pState,
823                           f32 width);
824 
825 /// \brief Function to get the width of rasterized lines.
826 ///
827 /// \param pState Pointer to GX2LineWidthReg structure to unpack.
828 /// \param pWidth Pointer to store width of lines
829 ///
830 /// \donotcall \threadsafe \devonly \enddonotcall
831 ///
832 void GX2API GX2GetLineWidthReg(const GX2LineWidthReg *pState,
833                           f32 *pWidth);
834 
835 /// \brief Set the width of rasterized lines registers
836 ///
837 /// \param pState Pointer to GX2LineWidthReg structure.
838 ///
839 /// \donotcall \gx2_typical \enddonotcall
840 ///
841 /// \writesgpu
842 /// \alwayswritesgpu
843 ///
844 void GX2API GX2SetLineWidthReg(const GX2LineWidthReg *pState);
845 
846 /// \brief Function to update viewport and depth range.
847 ///
848 /// \param pState Pointer to GX2ViewportReg structure to update.
849 /// \param xOrig orig x point of viewport
850 /// \param yOrig orig y point of viewport
851 /// \param wd width of viewport
852 /// \param ht height of viewport
853 /// \param nearZ near range of depth (typically 0.0)
854 /// \param farZ far range of depth (typically 1.0)
855 ///
856 /// \donotcall \threadsafe \devonly \enddonotcall
857 ///
858 void GX2API GX2InitViewportReg(GX2ViewportReg *pState,
859                          f32 xOrig, f32 yOrig, f32 wd, f32 ht, f32 nearZ, f32 farZ);
860 
861 /// \brief Version of GX2InitViewportReg to call when Z output range is 0 < z < 1.
862 ///
863 /// \param pState Pointer to GX2ViewportReg structure to update.
864 /// \param xOrig orig x point of viewport
865 /// \param yOrig orig y point of viewport
866 /// \param wd width of viewport
867 /// \param ht height of viewport
868 /// \param nearZ near range of depth (typically 0.0)
869 /// \param farZ far range of depth (typically 1.0)
870 ///
871 /// \donotcall \threadsafe \devonly \enddonotcall
872 ///
GX2InitViewportRegHalfZ(GX2ViewportReg * pState,f32 xOrig,f32 yOrig,f32 wd,f32 ht,f32 nearZ,f32 farZ)873 GX2_INLINE void GX2InitViewportRegHalfZ(GX2ViewportReg *pState,
874                          f32 xOrig, f32 yOrig, f32 wd, f32 ht, f32 nearZ, f32 farZ)
875 {
876     GX2InitViewportReg(pState, xOrig, yOrig, wd, ht, (2*nearZ-farZ), farZ);
877 }
878 
879 /// \brief Function to get viewport and depth range.
880 ///
881 /// \param pState Pointer to GX2ViewportReg structure to update.
882 /// \param pXOrig Pointer to store orig x point of viewport
883 /// \param pYOrig Pointer to store orig y point of viewport
884 /// \param pWd Pointer to store width of viewport
885 /// \param pHt Pointer to store height of viewport
886 /// \param pNearZ Pointer to store near range of depth
887 /// \param pFarZ Pointer to store far range of depth
888 ///
889 /// \donotcall \threadsafe \devonly \enddonotcall
890 ///
891 void GX2API GX2GetViewportReg(const GX2ViewportReg *pState,
892                          f32 *pXOrig, f32 *pYOrig, f32 *pWd, f32 *pHt, f32 *pNearZ, f32 *pFarZ);
893 
894 
895 // \brief Version of GX2GetViewportReg to call when Z output range is 0 < z < 1.
896 ///
897 /// \param pState Pointer to GX2ViewportReg structure to update.
898 /// \param pXOrig Pointer to store orig x point of viewport
899 /// \param pYOrig Pointer to store orig y point of viewport
900 /// \param pWd Pointer to store width of viewport
901 /// \param pHt Pointer to store height of viewport
902 /// \param pNearZ Pointer to store near range of depth
903 /// \param pFarZ Pointer to store far range of depth
904 ///
905 /// \donotcall \threadsafe \devonly \enddonotcall
906 ///
GX2GetViewportRegHalfZ(const GX2ViewportReg * pState,f32 * pXOrig,f32 * pYOrig,f32 * pWd,f32 * pHt,f32 * pNearZ,f32 * pFarZ)907 GX2_INLINE void GX2GetViewportRegHalfZ(const GX2ViewportReg *pState,
908                         f32 *pXOrig, f32 *pYOrig, f32 *pWd, f32 *pHt, f32 *pNearZ, f32 *pFarZ)
909 {
910     GX2GetViewportReg(pState, pXOrig, pYOrig, pWd, pHt, pNearZ, pFarZ);
911     *pNearZ = (*pNearZ  + *pFarZ) * 0.5f;
912 }
913 
914 /// \brief Set viewport and depth range registers.
915 ///
916 /// \param pState Pointer to GX2ViewportReg structure.
917 ///
918 /// \donotcall \gx2_typical \enddonotcall
919 ///
920 /// \writesgpu
921 /// \alwayswritesgpu
922 ///
923 void GX2API GX2SetViewportReg(const GX2ViewportReg *pState);
924 
925 
926 // \brief Version of GX2SetViewportReg to call when Z output range is 0 < z < 1.
927 // \note  This is identical to GX2SetViewportReg.  Only created for naming consistency.
928 ///
929 /// \param pState Pointer to GX2ViewportReg structure.
930 ///
931 /// \donotcall \gx2_typical \enddonotcall
932 ///
933 /// \writesgpu
934 /// \alwayswritesgpu
935 ///
GX2SetViewportRegHalfZ(const GX2ViewportReg * pState)936 GX2_INLINE void GX2SetViewportRegHalfZ(const GX2ViewportReg *pState) {
937     GX2SetViewportReg(pState);
938 }
939 
940 /// \brief Function to update scissor box.
941 ///
942 /// \param pState Pointer to GX2ScissorReg structure to update.
943 /// \param xOrig orig x point of scissor box
944 /// \param yOrig orig y point of scissor box
945 /// \param wd width of scissor box
946 /// \param ht height of scissor box
947 ///
948 /// \donotcall \threadsafe \devonly \enddonotcall
949 ///
950 void GX2API GX2InitScissorReg(GX2ScissorReg *pState,
951                         u32 xOrig, u32 yOrig, u32 wd, u32 ht);
952 
953 /// \brief Function to get scissor box.
954 ///
955 /// \param pState Pointer to GX2ScissorReg structure to unpack.
956 /// \param pXOrig orig x point of scissor box
957 /// \param pYOrig orig y point of scissor box
958 /// \param pWd width of scissor box
959 /// \param pHt height of scissor box
960 ///
961 /// \donotcall \threadsafe \devonly \enddonotcall
962 ///
963 void GX2API GX2GetScissorReg(const GX2ScissorReg *pState,
964                         u32 *pXOrig, u32 *pYOrig, u32 *pWd, u32 *pHt);
965 
966 /// \brief Set scissor box registers.
967 ///
968 /// \param pState Pointer to GX2ScissorReg structure.
969 ///
970 /// \donotcall \gx2_typical \enddonotcall
971 ///
972 /// \writesgpu
973 /// \alwayswritesgpu
974 ///
975 void GX2API GX2SetScissorReg(const GX2ScissorReg *pState);
976 
977 /// @}
978 
979 #ifdef __cplusplus
980 }
981 #endif // __cplusplus
982 
983 #endif // _CAFE_GX2_RENDERSTATE_REG_H_
984