Browse Source

require entities/meshes to have diffuse texture

testing
cinnaboot 6 years ago
parent
commit
3ebce450a3
  1. 7
      include/mesh.h
  2. 8
      include/render_object.h
  3. 14
      include/renderer.h
  4. 3
      src/entity.cpp
  5. 7
      src/mesh.cpp

7
include/mesh.h

@ -21,12 +21,7 @@ struct meMeshInfo
glm::vec3* texture_coords; // NOTE: using vec3 to stay aligned with other props
uint num_indices;
uint* indices;
glm::vec3 diffuse_color;
// TODO: move this to meMeshGroup
bool use_texture;
util_image diffuse_texture;
node_animation* node_anim;
};
@ -40,6 +35,8 @@ struct meMeshGroup
bool meInitAssimp();
// NOTE: meshes loaded from assimp require texture coordinates, and a diffuse
// texture, which can be a seperate file, or embedded in the input file
bool meLoadFromFile(meMeshGroup& mesh_group, const char* filepath);
void meFreeMeshGroup(meMeshGroup& mesh_group);

8
include/render_object.h

@ -16,13 +16,5 @@ struct render_object
GLuint index_buffer_id;
};
struct point_light
{
uint light_ID;
glm::vec3 position;
glm::vec3 color;
float intensity;
};
void roFree(render_object* ro);

14
include/renderer.h

@ -22,8 +22,15 @@ struct SDL_Handles
SDL_DisplayMode currentDisplayMode;
};
struct point_light;
struct point_light
{
uint light_ID;
glm::vec3 position;
glm::vec3 color;
float intensity;
};
/*
// NOTE: array of entities rendered with the same shader program
struct render_group
{
@ -32,6 +39,7 @@ struct render_group
shader_program shader;
};
*/
struct render_state
{
@ -41,8 +49,8 @@ struct render_state
camera cam;
util_RGBA clear_col;
render_group* render_groups;
uint render_group_count;
//render_group* render_groups;
//uint render_group_count;
point_light* lights;
uint num_lights;

3
src/entity.cpp

@ -5,7 +5,6 @@
#include "entity.h"
void initEntityRG(entity& e, rg_shader_program& shader, bool use_normals);
bool initEntityROs(entity& e);
bool convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_texture);
@ -61,6 +60,7 @@ entScale(entity& e, glm::vec3 v)
e.world_transform = glm::scale(e.world_transform, v);
}
#if 0
void
initEntityRG(entity& e, rg_shader_program& shader, bool use_normals)
{
@ -73,6 +73,7 @@ initEntityRG(entity& e, rg_shader_program& shader, bool use_normals)
uint num_meshes = rg->num_objects = e.mesh_group.num_meshes;
rg->render_objects = UTIL_ALLOC(num_meshes, render_object*);
}
#endif
bool
initEntityROs(entity& e)

7
src/mesh.cpp

@ -58,14 +58,14 @@ meLoadFromFile(meMeshGroup& mesh_group, const char* filepath)
aiMesh* mesh = scene->mMeshes[i];
meMeshInfo* mi = copyMeshInfo(scene, mesh);
if (mesh->HasTextureCoords(0)) {
if (!loadDiffuseTexture(scene, mesh, mi)) {
if (!mesh->HasTextureCoords(0)
|| !loadDiffuseTexture(scene, mesh, mi))
{
LOG(Error) << "Error loading texture, cleaning up import\n";
freeMesh(mi);
aiReleaseImport(scene);
return false;
}
}
mesh_group.meshes[i] = mi;
}
@ -152,7 +152,6 @@ loadDiffuseTexture(const aiScene* scene, aiMesh* mesh, meMeshInfo* mi)
LOG(Error) << "No diffuse texture from assimp\n";
return false;
} else {
mi->use_texture = true;
const aiTexture* tex = scene->GetEmbeddedTexture(file_name.C_Str());
if (tex != nullptr) {

Loading…
Cancel
Save