2022-06-22 11:36:06 -04:00
|
|
|
#include <STDInclude.hpp>
|
|
|
|
#include "IMaterialVertexShader.hpp"
|
2016-01-22 05:59:43 -05:00
|
|
|
|
2019-02-01 16:16:42 -05:00
|
|
|
#define IW4X_TECHSET_VERSION "0"
|
|
|
|
|
2016-01-22 05:59:43 -05:00
|
|
|
namespace Assets
|
|
|
|
{
|
2022-06-22 11:36:06 -04:00
|
|
|
void IMaterialVertexShader::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
if (!header->data) this->loadNative(header, name, builder); // Check if there is a native one
|
|
|
|
if (!header->data) this->loadBinary(header, name, builder); // Check if we need to import a new one into the game
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMaterialVertexShader::loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/)
|
|
|
|
{
|
|
|
|
header->vertexShader = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).vertexShader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMaterialVertexShader::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
Components::FileSystem::File vsFile(Utils::String::VA("vs/%s.iw4xVS", name.data()));
|
|
|
|
if (!vsFile.exists()) return;
|
|
|
|
|
|
|
|
Utils::Stream::Reader reader(builder->getAllocator(), vsFile.getBuffer());
|
|
|
|
|
|
|
|
char* magic = reader.readArray<char>(8);
|
|
|
|
if (std::memcmp(magic, "IW4xVERT", 8))
|
|
|
|
{
|
|
|
|
Components::Logger::Error(Game::ERR_FATAL, "Reading vertex shader '{}' failed, header is invalid!", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string version;
|
|
|
|
version.push_back(reader.read<char>());
|
|
|
|
if (version != IW4X_TECHSET_VERSION)
|
|
|
|
{
|
|
|
|
Components::Logger::Error(Game::ERR_FATAL, "Reading vertex shader '{}' failed, expected version is {}, but it was {}!",
|
|
|
|
name, IW4X_TECHSET_VERSION, version);
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::MaterialVertexShader* asset = reader.readObject<Game::MaterialVertexShader>();
|
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
|
|
|
asset->name = reader.readCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->prog.loadDef.program)
|
|
|
|
{
|
|
|
|
asset->prog.loadDef.program = reader.readArray<unsigned int>(asset->prog.loadDef.programSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
header->vertexShader = asset;
|
|
|
|
}
|
2019-02-01 16:16:42 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IMaterialVertexShader::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::MaterialVertexShader, 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::MaterialVertexShader* asset = header.vertexShader;
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::MaterialVertexShader* dest = buffer->dest<Game::MaterialVertexShader>();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|