Fixed a lot of warnings for possible problems.
[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 "windows.h"
8 #include "wintypes.h"
9 #include "winerror.h"
10 #include "interfaces.h"
11 #include "heap.h"
12 #include "ddraw.h"
13 #include "d3d.h"
14 #include "debug.h"
15
16 #include "d3d_private.h"
17
18 #ifdef HAVE_MESAGL
19
20 static IDirect3DMaterial2_VTable material2_vtable;
21 static IDirect3DMaterial_VTable material_vtable;
22
23 /*******************************************************************************
24  *                              Matrial2 static functions
25  */
26 static void activate(LPDIRECT3DMATERIAL2 this) {
27   TRACE(ddraw, "Activating material %p\n", this);
28   
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(ddraw, "Size  : %ld\n", this->mat.dwSize);
54   TRACE(ddraw, "Power : %f\n", this->mat.e.power);
55
56   TRACE(ddraw, "Texture handle : %ld\n", (DWORD)this->mat.hTexture);
57   
58   return ;
59 }
60
61 /*******************************************************************************
62  *                              Matrial2 Creation functions
63  */
64 LPDIRECT3DMATERIAL2 d3dmaterial2_create(LPDIRECT3D2 d3d)
65 {
66   LPDIRECT3DMATERIAL2 mat;
67   
68   mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DMaterial2));
69   mat->ref = 1;
70   mat->lpvtbl = &material2_vtable;
71
72   mat->use_d3d2 = 1;
73   mat->d3d.d3d2 = d3d;
74
75   mat->activate = activate;
76   
77   return mat;
78 }
79
80 LPDIRECT3DMATERIAL d3dmaterial_create(LPDIRECT3D d3d)
81 {
82   LPDIRECT3DMATERIAL2 mat;
83   
84   mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DMaterial2));
85   mat->ref = 1;
86   mat->lpvtbl = (LPDIRECT3DMATERIAL2_VTABLE) &material_vtable;
87
88   mat->use_d3d2 = 0;
89   mat->d3d.d3d1 = d3d;
90
91   mat->activate = activate;
92   
93   return (LPDIRECT3DMATERIAL) mat;
94 }
95
96 /*******************************************************************************
97  *                              IDirect3DMaterial2 methods
98  */
99
100 static HRESULT WINAPI IDirect3DMaterial2_QueryInterface(LPDIRECT3DMATERIAL2 this,
101                                                         REFIID riid,
102                                                         LPVOID* ppvObj)
103 {
104   char xrefiid[50];
105   
106   WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
107   FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
108   
109   return S_OK;
110 }
111
112
113
114 static ULONG WINAPI IDirect3DMaterial2_AddRef(LPDIRECT3DMATERIAL2 this)
115 {
116   TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
117   
118   return ++(this->ref);
119 }
120
121
122
123 static ULONG WINAPI IDirect3DMaterial2_Release(LPDIRECT3DMATERIAL2 this)
124 {
125   FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
126   
127   if (!--(this->ref)) {
128     HeapFree(GetProcessHeap(),0,this);
129     return 0;
130   }
131   
132   return this->ref;
133 }
134
135 /*** IDirect3DMaterial2 methods ***/
136 static void dump_material(LPD3DMATERIAL mat)
137 {
138   fprintf(stderr, "  dwSize : %ld\n", mat->dwSize);
139 }
140
141 static HRESULT WINAPI IDirect3DMaterial2_GetMaterial(LPDIRECT3DMATERIAL2 this,
142                                                      LPD3DMATERIAL lpMat)
143 {
144   TRACE(ddraw, "(%p)->(%p)\n", this, lpMat);
145   if (TRACE_ON(ddraw))
146     dump_material(lpMat);
147   
148   /* Copies the material structure */
149   *lpMat = this->mat;
150   
151   return DD_OK;
152 }
153
154 static HRESULT WINAPI IDirect3DMaterial2_SetMaterial(LPDIRECT3DMATERIAL2 this,
155                                                      LPD3DMATERIAL lpMat)
156 {
157   TRACE(ddraw, "(%p)->(%p)\n", this, lpMat);
158   if (TRACE_ON(ddraw))
159     dump_material(lpMat);
160   
161   /* Stores the material */
162   this->mat = *lpMat;
163   
164   return DD_OK;
165 }
166
167 static HRESULT WINAPI IDirect3DMaterial2_GetHandle(LPDIRECT3DMATERIAL2 this,
168                                                    LPDIRECT3DDEVICE2 lpD3DDevice2,
169                                                    LPD3DMATERIALHANDLE lpMatHandle)
170
171 {
172   FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lpD3DDevice2, lpMatHandle);
173
174   if (this->use_d3d2)
175     this->device.active_device2 = lpD3DDevice2;
176   else
177     this->device.active_device1 = (LPDIRECT3DDEVICE) lpD3DDevice2;
178   
179   *lpMatHandle = (DWORD) this; /* lpD3DDevice2->store_material(this); */
180   
181   return DD_OK;
182 }
183
184 static HRESULT WINAPI IDirect3DMaterial_Reserve(LPDIRECT3DMATERIAL this)
185 {
186   FIXME(ddraw, "(%p)->(): stub\n", this);
187
188   return DDERR_INVALIDPARAMS;
189 }
190                                                   
191 static HRESULT WINAPI IDirect3DMaterial_Unreserve(LPDIRECT3DMATERIAL this)
192 {
193   FIXME(ddraw, "(%p)->(): stub\n", this);
194
195   return DDERR_INVALIDPARAMS;
196 }
197
198 static HRESULT WINAPI IDirect3DMaterial_Initialize(LPDIRECT3DMATERIAL this,
199                                                    LPDIRECT3D lpDirect3D)
200
201 {
202   TRACE(ddraw, "(%p)->(%p)\n", this, lpDirect3D);
203   
204   return DDERR_ALREADYINITIALIZED;
205 }
206
207
208 /*******************************************************************************
209  *                              IDirect3DMaterial VTable
210  */
211 static IDirect3DMaterial_VTable material_vtable = {
212   /*** IUnknown methods ***/
213   IDirect3DMaterial2_QueryInterface,
214   IDirect3DMaterial2_AddRef,
215   IDirect3DMaterial2_Release,
216   /*** IDirect3DMaterial methods ***/
217   IDirect3DMaterial_Initialize,
218   IDirect3DMaterial2_SetMaterial,
219   IDirect3DMaterial2_GetMaterial,
220   IDirect3DMaterial2_GetHandle,
221   IDirect3DMaterial_Reserve,
222   IDirect3DMaterial_Unreserve
223 };
224
225
226 /*******************************************************************************
227  *                              IDirect3DMaterial2 VTable
228  */
229 static IDirect3DMaterial2_VTable material2_vtable = {
230   /*** IUnknown methods ***/
231   IDirect3DMaterial2_QueryInterface,
232   IDirect3DMaterial2_AddRef,
233   IDirect3DMaterial2_Release,
234   /*** IDirect3DMaterial methods ***/
235   IDirect3DMaterial2_SetMaterial,
236   IDirect3DMaterial2_GetMaterial,
237   IDirect3DMaterial2_GetHandle
238 };
239
240 #else /* HAVE_MESAGL */
241
242 LPDIRECT3DMATERIAL d3dmaterial_create(LPDIRECT3D d3d) {
243   ERR(ddraw, "Should not be called...\n");
244   return NULL;
245 }
246
247 LPDIRECT3DMATERIAL2 d3dmaterial2_create(LPDIRECT3D2 d3d) {
248   ERR(ddraw, "Should not be called...\n");
249   return NULL;
250 }
251
252
253 #endif /* HAVE_MESAGL */