Skip to content

Commit

Permalink
DirectXTK: Basic mesh support through Model class and related classes
Browse files Browse the repository at this point in the history
- EffectFactory utility class added.
  • Loading branch information
walbourn_cp authored and walbourn_cp committed Jan 25, 2013
1 parent a220a96 commit 475e0fd
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 6 deletions.
5 changes: 5 additions & 0 deletions DirectXTK_Desktop_2010.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ClInclude Include="Inc\DDSTextureLoader.h" />
<ClInclude Include="Inc\Effects.h" />
<ClInclude Include="Inc\GeometricPrimitive.h" />
<ClInclude Include="Inc\Model.h" />
<ClInclude Include="Inc\ScreenGrab.h" />
<ClInclude Include="Inc\SpriteBatch.h" />
<ClInclude Include="Inc\PrimitiveBatch.h" />
Expand All @@ -48,8 +49,12 @@
<ClCompile Include="Src\DualTextureEffect.cpp" />
<ClCompile Include="Src\BinaryReader.cpp" />
<ClCompile Include="Src\EffectCommon.cpp" />
<ClCompile Include="Src\EffectFactory.cpp" />
<ClCompile Include="Src\EnvironmentMapEffect.cpp" />
<ClCompile Include="Src\GeometricPrimitive.cpp" />
<ClCompile Include="Src\Model.cpp" />
<ClCompile Include="Src\ModelLoadCMO.cpp" />
<ClCompile Include="Src\ModelLoadSDKMESH.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down
15 changes: 15 additions & 0 deletions DirectXTK_Desktop_2010.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<ClInclude Include="Inc\WICTextureLoader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Inc\Model.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down Expand Up @@ -107,6 +110,9 @@
<ClCompile Include="Src\EffectCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\EffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\SkinnedEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
Expand All @@ -128,6 +134,15 @@
<ClCompile Include="Src\ScreenGrab.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\Model.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadCMO.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadSDKMESH.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
5 changes: 5 additions & 0 deletions DirectXTK_Desktop_2012.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ClInclude Include="Inc\DDSTextureLoader.h" />
<ClInclude Include="Inc\Effects.h" />
<ClInclude Include="Inc\GeometricPrimitive.h" />
<ClInclude Include="Inc\Model.h" />
<ClInclude Include="Inc\ScreenGrab.h" />
<ClInclude Include="Inc\SpriteBatch.h" />
<ClInclude Include="Inc\PrimitiveBatch.h" />
Expand All @@ -48,8 +49,12 @@
<ClCompile Include="Src\DualTextureEffect.cpp" />
<ClCompile Include="Src\BinaryReader.cpp" />
<ClCompile Include="Src\EffectCommon.cpp" />
<ClCompile Include="Src\EffectFactory.cpp" />
<ClCompile Include="Src\EnvironmentMapEffect.cpp" />
<ClCompile Include="Src\GeometricPrimitive.cpp" />
<ClCompile Include="Src\Model.cpp" />
<ClCompile Include="Src\ModelLoadCMO.cpp" />
<ClCompile Include="Src\ModelLoadSDKMESH.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down
15 changes: 15 additions & 0 deletions DirectXTK_Desktop_2012.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<ClInclude Include="Src\BinaryReader.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Inc\Model.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down Expand Up @@ -107,6 +110,9 @@
<ClCompile Include="Src\EffectCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\EffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\SkinnedEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
Expand All @@ -128,6 +134,15 @@
<ClCompile Include="Src\ScreenGrab.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadCMO.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadSDKMESH.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\Model.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
5 changes: 5 additions & 0 deletions DirectXTK_Windows8.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ClInclude Include="Inc\DDSTextureLoader.h" />
<ClInclude Include="Inc\Effects.h" />
<ClInclude Include="Inc\GeometricPrimitive.h" />
<ClInclude Include="Inc\Model.h" />
<ClInclude Include="Inc\ScreenGrab.h" />
<ClInclude Include="Inc\SpriteBatch.h" />
<ClInclude Include="Inc\PrimitiveBatch.h" />
Expand All @@ -55,9 +56,13 @@
<ClCompile Include="Src\DDSTextureLoader.cpp" />
<ClCompile Include="Src\DualTextureEffect.cpp" />
<ClCompile Include="Src\EffectCommon.cpp" />
<ClCompile Include="Src\EffectFactory.cpp" />
<ClCompile Include="Src\BinaryReader.cpp" />
<ClCompile Include="Src\EnvironmentMapEffect.cpp" />
<ClCompile Include="Src\GeometricPrimitive.cpp" />
<ClCompile Include="Src\Model.cpp" />
<ClCompile Include="Src\ModelLoadCMO.cpp" />
<ClCompile Include="Src\ModelLoadSDKMESH.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Create</PrecompiledHeader>
Expand Down
21 changes: 18 additions & 3 deletions DirectXTK_Windows8.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
<ClInclude Include="Src\ConstantBuffer.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Src\BinaryReader.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Src\pch.h">
<Filter>Src</Filter>
</ClInclude>
Expand Down Expand Up @@ -75,6 +72,12 @@
<ClInclude Include="Inc\WICTextureLoader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\BinaryReader.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Inc\Model.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down Expand Up @@ -107,6 +110,9 @@
<ClCompile Include="Src\EffectCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\EffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\SkinnedEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
Expand All @@ -128,6 +134,15 @@
<ClCompile Include="Src\ScreenGrab.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadCMO.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadSDKMESH.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\Model.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
5 changes: 5 additions & 0 deletions DirectXTK_WindowsPhone8.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ClInclude Include="Inc\DDSTextureLoader.h" />
<ClInclude Include="Inc\Effects.h" />
<ClInclude Include="Inc\GeometricPrimitive.h" />
<ClInclude Include="Inc\Model.h" />
<ClInclude Include="Inc\ScreenGrab.h" />
<ClInclude Include="Inc\SpriteBatch.h" />
<ClInclude Include="Inc\PrimitiveBatch.h" />
Expand All @@ -46,9 +47,13 @@
<ClCompile Include="Src\DDSTextureLoader.cpp" />
<ClCompile Include="Src\DualTextureEffect.cpp" />
<ClCompile Include="Src\EffectCommon.cpp" />
<ClCompile Include="Src\EffectFactory.cpp" />
<ClCompile Include="Src\BinaryReader.cpp" />
<ClCompile Include="Src\EnvironmentMapEffect.cpp" />
<ClCompile Include="Src\GeometricPrimitive.cpp" />
<ClCompile Include="Src\Model.cpp" />
<ClCompile Include="Src\ModelLoadCMO.cpp" />
<ClCompile Include="Src\ModelLoadSDKMESH.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down
21 changes: 18 additions & 3 deletions DirectXTK_WindowsPhone8.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
<ClInclude Include="Src\ConstantBuffer.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Src\BinaryReader.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Src\pch.h">
<Filter>Src</Filter>
</ClInclude>
Expand Down Expand Up @@ -72,6 +69,12 @@
<ClInclude Include="Inc\DDSTextureLoader.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\BinaryReader.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="Inc\Model.h">
<Filter>Inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down Expand Up @@ -104,6 +107,9 @@
<ClCompile Include="Src\EffectCommon.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\EffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\SkinnedEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
Expand All @@ -122,6 +128,15 @@
<ClCompile Include="Src\ScreenGrab.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadCMO.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\ModelLoadSDKMESH.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\Model.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
58 changes: 58 additions & 0 deletions Inc/Effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,64 @@ namespace DirectX
SkinnedEffect(SkinnedEffect const&);
SkinnedEffect& operator= (SkinnedEffect const&);
};



