Esempio n. 1
0
void gpuDrawVbo(u32 vbo) {
    VboData* vboData = (VboData*) vbo;
    if(vboData == NULL || vboData->data == NULL) {
        return;
    }

    gpuUpdateState();

    static u32 attributeBufferOffset = 0;
    GPU_SetAttributeBuffers(vboData->attributeCount, (u32*) osConvertVirtToPhys((u32) vboData->data), vboData->attributes, vboData->attributeMask, vboData->attributePermutations, 1, &attributeBufferOffset, &vboData->attributePermutations, &vboData->attributeCount);
    if(vboData->indices != NULL) {
        GPU_DrawElements((GPU_Primitive_t) vboData->primitive, (u32*) vboData->indices, vboData->numVertices);
    } else {
        GPU_DrawArray((GPU_Primitive_t) vboData->primitive, vboData->numVertices);
    }
}
Esempio n. 2
0
void drawRoom(room_s* r)
{
	if(!r)return;

	gsSwitchRenderMode(-1);

	gsSetShader(&roomProgram);

	GPU_SetAttributeBuffers(
		3, // number of attributes
		(u32*)osConvertVirtToPhys(roomBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located
		GPU_ATTRIBFMT(0, 3, GPU_SHORT)|GPU_ATTRIBFMT(1, 2, GPU_SHORT)|GPU_ATTRIBFMT(2, 2, GPU_SHORT), // we want v0, v1 and v2
		0xFF8, // mask : we want v0, v1 and v2
		0x210, // permutation : we use identity
		1, // number of buffers : we have one attribute per buffer
		(u32[]){(u32)r->vertexBuffer-roomBaseAddr}, // buffer offsets (placeholders)
		(u64[]){0x210}, // attribute permutations for each buffer
		(u8[]){3} // number of attributes for each buffer
		);

	GPU_SetTextureEnable(GPU_TEXUNIT0|GPU_TEXUNIT1);
	
	GPU_SetTexEnv(0, 
		GPU_TEVSOURCES(GPU_TEXTURE0, GPU_TEXTURE1, GPU_PRIMARY_COLOR),
		GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR),
		GPU_TEVOPERANDS(0,2,0), 
		GPU_TEVOPERANDS(0,0,0), 
		GPU_MODULATE, GPU_MODULATE, 
		0xFFFFFFFF);

	gsPushMatrix();

		gsScale(TILESIZE_FLOAT*2, HEIGHTUNIT_FLOAT, TILESIZE_FLOAT*2);

		gsUpdateTransformation();

		int i;
		for(i=0; i<r->numIndexBuffers; i++)
		{
			textureBind(r->indexBufferTextures[i], GPU_TEXUNIT0);
			textureBind(r->lightingData.data.lightMap.texture, GPU_TEXUNIT1);
			GPU_SetFloatUniform(GPU_VERTEX_SHADER, roomUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 1.0f / r->indexBufferTextures[i]->height, 1.0f / r->indexBufferTextures[i]->width}, 1);
			GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)r->indexBuffers[i]-roomBaseAddr), r->numIndices[i]);
		}