LoadStringA inserts terminating null in the buffer when the string
[wine] / dlls / ddraw / d3dmaterial.c
1 /* Direct3D Material
2    (c) 1998 Lionel ULMER
3    
4    This files contains the implementation of Direct3DMaterial2. */
5
6 #include "config.h"
7 #include "windef.h"
8 #include "winerror.h"
9 #include "wine/obj_base.h"
10 #include "heap.h"
11 #include "ddraw.h"
12 #include "d3d.h"
13 #include "debugtools.h"
14
15 #include "mesa_private.h"
16
17 DEFAULT_DEBUG_CHANNEL(ddraw)
18
19 static ICOM_VTABLE(IDirect3DMaterial2) material2_vtable;
20 static ICOM_VTABLE(IDirect3DMaterial) material_vtable;
21
22 /*******************************************************************************
23  *                              Matrial2 static functions
24  */
25 static void activate(IDirect3DMaterial2Impl* This) {
26   TRACE("Activating material %p\n", This);
27   
28   ENTER_GL();
29   /* First, set the rendering context */
30   if (This->use_d3d2)
31     This->device.active_device2->set_context(This->device.active_device2);
32   else
33     This->device.active_device1->set_context(This->device.active_device1);
34
35   /* Set the current Material */
36   _dump_colorvalue("Diffuse", This->mat.a.diffuse);
37   glMaterialfv(GL_FRONT,
38                GL_DIFFUSE,
39                (float *) &(This->mat.a.diffuse));
40   _dump_colorvalue("Ambient", This->mat.b.ambient);
41   glMaterialfv(GL_FRONT,
42                GL_AMBIENT,
43                (float *) &(This->mat.b.ambient));
44   _dump_colorvalue("Specular", This->mat.c.specular);
45   glMaterialfv(GL_FRONT,
46                GL_SPECULAR,
47                (float *) &(This->mat.c.specular));
48   _dump_colorvalue("Emissive", This->mat.d.emissive);
49   glMaterialfv(GL_FRONT,
50                GL_EMISSION,
51                (float *) &(This->mat.d.emissive));
52   
53   TRACE("Size  : %ld\n", This->mat.dwSize);
54   TRACE("Power : %f\n", This->mat.e.power);
55
56   TRACE("Texture handle : %08lx\n", (DWORD)This->mat.hTexture);
57   LEAVE_GL();
58   
59   return ;
60 }
61
62 /*******************************************************************************
63  *                              Matrial2 Creation functions
64  */
65 LPDIRECT3DMATERIAL2 d3dmaterial2_create(IDirect3D2Impl* d3d2)
66 {
67   IDirect3DMaterial2Impl* mat;
68   
69   mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DMaterial2Impl));
70   mat->ref = 1;
71   ICOM_VTBL(mat) = &material2_vtable;
72
73   mat->use_d3d2 = 1;
74   mat->d3d.d3d2 = d3d2;
75
76   mat->activate = activate;
77   
78   return (LPDIRECT3DMATERIAL2)mat;
79 }
80
81 LPDIRECT3DMATERIAL d3dmaterial_create(IDirect3DImpl* d3d1)
82 {
83   IDirect3DMaterial2Impl* mat;
84   
85   mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DMaterial2Impl));
86   mat->ref = 1;
87   ICOM_VTBL(mat) = (ICOM_VTABLE(IDirect3DMaterial2)*)&material_vtable;
88
89   mat->use_d3d2 = 0;
90   mat->d3d.d3d1 = d3d1;
91
92   mat->activate = activate;
93   
94   return (LPDIRECT3DMATERIAL) mat;
95 }
96
97 /*******************************************************************************
98  *                              IDirect3DMaterial2 methods
99  */
100
101 static HRESULT WINAPI IDirect3DMaterial2Impl_QueryInterface(LPDIRECT3DMATERIAL2 iface,
102                                                         REFIID riid,
103                                                         LPVOID* ppvObj)
104 {
105   ICOM_THIS(IDirect3DMaterial2Impl,iface);
106   
107   FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
108   
109   return S_OK;
110 }
111
112
113
114 static ULONG WINAPI IDirect3DMaterial2Impl_AddRef(LPDIRECT3DMATERIAL2 iface)
115 {
116   ICOM_THIS(IDirect3DMaterial2Impl,iface);
117   TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
118   
119   return ++(This->ref);
120 }
121
122
123
124 static ULONG WINAPI IDirect3DMaterial2Impl_Release(LPDIRECT3DMATERIAL2 iface)
125 {
126   ICOM_THIS(IDirect3DMaterial2Impl,iface);
127   FIXME("(%p)->() decrementing from %lu.\n", This, This->ref );
128   
129   if (!--(This->ref)) {
130     HeapFree(GetProcessHeap(),0,This);
131     return 0;
132   }
133   
134   return This->ref;
135 }
136
137 /*** IDirect3DMaterial2 methods ***/
138 static void dump_material(LPD3DMATERIAL mat)
139 {
140   DPRINTF("  dwSize : %ld\n", mat->dwSize);
141 }
142
143 static HRESULT WINAPI IDirect3DMaterial2Impl_GetMaterial(LPDIRECT3DMATERIAL2 iface,
144                                                      LPD3DMATERIAL lpMat)
145 {
146   ICOM_THIS(IDirect3DMaterial2Impl,iface);
147   TRACE("(%p)->(%p)\n", This, lpMat);
148   if (TRACE_ON(ddraw))
149     dump_material(lpMat);
150   
151   /* Copies the material structure */
152   *lpMat = This->mat;
153   
154   return DD_OK;
155 }
156
157 static HRESULT WINAPI IDirect3DMaterial2Impl_SetMaterial(LPDIRECT3DMATERIAL2 iface,
158                                                      LPD3DMATERIAL lpMat)
159 {
160   ICOM_THIS(IDirect3DMaterial2Impl,iface);
161   TRACE("(%p)->(%p)\n", This, lpMat);
162   if (TRACE_ON(ddraw))
163     dump_material(lpMat);
164   
165   /* Stores the material */
166   This->mat = *lpMat;
167   
168   return DD_OK;
169 }
170
171 static HRESULT WINAPI IDirect3DMaterial2Impl_GetHandle(LPDIRECT3DMATERIAL2 iface,
172                                                    LPDIRECT3DDEVICE2 lpD3DDevice2,
173                                                    LPD3DMATERIALHANDLE lpMatHandle)
174
175 {
176   ICOM_THIS(IDirect3DMaterial2Impl,iface);
177   FIXME("(%p)->(%p,%p): stub\n", This, lpD3DDevice2, lpMatHandle);
178
179   if (This->use_d3d2)
180     This->device.active_device2 = (IDirect3DDevice2Impl*)lpD3DDevice2;
181   else
182     This->device.active_device1 = (IDirect3DDeviceImpl*)lpD3DDevice2;
183   
184   *lpMatHandle = (DWORD) This; /* lpD3DDevice2->store_material(This); */
185   
186   return DD_OK;
187 }
188
189 static HRESULT WINAPI IDirect3DMaterialImpl_Reserve(LPDIRECT3DMATERIAL iface)
190 {
191   ICOM_THIS(IDirect3DMaterial2Impl,iface);
192   FIXME("(%p)->(): stub\n", This);
193
194   return DDERR_INVALIDPARAMS;
195 }
196                                                   
197 static HRESULT WINAPI IDirect3DMaterialImpl_Unreserve(LPDIRECT3DMATERIAL iface)
198 {
199   ICOM_THIS(IDirect3DMaterial2Impl,iface);
200   FIXME("(%p)->(): stub\n", This);
201
202   return DDERR_INVALIDPARAMS;
203 }
204
205 static HRESULT WINAPI IDirect3DMaterialImpl_Initialize(LPDIRECT3DMATERIAL iface,
206                                                    LPDIRECT3D lpDirect3D)
207
208 {
209   ICOM_THIS(IDirect3DMaterial2Impl,iface);
210   TRACE("(%p)->(%p)\n", This, lpDirect3D);
211   
212   return DDERR_ALREADYINITIALIZED;
213 }
214
215
216 /*******************************************************************************
217  *                              IDirect3DMaterial VTable
218  */
219 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
220 # define XCAST(fun)     (typeof(material_vtable.fn##fun))
221 #else
222 # define XCAST(fun)     (void*)
223 #endif
224
225 static ICOM_VTABLE(IDirect3DMaterial) material_vtable = 
226 {
227   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
228   /*** IUnknown methods ***/
229   XCAST(QueryInterface)IDirect3DMaterial2Impl_QueryInterface,
230   XCAST(AddRef)IDirect3DMaterial2Impl_AddRef,
231   XCAST(Release)IDirect3DMaterial2Impl_Release,
232   /*** IDirect3DMaterial methods ***/
233   IDirect3DMaterialImpl_Initialize,
234   XCAST(SetMaterial)IDirect3DMaterial2Impl_SetMaterial,
235   XCAST(GetMaterial)IDirect3DMaterial2Impl_GetMaterial,
236   XCAST(GetHandle)IDirect3DMaterial2Impl_GetHandle,
237   IDirect3DMaterialImpl_Reserve,
238   IDirect3DMaterialImpl_Unreserve
239 };
240
241 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
242 #undef XCAST
243 #endif
244
245 /*******************************************************************************
246  *                              IDirect3DMaterial2 VTable
247  */
248 static ICOM_VTABLE(IDirect3DMaterial2) material2_vtable = 
249 {
250   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
251   /*** IUnknown methods ***/
252   IDirect3DMaterial2Impl_QueryInterface,
253   IDirect3DMaterial2Impl_AddRef,
254   IDirect3DMaterial2Impl_Release,
255   /*** IDirect3DMaterial methods ***/
256   IDirect3DMaterial2Impl_SetMaterial,
257   IDirect3DMaterial2Impl_GetMaterial,
258   IDirect3DMaterial2Impl_GetHandle
259 };