X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fmesh.cc;h=04d25c298680344db737002a08e210152b53ff8a;hp=e17b909a0226fb02715ab59149f8112abe6146be;hb=e0894a58b7dd8732526c4e2e196acb97cd62cd02;hpb=8137121400748ee8afb1608253aae15323c5e3a2 diff --git a/src/mesh.cc b/src/mesh.cc index e17b909..04d25c2 100644 --- a/src/mesh.cc +++ b/src/mesh.cc @@ -4,6 +4,7 @@ #include #include "opengl.h" #include "mesh.h" +#include "logger.h" //#include "xform_node.h" #define USE_OLDGL @@ -154,12 +155,12 @@ void Mesh::clear() float *Mesh::set_attrib_data(int attrib, int nelem, unsigned int num, const float *data) { if(attrib < 0 || attrib >= NUM_MESH_ATTR) { - fprintf(stderr, "%s: invalid attrib: %d\n", __FUNCTION__, attrib); + error_log("%s: invalid attrib: %d\n", __FUNCTION__, attrib); return 0; } if(nverts && num != nverts) { - fprintf(stderr, "%s: attribute count missmatch (%d instead of %d)\n", __FUNCTION__, num, nverts); + error_log("%s: attribute count missmatch (%d instead of %d)\n", __FUNCTION__, num, nverts); return 0; } nverts = num; @@ -180,7 +181,7 @@ float *Mesh::set_attrib_data(int attrib, int nelem, unsigned int num, const floa float *Mesh::get_attrib_data(int attrib) { if(attrib < 0 || attrib >= NUM_MESH_ATTR) { - fprintf(stderr, "%s: invalid attrib: %d\n", __FUNCTION__, attrib); + error_log("%s: invalid attrib: %d\n", __FUNCTION__, attrib); return 0; } @@ -191,17 +192,17 @@ float *Mesh::get_attrib_data(int attrib) const float *Mesh::get_attrib_data(int attrib) const { if(attrib < 0 || attrib >= NUM_MESH_ATTR) { - fprintf(stderr, "%s: invalid attrib: %d\n", __FUNCTION__, attrib); + error_log("%s: invalid attrib: %d\n", __FUNCTION__, attrib); return 0; } if(!vattr[attrib].data_valid) { #if GL_ES_VERSION_2_0 - fprintf(stderr, "%s: can't read back attrib data on CrippledGL ES\n", __FUNCTION__); + error_log("%s: can't read back attrib data on CrippledGL ES\n", __FUNCTION__); return 0; #else if(!vattr[attrib].vbo_valid) { - fprintf(stderr, "%s: unavailable attrib: %d\n", __FUNCTION__, attrib); + error_log("%s: unavailable attrib: %d\n", __FUNCTION__, attrib); return 0; } @@ -255,7 +256,7 @@ unsigned int *Mesh::set_index_data(int num, const unsigned int *indices) { int nidx = nfaces * 3; if(nidx && num != nidx) { - fprintf(stderr, "%s: index count mismatch (%d instead of %d)\n", __FUNCTION__, num, nidx); + error_log("%s: index count mismatch (%d instead of %d)\n", __FUNCTION__, num, nidx); return 0; } nfaces = num / 3; @@ -283,11 +284,11 @@ const unsigned int *Mesh::get_index_data() const { if(!idata_valid) { #if GL_ES_VERSION_2_0 - fprintf(stderr, "%s: can't read back index data in CrippledGL ES\n", __FUNCTION__); + error_log("%s: can't read back index data in CrippledGL ES\n", __FUNCTION__); return 0; #else if(!ibo_valid) { - fprintf(stderr, "%s: indices unavailable\n", __FUNCTION__); + error_log("%s: indices unavailable\n", __FUNCTION__); return 0; } @@ -631,14 +632,14 @@ bool Mesh::pre_draw() const ((Mesh*)this)->update_buffers(); if(!vattr[MESH_ATTR_VERTEX].vbo_valid) { - fprintf(stderr, "%s: invalid vertex buffer\n", __FUNCTION__); + error_log("%s: invalid vertex buffer\n", __FUNCTION__); return false; } if(cur_sdr && use_custom_sdr_attr) { // rendering with shaders if(global_sdr_loc[MESH_ATTR_VERTEX] == -1) { - fprintf(stderr, "%s: shader attribute location for vertices unset\n", __FUNCTION__); + error_log("%s: shader attribute location for vertices unset\n", __FUNCTION__); return false; } @@ -1133,7 +1134,7 @@ bool Mesh::dump_obj(const char *fname) const return false; } -bool Mesh::dump_obj(FILE *fp) const +bool Mesh::dump_obj(FILE *fp, int voffs) const { if(!has_attrib(MESH_ATTR_VERTEX)) { return false; @@ -1141,20 +1142,20 @@ bool Mesh::dump_obj(FILE *fp) const for(int i=0; i<(int)nverts; i++) { Vec4 v = get_attrib(MESH_ATTR_VERTEX, i); - fprintf(fp, "v %g %g %g\n", v.x, v.y, v.z); + fprintf(fp, "v %f %f %f\n", v.x, v.y, v.z); } if(has_attrib(MESH_ATTR_NORMAL)) { for(int i=0; i<(int)nverts; i++) { Vec4 v = get_attrib(MESH_ATTR_NORMAL, i); - fprintf(fp, "vn %g %g %g\n", v.x, v.y, v.z); + fprintf(fp, "vn %f %f %f\n", v.x, v.y, v.z); } } if(has_attrib(MESH_ATTR_TEXCOORD)) { for(int i=0; i<(int)nverts; i++) { Vec4 v = get_attrib(MESH_ATTR_TEXCOORD, i); - fprintf(fp, "vt %g %g\n", v.x, v.y); + fprintf(fp, "vt %f %f\n", v.x, v.y); } } @@ -1167,14 +1168,14 @@ bool Mesh::dump_obj(FILE *fp) const for(int i=0; i