Max 5 API Reference
00001 /* 00002 * Copyright 2001-2005 - Cycling '74 00003 * Derek Gerstmann - derek@cycling74.com 00004 * 00005 * Struct and associated methods for maintaining an OpenGL 00006 * pixel buffer object (PBO). 00007 * 00008 */ 00009 00010 /****************************************************************************/ 00011 00012 #include "jit.gl.pbo.h" 00013 #include "jit.gl.support.h" 00014 00015 void *_jit_gl_pbo_class; 00016 00017 //targets 00018 static t_symbol *ps_jit_gl_pbo_pixel_pack_buffer; 00019 static t_symbol *ps_jit_gl_pbo_pixel_unpack_buffer; 00020 00021 //usages 00022 static t_symbol *ps_jit_gl_pbo_stream_draw; 00023 static t_symbol *ps_jit_gl_pbo_stream_read; 00024 static t_symbol *ps_jit_gl_pbo_stream_copy; 00025 static t_symbol *ps_jit_gl_pbo_static_draw; 00026 static t_symbol *ps_jit_gl_pbo_static_read; 00027 static t_symbol *ps_jit_gl_pbo_static_copy; 00028 static t_symbol *ps_jit_gl_pbo_dynamic_draw; 00029 static t_symbol *ps_jit_gl_pbo_dynamic_read; 00030 static t_symbol *ps_jit_gl_pbo_dynamic_copy; 00031 00032 /****************************************************************************/ 00033 00034 t_jit_err jit_gl_pbo_init(void) 00035 { 00036 long attrflags=0; 00037 long ob3d_flags=0; 00038 t_jit_object *attr; 00039 void * ob3d; 00040 00041 _jit_gl_pbo_class = jit_class_new("jit_gl_pbo", (method)jit_gl_pbo_new, (method)jit_gl_pbo_free, 00042 sizeof(t_jit_gl_pbo),A_DEFSYM,0L); 00043 00044 // set up object extension for 3d object, customized with flags 00045 ob3d_flags |= JIT_OB3D_NO_ROTATION_SCALE; 00046 ob3d_flags |= JIT_OB3D_NO_POLY_VARS; 00047 ob3d_flags |= JIT_OB3D_NO_BLEND; 00048 ob3d_flags |= JIT_OB3D_NO_TEXTURE; 00049 ob3d_flags |= JIT_OB3D_NO_DEPTH; 00050 ob3d_flags |= JIT_OB3D_NO_ANTIALIAS; 00051 ob3d_flags |= JIT_OB3D_NO_FOG; 00052 ob3d_flags |= JIT_OB3D_NO_LIGHTING_MATERIAL; 00053 ob3d_flags |= JIT_OB3D_NO_COLOR; 00054 ob3d = jit_ob3d_setup(_jit_gl_pbo_class, calcoffset(t_jit_gl_pbo, ob3d), ob3d_flags); 00055 00056 // add attributes 00057 attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW; 00058 attr = jit_object_new(_jit_sym_jit_attr_offset,"planecount",_jit_sym_long,attrflags, 00059 (method)0L,(method)jit_gl_pbo_setattr_planecount,calcoffset(t_jit_gl_pbo,planecount)); 00060 jit_class_addattr(_jit_gl_pbo_class,attr); 00061 00062 attr = jit_object_new(_jit_sym_jit_attr_offset,"type",_jit_sym_symbol,attrflags, 00063 (method)0L,(method)jit_gl_pbo_setattr_type,calcoffset(t_jit_gl_pbo,type)); 00064 jit_class_addattr(_jit_gl_pbo_class,attr); 00065 00066 attr = jit_object_new(_jit_sym_jit_attr_offset_array,"offset",_jit_sym_long,2,attrflags, 00067 (method)0L,(method)jit_gl_pbo_setattr_offset,NULL,calcoffset(t_jit_gl_pbo,offset)); 00068 jit_class_addattr(_jit_gl_pbo_class,attr); 00069 00070 attr = jit_object_new(_jit_sym_jit_attr_offset_array,"dim",_jit_sym_long,2,attrflags, 00071 (method)0L,(method)jit_gl_pbo_setattr_dim,NULL,calcoffset(t_jit_gl_pbo,dim)); 00072 jit_class_addattr(_jit_gl_pbo_class,attr); 00073 00074 attr = jit_object_new(_jit_sym_jit_attr_offset,"target",_jit_sym_symbol,attrflags, 00075 (method)0L,(method)jit_gl_pbo_setattr_target,calcoffset(t_jit_gl_pbo,target)); 00076 jit_class_addattr(_jit_gl_pbo_class,attr); 00077 00078 attr = jit_object_new(_jit_sym_jit_attr_offset,"usage",_jit_sym_symbol,attrflags, 00079 (method)0L,(method)jit_gl_pbo_setattr_usage,calcoffset(t_jit_gl_pbo,usage)); 00080 jit_class_addattr(_jit_gl_pbo_class,attr); 00081 00082 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_draw, "ob3d_draw", A_CANT, 0L); 00083 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_dest_changed, "dest_changed", A_CANT, 0L); 00084 00085 // must register for ob3d 00086 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_object_register, "register", A_CANT, 0L); 00087 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_dest_closing, "dest_closing", A_CANT, 0L); 00088 00089 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_destroy, "destroy", A_CANT, 0L); 00090 00091 //bind/unbind 00092 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_bind, "bind", A_DEFER_LOW, 0L); 00093 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_unbind, "unbind", A_DEFER_LOW, 0L); 00094 00095 //to/from matrix 00096 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_from_matrix, "from_matrix", A_CANT, 0L); 00097 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_to_matrix, "to_matrix", A_CANT, 0L); 00098 00099 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_readpixels, "readpixels", A_CANT, 0L); 00100 jit_class_addmethod(_jit_gl_pbo_class, (method)jit_gl_pbo_getteximage, "getteximage", A_CANT, 0L); 00101 00102 00103 jit_class_register(_jit_gl_pbo_class); 00104 00105 ps_jit_gl_pbo_pixel_pack_buffer = gensym("pixel_pack_buffer"); 00106 ps_jit_gl_pbo_pixel_unpack_buffer = gensym("pixel_unpack_buffer"); 00107 ps_jit_gl_pbo_stream_draw = gensym("stream_draw"); 00108 ps_jit_gl_pbo_stream_read = gensym("stream_read"); 00109 ps_jit_gl_pbo_stream_copy = gensym("stream_copy"); 00110 ps_jit_gl_pbo_static_draw = gensym("static_draw"); 00111 ps_jit_gl_pbo_static_read = gensym("static_read"); 00112 ps_jit_gl_pbo_static_copy = gensym("static_copy"); 00113 ps_jit_gl_pbo_dynamic_draw = gensym("dynamic_draw"); 00114 ps_jit_gl_pbo_dynamic_read = gensym("dynamic_read"); 00115 ps_jit_gl_pbo_dynamic_copy = gensym("dynamic_copy"); 00116 00117 return JIT_ERR_NONE; 00118 } 00119 00120 00121 t_jit_gl_pbo *jit_gl_pbo_new() 00122 { 00123 t_jit_gl_pbo *x = NULL; 00124 00125 if(x = (t_jit_gl_pbo *)jit_object_alloc(_jit_gl_pbo_class)) 00126 { 00127 jit_gl_pbo_reset(x); 00128 } 00129 00130 return x; 00131 } 00132 00133 void jit_gl_pbo_free(t_jit_gl_pbo *x) 00134 { 00135 if(x) 00136 { 00137 jit_gl_pbo_destroy(x); 00138 } 00139 } 00140 00141 #ifdef __glext_h 00142 #error "__glext_h" 00143 #endif 00144 00145 GLenum jit_gl_pbo_gltarget_from_target(t_symbol *target) 00146 { 00147 if(target == ps_jit_gl_pbo_pixel_pack_buffer) { 00148 return GL_PIXEL_PACK_BUFFER_EXT; 00149 } 00150 else { 00151 return GL_PIXEL_UNPACK_BUFFER_EXT; 00152 } 00153 } 00154 00155 GLenum jit_gl_pbo_glusage_from_usage(t_symbol *usage) 00156 { 00157 if(usage == ps_jit_gl_pbo_stream_draw) { 00158 return GL_STREAM_DRAW_ARB; 00159 } 00160 else if(usage == ps_jit_gl_pbo_stream_read) { 00161 return GL_STREAM_READ_ARB; 00162 } 00163 else if(usage == ps_jit_gl_pbo_stream_copy) { 00164 return GL_STREAM_COPY_ARB; 00165 } 00166 else if(usage == ps_jit_gl_pbo_static_draw) { 00167 return GL_STATIC_DRAW_ARB; 00168 } 00169 else if(usage == ps_jit_gl_pbo_static_read) { 00170 return GL_STATIC_READ_ARB; 00171 } 00172 else if(usage == ps_jit_gl_pbo_static_copy) { 00173 return GL_STATIC_COPY_ARB; 00174 } 00175 else if(usage == ps_jit_gl_pbo_dynamic_draw) { 00176 return GL_DYNAMIC_DRAW_ARB; 00177 } 00178 else if(usage == ps_jit_gl_pbo_dynamic_read) { 00179 return GL_DYNAMIC_READ_ARB; 00180 } 00181 else if(usage == ps_jit_gl_pbo_dynamic_copy) { 00182 return GL_DYNAMIC_COPY_ARB; 00183 } 00184 00185 //default 00186 return GL_STREAM_DRAW_ARB; 00187 } 00188 00189 GLenum jit_gl_pbo_gltype_from_type(t_symbol *type) 00190 { 00191 if(type == _jit_sym_float32) { 00192 return GL_FLOAT; 00193 } 00194 else if(type == _jit_sym_long) { 00195 return GL_UNSIGNED_INT; 00196 } 00197 else { 00198 return GL_UNSIGNED_BYTE; 00199 } 00200 } 00201 00202 long jit_gl_pbo_datasize_from_gltype(GLenum gltype) 00203 { 00204 switch(gltype) { 00205 case GL_FLOAT: return sizeof(GLfloat); break; 00206 case GL_UNSIGNED_INT: return sizeof(GLuint); break; 00207 00208 case GL_UNSIGNED_BYTE: 00209 default: return sizeof(GLubyte); break; 00210 } 00211 } 00212 00213 t_jit_err jit_gl_pbo_create(t_jit_gl_pbo *x) 00214 { 00215 GLuint id; 00216 t_jit_err err; 00217 long bpp, size; 00218 00219 //calculate size info to verify if we need to destroy 00220 x->gltype = jit_gl_pbo_gltype_from_type(x->type); 00221 bpp = jit_gl_pbo_datasize_from_gltype(x->gltype); 00222 00223 size = x->dim[0]*x->dim[1]*x->planecount*bpp; 00224 00225 // delete existing cache if buffer size is different 00226 if(x->size != size) 00227 { 00228 err = jit_gl_pbo_destroy(x); 00229 if(err) return err; 00230 } 00231 x->size = size; 00232 00233 // create the buffer object 00234 if(x->id < 0) 00235 { 00236 glGenBuffersARB(1, &id); 00237 x->id = id; 00238 } 00239 00240 if(x->id < 0) 00241 { 00242 jit_object_error((t_object *)x,"jit.gl.texture: unable to create pixel buffer object."); 00243 return JIT_ERR_GENERIC; 00244 } 00245 00246 x->recreate = FALSE; //must come before bind to avoid infinite recursion 00247 00248 // bind the buffer 00249 err = jit_gl_pbo_bind(x); 00250 if(err) return err; 00251 00252 // allocate buffer 00253 glBufferDataARB(x->gltarget, x->size, NULL, x->glusage); 00254 jit_gl_report_error("jit.gl: error allocating pixel buffer object!"); 00255 00256 // unbind buffer 00257 err = jit_gl_pbo_unbind(x); 00258 if(err) return err; 00259 00260 return JIT_ERR_NONE; 00261 } 00262 00263 t_jit_err jit_gl_pbo_setattr_dim(t_jit_gl_pbo *x, void *attr, long argc, t_atom *argv) 00264 { 00265 long v; 00266 long i, c, p; 00267 long changed = FALSE; 00268 00269 if (x) 00270 { 00271 for(i = 0; i < MIN(argc, 2); i++) 00272 { 00273 v = jit_atom_getlong(argv+i); 00274 if(x->dim[i] != v) 00275 { 00276 x->dim[i] = v; 00277 changed = TRUE; 00278 } 00279 } 00280 00281 if(changed) 00282 { 00283 x->destroy = TRUE; 00284 x->recreate = TRUE; 00285 } 00286 00287 return JIT_ERR_NONE; 00288 } 00289 return JIT_ERR_INVALID_PTR; 00290 } 00291 00292 t_jit_err jit_gl_pbo_setattr_offset(t_jit_gl_pbo *x, void *attr, long argc, t_atom *argv) 00293 { 00294 long v; 00295 long i, c, p; 00296 long changed = FALSE; 00297 00298 if (x) 00299 { 00300 for(i = 0; i < MIN(argc, 2); i++) 00301 { 00302 v = jit_atom_getlong(argv+i); 00303 if(x->offset[i] != v) 00304 { 00305 x->offset[i] = v; 00306 changed = TRUE; 00307 } 00308 } 00309 00310 if(changed) 00311 { 00312 x->destroy = TRUE; 00313 x->recreate = TRUE; 00314 } 00315 00316 return JIT_ERR_NONE; 00317 } 00318 return JIT_ERR_INVALID_PTR; 00319 } 00320 00321 t_jit_err jit_gl_pbo_setattr_target(t_jit_gl_pbo *x, void *attr, long argc, t_atom *argv) 00322 { 00323 if(x) 00324 { 00325 if(argc) 00326 { 00327 t_symbol *target = jit_atom_getsym(argv); 00328 if(target != x->target) 00329 { 00330 x->target = target; 00331 x->gltarget = jit_gl_pbo_gltarget_from_target(x->target); 00332 x->destroy = TRUE; 00333 x->recreate = TRUE; 00334 } 00335 } 00336 00337 return JIT_ERR_NONE; 00338 } 00339 return JIT_ERR_INVALID_PTR; 00340 } 00341 00342 t_jit_err jit_gl_pbo_setattr_usage(t_jit_gl_pbo *x, void *attr, long argc, t_atom *argv) 00343 { 00344 if(x) 00345 { 00346 if(argc) 00347 { 00348 t_symbol *usage = jit_atom_getsym(argv); 00349 if(usage != x->usage) 00350 { 00351 x->usage = usage; 00352 x->glusage = jit_gl_pbo_glusage_from_usage(x->usage); 00353 x->destroy = TRUE; 00354 x->recreate = TRUE; 00355 } 00356 } 00357 00358 return JIT_ERR_NONE; 00359 } 00360 return JIT_ERR_INVALID_PTR; 00361 } 00362 00363 t_jit_err jit_gl_pbo_setattr_planecount(t_jit_gl_pbo *x, void *attr, long argc, t_atom *argv) 00364 { 00365 if(x) 00366 { 00367 if(argc) 00368 { 00369 long planecount = jit_atom_getlong(argv); 00370 if(planecount != x->planecount) 00371 { 00372 x->planecount = planecount; 00373 x->destroy = TRUE; 00374 x->recreate = TRUE; 00375 } 00376 } 00377 00378 return JIT_ERR_NONE; 00379 } 00380 return JIT_ERR_INVALID_PTR; 00381 } 00382 00383 t_jit_err jit_gl_pbo_setattr_type(t_jit_gl_pbo *x, void *attr, long argc, t_atom *argv) 00384 { 00385 if(x) { 00386 if(argc) { 00387 t_symbol *type = jit_atom_getsym(argv); 00388 if(type != x->type) { 00389 x->type = type; 00390 x->destroy = TRUE; 00391 x->recreate = TRUE; 00392 } 00393 } 00394 00395 return JIT_ERR_NONE; 00396 } 00397 return JIT_ERR_INVALID_PTR; 00398 } 00399 00400 00401 //could also support mcinfo here in the future 00402 t_jit_err jit_gl_pbo_from_matrix(t_jit_gl_pbo *x, t_jit_matrix_info *minfo, char *bp) 00403 { 00404 GLuint id; 00405 t_jit_err err; 00406 00407 if(!x || !minfo || !bp) 00408 return JIT_ERR_GENERIC; 00409 00410 // delete existing cache if pbo size has changed 00411 if(x->size != minfo->size) 00412 { 00413 00414 //make pbo equivalent to matrix 00415 x->planecount = minfo->planecount; 00416 x->type = minfo->type; 00417 x->offset[0] = 0; 00418 x->offset[1] = 0; 00419 x->dim[0] = minfo->dim[0]; 00420 x->dim[1] = minfo->dim[1]; 00421 00422 err = jit_gl_pbo_create(x); 00423 if(err) return err; 00424 } 00425 00426 // bind the buffer 00427 err = jit_gl_pbo_bind(x); 00428 if(err) return err; 00429 00430 // request buffer handle 00431 x->handle = (char*)glMapBufferARB(x->gltarget, GL_WRITE_ONLY); 00432 if(!x->handle) 00433 { 00434 jit_gl_report_error("jit.gl: error mapping pixel buffer object!"); 00435 jit_object_error((t_object *)x,"jit.gl.pbo: unable to allocate pixel buffer: out of memory!"); 00436 return JIT_ERR_GENERIC; 00437 } 00438 00439 // modify buffer data 00440 jit_copy_bytes(x->handle, bp, x->size); 00441 00442 // release buffer handle 00443 if (!glUnmapBufferARB(x->gltarget)) 00444 { 00445 // handle error 00446 jit_gl_report_error("jit.gl: error unmapping pixel buffer object!"); 00447 jit_object_error((t_object *)x,"jit.gl.pbo: unable to update pixel buffer object"); 00448 return JIT_ERR_GENERIC; 00449 } 00450 00451 // reset current buffer state 00452 err = jit_gl_pbo_unbind(x); 00453 if(err) return err; 00454 00455 return JIT_ERR_NONE; 00456 } 00457 00458 // x->offset and x->dim are taken from an origin at the top left 00459 // of the image, however in OpenGL glReadPixels operations, 00460 // the buffer's origin is bottom left so we have to flip the 00461 // buffer copy about the horizontal (in the Y dimension) 00462 t_jit_err jit_gl_pbo_to_matrix(t_jit_gl_pbo *x, t_jit_matrix_info *minfo, char *bp) 00463 { 00464 t_jit_err err = JIT_ERR_NONE; 00465 char *data, *gl_bp, *mat_bp; 00466 long i, j, k; 00467 long planecount, lo_x, lo_y, hi_x, hi_y; 00468 00469 err = jit_gl_pbo_bind(x); 00470 if(err) return err; 00471 00472 if(x->type != minfo->type) { 00473 jit_object_error((t_object *)x,"jit.gl.pbo: matrix and pbo have different types"); 00474 return JIT_ERR_GENERIC; 00475 } 00476 if(x->planecount != minfo->planecount) { 00477 jit_object_error((t_object *)x,"jit.gl.pbo: matrix and pbo have different planecounts"); 00478 return JIT_ERR_GENERIC; 00479 } 00480 else { 00481 planecount = x->planecount; 00482 } 00483 //check matrix bounds 00484 lo_x = CLAMP(x->offset[0], 0, minfo->dim[0]); 00485 lo_y = CLAMP(x->offset[1], 0, minfo->dim[1]); 00486 00487 hi_x = CLAMP(x->offset[0]+x->dim[0], lo_x, minfo->dim[0]); 00488 hi_y = CLAMP(x->offset[1]+x->dim[1], lo_y, minfo->dim[1]); 00489 00490 jit_gl_report_error("jit.gl.pbo: error before mapping data"); 00491 data = (char *)glMapBuffer(x->gltarget, GL_READ_ONLY); 00492 if(data) 00493 { 00494 for(j = lo_y; j < hi_y; j++) 00495 { 00496 long glidx = j - lo_y; 00497 long matidx = minfo->dim[1] - j-1; //+ (minfo->dim[1] - hi_y - lo_y); 00498 mat_bp = (char *)(bp + matidx*minfo->dimstride[1]); 00499 gl_bp = (char *)(data + glidx*x->dim[0]*x->planecount); 00500 00501 for(i = lo_x; i < hi_x; i++) 00502 { 00503 mat_bp[0] = gl_bp[3]; 00504 mat_bp[1] = gl_bp[2]; 00505 mat_bp[2] = gl_bp[1]; 00506 mat_bp[3] = gl_bp[0]; 00507 00508 mat_bp += 4; 00509 gl_bp += 4; 00510 } 00511 } 00512 } 00513 else { 00514 jit_object_error((t_object *)x,"jit.gl.pbo: data not mapped in copy to matrix"); 00515 } 00516 jit_gl_report_error("jit.gl.pbo: error mapping data"); 00517 00518 if(!glUnmapBuffer(x->gltarget)) { 00519 jit_object_error((t_object *)x,"jit.gl.pbo: error unmapping buffer"); 00520 } 00521 00522 err = jit_gl_pbo_unbind(x); 00523 return err; 00524 } 00525 00526 t_jit_err jit_gl_pbo_dest_changed(t_jit_gl_pbo *x) 00527 { 00528 return JIT_ERR_NONE; 00529 } 00530 00531 t_jit_err jit_gl_pbo_dest_closing(t_jit_gl_pbo *x) 00532 { 00533 jit_gl_pbo_destroy(x); 00534 return JIT_ERR_NONE; 00535 } 00536 00537 //asynchronous read to pbo 00538 t_jit_err jit_gl_pbo_readpixels(t_jit_gl_pbo *x) 00539 { 00540 t_jit_err err = JIT_ERR_NONE; 00541 00542 err = jit_gl_pbo_bind(x); 00543 if(err) return err; 00544 00545 if(x->id > 0) { 00546 //may have to use a different pixel format etc. on windows?? 00547 switch(x->planecount) { 00548 case 4: glReadPixels(x->offset[0], x->offset[1], x->dim[0], x->dim[1], GL_BGRA, x->gltype, 0); break; 00549 case 3: glReadPixels(x->offset[0], x->offset[1], x->dim[0], x->dim[1], GL_BGR, x->gltype, 0); break; 00550 case 2: glReadPixels(x->offset[0], x->offset[1], x->dim[0], x->dim[1], GL_LUMINANCE_ALPHA, x->gltype, 0); break; 00551 case 1: glReadPixels(x->offset[0], x->offset[1], x->dim[0], x->dim[1], GL_LUMINANCE, x->gltype, 0); break; 00552 } 00553 } 00554 00555 err = jit_gl_pbo_unbind(x); 00556 return err; 00557 } 00558 00559 //asynchronous texture read to pbo 00560 t_jit_err jit_gl_pbo_getteximage(t_jit_gl_pbo *x, GLenum tex_target) 00561 { 00562 t_jit_err err = JIT_ERR_NONE; 00563 00564 err = jit_gl_pbo_bind(x); 00565 if(err) return err; 00566 00567 if(x->id > 0) { 00568 //may have to use a different pixel format etc. on windows?? 00569 switch(x->planecount) { 00570 case 4: glGetTexImage(tex_target, 0, GL_RGBA, x->gltype, 0); break; 00571 case 3: glGetTexImage(tex_target, 0, GL_BGR, x->gltype, 0); break; 00572 case 2: glGetTexImage(tex_target, 0, GL_LUMINANCE_ALPHA, x->gltype, 0); break; 00573 case 1: glGetTexImage(tex_target, 0, GL_LUMINANCE, x->gltype, 0); break; 00574 } 00575 } 00576 00577 err = jit_gl_pbo_unbind(x); 00578 return err; 00579 } 00580 00581 t_jit_err jit_gl_pbo_draw(t_jit_gl_pbo *x) 00582 { 00583 t_atom s; 00584 t_jit_err err = JIT_ERR_NONE; 00585 00586 // dummy, does nothing 00587 return err; 00588 } 00589 00590 00591 t_jit_err jit_gl_pbo_bind(t_jit_gl_pbo *x) 00592 { 00593 GLuint id; 00594 00595 if(!x) 00596 return JIT_ERR_INVALID_PTR; 00597 00598 if(x->destroy) jit_gl_pbo_destroy(x); 00599 if(x->recreate || x->id <= 0) jit_gl_pbo_create(x); 00600 00601 // bind the pbo 00602 if(x->id > 0) 00603 { 00604 id = x->id; 00605 glBindBufferARB(x->gltarget, id); 00606 jit_gl_report_error("jit.gl: error binding pixel buffer object!"); 00607 } 00608 return JIT_ERR_NONE; 00609 } 00610 00611 t_jit_err jit_gl_pbo_unbind(t_jit_gl_pbo *x) 00612 { 00613 if(!x) 00614 return JIT_ERR_INVALID_PTR; 00615 00616 glBindBufferARB(x->gltarget, 0); 00617 jit_gl_report_error("jit.gl: error unbinding pixel buffer object!"); 00618 return JIT_ERR_NONE; 00619 } 00620 00621 t_jit_err jit_gl_pbo_destroy(t_jit_gl_pbo *x) 00622 { 00623 GLuint id; 00624 00625 if(!x) 00626 return JIT_ERR_INVALID_PTR; 00627 00628 if(x->id > 0) 00629 { 00630 id = x->id; 00631 jit_gl_pbo_unbind(x); 00632 glDeleteBuffersARB(1, &id); 00633 x->id = -1; 00634 } 00635 00636 x->handle = NULL; 00637 x->size = 0; 00638 x->destroy = FALSE; 00639 00640 return JIT_ERR_NONE; 00641 } 00642 00643 t_jit_err jit_gl_pbo_reset(t_jit_gl_pbo *x) 00644 { 00645 if(!x) 00646 return JIT_ERR_INVALID_PTR; 00647 00648 x->id = -1; 00649 x->handle = NULL; 00650 x->size = 0; 00651 x->planecount = 4; 00652 x->offset[0] = 0; 00653 x->offset[1] = 0; 00654 x->dim[0] = 1; 00655 x->dim[1] = 1; 00656 x->type = _jit_sym_char; 00657 x->gltype = jit_gl_pbo_gltype_from_type(x->type); 00658 x->target = ps_jit_gl_pbo_pixel_pack_buffer; 00659 x->gltarget = jit_gl_pbo_gltarget_from_target(x->target); 00660 x->usage = ps_jit_gl_pbo_stream_draw; 00661 x->glusage = jit_gl_pbo_glusage_from_usage(x->usage); 00662 x->destroy = FALSE; 00663 00664 return JIT_ERR_NONE; 00665 } 00666 /****************************************************************************/
Copyright © 2008, Cycling '74