rendered paste bodystatic void stream_test(IDirect3DDevice9 *device)
{
IDirect3D9 *d3d = NULL;
IDirect3DDevice9_GetDirect3D(device, &d3d);
printf("####%i", IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','S','T'))==D3D_OK?1:0);
IDirect3DVertexBuffer9 *vb = NULL;
IDirect3DVertexBuffer9 *vb2 = NULL;
IDirect3DVertexBuffer9 *vb3 = NULL;
IDirect3DIndexBuffer9 *ib = NULL;
IDirect3DVertexDeclaration9 *pDecl = NULL;
IDirect3DVertexShader9 *shader;
HRESULT hr;
BYTE *data;
const DWORD shader_code[] =
{
0xfffe0101, /* vs_1_1 */
0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
0x0000001f, 0x80000005, 0x900f0002, /* dcl_texcoord v2 */
0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
0x00000002, 0xc00f0000, 0x80e40000, 0x90e40002, /* add oPos, r0, v2 */
0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
0x0000ffff
};
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 float vertcolor[][4] =
{
{1.0f, 1.0f, 0.0f, 1.0f}, //0
{1.0f, 0.0f, 0.0f, 1.0f}, //1
{0.0f, 1.0f, 0.0f, 1.0f}, //2
{0.0f, 0.0f, 0.0f, 0.0f}, //3
};
/*
const int vertcolor[] =
{
{0xffff00ff}, //0
{0xff0000ff}, //1
{0x00ff00ff}, //2
{0x00000000}, //3
};
*/
// 4 position for 4 instances
const float instancepos[][3] =
{
{0.0f, 0.0f, 0.0f},
{0.2f, 0.0f, 0.0f},
{0.4f, 0.0f, 0.0f},
{0.6f, 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_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
// {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{2, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
/* create all VertexBuffers*/
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(vertcolor), 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_CreateVertexBuffer(device, sizeof(instancepos), 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;
}
/* create IndexBuffer*/
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));
/* copy all Buffers (Vertex + Index)*/
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(vertcolor), (void **) &data, 0);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr));
memcpy(data, vertcolor, sizeof(vertcolor));
hr = IDirect3DVertexBuffer9_Unlock(vb2);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DVertexBuffer9_Lock(vb3, 0, sizeof(instancepos), (void **) &data, 0);
ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr));
memcpy(data, instancepos, sizeof(instancepos));
hr = IDirect3DVertexBuffer9_Unlock(vb3);
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));
/* create all VertexDeclarations */ /* add another on */
IDirect3DDevice9_CreateVertexDeclaration(device, decl, &pDecl);
/* create VertexShader */
hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader failed hr=%s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
/* test 1 */
hr = IDirect3DDevice9_BeginScene(device);
ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
if(SUCCEEDED(hr))
{
hr = IDirect3DDevice9_SetVertexDeclaration(device, pDecl);
ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
hr = IDirect3DDevice9_SetVertexShader(device, shader);
ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed hr=%s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetStreamSourceFreq(device, 0, (D3DSTREAMSOURCE_INDEXEDDATA | 2)); /* set this for the tests */
ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad[0]));
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INDEXEDDATA | 2));
ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetStreamSource(device, 1, vb2, 0, sizeof(vertcolor[0]));
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetStreamSourceFreq(device, 2, (D3DSTREAMSOURCE_INSTANCEDATA | 1));
ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetStreamSource(device, 2, vb3, 0, sizeof(instancepos[0]));
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetIndices(device, ib);
ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 0, 4 * 3 , 0, 4*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, "IDirect3DDevice9_SetIndices failed with %08x\n", hr);
hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 0, 0);
ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
hr = IDirect3DDevice9_SetStreamSource(device, 1, NULL, 0, 0);
ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
hr = IDirect3DDevice9_SetStreamSource(device, 2, NULL, 0, 0);
ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource 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);
IDirect3DVertexShader9_Release(shader);
}