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?
void dumpNodes(tinygltf::Model t_mdl);
bool parseMeshNode(mesh* m,
bool parseMeshNode(Mesh* m,
MemoryArena* arena,
const tinygltf::Node& node,
const tinygltf::Model& t_mdl);
model* getCachedModel(Assets* assets, u64 path_hash);
model* loadModelFile(Assets* assets, const char* filename);
util_image* getCachedTexture(Assets* assets, u64 path_hash);
Model* getCachedModel(Assets* assets, u64 path_hash);
Model* loadModelFile(Assets* assets, const char* filename);
Texture* getCachedTexture(Assets* assets, u64 path_hash);
// interface
model*
Model*
getModelByPath(Assets* assets, const char* filepath)
{
model* mdl = getCachedModel(assets, utilFNV64a_str(filepath));
Model* mdl = getCachedModel(assets, utilFNV64a_str(filepath));
if (!mdl)
mdl = loadModelFile(assets, filepath);
@ -36,10 +36,10 @@ getModelByPath(Assets* assets, const char* filepath)
return mdl;
}
util_image*
Texture*
getTextureByPath(Assets* assets, const char* filepath)
{
util_image* texture =
Texture* texture =
getCachedTexture(assets, utilFNV64a_str(filepath));
// 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
model*
Model*
initModel(Assets* assets,
tinygltf::Model t_mdl,
const char* filename)
{
// TODO: re-alloc array when out of space
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++;
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->filepath = arenaCopyCStr(assets->arena, filename, MAX_PATH_SIZE);
mdl->filepath_hash = utilFNV64a_str(mdl->filepath);
@ -74,7 +74,7 @@ initModel(Assets* assets,
return mdl;
}
util_image*
Texture*
getFreeTexture(Assets* assets)
{
if (assets->num_textures < assets->max_textures)
@ -84,7 +84,7 @@ getFreeTexture(Assets* assets)
return nullptr;
}
util_image*
Texture*
copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
{
// 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[0].image.size() > 0);
tinygltf::Image t_img = t_mdl.images[0];
util_image* dtex = getFreeTexture(assets);
Texture* dtex = getFreeTexture(assets);
if (!dtex) {
LOG(Error) << "Error Loading diffuse texture\n";
@ -114,7 +114,7 @@ copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
return dtex;
}
model*
Model*
loadModelFile(Assets* assets, const char* filename)
{
tinygltf::Model t_mdl;
@ -136,7 +136,7 @@ loadModelFile(Assets* assets, const char* filename)
// NOTE: assume we're working with a single buffer
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);
if (mdl->diffuse_texture == nullptr) return nullptr;
@ -158,7 +158,7 @@ loadModelFile(Assets* assets, const char* filename)
return mdl;
}
model*
Model*
getCachedModel(Assets* assets, u64 path_hash)
{
for (u32 i = 0; i < assets->num_models; i++) {
@ -170,7 +170,7 @@ getCachedModel(Assets* assets, u64 path_hash)
return nullptr;
}
util_image*
Texture*
getCachedTexture(Assets* assets, u64 path_hash)
{
for (u32 i = 0; i < assets->num_textures; i++) {
@ -246,7 +246,7 @@ parseNodeTransform(MemoryArena* arena, const tinygltf::Node* node)
}
bool
parseMeshNode(mesh* m,
parseMeshNode(Mesh* m,
MemoryArena* arena,
const tinygltf::Node& node,
const tinygltf::Model& t_mdl)
@ -341,11 +341,11 @@ getDrawMode(int drawMode)
}
void
dumpBuffer(tinygltf::Model model, tinygltf::Accessor acc)
dumpBuffer(tinygltf::Model mdl, tinygltf::Accessor acc)
{
size_t bv_idx = acc.bufferView;
assert(bv_idx >= 0 && bv_idx < model.bufferViews.size());
tinygltf::BufferView bv = model.bufferViews[bv_idx];
assert(bv_idx >= 0 && bv_idx < mdl.bufferViews.size());
tinygltf::BufferView bv = mdl.bufferViews[bv_idx];
LOG(Debug) << "-----------------------\n";
LOG(Debug) << "buf idx: " << bv_idx << "\n";

21
src/asset.h

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

2
src/entity.h

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

2
src/main.cpp

@ -8,7 +8,7 @@ bool
loadScene(RenderState* rs)
{
// 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;
// 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);
u32 getGLTypeSize(GLenum e);
GLTexture* getFreeGLTexture(GLContext* gl_ctx);
bool loadGLTexture(util_image* image, GLuint& tex_id);
void* getMeshData(const mesh& m, const GLBufferToAttribMapping& mapping);
bool loadGLTexture(Texture* image, GLuint& tex_id);
void* getMeshData(const Mesh& m, const GLBufferToAttribMapping& mapping);
// NOTE: interface
@ -138,7 +138,7 @@ getShaderByID(GLContext* gl_ctx, GLuint prog_id)
}
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);
@ -228,7 +228,7 @@ getVertexAttribByName(ShaderProgram* shader, const char* name)
}
GLmesh
initGLmesh(const mesh& m, u32 num_mappings, GLenum draw_mode)
initGLmesh(const Mesh& m, u32 num_mappings, GLenum draw_mode)
{
GLmesh glm = {0};
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
// going to use this, can void copying GLmesh twice that way
GLmesh
loadGLMesh(const mesh& m,
loadGLMesh(const Mesh& m,
GLenum draw_mode,
GLuint diffuse_texture_id,
u32 num_mappings,
@ -322,7 +322,7 @@ freeGLMesh(GLmesh* glm)
// NOTE: internal
void*
getMeshData(const mesh& m, const GLBufferToAttribMapping& mapping)
getMeshData(const Mesh& m, const GLBufferToAttribMapping& mapping)
{
switch (mapping.buf_type) {
case VERTEX: return m.vertices;
@ -344,7 +344,7 @@ getFreeGLTexture(GLContext* gl_ctx)
}
bool
loadGLTexture(util_image* image, GLuint& tex_id)
loadGLTexture(Texture* image, GLuint& tex_id)
{
glGenTextures(1, &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);
GLTexture* getGLTexture(GLContext* gl_ctx, util_image* diffuse_img);
GLTexture* getGLTexture(GLContext* gl_ctx, Texture* diffuse_img);
void renderVAO(GLmesh* glmesh,
glm::mat4* model_xform,
@ -188,7 +188,7 @@ void renderVAO(GLmesh* glmesh,
GLVertexAttrib* getVertexAttribByName(ShaderProgram* shader, const char* name);
GLmesh loadGLMesh(const mesh& m,
GLmesh loadGLMesh(const Mesh& m,
GLenum draw_mode,
GLuint diffuse_texture_id,
u32 num_mappings,

4
src/tangerine.cpp

@ -31,10 +31,10 @@ initRenderState(u32 max_models,
if (rs) {
rs->assets.arena = arenaInit(DEFAULT_ARENA_SIZE);
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.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->max_render_groups = DEFAULT_RENDER_GROUP_COUNT;

Loading…
Cancel
Save