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