Browse Source

remove extra tests for normals and texture coords

testing
cinnaboot 6 years ago
parent
commit
13da8d8344
  1. 3
      Makefile
  2. 24
      src/mesh.cpp
  3. 2
      src/render_object.cpp

3
Makefile

@ -30,5 +30,6 @@ examples: $(LIBNAME)
.PHONY: examples
clean:
rm -rf $(OBJDIR)/* bin/*
rm -rf $(OBJDIR)/*
$(MAKE) clean -C $(EXAMPLEDIR)
.PHONY: clean

24
src/mesh.cpp

@ -15,7 +15,7 @@
// forward declarations
void assimpLogCB(const char* message, char* user);
meMeshInfo* allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has_texture);
meMeshInfo* allocateMeshInfo(uint num_vertices, uint num_indices);
void freeMesh(meMeshInfo* mesh);
inline glm::vec3 copyVector(aiVector3D v_in, glm::vec3& v_out);
meMeshInfo* copyMeshInfo(const aiScene* scene, aiMesh* mesh);
@ -96,7 +96,7 @@ assimpLogCB(const char* message, char* user)
}
meMeshInfo*
allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has_texture)
allocateMeshInfo(uint num_vertices, uint num_indices)
{
meMeshInfo* mi = UTIL_ALLOC(1, meMeshInfo);
mi->model_transform = glm::mat4(1);
@ -106,8 +106,8 @@ allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has
mi->vertices = UTIL_ALLOC(mi->num_vertices, glm::vec3);
mi->num_indices = num_indices;
mi->indices = UTIL_ALLOC(num_indices, uint);
if (has_normals) mi->normals = UTIL_ALLOC(mi->num_vertices, glm::vec3);
if (has_texture) mi->texture_coords = UTIL_ALLOC(mi->num_vertices, glm::vec3);
mi->normals = UTIL_ALLOC(mi->num_vertices, glm::vec3);
mi->texture_coords = UTIL_ALLOC(mi->num_vertices, glm::vec3);
return mi;
}
@ -169,21 +169,15 @@ loadDiffuseTexture(const aiScene* scene, aiMesh* mesh, meMeshInfo* mi)
meMeshInfo*
copyMeshInfo(const aiScene* scene, aiMesh* mesh)
{
bool has_tex = mesh->HasTextureCoords(0);
bool has_normals = mesh->HasNormals();
meMeshInfo* mi = allocateMeshInfo(mesh->mNumVertices, mesh->mNumFaces * 3, has_normals, has_tex);
meMeshInfo* mi = allocateMeshInfo(mesh->mNumVertices, mesh->mNumFaces * 3);
// copy vertices, normals, and texture coords
for (uint i = 0; i < mi->num_vertices; i++) {
copyVector(mesh->mVertices[i], mi->vertices[i]);
if (has_normals)
copyVector(mesh->mNormals[i], mi->normals[i]);
if (has_tex) {
mi->texture_coords[i].x = mesh->mTextureCoords[0][i].x;
mi->texture_coords[i].y = mesh->mTextureCoords[0][i].y;
}
copyVector(mesh->mNormals[i], mi->normals[i]);
mi->texture_coords[i].x = mesh->mTextureCoords[0][i].x;
mi->texture_coords[i].y = mesh->mTextureCoords[0][i].y;
mi->texture_coords[i].z = 0;
}
// copy indices

2
src/render_object.cpp

@ -108,6 +108,8 @@ roDraw(render_object& ro,
// TODO: could pass in a stride parameter here to enableGLFloatBuffer()
// could then use a 2d buffer for uv coords
enableGLFloatBuffer(ro.uv_buffer_id, 2);
glBindTexture(GL_TEXTURE_2D, ro.tex_id);
glUniform1i(shader.sampler_id, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ro.index_buffer_id);
glDrawElements(GL_TRIANGLES, ro.index_buffer_count, GL_UNSIGNED_INT, 0);

Loading…
Cancel
Save