vertexdeclaration.c revision af062818b47340eef15700d2f0211576ba3506ee
af062818b47340eef15700d2f0211576ba3506eevboxsync * IDirect3DVertexDeclaration9 implementation
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright 2002-2003 Raphael Junqueira
af062818b47340eef15700d2f0211576ba3506eevboxsync * Jason Edmeades
af062818b47340eef15700d2f0211576ba3506eevboxsync * This library is free software; you can redistribute it and/or
af062818b47340eef15700d2f0211576ba3506eevboxsync * modify it under the terms of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync * License as published by the Free Software Foundation; either
af062818b47340eef15700d2f0211576ba3506eevboxsync * version 2.1 of the License, or (at your option) any later version.
af062818b47340eef15700d2f0211576ba3506eevboxsync * This library is distributed in the hope that it will be useful,
af062818b47340eef15700d2f0211576ba3506eevboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
af062818b47340eef15700d2f0211576ba3506eevboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * Lesser General Public License for more details.
af062818b47340eef15700d2f0211576ba3506eevboxsync * You should have received a copy of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync * License along with this library; if not, write to the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
af062818b47340eef15700d2f0211576ba3506eevboxsynctypedef struct _D3DDECLTYPE_INFO {
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic D3DDECLTYPE_INFO const d3d_dtype_lookup[D3DDECLTYPE_UNUSED] = {
af062818b47340eef15700d2f0211576ba3506eevboxsync#define D3D_DECL_SIZE(type) d3d_dtype_lookup[type].size
af062818b47340eef15700d2f0211576ba3506eevboxsync#define D3D_DECL_TYPESIZE(type) d3d_dtype_lookup[type].typesize
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned int offset;
af062818b47340eef15700d2f0211576ba3506eevboxsync BOOL has_blend = (fvf & D3DFVF_XYZB5) > D3DFVF_XYZRHW;
af062818b47340eef15700d2f0211576ba3506eevboxsync DWORD num_textures = (fvf & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned int size;
af062818b47340eef15700d2f0211576ba3506eevboxsync DWORD num_blends = 1 + (((fvf & D3DFVF_XYZB5) - D3DFVF_XYZB1) >> 1);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Compute declaration size */
af062818b47340eef15700d2f0211576ba3506eevboxsync size = has_pos + (has_blend && num_blends > 0) + has_blend_idx + has_normal +
af062818b47340eef15700d2f0211576ba3506eevboxsync has_psize + has_diffuse + has_specular + num_textures + 1;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* convert the declaration */
af062818b47340eef15700d2f0211576ba3506eevboxsync elements = HeapAlloc(GetProcessHeap(), 0, size * sizeof(D3DVERTEXELEMENT9));
af062818b47340eef15700d2f0211576ba3506eevboxsync if (((fvf & D3DFVF_XYZB5) == D3DFVF_XYZB2) && (fvf & D3DFVF_LASTBETA_D3DCOLOR))
af062818b47340eef15700d2f0211576ba3506eevboxsync case 1: elements[idx].Type = D3DDECLTYPE_FLOAT1; break;
af062818b47340eef15700d2f0211576ba3506eevboxsync case 2: elements[idx].Type = D3DDECLTYPE_FLOAT2; break;
af062818b47340eef15700d2f0211576ba3506eevboxsync case 3: elements[idx].Type = D3DDECLTYPE_FLOAT3; break;
af062818b47340eef15700d2f0211576ba3506eevboxsync case 4: elements[idx].Type = D3DDECLTYPE_FLOAT4; break;
af062818b47340eef15700d2f0211576ba3506eevboxsync ERR("Unexpected amount of blend values: %u\n", num_blends);
af062818b47340eef15700d2f0211576ba3506eevboxsync (((fvf & D3DFVF_XYZB5) == D3DFVF_XYZB2) && (fvf & D3DFVF_LASTBETA_D3DCOLOR)))
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned int numcoords = (texcoords >> (idx2*2)) & 0x03;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Now compute offsets, and initialize the rest of the fields */
af062818b47340eef15700d2f0211576ba3506eevboxsync offset += D3D_DECL_SIZE(elements[idx].Type) * D3D_DECL_TYPESIZE(elements[idx].Type);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* IDirect3DVertexDeclaration9 IUnknown parts follow: */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DVertexDeclaration9Impl_QueryInterface(LPDIRECT3DVERTEXDECLARATION9 iface, REFIID riid, LPVOID* ppobj) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync || IsEqualGUID(riid, &IID_IDirect3DVertexDeclaration9)) {
af062818b47340eef15700d2f0211576ba3506eevboxsync WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic ULONG WINAPI IDirect3DVertexDeclaration9Impl_AddRef(LPDIRECT3DVERTEXDECLARATION9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Should not happen unless wine has a bug or the application releases references it does not own */
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECLARATION9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync if (ref == 0) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Ex *parentDevice = This->parentDevice;
af062818b47340eef15700d2f0211576ba3506eevboxsync/* IDirect3DVertexDeclaration9 Interface follow: */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDevice(LPDIRECT3DVERTEXDECLARATION9 iface, IDirect3DDevice9** ppDevice) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDeclaration(LPDIRECT3DVERTEXDECLARATION9 iface, D3DVERTEXELEMENT9* pDecl, UINT* pNumElements) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : pDecl %p, pNumElements %p)\n", This, pDecl, pNumElements);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Passing a NULL pDecl is used to just retrieve the number of elements */
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("Copying %p to %p\n", This->elements, pDecl);
af062818b47340eef15700d2f0211576ba3506eevboxsync CopyMemory(pDecl, This->elements, This->element_count * sizeof(D3DVERTEXELEMENT9));
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic const IDirect3DVertexDeclaration9Vtbl Direct3DVertexDeclaration9_Vtbl =
af062818b47340eef15700d2f0211576ba3506eevboxsync /* IUnknown */
af062818b47340eef15700d2f0211576ba3506eevboxsync /* IDirect3DVertexDeclaration9 */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic UINT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elements, WINED3DVERTEXELEMENT **wined3d_elements) {
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("d3d9_elements %p, wined3d_elements %p\n", d3d9_elements, wined3d_elements);
af062818b47340eef15700d2f0211576ba3506eevboxsync while (element++->Stream != 0xff && element_count++ < 128);
af062818b47340eef15700d2f0211576ba3506eevboxsync *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(WINED3DVERTEXELEMENT));
af062818b47340eef15700d2f0211576ba3506eevboxsync for (i = 0; i < element_count; ++i) {
af062818b47340eef15700d2f0211576ba3506eevboxsync CopyMemory(*wined3d_elements + i, d3d9_elements + i, sizeof(D3DVERTEXELEMENT9));
af062818b47340eef15700d2f0211576ba3506eevboxsync/* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */
af062818b47340eef15700d2f0211576ba3506eevboxsyncHRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9EX iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync WARN("(%p) : Caller passed NULL As ppDecl, returning D3DERR_INVALIDCALL\n",This);
af062818b47340eef15700d2f0211576ba3506eevboxsync element_count = convert_to_wined3d_declaration(pVertexElements, &wined3d_elements);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p) : Error parsing vertex declaration\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Allocate the storage for the device */
af062818b47340eef15700d2f0211576ba3506eevboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl));
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
af062818b47340eef15700d2f0211576ba3506eevboxsync object->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(D3DVERTEXELEMENT9));
af062818b47340eef15700d2f0211576ba3506eevboxsync CopyMemory(object->elements, pVertexElements, element_count * sizeof(D3DVERTEXELEMENT9));
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wineD3DVertexDeclaration, (IUnknown *)object, wined3d_elements, element_count);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* free up object */
af062818b47340eef15700d2f0211576ba3506eevboxsync WARN("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : Created vertex declaration %p\n", This, object);
af062818b47340eef15700d2f0211576ba3506eevboxsyncHRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9* pDecl) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DVertexDeclaration9Impl *pDeclImpl = (IDirect3DVertexDeclaration9Impl *)pDecl;
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration);
af062818b47340eef15700d2f0211576ba3506eevboxsyncHRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9** ppDecl) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Impl* This = (IDirect3DDevice9Impl*) iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &pTest);