void PointSet::Initialize ( int mode, int total )
{
	switch (mode) {
	case BPOINT: {
		FreeBuffers ();
		AddBuffer ( BPOINT, sizeof ( Point ), total );
		AddAttribute ( 0, "pos", sizeof ( Vector3DF ), false );
		AddAttribute ( 0, "color", sizeof ( DWORD ), false );
		AddAttribute ( 0, "type", sizeof ( unsigned short), false );
		Reset ();
		} break;
	
	case BPARTICLE: {
		FreeBuffers ();
		AddBuffer ( BPARTICLE, sizeof ( Particle ), total );
		AddAttribute ( 0, "pos", sizeof ( Vector3DF ), false );	
		AddAttribute ( 0, "color", sizeof ( DWORD ), false );
		AddAttribute ( 0, "vel", sizeof ( Vector3DF ), false );
		AddAttribute ( 0, "ndx", sizeof ( unsigned short ), false );
		AddAttribute ( 0, "age", sizeof ( unsigned short ), false );
		AddAttribute ( 0, "type", sizeof ( unsigned short), false );
		Reset ();
		} break;
	}


}
/// <summary>
/// Initializes each of the frame buffers to the given image size.
/// </summary>
/// <param name="cImageSize">Number of pixels to allocate in each frame buffer.</param>
HRESULT KinectFusionProcessorFrame::Initialize(int cImageSize)
{
    HRESULT hr = S_OK;

    ZeroMemory(m_statusMessage, sizeof(m_statusMessage));

    ULONG cbImageSize = cImageSize * KinectFusionParams::BytesPerPixel;

    if (m_cbImageSize != cbImageSize)
    {
        FreeBuffers();

        m_cbImageSize = cbImageSize;
        m_pReconstructionRGBX = new(std::nothrow) BYTE[m_cbImageSize];
        m_pDepthRGBX = new(std::nothrow) BYTE[m_cbImageSize];
        m_pTrackingDataRGBX = new(std::nothrow) BYTE[m_cbImageSize];

        if (nullptr != m_pReconstructionRGBX ||
            nullptr != m_pDepthRGBX ||
            nullptr != m_pTrackingDataRGBX)
        {
            ZeroMemory(m_pReconstructionRGBX, m_cbImageSize);
            ZeroMemory(m_pDepthRGBX, m_cbImageSize);
            ZeroMemory(m_pTrackingDataRGBX, m_cbImageSize);
        }
        else
        {
            FreeBuffers();
            hr = E_OUTOFMEMORY;
        }
    }

    return hr;
}
示例#3
0
void MeshActor::ShadowPass()
{
	// Compute the MVP matrix from the light's point of view
	glm::mat4 depthProjectionMatrix = glm::ortho<float>(-25, 25, -25, 25, -25, 25);
	glm::mat4 depthViewMatrix = glm::lookAt(scene->light, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
	glm::mat4 depthModelMatrix = GetModelMatrix();
	glm::mat4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;

	// compute depthbiasMVP for actual shading step later
	depthBiasMVP = biasMatrix*depthMVP;

	if (!castsShadow) return;	//hop off here if we don't want this to cast shadows

	glUseProgram(shadowProgram);

	// set MVP in shadow shader
	GLint depthMatrixID = glGetUniformLocation(shadowProgram, "depthMVP");
	if (depthMatrixID != -1)
	{
		glUniformMatrix4fv(depthMatrixID, 1, GL_FALSE, &depthMVP[0][0]);
	}

	FreeBuffers();

	glBindVertexArray(vao);

	// set element buffer with face indices
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
	glBufferData(
		GL_ELEMENT_ARRAY_BUFFER,
		mesh.mFaces.size() * sizeof(glm::ivec3),
		mesh.mFaces.data(),
		GL_STATIC_DRAW
		);

	// set array buffer with vertex positions
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
	glBufferData(
		GL_ARRAY_BUFFER,
		mesh.mVertices.size() * sizeof(glm::vec3),
		mesh.mVertices.data(),
		GL_STATIC_DRAW
		);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

	// draw by index
	glDrawElements(
		GL_TRIANGLES,
		mesh.mFaces.size() * 3,
		GL_UNSIGNED_INT,
		NULL
	);

	glDisableVertexAttribArray(0);

	FreeBuffers();
}
示例#4
0
void MeshActor::Render()
{
	glUseProgram(shaderProgram);
	FreeBuffers();
	SetUniforms();
	SetBufferData();
	DrawBuffers();
	CleanUp();
	FreeBuffers();
}
示例#5
0
void GeomX::CopyBuffers ( GeomX& src )
{
	FreeBuffers ();
	for (int n = 0; n < src.GetNumBuf(); n++)
		CopyBuffer ( n, n, src );
	CopyHeap ( src );
}
StVKReducedHessianTensor::~StVKReducedHessianTensor()
{
  if (!shallowCopy)
  {
    free(freeCoef_);
    free(linearCoef_);
  }
  FreeBuffers();
}
示例#7
0
//
// AllocBuffers
//
void DoubleBuffer::AllocBuffers()
{
    FreeBuffers();

    for (int i = 0; i < BUFFERS; i++) {
        m_Buffers[i].lpData = new CHAR[CHUNKSIZE];
        m_Buffers[i].dwBufferLength = m_Buffers[i].dwBytesRecorded = CHUNKSIZE;
    }
}
CTXVirtQueue::~CTXVirtQueue()
{
    if(m_SGTable != nullptr)
    {
        NdisFreeMemory(m_SGTable, 0, 0);
    }

    FreeBuffers();
}
示例#9
0
DART::~DART ()
{
  if (DeviceId)
  {
    Stop ();
    FreeBuffers ();
    Close ();
  } /* endif */
}
示例#10
0
SDLAudio::~SDLAudio(void)
{
	// TODO
	delete ambim;
	Mix_HookMusic(NULL, NULL);
	FreeBuffers();
	SDL_DestroyMutex(OurMutex);
	Mix_ChannelFinished(NULL);
}
StVKReducedStiffnessMatrix::~StVKReducedStiffnessMatrix()
{
  if (!shallowCopy)
  {
    free(freeCoef_);
    free(linearCoef_);
    free(quadraticCoef_);
  }
  FreeBuffers();
}
void ReInitCPU(const int reallocBuffers) {
	// Check if I have to reallocate buffers
	if (reallocBuffers) {
		FreeBuffers();
		AllocateBuffers();
	}

	UpdateCamera();
	currentSample = 0;
	UpdateRenderingCPU();
}
示例#13
0
/**************************************************************************************
 * Function:    AACFreeDecoder
 *
 * Description: free platform-specific data allocated by AACInitDecoder
 *              free SBR decoder if enabled
 *
 * Inputs:      valid AAC decoder instance pointer (HAACDecoder)
 *
 * Outputs:     none
 *
 * Return:      none
 **************************************************************************************/
void AACFreeDecoder(HAACDecoder hAACDecoder)
{
	AACDecInfo *aacDecInfo = (AACDecInfo *)hAACDecoder;

	if (!aacDecInfo)
		return;

#ifdef AAC_ENABLE_SBR
	FreeSBR(aacDecInfo);
#endif
	FreeBuffers(aacDecInfo);
}
示例#14
0
/*************
 * DESCRIPTION:   free mem and iff-handle
 * INPUT:         data     handler data
 * OUTPUT:        none
 *************/
static void readLWOB_cleanup(HANDLER_DATA *data)
{
	FreeBuffers(data);

	if(data->iff)
	{
		CloseIFF(data->iff);
		if(data->iff->iff_Stream)
			Close(data->iff->iff_Stream);
		FreeIFF(data->iff);
		data->iff = NULL;
	}
}
示例#15
0
void DeInit()
{
	// Free the sprite we created
	FreeSprite(&gMonster);

	// Free the background image
	DeleteObject(hBackground);

	// Free the back buffer
	FreeBuffers(&gBuffer);

	// Post the QUIT message to the window (0 = WM_QUIT)															
	PostQuitMessage(0);				
}
StVKReducedInternalForces::~StVKReducedInternalForces()
{
  if (!shallowCopy)
  {
    free(unitReducedGravityForce);
    free(reducedGravityForce);
    free(linearCoef_);
    free(quadraticCoef_);
    free(cubicCoef_);
    free(lambdaLame);
    free(muLame);
  }
  FreeBuffers();
}
示例#17
0
文件: buffers.c 项目: ADTL/ARMWork
/**************************************************************************************
 * Function:    AllocateBuffers
 *
 * Description: allocate all the memory needed for the MP3 decoder
 *
 * Inputs:      none
 *
 * Outputs:     none
 *
 * Return:      pointer to MP3DecInfo structure (initialized with pointers to all 
 *                the internal buffers needed for decoding, all other members of 
 *                MP3DecInfo structure set to 0)
 *
 * Notes:       if one or more mallocs fail, function frees any buffers already
 *                allocated before returning
 **************************************************************************************/
MP3DecInfo *AllocateBuffers(void)
{
	MP3DecInfo *mp3DecInfo;
	FrameHeader *fh;
	SideInfo *si;
	ScaleFactorInfo *sfi;
	HuffmanInfo *hi;
	DequantInfo *di;
	IMDCTInfo *mi;
	SubbandInfo *sbi;

	mp3DecInfo = (MP3DecInfo *)malloc(sizeof(MP3DecInfo));
	if (!mp3DecInfo)
		return 0;
	ClearBuffer(mp3DecInfo, sizeof(MP3DecInfo));
	
	fh =  (FrameHeader *)     malloc(sizeof(FrameHeader));
	si =  (SideInfo *)        malloc(sizeof(SideInfo));
	sfi = (ScaleFactorInfo *) malloc(sizeof(ScaleFactorInfo));
	hi =  (HuffmanInfo *)     malloc(sizeof(HuffmanInfo));
	di =  (DequantInfo *)     malloc(sizeof(DequantInfo));
	mi =  (IMDCTInfo *)       malloc(sizeof(IMDCTInfo));
	sbi = (SubbandInfo *)     malloc(sizeof(SubbandInfo));

	mp3DecInfo->FrameHeaderPS =     (void *)fh;
	mp3DecInfo->SideInfoPS =        (void *)si;
	mp3DecInfo->ScaleFactorInfoPS = (void *)sfi;
	mp3DecInfo->HuffmanInfoPS =     (void *)hi;
	mp3DecInfo->DequantInfoPS =     (void *)di;
	mp3DecInfo->IMDCTInfoPS =       (void *)mi;
	mp3DecInfo->SubbandInfoPS =     (void *)sbi;

	if (!fh || !si || !sfi || !hi || !di || !mi || !sbi) {
		FreeBuffers(mp3DecInfo);	/* safe to call - only frees memory that was successfully allocated */
		return 0;
	}

	/* important to do this - DSP primitives assume a bunch of state variables are 0 on first use */
	ClearBuffer(fh,  sizeof(FrameHeader));
	ClearBuffer(si,  sizeof(SideInfo));
	ClearBuffer(sfi, sizeof(ScaleFactorInfo));
	ClearBuffer(hi,  sizeof(HuffmanInfo));
	ClearBuffer(di,  sizeof(DequantInfo));
	ClearBuffer(mi,  sizeof(IMDCTInfo));
	ClearBuffer(sbi, sizeof(SubbandInfo));

	return mp3DecInfo;
}
示例#18
0
bool SDLAudio::ReleaseStream(int stream, bool HardStop)
{
	if (stream != 0) {
		return false;
	}

	print("SDLAudio releasing stream\n");

	(void)HardStop;

	assert(!MusicPlaying);

	Mix_HookMusic(NULL, NULL);
	FreeBuffers();

	return true;
}
示例#19
0
ImageServer::~ImageServer()
{
	LOG( "-------------------- Shutdown() --------------------" );

	// Make sure any outstanding glReadPixels to the PBO on the image server
	// has actually completed.
	glFinish();

	if ( serverThread )
	{
		pthread_mutex_lock( &StartStopMutex );

		// write to the socket to signal shutdown
		char	data;
		write( ShutdownSocket, &data, 1 );

		// also fire the condition, in case it was waiting
		// on TimeWarp to signal completion
		ImageServerResponse	badResponse;
		badResponse.Data = NULL;
		badResponse.Resolution = -1;
		badResponse.Sequence = -1;
		Response.SetState( badResponse );
		pthread_cond_signal( &ResponseCondition );

		LOG( "Waiting on StartStopCondition." );

		pthread_cond_wait( &StartStopCondition, &StartStopMutex );
		pthread_mutex_unlock( &StartStopMutex );

		LOG( "Thread stop acknowledged." );
	}

	// free GL tools
	if ( UnitSquare.vertexArrayObject )
	{
		UnitSquare.Free();
	}
	if ( ResampleProg.program )
	{
		DeleteProgram( ResampleProg );
	}
	FreeBuffers();
	LOG( "-------------------- Shutdown completed --------------------" );
}
示例#20
0
CBuffer::~CBuffer()
{
    // We need to make sure if we used a pen or brush the original
    // pen and brushes are restored so there isn't a memory leak.
    if(oldPen)
    {
        HPEN setPen = (HPEN)SelectObject(hdcBack, oldPen);
        DeleteObject(setPen);
    }

    if(oldBrush)
    {
        HBRUSH setBrush = (HBRUSH)SelectObject(hdcBack, oldBrush);
        DeleteObject(setBrush);
    }

    // Free our back buffer information
    FreeBuffers();
}
void FluidSystem::Initialize ( int mode, int total )
{
	if ( mode != BFLUID ) {
		printf ( "ERROR: FluidSystem not initialized as BFLUID.\n");
	}
	PointSet::Initialize ( mode, total );
	
	FreeBuffers ();
	AddBuffer ( BFLUID, sizeof ( Fluid ), total );
	AddAttribute ( 0, "pos", sizeof ( Vector3DF ), false );	
	AddAttribute ( 0, "color", sizeof ( DWORD ), false );
	AddAttribute ( 0, "vel", sizeof ( Vector3DF ), false );
	AddAttribute ( 0, "ndx", sizeof ( unsigned short ), false );
	AddAttribute ( 0, "age", sizeof ( unsigned short ), false );

	AddAttribute ( 0, "pressure", sizeof ( double ), false );
	AddAttribute ( 0, "density", sizeof ( double ), false );
	AddAttribute ( 0, "sph_force", sizeof ( Vector3DF ), false );
	AddAttribute ( 0, "next", sizeof ( Fluid* ), false );
	AddAttribute ( 0, "tag", sizeof ( bool ), false );		
		
	SPH_Setup ();
	Reset ( total );	
}
示例#22
0
Halftoner::~Halftoner()
{
    DBG1("destroying Halftoner \n");

    FreeBuffers();

    for (int i=0; i < MAXCOLORPLANES; i++)
    {
        for (int j=0; j < NumRows[i]; j++)
        {
            for (int k=0; k < ColorDepth[i]; k++)
            {
                if (ColorPlane[i][j][k])
                {
                    pSS->FreeMemory(ColorPlane[i][j][k]);
                }
            }
        }
    }
	if (originalKData)
	{
		pSS->FreeMemory(originalKData);
	}
} //~Halftoner
示例#23
0
	virtual ~OpenCLBVHKernel() { FreeBuffers(); }
示例#24
0
//
// Destructor
//
DoubleBuffer::~DoubleBuffer()
{
    FreeBuffers();
}
示例#25
0
/*************
 * DESCRIPTION:   read the polygons
 * INPUT:         data     handler data
 *                cn       iff context node
 *                actor    actor
 * OUTPUT:        error string
 *************/
static char *ReadPolygons(HANDLER_DATA *data, struct ContextNode *cn, ACTOR *actor)
{
	ULONG count, edgecount, i,j,k,l;
	WORD *polybuffer = NULL, *p;
	LINK_EDGE *edges;
	LINK_MESH *faces;
	OBJECT *obj;
	VECTOR ox,oy,oz, axis_pos,axis_size;
	SURF_DATA *cursurf;

	SetVector(&axis_pos, 0.f, 0.f, 0.f);
	SetVector(&ox, 1.f, 0.f, 0.f);
	SetVector(&oy, 0.f, 1.f, 0.f);
	SetVector(&oz, 0.f, 0.f, 1.f);
	SetVector(&axis_size, 1.f, 1.f, 1.f);

	// Allocate Memory for whole chunk (the last word is the surface index for this polygon)
	count = cn->cn_Size/2 - 1;
	polybuffer = ALLOCMEM(WORD, count);
	if (!polybuffer)
		return errors[ERR_MEM];

	// Read polygons
	if(!ReadWord(data->iff, polybuffer, count))
	{
		FREEMEM(polybuffer);
		return errors[ERR_LWOBFILE];
	}

	// go through buffer and look how many edges and faces we need
	i = 0;
	while(i < count)
	{
		cursurf = &data->surfaces[abs(polybuffer[i+polybuffer[i]+1])-1];
		switch(polybuffer[i])
		{
			case 1:
			case 2:
				break;
			case 3:  // triangle
				cursurf->facecount++;
				cursurf->edgecount += 3;
				break;
			case 4:  //rectangle
				cursurf->facecount += 2;
				cursurf->edgecount += 5;
				break;
			default: // polygon
				cursurf->facecount += polybuffer[i] - 2;
				cursurf->edgecount += (polybuffer[i] - 2) * 2 + 1;
				break;
		}
		p = &polybuffer[i+1];
		for(j=0; j<polybuffer[i]; j++)
		{
			if(cursurf->nobound)
			{
				cursurf->lowbound = cursurf->highbound = data->points[*p];
				cursurf->nobound = FALSE;
			}
			else
			{
				if(data->points[*p].x < cursurf->lowbound.x)
					cursurf->lowbound.x = data->points[*p].x;
				if(data->points[*p].y < cursurf->lowbound.y)
					cursurf->lowbound.y = data->points[*p].y;
				if(data->points[*p].z < cursurf->lowbound.z)
					cursurf->lowbound.z = data->points[*p].z;

				if(data->points[*p].x > cursurf->highbound.x)
					cursurf->highbound.x = data->points[*p].x;
				if(data->points[*p].y > cursurf->highbound.y)
					cursurf->highbound.y = data->points[*p].y;
				if(data->points[*p].z > cursurf->highbound.z)
					cursurf->highbound.z = data->points[*p].z;
			}
			p++;
		}
		i += polybuffer[i] + 1;
		// if surface number < 0 then get detail polygons
		if (polybuffer[i] < 0)
		{
			// jump over amount of detail polygons
			i++;
		}
		i++;
	}

	// for each surface go through the polygons and create a single object
	for(j=0; j<data->surfcount; j++)
	{
		data->link->ObjectBegin(data->rc);
		cursurf = &data->surfaces[j];
		if(cursurf->edgecount && cursurf->facecount)
		{
			// Allocate memory for edges
			edges = ALLOCMEM(LINK_EDGE, cursurf->edgecount);
			if (!edges)
			{
				FREEMEM(polybuffer);
				FreeBuffers(data);
				return errors[ERR_MEM];
			}
			// Allocate memory for faces
			faces = ALLOCMEM(LINK_MESH, cursurf->facecount);
			if (!faces)
			{
				FREEMEM(edges);
				FREEMEM(polybuffer);
				FreeBuffers(data);
				return errors[ERR_MEM];
			}

			// and again, go through buffer and now create edges, create only
			// one edge between two points
			i = 0;
			k = 0;   // current face
			edgecount = 0;
			while(i < count)
			{
				if(j == (ULONG)abs(polybuffer[i+polybuffer[i]+1])-1)
				{
					switch(polybuffer[i])
					{
						case 1:
						case 2:
							break;
						case 3:  // triangle
							// search for edge, and create one if no found
							FindEdges(&faces[k], &edgecount, polybuffer[i+1], polybuffer[i+2], polybuffer[i+3], edges);
							k++;
							break;
						case 4:  // rectangle
							// split rectangle in two triangles
							// search for edge, and create one if no found
							FindEdges(&faces[k], &edgecount, polybuffer[i+1], polybuffer[i+2], polybuffer[i+3], edges);
							k++;

							FindEdges(&faces[k], &edgecount, polybuffer[i+3], polybuffer[i+4], polybuffer[i+1], edges);
							k++;
							break;
						default: // polygon
							for(l = 0; l < (ULONG)polybuffer[i]-2; l++)
							{
								FindEdges(&faces[k], &edgecount, polybuffer[i+1], polybuffer[i+l+2], polybuffer[i+l+3], edges);
								k++;
							}
							break;
					}
				}

				i += polybuffer[i] + 1;
				// if surface number < 0 then get detail polygons
				if (polybuffer[i] < 0)
				{
					// jump over amount of detail polygons
					i++;
				}
				i++;
			}

			if(data->link->type == LINK_SCENARIO)
			{
				SetVector(&axis_pos,
					(cursurf->lowbound.x + cursurf->highbound.x) * .5f,
					(cursurf->lowbound.y + cursurf->highbound.y) * .5f,
					(cursurf->lowbound.z + cursurf->highbound.z) * .5f);
				SetVector(&axis_size,
					(cursurf->highbound.x - cursurf->lowbound.x) * .5f,
					(cursurf->highbound.y - cursurf->lowbound.y) * .5f,
					(cursurf->highbound.z - cursurf->lowbound.z) * .5f);

				obj = data->link->MeshCreate(data->rc);
				if(!obj)
					return errors[ERR_MEM];

				if((cursurf->object_count & 0xF) == 0)
				{
					OBJECT **objects;

					objects = new OBJECT*[cursurf->object_count+16];
					if(!objects)
						return errors[ERR_MEM];

					if(cursurf->object_count)
						memcpy(objects, cursurf->objects, cursurf->object_count*sizeof(OBJECT*));

					if(cursurf->objects)
						delete cursurf->objects;

					cursurf->objects = objects;
				}

				cursurf->objects[cursurf->object_count] = obj;
				cursurf->object_count++;

				data->link->ObjectAxis(data->rc, obj, &axis_pos, &ox,&oy,&oz, &axis_size);
				if(cursurf->name)
					data->link->ObjectName(data->rc, obj, cursurf->name);

				if(!data->link->MeshAddScenario(data->rc, obj,
					data->points, data->pointcount,
					edges, cursurf->edgecount,
					faces, cursurf->facecount,
					&data->size,
					FALSE))
				{
					FREEMEM(edges);
					FREEMEM(faces);
					FREEMEM(polybuffer);
					return errors[ERR_MEM];
				}
				data->link->ObjectSurface(data->rc, obj, cursurf->surface);
			}
			else
			{
				if(!data->link->MeshAddRenderer(data->rc, cursurf->surface, NULL, actor,
					data->points, data->pointcount,
					edges, cursurf->edgecount,
					faces, cursurf->facecount,
					&data->pos, &data->ox, &data->oy, &data->oz, &data->size,
					FALSE))
				{
					FREEMEM(edges);
					FREEMEM(faces);
					FREEMEM(polybuffer);
					return errors[ERR_MEM];
				}
			}
			FREEMEM(edges);
			FREEMEM(faces);
		}
		else
		{
			if(data->link->type == LINK_SCENARIO)
			{
				// Scenario needs even empty meshes to create the axis
				obj = data->link->MeshCreate(data->rc);
				if(!obj)
					return errors[ERR_MEM];

				data->link->ObjectAxis(data->rc, obj, &axis_pos, &ox,&oy,&oz, &axis_size);
				if(cursurf->name)
					data->link->ObjectName(data->rc, obj, cursurf->name);
				data->link->ObjectSurface(data->rc, obj, cursurf->surface);
			}
		}
		data->link->ObjectEnd(data->rc);
		if(data->SetProgress)
			data->SetProgress(data->rc, ((float)data->size_done + (float)(cn->cn_Size*j)/(float)data->surfcount)/(float)data->filesize);
	}

	// free polygonbuffer
	if(polybuffer)
		FREEMEM(polybuffer);

	return NULL;
}
示例#26
0
bool VideoCodec::SetupBuffers(zmbv_format_t _format, int blockwidth, int blockheight) {
	FreeBuffers();
	palsize = 0;
	switch (_format) {
	case ZMBV_FORMAT_8BPP:
		pixelsize = 1;
		palsize = 256;
		break;
	case ZMBV_FORMAT_15BPP:
		pixelsize = 2;
		break;
	case ZMBV_FORMAT_16BPP:
		pixelsize = 2;
		break;
	case ZMBV_FORMAT_32BPP:
		pixelsize = 4;
		break;
	default:
		return false;
	};
	bufsize = (height+2*MAX_VECTOR)*pitch*pixelsize+2048;

	buf1 = new unsigned char[bufsize];
	buf2 = new unsigned char[bufsize];
	work = new unsigned char[bufsize];

	int xblocks = (width/blockwidth);
	int xleft = width % blockwidth;
	if (xleft) xblocks++;
	int yblocks = (height/blockheight);
	int yleft = height % blockheight;
	if (yleft) yblocks++;
	blockcount=yblocks*xblocks;
	blocks=new FrameBlock[blockcount];

	if (!buf1 || !buf2 || !work || !blocks) {
		FreeBuffers();
		return false;
	}
	int y,x,i;
	i=0;
	for (y=0;y<yblocks;y++) {
		for (x=0;x<xblocks;x++) {
			blocks[i].start=((y*blockheight)+MAX_VECTOR)*pitch+
				(x*blockwidth)+MAX_VECTOR;
			if (xleft && x==(xblocks-1)) {
                blocks[i].dx=xleft;
			} else {
				blocks[i].dx=blockwidth;
			}
			if (yleft && y==(yblocks-1)) {
                blocks[i].dy=yleft;
			} else {
				blocks[i].dy=blockheight;
			}
			i++;
		}
	}

	memset(buf1,0,bufsize);
	memset(buf2,0,bufsize);
	memset(work,0,bufsize);
	oldframe=buf1;
	newframe=buf2;
	format = _format;
	return true;
}
/// <summary>
/// Destructor.
/// </summary>
KinectFusionProcessorFrame::~KinectFusionProcessorFrame()
{
    ZeroMemory(m_statusMessage, sizeof(m_statusMessage));
    FreeBuffers();
}
示例#28
0
// Called by TimeWarp before adding the KHR sync object.
void	ImageServer::EnterWarpSwap( int eyeTexture )
{
	ImageServerRequest	request = Request.GetState();
	if ( request.Sequence <= SequenceCaptured )
	{
		return;
	}
	SequenceCaptured = request.Sequence;

	// create GL objects if necessary
	if ( !ResampleProg.program )
	{
		ResampleProg = BuildProgram(
			"uniform highp mat4 Mvpm;\n"
			"attribute vec4 Position;\n"
			"attribute vec2 TexCoord;\n"
			"varying  highp vec2 oTexCoord;\n"
			"void main()\n"
			"{\n"
			"   gl_Position = Position;\n"
			"   oTexCoord = vec2( TexCoord.x, 1.0 - TexCoord.y );\n"	// need to flip Y
			"}\n"
		,
			"uniform sampler2D Texture0;\n"
			"varying highp vec2 oTexCoord;\n"
			"void main()\n"
			"{\n"
			"	gl_FragColor = texture2D( Texture0, oTexCoord );\n"
			"}\n"
		);
	}

	if ( !UnitSquare.vertexArrayObject )
	{
		UnitSquare = BuildTesselatedQuad( 1, 1 );
	}

	// If resolution has changed, delete and reallocate the buffers
	// These might still be in use, do we trust the driver or try to
	// deal with it ourselves?
	if ( request.Resolution != CurrentResolution )
	{
		CurrentResolution = request.Resolution;
		FreeBuffers();
	}

	// Allocate any resources we need
	if ( !ResampleRenderBuffer )
	{
		LOG( "Alloc %i res renderbuffer", CurrentResolution );
		glGenRenderbuffers( 1, &ResampleRenderBuffer );
		glBindRenderbuffer( GL_RENDERBUFFER, ResampleRenderBuffer );
		glRenderbufferStorage( GL_RENDERBUFFER, GL_RGB565, CurrentResolution, CurrentResolution );
	}

	if ( !FrameBufferObject )
	{
		LOG( "Alloc FrameBufferObject" );
		glGenFramebuffers( 1, &FrameBufferObject );
		glBindFramebuffer( GL_FRAMEBUFFER, FrameBufferObject );
		glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				GL_RENDERBUFFER, ResampleRenderBuffer );
		const GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
		if (status != GL_FRAMEBUFFER_COMPLETE )
		{
			LOG( "FBO is not complete: 0x%x", status );
		}
	}

	if ( !PixelBufferObject )
	{
		LOG( "Alloc PixelBufferObject" );
		glGenBuffers( 1, &PixelBufferObject );
		glBindBuffer( GL_PIXEL_PACK_BUFFER, PixelBufferObject );
		glBufferData( GL_PIXEL_PACK_BUFFER, CurrentResolution*CurrentResolution*2, NULL,
                GL_DYNAMIC_READ );
		glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
	}

	// Render the FBO
	glBindFramebuffer( GL_FRAMEBUFFER, FrameBufferObject );
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_SCISSOR_TEST );
	GL_InvalidateFramebuffer( INV_FBO, true, false );
	glViewport( 0, 0, CurrentResolution, CurrentResolution );
	glActiveTexture( GL_TEXTURE0 );
	glBindTexture( GL_TEXTURE_2D, eyeTexture );
	glUseProgram( ResampleProg.program );
	UnitSquare.Draw();
	glUseProgram( 0 );

	// unmap the previous PBO mapping
	if ( PboMappedAddress )
	{
		glBindBuffer( GL_PIXEL_PACK_BUFFER, PixelBufferObject );
		glUnmapBuffer_( GL_PIXEL_PACK_BUFFER );
		glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
		PboMappedAddress = NULL;
	}

	// Issue an async read into our PBO
