Skip to content
Merged
42 changes: 39 additions & 3 deletions D3D11Engine/D3D11Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// TODO: Remove this!
#include "D3D11GraphicsEngine.h"
#include "oCGame.h"
#include "zFILE_VDFS.h"

constexpr float snowSpeedFactor = 0.15f;

Expand Down Expand Up @@ -441,20 +442,33 @@ XRESULT D3D11Effect::LoadRainResources()
{
D3D11GraphicsEngineBase* e = reinterpret_cast<D3D11GraphicsEngineBase*>(Engine::GraphicsEngine);

std::string path;
path.resize( MAX_PATH );
path.resize(GetModuleFileNameA( nullptr, path.data(), path.size()-1 ));

std::filesystem::path basePath = std::filesystem::path( path ).parent_path() / "GD3D11" / "Textures";

if ( !RainTextureArray.Get() ) {
HRESULT hr = S_OK;
// Load textures...
LogInfo() << "Loading rain-drop textures";
ZoneScopedN( "LoadRainTextures" );
LE( LoadTextureArray( e->GetDevice().Get(), e->GetContext().Get(), "system\\GD3D11\\Textures\\Raindrops\\cv0_vPositive_", 370, &RainTextureArray, &RainTextureArraySRV ) );
LE( LoadTextureArray( e->GetDevice().Get(), e->GetContext().Get(), "\\_work\\Data\\Textures\\GD3D11\\Raindrops\\cv0_vPositive_", 370, &RainTextureArray, &RainTextureArraySRV ) );
if (!SUCCEEDED(hr)) {
// try old file paths
LE( LoadTextureArray( e->GetDevice().Get(), e->GetContext().Get(), (basePath / "Raindrops"/"cv0_vPositive_").string().c_str(), 370, &RainTextureArray, &RainTextureArraySRV ) );
}
}

if ( !SnowTextureArray.Get() ) {
HRESULT hr = S_OK;
// Load textures...
LogInfo() << "Loading snow flake textures";
ZoneScopedN( "LoadSnowTextures" );
LE( LoadTextureArray( e->GetDevice().Get(), e->GetContext().Get(), "system\\GD3D11\\Textures\\Snowflakes\\Snow_", 256, &SnowTextureArray, &SnowTextureArraySRV ) );
LE( LoadTextureArray( e->GetDevice().Get(), e->GetContext().Get(), "\\_work\\Data\\Textures\\GD3D11\\Snowflakes\\Snow_", 256, &SnowTextureArray, &SnowTextureArraySRV ) );
if (!SUCCEEDED(hr)) {
LE( LoadTextureArray( e->GetDevice().Get(), e->GetContext().Get(), (basePath / "Snowflakes"/"Snow_").string().c_str(), 256, &SnowTextureArray, &SnowTextureArraySRV ) );
}
}

if ( !RainShadowmap.get() ) {
Expand Down Expand Up @@ -625,11 +639,33 @@ HRESULT LoadTextureArray( Microsoft::WRL::ComPtr<ID3D11Device1> pd3dDevice, Micr

// CHAR szTextureName[MAX_PATH];
CHAR str[MAX_PATH];

std::vector<uint8_t> storage{};
for ( int i = 0; i < iNumTextures; i++ ) {
sprintf( str, "%s%.4d.dds", sTexturePrefix, i );

auto file = zFILE_VDFS::Create( str );
if ( !file->Exists() ) {
LogError() << "File does not exist: " << str;
return E_FAIL;
}
auto retOpen = file->Open( false );
if ( retOpen != 0 ) {
LogError() << "Failed to open filepath: " << str;
return E_FAIL;
}
auto size = file->Size();

if ( storage.size() < size ) {
storage.resize( size*2 );
}
// assume single op file read.
auto numRead = file->Read( storage.data(), size );
auto retClose = file->Close();


Microsoft::WRL::ComPtr<ID3D11Resource> pRes;
LE( CreateDDSTextureFromFileEx( pd3dDevice.Get(), Toolbox::ToWideChar( str ).c_str(), 0, D3D11_USAGE_STAGING, 0, D3D11_CPU_ACCESS_WRITE, 0, DDS_LOADER_DEFAULT, pRes.GetAddressOf(), nullptr ) );
LE( CreateDDSTextureFromMemoryEx( pd3dDevice.Get(), storage.data(), size, 0, D3D11_USAGE_STAGING, 0, D3D11_CPU_ACCESS_WRITE, 0, DDS_LOADER_DEFAULT, pRes.GetAddressOf(), nullptr));
if ( pRes.Get() ) {
Microsoft::WRL::ComPtr<ID3D11Texture2D> pTemp;
pRes.As( &pTemp );
Expand Down
2 changes: 2 additions & 0 deletions D3D11Engine/D3D11Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
<ClInclude Include="Widget_TransRot.h" />
<ClInclude Include="win32ClipboardWrapper.h" />
<ClInclude Include="WorldObjects.h" />
<ClInclude Include="zAllocator.h" />
<ClInclude Include="zCArray.h" />
<ClInclude Include="zCArrayAdapt.h" />
<ClInclude Include="zCCamera.h" />
Expand All @@ -1110,6 +1111,7 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
<ClInclude Include="zCModelTexAniState.h" />
<ClInclude Include="zCMorphMesh.h" />
<ClInclude Include="zCObject.h" />
<ClInclude Include="zFILE_VDFS.h" />
<ClInclude Include="zCOption.h" />
<ClInclude Include="zCParser.h" />
<ClInclude Include="zCParticleFX.h" />
Expand Down
50 changes: 17 additions & 33 deletions D3D11Engine/D3D11Engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -732,24 +732,6 @@
<ClInclude Include="SMAA\D3D11SMAA.h">
<Filter>Engine\D3D11\PFX</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\GraphEditor.h">
<Filter>Librarys\ImGuizmo</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\ImCurveEdit.h">
<Filter>Librarys\ImGuizmo</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\ImGradient.h">
<Filter>Librarys\ImGuizmo</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\ImGuizmo.h">
<Filter>Librarys\ImGuizmo</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\ImSequencer.h">
<Filter>Librarys\ImGuizmo</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\ImZoomSlider.h">
<Filter>Librarys\ImGuizmo</Filter>
</ClInclude>
<ClInclude Include="D3D11CascadedShadowMapBuffer.h">
<Filter>Engine\D3D11</Filter>
</ClInclude>
Expand Down Expand Up @@ -856,6 +838,18 @@
<ClInclude Include="D3D11TracyDebug.h">
<Filter>Engine\D3D11</Filter>
</ClInclude>
<ClInclude Include="include\ImGuizmo\src\GraphEditor.h" />
<ClInclude Include="include\ImGuizmo\src\ImCurveEdit.h" />
<ClInclude Include="include\ImGuizmo\src\ImGradient.h" />
<ClInclude Include="include\ImGuizmo\src\ImGuizmo.h" />
<ClInclude Include="include\ImGuizmo\src\ImSequencer.h" />
<ClInclude Include="include\ImGuizmo\src\ImZoomSlider.h" />
<ClInclude Include="zFILE_VDFS.h">
<Filter>Engine\GAPI</Filter>
</ClInclude>
<ClInclude Include="zAllocator.h">
<Filter>Engine\GAPI</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down Expand Up @@ -1078,21 +1072,6 @@
<ClCompile Include="SMAA\D3D11SMAA.cpp">
<Filter>Engine\D3D11\PFX</Filter>
</ClCompile>
<ClCompile Include="include\ImGuizmo\GraphEditor.cpp">
<Filter>Librarys\ImGuizmo</Filter>
</ClCompile>
<ClCompile Include="include\ImGuizmo\ImCurveEdit.cpp">
<Filter>Librarys\ImGuizmo</Filter>
</ClCompile>
<ClCompile Include="include\ImGuizmo\ImGradient.cpp">
<Filter>Librarys\ImGuizmo</Filter>
</ClCompile>
<ClCompile Include="include\ImGuizmo\ImGuizmo.cpp">
<Filter>Librarys\ImGuizmo</Filter>
</ClCompile>
<ClCompile Include="include\ImGuizmo\ImSequencer.cpp">
<Filter>Librarys\ImGuizmo</Filter>
</ClCompile>
<ClCompile Include="D3D11CascadedShadowMapBuffer.cpp">
<Filter>Engine\D3D11</Filter>
</ClCompile>
Expand Down Expand Up @@ -1172,6 +1151,11 @@
<ClCompile Include="include\meshoptimizer\src\quantization.cpp" />
<ClCompile Include="include\meshoptimizer\src\vcacheoptimizer.cpp" />
<ClCompile Include="include\meshoptimizer\src\vfetchoptimizer.cpp" />
<ClCompile Include="include\ImGuizmo\src\GraphEditor.cpp" />
<ClCompile Include="include\ImGuizmo\src\ImCurveEdit.cpp" />
<ClCompile Include="include\ImGuizmo\src\ImGradient.cpp" />
<ClCompile Include="include\ImGuizmo\src\ImGuizmo.cpp" />
<ClCompile Include="include\ImGuizmo\src\ImSequencer.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="ddraw.def">
Expand Down
6 changes: 3 additions & 3 deletions D3D11Engine/D3D11GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6730,7 +6730,7 @@ XRESULT D3D11GraphicsEngine::DrawVOBsInstanced() {
// Use default material info for now
MaterialInfo defInfo = {};
ActivePS->GetBuffer( "MI_MaterialInfo" )
.Update( &defInfo )
.Update( &defInfo.buffer )
.Bind();

XMMATRIX view = Engine::GAPI->GetViewMatrixXM();
Expand Down Expand Up @@ -7439,9 +7439,9 @@ XRESULT D3D11GraphicsEngine::DrawPolyStrips( bool noTextures ) {
.Bind();

// Use default material info for now
MaterialInfo defInfo;
MaterialInfo defInfo{};
ActivePS->GetBuffer( "MI_MaterialInfo" )
.Update( &defInfo )
.Update( &defInfo.buffer )
.Bind();

auto vsBufMPI = ActiveVS->GetBuffer( "Matrices_PerInstances" );
Expand Down
27 changes: 27 additions & 0 deletions D3D11Engine/D3D11Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ XRESULT D3D11Texture::Init( const std::string& file ) {
return XR_SUCCESS;
}

XRESULT D3D11Texture::Init( const uint8_t* data, size_t size, const std::string& debugFileName ) {
HRESULT hr;
D3D11GraphicsEngineBase* engine = reinterpret_cast<D3D11GraphicsEngineBase*>(Engine::GraphicsEngine);

//LogInfo() << "Loading Engine-Texture: " << debugFileName;

Microsoft::WRL::ComPtr<ID3D11Texture2D> res;
LE( CreateDDSTextureFromMemory( engine->GetDevice().Get(), data, size,
reinterpret_cast<ID3D11Resource**>(res.ReleaseAndGetAddressOf()), ShaderResourceView.GetAddressOf() ) );

if ( !ShaderResourceView.Get() || !res.Get() )
return XR_FAILED;

D3D11_TEXTURE2D_DESC desc;
res->GetDesc( &desc );

Texture = res;
TextureFormat = desc.Format;

TextureSize.x = desc.Width;
TextureSize.y = desc.Height;
SetDebugName( res.Get(), "D3D11Texture(\"" + debugFileName + "\")->Texture" );
SetDebugName( ShaderResourceView.Get(), "D3D11Texture(\"" + debugFileName + "\")->ShaderResourceView" );

return XR_SUCCESS;
}

/** Updates the Texture-Object */
XRESULT D3D11Texture::UpdateData( void* data, int mip ) {
D3D11GraphicsEngineBase* engine = reinterpret_cast<D3D11GraphicsEngineBase*>(Engine::GraphicsEngine);
Expand Down
2 changes: 2 additions & 0 deletions D3D11Engine/D3D11Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class D3D11Texture {
/** Initializes the texture from a file */
XRESULT Init( const std::string& file );

XRESULT Init( const uint8_t* data, size_t size, const std::string& debugFileName );

/** Updates the Texture-Object */
XRESULT UpdateData( void* data, int mip = 0 );

Expand Down
Loading
Loading