Converted to the new COM declaration 'standard' for better
[wine/wine-kai.git] / graphics / d3dmaterial.c
blob17727159b39ad89098aa633ab5a9fdc8a682350e
1 /* Direct3D Material
2 (c) 1998 Lionel ULMER
4 This files contains the implementation of Direct3DMaterial2. */
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"
17 #include "d3d_private.h"
19 #ifdef HAVE_MESAGL
21 static IDirect3DMaterial2_VTable material2_vtable;
22 static IDirect3DMaterial_VTable material_vtable;
24 /*******************************************************************************
25 * Matrial2 static functions
27 static void activate(LPDIRECT3DMATERIAL2 this) {
28 TRACE(ddraw, "Activating material %p\n", this);
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);
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));
54 TRACE(ddraw, "Size : %ld\n", this->mat.dwSize);
55 TRACE(ddraw, "Power : %f\n", this->mat.e.power);
57 TRACE(ddraw, "Texture handle : %08lx\n", (DWORD)this->mat.hTexture);
59 return ;
62 /*******************************************************************************
63 * Matrial2 Creation functions
65 LPDIRECT3DMATERIAL2 d3dmaterial2_create(LPDIRECT3D2 d3d)
67 LPDIRECT3DMATERIAL2 mat;
69 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DMaterial2));
70 mat->ref = 1;
71 mat->lpvtbl = &material2_vtable;
73 mat->use_d3d2 = 1;
74 mat->d3d.d3d2 = d3d;
76 mat->activate = activate;
78 return mat;
81 LPDIRECT3DMATERIAL d3dmaterial_create(LPDIRECT3D d3d)
83 LPDIRECT3DMATERIAL2 mat;
85 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DMaterial2));
86 mat->ref = 1;
87 mat->lpvtbl = (LPDIRECT3DMATERIAL2_VTABLE) &material_vtable;
89 mat->use_d3d2 = 0;
90 mat->d3d.d3d1 = d3d;
92 mat->activate = activate;
94 return (LPDIRECT3DMATERIAL) mat;
97 /*******************************************************************************
98 * IDirect3DMaterial2 methods
101 static HRESULT WINAPI IDirect3DMaterial2_QueryInterface(LPDIRECT3DMATERIAL2 this,
102 REFIID riid,
103 LPVOID* ppvObj)
105 char xrefiid[50];
107 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
108 FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
110 return S_OK;
115 static ULONG WINAPI IDirect3DMaterial2_AddRef(LPDIRECT3DMATERIAL2 this)
117 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
119 return ++(this->ref);
124 static ULONG WINAPI IDirect3DMaterial2_Release(LPDIRECT3DMATERIAL2 this)
126 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
128 if (!--(this->ref)) {
129 HeapFree(GetProcessHeap(),0,this);
130 return 0;
133 return this->ref;
136 /*** IDirect3DMaterial2 methods ***/
137 static void dump_material(LPD3DMATERIAL mat)
139 fprintf(stderr, " dwSize : %ld\n", mat->dwSize);
142 static HRESULT WINAPI IDirect3DMaterial2_GetMaterial(LPDIRECT3DMATERIAL2 this,
143 LPD3DMATERIAL lpMat)
145 TRACE(ddraw, "(%p)->(%p)\n", this, lpMat);
146 if (TRACE_ON(ddraw))
147 dump_material(lpMat);
149 /* Copies the material structure */
150 *lpMat = this->mat;
152 return DD_OK;
155 static HRESULT WINAPI IDirect3DMaterial2_SetMaterial(LPDIRECT3DMATERIAL2 this,
156 LPD3DMATERIAL lpMat)
158 TRACE(ddraw, "(%p)->(%p)\n", this, lpMat);
159 if (TRACE_ON(ddraw))
160 dump_material(lpMat);
162 /* Stores the material */
163 this->mat = *lpMat;
165 return DD_OK;
168 static HRESULT WINAPI IDirect3DMaterial2_GetHandle(LPDIRECT3DMATERIAL2 this,
169 LPDIRECT3DDEVICE2 lpD3DDevice2,
170 LPD3DMATERIALHANDLE lpMatHandle)
173 FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lpD3DDevice2, lpMatHandle);
175 if (this->use_d3d2)
176 this->device.active_device2 = lpD3DDevice2;
177 else
178 this->device.active_device1 = (LPDIRECT3DDEVICE) lpD3DDevice2;
180 *lpMatHandle = (DWORD) this; /* lpD3DDevice2->store_material(this); */
182 return DD_OK;
185 static HRESULT WINAPI IDirect3DMaterial_Reserve(LPDIRECT3DMATERIAL this)
187 FIXME(ddraw, "(%p)->(): stub\n", this);
189 return DDERR_INVALIDPARAMS;
192 static HRESULT WINAPI IDirect3DMaterial_Unreserve(LPDIRECT3DMATERIAL this)
194 FIXME(ddraw, "(%p)->(): stub\n", this);
196 return DDERR_INVALIDPARAMS;
199 static HRESULT WINAPI IDirect3DMaterial_Initialize(LPDIRECT3DMATERIAL this,
200 LPDIRECT3D lpDirect3D)
203 TRACE(ddraw, "(%p)->(%p)\n", this, lpDirect3D);
205 return DDERR_ALREADYINITIALIZED;
209 /*******************************************************************************
210 * IDirect3DMaterial VTable
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
227 /*******************************************************************************
228 * IDirect3DMaterial2 VTable
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
241 #else /* HAVE_MESAGL */
243 LPDIRECT3DMATERIAL d3dmaterial_create(LPDIRECT3D d3d) {
244 ERR(ddraw, "Should not be called...\n");
245 return NULL;
248 LPDIRECT3DMATERIAL2 d3dmaterial2_create(LPDIRECT3D2 d3d) {
249 ERR(ddraw, "Should not be called...\n");
250 return NULL;
254 #endif /* HAVE_MESAGL */