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