示例#1
0
文件: pgr.c 项目: jbmulligan/quip
static Data_Obj *make_1394frame_obj(QSP_ARG_DECL  dc1394video_frame_t *framep)
{
	Dimension_Set dimset;
	Data_Obj *dp;
	char fname[32];

	sprintf(fname,"_frame%d",framep->id);

	dimset.ds_dimension[0] = 1;	/* 1 or two depending on video mode (8 or 16) */
	dimset.ds_dimension[1] = framep->size[0];
	dimset.ds_dimension[2] = framep->size[1];
	dimset.ds_dimension[3] = 1;
	dimset.ds_dimension[4] = 1;

	dp = _make_dp(QSP_ARG  fname,&dimset,PREC_FOR_CODE(PREC_UBY));

	/* Do we need to test for a good return value??? */
	/* Only one buffer?  where do we specify the index? BUG */
	SET_OBJ_DATA_PTR(dp, framep->image);
if( verbose )
fprintf(stderr,"Object %s, data ptr set to 0x%lx\n",OBJ_NAME(dp),(long)OBJ_DATA_PTR(dp));

	if( framep->total_bytes != framep->image_bytes ){
		sprintf(DEFAULT_ERROR_STRING,"image may be padded...");
		warn(DEFAULT_ERROR_STRING);
	}

	return(dp);
}
示例#2
0
文件: glmenu.c 项目: nasa/QuIP
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 */
示例#3
0
文件: fbmenu.c 项目: E-LLP/QuIP
static void fb_open(QSP_ARG_DECL const char *fb_name)
{
#ifdef HAVE_FB_DEV

	Dimension_Set dimset;
	FB_Info *fbip;

	long nbytes;

	fbip = new_fbi(QSP_ARG  fb_name);
	if( fbip == NO_FBI ) return;

	fbip->fbi_fd = open(fb_name,O_RDWR);
	if( fbip->fbi_fd < 0 ){
		perror(fb_name);
		sprintf(ERROR_STRING,"couldn't open device %s",fb_name);
		WARN(ERROR_STRING);
		/* BUG? - do we need any more cleanup? */
		del_fbi(QSP_ARG  fbip);
		return;
	}

	if (ioctl(fbip->fbi_fd,FBIOGET_VSCREENINFO, &fbip->fbi_var_info)<0) {
		perror("ioctl error getting variable screeninfo");
		return;
	}	
	/* see if the vbl sync flags are set... */

	if (ioctl(fbip->fbi_fd,FBIOGET_FSCREENINFO, &fbip->fbi_fix_info)<0) {
		perror("ioctl error getting fixed screeninfo");
		return;
	}	

	SET_DS_COMPS(&dimset, fbip->fbi_var_info.bits_per_pixel/8 );
	SET_DS_COLS(&dimset, fbip->fbi_var_info.xres_virtual );
	SET_DS_ROWS(&dimset, fbip->fbi_var_info.yres_virtual );
	SET_DS_FRAMES(&dimset, 1 );
	SET_DS_SEQS(&dimset, 1 );

	fbip->fbi_dp = _make_dp(QSP_ARG  fb_name,&dimset,PREC_FOR_CODE(PREC_UBY));
	if( fbip->fbi_dp == NO_OBJ ){
		sprintf(ERROR_STRING,"Unable to create data object structure for %s",fb_name);
		WARN(ERROR_STRING);
		close(fbip->fbi_fd);
		del_fbi(QSP_ARG  fbip);
		return;
	}

	nbytes = OBJ_ROWS(fbip->fbi_dp) * OBJ_COLS(fbip->fbi_dp)
		* OBJ_COMPS(fbip->fbi_dp);

sprintf(ERROR_STRING,"mapping frame buffer device, %ld (0x%lx) bytes (%ld Mb)",nbytes,nbytes,nbytes/(1024*1024));
advise(ERROR_STRING);

	if( (OBJ_DATA_PTR(fbip->fbi_dp)=mmap(0,nbytes,PROT_READ|PROT_WRITE,MAP_SHARED,fbip->fbi_fd,0)) == MAP_FAILED ){
		perror("mmap /dev/fb");
		close(fbip->fbi_fd);
		fbip->fbi_fd = -1;
		del_fbi(QSP_ARG  fbip);
		return;
	}

	curr_fbip = fbip;
#else /* ! HAVE_FB_DEV */
	WARN("No frame buffer device present at config time!?");
#endif /* ! HAVE_FB_DEV */
}