1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_TexMap.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: 23638 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_LYT_TEXMAP_H_
17 #define NW_LYT_TEXMAP_H_
18 
19 #include <nw/types.h>
20 #include <nw/lyt/lyt_Types.h>
21 
22 #include <nw/lyt/lyt_Drawer.h>
23 
24 namespace nw
25 {
26 namespace lyt
27 {
28 
29 namespace res
30 {
31     struct Image;
32 }
33 
34 class TextureInfo;
35 
36 //---------------------------------------------------------------------------
37 //! :category 描画
38 //!
39 //! @brief テクスチャマップを制御するクラスです。
40 //!
41 //! @since 2009/09/18 初版。
42 //---------------------------------------------------------------------------
43 class TexMap
44 {
45 public:
46     //----------------------------------------
47     //! @name コンストラクタ/デストラクタ
48     //@{
49 
50     //! @brief コンストラクタです。
51     //!
52     //! @since 2009/09/18 初版。
53     //!
54     TexMap();
55 
56     //! @brief コンストラクタです。
57     //!
58     //! @details
59     //! 指定のテクスチャ情報で初期化します。
60     //!
61     //! @param textureInfo テクスチャ情報です。
62     //!
63     //! @since 2009/09/18 初版。
64     //!
65     TexMap(const TextureInfo& textureInfo);
66 
67     //@}
68 
69     //----------------------------------------
70     //! @name 設定/取得
71     //@{
72 
73     //! @brief テクスチャオブジェクトを取得します。
74     //!
75     //! @return テクスチャ名ブジェクトのハンドルを返します。
76     //!
77     //! @since 2009/09/18 初版。
78     //!
GetTextureObject()79     u32 GetTextureObject() const
80     {
81         return m_TexObject;
82     }
83 
84     //! @brief テクスチャオブジェクトを設定します。
85     //!
86     //! @param texObject テクスチャオブジェクトのハンドルです。
87     //!
88     //! @since 2009/09/18 初版。
89     //!
SetTextureObject(u32 texObject)90     void SetTextureObject(u32 texObject)
91     {
92         m_TexObject = texObject;
93 
94 #ifdef NW_LYT_DRAWER_ENABLE
95         ResetU32Info();
96 #endif
97     }
98 
99     //! @brief テクスチャの S 方向のラップモードを取得します。
100     //!
101     //! @return S 方向のラップモードを返します。
102     //!
103     //! @since 2009/09/18 初版。
104     //!
GetWrapModeS()105     TexWrap GetWrapModeS() const
106     {
107         return TexWrap(m_Bits.wrapS);
108     }
109 
110     //! @brief テクスチャの T 方向のラップモードを取得します。
111     //!
112     //! @return T 方向のラップモードを返します。
113     //!
114     //! @since 2009/09/18 初版。
115     //!
GetWrapModeT()116     TexWrap GetWrapModeT() const
117     {
118         return TexWrap(m_Bits.wrapT);
119     }
120 
121     //! @brief テクスチャのラップモードを設定します。
122     //!
123     //! @param wrapS テクスチャの S 方向のラップモードです。
124     //! @param wrapT テクスチャの T 方向のラップモードです。
125     //!
126     //! @since 2009/09/18 初版。
127     //!
SetWrapMode(TexWrap wrapS,TexWrap wrapT)128     void SetWrapMode(TexWrap wrapS, TexWrap wrapT)
129     {
130         NW_ASSERT(wrapS < TEXWRAP_MAX);
131         NW_ASSERT(wrapT < TEXWRAP_MAX);
132 
133         m_Bits.wrapS = wrapS;
134         m_Bits.wrapT = wrapT;
135 
136 #ifdef NW_LYT_DRAWER_ENABLE
137         ResetU32Info();
138 #endif
139     }
140 
141     //! @brief テクスチャが縮小されるときに適用されるフィルタモードを取得します。
142     //!
143     //! @return テクスチャが縮小されるときに適用されるフィルタモードを返します。
144     //!
145     //! @since 2009/09/18 初版。
146     //!
GetMinFilter()147     TexFilter GetMinFilter() const
148     {
149         return TexFilter(m_Bits.minFilter);
150     }
151 
152     //! @brief テクスチャが拡大されるときに適用されるフィルタモードを取得します。
153     //!
154     //! @return テクスチャが拡大されるときに適用されるフィルタモードを返します。
155     //!
156     //! @since 2009/09/18 初版。
157     //!
GetMagFilter()158     TexFilter GetMagFilter() const
159     {
160         return TexFilter(m_Bits.magFilter);
161     }
162 
163     //! @brief テクスチャのフィルタモードを設定します。
164     //!
165     //! @param minFlt テクスチャが縮小されるときに適用されるフィルタモードです。
166     //! @param magFlt テクスチャが拡大されるときに適用されるフィルタモードです。
167     //!
168     //! @since 2009/09/18 初版。
169     //!
SetFilter(TexFilter minFlt,TexFilter magFlt)170     void SetFilter(TexFilter minFlt, TexFilter magFlt)
171     {
172         NW_ASSERT(minFlt <= TEXFILTER_MAX);
173         NW_ASSERT(magFlt <= TEXFILTER_MAX);
174 
175         m_Bits.minFilter = minFlt;
176         m_Bits.magFilter = magFlt;
177 
178 #ifdef NW_LYT_DRAWER_ENABLE
179         ResetU32Info();
180 #endif
181     }
182 
183     //! @brief テクスチャの幅を取得します。
184     //!
185     //! @return テクスチャの幅を返します。
186     //!
187     //! @since 2009/09/18 初版。
188     //!
GetWidth()189     u16 GetWidth() const
190     {
191         return m_Width;
192     }
193 
194     //! @brief テクスチャの高さを取得します。
195     //!
196     //! @return テクスチャの高さを取得します。
197     //!
198     //! @since 2009/09/18 初版。
199     //!
GetHeight()200     u16 GetHeight() const
201     {
202         return m_Height;
203     }
204 
205     //! @brief テクスチャのサイズ(幅、高さ)を取得します。
206     //!
207     //! @return テクスチャのサイズ(幅、高さ)を返します。
208     //!
209     //! @since 2009/09/18 初版。
210     //!
GetSize()211     const TexSize GetSize() const
212     {
213         return TexSize(m_Width, m_Height);
214     }
215 
216     //! @brief テクスチャのサイズ(幅、高さ)を設定します。
217     //!
218     //! @param width テクスチャの幅です。
219     //! @param height テクスチャの高さです。
220     //!
221     //! @since 2009/09/18 初版。
222     //!
SetSize(u16 width,u16 height)223     void SetSize(u16 width, u16 height)
224     {
225         m_Width = width;
226         m_Height = height;
227 
228 #ifdef NW_LYT_DRAWER_ENABLE
229         ResetU32Info();
230 #endif
231     }
232 
233     //! @brief テクスチャのサイズ(幅、高さ)を設定します。
234     //!
235     //! @param size テクスチャのサイズ(幅、高さ)です。
SetSize(const TexSize & size)236     void SetSize(const TexSize& size)
237     {
238         SetSize(size.width, size.height);
239     }
240 
241     //! @brief テクスチャの幅を取得します。
242     //!
243     //! @return テクスチャの幅を返します。
244     //!
245     //! @since 2009/09/18 初版。
246     //!
GetRealWidth()247     u16 GetRealWidth() const
248     {
249         return m_RealWidth;
250     }
251 
252     //! @brief テクスチャの高さを取得します。
253     //!
254     //! @return テクスチャの高さを取得します。
255     //!
256     //! @since 2009/09/18 初版。
257     //!
GetRealHeight()258     u16 GetRealHeight() const
259     {
260         return m_RealHeight;
261     }
262 
263     //! @brief テクスチャのサイズ(幅、高さ)を取得します。
264     //!
265     //! @return テクスチャのサイズ(幅、高さ)を返します。
266     //!
267     //! @since 2009/09/18 初版。
268     //!
GetRealSize()269     const TexSize GetRealSize() const
270     {
271         return TexSize(m_RealWidth, m_RealHeight);
272     }
273 
274     //! @brief テクスチャのサイズ(幅、高さ)を設定します。
275     //!
276     //! @param width テクスチャの幅です。
277     //! @param height テクスチャの高さです。
278     //!
279     //! @since 2009/09/18 初版。
280     //!
SetRealSize(u16 width,u16 height)281     void SetRealSize(u16 width, u16 height)
282     {
283         m_RealWidth = width;
284         m_RealHeight = height;
285 
286 #ifdef NW_LYT_DRAWER_ENABLE
287         ResetU32Info();
288 #endif
289     }
290 
291     //! @brief テクスチャのサイズ(幅、高さ)を設定します。
292     //!
293     //! @param size テクスチャのサイズ(幅、高さ)です。
294     //!
295     //! @since 2009/09/18 初版。
296     //!
SetRealSize(const TexSize & size)297     void SetRealSize(const TexSize& size)
298     {
299         SetRealSize(size.width, size.height);
300     }
301 
302     //! @brief テクスチャの物理を設定します。
303     //!
304     //! @details
305     //! テクスチャの物理アドレスは Drawer の描画で使用されます。
306     //!
307     //! @param physicalAddress テクスチャの物理アドレスです。
308     //!
309     //! @sa GetPhysicalAddress
310     //!
311     //! @since 2010/05/14 初版。
312     //!
SetPhysicalAddress(uptr physicalAddress)313     void SetPhysicalAddress(uptr physicalAddress)
314     {
315         m_PhysicalAddress = physicalAddress;
316     }
317 
318     //! @brief テクスチャの物理アドレスを取得します。
319     //!
320     //! @return テクスチャの物理アドレスを返します。
321     //!
322     //! @sa SetPhysicalAddress
323     //!
324     //! @since 2010/05/14 初版。
325     //!
GetPhysicalAddress()326     uptr GetPhysicalAddress() const
327     {
328         return m_PhysicalAddress;
329     }
330 
331     //! @brief テクスチャのフォーマットを取得します。
332     //!
333     //! @return テクスチャのフォーマットを返します。
334     //!
335     //! @since 2010/04/23 初版。
336     //!
GetFormat()337     TexFormat GetFormat() const
338     {
339         return TexFormat(m_Bits.format);
340     }
341 
342     //! @brief テクスチャのフォーマットを設定します。
343     //!
344     //! @param format テクスチャのフォーマットです。
345     //!
346     //! @since 2010/04/23 初版。
347     //!
SetFormat(TexFormat format)348     void SetFormat(TexFormat format)
349     {
350         m_Bits.format = format;
351 
352 #ifdef NW_LYT_DRAWER_ENABLE
353         ResetU32Info();
354 #endif
355     }
356 
357     //! @brief テクスチャの情報を設定します。
358     //!
359     //! @details
360     //! TextureInfo の値をコピーします。
361     //!
362     //! @param src コピー元です。
363     //!
364     //! @since 2009/09/18 初版。
365     //!
Set(const TextureInfo & src)366     void Set(const TextureInfo& src)
367     {
368         m_TexObject = src.GetTextureObject();
369         m_PhysicalAddress = src.GetPhysicalAddress();
370         m_Width = src.GetSize().width;
371         m_Height = src.GetSize().height;
372         m_RealWidth = src.GetRealSize().width;
373         m_RealHeight = src.GetRealSize().height;
374         m_Bits.format = src.GetFormat();
375 
376 #ifdef NW_LYT_DRAWER_ENABLE
377         ResetU32Info();
378 #endif
379     }
380 
381     //! @brief テクスチャの情報を設定します。
382     //!
383     //! @details
384     //! 内容全体をコピーします。
385     //!
386     //! @param texMap TexMap オブジェクトへの参照です。
387     //!
388     //! @since 2009/09/18 初版。
389     //!
Set(const TexMap & texMap)390     void Set(const TexMap& texMap)
391     {
392         *this = texMap;
393     }
394 
395     //@}
396 
397 #ifdef NW_LYT_DRAWER_ENABLE
398 public:
399     //! @details :private
GetU32WrapFilter()400     inline u32 GetU32WrapFilter() const
401     {
402         return m_u32WrapFilter;
403     }
404 
405     //! @details :private
GetU32WidthHeight()406     inline u32 GetU32WidthHeight() const
407     {
408         return m_u32WidthHeight;
409     }
410 
411     //! @details :private
GetU32Format()412     inline u32 GetU32Format() const
413     {
414         return m_u32Format;
415     }
416 
417 protected:
418     //! @details :private
419     void ResetU32Info();
420 #endif
421 
422 private:
423     u32 m_TexObject;
424     uptr m_PhysicalAddress;
425     u16 m_Width;
426     u16 m_Height;
427     u16 m_RealWidth;
428     u16 m_RealHeight;
429 
430     //! @details :private
431     struct Bits
432     {
433         u32 wrapS: 2;
434         u32 wrapT: 2;
435         u32 minFilter: 3;
436         u32 magFilter: 1;
437         u32 format: 4;
438     };
439 
440     Bits m_Bits;
441 
442 #ifdef NW_LYT_DRAWER_ENABLE
443     u32 m_u32WrapFilter;
444     u32 m_u32WidthHeight;
445     u32 m_u32Format;
446 #endif
447 };
448 
449 } // namespace nw::lyt
450 } // namespace nw
451 
452 #endif // NW_LYT_TEXMAP_H_
453