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