forked from Kenix3/libultraship
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0f91b4
commit d70fd7d
Showing
8 changed files
with
110 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "GuiTexture.h" | ||
|
||
namespace LUS { | ||
GuiTexture::GuiTexture() : Resource(std::shared_ptr<ResourceInitData>()) { | ||
} | ||
|
||
GuiTexture::~GuiTexture() { | ||
if (Data != nullptr) { | ||
stbi_image_free(Data); | ||
} | ||
} | ||
|
||
void* GuiTexture::GetPointer() { | ||
return Data; | ||
} | ||
|
||
size_t GuiTexture::GetPointerSize() { | ||
return DataSize * sizeof(uint8_t); | ||
} | ||
} // namespace LUS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "resource/Resource.h" | ||
#include <stb/stb_image.h> | ||
|
||
namespace LUS { | ||
#define RESOURCE_TYPE_GUI_TEXTURE 0x47544558 // GTEX | ||
|
||
struct GuiTextureMetadata { | ||
uint32_t RendererTextureId; | ||
int32_t Width; | ||
int32_t Height; | ||
}; | ||
|
||
class GuiTexture : public Resource<void> { | ||
public: | ||
using Resource::Resource; | ||
|
||
GuiTexture(); | ||
~GuiTexture(); | ||
|
||
void* GetPointer() override; | ||
size_t GetPointerSize() override; | ||
|
||
uint8_t* Data; | ||
size_t DataSize; | ||
GuiTextureMetadata Metadata; | ||
}; | ||
}; // namespace LUS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "window/gui/resource/GuiTextureFactory.h" | ||
#include "window/gui/resource/GuiTexture.h" | ||
#include "spdlog/spdlog.h" | ||
|
||
namespace LUS { | ||
std::shared_ptr<IResource> ResourceFactoryBinaryGuiTextureV0::ReadResource(std::shared_ptr<File> file) { | ||
if (!FileHasValidFormatAndReader(file)) { | ||
return nullptr; | ||
} | ||
|
||
auto guiTexture = std::make_shared<GuiTexture>(file->InitData); | ||
auto reader = std::get<std::shared_ptr<BinaryReader>>(file->Reader); | ||
|
||
guiTexture->DataSize = file->Buffer->size(); | ||
guiTexture->Metadata.Width = 0; | ||
guiTexture->Metadata.Height = 0; | ||
guiTexture->Data = | ||
stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(file->Buffer->data()), guiTexture->DataSize, | ||
&guiTexture->Metadata.Width, &guiTexture->Metadata.Height, nullptr, 4); | ||
|
||
if (guiTexture->Data == nullptr) { | ||
SPDLOG_ERROR("Error loading imgui texture {}", stbi_failure_reason()); | ||
return nullptr; | ||
} | ||
|
||
return guiTexture; | ||
} | ||
} // namespace LUS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "resource/Resource.h" | ||
#include "resource/ResourceFactoryBinary.h" | ||
|
||
namespace LUS { | ||
class ResourceFactoryBinaryGuiTextureV0 : public ResourceFactoryBinary { | ||
public: | ||
std::shared_ptr<IResource> ReadResource(std::shared_ptr<File> file) override; | ||
}; | ||
}; // namespace LUS |