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