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); }
static HRESULT test_decl_to_fvf(IDirect3DDevice9* device, DWORD default_fvf, const D3DVERTEXELEMENT9 test_decl[], DWORD test_fvf, BOOL todo) { HRESULT hr; IDirect3DVertexDeclaration9 *vdecl = NULL; DWORD result_fvf = 0xdeadbeef; /* Set a default FVF of SPECULAR and DIFFUSE to make sure it is changed back to 0 */ hr = IDirect3DDevice9_SetFVF( device, default_fvf); ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; /* Create a testing declaration */ hr = IDirect3DDevice9_CreateVertexDeclaration( device, test_decl, &vdecl ); ok(SUCCEEDED(hr), "CreateVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; /* Set the declaration */ hr = IDirect3DDevice9_SetVertexDeclaration ( device, vdecl ); ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; /* Check the FVF */ hr = IDirect3DDevice9_GetFVF( device, &result_fvf); ok(SUCCEEDED(hr), "GetFVF returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; if (todo) todo_wine ok(test_fvf == result_fvf, "result FVF was: %#x, expected: %#x\n", result_fvf, test_fvf); else ok(test_fvf == result_fvf, "result FVF was: %#x, expected: %#x\n", result_fvf, test_fvf); if (test_fvf != result_fvf) goto fail; IDirect3DDevice9_SetVertexDeclaration ( device, NULL ); if (vdecl) IUnknown_Release( vdecl ); return S_OK; fail: IDirect3DDevice9_SetVertexDeclaration ( device, NULL ); if (vdecl) IUnknown_Release( vdecl ); return E_FAIL; }
void d3d_set_vertex_declaration(void *data, void *vertex_data) { LPDIRECT3DDEVICE dev = (LPDIRECT3DDEVICE)data; #if defined(HAVE_D3D9) LPDIRECT3DVERTEXDECLARATION decl = (LPDIRECT3DVERTEXDECLARATION)vertex_data; #endif if (!dev) return; #ifdef _XBOX1 d3d_set_vertex_shader(dev, D3DFVF_XYZ | D3DFVF_TEX1, NULL); #elif defined(HAVE_D3D9) && !defined(__cplusplus) IDirect3DDevice9_SetVertexDeclaration(dev, decl); #elif defined(HAVE_D3D9) dev->SetVertexDeclaration(decl); #endif }
static HRESULT test_fvf_to_decl( IDirect3DDevice9* device, IDirect3DVertexDeclaration9* default_decl, DWORD test_fvf, const D3DVERTEXELEMENT9 expected_elements[], char object_should_change) { HRESULT hr; IDirect3DVertexDeclaration9 *result_decl = NULL; /* Set a default declaration to make sure it is changed */ hr = IDirect3DDevice9_SetVertexDeclaration ( device, default_decl ); ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; /* Set an FVF */ hr = IDirect3DDevice9_SetFVF( device, test_fvf); ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; /* Check if the declaration object changed underneath */ hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl); ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto fail; if (object_should_change) { ok(result_decl != default_decl, "result declaration matches original\n"); if (result_decl == default_decl) goto fail; } else { ok(result_decl == default_decl, "result declaration does not match original\n"); if (result_decl != default_decl) goto fail; } /* Declaration content/size test */ ok(result_decl != NULL, "result declaration was null\n"); if (result_decl == NULL) goto fail; else if (compare_elements(result_decl, expected_elements) != S_OK) goto fail; if (result_decl) IUnknown_Release( result_decl ); return S_OK; fail: if (result_decl) IUnknown_Release( result_decl ); return E_FAIL; }
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); }
static int _al_draw_prim_raw(ALLEGRO_BITMAP* texture, const void* vtx, const ALLEGRO_VERTEX_DECL* decl, const int* indices, int num_vtx, int type) { int stride = decl ? decl->stride : (int)sizeof(ALLEGRO_VERTEX); int num_primitives = 0; ALLEGRO_DISPLAY *display; LPDIRECT3DDEVICE9 device; LPDIRECT3DBASETEXTURE9 d3d_texture; DWORD old_wrap_state[2]; DWORD old_ttf_state; int min_idx = 0, max_idx = num_vtx - 1; if(indices) { int ii; for(ii = 0; ii < num_vtx; ii++) { int idx = indices[ii]; if(ii == 0) { min_idx = idx; max_idx = idx; } else if (idx < min_idx) { min_idx = idx; } else if (idx > max_idx) { max_idx = idx; } } } display = al_get_current_display(); device = al_d3d_get_device(display); if(decl) { if(decl->d3d_decl) { IDirect3DDevice9_SetVertexDeclaration(device, (IDirect3DVertexDeclaration9*)decl->d3d_decl); } else { return _al_draw_prim_soft(texture, vtx, decl, 0, num_vtx, type); } } else { IDirect3DDevice9_SetFVF(device, A5V_FVF); } set_blender(display); if (texture) { int tex_x, tex_y; D3DSURFACE_DESC desc; float mat[4][4] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }; IDirect3DTexture9_GetLevelDesc(al_d3d_get_video_texture(texture), 0, &desc); al_get_d3d_texture_position(texture, &tex_x, &tex_y); if(decl) { if(decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL].attribute) { mat[0][0] = 1.0f / desc.Width; mat[1][1] = 1.0f / desc.Height; } else { mat[0][0] = (float)al_get_bitmap_width(texture) / desc.Width; mat[1][1] = (float)al_get_bitmap_height(texture) / desc.Height; } } else { mat[0][0] = 1.0f / desc.Width; mat[1][1] = 1.0f / desc.Height; } mat[2][0] = (float)tex_x / desc.Width; mat[2][1] = (float)tex_y / desc.Height; IDirect3DDevice9_GetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, &old_ttf_state); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, (D3DMATRIX *)&mat); d3d_texture = (LPDIRECT3DBASETEXTURE9)al_d3d_get_video_texture(texture); IDirect3DDevice9_SetTexture(device, 0, d3d_texture); } else { IDirect3DDevice9_SetTexture(device, 0, NULL); } IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_ADDRESSU, &old_wrap_state[0]); IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_ADDRESSV, &old_wrap_state[1]); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); if(!indices) { switch (type) { case ALLEGRO_PRIM_LINE_LIST: { num_primitives = num_vtx / 2; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_LINELIST, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_STRIP: { num_primitives = num_vtx - 1; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_LINESTRIP, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_LOOP: { int in[2]; in[0] = 0; in[1] = num_vtx-1; num_primitives = num_vtx - 1; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_LINESTRIP, num_primitives, vtx, stride); IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINELIST, 0, num_vtx, 1, in, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_LIST: { num_primitives = num_vtx / 3; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_STRIP: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_FAN: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLEFAN, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_POINT_LIST: { num_primitives = num_vtx; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, num_primitives, vtx, stride); break; }; } } else { switch (type) { case ALLEGRO_PRIM_LINE_LIST: { num_primitives = num_vtx / 2; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINELIST, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_STRIP: { num_primitives = num_vtx - 1; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINESTRIP, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_LOOP: { int in[2]; num_primitives = num_vtx - 1; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINESTRIP, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); in[0] = indices[0]; in[1] = indices[num_vtx-1]; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINELIST, min_idx, max_idx + 1, 1, in, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_LIST: { num_primitives = num_vtx / 3; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_STRIP: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLESTRIP, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_FAN: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLEFAN, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_POINT_LIST: { /* * D3D does not support point lists in indexed mode, so we draw them using the non-indexed mode. To gain at least a semblance * of speed, we detect consecutive runs of vertices and draw them using a single DrawPrimitiveUP call */ int ii = 0; int start_idx = indices[0]; int run_length = 0; for(ii = 0; ii < num_vtx; ii++) { run_length++; if(indices[ii] + 1 != indices[ii + 1] || ii == num_vtx - 1) { IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, run_length, (const char*)vtx + start_idx * stride, stride); if(ii != num_vtx - 1) start_idx = indices[ii + 1]; run_length = 0; } } break; }; } } IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, old_wrap_state[0]); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, old_wrap_state[1]); if(texture) { IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, old_ttf_state); } return num_primitives; }
static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); SPRITEVERTEX *vertices; int i, count=0, start; TRACE("(%p)->(): relay\n", This); if(!This->ready) return D3DERR_INVALIDCALL; if(!This->sprite_count) return D3D_OK; /* TODO: use of a vertex buffer here */ vertices=HeapAlloc(GetProcessHeap(), 0, sizeof(SPRITEVERTEX)*6*This->sprite_count); for(start=0; start<This->sprite_count; start+=count,count=0) { i=start; while(i<This->sprite_count && (count==0 || This->sprites[i].texture==This->sprites[i-1].texture)) { float spritewidth=(float)This->sprites[i].rect.right-(float)This->sprites[i].rect.left; float spriteheight=(float)This->sprites[i].rect.bottom-(float)This->sprites[i].rect.top; vertices[6*i ].pos.x = This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i ].pos.y = This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i ].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i+1].pos.x = spritewidth + This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i+1].pos.y = This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i+1].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i+2].pos.x = spritewidth + This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i+2].pos.y = spriteheight + This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i+2].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i+3].pos.x = This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i+3].pos.y = spriteheight + This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i+3].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i ].col = This->sprites[i].color; vertices[6*i+1].col = This->sprites[i].color; vertices[6*i+2].col = This->sprites[i].color; vertices[6*i+3].col = This->sprites[i].color; vertices[6*i ].tex.x = (float)This->sprites[i].rect.left / (float)This->sprites[i].texw; vertices[6*i ].tex.y = (float)This->sprites[i].rect.top / (float)This->sprites[i].texh; vertices[6*i+1].tex.x = (float)This->sprites[i].rect.right / (float)This->sprites[i].texw; vertices[6*i+1].tex.y = (float)This->sprites[i].rect.top / (float)This->sprites[i].texh; vertices[6*i+2].tex.x = (float)This->sprites[i].rect.right / (float)This->sprites[i].texw; vertices[6*i+2].tex.y = (float)This->sprites[i].rect.bottom / (float)This->sprites[i].texh; vertices[6*i+3].tex.x = (float)This->sprites[i].rect.left / (float)This->sprites[i].texw; vertices[6*i+3].tex.y = (float)This->sprites[i].rect.bottom / (float)This->sprites[i].texh; vertices[6*i+4]=vertices[6*i]; vertices[6*i+5]=vertices[6*i+2]; D3DXVec3TransformCoordArray(&vertices[6*i].pos, sizeof(SPRITEVERTEX), &vertices[6*i].pos, sizeof(SPRITEVERTEX), &This->sprites[i].transform, 6); count++; i++; } IDirect3DDevice9_SetTexture(This->device, 0, (struct IDirect3DBaseTexture9 *)This->sprites[start].texture); IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl); IDirect3DDevice9_DrawPrimitiveUP(This->device, D3DPT_TRIANGLELIST, 2*count, vertices+6*start, sizeof(SPRITEVERTEX)); } HeapFree(GetProcessHeap(), 0, vertices); if(!(This->flags & D3DXSPRITE_DO_NOT_ADDREF_TEXTURE)) for(i=0; i<This->sprite_count; i++) IDirect3DTexture9_Release(This->sprites[i].texture); This->sprite_count=0; /* Flush may be called more than once, so we don't reset This->ready here */ return D3D_OK; }
static HRESULT WINAPI ID3DXSpriteImpl_Begin(ID3DXSprite *iface, DWORD flags) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); HRESULT hr; TRACE("(%p): relay\n", This); if(flags>D3DXSPRITE_FLAGLIMIT || This->ready) return D3DERR_INVALIDCALL; /* TODO: Implement flags: D3DXSPRITE_BILLBOARD: makes the sprite always face the camera D3DXSPRITE_DONOTMODIFY_RENDERSTATE: name says it all D3DXSPRITE_OBJECTSPACE: do not change device transforms D3DXSPRITE_SORT_DEPTH_BACKTOFRONT: sort by position D3DXSPRITE_SORT_DEPTH_FRONTTOBACK: sort by position D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often) */ /* Seems like alpha blending is always enabled, regardless of D3DXSPRITE_ALPHABLEND flag */ if(flags & (D3DXSPRITE_BILLBOARD | D3DXSPRITE_DONOTMODIFY_RENDERSTATE | D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT)) FIXME("Flags unsupported: %#x\n", flags); /* These flags should only matter to performances */ else if(flags & (D3DXSPRITE_SORT_DEPTH_FRONTTOBACK | D3DXSPRITE_SORT_TEXTURE)) TRACE("Flags unsupported: %#x\n", flags); if(This->vdecl==NULL) { static const D3DVERTEXELEMENT9 elements[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 }, { 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; IDirect3DDevice9_CreateVertexDeclaration(This->device, elements, &This->vdecl); } if(!(flags & D3DXSPRITE_DONOTSAVESTATE)) { if(This->stateblock==NULL) { /* Tell our state block what it must store */ hr=IDirect3DDevice9_BeginStateBlock(This->device); if(hr!=D3D_OK) return hr; set_states(This); IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl); IDirect3DDevice9_SetStreamSource(This->device, 0, NULL, 0, sizeof(SPRITEVERTEX)); IDirect3DDevice9_SetIndices(This->device, NULL); IDirect3DDevice9_SetTexture(This->device, 0, NULL); IDirect3DDevice9_EndStateBlock(This->device, &This->stateblock); } IDirect3DStateBlock9_Capture(This->stateblock); /* Save current state */ } /* Apply device state */ set_states(This); This->flags=flags; This->ready=TRUE; return D3D_OK; }
/* 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; }
static void test_fvf_decl_conversion(IDirect3DDevice9 *pDevice) { HRESULT hr; unsigned int i; IDirect3DVertexDeclaration9* default_decl = NULL; DWORD default_fvf = D3DFVF_SPECULAR | D3DFVF_DIFFUSE; D3DVERTEXELEMENT9 default_elements[] = { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, { 0, 4, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() }; /* Create a default declaration and FVF that does not match any of the tests */ hr = IDirect3DDevice9_CreateVertexDeclaration( pDevice, default_elements, &default_decl ); ok(SUCCEEDED(hr), "CreateVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK); if (FAILED(hr)) goto cleanup; /* Test conversions from vertex declaration to an FVF. * For some reason those seem to occur only for POSITION/POSITIONT, * Otherwise the FVF is forced to 0 - maybe this is configuration specific */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, D3DFVF_XYZ, TRUE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, D3DFVF_XYZRHW, TRUE)); } for (i = 0; i < 4; i++) { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1+i, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0}, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } /* Make sure textures of different sizes work */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } /* Make sure the TEXCOORD index works correctly - try several textures */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 }, { 0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2 }, { 0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } /* No FVF mapping available */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 1 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 1 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } /* Try empty declaration */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } /* Now try a combination test */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITIONT, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, { 0, 24, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, { 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, { 0, 32, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 44, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() }; VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE)); } /* Test conversions from FVF to a vertex declaration * These seem to always occur internally. A new declaration object is created if necessary */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZ, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZW, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZRHW, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 28, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB5 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 28, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB5, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB1, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB1 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB1 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB2, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB2 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB2 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB3, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 20, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB3 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB3 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 24, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 24, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_NORMAL, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_PSIZE, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_DIFFUSE, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_SPECULAR, test_buffer, 1)); } /* Make sure textures of different sizes work */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEX1, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEX1, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, test_buffer, 1)); } { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1, test_buffer, 1)); } /* Make sure the TEXCOORD index works correctly - try several textures */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 }, { 0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2 }, { 0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEXCOORDSIZE2(2) | D3DFVF_TEXCOORDSIZE4(3) | D3DFVF_TEX4, test_buffer, 1)); } /* Now try a combination test */ { CONST D3DVERTEXELEMENT9 test_buffer[] = { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, { 0, 32, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, { 0, 36, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 44, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() }; VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4 | D3DFVF_SPECULAR | D3DFVF_DIFFUSE | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEX2, test_buffer, 1)); } /* Setting the FVF to 0 should result in no change to the default decl */ VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, 0, default_elements, 0)); cleanup: IDirect3DDevice9_SetVertexDeclaration ( pDevice, NULL ); if ( default_decl ) IUnknown_Release (default_decl); }