mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Load vertex shader and pixel shader from raw
This commit is contained in:
parent
90eaf9c4a9
commit
d0e8e94561
@ -1,6 +1,9 @@
|
|||||||
#include "AssetLoaderPixelShader.h"
|
#include "AssetLoaderPixelShader.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
#include "Game/IW4/IW4.h"
|
#include "Game/IW4/IW4.h"
|
||||||
@ -15,3 +18,40 @@ void* AssetLoaderPixelShader::CreateEmptyAsset(const std::string& assetName, Mem
|
|||||||
pixelShader->name = memory->Dup(assetName.c_str());
|
pixelShader->name = memory->Dup(assetName.c_str());
|
||||||
return pixelShader;
|
return pixelShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderPixelShader::CanLoadFromRaw() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderPixelShader::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "shader_bin/ps_" << assetName << ".cso";
|
||||||
|
|
||||||
|
const auto file = searchPath->Open(assetName);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(file.m_length % sizeof(uint32_t) != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid pixel shader \"" << assetName << "\": Size must be dividable by " << sizeof(uint32_t) << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* pixelShader = memory->Create<MaterialPixelShader>();
|
||||||
|
pixelShader->name = memory->Dup(assetName.c_str());
|
||||||
|
pixelShader->prog.loadDef.programSize = static_cast<uint16_t>(static_cast<size_t>(file.m_length) / sizeof(uint32_t));
|
||||||
|
pixelShader->prog.loadDef.loadForRenderer = 0;
|
||||||
|
pixelShader->prog.ps = nullptr;
|
||||||
|
|
||||||
|
auto* fileBuffer = static_cast<char*>(memory->Alloc(pixelShader->prog.loadDef.programSize * sizeof(uint32_t)));
|
||||||
|
file.m_stream->read(fileBuffer, static_cast<std::streamsize>(pixelShader->prog.loadDef.programSize) * sizeof(uint32_t));
|
||||||
|
if (file.m_stream->gcount() != file.m_length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
pixelShader->prog.loadDef.program = reinterpret_cast<uint32_t*>(fileBuffer);
|
||||||
|
manager->AddAsset(ASSET_TYPE_PIXELSHADER, assetName, pixelShader);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -10,5 +10,7 @@ namespace IW4
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||||
|
_NODISCARD bool CanLoadFromRaw() const override;
|
||||||
|
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#include "AssetLoaderVertexShader.h"
|
#include "AssetLoaderVertexShader.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
#include "Game/IW4/IW4.h"
|
#include "Game/IW4/IW4.h"
|
||||||
@ -15,3 +18,40 @@ void* AssetLoaderVertexShader::CreateEmptyAsset(const std::string& assetName, Me
|
|||||||
vertexShader->name = memory->Dup(assetName.c_str());
|
vertexShader->name = memory->Dup(assetName.c_str());
|
||||||
return vertexShader;
|
return vertexShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderVertexShader::CanLoadFromRaw() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderVertexShader::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "shader_bin/vs_" << assetName << ".cso";
|
||||||
|
|
||||||
|
const auto file = searchPath->Open(assetName);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (file.m_length % sizeof(uint32_t) != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid vertex shader \"" << assetName << "\": Size must be dividable by " << sizeof(uint32_t) << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* vertexShader = memory->Create<MaterialVertexShader>();
|
||||||
|
vertexShader->name = memory->Dup(assetName.c_str());
|
||||||
|
vertexShader->prog.loadDef.programSize = static_cast<uint16_t>(static_cast<size_t>(file.m_length) / sizeof(uint32_t));
|
||||||
|
vertexShader->prog.loadDef.loadForRenderer = 0;
|
||||||
|
vertexShader->prog.vs = nullptr;
|
||||||
|
|
||||||
|
auto* fileBuffer = static_cast<char*>(memory->Alloc(vertexShader->prog.loadDef.programSize * sizeof(uint32_t)));
|
||||||
|
file.m_stream->read(fileBuffer, static_cast<std::streamsize>(vertexShader->prog.loadDef.programSize) * sizeof(uint32_t));
|
||||||
|
if (file.m_stream->gcount() != file.m_length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vertexShader->prog.loadDef.program = reinterpret_cast<uint32_t*>(fileBuffer);
|
||||||
|
manager->AddAsset(ASSET_TYPE_VERTEXSHADER, assetName, vertexShader);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -10,5 +10,7 @@ namespace IW4
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||||
|
_NODISCARD bool CanLoadFromRaw() const override;
|
||||||
|
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user