Browse Source

move file_peth from meMeshInfo to util_image struct

master
cinnaboot 8 years ago
parent
commit
bf48abc7d4
  1. 5
      src/mesh.cpp
  2. 1
      src/mesh.h
  3. 4
      src/util.cpp
  4. 1
      src/util.h

5
src/mesh.cpp

@ -129,7 +129,6 @@ copyMeshInfo(const char* data_dir, const aiScene* scene, aiMesh* mesh)
std::string file_path;
file_path.append(data_dir).append("/").append(file_name.C_Str());
LOG(INFO) << "Loading texture file: " << file_name.C_Str() << "\n";
mi->diffuse_texture_path = file_path.c_str();
mi->diffuse_texture = utilLoadImage(file_path.c_str());
}
}
@ -140,10 +139,8 @@ copyMeshInfo(const char* data_dir, const aiScene* scene, aiMesh* mesh)
void
freeMesh(meMeshInfo* mesh)
{
if (mesh->diffuse_texture.pixels != 0) {
if (mesh->diffuse_texture.pixels != 0)
utilFreeImage(mesh->diffuse_texture);
mesh->diffuse_texture_path = 0;
}
utilSafeFree(mesh->vertices);
utilSafeFree(mesh->normals);

1
src/mesh.h

@ -19,7 +19,6 @@ struct meMeshInfo
uint* indices = nullptr;
glm::vec3 diffuse_color;
const char* diffuse_texture_path;
util_image diffuse_texture;
};

4
src/util.cpp

@ -2,6 +2,7 @@
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
@ -66,8 +67,10 @@ util_image
utilLoadImage(const char* filename)
{
LOG(INFO) << "Loading Image: " << filename << "\n";
assert(std::strlen(filename) < 256);
util_image image;
std::memcpy(image.file_path, filename, std::strlen(filename) + 1);
image.pixels = stbi_load(filename, &image.w, &image.h, &image.num_channels, 0);
image.data_len = image.w * image.h * image.num_channels; // NOTE: assumes 8 bits per channel
@ -89,5 +92,6 @@ utilFreeImage(util_image image)
image.w = image.h = image.data_len = 0;
image.bits_per_channel = 8;
image.num_channels = 4;
std::memset(image.file_path, 0, std::strlen(image.file_path) + 1);
utilSafeFree(image.pixels);
}

1
src/util.h

@ -57,6 +57,7 @@ struct util_image
int32 num_channels = 4;
uint data_len = 0;
uint8* pixels = nullptr;
char file_path[256];
};
inline real32

Loading…
Cancel
Save