예제 #1
0
void draw_object_ex(IDirect3DDevice9 *device, object *obj, BOOL trans){
	unsigned int mesh;
	if(!device) return;
	if(!obj) return;

	if(obj->update){
		vertex *dest;
		generate_normals(obj);
		IDirect3DVertexBuffer9_Lock(obj->vertexbuffer, 0, 0, (BYTE**)&dest, 0 );
		memcpy(dest,obj->vertices,sizeof(vertex)*obj->vertex_count);
		IDirect3DVertexBuffer9_Unlock(obj->vertexbuffer);
		obj->update = FALSE;
	}

	IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&obj->mat );
	IDirect3DDevice9_SetStreamSource(device, 0, obj->vertexbuffer, 0, sizeof(vertex));
	IDirect3DDevice9_SetFVF(device, OBJECT_VERTEX_TYPE);

	for(mesh=0;mesh<obj->submesh_count;mesh++){
		if(obj->submeshes[mesh].mat){
			if(obj->submeshes[mesh].mat->additive==trans){
				set_material(device,obj->submeshes[mesh].mat);
				IDirect3DDevice9_SetIndices(device,obj->submeshes[mesh].indexbuffer);
				IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0,0,obj->vertex_count, 0,obj->submeshes[mesh].triangle_count);
			}
		}else{
			if(!trans){
				IDirect3DDevice9_SetIndices(device,obj->submeshes[mesh].indexbuffer);
				IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0,0,obj->vertex_count, 0,obj->submeshes[mesh].triangle_count);
			}
		}
	}
}
예제 #2
0
static void displayD3D9()
{
    int i;

    update();

    IDirect3DDevice9_SetRenderState(gDevicePtr, D3DRS_LIGHTING, FALSE);
    IDirect3DDevice9_SetRenderState(gDevicePtr, D3DRS_CLIPPING, FALSE);
    IDirect3DDevice9_SetRenderTarget(gDevicePtr, 0, gDeviceBackBufferPtr);
    utilReshapeOrtho(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
    IDirect3DDevice9_Clear(gDevicePtr, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFF000000, 1.0f, 0);
    IDirect3DDevice9_SetVertexShader(gDevicePtr, gVShaderPtr);
    IDirect3DDevice9_SetPixelShader(gDevicePtr, gPShaderPtr);
    IDirect3DDevice9_SetVertexDeclaration(gDevicePtr, gVertexDeclPtr);
    IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, gVertexBufferPtr, 0, sizeof(FLOAT) * 3);
    IDirect3DDevice9_SetIndices(gDevicePtr, gIndexBufferPtr);

    /* Send projection matrix constants */
    IDirect3DDevice9_SetVertexShaderConstantF(gDevicePtr, 0, gProjectionMatrixf, 4);

    IDirect3DDevice9_BeginScene(gDevicePtr);

    for (i = 0; i < gNumDrawCalls; i++) {
        if (gResetVertexPointers)
            IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, gVertexBufferPtr, 0, sizeof(FLOAT) * 3);

        if (gResetConstants || i == 0)
            update_modelview_constants_d3d9(gModelViewMatrixf);

        IDirect3DDevice9_DrawIndexedPrimitive(gDevicePtr, D3DPT_TRIANGLELIST, 0, 0, NUM_VERTICES, 0, NUM_INDICES);

        if (gResetVertexPointers)
            IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, gVertexBufferPtr, 36, sizeof(FLOAT) * 3);

        if (gResetConstants || i == 0)
            update_modelview_constants_d3d9(gModelViewMatrixf2);

        IDirect3DDevice9_DrawIndexedPrimitive(gDevicePtr, D3DPT_TRIANGLELIST, 0, 0, NUM_VERTICES, 0, NUM_INDICES);
    }

    IDirect3DDevice9_EndScene(gDevicePtr);

    IDirect3DDevice9_Present(gDevicePtr, NULL, NULL, 0, NULL);

    /* Reset state to default */
    IDirect3DDevice9_SetVertexShader(gDevicePtr, NULL);
    IDirect3DDevice9_SetPixelShader(gDevicePtr, NULL);
    IDirect3DDevice9_SetVertexDeclaration(gDevicePtr, NULL);
    IDirect3DDevice9_SetStreamSource(gDevicePtr, 0, NULL, 0, 0);
    IDirect3DDevice9_SetIndices(gDevicePtr, NULL);
}
예제 #3
0
void D3DCacheFlush(d3d_render_cache_system *pCacheSystem, d3d_render_pool_new *pPool, int numStages,
				   int type)
{
	u_int				curPacket, curChunk, numPackets;
	LPDIRECT3DTEXTURE9	pTexture = NULL;
	d3d_render_cache		*pRenderCache = NULL;
	d3d_render_packet_new	*pPacket;
	d3d_render_chunk_new	*pChunk;
	list_type				list;
	int						i;

	// call material function for this pool
	if (FALSE == pPool->pMaterialFctn(pPool))
		return;

	for (list = pPool->renderPacketList; list != pPool->curPacketList->next; list = list->next)
	{
		pPacket = (d3d_render_packet_new *)list->data;

		if (list == pPool->curPacketList)
			numPackets = pPool->curPacket;
		else
			numPackets = pPool->size;

		for (curPacket = 0; curPacket < numPackets; curPacket++, pPacket++)
		{
			// call material function for this packet
			if (FALSE == pPacket->pMaterialFctn(pPacket, pCacheSystem))
				continue;

			for (curChunk = 0; curChunk < pPacket->curChunk; curChunk++)
			{
				pChunk = &pPacket->renderChunks[curChunk];

				// call material function for this chunk
				if (FALSE == pChunk->pMaterialFctn(pChunk))
					continue;

				if (pRenderCache != pChunk->pRenderCache)
				{
					pRenderCache = pChunk->pRenderCache;
					D3DRENDER_SET_STREAMS(gpD3DDevice, pRenderCache, numStages);
				}

				IDirect3DDevice9_DrawIndexedPrimitive(gpD3DDevice,
                                                  (D3DPRIMITIVETYPE) type,
                                                  0,
                                                  pChunk->startIndex,
                                                  pChunk->numIndices,
                                                  pChunk->startIndex,
                                                  pChunk->numPrimitives);

				gNumVertices += pChunk->numIndices;
				gNumDPCalls++;
			}
		}
	}

	// now decrement reference count for these textures
	for (i = 0; i < numStages; i++)
	{
		IDirect3DDevice9_SetTexture(gpD3DDevice, i, NULL);
	}

	D3DRENDER_CLEAR_STREAMS(gpD3DDevice, numStages);
}