1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_ResShader.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: 19452 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_GFX_RESSHADER_H_ 17 #define NW_GFX_RESSHADER_H_ 18 19 #include <nw/ut/ut_ResUtil.h> 20 #include <nw/ut/ut_ResDictionary.h> 21 #include <nw/gfx/res/gfx_ResSceneObject.h> 22 #include <nw/gfx/res/gfx_ResRevision.h> 23 #include <nw/gfx/res/gfx_ResTypeInfo.h> 24 #include <nw/gfx/gfx_Config.h> 25 #include <nw/gfx/gfx_ShaderBinaryInfo.h> 26 27 namespace nw { 28 29 namespace os { 30 class IAllocator; 31 } 32 33 namespace gfx { 34 35 namespace res { 36 37 class ResGraphicsFile; 38 class ResShaderSymbol; 39 class ResBinaryShader; 40 41 typedef ut::ResArrayClass<ResShaderSymbol>::type::iterator ResShaderSymbolArrayIterator; 42 typedef ut::ResArrayClass<const ResShaderSymbol>::type::const_iterator ResShaderSymbolArrayConstIterator; 43 typedef ut::ResArrayClass<ResShaderSymbol>::type ResShaderSymbolArray; 44 typedef ut::ResArrayClass<const ResShaderSymbol>::type ResShaderSymbolArrayConst; 45 46 //! @details :private 47 struct ResShaderParameterValueData 48 { 49 nw::ut::ResS32 m_UniformType; 50 nw::ut::ResF32 m_Value[1]; // UniformType によってこの後に可変長のデータが続きます。 51 }; 52 53 //! @details :private 54 struct ResShaderSymbolData 55 { 56 nw::ut::BinString toName; 57 nw::ut::ResBool m_IsEnabled; 58 nw::ut::ResBool m_IsGeometryUniform; 59 u8 _padding_0[2]; 60 nw::ut::ResS32 m_Location; 61 ResShaderParameterValueData m_DefaultValue; // 可変長となりますので、この後ろにデータを入れてはならない。 62 }; 63 64 //! @details :private 65 struct ResShaderParameterData 66 { 67 nw::ut::BinString toName; 68 nw::ut::ResS32 m_SymbolIndex; 69 ResShaderParameterValueData m_Parameter; 70 }; 71 72 //! @details :private 73 struct ResShaderProgramDescriptionData 74 { 75 enum { VERTEX_ATTRIBUTE_USAGE_COUNT = 22 }; 76 77 nw::ut::ResU32 m_Flags; 78 nw::ut::ResU32 m_VertexShaderObject; 79 nw::ut::ResU32 m_GeometryShaderObject; 80 nw::ut::ResS32 m_VertexShaderIndex; 81 nw::ut::ResS32 m_GeometryShaderIndex; 82 nw::ut::ResS32 m_SymbolsTableCount; 83 nw::ut::Offset toSymbolsTable; 84 nw::ut::BinString toAttributeSymbols[VERTEX_ATTRIBUTE_COUNT]; 85 nw::ut::ResS8 m_AttributeIndices[VERTEX_ATTRIBUTE_USAGE_COUNT]; 86 u8 _padding_0[2]; 87 nw::ut::ResS32 m_MaxBoneCount; 88 nw::ut::ResS32 m_MaxVertexLightCount; 89 nw::ut::ResS32 m_VertexLightEndUniform; 90 nw::ut::ResS32 m_GeometryShaderMode; 91 nw::ut::ResU32 m_ProgramObject; 92 void* m_UniformLocation; 93 94 void* m_CommandCache; 95 u32 m_CommandCacheSize; 96 97 nw::ut::Offset toOwnerShader; 98 }; 99 100 //! @details :private 101 struct ResShaderData : public ResSceneObjectData 102 { 103 }; 104 105 //! @details :private 106 struct ResBinaryShaderData : public ResShaderData 107 { 108 nw::ut::ResS32 m_BinaryDataTableCount; 109 nw::ut::Offset toBinaryDataTable; 110 nw::ut::ResS32 m_ShaderKindsTableCount; 111 nw::ut::Offset toShaderKindsTable; 112 nw::ut::ResS32 m_DescriptionsTableCount; 113 nw::ut::Offset toDescriptionsTable; 114 nw::ut::ResS32 m_ShaderObjectsTableCount; 115 nw::ut::Offset toShaderObjectsTable; 116 void* m_CommandCache; 117 s32 m_CommandCacheSize; 118 void* m_ShaderBinaryInfo; 119 }; 120 121 //! @details :private 122 struct ResReferenceShaderData : public ResShaderData 123 { 124 nw::ut::BinString toPath; 125 nw::ut::Offset toTargetShader; 126 }; 127 128 //-------------------------------------------------------------------------- 129 //! @brief シェーダパラメータの値を表すバイナリリソースクラスです。 130 //--------------------------------------------------------------------------- 131 class ResShaderParameterValue : public nw::ut::ResCommon< ResShaderParameterValueData > 132 { 133 public: 134 //! @brief シェーダパラメータの型です。 135 enum UniformType 136 { 137 TYPE_BOOL1, //!< ブール値です。 138 TYPE_FLOAT1, //!< 1 次元のベクトルです。 139 TYPE_FLOAT2, //!< 2 次元のベクトルです。 140 TYPE_FLOAT3, //!< 3 次元のベクトルです。 141 TYPE_FLOAT4 //!< 4 次元のベクトルです。 142 }; 143 144 NW_RES_CTOR( ResShaderParameterValue ) 145 146 //--------------------------------------------------------------------------- 147 //! @fn void SetUniformType(UniformType value) 148 //! @brief ユニフォームの種類を設定します。 149 //--------------------------------------------------------------------------- 150 //--------------------------------------------------------------------------- 151 //! @fn UniformType GetUniformType() const 152 //! @brief ユニフォームの種類を取得します。 153 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL(UniformType,UniformType)154 NW_RES_FIELD_PRIMITIVE_DECL( UniformType, UniformType ) // GetUniformType(), SetUniformType() 155 156 //--------------------------------------------------------------------------- 157 //! @brief パラメータの値を指し示す float 型のポインタを取得します。 158 //! 159 //! パラメータの 1 次元目の値を指し示す float 型のポインタを返します。 160 //! 2 次元目以降は戻り値をインクリメントすることで取得できます。 161 //! 162 //! @return パラメータの値を指し示す float 型のポインタを返します。 163 //--------------------------------------------------------------------------- 164 const f32* GetValueF32() const { return &ref().m_Value[0]; } 165 166 //--------------------------------------------------------------------------- 167 //! @brief パラメータの値を指し示す float 型のポインタを取得します。 168 //! 169 //! パラメータの 1 次元目の値を指し示す float 型のポインタを返します。 170 //! 2 次元目以降は戻り値をインクリメントすることで取得できます。 171 //! 172 //! @return パラメータの値を指し示す float 型のポインタを返します。 173 //--------------------------------------------------------------------------- GetValueF32()174 f32* GetValueF32() { return &ref().m_Value[0]; } 175 176 //--------------------------------------------------------------------------- 177 //! @brief パラメータの値を指し示す int 型のポインタを取得します。 178 //! 179 //! パラメータの 1 次元目の値を指し示す int 型のポインタを返します。 180 //! 2 次元目以降は戻り値をインクリメントすることで取得できます。 181 //! 182 //! @return パラメータの値を指し示す int 型のポインタを返します。 183 //--------------------------------------------------------------------------- GetValueS32()184 const s32* GetValueS32() const { return reinterpret_cast<const s32*>( &ref().m_Value[0] ); } 185 186 //--------------------------------------------------------------------------- 187 //! @brief パラメータの値を指し示す int 型のポインタを取得します。 188 //! 189 //! パラメータの 1 次元目の値を指し示す int 型のポインタを返します。 190 //! 2 次元目以降は戻り値をインクリメントすることで取得できます。 191 //! 192 //! @return パラメータの値を指し示す int 型のポインタを返します。 193 //--------------------------------------------------------------------------- GetValueS32()194 s32* GetValueS32() { return reinterpret_cast<s32*>( &ref().m_Value[0] ); } 195 196 //--------------------------------------------------------------------------- 197 //! @brief パラメータの値を bool 型で取得します。 198 //! 199 //! @return パラメータの値を bool 型で返します。 200 //--------------------------------------------------------------------------- GetValueBool()201 bool GetValueBool() const { return *reinterpret_cast<const s32*>( &ref().m_Value[0]) != 0; } 202 203 //--------------------------------------------------------------------------- 204 //! @brief 種別が TYPE_BOOL1 の場合に値を設定します。 205 //! 206 //! @param[in] value 設定する値です。 207 //--------------------------------------------------------------------------- SetValue(bool value)208 void SetValue(bool value) 209 { 210 NW_ASSERT( this->GetUniformType() == TYPE_BOOL1 ); 211 s32* pValue = this->GetValueS32(); 212 *pValue = value ? 1 : 0; 213 } 214 215 //--------------------------------------------------------------------------- 216 //! @brief 種別が TYPE_FLOAT1 の場合に値を設定します。 217 //! 218 //! @param[in] x 設定する値です。 219 //--------------------------------------------------------------------------- SetValue(f32 x)220 void SetValue(f32 x) 221 { 222 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT1 ); 223 f32* pValue = this->GetValueF32(); 224 *pValue = x; 225 } 226 227 //--------------------------------------------------------------------------- 228 //! @brief 種別が TYPE_FLOAT2 の場合に値を設定します。 229 //! 230 //! @param[in] x 設定する値の x 座標です。 231 //! @param[in] y 設定する値の x 座標です。 232 //--------------------------------------------------------------------------- SetValue(f32 x,f32 y)233 void SetValue(f32 x, f32 y) 234 { 235 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT2 ); 236 f32* pValue = this->GetValueF32(); 237 *pValue++ = x; 238 *pValue = y; 239 } 240 241 //--------------------------------------------------------------------------- 242 //! @brief 種別が TYPE_FLOAT2 の場合に値を設定します。 243 //! 244 //! @param[in] value 設定する VEC2 の値です。 245 //--------------------------------------------------------------------------- SetValue(const math::VEC2 & value)246 void SetValue(const math::VEC2& value) 247 { 248 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT2 ); 249 f32* pDstValue = this->GetValueF32(); 250 const f32* pSrcValue = value; 251 252 *pDstValue++ = *pSrcValue++; 253 *pDstValue = *pSrcValue; 254 } 255 256 //--------------------------------------------------------------------------- 257 //! @brief 種別が TYPE_FLOAT2 の場合に値を設定します。 258 //! 259 //! @param[in] x 設定する値の x 座標です。 260 //! @param[in] y 設定する値の x 座標です。 261 //! @param[in] z 設定する値の z 座標です。 262 //--------------------------------------------------------------------------- SetValue(f32 x,f32 y,f32 z)263 void SetValue(f32 x, f32 y, f32 z) 264 { 265 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT3 ); 266 f32* pValue = this->GetValueF32(); 267 *pValue = x; ++pValue; 268 *pValue = y; ++pValue; 269 *pValue = z; 270 } 271 272 //--------------------------------------------------------------------------- 273 //! @brief 種別が TYPE_FLOAT3 の場合に値を設定します。 274 //! 275 //! @param[in] value 設定する VEC3 の値です。 276 //--------------------------------------------------------------------------- SetValue(const math::VEC3 & value)277 void SetValue(const math::VEC3& value) 278 { 279 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT3 ); 280 f32* pDstValue = this->GetValueF32(); 281 const f32* pSrcValue = value; 282 283 *pDstValue++ = *pSrcValue++; 284 *pDstValue++ = *pSrcValue++; 285 *pDstValue = *pSrcValue; 286 } 287 288 //--------------------------------------------------------------------------- 289 //! @brief 種別が TYPE_FLOAT2 の場合に値を設定します。 290 //! 291 //! @param[in] x 設定する値の x 座標です。 292 //! @param[in] y 設定する値の x 座標です。 293 //! @param[in] z 設定する値の z 座標です。 294 //! @param[in] w 設定する値の w 座標です。 295 //--------------------------------------------------------------------------- SetValue(f32 x,f32 y,f32 z,f32 w)296 void SetValue(f32 x, f32 y, f32 z, f32 w) 297 { 298 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT4 ); 299 f32* pValue = this->GetValueF32(); 300 *pValue = x; ++pValue; 301 *pValue = y; ++pValue; 302 *pValue = z; ++pValue; 303 *pValue = w; 304 } 305 306 //--------------------------------------------------------------------------- 307 //! @brief 種別が TYPE_FLOAT4 の場合に値を設定します。 308 //! 309 //! @param[in] value 設定する VEC4 の値です。 310 //--------------------------------------------------------------------------- SetValue(const math::VEC4 & value)311 void SetValue(const math::VEC4& value) 312 { 313 NW_ASSERT( this->GetUniformType() == TYPE_FLOAT4 ); 314 f32* pDstValue = this->GetValueF32(); 315 const f32* pSrcValue = value; 316 317 *pDstValue++ = *pSrcValue++; 318 *pDstValue++ = *pSrcValue++; 319 *pDstValue++ = *pSrcValue++; 320 *pDstValue = *pSrcValue; 321 } 322 }; 323 324 //-------------------------------------------------------------------------- 325 //! @brief シェーダパラメータを表すバイナリリソースクラスです。 326 //--------------------------------------------------------------------------- 327 class ResShaderParameter : public nw::ut::ResCommon< ResShaderParameterData > 328 { 329 public: NW_RES_CTOR(ResShaderParameter)330 NW_RES_CTOR( ResShaderParameter ) 331 332 //--------------------------------------------------------------------------- 333 //! @fn void SetSymbolIndex(s32 value) 334 //! @brief シンボルのインデクスを設定します。 335 //--------------------------------------------------------------------------- 336 //--------------------------------------------------------------------------- 337 //! @fn s32 GetSymbolIndex() const 338 //! @brief シンボルのインデクスを取得します。 339 //--------------------------------------------------------------------------- 340 //--------------------------------------------------------------------------- 341 //! @fn ResShaderParameterValueData & GetParameterData() 342 //! @brief パラメータを取得します。 343 //--------------------------------------------------------------------------- 344 //--------------------------------------------------------------------------- 345 //! @fn ResShaderParameterValue GetParameter() 346 //! @brief パラメータを取得します。 347 //--------------------------------------------------------------------------- 348 //--------------------------------------------------------------------------- 349 //! @fn const char * GetName() const 350 //! @brief シェーダパラメータの名前を取得します。 351 //--------------------------------------------------------------------------- 352 NW_RES_FIELD_STRING_DECL( Name ) // GetName() 353 NW_RES_FIELD_PRIMITIVE_DECL( s32, SymbolIndex ) // GetSymbolIndex(), SetSymbolIndex() 354 NW_RES_FIELD_RESSTRUCT_DECL( ResShaderParameterValue, Parameter ) // GetParamter() 355 356 //--------------------------------------------------------------------------- 357 //! @brief パラメータの要素数を取得します。 358 //--------------------------------------------------------------------------- 359 s32 GetParameterLength() 360 { 361 switch (GetParameter().GetUniformType()) 362 { 363 case ResShaderParameterValue::TYPE_BOOL1: 364 return 1; 365 366 case ResShaderParameterValue::TYPE_FLOAT1: 367 return 1; 368 369 case ResShaderParameterValue::TYPE_FLOAT2: 370 return 2; 371 372 case ResShaderParameterValue::TYPE_FLOAT3: 373 return 3; 374 375 case ResShaderParameterValue::TYPE_FLOAT4: 376 return 4; 377 378 default: 379 NW_FATAL_ERROR("Unsupported ShaderParameterValue type."); 380 return 0; 381 } 382 } 383 }; 384 385 typedef nw::ut::ResArrayClass<ResShaderParameter>::type ResShaderParameterArray; 386 typedef nw::ut::ResArrayClass<const ResShaderParameter>::type ResShaderParameterArrayConst; 387 388 389 //-------------------------------------------------------------------------- 390 //! @brief シェーダシンボルを表すバイナリリソースクラスです。 391 //--------------------------------------------------------------------------- 392 class ResShaderSymbol : public nw::ut::ResCommon< ResShaderSymbolData > 393 { 394 public: 395 NW_RES_CTOR( ResShaderSymbol ) 396 397 //--------------------------------------------------------------------------- 398 //! @fn void SetLocation(s32 value) 399 //! @brief シェーダユニフォームのロケーションを設定します。 400 //--------------------------------------------------------------------------- 401 //--------------------------------------------------------------------------- 402 //! @fn void SetGeometryUniform(bool value) 403 //! @brief ジオメトリシェーダのパラメータかどうかのフラグを設定します。 404 //--------------------------------------------------------------------------- 405 //--------------------------------------------------------------------------- 406 //! @fn void SetEnabled(bool value) 407 //! @brief シェーダシンボルの有効フラグを設定します。 408 //--------------------------------------------------------------------------- 409 //--------------------------------------------------------------------------- 410 //! @fn bool IsGeometryUniform() const 411 //! @brief ジオメトリシェーダのパラメータかどうかのフラグを取得します。 412 //--------------------------------------------------------------------------- 413 //--------------------------------------------------------------------------- 414 //! @fn bool IsEnabled() const 415 //! @brief シェーダシンボルの有効フラグを取得します。 416 //--------------------------------------------------------------------------- 417 //--------------------------------------------------------------------------- 418 //! @fn const char * GetName() const 419 //! @brief シェーダシンボルの名前を取得します。 420 //--------------------------------------------------------------------------- 421 //--------------------------------------------------------------------------- 422 //! @fn s32 GetLocation() const 423 //! @brief シェーダユニフォームのロケーションを取得します。 424 //--------------------------------------------------------------------------- 425 //--------------------------------------------------------------------------- 426 //! @fn ResShaderParameterValueData & GetDefaultValueData() 427 //! @brief 初期値を取得します。 428 //--------------------------------------------------------------------------- 429 //--------------------------------------------------------------------------- 430 //! @fn ResShaderParameterValue GetDefaultValue() 431 //! @brief 初期値を取得します。 432 //--------------------------------------------------------------------------- 433 NW_RES_FIELD_STRING_DECL( Name ) // GetName() 434 NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Enabled ) // IsEnabled(), SetEnabled() 435 NW_RES_FIELD_RESSTRUCT_DECL( ResShaderParameterValue, DefaultValue ) // GetDefaultValue() 436 NW_RES_FIELD_BOOL_PRIMITIVE_DECL( GeometryUniform ) // IsGeometryUniform(), SetGeometryUniform() 437 NW_RES_FIELD_PRIMITIVE_DECL( s32, Location) // GetLocation(), SetLocation() 438 }; 439 440 //-------------------------------------------------------------------------- 441 //! @brief シェーダープログラムの詳細設定を表すバイナリリソースクラスです。 442 //--------------------------------------------------------------------------- 443 class ResShaderProgramDescription : public nw::ut::ResCommon< ResShaderProgramDescriptionData > 444 { 445 public: 446 447 //! @brief シェーダプログラムリソースのフラグ定義です。 448 enum Flag 449 { 450 FLAG_IS_SUPPORTING_RIGID_SKINNING = 0x1 << 0, //!< リジッドスキニングがサポートされているかのフラグです。 451 FLAG_IS_SUPPORTING_SMOOTH_SKINNING = 0x1 << 1, //!< スムーススキニングがサポートされているかのフラグです。 452 FLAG_IS_SUPPORTING_HEMISPHERE_LIGHTING = 0x1 << 2, //!< 半球ライティングをサポートしているかのフラグです。 453 FLAG_IS_SUPPORTING_VERTEX_MORPH_SHADER = 0x1 << 3 //!< 頂点モーフィングをサポートしているかのフラグです。 454 }; 455 456 NW_RES_CTOR( ResShaderProgramDescription ) 457 458 //--------------------------------------------------------------------------- 459 //! @fn void SetVertexShaderObject(u32 value) 460 //! @brief 頂点シェーダオブジェクトを設定します。 461 //--------------------------------------------------------------------------- 462 //--------------------------------------------------------------------------- 463 //! @fn void SetVertexShaderIndex(s32 value) 464 //! @brief シェーダバイナリ中の頂点シェーダのインデクスを設定します。 465 //--------------------------------------------------------------------------- 466 //--------------------------------------------------------------------------- 467 //! @fn void SetVertexLightEndUniform(s32 value) 468 //! @brief 頂点ライトの終了ユニフォームを設定します。 469 //--------------------------------------------------------------------------- 470 //--------------------------------------------------------------------------- 471 //! @fn void SetUniformLocation(void * uniformLocation) 472 //! @brief ユニフォームのロケーションを設定します。 473 //--------------------------------------------------------------------------- 474 //--------------------------------------------------------------------------- 475 //! @fn void SetProgramObject(u32 value) 476 //! @brief プログラムオブジェクトを設定します。 477 //--------------------------------------------------------------------------- 478 //--------------------------------------------------------------------------- 479 //! @fn void SetMaxVertexLightCount(s32 value) 480 //! @brief 処理可能な頂点ライト数の最大値を設定します。 481 //--------------------------------------------------------------------------- 482 //--------------------------------------------------------------------------- 483 //! @fn void SetMaxBoneCount(s32 value) 484 //! @brief 一度に設定できるマトリックスパレットの最大値を設定します。 485 //--------------------------------------------------------------------------- 486 //--------------------------------------------------------------------------- 487 //! @fn void SetGeometryShaderObject(u32 value) 488 //! @brief ジオメトリシェーダオブジェクトを設定します。 489 //--------------------------------------------------------------------------- 490 //--------------------------------------------------------------------------- 491 //! @fn void SetGeometryShaderMode(s32 value) 492 //! @brief ジオメトリシェーダのモードを設定します。 493 //--------------------------------------------------------------------------- 494 //--------------------------------------------------------------------------- 495 //! @fn void SetGeometryShaderIndex(s32 value) 496 //! @brief シェーダバイナリ中のジオメトリシェーダのインデクスを設定します。 497 //--------------------------------------------------------------------------- 498 //--------------------------------------------------------------------------- 499 //! @fn void SetFlags(u32 value) 500 //! @brief フラグの値を設定します。 501 //--------------------------------------------------------------------------- 502 //--------------------------------------------------------------------------- 503 //! @fn void SetAttributeIndices(int idx, s8 value) 504 //! @brief 頂点属性のインデックスのリストに要素を設定します。 505 //--------------------------------------------------------------------------- 506 //--------------------------------------------------------------------------- 507 //! @fn u32 GetVertexShaderObject() const 508 //! @brief 頂点シェーダオブジェクトを取得します。 509 //--------------------------------------------------------------------------- 510 //--------------------------------------------------------------------------- 511 //! @fn s32 GetVertexShaderIndex() const 512 //! @brief シェーダバイナリ中の頂点シェーダのインデクスを取得します。 513 //--------------------------------------------------------------------------- 514 //--------------------------------------------------------------------------- 515 //! @fn s32 GetVertexLightEndUniform() const 516 //! @brief 頂点ライトの終了ユニフォームを取得します。 517 //--------------------------------------------------------------------------- 518 //--------------------------------------------------------------------------- 519 //! @fn void * GetUniformLocation() 520 //! @brief ユニフォームのロケーションを取得します。 521 //--------------------------------------------------------------------------- 522 //--------------------------------------------------------------------------- 523 //! @fn s32 GetSymbolsCount() const 524 //! @brief シンボルの要素数を取得します。 525 //--------------------------------------------------------------------------- 526 //--------------------------------------------------------------------------- 527 //! @fn ResShaderSymbol GetSymbols(int idx) 528 //! @brief シンボルを取得します。 529 //--------------------------------------------------------------------------- 530 //--------------------------------------------------------------------------- 531 //! @fn u32 GetProgramObject() const 532 //! @brief プログラムオブジェクトを取得します。 533 //--------------------------------------------------------------------------- 534 //--------------------------------------------------------------------------- 535 //! @fn s32 GetMaxVertexLightCount() const 536 //! @brief 処理可能な頂点ライト数の最大値を取得します。 537 //--------------------------------------------------------------------------- 538 //--------------------------------------------------------------------------- 539 //! @fn s32 GetMaxBoneCount() const 540 //! @brief 一度に設定できるマトリックスパレットの最大値を取得します。 541 //--------------------------------------------------------------------------- 542 //--------------------------------------------------------------------------- 543 //! @fn u32 GetGeometryShaderObject() const 544 //! @brief ジオメトリシェーダオブジェクトを取得します。 545 //--------------------------------------------------------------------------- 546 //--------------------------------------------------------------------------- 547 //! @fn s32 GetGeometryShaderMode() const 548 //! @brief ジオメトリシェーダのモードを取得します。 549 //--------------------------------------------------------------------------- 550 //--------------------------------------------------------------------------- 551 //! @fn s32 GetGeometryShaderIndex() const 552 //! @brief シェーダバイナリ中のジオメトリシェーダのインデクスを取得します。 553 //--------------------------------------------------------------------------- 554 //--------------------------------------------------------------------------- 555 //! @fn u32 GetFlags() const 556 //! @brief フラグの値を取得します。 557 //--------------------------------------------------------------------------- 558 //--------------------------------------------------------------------------- 559 //! @fn s32 GetAttributeSymbolsCount() const 560 //! @brief 頂点属性のシンボル名の要素数を取得します。 561 //--------------------------------------------------------------------------- 562 //--------------------------------------------------------------------------- 563 //! @fn const char * GetAttributeSymbols(int idx) const 564 //! @brief 頂点属性のシンボル名を取得します。 565 //--------------------------------------------------------------------------- 566 //--------------------------------------------------------------------------- 567 //! @fn s32 GetAttributeIndicesCount() const 568 //! @brief 頂点属性のインデックスの要素数を取得します。 569 //--------------------------------------------------------------------------- 570 //--------------------------------------------------------------------------- 571 //! @fn s8 GetAttributeIndices(int idx) const 572 //! @brief 頂点属性のインデックスを取得します。 573 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL(u32,Flags)574 NW_RES_FIELD_PRIMITIVE_DECL( u32, Flags ) // GetFlags(), SetFlags() 575 NW_RES_FIELD_PRIMITIVE_DECL( u32, VertexShaderObject ) // GetVertexShaderObject(), SetVertexShaderObject() 576 NW_RES_FIELD_PRIMITIVE_DECL( u32, GeometryShaderObject ) // GetGeometryShaderObject(), SetGeometryShaderObject() 577 NW_RES_FIELD_PRIMITIVE_DECL( s32, VertexShaderIndex ) // GetVertexShaderIndex(), SetVertexShaderIndex() 578 NW_RES_FIELD_PRIMITIVE_DECL( s32, GeometryShaderIndex ) // GetGeometryShaderIndex(), SetGeometryShaderIndex() 579 NW_RES_FIELD_CLASS_LIST_DECL( ResShaderSymbol, Symbols ) // GetSymbols(int idx), GetSymbolsCount() 580 NW_RES_FIELD_STRING_FIXED_LIST_DECL( AttributeSymbols ) // GetAttributeSymbols(int idx), GetAttributeSymbolsCount() 581 NW_RES_FIELD_PRIMITIVE_FIXED_LIST_DECL( s8, AttributeIndices ) // GetAttributeIndices(int idx), GetAttributeIndices(), GetAttributeIndicesCount(), SetAttributeIndices(int,s8) 582 NW_RES_FIELD_PRIMITIVE_DECL( s32, MaxBoneCount ) // GetMaxBoneCount(), SetMaxBoneCount() 583 NW_RES_FIELD_PRIMITIVE_DECL( s32, MaxVertexLightCount ) // GetMaxVertexLightCount(), SetMaxVertexLightCount() 584 NW_RES_FIELD_PRIMITIVE_DECL( s32, VertexLightEndUniform ) // GetVertexLightEndUniform(), SetVertexLightEndUniform() 585 NW_RES_FIELD_PRIMITIVE_DECL( s32, GeometryShaderMode ) // GetGeometryShaderMode(), SetGeometryShaderMode() 586 NW_RES_FIELD_PRIMITIVE_DECL( u32, ProgramObject ) // GetProgramObject(), SetProgramObject() 587 588 #if defined(NW_GFX_PROGRAM_OBJECT_ENABLED) 589 void* GetUniformLocation() { return ref().m_UniformLocation; } GetUniformLocation()590 const void* GetUniformLocation() const { return ref().m_UniformLocation; } SetUniformLocation(void * uniformLocation)591 void SetUniformLocation(void* uniformLocation) { ref().m_UniformLocation = uniformLocation; } 592 #endif 593 594 //--------------------------------------------------------------------------- 595 //! @brief このシェーダプログラムを所有するシェーダバイナリを取得します。 596 //! 597 //! @return シェーダバイナリへのポインタです。 598 //--------------------------------------------------------------------------- GetOwnerShaderData()599 ResBinaryShaderData* GetOwnerShaderData() 600 { 601 return static_cast<ResBinaryShaderData*>( ref().toOwnerShader.to_ptr() ); 602 } 603 604 //--------------------------------------------------------------------------- 605 //! @brief このシェーダプログラムを所有するシェーダバイナリを取得します。 606 //! 607 //! @return シェーダバイナリへのポインタです。 608 //--------------------------------------------------------------------------- GetOwnerShaderData()609 const ResBinaryShaderData* GetOwnerShaderData() const 610 { 611 return static_cast<const ResBinaryShaderData*>( ref().toOwnerShader.to_ptr() ); 612 } 613 614 //--------------------------------------------------------------------------- 615 //! @brief シェーダバイナリ解析情報クラスを取得します。 616 //! 617 //! @return シェーダバイナリ解析情報クラスへのポインタです。 618 //--------------------------------------------------------------------------- GetShaderBinaryInfo()619 const ShaderBinaryInfo* GetShaderBinaryInfo() const 620 { 621 return static_cast<const ShaderBinaryInfo*>( this->GetOwnerShaderData()->m_ShaderBinaryInfo ); 622 } 623 624 //--------------------------------------------------------------------------- 625 //! @brief 頂点シェーダのユニフォームインデックスを取得します。 626 //! 627 //! @param[in] name ユニフォーム名です。 628 //! @param[out] pSymbolType ユニフォームのタイプ取得用の領域です。 629 //! 630 //! @return シェーダユニフォームレジスタのインデックスを返します。 631 //! 見つからなかった場合には -1 を返します。 632 //--------------------------------------------------------------------------- 633 s32 GetVertexUniformIndex( const char* name, ShaderBinaryInfo::SymbolType* pSymbolType ) const; 634 635 //--------------------------------------------------------------------------- 636 //! @brief ジオメトリシェーダのユニフォームインデックスを取得します。 637 //! 638 //! @param[in] name ユニフォーム名です。 639 //! @param[out] pSymbolType ユニフォームのタイプ取得用の領域です。 640 //! 641 //! @return シェーダユニフォームレジスタのインデックスを返します。 642 //! 見つからなかった場合には -1 を返します。 643 //--------------------------------------------------------------------------- 644 s32 GetGeometryUniformIndex( const char* name, ShaderBinaryInfo::SymbolType* pSymbolType ) const; 645 646 //--------------------------------------------------------------------------- 647 //! @brief リソースの初期化処理をおこないます。 648 //! 649 //! @param[in] allocator アロケータです。 650 //--------------------------------------------------------------------------- 651 Result Setup(os::IAllocator* allocator); 652 653 //--------------------------------------------------------------------------- 654 //! @brief リソースの後始末をおこないます。 655 //--------------------------------------------------------------------------- 656 void Cleanup(); 657 658 #if defined(NW_GFX_PROGRAM_OBJECT_ENABLED) 659 private: 660 GLuint CreateProgramObject(); 661 void AttachProgram(GLuint programObject); 662 void LinkProgram(GLuint programObject); 663 #endif 664 }; 665 666 //-------------------------------------------------------------------------- 667 //! @brief シェーダを表すバイナリリソースの基底クラスです。 668 //--------------------------------------------------------------------------- 669 class ResShader : public ResSceneObject 670 { 671 public: 672 enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResShader) }; 673 enum { SIGNATURE = NW_RES_SIGNATURE32('SHDR') }; 674 enum { BINARY_REVISION = REVISION_RES_SHADER }; 675 NW_RES_CTOR_INHERIT(ResShader,ResSceneObject)676 NW_RES_CTOR_INHERIT( ResShader, ResSceneObject ) 677 678 //--------------------------------------------------------------------------- 679 //! @brief リビジョンを取得します。 680 //! 681 //! @return リソースのリビジョン情報です。 682 //--------------------------------------------------------------------------- 683 u32 GetRevision() const { return this->GetHeader().revision; } 684 685 //--------------------------------------------------------------------------- 686 //! @brief リソースの初期化処理をおこないます。 687 //! 688 //! @param[in] allocator アロケータです。 689 //! @param[in] graphicsFile グラフィックスリソースです。 690 //--------------------------------------------------------------------------- 691 Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile); 692 693 //--------------------------------------------------------------------------- 694 //! @brief リソースの後始末をおこないます。 695 //--------------------------------------------------------------------------- 696 void Cleanup(); 697 698 //--------------------------------------------------------------------------- 699 //! @brief 参照を解決し、ResBinaryShader を取得します。 700 //--------------------------------------------------------------------------- 701 ResBinaryShader Dereference(); 702 703 //--------------------------------------------------------------------------- 704 //! @brief 参照を解決し、const ResBinaryShader を取得します。 705 //--------------------------------------------------------------------------- 706 const ResBinaryShader Dereference() const; 707 }; 708 709 710 //-------------------------------------------------------------------------- 711 //! @brief シェーダバイナリを表すバイナリリソースクラスです。 712 //--------------------------------------------------------------------------- 713 class ResBinaryShader : public ResShader 714 { 715 public: 716 enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResBinaryShader) }; 717 enum { SIGNATURE = NW_RES_SIGNATURE32('BSHD') }; 718 NW_RES_CTOR_INHERIT(ResBinaryShader,ResShader)719 NW_RES_CTOR_INHERIT( ResBinaryShader, ResShader ) 720 721 //--------------------------------------------------------------------------- 722 //! @fn void SetShaderObjects(int idx, u32 value) 723 //! @brief シェーダオブジェクトのリストに要素を設定します。 724 //--------------------------------------------------------------------------- 725 //--------------------------------------------------------------------------- 726 //! @fn void SetShaderKinds(int idx, u32 value) 727 //! @brief 格納されているシェーダーの種類のリストに要素を設定します。 728 //--------------------------------------------------------------------------- 729 //--------------------------------------------------------------------------- 730 //! @fn void SetBinaryData(int idx, u8 value) 731 //! @brief シェーダバイナリデータのリストに要素を設定します。 732 //--------------------------------------------------------------------------- 733 //--------------------------------------------------------------------------- 734 //! @fn s32 GetShaderObjectsCount() const 735 //! @brief シェーダオブジェクトの要素数を取得します。 736 //--------------------------------------------------------------------------- 737 //--------------------------------------------------------------------------- 738 //! @fn u32 GetShaderObjects(int idx) const 739 //! @brief シェーダオブジェクトを取得します。 740 //--------------------------------------------------------------------------- 741 //--------------------------------------------------------------------------- 742 //! @fn s32 GetShaderKindsCount() const 743 //! @brief 格納されているシェーダーの種類の要素数を取得します。 744 //--------------------------------------------------------------------------- 745 //--------------------------------------------------------------------------- 746 //! @fn u32 GetShaderKinds(int idx) const 747 //! @brief 格納されているシェーダーの種類を取得します。 748 //--------------------------------------------------------------------------- 749 //--------------------------------------------------------------------------- 750 //! @fn s32 GetDescriptionsCount() const 751 //! @brief シェーダープログラムの設定の要素数を取得します。 752 //--------------------------------------------------------------------------- 753 //--------------------------------------------------------------------------- 754 //! @fn ResShaderProgramDescription GetDescriptions(int idx) 755 //! @brief シェーダープログラムの設定を取得します。 756 //--------------------------------------------------------------------------- 757 //--------------------------------------------------------------------------- 758 //! @fn s32 GetBinaryDataCount() const 759 //! @brief シェーダバイナリデータの要素数を取得します。 760 //--------------------------------------------------------------------------- 761 //--------------------------------------------------------------------------- 762 //! @fn u8 GetBinaryData(int idx) const 763 //! @brief シェーダバイナリデータを取得します。 764 //--------------------------------------------------------------------------- 765 NW_RES_FIELD_PRIMITIVE_LIST_DECL( u8, BinaryData ) // GetBinaryData(), GetBinaryData(int idx), GetBinaryDataCount() 766 NW_RES_FIELD_PRIMITIVE_LIST_DECL( u32, ShaderKinds ) // GetShaderKinds(), GetShaderKinds(int idx), GetShaderKindsCount() 767 NW_RES_FIELD_CLASS_LIST_DECL( ResShaderProgramDescription, Descriptions ) // GetDescriptions(int idx), GetDescriptionsCount() 768 NW_RES_FIELD_PRIMITIVE_LIST_DECL( u32, ShaderObjects ) // GetShaderObjects(), GetShaderObjects(int idx), GetShaderObjectsCount() 769 770 //--------------------------------------------------------------------------- 771 //! @brief シェーダバイナリ設定用の GPU コマンドです。 772 //! 773 //! @return GPU コマンドへのポインタです。 774 //--------------------------------------------------------------------------- 775 const void* GetCommandCache() const { return ref().m_CommandCache; } 776 777 //--------------------------------------------------------------------------- 778 //! @brief シェーダバイナリ設定用の GPU コマンドのサイズです。 779 //! 780 //! @return GPU コマンドのサイズを返します。 781 //--------------------------------------------------------------------------- GetCommandCacheSize()782 int GetCommandCacheSize() const { return ref().m_CommandCacheSize; } 783 784 //--------------------------------------------------------------------------- 785 //! @brief シェーダバイナリ解析情報クラスを取得します。 786 //! 787 //! @return シェーダバイナリ解析情報クラスへのポインタです。 788 //--------------------------------------------------------------------------- GetShaderBinaryInfo()789 ShaderBinaryInfo* GetShaderBinaryInfo() 790 { 791 return static_cast<ShaderBinaryInfo*>( ref().m_ShaderBinaryInfo ); 792 } 793 794 //--------------------------------------------------------------------------- 795 //! @brief シェーダバイナリ情報へのアクセサを取得します。 796 //! 797 //! @return シェーダバイナリへのアクセサクラスへのポインタです。 798 //--------------------------------------------------------------------------- GetShaderBinaryInfo()799 const ShaderBinaryInfo* GetShaderBinaryInfo() const 800 { 801 return static_cast<const ShaderBinaryInfo*>( ref().m_ShaderBinaryInfo ); 802 } 803 }; 804 805 //-------------------------------------------------------------------------- 806 //! @brief シェーダの外部参照を表すバイナリリソースクラスです。 807 //--------------------------------------------------------------------------- 808 class ResReferenceShader : public ResShader 809 { 810 public: 811 enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResReferenceShader) }; 812 enum { SIGNATURE = NW_RES_SIGNATURE32('SDRF') }; 813 814 NW_RES_CTOR_INHERIT( ResReferenceShader, ResShader ) 815 816 //--------------------------------------------------------------------------- 817 //! @fn ResShader GetTargetShader() 818 //! @brief 参照解決後のシェーダデータを取得します。 819 //--------------------------------------------------------------------------- 820 //--------------------------------------------------------------------------- 821 //! @fn const char * GetPath() const 822 //! @brief 参照するシェーダのパスを取得します。 823 //--------------------------------------------------------------------------- 824 NW_RES_FIELD_STRING_DECL( Path ) // GetPath() 825 NW_RES_FIELD_CLASS_DECL( ResShader, TargetShader ) // GetTargetShader() 826 }; 827 828 } // namespace res 829 } // namespace gfx 830 } // namespace nw 831 832 #endif // NW_GFX_RESSHADER_H_ 833