riched20: Add newlines to ERR macro output.
[wine] / dlls / d3d8 / vertexbuffer.c
1 /*
2  * IDirect3DResource8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
30
31 #include "d3d8_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 /* IDirect3DResource IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj)
37 {
38     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
39
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DResource8)
42         || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
43         IDirect3DVertexBuffer8Impl_AddRef(iface);
44         *ppobj = This;
45         return D3D_OK;
46     }
47
48     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
49     return E_NOINTERFACE;
50 }
51
52 ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
53     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
54     ULONG ref = InterlockedIncrement(&This->ref);
55
56     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
57
58     return ref;
59 }
60
61 ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
62     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
63     ULONG ref = InterlockedDecrement(&This->ref);
64
65     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
66
67     if (ref == 0 && 0 == This->refInt) {
68         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
69         HeapFree(GetProcessHeap(), 0, This);
70     } else if (0 == ref) {
71       WARN("(%p) : The application failed to set Stream source to NULL before releasing the vertex shader, leak\n", This);
72     }
73
74     return ref;
75 }
76
77 ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRefInt(LPDIRECT3DVERTEXBUFFER8 iface) {
78     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
79     ULONG refInt = InterlockedIncrement(&This->refInt);
80
81     TRACE("(%p) : AddRefInt from %ld\n", This, refInt - 1);
82
83     return refInt;
84 }
85
86 ULONG WINAPI IDirect3DVertexBuffer8Impl_ReleaseInt(LPDIRECT3DVERTEXBUFFER8 iface) {
87     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
88     ULONG refInt = InterlockedDecrement(&This->refInt);
89
90     TRACE("(%p) : ReleaseRefInt to %ld\n", This, refInt);
91
92     if (0 == This->ref && 0 == refInt) {
93         WARN("(%p) : Cleaning up after the calling application failed to release the stream source properly\n", This);
94         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
95         HeapFree(GetProcessHeap(), 0, This);
96     }
97
98     return refInt;
99 }
100
101 /* IDirect3DResource Interface follow: */
102 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8** ppDevice) {
103     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
104     TRACE("(%p) : returning %p\n", This, This->Device);
105     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
106     IDirect3DDevice8Impl_AddRef(*ppDevice);
107     return D3D_OK;
108 }
109 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
110     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
111     FIXME("(%p) : stub\n", This);    return D3D_OK;
112 }
113 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
114     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
115     FIXME("(%p) : stub\n", This);    return D3D_OK;
116 }
117 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
118     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
119     FIXME("(%p) : stub\n", This);    return D3D_OK;
120 }
121 DWORD    WINAPI        IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
122     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
123     FIXME("(%p) : stub\n", This);    return D3D_OK;
124 }
125 DWORD    WINAPI        IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
126     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
127     FIXME("(%p) : stub\n", This);    return D3D_OK;
128 }
129 void     WINAPI        IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
130     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
131     FIXME("(%p) : stub\n", This);
132 }
133 D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
134     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
135     TRACE("(%p) : returning %d\n", This, This->ResourceType);
136     return This->ResourceType;
137 }
138
139 /* IDirect3DVertexBuffer8 */
140 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) {
141     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
142     TRACE("(%p) : returning memory of %p (base:%p,offset:%u)\n", This, This->allocatedMemory + OffsetToLock, This->allocatedMemory, OffsetToLock);
143     /* TODO: check Flags compatibility with This->currentDesc.Usage (see MSDN) */
144     *ppbData = This->allocatedMemory + OffsetToLock;
145     return D3D_OK;
146 }
147 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
148     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
149     TRACE("(%p) : stub\n", This);
150     return D3D_OK;
151 }
152 HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
153     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
154
155     TRACE("(%p)\n", This);
156     pDesc->Format = This->currentDesc.Format;
157     pDesc->Type   = This->currentDesc.Type;
158     pDesc->Usage  = This->currentDesc.Usage;
159     pDesc->Pool   = This->currentDesc.Pool;
160     pDesc->Size   = This->currentDesc.Size;
161     pDesc->FVF    = This->currentDesc.FVF;
162     return D3D_OK;
163 }
164
165 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
166 {
167     IDirect3DVertexBuffer8Impl_QueryInterface,
168     IDirect3DVertexBuffer8Impl_AddRef,
169     IDirect3DVertexBuffer8Impl_Release,
170     IDirect3DVertexBuffer8Impl_GetDevice,
171     IDirect3DVertexBuffer8Impl_SetPrivateData,
172     IDirect3DVertexBuffer8Impl_GetPrivateData,
173     IDirect3DVertexBuffer8Impl_FreePrivateData,
174     IDirect3DVertexBuffer8Impl_SetPriority,
175     IDirect3DVertexBuffer8Impl_GetPriority,
176     IDirect3DVertexBuffer8Impl_PreLoad,
177     IDirect3DVertexBuffer8Impl_GetType,
178     IDirect3DVertexBuffer8Impl_Lock,
179     IDirect3DVertexBuffer8Impl_Unlock,
180     IDirect3DVertexBuffer8Impl_GetDesc
181 };