TMP / assets will be embedded for now

This commit is contained in:
OLEGSHA 2023-03-09 23:28:35 +01:00
parent 15d41b60bd
commit 9d5ce3dca2
5 changed files with 19 additions and 19 deletions

View File

@ -60,6 +60,11 @@ target_sources(progressia PRIVATE
target_glsl_shaders(progressia
desktop/graphics/shaders/shader.frag
desktop/graphics/shaders/shader.vert)
target_embeds(progressia
assets/texture.png
assets/texture2.png)
compile_glsl(progressia)
compile_embeds(progressia)
target_include_directories(progressia PRIVATE ${generated}/embedded_resources)

View File

@ -63,10 +63,10 @@ void initialize(GraphicsInterface &gintp) {
debug("game init begin");
gint = &gintp;
texture1.reset(gint->newTexture(
progressia::main::loadImage(u"../assets/texture.png")));
texture2.reset(gint->newTexture(
progressia::main::loadImage(u"../assets/texture2.png")));
texture1.reset(
gint->newTexture(progressia::main::loadImage("assets/texture.png")));
texture2.reset(
gint->newTexture(progressia::main::loadImage("assets/texture2.png")));
// Cube 1
{

View File

@ -8,6 +8,8 @@
#include "stb/stb_image.h"
#include <embedded_resources.h>
#include "../logging.h"
using namespace progressia::main::logging;
@ -20,23 +22,19 @@ const Image::Byte *Image::getData() const { return data.data(); }
Image::Byte *Image::getData() { return data.data(); }
Image loadImage(const std::filesystem::path &path) {
Image loadImage(const std::string &path) {
std::ifstream file(path, std::ios::ate | std::ios::binary);
auto resource = __embedded_resources::getEmbeddedResource(path.c_str());
if (!file.is_open()) {
fatal() << "Could not access a PNG image in file " << path;
if (resource.data == nullptr) {
// REPORT_ERROR
progressia::main::logging::fatal()
<< "Could not find resource \"" << path << "\"";
exit(1);
}
std::size_t fileSize = static_cast<std::size_t>(file.tellg());
std::vector<Image::Byte> png(fileSize);
file.seekg(0);
file.read(reinterpret_cast<char *>(png.data()), fileSize);
file.close();
std::vector<Image::Byte> png(resource.data,
resource.data + resource.length);
int width;
int height;

View File

@ -19,7 +19,7 @@ class Image {
Byte *getData();
};
Image loadImage(const std::filesystem::path &);
Image loadImage(const std::string &);
} // namespace main
} // namespace progressia

View File

@ -1,9 +1,6 @@
# embed.cmake
# Generates embedded_resources.h and embedded_resources.cpp
find_package(Vulkan COMPONENTS glslc REQUIRED)
find_program(glslc_EXECUTABLE NAMES glslc HINTS Vulkan::glslc)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
macro (get_target_property_or var target prop default)