2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2022-06-22 11:36:06 -04:00
|
|
|
#include "IMaterialPixelShader.hpp"
|
2016-01-22 05:59:43 -05:00
|
|
|
|
2022-12-14 03:40:15 -05:00
|
|
|
#define GFX_RENDERER_SHADER_SM3 0
|
2019-02-01 16:16:42 -05:00
|
|
|
|
2016-01-22 05:59:43 -05:00
|
|
|
namespace Assets
|
|
|
|
{
|
2019-02-01 16:16:42 -05:00
|
|
|
|
2022-06-22 11:36:06 -04:00
|
|
|
void IMaterialPixelShader::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
if (!header->data) this->loadBinary(header, name, builder); // Check if we need to import a new one into the game
|
2022-12-14 03:40:15 -05:00
|
|
|
if (!header->data) this->loadNative(header, name, builder); // Check if there is a native one
|
2022-06-22 11:36:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void IMaterialPixelShader::loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/)
|
|
|
|
{
|
|
|
|
header->pixelShader = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).pixelShader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMaterialPixelShader::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
2022-12-14 03:40:15 -05:00
|
|
|
Components::FileSystem::File psFile(std::format("ps/{}.cso", name));
|
2022-06-22 11:36:06 -04:00
|
|
|
if (!psFile.exists()) return;
|
|
|
|
|
2022-12-14 03:40:15 -05:00
|
|
|
auto buff = psFile.getBuffer();
|
|
|
|
auto programSize = buff.size() / 4;
|
|
|
|
Game::MaterialPixelShader* asset = builder->getAllocator()->allocate<Game::MaterialPixelShader>();
|
2022-06-22 11:36:06 -04:00
|
|
|
|
2022-12-14 03:40:15 -05:00
|
|
|
asset->name = builder->getAllocator()->duplicateString(name);
|
|
|
|
asset->prog.loadDef.loadForRenderer = GFX_RENDERER_SHADER_SM3;
|
|
|
|
asset->prog.loadDef.programSize = static_cast<unsigned short>(programSize);
|
|
|
|
asset->prog.loadDef.program = builder->getAllocator()->allocateArray<unsigned int>(programSize);
|
|
|
|
memcpy_s(asset->prog.loadDef.program, buff.size(), buff.data(), buff.size());
|
2022-06-22 11:36:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
header->pixelShader = asset;
|
|
|
|
}
|
2019-02-01 16:16:42 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IMaterialPixelShader::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
2016-01-22 05:59:43 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::MaterialPixelShader, 16);
|
2016-01-22 05:59:43 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-01-22 05:59:43 -05:00
|
|
|
Game::MaterialPixelShader* asset = header.pixelShader;
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::MaterialPixelShader* dest = buffer->dest<Game::MaterialPixelShader>();
|
|
|
|
buffer->save(asset);
|
2016-01-22 05:59:43 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
2016-01-22 05:59:43 -05:00
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
|
2016-06-10 07:52:55 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->name);
|
2016-01-22 05:59:43 -05:00
|
|
|
}
|
|
|
|
|
2017-04-22 15:47:04 -04:00
|
|
|
if (asset->prog.loadDef.program)
|
2016-01-22 05:59:43 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2017-04-22 15:47:04 -04:00
|
|
|
buffer->saveArray(asset->prog.loadDef.program, asset->prog.loadDef.programSize);
|
|
|
|
Utils::Stream::ClearPointer(&dest->prog.loadDef.program);
|
2016-01-22 05:59:43 -05:00
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-01-22 05:59:43 -05:00
|
|
|
}
|
|
|
|
}
|