# HG changeset patch # User John Tsiombikas # Date 1280893866 -3600 # Node ID 407935b73af33f41169876357aeb936188c9a5b2 # Parent 85fd61f374d968a74d5e50c415955af5e0944c7c bollocks diff -r 85fd61f374d9 -r 407935b73af3 Makefile --- a/Makefile Tue Aug 03 13:06:59 2010 +0100 +++ b/Makefile Wed Aug 04 04:51:06 2010 +0100 @@ -5,7 +5,7 @@ CXX = g++ CXXFLAGS = -pedantic -Wall -g -LDFLAGS = $(libgl) $(libcl) +LDFLAGS = $(libgl) $(libcl) -lpthread ifeq ($(shell uname -s), Darwin) libgl = -framework OpenGL -framework GLUT diff -r 85fd61f374d9 -r 407935b73af3 src/clray.cc --- a/src/clray.cc Tue Aug 03 13:06:59 2010 +0100 +++ b/src/clray.cc Wed Aug 04 04:51:06 2010 +0100 @@ -9,6 +9,7 @@ #endif #include "rt.h" #include "matrix.h" +#include "mesh.h" void cleanup(); void disp(); @@ -24,12 +25,33 @@ static float cam_theta, cam_phi = 25.0; static float cam_dist = 10.0; -static bool dbg_glrender; +static bool dbg_glrender = true; + +static Scene scn; int main(int argc, char **argv) { glutInitWindowSize(800, 600); glutInit(&argc, argv); + + int loaded = 0; + for(int i=1; i +#include "matrix.h" + +#define M(x, y) ((y) * 4 + (x)) + +Matrix4x4::Matrix4x4() +{ + memset(m, 0, sizeof m); + m[0] = m[5] = m[10] = m[15] = 1.0; +} + +Matrix4x4::Matrix4x4(const float *mat) +{ + memcpy(m, mat, sizeof m); +} + +Matrix4x4::Matrix4x4(float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33) +{ + m[M(0, 0)] = m00; m[M(0, 1)] = m01; m[M(0, 2)] = m02; m[M(0, 3)] = m03; + m[M(1, 0)] = m10; m[M(1, 1)] = m11; m[M(1, 2)] = m12; m[M(1, 3)] = m13; + m[M(2, 0)] = m20; m[M(2, 1)] = m21; m[M(2, 2)] = m22; m[M(2, 3)] = m23; + m[M(3, 0)] = m30; m[M(3, 1)] = m31; m[M(3, 2)] = m32; m[M(3, 3)] = m33; +} + +Matrix4x4::Matrix4x4(const Matrix4x4 &mat) +{ + memcpy(m, mat.m, sizeof m); +} + +Matrix4x4 &Matrix4x4::operator =(const Matrix4x4 &mat) +{ + memcpy(m, mat.m, sizeof m); + return *this; +} + +void Matrix4x4::identity() +{ + memset(m, 0, sizeof m); + m[0] = m[5] = m[10] = m[15] = 1.0; +} + +float Matrix4x4::determinant() const +{ + float det11 = (m[M(1, 1)] * (m[M(2, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(2, 3)])) - + (m[M(1, 2)] * (m[M(2, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(2, 3)])) + + (m[M(1, 3)] * (m[M(2, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(2, 2)])); + + float det12 = (m[M(1, 0)] * (m[M(2, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(2, 3)])) - + (m[M(1, 2)] * (m[M(2, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(2, 3)])) + + (m[M(1, 3)] * (m[M(2, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(2, 2)])); + + float det13 = (m[M(1, 0)] * (m[M(2, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(2, 3)])) - + (m[M(1, 1)] * (m[M(2, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(2, 3)])) + + (m[M(1, 3)] * (m[M(2, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(2, 1)])); + + float det14 = (m[M(1, 0)] * (m[M(2, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(2, 2)])) - + (m[M(1, 1)] * (m[M(2, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(2, 2)])) + + (m[M(1, 2)] * (m[M(2, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(2, 1)])); + + return m[M(0, 0)] * det11 - m[M(0, 1)] * det12 + m[M(0, 2)] * det13 - m[M(0, 3)] * det14; +} + +Matrix4x4 Matrix4x4::adjoint() const +{ + Matrix4x4 coef; + + coef.m[M(0, 0)] = (m[M(1, 1)] * (m[M(2, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(2, 3)])) - + (m[M(1, 2)] * (m[M(2, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(2, 3)])) + + (m[M(1, 3)] * (m[M(2, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(2, 2)])); + coef.m[M(0, 1)] = (m[M(1, 0)] * (m[M(2, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(2, 3)])) - + (m[M(1, 2)] * (m[M(2, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(2, 3)])) + + (m[M(1, 3)] * (m[M(2, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(2, 2)])); + coef.m[M(0, 2)] = (m[M(1, 0)] * (m[M(2, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(2, 3)])) - + (m[M(1, 1)] * (m[M(2, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(2, 3)])) + + (m[M(1, 3)] * (m[M(2, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(2, 1)])); + coef.m[M(0, 3)] = (m[M(1, 0)] * (m[M(2, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(2, 2)])) - + (m[M(1, 1)] * (m[M(2, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(2, 2)])) + + (m[M(1, 2)] * (m[M(2, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(2, 1)])); + + coef.m[M(1, 0)] = (m[M(0, 1)] * (m[M(2, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(2, 3)])) - + (m[M(0, 2)] * (m[M(2, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(2, 3)])) + + (m[M(0, 3)] * (m[M(2, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(2, 2)])); + coef.m[M(1, 1)] = (m[M(0, 0)] * (m[M(2, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(2, 3)])) - + (m[M(0, 2)] * (m[M(2, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(2, 3)])) + + (m[M(0, 3)] * (m[M(2, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(2, 2)])); + coef.m[M(1, 2)] = (m[M(0, 0)] * (m[M(2, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(2, 3)])) - + (m[M(0, 1)] * (m[M(2, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(2, 3)])) + + (m[M(0, 3)] * (m[M(2, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(2, 1)])); + coef.m[M(1, 3)] = (m[M(0, 0)] * (m[M(2, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(2, 2)])) - + (m[M(0, 1)] * (m[M(2, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(2, 2)])) + + (m[M(0, 2)] * (m[M(2, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(2, 1)])); + + coef.m[M(2, 0)] = (m[M(0, 1)] * (m[M(1, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(1, 3)])) - + (m[M(0, 2)] * (m[M(1, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(1, 3)])) + + (m[M(0, 3)] * (m[M(1, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(1, 2)])); + coef.m[M(2, 1)] = (m[M(0, 0)] * (m[M(1, 2)] * m[M(3, 3)] - m[M(3, 2)] * m[M(1, 3)])) - + (m[M(0, 2)] * (m[M(1, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(1, 3)])) + + (m[M(0, 3)] * (m[M(1, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(1, 2)])); + coef.m[M(2, 2)] = (m[M(0, 0)] * (m[M(1, 1)] * m[M(3, 3)] - m[M(3, 1)] * m[M(1, 3)])) - + (m[M(0, 1)] * (m[M(1, 0)] * m[M(3, 3)] - m[M(3, 0)] * m[M(1, 3)])) + + (m[M(0, 3)] * (m[M(1, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(1, 1)])); + coef.m[M(2, 3)] = (m[M(0, 0)] * (m[M(1, 1)] * m[M(3, 2)] - m[M(3, 1)] * m[M(1, 2)])) - + (m[M(0, 1)] * (m[M(1, 0)] * m[M(3, 2)] - m[M(3, 0)] * m[M(1, 2)])) + + (m[M(0, 2)] * (m[M(1, 0)] * m[M(3, 1)] - m[M(3, 0)] * m[M(1, 1)])); + + coef.m[M(3, 0)] = (m[M(0, 1)] * (m[M(1, 2)] * m[M(2, 3)] - m[M(2, 2)] * m[M(1, 3)])) - + (m[M(0, 2)] * (m[M(1, 1)] * m[M(2, 3)] - m[M(2, 1)] * m[M(1, 3)])) + + (m[M(0, 3)] * (m[M(1, 1)] * m[M(2, 2)] - m[M(2, 1)] * m[M(1, 2)])); + coef.m[M(3, 1)] = (m[M(0, 0)] * (m[M(1, 2)] * m[M(2, 3)] - m[M(2, 2)] * m[M(1, 3)])) - + (m[M(0, 2)] * (m[M(1, 0)] * m[M(2, 3)] - m[M(2, 0)] * m[M(1, 3)])) + + (m[M(0, 3)] * (m[M(1, 0)] * m[M(2, 2)] - m[M(2, 0)] * m[M(1, 2)])); + coef.m[M(3, 2)] = (m[M(0, 0)] * (m[M(1, 1)] * m[M(2, 3)] - m[M(2, 1)] * m[M(1, 3)])) - + (m[M(0, 1)] * (m[M(1, 0)] * m[M(2, 3)] - m[M(2, 0)] * m[M(1, 3)])) + + (m[M(0, 3)] * (m[M(1, 0)] * m[M(2, 1)] - m[M(2, 0)] * m[M(1, 1)])); + coef.m[M(3, 3)] = (m[M(0, 0)] * (m[M(1, 1)] * m[M(2, 2)] - m[M(2, 1)] * m[M(1, 2)])) - + (m[M(0, 1)] * (m[M(1, 0)] * m[M(2, 2)] - m[M(2, 0)] * m[M(1, 2)])) + + (m[M(0, 2)] * (m[M(1, 0)] * m[M(2, 1)] - m[M(2, 0)] * m[M(1, 1)])); + + coef.transpose(); + + for(int i=0; i<4; i++) { + for(int j=0; j<4; j++) { + coef.m[M(i, j)] = j % 2 ? -coef.m[M(i, j)] : coef.m[M(i, j)]; + if(i % 2) coef.m[M(i, j)] = -coef.m[M(i, j)]; + } + } + + return coef; +} + +void Matrix4x4::invert() +{ + Matrix4x4 adj = adjoint(); + + float det = determinant(); + + for(int i=0; i<16; i++) { + m[i] = adj.m[i] / det; + } +} + +void Matrix4x4::transpose() +{ + float tmp[16]; + + memcpy(tmp, m, sizeof tmp); + for(int i=0; i<4; i++) { + for(int j=0; j<4; j++) { + m[M(i, j)] = tmp[M(j, i)]; + } + } +} diff -r 85fd61f374d9 -r 407935b73af3 src/matrix.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matrix.h Wed Aug 04 04:51:06 2010 +0100 @@ -0,0 +1,30 @@ +#ifndef MATRIX_H_ +#define MATRIX_H_ + +class Matrix4x4 { +public: + float m[16]; + + Matrix4x4(); + Matrix4x4(const float *mat); + Matrix4x4(float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33); + Matrix4x4(const Matrix4x4 &mat); + Matrix4x4 &operator =(const Matrix4x4 &mat); + + void identity(); + + float determinant() const; + Matrix4x4 adjoint() const; + void invert(); + void transpose(); + + + float *operator [](int idx); + const float *operator [](int idx) const; +}; + + +#endif /* MATRIX_H_ */ diff -r 85fd61f374d9 -r 407935b73af3 src/mesh.cc --- a/src/mesh.cc Tue Aug 03 13:06:59 2010 +0100 +++ b/src/mesh.cc Wed Aug 04 04:51:06 2010 +0100 @@ -115,6 +115,26 @@ static map matnames; +bool Scene::add_mesh(Mesh *m) +{ + // make sure triangles have material ids + for(size_t i=0; ifaces.size(); i++) { + m->faces[i].matid = m->matid; + } + meshes.push_back(m); + return true; +} + +int Scene::get_num_faces() const +{ + int num_faces = 0; + for(size_t i=0; ifaces.size(); + } + printf("get_num_faces() = %d\n", num_faces); + return num_faces; +} + #define INVALID_IDX INT_MIN @@ -200,7 +220,7 @@ if(!obj.f.empty()) { Mesh *mesh = cons_mesh(&obj); mesh->matid = matnames[obj.cur_mat]; - meshes.push_back(mesh); + add_mesh(mesh); obj_added++; obj.f.clear(); // clean the face list @@ -252,6 +272,7 @@ mat.kr = 0.0; // TODO mat.spow = vmtl[i].shininess; + matlib.push_back(mat); matnames[vmtl[i].name] = i; } } @@ -309,7 +330,7 @@ if(!obj.f.empty()) { Mesh *mesh = cons_mesh(&obj); mesh->matid = matnames[obj.cur_mat]; - meshes.push_back(mesh); + add_mesh(mesh); obj_added++; } @@ -342,16 +363,24 @@ face.v[j].pos[0] = obj->v[f->v[j]].x; face.v[j].pos[1] = obj->v[f->v[j]].y; face.v[j].pos[2] = obj->v[f->v[j]].z; + face.v[j].pos[3] = 0.0; int nidx = f->n[j] < 0 ? 0 : f->n[j]; face.v[j].normal[0] = obj->vn[nidx].x; face.v[j].normal[1] = obj->vn[nidx].y; face.v[j].normal[2] = obj->vn[nidx].z; + face.v[j].normal[3] = 0.0; int tidx = f->t[j] < 0 ? 0 : f->t[j]; face.v[j].tex[0] = obj->vt[tidx].x; face.v[j].tex[1] = obj->vt[tidx].y; } + + face.normal[0] = face.v[0].normal[0]; + face.normal[1] = face.v[1].normal[1]; + face.normal[2] = face.v[2].normal[2]; + face.normal[3] = 0.0; + mesh->faces.push_back(face); } @@ -390,6 +419,7 @@ case CMD_NEWMTL: // add the previous material, and start a new one if(mat.name.length() > 0) { + printf("Adding material: %s\n", mat.name.c_str()); vmtl->push_back(mat); mat.reset(); } @@ -442,6 +472,7 @@ } if(mat.name.length() > 0) { + printf("Adding material: %s\n", mat.name.c_str()); vmtl->push_back(mat); } return true; @@ -603,9 +634,10 @@ end++; } - int sz = end - beg + 1; - char *pathname = (char*)alloca(sz + fnamelen + 2); - memcpy(pathname, beg, sz); + int res_len = end - beg; + char *pathname = (char*)alloca(res_len + fnamelen + 2); + memcpy(pathname, beg, res_len); + pathname[res_len] = 0; strcat(pathname, "/"); strcat(pathname, fname); @@ -615,7 +647,7 @@ return true; } - beg += sz; + beg += res_len; } return false; } @@ -630,7 +662,7 @@ strncpy(buf, str, PATH_MAX); char *ptr = strrchr(buf, '/'); - if(*ptr) *ptr = 0; + if(ptr && *ptr) *ptr = 0; } return buf; } diff -r 85fd61f374d9 -r 407935b73af3 src/mesh.h --- a/src/mesh.h Tue Aug 03 13:06:59 2010 +0100 +++ b/src/mesh.h Wed Aug 04 04:51:06 2010 +0100 @@ -34,6 +34,10 @@ std::vector meshes; std::vector matlib; + bool add_mesh(Mesh *m); + + int get_num_faces() const; + bool load(const char *fname); bool load(FILE *fp); }; diff -r 85fd61f374d9 -r 407935b73af3 src/ocl.cc --- a/src/ocl.cc Tue Aug 03 13:06:59 2010 +0100 +++ b/src/ocl.cc Wed Aug 04 04:51:06 2010 +0100 @@ -239,6 +239,7 @@ bool CLProgram::set_arg_buffer(int idx, int rdwr, size_t sz, void *ptr) { + printf("create argument %d buffer: %d bytes\n", idx, (int)sz); CLMemBuffer *buf; if(!(buf = create_mem_buffer(rdwr, sz, ptr))) { diff -r 85fd61f374d9 -r 407935b73af3 src/rt.cc --- a/src/rt.cc Tue Aug 03 13:06:59 2010 +0100 +++ b/src/rt.cc Wed Aug 04 04:51:06 2010 +0100 @@ -41,35 +41,13 @@ }; static Ray get_primary_ray(int x, int y, int w, int h, float vfov_deg); +static Face *create_face_buffer(Mesh **meshes, int num_meshes); +static Face *faces; static Ray *prim_rays; static CLProgram *prog; static int global_size; -static Face faces[] = { - {/* face0 */ - { - {{-1, 0, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, - {{0, 1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, - {{1, 0, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}} - }, - {0, 0, -1, 0}, 0, {0, 0, 0} - }, - {/* face1 */ - { - {{-5, 0, -3, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, - {{0, 0, 3, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, - {{5, 0, -3, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}} - }, - {0, 1, 0, 0}, 1, {0, 0, 0} - } -}; - -static Material matlib[] = { - {{1, 0, 0, 1}, {1, 1, 1, 1}, 0, 0, 60.0, 0}, - {{0.2, 0.8, 0.3, 1}, {0, 0, 0, 0}, 0, 0, 0, 0} -}; - static Light lightlist[] = { {{-10, 10, -20, 0}, {1, 1, 1, 1}} }; @@ -78,12 +56,12 @@ static RendInfo rinf; -bool init_renderer(int xsz, int ysz) +bool init_renderer(int xsz, int ysz, Scene *scn) { // render info rinf.xsz = xsz; rinf.ysz = ysz; - rinf.num_faces = sizeof faces / sizeof *faces; + rinf.num_faces = scn->get_num_faces(); rinf.num_lights = sizeof lightlist / sizeof *lightlist; rinf.max_iter = 6; @@ -102,11 +80,17 @@ return false; } + /*Face **/faces = create_face_buffer(&scn->meshes[0], scn->meshes.size()); + if(!faces) { + fprintf(stderr, "failed to create face buffer\n"); + return false; + } + /* setup argument buffers */ prog->set_arg_buffer(KARG_FRAMEBUFFER, ARG_WR, xsz * ysz * 4 * sizeof(float)); prog->set_arg_buffer(KARG_RENDER_INFO, ARG_RD, sizeof rinf, &rinf); - prog->set_arg_buffer(KARG_FACES, ARG_RD, sizeof faces, faces); - prog->set_arg_buffer(KARG_MATLIB, ARG_RD, sizeof matlib, matlib); + prog->set_arg_buffer(KARG_FACES, ARG_RD, rinf.num_faces, faces); + prog->set_arg_buffer(KARG_MATLIB, ARG_RD, scn->matlib.size() * sizeof(Material), &scn->matlib[0]); prog->set_arg_buffer(KARG_LIGHTS, ARG_RD, sizeof lightlist, lightlist); prog->set_arg_buffer(KARG_PRIM_RAYS, ARG_RD, xsz * ysz * sizeof *prim_rays, prim_rays); prog->set_arg_buffer(KARG_XFORM, ARG_RD, 16 * sizeof(float)); @@ -125,18 +109,26 @@ bool render() { + printf("Running kernel..."); + fflush(stdout); if(!prog->run(1, global_size)) { return false; } + printf("done\n"); - CLMemBuffer *mbuf = prog->get_arg_buffer(0); + CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_FRAMEBUFFER); void *fb = map_mem_buffer(mbuf, MAP_RD); + if(!fb) { + fprintf(stderr, "FAILED\n"); + return false; + } + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rinf.xsz, rinf.ysz, GL_RGBA, GL_FLOAT, fb); unmap_mem_buffer(mbuf); return true; } -void dbg_render_gl() +void dbg_render_gl(Scene *scn) { glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT); @@ -149,8 +141,9 @@ gluPerspective(45.0, (float)rinf.xsz / (float)rinf.ysz, 0.5, 1000.0); glBegin(GL_TRIANGLES); - for(int i=0; iget_num_faces(); + for(int i=0; imatlib[faces[i].matid]; glColor3f(mat->kd[0], mat->kd[1], mat->kd[2]); for(int j=0; j<3; j++) { @@ -158,6 +151,18 @@ glVertex3f(pos[0], pos[1], pos[2]); } } + + /*for(size_t i=0; imeshes.size(); i++) { + Material *mat = &scn->matlib[scn->meshes[i]->matid]; + + glColor3f(mat->kd[0], mat->kd[1], mat->kd[2]); + for(size_t j=0; jmeshes[i]->faces.size(); j++) { + for(int k=0; k<3; k++) { + float *pos = scn->meshes[i]->faces[j].v[k].pos; + glVertex3f(pos[0], pos[1], pos[2]); + } + } + }*/ glEnd(); glPopMatrix(); @@ -172,20 +177,20 @@ float *mem = (float*)map_mem_buffer(mbuf_xform, MAP_WR); memcpy(mem, matrix, 16 * sizeof *mem); - printf("-- xform:\n"); + /*printf("-- xform:\n"); for(int i=0; i<16; i++) { printf("%2.3f\t", mem[i]); if(i % 4 == 3) putchar('\n'); - } + }*/ unmap_mem_buffer(mbuf_xform); mem = (float*)map_mem_buffer(mbuf_invtrans, MAP_WR); memcpy(mem, invtrans, 16 * sizeof *mem); - printf("-- inverse-transpose:\n"); + /*printf("-- inverse-transpose:\n"); for(int i=0; i<16; i++) { printf("%2.3f\t", mem[i]); if(i % 4 == 3) putchar('\n'); - } + }*/ unmap_mem_buffer(mbuf_invtrans); } @@ -208,3 +213,23 @@ Ray ray = {{0, 0, 0, 1}, {px, py, -pz, 1}}; return ray; } + +static Face *create_face_buffer(Mesh **meshes, int num_meshes) +{ + int num_faces = 0; + for(int i=0; ifaces.size(); + } + printf("constructing face buffer with %d faces (out of %d meshes)\n", num_faces, num_meshes); + + Face *faces = new Face[num_faces]; + memset(faces, 0, num_faces * sizeof *faces); + Face *fptr = faces; + + for(int i=0; ifaces.size(); j++) { + *fptr++ = meshes[i]->faces[j]; + } + } + return faces; +} diff -r 85fd61f374d9 -r 407935b73af3 src/rt.h --- a/src/rt.h Tue Aug 03 13:06:59 2010 +0100 +++ b/src/rt.h Wed Aug 04 04:51:06 2010 +0100 @@ -1,11 +1,13 @@ #ifndef RT_H_ #define RT_H_ -bool init_renderer(int xsz, int ysz); +#include "mesh.h" + +bool init_renderer(int xsz, int ysz, Scene *scn); void destroy_renderer(); bool render(); void set_xform(float *matrix, float *invtrans); -void dbg_render_gl(); +void dbg_render_gl(Scene *scn); #endif /* RT_H_ */