void shutdownD3D9() { #ifdef __WIN32__ /* Free all resources */ if (gTexturePtr) IDirect3DTexture9_Release(gTexturePtr); gTexturePtr = NULL; if (gVShaderPtr) IDirect3DVertexShader9_Release(gVShaderPtr); gVShaderPtr = NULL; if (gPShaderPtr) IDirect3DPixelShader9_Release(gPShaderPtr); gPShaderPtr = NULL; if (gVertexBufferPtr) IDirect3DVertexBuffer9_Release(gVertexBufferPtr); gVertexBufferPtr = NULL; if (gIndexBufferPtr) IDirect3DIndexBuffer9_Release(gIndexBufferPtr); gIndexBufferPtr = NULL; if (gVertexDeclPtr) IDirect3DVertexDeclaration9_Release(gVertexDeclPtr); gVertexDeclPtr = NULL; if (gDevicePtr) IDirect3DDevice9_Release(gDevicePtr); gDevicePtr = NULL; if (gD3D9Ptr) IDirect3D9_Release(gD3D9Ptr); gD3D9Ptr = NULL; gDeviceBackBufferPtr = NULL; #endif }
static void test_unused_type( IDirect3DDevice9* device) { HRESULT hr; IDirect3DVertexDeclaration9* result_decl = NULL; int i; static const D3DVERTEXELEMENT9 test_elements[][3] = { { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_COLOR , 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12}, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12}, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() }, }; for(i = 0; i < sizeof(test_elements) / sizeof(test_elements[0]); i++) { result_decl = NULL; hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &result_decl); ok(hr == E_FAIL, "CreateVertexDeclaration for declaration %d returned %#x, expected E_FAIL(%#x)\n", i, hr, E_FAIL); if(result_decl) IDirect3DVertexDeclaration9_Release(result_decl); } }
static HRESULT WINAPI ID3DXSpriteImpl_OnLostDevice(ID3DXSprite *iface) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); TRACE("(%p)->()\n", This); if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock); if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl); This->vdecl=NULL; This->stateblock=NULL; /* Reset some variables */ ID3DXSprite_OnResetDevice(iface); return D3D_OK; }
static void test_vertex_declaration_alignment( IDirect3DDevice9* device) { HRESULT hr; IDirect3DVertexDeclaration9* result_decl = NULL; int i; CONST D3DVERTEXELEMENT9 test_elements[5][3] = { { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 16, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 17, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 18, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 19, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 }, D3DDECL_END() }, { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 }, D3DDECL_END() } }; HRESULT results[5] = {D3D_OK, E_FAIL, E_FAIL, E_FAIL, D3D_OK}; for(i = 0; i < sizeof(test_elements) / sizeof(test_elements[0]); i++) { result_decl = NULL; hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &result_decl); ok(hr == results[i], "CreateVertexDeclaration for declaration %d returned %#x, expected %#x\n", i, hr, results[i]); if(result_decl) IDirect3DVertexDeclaration9_Release(result_decl); } }
static ULONG WINAPI ID3DXSpriteImpl_Release(ID3DXSprite *iface) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); ULONG ref=InterlockedDecrement(&This->ref); TRACE("(%p)->(): ReleaseRef to %d\n", This, ref); if(ref==0) { if(This->sprites) { int i; for(i=0; i<This->sprite_count; i++) if(This->sprites[i].texture) IDirect3DTexture9_Release(This->sprites[i].texture); HeapFree(GetProcessHeap(), 0, This->sprites); } if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock); if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl); if(This->device) IDirect3DDevice9_Release(This->device); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static void test_get_set_vertex_declaration(IDirect3DDevice9 *device_ptr, IDirect3DVertexDeclaration9 *decl_ptr) { IDirect3DVertexDeclaration9 *current_decl_ptr = 0; HRESULT hret = 0; int decl_refcount = 0; int i = 0; /* SetVertexDeclaration should not touch the declaration's refcount. */ i = get_refcount((IUnknown *)decl_ptr); hret = IDirect3DDevice9_SetVertexDeclaration(device_ptr, decl_ptr); decl_refcount = get_refcount((IUnknown *)decl_ptr); ok(hret == D3D_OK && decl_refcount == i, "SetVertexDeclaration returned: hret 0x%x, refcount %d. " "Expected hret 0x%x, refcount %d.\n", hret, decl_refcount, D3D_OK, i); /* GetVertexDeclaration should increase the declaration's refcount by one. */ i = decl_refcount+1; hret = IDirect3DDevice9_GetVertexDeclaration(device_ptr, ¤t_decl_ptr); decl_refcount = get_refcount((IUnknown *)decl_ptr); ok(hret == D3D_OK && decl_refcount == i && current_decl_ptr == decl_ptr, "GetVertexDeclaration returned: hret 0x%x, current_decl_ptr %p refcount %d. " "Expected hret 0x%x, current_decl_ptr %p, refcount %d.\n", hret, current_decl_ptr, decl_refcount, D3D_OK, decl_ptr, i); IDirect3DVertexDeclaration9_Release(current_decl_ptr); }
/* Check whether a declaration converted from FVF is shared. * Check whether refcounts behave as expected */ static void test_fvf_decl_management( IDirect3DDevice9* device) { HRESULT hr; IDirect3DVertexDeclaration9* result_decl1 = NULL; IDirect3DVertexDeclaration9* result_decl2 = NULL; IDirect3DVertexDeclaration9* result_decl3 = NULL; IDirect3DVertexDeclaration9* result_decl4 = NULL; int ref1, ref2, ref3, ref4; DWORD test_fvf1 = D3DFVF_XYZRHW; DWORD test_fvf2 = D3DFVF_NORMAL; CONST D3DVERTEXELEMENT9 test_elements1[] = { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() }; CONST D3DVERTEXELEMENT9 test_elements2[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() }; /* Clear down any current vertex declaration */ hr = IDirect3DDevice9_SetVertexDeclaration ( device, NULL ); ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; /* Conversion */ hr = IDirect3DDevice9_SetFVF( device, test_fvf1); ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; /* Get converted decl (#1) */ hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl1); ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; /* Get converted decl again (#2) */ hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl2); ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; /* Conversion */ hr = IDirect3DDevice9_SetFVF( device, test_fvf2); ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; /* The contents should correspond to the first conversion */ VDECL_CHECK(compare_elements(result_decl1, test_elements1)); /* Get converted decl (#3) */ hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl3); ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; /* The object should be the same */ ok (result_decl1 == result_decl2, "Declaration object changes on the second Get() call\n"); ok (result_decl2 != result_decl3, "Declaration object did not change during conversion\n"); /* The contents should correspond to the second conversion */ VDECL_CHECK(compare_elements(result_decl3, test_elements2)); /* Re-Check if the first decl was overwritten by the new Get() */ VDECL_CHECK(compare_elements(result_decl1, test_elements1)); hr = IDirect3DDevice9_SetFVF( device, test_fvf1); ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl4); ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; ok(result_decl4 == result_decl1, "Setting an already used FVF over results in a different vertexdeclaration\n"); ref1 = get_refcount((IUnknown*) result_decl1); ref2 = get_refcount((IUnknown*) result_decl2); ref3 = get_refcount((IUnknown*) result_decl3); ref4 = get_refcount((IUnknown*) result_decl4); ok (ref1 == 3, "Refcount #1 is %d, expected 3\n", ref1); ok (ref2 == 3, "Refcount #2 is %d, expected 3\n", ref2); ok (ref3 == 1, "Refcount #3 is %d, expected 1\n", ref3); ok (ref4 == 3, "Refcount #4 is %d, expected 3\n", ref4); /* Clear down any current vertex declaration */ hr = IDirect3DDevice9_SetVertexDeclaration ( device, NULL ); ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) return; IDirect3DVertexDeclaration9_Release(result_decl1); IDirect3DVertexDeclaration9_Release(result_decl2); IDirect3DVertexDeclaration9_Release(result_decl3); IDirect3DVertexDeclaration9_Release(result_decl4); return; }