//----------------------------------------------------------------------------------
// Abstract interface to factory for sharing effects and texture resources
class IEffectFactory
{
public:
virtual ~IEffectFactory() {}

struct EffectInfo
{
const WCHAR* name;
bool perVertexColor;
float specularPower;
float alpha;
DirectX::XMFLOAT3 ambientColor;
DirectX::XMFLOAT3 diffuseColor;
DirectX::XMFLOAT3 specularColor;
DirectX::XMFLOAT3 emissiveColor;
const WCHAR* texture;

EffectInfo() { memset( this, 0, sizeof(EffectInfo) ); };
};

virtual std::shared_ptr<IEffect> CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0;

virtual void CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) = 0;
};


// Factory for sharing effects and texture resources
class EffectFactory : public IEffectFactory
{
public:
explicit EffectFactory(_In_ ID3D11Device* device);
EffectFactory(EffectFactory&& moveFrom);
EffectFactory& operator= (EffectFactory&& moveFrom);
virtual ~EffectFactory();

virtual std::shared_ptr<IEffect> CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;

virtual void CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;

void ReleaseCache();

void SetSharing( bool enabled );

private:
// Private implementation.
class Impl;

std::shared_ptr<Impl> pImpl;

// Prevent copying.
EffectFactory(EffectFactory const&);
EffectFactory& operator= (EffectFactory const&);
};
}

#pragma warning(pop)
Loading

0 comments on commit 475e0fd

Please sign in to comment.