Skip to content

Commit

Permalink
GfxImage / Material / Techset support for xbox
Browse files Browse the repository at this point in the history
  • Loading branch information
RektInator committed Jan 11, 2020
1 parent a0b4dcd commit 8b120cb
Show file tree
Hide file tree
Showing 14 changed files with 763 additions and 183 deletions.
135 changes: 103 additions & 32 deletions src/IW4/Assets/GfxImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ namespace ZoneTool
{
namespace IW4
{
IGfxImage::IGfxImage()
{
}

IGfxImage::~IGfxImage()
{
}

std::string IGfxImage::clean_name(const std::string& name)
{
auto newName = name;
Expand Down Expand Up @@ -158,44 +150,123 @@ namespace ZoneTool

void IGfxImage::write(IZone* zone, ZoneBuffer* buf)
{
IW5::IGfxImage::dump_iwi(this->name());

auto data = this->asset_;
auto dest = buf->write(data);
if (zone->get_target() == zone_target::pc)
{
IW5::IGfxImage::dump_iwi(this->name());

auto data = this->asset_;
auto dest = buf->write(data);

// sizeof GfxImage;

buf->push_stream(3);
START_LOG_STREAM;
buf->push_stream(3);
START_LOG_STREAM;

dest->name = buf->write_str(this->name());
dest->name = buf->write_str(this->name());

// set loaded to false
dest->loaded = false;
// set loaded to false
dest->loaded = false;

buf->push_stream(0);
if (data->texture)
buf->push_stream(0);
if (data->texture)
{
buf->align(3);

auto desttext = buf->at<GfxImageLoadDef>();
buf->write_stream(data->texture, sizeof GfxImageLoadDef - sizeof std::uintptr_t);

if (isMapImage && desttext->dataSize)
{
buf->write_stream(&data->texture->texture, data->texture->dataSize);
}
else
{
desttext->dataSize = 0;
}

ZoneBuffer::ClearPointer(&dest->texture);
}
buf->pop_stream();

END_LOG_STREAM;
buf->pop_stream();
}
else
{
buf->align(3);
alpha::GfxImage alpha_image = {};

auto desttext = buf->at<GfxImageLoadDef>();
buf->write_stream(data->texture, sizeof GfxImageLoadDef - sizeof std::uintptr_t);
// transform iwi
if (!FileSystem::FileExists(va("images/%s.iwi", this->name().data())))
{
ZONETOOL_FATAL("Image %s is missing!", this->name().data());
}

if (isMapImage && desttext->dataSize)
std::vector<std::uint8_t> pixels;
auto fp = FileSystem::FileOpen(va("images/%s.iwi", this->name().data()), "rb");
if (fp)
{
buf->write_stream(&data->texture->texture, data->texture->dataSize);
auto file_size = FileSystem::FileSize(fp);
auto img_data = FileSystem::ReadBytes(fp, file_size);

auto iwi_header = (GfxImageFileHeader*)img_data.data();

auto pixel_data = img_data.data() + 32;
auto pixel_data_size = img_data.size() - 32;

pixels.resize(pixel_data_size);
memcpy(&pixels[0], pixel_data, pixel_data_size);

// add image to imagepak
// buf->add_image(pixels);

// dunno
alpha_image.cached = false;
alpha_image.format = 0x1A200154; // iwi_header->format;
alpha_image.width = iwi_header->dimensions[0];
alpha_image.height = iwi_header->dimensions[1];
alpha_image.depth = iwi_header->dimensions[2];
alpha_image.levelCount = 1;
alpha_image.mapType = 3;
alpha_image.category = 3;
alpha_image.cardMemory.platform[0] = pixels.size();
}
else
{
desttext->dataSize = 0;
ZONETOOL_FATAL("Cannot open image %s!", this->name().data());
}


ZoneBuffer::ClearPointer(&dest->texture);
}
buf->pop_stream();
auto data = &alpha_image;
auto dest = buf->write(data);

END_LOG_STREAM;
buf->pop_stream();
buf->push_stream(3);

dest->name = buf->write_str(this->name());

buf->push_stream(1);
if (pixels.size())
{
buf->align(4095);
buf->write(pixels.data(), pixels.size());
ZoneBuffer::ClearPointer(&dest->pixels);
}
else
{
dest->pixels = nullptr;
}
buf->pop_stream();

buf->pop_stream();

if (zone->get_target() != zone_target::pc)
{
endian_convert(&dest->name);
endian_convert(&dest->format);
endian_convert(&dest->width);
endian_convert(&dest->height);
endian_convert(&dest->depth);
endian_convert(&dest->pixels);
endian_convert(&dest->cardMemory.platform[0]);
}
}
}

// Legacy cancer code
Expand Down
4 changes: 0 additions & 4 deletions src/IW4/Assets/GfxImage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace ZoneTool
GfxImage* parse(const std::string& name, ZoneMemory* mem);

public:
IGfxImage();
~IGfxImage();


void init(const std::string& name, ZoneMemory* mem) override;
void init(void* asset, ZoneMemory* mem) override;

Expand Down
Loading

0 comments on commit 8b120cb

Please sign in to comment.