# HG changeset patch # User John Tsiombikas # Date 1281148596 -3600 # Node ID 29f9330cfa4b32f9bd6d068093984c48b9a8482b # Parent 407935b73af33f41169876357aeb936188c9a5b2 trying to debug the bloody thing diff -r 407935b73af3 -r 29f9330cfa4b clray.vcproj --- a/clray.vcproj Wed Aug 04 04:51:06 2010 +0100 +++ b/clray.vcproj Sat Aug 07 03:36:36 2010 +0100 @@ -41,7 +41,7 @@ + + + + @@ -195,6 +203,10 @@ > + + diff -r 407935b73af3 -r 29f9330cfa4b src/mesh.cc --- a/src/mesh.cc Wed Aug 04 04:51:06 2010 +0100 +++ b/src/mesh.cc Sat Aug 07 03:36:36 2010 +0100 @@ -125,6 +125,11 @@ return true; } +int Scene::get_num_meshes() const +{ + return (int)meshes.size(); +} + int Scene::get_num_faces() const { int num_faces = 0; @@ -135,6 +140,27 @@ return num_faces; } +int Scene::get_num_materials() const +{ + return (int)matlib.size(); +} + +Material *Scene::get_materials() +{ + if(matlib.empty()) { + return 0; + } + return &matlib[0]; +} + +const Material *Scene::get_materials() const +{ + if(matlib.empty()) { + return 0; + } + return &matlib[0]; +} + #define INVALID_IDX INT_MIN @@ -638,7 +664,9 @@ char *pathname = (char*)alloca(res_len + fnamelen + 2); memcpy(pathname, beg, res_len); pathname[res_len] = 0; - strcat(pathname, "/"); + if(res_len) { + strcat(pathname, "/"); + } strcat(pathname, fname); if((fp = fopen(pathname, mode))) { @@ -648,6 +676,7 @@ } beg += res_len; + if(*beg == ':') beg++; } return false; } @@ -662,7 +691,11 @@ strncpy(buf, str, PATH_MAX); char *ptr = strrchr(buf, '/'); - if(ptr && *ptr) *ptr = 0; + if(ptr && *ptr) { + *ptr = 0; + } else { + strcpy(buf, "."); + } } return buf; } diff -r 407935b73af3 -r 29f9330cfa4b src/mesh.h --- a/src/mesh.h Wed Aug 04 04:51:06 2010 +0100 +++ b/src/mesh.h Sat Aug 07 03:36:36 2010 +0100 @@ -35,8 +35,12 @@ std::vector matlib; bool add_mesh(Mesh *m); + int get_num_meshes() const; + int get_num_materials() const; + int get_num_faces() const; - int get_num_faces() const; + Material *get_materials(); + const Material *get_materials() const; bool load(const char *fname); bool load(FILE *fp); diff -r 407935b73af3 -r 29f9330cfa4b src/ocl.cc --- a/src/ocl.cc Wed Aug 04 04:51:06 2010 +0100 +++ b/src/ocl.cc Sat Aug 07 03:36:36 2010 +0100 @@ -156,6 +156,12 @@ } +CLArg::CLArg() +{ + memset(this, 0, sizeof *this); +} + + CLProgram::CLProgram(const char *kname) { prog = 0; @@ -242,7 +248,8 @@ printf("create argument %d buffer: %d bytes\n", idx, (int)sz); CLMemBuffer *buf; - if(!(buf = create_mem_buffer(rdwr, sz, ptr))) { + if(sz <= 0 || !(buf = create_mem_buffer(rdwr, sz, ptr))) { + fprintf(stderr, "invalid size while creating argument buffer %d: %d\n", idx, (int)sz); return false; } @@ -262,6 +269,17 @@ return args[arg].v.mbuf; } +int CLProgram::get_num_args() const +{ + int num_args = 0; + for(size_t i=0; i +#endif + +#include +#include + +#else /* __APPLE__ */ +#include +#include +#endif + + +#endif /* OGL_H_ */ diff -r 407935b73af3 -r 29f9330cfa4b src/rt.cc --- a/src/rt.cc Wed Aug 04 04:51:06 2010 +0100 +++ b/src/rt.cc Sat Aug 07 03:36:36 2010 +0100 @@ -2,15 +2,7 @@ #include #include #include - -#ifndef __APPLE__ -#include -#include -#else -#include -#include -#endif - +#include "ogl.h" #include "ocl.h" #include "mesh.h" @@ -23,7 +15,9 @@ KARG_LIGHTS, KARG_PRIM_RAYS, KARG_XFORM, - KARG_INVTRANS_XFORM + KARG_INVTRANS_XFORM, + + NUM_KERNEL_ARGS }; struct RendInfo { @@ -89,13 +83,17 @@ /* 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, 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_FACES, ARG_RD, rinf.num_faces * sizeof(Face), faces); + prog->set_arg_buffer(KARG_MATLIB, ARG_RD, scn->get_num_materials() * sizeof(Material), scn->get_materials()); 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)); prog->set_arg_buffer(KARG_INVTRANS_XFORM, ARG_RD, 16 * sizeof(float)); + if(prog->get_num_args() < NUM_KERNEL_ARGS) { + return false; + } + delete [] prim_rays; global_size = xsz * ysz; @@ -140,11 +138,18 @@ glLoadIdentity(); gluPerspective(45.0, (float)rinf.xsz / (float)rinf.ysz, 0.5, 1000.0); + Material *materials = scn->get_materials(); + glBegin(GL_TRIANGLES); int num_faces = scn->get_num_faces(); for(int i=0; imatlib[faces[i].matid]; - glColor3f(mat->kd[0], mat->kd[1], mat->kd[2]); + Material *mat = materials ? materials + faces[i].matid : 0; + + if(mat) { + glColor3f(mat->kd[0], mat->kd[1], mat->kd[2]); + } else { + glColor3f(1, 1, 1); + } for(int j=0; j<3; j++) { float *pos = faces[i].v[j].pos;