1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: lyt_Common.h
4
5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. 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 $Revision: 26780 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NW_LYT_COMMON_H_
17 #define NW_LYT_COMMON_H_
18
19 #include <nw/sdk.h>
20 #include <nw/lyt/lyt_Material.h>
21 #include <nw/lyt/lyt_Resources.h>
22 #include <nw/lyt/lyt_Types.h>
23
24 #ifdef NW_PLATFORM_CTR
25 #define NW_LYT_WRITEONLY __writeonly
26 #else
27 #define NW_LYT_WRITEONLY
28 #endif
29
30 // ビルドターゲットにかかわらず出力します。
31 #define NW_LYT_PRINT ::nw::os::internal::Printf
32
33 namespace nw
34 {
35 namespace lyt
36 {
37
38 class Material;
39 struct Size;
40 class DrawInfo;
41 class GraphicsResource;
42 class Layout;
43 class ResourceAccessor;
44
45 //---------------------------------------------------------------------------
46 //! :category リソースアクセサ
47 //!
48 //! @brief レイアウトリソースへのポインタを持つ構造体です。
49 //!
50 //! @since 2009/09/18 初版。
51 //---------------------------------------------------------------------------
52 struct ResBlockSet
53 {
54 //! テクスチャリソースのリストです。
55 const res::TextureList* pTextureList;
56 //! フォントリソースのリストです。
57 const res::FontList* pFontList;
58 //! マテリアルリソースのリストです。
59 const res::MaterialList* pMaterialList;
60 //! リソースアクセサです。
61 ResourceAccessor* pResAccessor;
62 };
63
64 namespace internal
65 {
66
67 enum FrameSpecFlag
68 {
69 FRAMESPECFLAG_CONST_VERTEX = 1 << 0,
70 FRAMESPECFLAG_FRAME = 1 << 1,
71 FRAMESPECFLAG_SWAP = 1 << 2,
72 FRAMESPECFLAG_RIGHT = 1 << 3,
73 FRAMESPECFLAG_BOTTOM = 1 << 4,
74 FRAMESPECFLAG_HFLIP = 1 << 5,
75 FRAMESPECFLAG_VFLIP = 1 << 6,
76
77 FRAMESPECFLAG_FRAME_LT = FRAMESPECFLAG_CONST_VERTEX | FRAMESPECFLAG_FRAME,
78 FRAMESPECFLAG_FRAME_RT = FRAMESPECFLAG_CONST_VERTEX | FRAMESPECFLAG_FRAME | FRAMESPECFLAG_RIGHT,
79 FRAMESPECFLAG_FRAME_LB = FRAMESPECFLAG_CONST_VERTEX | FRAMESPECFLAG_FRAME | FRAMESPECFLAG_BOTTOM,
80 FRAMESPECFLAG_FRAME_RB = FRAMESPECFLAG_CONST_VERTEX | FRAMESPECFLAG_FRAME | FRAMESPECFLAG_RIGHT | FRAMESPECFLAG_BOTTOM,
81 FRAMESPECFLAG_FLIP_HFLIP = FRAMESPECFLAG_HFLIP,
82 FRAMESPECFLAG_FLIP_VFLIP = FRAMESPECFLAG_VFLIP,
83 FRAMESPECFLAG_FLIP_R90 = FRAMESPECFLAG_HFLIP | FRAMESPECFLAG_SWAP,
84 FRAMESPECFLAG_FLIP_R180 = FRAMESPECFLAG_HFLIP | FRAMESPECFLAG_VFLIP,
85 FRAMESPECFLAG_FLIP_R270 = FRAMESPECFLAG_VFLIP | FRAMESPECFLAG_SWAP,
86 FRAMESPECFLAG_NORMAL = 0
87 };
88
89 bool EqualsResName(const char* name1, const char* name2);
90 bool EqualsMaterialName(const char* name1, const char* name2);
91
92 inline const char*
GetStrTableStr(const void * pStrTable,int index)93 GetStrTableStr(const void* pStrTable, int index)
94 {
95 const u32* offsets = static_cast<const u32*>(pStrTable);
96 const char* stringPool = static_cast<const char*>(pStrTable);
97
98 return &stringPool[offsets[index]];
99 }
100
101 // 矩形のテクスチャ座標を複数個保持するクラスです。
102 class TexCoordAry
103 {
104 public:
105 // コンストラクタです。
106 TexCoordAry();
107
108 // 保持可能なセット数が0か調べます。
IsEmpty()109 bool IsEmpty() const
110 {
111 return m_Cap == 0;
112 }
113
114 // メンバーを解放し、保持可能なセット数を0に設定します。
115 void Free();
116
117 // 指定のセット数を保持するのに十分なメモリを確保します。
118 void Reserve(u8 num);
119
120 // 保持しているセット数を取得します。
GetSize()121 u8 GetSize() const
122 {
123 return m_Num;
124 }
125
126 // 保持するセット数を設定し、座標を初期化します。
127 void SetSize(u8 num);
128
129 // テクスチャ座標配列の先頭アドレスを取得します。
GetArray()130 const TexCoordQuad* GetArray() const
131 {
132 return m_pData;
133 }
134
135 // 指定したセットのテクスチャ座標配列の先頭アドレスを取得します。
136 void GetCoord(
137 u32 idx,
138 TexCoordQuad coord) const;
139
140 // 指定したセットのテクスチャ座標を設定します。
141 void SetCoord(
142 u32 idx,
143 const TexCoordQuad coord);
144
145 // リソースのテクスチャ座標をコピーします。
146 void Copy(
147 const void* pResTexCoord,
148 u8 texCoordNum);
149
150 protected:
151 //! @details :private
152 u8 m_Cap;
153
154 //! @details :private
155 u8 m_Num;
156
157 //! @details :private
158 math::VEC2 (*m_pData)[VERTEX_MAX];
159 };
160
161 const ut::Color8 MultipleAlpha(
162 const ut::Color8 col,
163 u8 alpha);
164
165 void DrawQuad(
166 const DrawInfo& drawInfo,
167 const math::VEC2& basePt,
168 const Size& size,
169 u8 texCoordNum = 0,
170 const math::VEC2 (*texCoords)[VERTEX_MAX] = NULL,
171 const ut::Color8* vtxColors = NULL);
172
173 void DrawQuad_Repeat(
174 const DrawInfo& drawInfo,
175 const math::VEC2& basePt,
176 const Size& size);
177
178 void DrawLine(
179 const DrawInfo& drawInfo,
180 const math::VEC2& pos,
181 const Size& size,
182 ut::Color8 color);
183
184 void FinalizeGraphics();
185
186 inline
187 u8
GetVtxColorElement(const ut::Color8 cols[],u32 idx)188 GetVtxColorElement(
189 const ut::Color8 cols[],
190 u32 idx
191 )
192 {
193 NW_ASSERT(idx < ANIMTARGET_VERTEXCOLOR_MAX);
194
195 return reinterpret_cast<const u8*>(&cols[idx / sizeof(ut::Color8)])[idx % sizeof(ut::Color8)];
196 }
197
198 inline
199 void
SetVtxColorElement(ut::Color8 cols[],u32 idx,u8 value)200 SetVtxColorElement(
201 ut::Color8 cols[],
202 u32 idx,
203 u8 value
204 )
205 {
206 NW_ASSERT(idx < ANIMTARGET_VERTEXCOLOR_MAX);
207
208 reinterpret_cast<u8*>(&cols[idx / sizeof(ut::Color8)])[idx % sizeof(ut::Color8)] = value;
209 }
210
211 inline
212 HorizontalPosition
GetHorizontalPosition(u8 var)213 GetHorizontalPosition(u8 var)
214 {
215 return static_cast<HorizontalPosition>(var % HORIZONTALPOSITION_MAX);
216 }
217
218 inline
219 VerticalPosition
GetVerticalPosition(u8 var)220 GetVerticalPosition(u8 var)
221 {
222 return static_cast<VerticalPosition>(var / HORIZONTALPOSITION_MAX);
223 }
224
225 inline
226 void
SetHorizontalPosition(u8 * pVar,u8 newVal)227 SetHorizontalPosition(u8* pVar, u8 newVal)
228 {
229 NW_ASSERT(newVal < HORIZONTALPOSITION_MAX);
230
231 *pVar = u8(GetVerticalPosition(*pVar) * HORIZONTALPOSITION_MAX + newVal);
232 }
233
234 inline
235 void
SetVerticalPosition(u8 * pVar,u8 newVal)236 SetVerticalPosition(u8* pVar, u8 newVal)
237 {
238 NW_ASSERT(newVal < VERTICALPOSITION_MAX);
239
240 *pVar = u8(newVal * HORIZONTALPOSITION_MAX + GetHorizontalPosition(*pVar));
241 }
242
243 class GL
244 {
245 public:
246 static void SetTextureSamplerType(GraphicsResource& graphicsResource, int index, int value);
247 static void SetTevCombineRgb(GraphicsResource& graphicsResource, int index, TevMode value);
248 static void SetTevCombineAlpha(GraphicsResource& graphicsResource, int index, TevMode value);
249 static void SetTevSrcRgb(GraphicsResource& graphicsResource, int index, TevSrc value0, TevSrc value1, TevSrc value2);
250 static void SetTevSrcAlpha(GraphicsResource& graphicsResource, int index, TevSrc value0, TevSrc value1, TevSrc value2);
251 static void SetTevOperandRgb(GraphicsResource& graphicsResource, int index, TevOpRgb value0, TevOpRgb value1, TevOpRgb value2);
252 static void SetTevOperandAlpha(GraphicsResource& graphicsResource, int index, TevOpAlp value0, TevOpAlp value1, TevOpAlp value2);
253 static void SetTevScaleRgb(GraphicsResource& graphicsResource, int index, TevScale value);
254 static void SetTevScaleAlpha(GraphicsResource& graphicsResource, int index, TevScale value);
255 static void SetTevConstRgba(GraphicsResource& graphicsResource, int index, ut::Color8 value);
256 static void SetTevConstRgba(GraphicsResource& graphicsResource, int index, ut::Color8 value0, ut::Color8 value1);
257 static void SetTevBufferColor(GraphicsResource &graphicsResource, ut::Color8 value);
258 static void SetTevBufferInput(GraphicsResource &graphicsResource, int index, bool valueRgb, bool valueAlpha);
259 static void SetEnableAlphaTest(GraphicsResource& graphicsResource, bool value);
260 static void SetAlphaRefValue(GraphicsResource& graphicsResource, f32 value);
261 static void SetAlphaTestFunc(GraphicsResource& graphicsResource, AlphaTest value);
262 static void SetTexMinFilter(GraphicsResource& graphicsResoruce, TexFilter value);
263 static void SetTexMagFilter(GraphicsResource& graphicsResoruce, TexFilter value);
264 };
265
266 } // namespace nw::lyt::internal
267 } // namespace nw::lyt
268 } // namespace nw
269
270 #endif // NW_LYT_COMMON_H_
271