bool could_have_magic_bool_conversion(Type t) { if (!t.couldBe(TObj)) return false; if (t.strictSubtypeOf(TObj)) { return has_magic_bool_conversion(dobj_of(t).cls); } if (is_opt(t) && unopt(t).strictSubtypeOf(TObj)) { return has_magic_bool_conversion(dobj_of(t).cls); } return true; }
double obj_exists(QSP_ARG_DECL const char *name) { Data_Obj *dp; dp = dobj_of(QSP_ARG name); if( dp==NO_OBJ ) return(0.0); return(1.0); }
folly::Optional<Bytecode> makeAssert(ArgType arg, Type t) { if (t.strictSubtypeOf(TObj)) { auto const dobj = dobj_of(t); auto const op = dobj.type == DObj::Exact ? AssertObjOp::Exact : AssertObjOp::Sub; return Bytecode { ObjBC { arg, dobj.cls.name(), op } }; } if (is_opt(t) && t.strictSubtypeOf(TOptObj)) { auto const dobj = dobj_of(t); auto const op = dobj.type == DObj::Exact ? AssertObjOp::OptExact : AssertObjOp::OptSub; return Bytecode { ObjBC { arg, dobj.cls.name(), op } }; } if (auto const op = assertTOpFor(t)) { return Bytecode { TyBC { arg, *op } }; } return folly::none; }
RepoAuthType make_repo_type(UnitEmitter& ue, const Type& t) { using T = RepoAuthType::Tag; if (t.strictSubtypeOf(TObj) || (is_opt(t) && t.strictSubtypeOf(TOptObj))) { auto const dobj = dobj_of(t); auto const tag = is_opt(t) ? (dobj.type == DObj::Exact ? T::OptExactObj : T::OptSubObj) : (dobj.type == DObj::Exact ? T::ExactObj : T::SubObj); ue.mergeLitstr(dobj.cls.name()); return RepoAuthType { tag, dobj.cls.name() }; } #define ASSERTT_OP(x) if (t.subtypeOf(T##x)) return RepoAuthType{T::x}; ASSERTT_OPS #undef ASSERTT_OP return RepoAuthType{}; }
void newmtrx(QSP_ARG_DECL const char *s,int dim) { Data_Obj *mp; if( dim <= 1 ){ WARN("bad dimension"); return; } mp=dobj_of(QSP_ARG s); if( mp!=(NO_OBJ) ){ WARN("name in use already"); return; } mp=make_obj(QSP_ARG s,1,dim,dim,1,prec_for_code(PREC_SP)); if( mp == NO_OBJ ){ WARN("couldn't create new matrix"); return; } unity(mp); }
static COMMAND_FUNC( do_new_gl_buffer ) { const char *s; Data_Obj *dp; Platform_Device *pdp; Compute_Platform *cdp; dimension_t d,w,h; #ifdef HAVE_OPENGL Dimension_Set ds; int t; #endif // HAVE_OPENGL s = NAMEOF("name for GL buffer object"); cdp = pick_platform("platform"); if( cdp != NULL ) push_pfdev_context(QSP_ARG PF_CONTEXT(cdp) ); pdp = pick_pfdev("device"); if( cdp != NULL ) pop_pfdev_context(SINGLE_QSP_ARG); w = (int)HOW_MANY("width"); h = (int)HOW_MANY("height"); d = (int)HOW_MANY("depth"); /* what should the depth be??? default to 1 for now... */ if( pdp == NULL ) return; /* Make sure this name isn't already in use... */ dp = dobj_of(s); if( dp != NULL ){ sprintf(ERROR_STRING,"Data object name '%s' is already in use, can't use for GL buffer object.",s); warn(ERROR_STRING); return; } #ifdef HAVE_OPENGL // BUG need to be able to set the cuda device. // Note, however, that we don't need GL buffers on the Tesla... //set_data_area(cuda_data_area[0][0]); set_data_area( PFDEV_AREA(pdp,PFDEV_GLOBAL_AREA_INDEX) ); ds.ds_dimension[0]=d; ds.ds_dimension[1]=w; ds.ds_dimension[2]=h; ds.ds_dimension[3]=1; ds.ds_dimension[4]=1; dp = _make_dp(QSP_ARG s,&ds,PREC_FOR_CODE(PREC_UBY)); if( dp == NULL ){ sprintf(ERROR_STRING, "Error creating data_obj header for %s",s); error1(ERROR_STRING); } SET_OBJ_FLAG_BITS(dp, DT_NO_DATA); /* can't free this data */ SET_OBJ_FLAG_BITS(dp, DT_GL_BUF); /* indicate obj is a GL buffer */ SET_OBJ_DATA_PTR(dp, NULL); //fprintf(stderr,"do_new_gl_buffer: allocating gl_info for %s\n",OBJ_NAME(dp)); SET_OBJ_GL_INFO(dp, (GL_Info *) getbuf( sizeof(GL_Info) ) ); //fprintf(stderr,"do_new_gl_buffer: DONE allocating gl_info for %s\n",OBJ_NAME(dp)); glew_check(SINGLE_QSP_ARG); /* without this, we get a segmentation * violation on glGenBuffers??? */ // We need an extra field in which to store the GL identifier... // AND another extra field in which to store the associated texid. // Why is this ifdef here? These don't seem to depend // on libglew??? // Answer: We need libglew to bring in openGL extensions like glBindBuffer... //advise("calling glGenBuffers"); //fprintf(stderr,"OBJ_GL_INFO(%s) = 0x%lx\n",OBJ_NAME(dp),(long)OBJ_GL_INFO(dp)); //fprintf(stderr,"OBJ_BUF_ID_P(%s) = 0x%lx\n",OBJ_NAME(dp),(long)OBJ_BUF_ID_P(dp)); // BUG glGenBuffers seems to require v1.5??? glGenBuffers(1, OBJ_BUF_ID_P(dp) ); // first arg is # buffers to generate? //sprintf(ERROR_STRING,"glGenBuffers gave us buf_id = %d",OBJ_BUF_ID(dp)); //advise(ERROR_STRING); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OBJ_BUF_ID(dp) ); // glBufferData will allocate the memory for the buffer, // but won't copy unless the pointer is non-null // How do we get the gpu memory space address? // That must be with map glBufferData(GL_PIXEL_UNPACK_BUFFER, OBJ_COMPS(dp) * OBJ_COLS(dp) * OBJ_ROWS(dp), NULL, GL_STREAM_DRAW); /* buffer arg set to 0 unbinds any previously bound buffers... * and restores client memory usage. */ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); //#endif // HAVE_LIBGLEW glGenTextures(1, OBJ_TEX_ID_P(dp) ); // makes a texture name fprintf(stderr,"new_gl_buffer: new texture name is 0x%x\n",OBJ_TEX_ID(dp)); glBindTexture(GL_TEXTURE_2D, OBJ_TEX_ID(dp) ); t = gl_pixel_type(dp); glTexImage2D( GL_TEXTURE_2D, 0, // level-of-detail - is this the same as miplevel??? OBJ_COMPS(dp), // internal format, can also be symbolic constant such as // GL_RGBA etc OBJ_COLS(dp), // width - must be 2^n+2 (border) for some n??? OBJ_ROWS(dp), // height - must be 2^m+2 (border) for some m??? 0, // border - must be 0 or 1 t, // format of pixel data GL_UNSIGNED_BYTE, // type of pixel data NULL // pixel data - null pointer means // allocate but do not copy? // - offset into PIXEL_UNPACK_BUFFER?? ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Why was this here? It would seem to un-bind the target??? glBindTexture(GL_TEXTURE_2D, 0); //glFinish(); // necessary or not? //advise("calling platform-specific buffer registration function"); if( (*PF_REGBUF_FN(PFDEV_PLATFORM(pdp)))( QSP_ARG dp ) < 0 ){ WARN("do_new_gl_buffer: Error in platform-specific buffer registration!?"); // BUG? - should clean up here! } // Leave the buffer mapped by default //cutilSafeCall(cudaGLMapBufferObject( &OBJ_DATA_PTR(dp), OBJ_BUF_ID(dp) )); //advise("calling platform-specific buffer mapping function"); if( (*PF_MAPBUF_FN(PFDEV_PLATFORM(pdp)))( QSP_ARG dp ) < 0 ){ WARN("do_new_gl_buffer: Error in platform-specific buffer mapping!?"); // BUG? - should clean up here! } SET_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED); // propagate change to children and parents propagate_flag(dp,DT_BUF_MAPPED); #else // ! HAVE_OPENGL NO_OGL_MSG #endif // ! HAVE_OPENGL } /* end do_new_gl_buffer */
int start_firewire_transmission(QSP_ARG_DECL PGR_Cam * pgcp, int _ring_buffer_size ) { int i; dc1394error_t err; Data_Obj *dp; //advise("start_firewire_transmission BEGIN"); /* older version had third flags arg... */ //advise("calling dc1394_capture_setup"); if( (err=dc1394_capture_setup(pgcp->pc_cam_p,_ring_buffer_size ,DC1394_CAPTURE_FLAGS_DEFAULT )) != DC1394_SUCCESS ) { WARN("dc1394_capture_setup failed!?"); describe_dc1394_error( QSP_ARG err ); if( err == DC1394_IOCTL_FAILURE ){ advise("Try decreasing the number of ring buffer frames requested?"); return -1; } fprintf( stderr,"unable to setup camera-\n" "check line %d of %s to make sure\n" "that the video mode and framerate are\n" "supported by your camera\n", __LINE__,__FILE__ ); /* fprintf( stderr, "video_mode = %d, framerate = %d\n" "Check dc1394_control.h for the meanings of these values\n", pgcp->pc_video_mode, pgcp->pc_framerate ); */ fprintf( stderr, "video_mode = %s (%d), framerate = %s (%d)\n", name_for_video_mode(pgcp->pc_video_mode), pgcp->pc_video_mode, name_for_framerate(pgcp->pc_framerate), pgcp->pc_framerate ); NERROR1("error starting capture"); return(-1); } pgcp->pc_ring_buffer_size = _ring_buffer_size; pgcp->pc_n_avail = _ring_buffer_size; pgcp->pc_flags |= PGR_CAM_IS_CAPTURING; #ifdef FOOBAR // we set this in the script already!? sprintf(msg_str,"%d",ring_buffer_size); /* tell the scripting language */ assign_var("ring_buffer_size",msg_str); #endif // FOOBAR // have the camera start sending us data //advise("calling dc1394_video_set_transmission"); if( (err=dc1394_video_set_transmission( pgcp->pc_cam_p, DC1394_ON )) != DC1394_SUCCESS ) { WARN("Unable to start camera iso transmission"); describe_dc1394_error( QSP_ARG err ); // do we need to undo capture_setup? dc1394_capture_stop( pgcp->pc_cam_p ); pgcp->pc_flags &= ~PGR_CAM_IS_CAPTURING; return(-1); } pgcp->pc_flags |= PGR_CAM_IS_TRANSMITTING; // Sleep untill the camera has a transmission dc1394switch_t status = DC1394_OFF; for ( i = 0; i <= 5; i++ ) { usleep(50000); //advise("calling dc1394_video_get_transmission"); if ( dc1394_video_get_transmission( pgcp->pc_cam_p, &status ) != DC1394_SUCCESS ) { fprintf( stderr, "Unable to get transmision status\n" ); return(-1); } if ( status != DC1394_OFF ) break; if( i == 5 ) { fprintf(stderr,"Camera doesn't seem to want to turn on!\n"); return(-1); } } //advise("start_firewire_transmission DONE"); // Now make sure that we have the frame objects... dp = dobj_of("_frame1"); if( dp == NULL ) init_buffer_objects(QSP_ARG pgcp); return(0); }