From 6f206c75ecd9d9849b47d8faa5b85f26184e8479 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 27 Mar 2009 10:25:56 +0100 Subject: [PATCH] wined3d: Don't create an END element for wined3d vertex declarations. Wined3d doesn't need it since it already has the element count. --- dlls/d3d8/vertexdeclaration.c | 5 ----- dlls/d3d9/vertexdeclaration.c | 17 ++++++++++++----- dlls/wined3d/device.c | 13 +++++-------- dlls/wined3d/vertexdeclaration.c | 3 --- include/wine/wined3d.idl | 1 - 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/dlls/d3d8/vertexdeclaration.c b/dlls/d3d8/vertexdeclaration.c index 46957d0207e..f2da777f179 100644 --- a/dlls/d3d8/vertexdeclaration.c +++ b/dlls/d3d8/vertexdeclaration.c @@ -324,11 +324,6 @@ UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elem token += parse_token(token); } - /* END */ - element = *wined3d_elements + element_count++; - element->Stream = 0xFF; - element->Type = WINED3DDECLTYPE_UNUSED; - *d3d8_elements_size = (++token - d3d8_elements) * sizeof(DWORD); return element_count; diff --git a/dlls/d3d9/vertexdeclaration.c b/dlls/d3d9/vertexdeclaration.c index 86403fd9fc3..74229e9d3a2 100644 --- a/dlls/d3d9/vertexdeclaration.c +++ b/dlls/d3d9/vertexdeclaration.c @@ -312,13 +312,16 @@ static UINT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_element while (element++->Stream != 0xff && element_count++ < 128); if (element_count == 128) { - return 0; + return ~0U; } + /* Skip the END element */ + --element_count; + *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(WINED3DVERTEXELEMENT)); if (!*wined3d_elements) { FIXME("Memory allocation failed\n"); - return 0; + return ~0U; } for (i = 0; i < element_count; ++i) { @@ -335,6 +338,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9E IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; IDirect3DVertexDeclaration9Impl *object = NULL; WINED3DVERTEXELEMENT* wined3d_elements; + UINT wined3d_element_count; UINT element_count; HRESULT hr = D3D_OK; @@ -344,8 +348,9 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9E return D3DERR_INVALIDCALL; } - element_count = convert_to_wined3d_declaration(pVertexElements, &wined3d_elements); - if (!element_count) { + wined3d_element_count = convert_to_wined3d_declaration(pVertexElements, &wined3d_elements); + if (wined3d_element_count == ~0U) + { FIXME("(%p) : Error parsing vertex declaration\n", This); return D3DERR_INVALIDCALL; } @@ -361,6 +366,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9E object->lpVtbl = &Direct3DVertexDeclaration9_Vtbl; object->ref = 0; + element_count = wined3d_element_count + 1; object->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(D3DVERTEXELEMENT9)); if (!object->elements) { HeapFree(GetProcessHeap(), 0, wined3d_elements); @@ -372,7 +378,8 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9E object->element_count = element_count; EnterCriticalSection(&d3d9_cs); - hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wineD3DVertexDeclaration, (IUnknown *)object, wined3d_elements, element_count); + hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wineD3DVertexDeclaration, + (IUnknown *)object, wined3d_elements, wined3d_element_count); LeaveCriticalSection(&d3d9_cs); HeapFree(GetProcessHeap(), 0, wined3d_elements); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index dd493f5a521..5bb9771db3f 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -2200,8 +2200,6 @@ static unsigned int ConvertFvfToDeclaration(IWineD3DDeviceImpl *This, /* For the DWORD num_textures = (fvf & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT; DWORD texcoords = (fvf & 0xFFFF0000) >> 16; - - WINED3DVERTEXELEMENT end_element = WINED3DDECL_END(); WINED3DVERTEXELEMENT *elements = NULL; unsigned int size; @@ -2210,14 +2208,12 @@ static unsigned int ConvertFvfToDeclaration(IWineD3DDeviceImpl *This, /* For the /* Compute declaration size */ size = has_pos + (has_blend && num_blends > 0) + has_blend_idx + has_normal + - has_psize + has_diffuse + has_specular + num_textures + 1; + has_psize + has_diffuse + has_specular + num_textures; /* convert the declaration */ elements = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WINED3DVERTEXELEMENT)); - if (!elements) - return 0; + if (!elements) return ~0U; - elements[size-1] = end_element; idx = 0; if (has_pos) { if (!has_blend && (fvf & WINED3DFVF_XYZRHW)) { @@ -2310,7 +2306,8 @@ static unsigned int ConvertFvfToDeclaration(IWineD3DDeviceImpl *This, /* For the } /* Now compute offsets, and initialize the rest of the fields */ - for (idx = 0, offset = 0; idx < size-1; idx++) { + for (idx = 0, offset = 0; idx < size; ++idx) + { elements[idx].Stream = 0; elements[idx].Method = WINED3DDECLMETHOD_DEFAULT; elements[idx].Offset = offset; @@ -2328,7 +2325,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclarationFromFVF(IWineD3D DWORD hr; size = ConvertFvfToDeclaration(This, Fvf, &elements); - if (size == 0) return WINED3DERR_OUTOFVIDEOMEMORY; + if (size == ~0U) return WINED3DERR_OUTOFVIDEOMEMORY; hr = IWineD3DDevice_CreateVertexDeclaration(iface, ppVertexDeclaration, Parent, elements, size); HeapFree(GetProcessHeap(), 0, elements); diff --git a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c index cb2915daeb9..1c23c51bac8 100644 --- a/dlls/wined3d/vertexdeclaration.c +++ b/dlls/wined3d/vertexdeclaration.c @@ -206,9 +206,6 @@ HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *This, } } - /* Skip the END element. */ - --element_count; - This->element_count = element_count; This->elements = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->elements) * element_count); if (!This->elements) diff --git a/include/wine/wined3d.idl b/include/wine/wined3d.idl index 2f928987afe..bed165b3ed5 100644 --- a/include/wine/wined3d.idl +++ b/include/wine/wined3d.idl @@ -846,7 +846,6 @@ typedef enum _WINED3DDECLTYPE WINED3DDECLTYPE_FLOAT16_4 = 16, WINED3DDECLTYPE_UNUSED = 17, } WINED3DDECLTYPE; -cpp_quote("#define WINED3DDECL_END() {0xFF, 0, WINED3DDECLTYPE_UNUSED, 0, 0, 0, -1}") typedef enum _WINED3DDECLUSAGE { -- 2.11.4.GIT