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