1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: gd_GasFog.h
4
5 Copyright (C)2011 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 *---------------------------------------------------------------------------*/
14
15 #ifndef NN_GD_CTR_GD_GASFOG_H_
16 #define NN_GD_CTR_GD_GASFOG_H_
17
18 #include <nn/gd/CTR/gd_Types.h>
19 #include <nn/gd/CTR/gd_Result.h>
20 #include <nn/gd/CTR/gd_Utils.h>
21 #include <nn/dbg.h>
22
23 #if NN_GD_DOCUMENT_TYPE == ENGLISH
24 /* Please see man pages for details
25
26
27
28 */
29 #else
30 /* Please see man pages for details
31
32
33
34 */
35 #endif
36
37 namespace nn {
38 namespace gd {
39 namespace CTR {
40
41 /*********************************************************************************************************/
42 /********************************************** Internal data ********************************************/
43 class FogStage;
44 class System;
45 namespace internal
46 {
47
48 class System;
49 class FogStage;
50 class OutputStage;
51 class GasFogSettings
52 {
53 private:
54 // 0x0e0 (Fog/Gas mode, shading density, zFlip)
55 u32 m_ModeShadingZFlip;
56
57 // 0x0e1
58 u32 m_FogColor;
59
60 // 0x0e4
61 u32 m_GasAttenuation;
62
63 // 0x0e5
64 u32 m_GasMaxAcc;
65
66 // 0x120 - 0x122
67 u32 m_GasLightXY;
68 u32 m_GasLightZ;
69 u32 m_GasLightZ4ColorLut;
70
71 // 0x126
72 u32 m_GasDeltaZ;
73
74 // Mask for dirty attributes
75 u32 m_DirtyFieldMask;
76 u32 m_GasAutoAcc;
77
78 enum
79 {
80 MASK_FOG_GAS_MODE_UPDATED = 1 << 0,
81 MASK_FOG_COLOR_UPDATED = 1 << 1,
82 MASK_GAS_ATTENUATION_UPDATED = 1 << 2,
83 MASK_GAS_MAX_ACC_UPDATED = 1 << 3,
84 MASK_GAS_LIGHT_XY_UPDATED = 1 << 4,
85 MASK_GAS_LIGHT_Z_UPDATED = 1 << 5,
86 MASK_GAS_LIGHT_Z4_COLOR_LUT_UPDATED = 1 << 6,
87 MASK_GAS_DELTA_Z_UPDATED = 1 << 7,
88
89 MASK_RESERVED_MAX_U32 = 0xffffffffu
90 };
91
92 friend class nn::gd::CTR::FogStage;
93 friend class nn::gd::CTR::internal::System;
94 friend class nn::gd::CTR::System;
95 friend class nn::gd::CTR::internal::FogStage;
96 friend class nn::gd::CTR::internal::OutputStage;
97 }; // GasFogSettings
98
99 #if NN_GD_DOCUMENT_TYPE == ENGLISH
100 /* Please see man pages for details */
101 #else
102 /* Please see man pages for details */
103 #endif
104 extern GasFogSettings g_gasFogSettings;
105 } // internal
106
107
108 /*********************************************************************************************************/
109 /************************************************* FogStage ************************************************/
110 #if NN_GD_DOCUMENT_TYPE == ENGLISH
111 /* Please see man pages for details
112
113
114
115
116
117
118 */
119 #else
120 /* Please see man pages for details
121
122
123
124
125
126
127 */
128 #endif
129 class FogStage
130 {
131 public:
132
133 #if NN_GD_DOCUMENT_TYPE == ENGLISH
134 /* Please see man pages for details */
135 #else
136 /* Please see man pages for details */
137 #endif
138 enum Mode
139 {
140 MODE_NONE = 0x0,
141 MODE_FOG = 0x5,
142 MODE_GAS = 0x7,
143
144 MODE_RESERVED_MAX_U32 = 0xffffffffu
145 };
146
147 #if NN_GD_DOCUMENT_TYPE == ENGLISH
148 /* Please see man pages for details */
149 #else
150 /* Please see man pages for details */
151 #endif
152 enum GasColorLookUpTableInput
153 {
154 GAS_COLOR_INPUT_DENSITY = 0,
155 GAS_COLOR_INPUT_LIGHT_FACTOR = 1,
156
157 GAS_COLOR_INPUT_RESERVED_MAX_U32 = 0xffffffffu
158 };
159
160 #if NN_GD_DOCUMENT_TYPE == ENGLISH
161 /* Please see man pages for details */
162 #else
163 /* Please see man pages for details */
164 #endif
165 enum GasShadingDensitySource
166 {
167 GAS_SHADING_DENSITY_SOURCE_PLAIN = 0,
168 GAS_SHADING_DENSITY_SOURCE_DEPTH = 1,
169
170 GAS_SHADING_DENSITY_RESERVED_MAX_U32 = 0xffffffffu
171 };
172
173 #if NN_GD_DOCUMENT_TYPE == ENGLISH
174 /* Please see man pages for details
175
176 */
177 #else
178 /* Please see man pages for details
179
180 */
181 #endif
182 static void SetGasFogMode(Mode mode);
183
184 #if NN_GD_DOCUMENT_TYPE == ENGLISH
185 /* Please see man pages for details
186
187 */
188 #else
189 /* Please see man pages for details
190
191 */
192 #endif
193 static void SetGasShadingDensity(GasShadingDensitySource shadingDensitySrc);
194
195 #if NN_GD_DOCUMENT_TYPE == ENGLISH
196 /* Please see man pages for details
197
198 */
199 #else
200 /* Please see man pages for details
201
202 */
203 #endif
204 static void SetFogZFlip(gdBool zFlip);
205
206 #if NN_GD_DOCUMENT_TYPE == ENGLISH
207 /* Please see man pages for details
208
209
210
211 */
212 #else
213 /* Please see man pages for details
214
215
216
217 */
218 #endif
219 static void SetFogColor(u8 R, u8 G, u8 B);
220
221 #if NN_GD_DOCUMENT_TYPE == ENGLISH
222 /* Please see man pages for details
223
224 */
225 #else
226 /* Please see man pages for details
227
228 */
229 #endif
230 static void SetGasAttenuation(f32 attenuation);
231
232 #if NN_GD_DOCUMENT_TYPE == ENGLISH
233 /* Please see man pages for details
234
235 */
236 #else
237 /* Please see man pages for details
238
239 */
240 #endif
241 static void SetGasAccumulationMax(f32 maxAccumulation);
242
243 #if NN_GD_DOCUMENT_TYPE == ENGLISH
244 /* Please see man pages for details
245
246 */
247 #else
248 /* Please see man pages for details
249
250 */
251 #endif
252 static void SetGasAutoAccumulation(gdBool enableAutoAccumulation);
253
254 #if NN_GD_DOCUMENT_TYPE == ENGLISH
255 /* Please see man pages for details
256
257
258
259 */
260 #else
261 /* Please see man pages for details
262
263
264
265 */
266 #endif
267 static void SetGasLightXY(u8 lightMinimum, u8 lightMaximum, u8 lightAttenuation);
268
269 #if NN_GD_DOCUMENT_TYPE == ENGLISH
270 /* Please see man pages for details
271
272
273
274
275 */
276 #else
277 /* Please see man pages for details
278
279
280
281
282 */
283 #endif
284 static void SetGasLightZ(u8 scattMinimum, u8 scattMaximum, u8 scattAttenuation, u8 lz);
285
286 #if NN_GD_DOCUMENT_TYPE == ENGLISH
287 /* Please see man pages for details
288
289 */
290 #else
291 /* Please see man pages for details
292
293
294 */
295 #endif
296 static void SetGasLightColorLutInput(GasColorLookUpTableInput colorLutInput);
297
298 #if NN_GD_DOCUMENT_TYPE == ENGLISH
299 /* Please see man pages for details
300
301 */
302 #else
303 /* Please see man pages for details
304
305 */
306 #endif
307 static void SetGasDeltaZ(f32 deltaZ);
308
309 #if NN_GD_DOCUMENT_TYPE == ENGLISH
310 /* Please see man pages for details
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325 */
326 #else
327 /* Please see man pages for details
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344 */
345 #endif
346 static nnResult UploadFogLookUpTableNative(u32 lutStartIndex, u32* data, u32 countData);
347
348 #if NN_GD_DOCUMENT_TYPE == ENGLISH
349 /* Please see man pages for details
350
351
352
353
354
355
356
357
358
359
360
361
362
363 */
364 #else
365 /* Please see man pages for details
366
367
368
369
370
371
372
373
374
375
376
377
378
379 */
380 #endif
381 static nnResult UploadFogLookUpTableFloat(u32 lutStartIndex, const f32* dataValue, const f32* dataDelta, u32 countData);
382
383 #if NN_GD_DOCUMENT_TYPE == ENGLISH
384 /* Please see man pages for details
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401 */
402 #else
403 /* Please see man pages for details
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420 */
421 #endif
422 static nnResult UploadGasLookUpTableNative(u32 lutStartIndex, u32* data, u32 countData);
423
424 #if NN_GD_DOCUMENT_TYPE == ENGLISH
425 /* Please see man pages for details
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441 */
442 #else
443 /* Please see man pages for details
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463 */
464 #endif
465 static nnResult UploadGasLookUpTableFloat(u32 lutStartIndex, f32* dataValue, f32* dataDelta, u32 countData);
466
467 #if NN_GD_DOCUMENT_TYPE == ENGLISH
468 /* Please see man pages for details
469 */
470 #else
471 /* Please see man pages for details
472 */
473 #endif
474 class Helper
475 {
476 public:
477
478 #if NN_GD_DOCUMENT_TYPE == ENGLISH
479 /* Please see man pages for details
480
481
482
483
484
485
486
487
488 */
489 #else
490 /* Please see man pages for details
491
492
493
494
495
496
497
498
499 */
500 #endif
501 static nnResult ConvertFogLookUpTableDataFloatToNative(const f32* dataValue, const f32* dataDelta, u32 countData, u32 *__restrict dest);
502
503 #if NN_GD_DOCUMENT_TYPE == ENGLISH
504 /* Please see man pages for details
505
506
507
508
509
510
511
512
513
514
515
516 */
517 #else
518 /* Please see man pages for details
519
520
521
522
523
524
525
526
527
528
529
530 */
531 #endif
532 static nnResult ConvertGasLookUpTableDataFloatToNative(const f32* dataValue, const f32* dataDelta, u32 countData, u32 *__restrict dest);
533 };
534
535 }; // class FogStage
536
537
538
539 /*-------------------------------------------------------------
540 FogStage inline functions implementation
541 ---------------------------------------------------------------*/
542
SetGasFogMode(Mode mode)543 NN_FORCE_INLINE void FogStage::SetGasFogMode(Mode mode)
544 {
545 internal::g_gasFogSettings.m_ModeShadingZFlip &= ~(0x7);
546 internal::g_gasFogSettings.m_ModeShadingZFlip |= (mode & 0x7);
547 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_FOG_GAS_MODE_UPDATED;
548 }
549
SetGasShadingDensity(GasShadingDensitySource shadingDensitySrc)550 NN_FORCE_INLINE void FogStage::SetGasShadingDensity(GasShadingDensitySource shadingDensitySrc)
551 {
552 internal::g_gasFogSettings.m_ModeShadingZFlip &= ~(1 << 3);
553 if (shadingDensitySrc) internal::g_gasFogSettings.m_ModeShadingZFlip |= (1<<3);
554 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_FOG_GAS_MODE_UPDATED;
555 }
556
SetFogZFlip(gdBool zFlip)557 NN_FORCE_INLINE void FogStage::SetFogZFlip(gdBool zFlip)
558 {
559 internal::g_gasFogSettings.m_ModeShadingZFlip &= ~(1 << 16);
560 if (zFlip) internal::g_gasFogSettings.m_ModeShadingZFlip |= (1 << 16);
561 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_FOG_GAS_MODE_UPDATED;
562 }
563
SetFogColor(u8 R,u8 G,u8 B)564 NN_FORCE_INLINE void FogStage::SetFogColor(u8 R, u8 G, u8 B)
565 {
566 internal::g_gasFogSettings.m_FogColor = R | (G << 8) | (B << 16);
567 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_FOG_COLOR_UPDATED;
568 }
569
SetGasAttenuation(f32 atte)570 NN_FORCE_INLINE void FogStage::SetGasAttenuation(f32 atte)
571 {
572 internal::g_gasFogSettings.m_GasAttenuation = Utils::Float32ToFloat16(atte);
573 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_ATTENUATION_UPDATED;
574 }
575
SetGasAccumulationMax(f32 maxAcc)576 NN_FORCE_INLINE void FogStage::SetGasAccumulationMax(f32 maxAcc)
577 {
578 // Convert to f16
579 internal::g_gasFogSettings.m_GasMaxAcc = Utils::Float32ToFloat16(maxAcc);
580 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_MAX_ACC_UPDATED;
581 }
582
SetGasAutoAccumulation(gdBool autoAcc)583 NN_FORCE_INLINE void FogStage::SetGasAutoAccumulation(gdBool autoAcc)
584 {
585 internal::g_gasFogSettings.m_GasAutoAcc = autoAcc;
586 //internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_AUTO_ACC_UPDATED;
587 }
588
SetGasLightXY(u8 lightMin,u8 lightMax,u8 lightAtt)589 NN_FORCE_INLINE void FogStage::SetGasLightXY(u8 lightMin, u8 lightMax, u8 lightAtt)
590 {
591 internal::g_gasFogSettings.m_GasLightXY = lightMin | (lightMax << 8) | (lightAtt << 16);
592 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_LIGHT_XY_UPDATED;
593 }
594
SetGasLightZ(u8 scattMin,u8 scattMax,u8 scattAtt,u8 lz)595 NN_FORCE_INLINE void FogStage::SetGasLightZ(u8 scattMin, u8 scattMax, u8 scattAtt, u8 lz)
596 {
597 internal::g_gasFogSettings.m_GasLightZ = scattMin | (scattMax << 8) | (scattAtt << 16);
598 internal::g_gasFogSettings.m_GasLightZ4ColorLut &= ~(0xff);
599 internal::g_gasFogSettings.m_GasLightZ4ColorLut |= lz;
600 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_LIGHT_Z_UPDATED | internal::GasFogSettings::MASK_GAS_LIGHT_Z4_COLOR_LUT_UPDATED;
601 }
602
SetGasLightColorLutInput(GasColorLookUpTableInput colorLutInput)603 NN_FORCE_INLINE void FogStage::SetGasLightColorLutInput(GasColorLookUpTableInput colorLutInput)
604 {
605 internal::g_gasFogSettings.m_GasLightZ4ColorLut &= ~(1 << 8);
606 if (colorLutInput) internal::g_gasFogSettings.m_GasLightZ4ColorLut |= (1<<8);
607 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_LIGHT_Z4_COLOR_LUT_UPDATED;
608 }
609
SetGasDeltaZ(f32 deltaZ)610 NN_FORCE_INLINE void FogStage::SetGasDeltaZ(f32 deltaZ)
611 {
612 internal::g_gasFogSettings.m_GasDeltaZ = Utils::Float32ToUnsignedFix24Fraction8(deltaZ);
613 internal::g_gasFogSettings.m_DirtyFieldMask |= internal::GasFogSettings::MASK_GAS_DELTA_Z_UPDATED;
614 }
615
616 } // namespace CTR
617 } // namespace gd
618 } // namespace nn
619
620
621 #endif // NN_GD_CTR_GD_GASFOG_H_
622