clray
diff src/rt.cc @ 39:980bc07be868
Implemented OpenGL/OpenCL interop, and removed the texture copy
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 27 Aug 2010 18:30:09 +0100 |
parents | 7d77ded5f890 |
children | 1bcbb53b3505 |
line diff
1.1 --- a/src/rt.cc Fri Aug 27 02:22:08 2010 +0100 1.2 +++ b/src/rt.cc Fri Aug 27 18:30:09 2010 +0100 1.3 @@ -53,7 +53,7 @@ 1.4 static RendInfo rinf; 1.5 1.6 1.7 -bool init_renderer(int xsz, int ysz, Scene *scn) 1.8 +bool init_renderer(int xsz, int ysz, Scene *scn, unsigned int tex) 1.9 { 1.10 // render info 1.11 rinf.ambient[0] = rinf.ambient[1] = rinf.ambient[2] = 0.0; 1.12 @@ -94,7 +94,7 @@ 1.13 // XXX now we can actually destroy the original kdtree and keep only the GPU version 1.14 1.15 /* setup argument buffers */ 1.16 - prog->set_arg_buffer(KARG_FRAMEBUFFER, ARG_WR, xsz * ysz * 4 * sizeof(float)); 1.17 + prog->set_arg_texture(KARG_FRAMEBUFFER, ARG_WR, tex); 1.18 prog->set_arg_buffer(KARG_RENDER_INFO, ARG_RD, sizeof rinf, &rinf); 1.19 prog->set_arg_buffer(KARG_FACES, ARG_RD, rinf.num_faces * sizeof(Face), faces); 1.20 prog->set_arg_buffer(KARG_MATLIB, ARG_RD, scn->get_num_materials() * sizeof(Material), scn->get_materials()); 1.21 @@ -125,13 +125,32 @@ 1.22 1.23 bool render() 1.24 { 1.25 + // XXX do we need to call glFinish ? 1.26 + 1.27 long tm0 = get_msec(); 1.28 1.29 + cl_event ev; 1.30 + CLMemBuffer *texbuf = prog->get_arg_buffer(KARG_FRAMEBUFFER); 1.31 + 1.32 + if(!acquire_gl_object(texbuf, &ev)) { 1.33 + return false; 1.34 + } 1.35 + 1.36 + // make sure that we will wait for the acquire to finish before running 1.37 + prog->set_wait_event(ev); 1.38 + 1.39 if(!prog->run(1, global_size)) { 1.40 return false; 1.41 } 1.42 1.43 - long tm_run = get_msec() - tm0; 1.44 + if(!release_gl_object(texbuf, &ev)) { 1.45 + return false; 1.46 + } 1.47 + clWaitForEvents(1, &ev); 1.48 + 1.49 + printf("rendered in %ld msec\n", get_msec() - tm0); 1.50 + 1.51 + /*long tm_run = get_msec() - tm0; 1.52 1.53 CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_FRAMEBUFFER); 1.54 void *fb = map_mem_buffer(mbuf, MAP_RD); 1.55 @@ -146,6 +165,7 @@ 1.56 long tm_upd = get_msec() - tm0 - tm_run; 1.57 1.58 printf("render %ld msec (%ld run, %ld upd)\n", tm_run + tm_upd, tm_run, tm_upd); 1.59 + */ 1.60 return true; 1.61 } 1.62