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