1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_TexResource.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_LYT_TEXRESOURCE_H_
19 #define NW_LYT_TEXRESOURCE_H_
20 
21 #include <nw/lyt/lyt_Arc.h>
22 #include <nw/lyt/lyt_Resources.h>
23 #include <nw/lyt/lyt_Types.h>
24 
25 namespace nw
26 {
27 namespace lyt
28 {
29 
30 //---------------------------------------------------------------------------
31 //! :category リソースアクセサ
32 //!
33 //! @brief テクスチャイメージ・リソースファイルにアクセスするためのクラスです。
34 //!
35 //! @details
36 //! アーカイブファイル内のテクスチャイメージ・リソースを取得するには
37 //! ArcUtil クラスが利用できます。
38 //!
39 //! @sa res::Lim
40 //! @sa ArcUtil
41 //!
42 //! @since 2011/02/28 初版。
43 //---------------------------------------------------------------------------
44 class TexResource
45 {
46 public:
47     //----------------------------------------
48     //! @name コンストラクタ/デストラクタ
49     //@{
50 
51     //! @brief コンストラクタです。
52     //!
53     //! @details
54     //! 無効状態で初期化します。
55     //!
56     //! @since 2011/02/28 初版。
57     //!
TexResource()58     TexResource()
59     : m_pTop(NULL)
60     , m_pImage(NULL)
61     , m_pImageSize(NULL)
62     {}
63 
64     //! @brief コンストラクタです。
65     //!
66     //! @details
67     //! アクセスするリソースファイルを指定します。
68     //!
69     //! @param[in] pTexRes  リソースファイルのアドレスです。
70     //! @param[in] size  リソースファイルのサイズです。
71     //!
72     //! @sa res::Lim
73     //!
74     //! @since 2011/02/28 初版。
75     //!
TexResource(void * pTexRes,u32 size)76     TexResource(void* pTexRes, u32 size)
77     {
78         this->Set(pTexRes, size);
79     }
80 
81     //! @brief コンストラクタです。
82     //!
83     //! @details
84     //! アクセスするリソースファイルを指定します。
85     //!
86     //! @param[in] fileInfo  リソースファイルの ARCFileInfo を指定します。
87     //!
88     //! @sa res::Lim
89     //!
90     //! @since 2011/02/28 初版。
91     //!
TexResource(ARCFileInfo & fileInfo)92     explicit TexResource(ARCFileInfo& fileInfo)
93     {
94         this->Set(fileInfo);
95     }
96 
97     // @}
98 
99     //----------------------------------------
100     //! @name 設定/取得
101     //@{
102 
103     //! @brief 有効なリソースファイルが設定されているかを取得します。
104     //!
105     //! @return  有効な場合は true を返します。
106     //!
107     //! @since 2011/02/28 初版。
108     //!
IsValid()109     bool IsValid() const
110     {
111         return m_pTop != NULL;
112     }
113 
114     //! @brief アクセスするリソースファイルを指定します。
115     //!
116     //! @param[in] pTexRes  リソースファイルのアドレスです。
117     //! @param[in] size  リソースファイルのサイズです。
118     //!
119     //! @sa res::Lim
120     //!
121     //! @return  指定に成功した場合は true を返します。
122     //!
123     //! @since 2011/02/28 初版。
124     //!
125     bool Set(void* pTexRes, u32 size);
126 
127     //! @brief アクセスするリソースファイルを指定します。
128     //!
129     //! @param[in] fileInfo  リソースファイルの ARCFileInfo を指定します。
130     //!
131     //! @return  指定に成功した場合は true を返します。
132     //!
133     //! @sa ArcUtil::ReadTextureDir
134     //! @sa res::Lim
135     //!
136     //! @since 2011/02/28 初版。
137     //!
Set(ARCFileInfo & fileInfo)138     bool Set(ARCFileInfo& fileInfo)
139     {
140         return this->Set(
141             ARCGetStartAddrInMem(&fileInfo),
142             ARCGetLength(&fileInfo));
143     }
144 
145     //! @brief テクスチャイメージのアドレスを取得します。
146     //!
147     //! @return  テクスチャイメージのアドレスを返します。
148     //!
149     //! @since 2011/02/28 初版。
150     //!
GetImageAddress()151     const void* GetImageAddress() const
152     {
153         NW_NULL_ASSERT(m_pTop);
154 
155         return m_pTop;
156     }
157 
158     //! @brief テクスチャイメージのアドレスを取得します。
159     //!
160     //! @return  テクスチャイメージのアドレスを返します。
161     //!
162     //! @since 2011/02/28 初版。
163     //!
GetImageAddress()164     void* GetImageAddress()
165     {
166         NW_NULL_ASSERT(m_pTop);
167 
168         return m_pTop;
169     }
170 
171     //! @brief テクスチャイメージのサイズを取得します。
172     //!
173     //! @return  テクスチャイメージのサイズを返します。
174     //!
175     //! @since 2011/02/28 初版。
176     //!
GetImageSize()177     u32 GetImageSize() const
178     {
179         NW_NULL_ASSERT(m_pImageSize);
180 
181         return m_pImageSize->imageSize;
182     }
183 
184     //! @brief テクスチャイメージのフォーマットを取得します。
185     //!
186     //! @return  テクスチャイメージのフォーマットを返します。
187     //!
188     //! @since 2011/02/28 初版。
189     //!
GetFormat()190     lyt::TexFormat GetFormat() const
191     {
192         NW_NULL_ASSERT(m_pImage);
193 
194         return static_cast<lyt::TexFormat>(m_pImage->format);
195     }
196 
197     //! @brief テクスチャイメージが4bitフォーマットか調べます。
198     //!
199     //! @return  テクスチャイメージが4bitフォーマットの場合は true を返します。
200     //!
201     //! @details
202     //! 4bitフォーマットのテクスチャは非4bitフォーマットのテクスチャと
203     //! 同時に使用する場合にメモリ配置上の制限があります。
204     //!
205     //! @since 2011/02/28 初版。
206     //!
Is4bitFormat()207     bool Is4bitFormat() const
208     {
209         NW_NULL_ASSERT(m_pImage);
210 
211         return m_pImage->format == lyt::TEXFORMAT_L4
212             || m_pImage->format == lyt::TEXFORMAT_A4;
213     }
214 
215     //! @brief テクスチャイメージの幅(ピクセル数)を取得します。
216     //!
217     //! @return  テクスチャイメージの幅(ピクセル数)を返します。
218     //!
219     //! @since 2011/02/28 初版。
220     //!
GetWidth()221     u16 GetWidth() const
222     {
223         NW_NULL_ASSERT(m_pImage);
224 
225         return m_pImage->width;
226     }
227 
228     //! @brief テクスチャイメージの高さ(ピクセル数)を取得します。
229     //!
230     //! @return  テクスチャイメージの高さ(ピクセル数)を返します。
231     //!
232     //! @since 2011/02/28 初版。
233     //!
GetHeight()234     u16 GetHeight() const
235     {
236         NW_NULL_ASSERT(m_pImage);
237 
238         return m_pImage->height;
239     }
240 
241     //! @brief テクスチャイメージの配置指定を取得します。
242     //!
243     //! @return  テクスチャイメージの配置指定を返します。
244     //!
245     //! @sa SetImageArea
246     //!
247     //! @since 2011/02/28 初版。
248     //!
GetImageArea()249     MemArea GetImageArea() const
250     {
251         NW_NULL_ASSERT(m_pImage);
252 
253         return static_cast<lyt::MemArea>(
254             internal::GetBits(
255                 m_pImage->flag,
256                 lyt::IMAGEFLAG_AREA_POS,
257                 lyt::IMAGEFLAG_AREA_LEN));
258     }
259 
260     //! @brief テクスチャイメージの配置を設定します。
261     //!
262     //! @param[in] area  テクスチャイメージの配置を指定します。
263     //!
264     //! @details
265     //! リソースファイルの内容を書き換えます。
266     //!
267     //! 4bitフォーマットのテクスチャは非4bitフォーマットのテクスチャと
268     //! 同時に使用する場合にメモリ配置上の制限があります。
269     //!
270     //! @sa Is4bitFormat
271     //! @sa GetImageArea
272     //!
273     //! @since 2011/02/28 初版。
274     //!
SetImageArea(lyt::MemArea area)275     void SetImageArea(lyt::MemArea area)
276     {
277         NW_NULL_ASSERT(m_pImage);
278 
279         m_pImage->flag = internal::SetBits(
280             m_pImage->flag,
281             lyt::IMAGEFLAG_AREA_POS,
282             lyt::IMAGEFLAG_AREA_LEN,
283             static_cast<u8>(area));
284     }
285 
286     //! @brief res::Image を取得します。
287     //!
288     //! @return res::Image のアドレスを返します。
289     //!
290     //! @since 2011/02/28 初版。
291     //!
GetResImage()292     res::Image* GetResImage()
293     {
294         return m_pImage;
295     }
296 
297     //! @brief res::Image を取得します。
298     //!
299     //! @return res::Image のアドレスを返します。
300     //!
301     //! @since 2011/02/28 初版。
302     //!
GetResImage()303     const res::Image* GetResImage() const
304     {
305         return m_pImage;
306     }
307 
308 protected:
309     //! @details :private
310     void* m_pTop;
311 
312     //! @details :private
313     res::Image* m_pImage;
314 
315     //! @details :private
316     res::ImageSize* m_pImageSize;
317 };
318 
319 } // namespace nw::lyt
320 } // namespace nw
321 
322 #endif // NW_LYT_TEXRESOURCE_H_
323