Skip to content
Snippets Groups Projects
Commit 2451dd7d authored by Trevor Hollmann's avatar Trevor Hollmann
Browse files

[#26] Implement hack to load texture.

parent 81b1136f
No related branches found
No related tags found
1 merge request!19Resolve "Asset Loading"
Pipeline #25184 failed
...@@ -96,9 +96,10 @@ typedef struct { ...@@ -96,9 +96,10 @@ typedef struct {
std::vector<VertexGroup> vertexGroups; std::vector<VertexGroup> vertexGroups;
std::vector<Material> materials; std::vector<Material> materials;
// FIXME Dirty hack to get one(!) texture for our cube demo // FIXME Dirty hack to get one(!) texture for our cube demo
// hardcoded to always have RGBA channel layout
struct { struct {
int w, h, ch; // width, height and channels of image int w, h, ch; // width, height and channels of image
void *img; // raw data, free after use (deal with it) uint8_t *img; // raw bytes, free after use (deal with it)
} texture_hack; } texture_hack;
} Mesh; } Mesh;
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include <string.h> // memcpy(3) #include <string.h> // memcpy(3)
#include <stdlib.h> // calloc(3) #include <stdlib.h> // calloc(3)
#include <fx/gltf.h> #include <fx/gltf.h>
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_JPEG
#include <stb_image.h>
namespace vkcv::asset { namespace vkcv::asset {
...@@ -170,24 +173,30 @@ int loadMesh(const std::string &path, Mesh &mesh) { ...@@ -170,24 +173,30 @@ int loadMesh(const std::string &path, Mesh &mesh) {
std::vector<Material> materials; std::vector<Material> materials;
mesh = {
object.meshes[0].name,
vertexGroups,
materials,
0, 0, 0, NULL
};
// FIXME HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK // FIXME HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK
// fail quietly if there is no texture // fail quietly if there is no texture
if (object.textures.size()) { if (object.textures.size()) {
const std::string mime_type("image/jpeg"); const std::string mime_type("image/jpeg");
const fx::gltf::Texture &tex = object.textures[0]; const fx::gltf::Texture &tex = object.textures[0];
const fx::gltf::Image &img = object.images[tex.source]; const fx::gltf::Image &img = object.images[tex.source];
#ifdef DEBUG
printf("texture name=%s sampler=%u source=%u\n", printf("texture name=%s sampler=%u source=%u\n",
tex.name.c_str(), tex.sampler, tex.source); tex.name.c_str(), tex.sampler, tex.source);
printf("image name=%s uri=%s mime=%s\n", printf("image name=%s uri=%s mime=%s\n", img.name.c_str(),
img.name.c_str(), img.uri.c_str(), img.uri.c_str(), img.mimeType.c_str());
img.mimeType.c_str()); #endif
// URI is in img.uri mesh.texture_hack.img = stbi_load(img.uri.c_str(),
&mesh.texture_hack.w, &mesh.texture_hack.h,
// TODO decode using stbimage lib and store in mesh.texture &mesh.texture_hack.ch, 4);
} }
// FIXME HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK // FIXME HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK
mesh = { object.meshes[0].name, vertexGroups, materials };
return 1; return 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment