1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResTextureMapper.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: 18106 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_RESTEXTUREMAPPER_H_
17 #define NW_GFX_RESTEXTUREMAPPER_H_
18 
19 #include <nw/types.h>
20 #include <nw/gfx/res/gfx_ResTexture.h>
21 #include <nw/gfx/gfx_CommandUtil.h>
22 
23 namespace nw {
24 namespace gfx {
25 namespace res {
26 
27 class ResGraphicsFile;
28 
29 //! @details :private
30 struct ResTextureSamplerData
31 {
32     nw::ut::ResTypeInfo typeInfo;
33     nw::ut::Offset toOwner;
34     nw::ut::ResS32 m_MinFilter;
35 };
36 
37 //! @details :private
38 struct ResStandardTextureSamplerData : public ResTextureSamplerData
39 {
40     nw::ut::ResFloatColor m_BorderColor;
41     nw::ut::ResF32 m_LodBias;
42 };
43 
44 //! @details :private
45 struct ResShadowTextureSamplerData : public ResTextureSamplerData
46 {
47 };
48 
49 //! @details :private
50 struct ResTextureMapperData
51 {
52     nw::ut::ResTypeInfo typeInfo;
53     nw::os::IAllocator* m_DynamicAllocator;
54     nw::ut::Offset toTexture;
55 };
56 
57 //! @details :private
58 struct ResPixelBasedTextureMapperData : public ResTextureMapperData
59 {
60     nw::ut::Offset toSampler;
61 
62     enum { ADDRESS_INDEX = 7 };
63 
64     nw::ut::ResU32 m_CommandCache[14];
65     nw::ut::ResU32 m_CommandSizeToSend;
66 };
67 
68 //! @details :private
69 struct ResProceduralTextureMapperData : public ResTextureMapperData
70 {
71 };
72 
73 //--------------------------------------------------------------------------
74 //! @brief  テクスチャサンプラの設定を管理するためのバイナリリソースクラスです。
75 //---------------------------------------------------------------------------
76 class ResTextureSampler : public nw::ut::ResCommon< ResTextureSamplerData >
77 {
78 public:
79     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResTextureSampler) };
80     enum { SIGNATURE = NW_RES_SIGNATURE32('BSTS') };
81 
82     //! @brief 縮小時の補間処理です。
83     enum MinFilter
84     {
85         MINFILTER_NEAREST,                //!< ニアレスト(補間なし)で、ミップマップは使用しません。
86         MINFILTER_LINEAR,                 //!< リニア(補間あり)で、ミップマップは使用しません。
87         MINFILTER_NEAREST_MIPMAP_NEAREST, //!< ニアレスト(補間なし)で、ミップマップもニアレスト(補間なし)です。
88         MINFILTER_NEAREST_MIPMAP_LINEAR,  //!< ニアレスト(補間なし)で、ミップマップはリニア(補間あり)です。
89         MINFILTER_LINEAR_MIPMAP_NEAREST,  //!< リニア(補間あり)で、ミップマップはニアレスト(補間なし)です。
90         MINFILTER_LINEAR_MIPMAP_LINEAR    //!< リニア(補間あり)で、ミップマップもリニア(補間あり)です。
91     };
92 
93     //! @brief 拡大時の補間処理です。
94     enum MagFilter
95     {
96         MAGFILTER_NEAREST, //!< ニアレスト(補間なし)です。
97         MAGFILTER_LINEAR   //!< リニア(補間あり)です。
98     };
99 
100     //! @brief      テクスチャマッピングの方法です。
101     enum SamplerType
102     {
103         SAMPLERTYPE_TEXTURE_2D,    //!< テクスチャ座標です。
104         SAMPLERTYPE_CUBE_MAP,      //!< カメラキューブ座標です。
105         SAMPLERTYPE_SHADOW,        //!< シャドウ用の投影です。
106         SAMPLERTYPE_PROJECTION,    //!< 投影します。
107         SAMPLERTYPE_SHADOW_CUBE    //!< シャドウキューブ用の投影です。
108     };
109 
NW_RES_CTOR(ResTextureSampler)110     NW_RES_CTOR( ResTextureSampler )
111 
112     //---------------------------------------------------------------------------
113     //! @fn           MinFilter GetMinFilter() const
114     //! @brief        縮小フィルタを取得します。
115     //---------------------------------------------------------------------------
116     MinFilter GetMinFilter() const
117     {
118         return static_cast<MinFilter>(this->ref().m_MinFilter);
119     }
120 
121     //---------------------------------------------------------------------------
122     //! @fn           void SetMinFilter(MinFilter value)
123     //! @brief        縮小フィルタを設定します。
124     //---------------------------------------------------------------------------
SetMinFilter(MinFilter value)125     void SetMinFilter(MinFilter value)
126     {
127         this->ref().m_MinFilter = static_cast<MinFilter>(value);
128 
129         ::std::pair<u32, u32*> command = GetOwnerCommand();
130 
131         enum {
132             CMD_SHIFT2 = 2,
133             CMD_MASK2 = 0x1,
134             CMD_NEAR = 0,
135             CMD_LINEAR = 1,
136             CMD_SHIFT24 = 24,
137             CMD_MASK24 = 0x1,
138             CMD_OTHER = 0,
139             CMD_MIPMAP_LINER = 1,
140             CMD_INDEX = 5
141         };
142 
143         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
144         NW_NULL_ASSERT(command.second);
145 
146         const u32 table2[] =
147         {
148             CMD_NEAR,
149             CMD_LINEAR,
150             CMD_NEAR,
151             CMD_NEAR,
152             CMD_LINEAR,
153             CMD_LINEAR
154         };
155         u32 value2 = table2[value];
156         internal::SetCmdValue( &command.second[CMD_INDEX], value2, CMD_MASK2, CMD_SHIFT2 );
157 
158         const u32 table24[] =
159         {
160             CMD_OTHER,
161             CMD_OTHER,
162             CMD_OTHER,
163             CMD_MIPMAP_LINER,
164             CMD_OTHER,
165             CMD_MIPMAP_LINER
166         };
167         u32 value24 = table24[value];
168 
169         internal::SetCmdValue( &command.second[CMD_INDEX], value24, CMD_MASK24, CMD_SHIFT24 );
170 
171         // 0x84 [27:24]min lod|[19:16]mipmap size を変更します。
172         SetTextureMipmapCommand();
173     }
174 
175     //---------------------------------------------------------------------------
176     //! @fn           MagFilter GetMagFilter() const
177     //! @brief        拡大フィルタを取得します。
178     //---------------------------------------------------------------------------
GetMagFilter()179     MagFilter GetMagFilter() const
180     {
181         ::std::pair<u32, u32*> command = GetOwnerCommand();
182 
183         enum { CMD_SHIFT = 1, CMD_MASK = 0x1, CMD_INDEX = 5 };
184 
185         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
186         NW_NULL_ASSERT(command.second);
187 
188         return static_cast<MagFilter>(internal::GetCmdValue( command.second[CMD_INDEX], CMD_MASK, CMD_SHIFT ));
189     }
190 
191     //---------------------------------------------------------------------------
192     //! @fn           void SetMagFilter(MagFilter value)
193     //! @brief        拡大フィルタを設定します。
194     //---------------------------------------------------------------------------
SetMagFilter(MagFilter value)195     void SetMagFilter(MagFilter value)
196     {
197         ::std::pair<u32, u32*> command = GetOwnerCommand();
198 
199         enum { CMD_SHIFT = 1, CMD_MASK = 0x1, CMD_INDEX = 5 };
200 
201         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
202         NW_NULL_ASSERT(command.second);
203 
204         internal::SetCmdValue( &command.second[CMD_INDEX], value, CMD_MASK, CMD_SHIFT );
205     }
206 
207     //---------------------------------------------------------------------------
208     //! @brief  テクスチャサンプラータイプを設定します。
209     //!         テクスチャサンプラータイプが設定可能なのは0番目のテクスチャマッパーのみです。
210     //!         1、2番目に設定すると正しく動作しません。
211     //!
212     //! @return テクスチャサンプラータイプです。
213     //---------------------------------------------------------------------------
SetSamplerType(SamplerType value)214     void SetSamplerType(SamplerType value)
215     {
216         ::std::pair<u32, u32*> command = GetOwnerCommand();
217 
218         enum { CMD_SHIFT = 28, CMD_MASK = 0x7, CMD_INDEX = 5 };
219 
220         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
221         NW_NULL_ASSERT(command.second);
222 
223         internal::SetCmdValue( &command.second[CMD_INDEX], value, CMD_MASK, CMD_SHIFT );
224     }
225 
226     //---------------------------------------------------------------------------
227     //! @brief  テクスチャサンプラータイプを設定します。
228     //!
229     //! @return テクスチャサンプラータイプです。
230     //---------------------------------------------------------------------------
GetSamplerType()231     SamplerType GetSamplerType() const
232     {
233         ::std::pair<u32, u32*> command = GetOwnerCommand();
234 
235         enum { CMD_SHIFT = 28, CMD_MASK = 0x7, CMD_INDEX = 5 };
236 
237         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
238         NW_NULL_ASSERT(command.second);
239 
240         return static_cast<SamplerType>(internal::GetCmdValue( command.second[CMD_INDEX], CMD_MASK, CMD_SHIFT ));
241     }
242 
243     //---------------------------------------------------------------------------
244     //! @brief        このテクスチャサンプラーを所有するテクスチャマッパーを取得します。
245     //!
246     //! @return       テクスチャマッパーへのポインタです。
247     //---------------------------------------------------------------------------
GetOwnerData()248     ResTextureMapperData* GetOwnerData()
249     {
250         return static_cast<ResTextureMapperData*>( ref().toOwner.to_ptr() );
251     }
252 
253     //---------------------------------------------------------------------------
254     //! @brief        このテクスチャサンプラーを所有するテクスチャマッパーを取得します。
255     //!
256     //! @return       テクスチャマッパーへのポインタです。
257     //---------------------------------------------------------------------------
GetOwnerData()258     const ResTextureMapperData* GetOwnerData() const
259     {
260         return static_cast<const ResTextureMapperData*>( ref().toOwner.to_ptr() );
261     }
262 
263     //---------------------------------------------------------------------------
264     //! @brief        インスタンスの型情報を取得します。
265     //!
266     //! @return       型情報です。
267     //---------------------------------------------------------------------------
GetTypeInfo()268     nw::ut::ResTypeInfo GetTypeInfo() const { return ref().typeInfo; }
269 
270 protected:
271     //! @brief このテクスチャサンプラーを所有するテクスチャマッパーのコマンドを取得します。
272     ::std::pair<u32, u32*> GetOwnerCommand() const;
273 
274     //! @brief テクスチャミップマップのコマンドを設定します。
275     void SetTextureMipmapCommand();
276 };
277 
278 //--------------------------------------------------------------------------
279 //! @brief 標準のテクスチャサンプラの設定を表すバイナリリソースクラスです。
280 //---------------------------------------------------------------------------
281 class ResStandardTextureSampler : public ResTextureSampler
282 {
283 public:
284     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResStandardTextureSampler) };
285     enum { SIGNATURE = NW_RES_SIGNATURE32('STTS') };
286 
NW_RES_CTOR_INHERIT(ResStandardTextureSampler,ResTextureSampler)287     NW_RES_CTOR_INHERIT( ResStandardTextureSampler, ResTextureSampler )
288 
289     //---------------------------------------------------------------------------
290     //! @fn           const nw::ut::FloatColor & GetBorderColor() const
291     //! @brief        縁の色を取得します。
292     //---------------------------------------------------------------------------
293     const ut::FloatColor& GetBorderColor() const { return ref().m_BorderColor; }
294 
295     //---------------------------------------------------------------------------
296     //! @fn           void SetBorderColor(const ut::FloatColor& value)
297     //! @brief        縁の色を設定します。
298     //---------------------------------------------------------------------------
SetBorderColor(const ut::FloatColor & value)299     void SetBorderColor(const ut::FloatColor& value) {
300         ref().m_BorderColor = value;
301         u32 borderColorU32 = ref().m_BorderColor.ToPicaU32();
302 
303         enum { CMD_INDEX = 2 };
304         ::std::pair<u32, u32*> command = GetOwnerCommand();
305 
306         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
307         NW_NULL_ASSERT(command.second);
308 
309         command.second[CMD_INDEX] = borderColorU32;
310     }
311 
312     //---------------------------------------------------------------------------
313     //! @fn           void SetBorderColor(f32 r, f32 g, f32 b)
314     //! @brief        縁の色を設定します。
315     //---------------------------------------------------------------------------
SetBorderColor(f32 r,f32 g,f32 b)316     void SetBorderColor( f32 r, f32 g, f32 b )
317     {
318         ref().m_BorderColor.Set(r, g, b);
319         u32 borderColorU32 = ref().m_BorderColor.ToPicaU32();
320 
321         enum { CMD_INDEX = 2 };
322         ::std::pair<u32, u32*> command = GetOwnerCommand();
323 
324         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
325         NW_NULL_ASSERT(command.second);
326 
327         command.second[CMD_INDEX] = borderColorU32;
328     }
329 
330 
331         //---------------------------------------------------------------------------
332         //! @fn           void SetBorderColor(f32 r, f32 g, f32 b, f32 a)
333         //! @brief        縁の色を設定します。
334         //---------------------------------------------------------------------------
SetBorderColor(f32 r,f32 g,f32 b,f32 a)335     void SetBorderColor( f32 r, f32 g, f32 b, f32 a )
336     {
337             ref().m_BorderColor.Set(r, g, b, a);
338             u32 borderColorU32 = ref().m_BorderColor.ToPicaU32();
339 
340             enum { CMD_INDEX = 2 };
341             ::std::pair<u32, u32*> command = GetOwnerCommand();
342 
343             NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
344             NW_NULL_ASSERT(command.second);
345 
346             command.second[CMD_INDEX] = borderColorU32;
347     }
348 
349     enum Wrap
350     {
351         WRAP_CLAMP_TO_EDGE   = 0,     //!< テクスチャの端のピクセルを引き伸ばします。
352         WRAP_CLAMP_TO_BORDER = 1,     //!< テクスチャの端でボーダーカラーを引き伸ばします。
353         WRAP_REPEAT          = 2,     //!< テクスチャの端で繰り返します。
354         WRAP_MIRRORED_REPEAT = 3      //!< テクスチャの端で反転しながら繰り返します。
355     };
356 
357     //---------------------------------------------------------------------------
358     //! @fn           Wrap GetWrapS() const
359     //! @brief        S方向の繰り返し方法を取得します。
360     //---------------------------------------------------------------------------
GetWrapS()361     Wrap GetWrapS() const
362     {
363         ::std::pair<u32, u32*> command = GetOwnerCommand();
364 
365         enum { CMD_SHIFT = 12, CMD_MASK = 0x7, CMD_INDEX = 5 };
366 
367         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
368         NW_NULL_ASSERT(command.second);
369 
370         return static_cast<Wrap>(internal::GetCmdValue( command.second[CMD_INDEX], CMD_MASK, CMD_SHIFT ));
371     }
372 
373     //---------------------------------------------------------------------------
374     //! @fn           void SetWrapS(Wrap value)
375     //! @brief        S方向の繰り返し方法を設定します。
376     //---------------------------------------------------------------------------
SetWrapS(Wrap value)377     void SetWrapS(Wrap value)
378     {
379         ::std::pair<u32, u32*> command = GetOwnerCommand();
380 
381         enum { CMD_SHIFT = 12, CMD_MASK = 0x7, CMD_INDEX = 5 };
382 
383         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
384         NW_NULL_ASSERT(command.second);
385 
386         internal::SetCmdValue( &command.second[CMD_INDEX], value, CMD_MASK, CMD_SHIFT );
387     }
388 
389     //---------------------------------------------------------------------------
390     //! @fn           Wrap GetWrapT() const
391     //! @brief        T方向の繰り返し方法を取得します。
392     //---------------------------------------------------------------------------
GetWrapT()393     Wrap GetWrapT() const
394     {
395         ::std::pair<u32, u32*> command = GetOwnerCommand();
396 
397         enum { CMD_SHIFT = 8, CMD_MASK = 0x7, CMD_INDEX = 5 };
398 
399         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
400         NW_NULL_ASSERT(command.second);
401 
402         return static_cast<Wrap>(internal::GetCmdValue( command.second[CMD_INDEX], CMD_MASK, CMD_SHIFT ));
403     }
404 
405     //---------------------------------------------------------------------------
406     //! @fn           void SetWrapT(Wrap value)
407     //! @brief        T方向の繰り返し方法を設定します。
408     //---------------------------------------------------------------------------
SetWrapT(Wrap value)409     void SetWrapT(Wrap value)
410     {
411         ::std::pair<u32, u32*> command = GetOwnerCommand();
412 
413         enum { CMD_SHIFT = 8, CMD_MASK = 0x7, CMD_INDEX = 5 };
414 
415         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
416         NW_NULL_ASSERT(command.second);
417 
418         internal::SetCmdValue( &command.second[CMD_INDEX], value, CMD_MASK, CMD_SHIFT );
419     }
420 
421     //---------------------------------------------------------------------------
422     //! @fn           u32 GetMinLod() const
423     //! @brief        最小のLevel Of Detailsを取得します。
424     //---------------------------------------------------------------------------
GetMinLod()425     u32 GetMinLod() const
426     {
427         ::std::pair<u32, u32*> command = GetOwnerCommand();
428 
429         enum { CMD_SHIFT = 24, CMD_MASK = 0xf, CMD_INDEX = 6 };
430 
431         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
432         NW_NULL_ASSERT(command.second);
433 
434         return static_cast<Wrap>(internal::GetCmdValue( command.second[CMD_INDEX], CMD_MASK, CMD_SHIFT ));
435     }
436 
437     //---------------------------------------------------------------------------
438     //! @fn           void SetMinLod(u32 value)
439     //! @brief        最小のLevel Of Detailsを設定します。
440     //---------------------------------------------------------------------------
SetMinLod(u32 value)441     void SetMinLod(u32 value)
442     {
443         ::std::pair<u32, u32*> command = GetOwnerCommand();
444 
445         enum { CMD_SHIFT = 24, CMD_MASK = 0xf, CMD_INDEX = 6 };
446 
447         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
448         NW_NULL_ASSERT(command.second);
449         NW_MINMAX_ASSERT(value, 0, 15);
450 
451         u32 minLod = value;
452         if (this->ref().m_MinFilter == ResTextureSampler::MINFILTER_NEAREST ||
453             this->ref().m_MinFilter == ResTextureSampler::MINFILTER_LINEAR)
454         {
455             minLod = 0;
456         }
457 
458         internal::SetCmdValue( &command.second[CMD_INDEX], minLod, CMD_MASK, CMD_SHIFT );
459     }
460 
461     //---------------------------------------------------------------------------
462     //! @fn           f32 GetLodBias() const
463     //! @brief        Level Of Details のバイアスを取得します。
464     //---------------------------------------------------------------------------
GetLodBias()465     f32 GetLodBias() const { return this->ref().m_LodBias; }
466 
467     //---------------------------------------------------------------------------
468     //! @fn           void SetLodBias(f32 value)
469     //! @brief        Level Of Details のバイアスを設定します。
470     //---------------------------------------------------------------------------
SetLodBias(f32 value)471     void SetLodBias(f32 value)
472     {
473         this->ref().m_LodBias = value;
474         ::std::pair<u32, u32*> command = GetOwnerCommand();
475         enum { CMD_SHIFT = 0, CMD_MASK = 0x1fff, CMD_INDEX = 6 };
476 
477         NW_MIN_ASSERT(command.first, (CMD_INDEX + 1) * sizeof(u32));
478         NW_NULL_ASSERT(command.second);
479 
480         u32 lodBias = ut::FixedS13Fraction8::Float32ToFixed13(value);
481         internal::SetCmdValue( &command.second[CMD_INDEX], lodBias, CMD_MASK, CMD_SHIFT );
482     }
483 };
484 
485 //--------------------------------------------------------------------------
486 //! @brief 影用テクスチャサンプラの設定を表すバイナリリソースクラスです。
487 //---------------------------------------------------------------------------
488 class ResShadowTextureSampler : public ResTextureSampler
489 {
490 public:
491     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResShadowTextureSampler) };
492     enum { SIGNATURE = NW_RES_SIGNATURE32('SHTS') };
493 
494     NW_RES_CTOR_INHERIT( ResShadowTextureSampler, ResTextureSampler )
495 };
496 
497 //--------------------------------------------------------------------------
498 //! @brief テクスチャとサンプラの設定を管理し、メッシュへのテクスチャ貼り付けを表すバイナリリソースクラスです。
499 //---------------------------------------------------------------------------
500 class ResTextureMapper : public nw::ut::ResCommon< ResTextureMapperData >
501 {
502 public:
503     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResTextureMapper) };
504     enum { SIGNATURE = NW_RES_SIGNATURE32('TMAP') };
505 
506     NW_RES_CTOR( ResTextureMapper )
507 
508     //---------------------------------------------------------------------------
509     //! @brief        テクスチャマッパーにテクスチャを設定します。
510     //!               テクスチャを設定した後にコマンドの生成を行います。
511     //!
512     //! @param[in]    resTexture テクスチャです。
513     //---------------------------------------------------------------------------
514     void SetTexture(ResTexture resTexture);
515 
516     //---------------------------------------------------------------------------
517     //! @brief        テクスチャマッパーからテクスチャを取得します。
518     //!
519     //! @return       テクスチャです。
520     //---------------------------------------------------------------------------
GetTexture()521     const ResTexture GetTexture() const { return ResTexture( ref().toTexture.to_ptr() ); }
522 
523     //---------------------------------------------------------------------------
524     //! @brief        リソースの初期化処理をおこないます。
525     //!
526     //! @param[in]    allocator アロケータです。
527     //! @param[in]    graphicsFile グラフィックスリソースです。
528     //---------------------------------------------------------------------------
529     Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile);
530 
531     //---------------------------------------------------------------------------
532     //! @brief        リソースの後始末をおこないます。
533     //---------------------------------------------------------------------------
534     void Cleanup();
535 
536     //---------------------------------------------------------------------------
537     //! @brief        リソースからテクスチャマッパーをクローンします。
538     //!
539     //! @param[in]    allocator アロケータです。
540     //---------------------------------------------------------------------------
541     ResTextureMapper CloneDynamic(os::IAllocator* allocator);
542 
543     //---------------------------------------------------------------------------
544     //! @brief        クローン時に必要なメモリサイズを取得します。
545     //!
546     //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。
547     //---------------------------------------------------------------------------
548     size_t GetMemorySizeForClone(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const
549     {
550         os::MemorySizeCalculator size(alignment);
551 
552         GetMemorySizeForCloneInternal(&size);
553 
554         return size.GetSizeWithPadding(alignment);
555     }
556 
557     //! @details :private
558     void GetMemorySizeForCloneInternal(os::MemorySizeCalculator* pSize) const;
559 
560     //---------------------------------------------------------------------------
561     //! @brief        ResTextureMapper のリソースを破棄します。
562     //---------------------------------------------------------------------------
563     void DestroyDynamic();
564 
565     //---------------------------------------------------------------------------
566     //! @brief        リソースの型情報を取得します。
567     //!
568     //! @return       型情報です。
569     //---------------------------------------------------------------------------
GetTypeInfo()570     nw::ut::ResTypeInfo     GetTypeInfo() const { return ref().typeInfo; }
571 };
572 
573 typedef nw::ut::ResArrayClass<ResTextureMapper>::type  ResTextureMapperArray;
574 
575 //--------------------------------------------------------------------------
576 //! @brief  画像データによるテクスチャをメッシュに貼り付けるためのバイナリリソースクラスです。
577 //---------------------------------------------------------------------------
578 class ResPixelBasedTextureMapper : public ResTextureMapper
579 {
580 public:
581     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResPixelBasedTextureMapper) };
582     enum { SIGNATURE = NW_RES_SIGNATURE32('PMAP') };
583 
NW_RES_CTOR_INHERIT(ResPixelBasedTextureMapper,ResTextureMapper)584     NW_RES_CTOR_INHERIT( ResPixelBasedTextureMapper, ResTextureMapper )
585 
586     //---------------------------------------------------------------------------
587     //! @brief        テクスチャマッパーからテクスチャサンプラーを取得します。
588     //!
589     //! @return       テクスチャサンプラーです。
590     //---------------------------------------------------------------------------
591     const ResTextureSampler  GetSampler() const { return ResTextureSampler( ref().toSampler.to_ptr() ); }
GetSampler()592     ResTextureSampler  GetSampler() { return ResTextureSampler( ref().toSampler.to_ptr() ); }
593 
594     //---------------------------------------------------------------------------
595     //! @brief        コマンドキャッシュを取得します。
596     //!
597     //! @return       コマンドキャッシュへのポインタです。
598     //---------------------------------------------------------------------------
GetCommandCache()599     u32* GetCommandCache() { return &ref().m_CommandCache[0]; }
GetCommandCache()600     const u32* GetCommandCache() const { return &ref().m_CommandCache[0]; }
601 
602     //---------------------------------------------------------------------------
603     //! @fn           void SetCommandSizeToSend(u32 value)
604     //! @brief        送信するコマンドサイズを設定します。
605     //---------------------------------------------------------------------------
606     //---------------------------------------------------------------------------
607     //! @fn           u32 GetCommandSizeToSend() const
608     //! @brief        送信するコマンドサイズを取得します。
609     //---------------------------------------------------------------------------
NW_RES_FIELD_PRIMITIVE_DECL(u32,CommandSizeToSend)610     NW_RES_FIELD_PRIMITIVE_DECL( u32, CommandSizeToSend )       // GetCommandSizeToSend(), SetCommandSizeToSend()
611 
612     //---------------------------------------------------------------------------
613     //! @brief    テクスチャ設定用のコマンドが設定されているかどうかを確認します。
614     //!
615     //! @return   すでに設定済みであれば true、設定されていなければ false を返します。
616     //---------------------------------------------------------------------------
617     bool IsCommandReady() const
618     {
619         return ref().m_CommandCache[ResPixelBasedTextureMapperData::ADDRESS_INDEX] != 0;
620     }
621 
622     //---------------------------------------------------------------------------
623     //! @brief    テクスチャ設定用のコマンドとテクスチャのバインドをリセットします。
624     //---------------------------------------------------------------------------
ResetCommand()625     void ResetCommand()
626     {
627         ref().m_CommandCache[ResPixelBasedTextureMapperData::ADDRESS_INDEX] = 0;
628     }
629 };
630 
631 typedef nw::ut::ResArrayClass<ResPixelBasedTextureMapper>::type        ResPixelBasedTextureMapperArray;
632 typedef nw::ut::ResArrayClass<const ResPixelBasedTextureMapper>::type  ResPixelBasedTextureMapperArrayConst;
633 
634 
635 //--------------------------------------------------------------------------
636 //! @brief  プロシージャルテクスチャのメッシュへの貼り付けを表すバイナリリソースクラスです。
637 //! @details :private
638 //---------------------------------------------------------------------------
639 class ResProceduralTextureMapper : public ResTextureMapper
640 {
641 public:
642     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResProceduralTextureMapper) };
643     enum { SIGNATURE = NW_RES_SIGNATURE32('PRCM') };
644 
645     NW_RES_CTOR_INHERIT( ResProceduralTextureMapper, ResTextureMapper )
646 };
647 
648 } // namespace res
649 } // namespace gfx
650 } // namespace nw
651 
652 #endif // NW_GFX_RESTEXTUREMAPPER_H_
653