Esempio n. 1
0
void mesh_copy(struct mesh *to, const struct mesh *from)
{
	int i;

	DEBUG(2, "Copying mesh at %p (%d verts, %d faces) to %p\n"
		, from, from->nverts, from->nfaces, to);
	if (to->nverts || to->nfaces)
		mesh_clear(to);
	mesh_addverts(to, from->verts, from->nverts);
	REALLOC(to->faces, from->nfaces);
	for (i=0; i < from->nfaces; i++)
	{
		int nverts = from->faces[i].nverts;
		if (nverts <= 0)
		{
			luaL_error(L1, "face %d (%p) has %d vertices",
				i, &from->faces[i], nverts
			);
			continue;
		}
		to->faces[i].nverts = nverts;
		to->faces[i].verts = NULL;
		to->faces[i].normal = from->faces[i].normal;
		to->faces[i].texture = from->faces[i].texture;
		REALLOC(to->faces[i].verts, nverts);
		MEMCPY(to->faces[i].verts, from->faces[i].verts, nverts);
	}
	to->nfaces = from->nfaces;
	DEBUG(2, "%d verts, %d faces copied\n", to->nverts, to->nfaces);
}
Esempio n. 2
0
void mesh_destroy(struct mesh *m)
{
	DEBUG(2, "Destroying mesh at %p\n", m);
	mesh_clear(m);
	if (m->gfx_handle >= 0)
		gfx->release_mesh(m->gfx_handle);
	FREE(m);
}
Esempio n. 3
0
void model_destroy(struct model *m)
{
	int i;

	DEBUG(2, "Destroying model %p\n", m);
	for (i=0; i < m->ngroups; i++)
		mesh_clear(&m->groups[i]);
	FREE(m->groups);
	FREE(m->offsets);
	FREE(m);
}
Esempio n. 4
0
static void mesh_flush(int do_sort)
{
	int i, j;

	// Sort
	if(do_sort)
		qsort(pcorder, pclist_num, sizeof(uint32_t), mesh_flush_sort_compar);

	// Draw
	for(i = 0; i < pclist_num; i++)
	{
		int ri = pcorder[i];

#ifdef USE_DMA
		// DMA
		uint32_t nptr = (i+1 < pclist_num
			? (uint32_t )&pclist[pcorder[i+1]].dma_chain
			: 0xFFFFFF)
				& 0xFFFFFF;

		pclist[ri].dma_chain = ((pclist[ri].len)<<24) | nptr;

#else
		// FIFO
		gpu_send_control_gp0(pclist[ri].cmd_list[0]);
		for(j = 1; j < pclist[ri].len; j++)
			gpu_send_data(pclist[ri].cmd_list[j]);
#endif
	}

#ifdef USE_DMA
	// Send DMA
	while((GP1 & 0x10000000) == 0) {}
	while((GP1 & 0x04000000) == 0) {}
	gpu_send_control_gp1(0x04000002);
	gpu_send_control_gp1(0x01000000);
	DMA_n_CHCR(2) = 0x01000401;
	DMA_DPCR = (DMA_DPCR & ~0xF00) | 0x800;
	DMA_n_MADR(2) = ((uint32_t)&pclist[pcorder[0]].dma_chain) & 0xFFFFFF;
	DMA_n_BCR(2) = 0;
	DMA_n_CHCR(2) = 0x01000401;
#endif

	// Clear
	mesh_clear();

}