#if 1

	glBindBuffer( GL_PIXEL_PACK_BUFFER, PixelBufferObject );
	glReadPixels( 0, 0, CurrentResolution, CurrentResolution, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0 );
	// back to normal memory read operations
	glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );

#else
	GL_CheckErrors( "before read" );

	static short	pixels[256*256];
	glReadPixels( 0, 0, CurrentResolution, CurrentResolution, GL_RGB,
			GL_UNSIGNED_SHORT_5_6_5, (GLvoid *)pixels );
	ImageServerResponse	response;
	response.Data = (void *)pixels;
	response.Resolution = CurrentResolution;
	response.Sequence = request.Sequence;
	Response.SetState( response );
#endif
	glBindFramebuffer( GL_FRAMEBUFFER, 0 );

	GL_CheckErrors( "after read" );

	CountdownToSend = 2;
}
示例#29
0
/**************************************************************************************
 * Function:    AllocateBuffers
 *
 * Description: allocate all the memory needed for the MP3 decoder
 *
 * Inputs:      none
 *
 * Outputs:     none
 *
 * Return:      pointer to MP3DecInfo structure (initialized with pointers to all 
 *                the internal buffers needed for decoding, all other members of 
 *                MP3DecInfo structure set to 0)
 *
 * Notes:       if one or more mallocs fail, function frees any buffers already
 *                allocated before returning
 *
 *              Changed by Kasper Jepsen to support static buffers as well.
 *
 **************************************************************************************/
