rendered paste body/* Drawing Indexed Geometry with instances*/
static void stream_test(IDirect3DDevice9 *device)
{
IDirect3DVertexBuffer9 *vb = NULL;
IDirect3DVertexBuffer9 *vb2 = NULL;
IDirect3DIndexBuffer9 *ib = NULL;
IDirect3DVertexDeclaration9 *pDecl = NULL;
HRESULT hr;
BYTE *data;
const float quad[][3] =
{
{-0.5f, 0.0f, 1.1f}, //0
{-0.5f, 0.5f, 1.1f}, //1
{ 0.5f, 0.0f, -1.1f}, //2
{ 0.5f, 0.5f, -1.1f}, //3
};
const unsigned quad2[] =
{
0xff00ff00, 0x00000000, 0x12345678, 0xaaff00aa
};
const float quad3[][4] =
{
{1.0f, 1.0f, 0.0f, 0.0f},
{-1.0f, 1.0f, 0.0f, 0.0f},
};
short indices[] = {0, 1, 2, 1, 2, 3};
const D3DVERTEXELEMENT9 decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{2, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
IDirect3DVertexBuffer9 *vb3 = NULL;
hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad3), 0, 0, D3DPOOL_MANAGED, &vb3, NULL);
ok(hr == D3D_OK, "CreateVertexBuffer failed with %s\n", DXGetErrorString9(hr));
if(!vb3) {
skip("Failed to create a vertex buffer\n");
return;
}
hr = IDirect3DVertexBuffer9_Lock(vb3, 0, sizeof(quad3), (void **) &data, 0);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr));
memcpy(data, quad2, sizeof(quad3));
hr = IDirect3DVertexBuffer9_Unlock(vb3);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_MANAGED, &vb, NULL);
ok(hr == D3D_OK, "CreateVertexBuffer failed with %s\n", DXGetErrorString9(hr));
if(!vb) {
skip("Failed to create a vertex buffer\n");
return;
}
hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad2), 0, 0, D3DPOOL_MANAGED, &vb2, NULL);
ok(hr == D3D_OK, "CreateVertexBuffer failed with %s\n", DXGetErrorString9(hr));
if(!vb2) {
skip("Failed to create a vertex buffer\n");
return;
}
hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ib, NULL);
ok(hr == D3D_OK, "IDirect3DDevice9_CreateIndexBuffer failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **) &data, 0);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr));
memcpy(data, quad, sizeof(quad));
hr = IDirect3DVertexBuffer9_Unlock(vb);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DVertexBuffer9_Lock(vb2, 0, sizeof(quad2), (void **) &data, 0);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr));
memcpy(data, quad2, sizeof(quad2));
hr = IDirect3DVertexBuffer9_Unlock(vb2);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **) &data, 0);
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr));
memcpy(data, indices, sizeof(indices));
hr = IDirect3DIndexBuffer9_Unlock(ib);
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
IDirect3DDevice9_CreateVertexDeclaration(device, decl, &pDecl);
IDirect3DDevice9_SetVertexDeclaration(device, pDecl);
hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
hr = IDirect3DDevice9_BeginScene(device);
ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
if(SUCCEEDED(hr))
{
/* Deliberately using minvertexindex = 0 and numVertices = 6 to prevent d3d from
* making assumptions about the indices or vertices
*/
IDirect3DDevice9_SetStreamSourceFreq(device, 0, (D3DSTREAMSOURCE_INDEXEDDATA | 2));
hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad[0]));
ok(hr == D3D_OK, "IDirect3DIndexBuffer8_Unlock failed with %s\n", DXGetErrorString9(hr));
IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INDEXEDDATA | 2));
hr = IDirect3DDevice9_SetStreamSource(device, 1, vb2, 0, sizeof(quad2[0]));
ok(hr == D3D_OK, "IDirect3DIndexBuffer8_Unlock failed with %s\n", DXGetErrorString9(hr));
IDirect3DDevice9_SetStreamSourceFreq(device, 2, (D3DSTREAMSOURCE_INSTANCEDATA | 1));
hr = IDirect3DDevice9_SetStreamSource(device, 2, vb3, 0, sizeof(quad3[0]));
ok(hr == D3D_OK, "IDirect3DIndexBuffer8_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetIndices(device, ib);
ok(hr == D3D_OK, "IDirect3DIndexBuffer8_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 0, 6, 0, 1);
ok(hr == D3D_OK, "IDirect3DDevice9_DrawIndexedPrimitive failed with %08x\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
}
hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
Sleep(5000);
hr = IDirect3DDevice9_SetIndices(device, NULL);
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 0, 0);
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
hr = IDirect3DDevice9_SetStreamSource(device, 1, NULL, 0, 0);
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
/* Index buffer was already destroyed as part of the test */
IDirect3DVertexDeclaration9_Release(pDecl);
IDirect3DVertexBuffer9_Release(vb);
IDirect3DVertexBuffer9_Release(vb2);
IDirect3DVertexBuffer9_Release(vb3);
IDirect3DIndexBuffer9_Release(ib);
}