Browse Source

rename structures in asset.h to consistent style

main
cinnaboot 5 years ago
parent
commit
9f94c153f8
  1. 44
      src/asset.cpp
  2. 21
      src/asset.h
  3. 2
      src/entity.cpp
  4. 2
      src/entity.h
  5. 2
      src/main.cpp
  6. 14
      src/shader.cpp
  7. 4
      src/shader.h
  8. 4
      src/tangerine.cpp

44
src/asset.cpp

@ -13,22 +13,22 @@
// TODO: move to GLDebug.h? // TODO: move to GLDebug.h?
void dumpNodes(tinygltf::Model t_mdl); void dumpNodes(tinygltf::Model t_mdl);
bool parseMeshNode(mesh* m, bool parseMeshNode(Mesh* m,
MemoryArena* arena, MemoryArena* arena,
const tinygltf::Node& node, const tinygltf::Node& node,
const tinygltf::Model& t_mdl); const tinygltf::Model& t_mdl);
model* getCachedModel(Assets* assets, u64 path_hash); Model* getCachedModel(Assets* assets, u64 path_hash);
model* loadModelFile(Assets* assets, const char* filename); Model* loadModelFile(Assets* assets, const char* filename);
util_image* getCachedTexture(Assets* assets, u64 path_hash); Texture* getCachedTexture(Assets* assets, u64 path_hash);
// interface // interface
model* Model*
getModelByPath(Assets* assets, const char* filepath) getModelByPath(Assets* assets, const char* filepath)
{ {
model* mdl = getCachedModel(assets, utilFNV64a_str(filepath)); Model* mdl = getCachedModel(assets, utilFNV64a_str(filepath));
if (!mdl) if (!mdl)
mdl = loadModelFile(assets, filepath); mdl = loadModelFile(assets, filepath);
@ -36,10 +36,10 @@ getModelByPath(Assets* assets, const char* filepath)
return mdl; return mdl;
} }
util_image* Texture*
getTextureByPath(Assets* assets, const char* filepath) getTextureByPath(Assets* assets, const char* filepath)
{ {
util_image* texture = Texture* texture =
getCachedTexture(assets, utilFNV64a_str(filepath)); getCachedTexture(assets, utilFNV64a_str(filepath));
// NOTE: the texture should be loaded when the model is loaded, so it's an // NOTE: the texture should be loaded when the model is loaded, so it's an
@ -55,18 +55,18 @@ getTextureByPath(Assets* assets, const char* filepath)
// internal // internal
model* Model*
initModel(Assets* assets, initModel(Assets* assets,
tinygltf::Model t_mdl, tinygltf::Model t_mdl,
const char* filename) const char* filename)
{ {
// TODO: re-alloc array when out of space // TODO: re-alloc array when out of space
assert(assets->num_models < assets->max_models && assets->arena != nullptr); assert(assets->num_models < assets->max_models && assets->arena != nullptr);
model* mdl = &assets->models[assets->num_models]; Model* mdl = &assets->models[assets->num_models];
assets->num_models++; assets->num_models++;
uint buf_count = t_mdl.bufferViews.size(); uint buf_count = t_mdl.bufferViews.size();
mdl->meshes = ARENA_ALLOC(assets->arena, mesh, buf_count); mdl->meshes = ARENA_ALLOC(assets->arena, Mesh, buf_count);
mdl->num_meshes = t_mdl.meshes.size(); mdl->num_meshes = t_mdl.meshes.size();
mdl->filepath = arenaCopyCStr(assets->arena, filename, MAX_PATH_SIZE); mdl->filepath = arenaCopyCStr(assets->arena, filename, MAX_PATH_SIZE);
mdl->filepath_hash = utilFNV64a_str(mdl->filepath); mdl->filepath_hash = utilFNV64a_str(mdl->filepath);
@ -74,7 +74,7 @@ initModel(Assets* assets,
return mdl; return mdl;
} }
util_image* Texture*
getFreeTexture(Assets* assets) getFreeTexture(Assets* assets)
{ {
if (assets->num_textures < assets->max_textures) if (assets->num_textures < assets->max_textures)
@ -84,7 +84,7 @@ getFreeTexture(Assets* assets)
return nullptr; return nullptr;
} }
util_image* Texture*
copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl) copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
{ {
// NOTE: assuming material[0] since we're using pallete texture // NOTE: assuming material[0] since we're using pallete texture
@ -93,7 +93,7 @@ copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
&& t_mdl.images.size() == 1 && t_mdl.images.size() == 1
&& t_mdl.images[0].image.size() > 0); && t_mdl.images[0].image.size() > 0);
tinygltf::Image t_img = t_mdl.images[0]; tinygltf::Image t_img = t_mdl.images[0];
util_image* dtex = getFreeTexture(assets); Texture* dtex = getFreeTexture(assets);
if (!dtex) { if (!dtex) {
LOG(Error) << "Error Loading diffuse texture\n"; LOG(Error) << "Error Loading diffuse texture\n";
@ -114,7 +114,7 @@ copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
return dtex; return dtex;
} }
model* Model*
loadModelFile(Assets* assets, const char* filename) loadModelFile(Assets* assets, const char* filename)
{ {
tinygltf::Model t_mdl; tinygltf::Model t_mdl;
@ -136,7 +136,7 @@ loadModelFile(Assets* assets, const char* filename)
// NOTE: assume we're working with a single buffer // NOTE: assume we're working with a single buffer
assert(t_mdl.buffers.size() == 1); assert(t_mdl.buffers.size() == 1);
model* mdl = initModel(assets, t_mdl, filename); Model* mdl = initModel(assets, t_mdl, filename);
mdl->diffuse_texture = copyDiffuseTexture(assets, t_mdl); mdl->diffuse_texture = copyDiffuseTexture(assets, t_mdl);
if (mdl->diffuse_texture == nullptr) return nullptr; if (mdl->diffuse_texture == nullptr) return nullptr;
@ -158,7 +158,7 @@ loadModelFile(Assets* assets, const char* filename)
return mdl; return mdl;
} }
model* Model*
getCachedModel(Assets* assets, u64 path_hash) getCachedModel(Assets* assets, u64 path_hash)
{ {
for (u32 i = 0; i < assets->num_models; i++) { for (u32 i = 0; i < assets->num_models; i++) {
@ -170,7 +170,7 @@ getCachedModel(Assets* assets, u64 path_hash)
return nullptr; return nullptr;
} }
util_image* Texture*
getCachedTexture(Assets* assets, u64 path_hash) getCachedTexture(Assets* assets, u64 path_hash)
{ {
for (u32 i = 0; i < assets->num_textures; i++) { for (u32 i = 0; i < assets->num_textures; i++) {
@ -246,7 +246,7 @@ parseNodeTransform(MemoryArena* arena, const tinygltf::Node* node)
} }
bool bool
parseMeshNode(mesh* m, parseMeshNode(Mesh* m,
MemoryArena* arena, MemoryArena* arena,
const tinygltf::Node& node, const tinygltf::Node& node,
const tinygltf::Model& t_mdl) const tinygltf::Model& t_mdl)
@ -341,11 +341,11 @@ getDrawMode(int drawMode)
} }
void void
dumpBuffer(tinygltf::Model model, tinygltf::Accessor acc) dumpBuffer(tinygltf::Model mdl, tinygltf::Accessor acc)
{ {
size_t bv_idx = acc.bufferView; size_t bv_idx = acc.bufferView;
assert(bv_idx >= 0 && bv_idx < model.bufferViews.size()); assert(bv_idx >= 0 && bv_idx < mdl.bufferViews.size());
tinygltf::BufferView bv = model.bufferViews[bv_idx]; tinygltf::BufferView bv = mdl.bufferViews[bv_idx];
LOG(Debug) << "-----------------------\n"; LOG(Debug) << "-----------------------\n";
LOG(Debug) << "buf idx: " << bv_idx << "\n"; LOG(Debug) << "buf idx: " << bv_idx << "\n";

21
src/asset.h

@ -9,8 +9,7 @@
// NOTE: wrapper for stb_image // NOTE: wrapper for stb_image
// TODO: better name would be AssetTexture struct Texture
struct util_image
{ {
i32 w; i32 w;
i32 h; i32 h;
@ -24,8 +23,7 @@ struct util_image
// NOTE: wrapper for tinygltf https://github.com/syoyo/tinygltf // NOTE: wrapper for tinygltf https://github.com/syoyo/tinygltf
// https://github.com/KhronosGroup/glTF // https://github.com/KhronosGroup/glTF
// TODO: rename to Mesh or MeshAsset? struct Mesh
struct mesh
{ {
u32 num_vertices; u32 num_vertices;
u32 num_indices; u32 num_indices;
@ -37,15 +35,14 @@ struct mesh
glm::mat4* xform; glm::mat4* xform;
}; };
// TODO: rename to Model or ModelAsset
#define MAX_PATH_SIZE 256 #define MAX_PATH_SIZE 256
struct model struct Model
{ {
char* filepath; char* filepath;
u64 filepath_hash; u64 filepath_hash;
uint num_meshes; uint num_meshes;
mesh* meshes; Mesh* meshes;
util_image* diffuse_texture; Texture* diffuse_texture;
}; };
struct Assets struct Assets
@ -53,15 +50,15 @@ struct Assets
MemoryArena* arena; MemoryArena* arena;
u32 num_models; u32 num_models;
u32 max_models; u32 max_models;
model* models; Model* models;
u32 num_textures; u32 num_textures;
u32 max_textures; u32 max_textures;
util_image* textures; Texture* textures;
}; };
model* getModelByPath(Assets* assets, const char* filepath); Model* getModelByPath(Assets* assets, const char* filepath);
util_image* getTextureByPath(Assets* assets, const char* filepath); Texture* getTextureByPath(Assets* assets, const char* filepath);

2
src/entity.cpp

@ -9,7 +9,7 @@ bool
initEntity(Entity* e, initEntity(Entity* e,
GLContext* gl_ctx, GLContext* gl_ctx,
MemoryArena* arena, MemoryArena* arena,
model* mdl, Model* mdl,
u32 num_attrib_mappings, u32 num_attrib_mappings,
GLBufferToAttribMapping* attrib_mappings, GLBufferToAttribMapping* attrib_mappings,
const char* name) const char* name)

2
src/entity.h

@ -20,7 +20,7 @@ struct Entity
bool initEntity(Entity* e, bool initEntity(Entity* e,
GLContext* gl_ctx, GLContext* gl_ctx,
MemoryArena* arena, MemoryArena* arena,
model* mdl, Model* mdl,
u32 num_attrib_mappings, u32 num_attrib_mappings,
GLBufferToAttribMapping* attrib_mappings, GLBufferToAttribMapping* attrib_mappings,
const char* name = ""); const char* name = "");

2
src/main.cpp

@ -8,7 +8,7 @@ bool
loadScene(RenderState* rs) loadScene(RenderState* rs)
{ {
// NOTE: load model // NOTE: load model
model* tex_cube = getModelByPath(&rs->assets, "../data/textured_cube.gltf"); Model* tex_cube = getModelByPath(&rs->assets, "../data/textured_cube.gltf");
if (!tex_cube) return false; if (!tex_cube) return false;
// NOTE: load new shader, or get one of the defaults // NOTE: load new shader, or get one of the defaults

14
src/shader.cpp

@ -29,8 +29,8 @@ bool compileAndLinkShader(ShaderProgram* shader,
GLuint& fs_id); GLuint& fs_id);
u32 getGLTypeSize(GLenum e); u32 getGLTypeSize(GLenum e);
GLTexture* getFreeGLTexture(GLContext* gl_ctx); GLTexture* getFreeGLTexture(GLContext* gl_ctx);
bool loadGLTexture(util_image* image, GLuint& tex_id); bool loadGLTexture(Texture* image, GLuint& tex_id);
void* getMeshData(const mesh& m, const GLBufferToAttribMapping& mapping); void* getMeshData(const Mesh& m, const GLBufferToAttribMapping& mapping);
// NOTE: interface // NOTE: interface
@ -138,7 +138,7 @@ getShaderByID(GLContext* gl_ctx, GLuint prog_id)
} }
GLTexture* GLTexture*
getGLTexture(GLContext* gl_ctx, util_image* diffuse_img) getGLTexture(GLContext* gl_ctx, Texture* diffuse_img)
{ {
u64 fp_hash = utilFNV64a_str(diffuse_img->file_path); u64 fp_hash = utilFNV64a_str(diffuse_img->file_path);
@ -228,7 +228,7 @@ getVertexAttribByName(ShaderProgram* shader, const char* name)
} }
GLmesh GLmesh
initGLmesh(const mesh& m, u32 num_mappings, GLenum draw_mode) initGLmesh(const Mesh& m, u32 num_mappings, GLenum draw_mode)
{ {
GLmesh glm = {0}; GLmesh glm = {0};
glm.num_indices = m.num_indices; glm.num_indices = m.num_indices;
@ -256,7 +256,7 @@ initGLAttribBuffer(GLBuffer* buf, GLenum target, GLVertexAttrib* attrib)
// FIXME: might as well pass in pointer to GLmesh, since that's how we're // FIXME: might as well pass in pointer to GLmesh, since that's how we're
// going to use this, can void copying GLmesh twice that way // going to use this, can void copying GLmesh twice that way
GLmesh GLmesh
loadGLMesh(const mesh& m, loadGLMesh(const Mesh& m,
GLenum draw_mode, GLenum draw_mode,
GLuint diffuse_texture_id, GLuint diffuse_texture_id,
u32 num_mappings, u32 num_mappings,
@ -322,7 +322,7 @@ freeGLMesh(GLmesh* glm)
// NOTE: internal // NOTE: internal
void* void*
getMeshData(const mesh& m, const GLBufferToAttribMapping& mapping) getMeshData(const Mesh& m, const GLBufferToAttribMapping& mapping)
{ {
switch (mapping.buf_type) { switch (mapping.buf_type) {
case VERTEX: return m.vertices; case VERTEX: return m.vertices;
@ -344,7 +344,7 @@ getFreeGLTexture(GLContext* gl_ctx)
} }
bool bool
loadGLTexture(util_image* image, GLuint& tex_id) loadGLTexture(Texture* image, GLuint& tex_id)
{ {
glGenTextures(1, &tex_id); glGenTextures(1, &tex_id);
glBindTexture(GL_TEXTURE_2D, tex_id); glBindTexture(GL_TEXTURE_2D, tex_id);

4
src/shader.h

@ -179,7 +179,7 @@ ShaderProgram* getShaderByHash(GLContext* gl_ctx, u64 hash);
ShaderProgram* getFreeShader(GLContext* gl_ctx); ShaderProgram* getFreeShader(GLContext* gl_ctx);
GLTexture* getGLTexture(GLContext* gl_ctx, util_image* diffuse_img); GLTexture* getGLTexture(GLContext* gl_ctx, Texture* diffuse_img);
void renderVAO(GLmesh* glmesh, void renderVAO(GLmesh* glmesh,
glm::mat4* model_xform, glm::mat4* model_xform,
@ -188,7 +188,7 @@ void renderVAO(GLmesh* glmesh,
GLVertexAttrib* getVertexAttribByName(ShaderProgram* shader, const char* name); GLVertexAttrib* getVertexAttribByName(ShaderProgram* shader, const char* name);
GLmesh loadGLMesh(const mesh& m, GLmesh loadGLMesh(const Mesh& m,
GLenum draw_mode, GLenum draw_mode,
GLuint diffuse_texture_id, GLuint diffuse_texture_id,
u32 num_mappings, u32 num_mappings,

4
src/tangerine.cpp

@ -31,10 +31,10 @@ initRenderState(u32 max_models,
if (rs) { if (rs) {
rs->assets.arena = arenaInit(DEFAULT_ARENA_SIZE); rs->assets.arena = arenaInit(DEFAULT_ARENA_SIZE);
rs->assets.max_models = max_models; rs->assets.max_models = max_models;
rs->assets.models = ARENA_ALLOC(rs->assets.arena, model, max_models); rs->assets.models = ARENA_ALLOC(rs->assets.arena, Model, max_models);
rs->assets.max_textures = max_textures; rs->assets.max_textures = max_textures;
rs->assets.textures = rs->assets.textures =
ARENA_ALLOC(rs->assets.arena, util_image, max_textures); ARENA_ALLOC(rs->assets.arena, Texture, max_textures);
rs->rg_arena = arenaInit(DEFAULT_ARENA_SIZE); rs->rg_arena = arenaInit(DEFAULT_ARENA_SIZE);
rs->max_render_groups = DEFAULT_RENDER_GROUP_COUNT; rs->max_render_groups = DEFAULT_RENDER_GROUP_COUNT;

Loading…
Cancel
Save