MP3DecInfo *AllocateBuffers(void)
{
  MP3DecInfo *mp3DecInfo_pointer;
  #ifdef static_buffers
  mp3DecInfo_pointer = (MP3DecInfo*)&mp3DecInfo;
  ClearBuffer((void*)&mp3DecInfo, sizeof(MP3DecInfo));

	mp3DecInfo.FrameHeaderPS =     (void*)&fh;
	mp3DecInfo.SideInfoPS =        (void*)&si;
	mp3DecInfo.ScaleFactorInfoPS = (void*)&sfi;
	mp3DecInfo.HuffmanInfoPS =     (void*)&hi;
	mp3DecInfo.DequantInfoPS =     (void*)&di;
	mp3DecInfo.IMDCTInfoPS =       (void*)&mi;
	mp3DecInfo.SubbandInfoPS =     (void*)&sbi;

	/* important to do this - DSP primitives assume a bunch of state variables are 0 on first use */
  ClearBuffer((void*)&fh,  sizeof(FrameHeader));
	ClearBuffer((void*)&si,  sizeof(SideInfo));
	ClearBuffer((void*)&sfi, sizeof(ScaleFactorInfo));
	ClearBuffer((void*)&hi,  sizeof(HuffmanInfo));
	ClearBuffer((void*)&di,  sizeof(DequantInfo));
	ClearBuffer((void*)&mi,  sizeof(IMDCTInfo));
	ClearBuffer((void*)&sbi, sizeof(SubbandInfo));
   // return mp3DecInfo_pointer;

  #else
	FrameHeader *fh;
	SideInfo *si;
	ScaleFactorInfo *sfi;
	HuffmanInfo *hi;
	DequantInfo *di;
	IMDCTInfo *mi;
	SubbandInfo *sbi;

	mp3DecInfo_pointer = (MP3DecInfo *)malloc(sizeof(MP3DecInfo));
	if (!mp3DecInfo_pointer)
		return 0;
	ClearBuffer(mp3DecInfo_pointer, sizeof(MP3DecInfo));
	
	fh =  (FrameHeader *)     malloc(sizeof(FrameHeader));
	si =  (SideInfo *)        malloc(sizeof(SideInfo));
	sfi = (ScaleFactorInfo *) malloc(sizeof(ScaleFactorInfo));
	hi =  (HuffmanInfo *)     malloc(sizeof(HuffmanInfo));
	di =  (DequantInfo *)     malloc(sizeof(DequantInfo));
	mi =  (IMDCTInfo *)       malloc(sizeof(IMDCTInfo));
	sbi = (SubbandInfo *)     malloc(sizeof(SubbandInfo));

	mp3DecInfo_pointer->FrameHeaderPS =     (void *)fh;
	mp3DecInfo_pointer->SideInfoPS =        (void *)si;
	mp3DecInfo_pointer->ScaleFactorInfoPS = (void *)sfi;
	mp3DecInfo_pointer->HuffmanInfoPS =     (void *)hi;
	mp3DecInfo_pointer->DequantInfoPS =     (void *)di;
	mp3DecInfo_pointer->IMDCTInfoPS =       (void *)mi;
	mp3DecInfo_pointer->SubbandInfoPS =     (void *)sbi;

	if (!fh || !si || !sfi || !hi || !di || !mi || !sbi) {
		FreeBuffers(mp3DecInfo_pointer);	/* safe to call - only frees memory that was successfully allocated */
		return 0;
	}

	/* important to do this - DSP primitives assume a bunch of state variables are 0 on first use */
	//Optimized away.. hmm
    ClearBuffer(fh,  sizeof(FrameHeader));
	ClearBuffer(si,  sizeof(SideInfo));
	ClearBuffer(sfi, sizeof(ScaleFactorInfo));
	ClearBuffer(hi,  sizeof(HuffmanInfo));
	ClearBuffer(di,  sizeof(DequantInfo));
	ClearBuffer(mi,  sizeof(IMDCTInfo));
	ClearBuffer(sbi, sizeof(SubbandInfo));

#endif
	return mp3DecInfo_pointer;
}
示例#30
0
void PointSet::uninitialize()
{
	FreeBuffers ();
}