[D3DRM]
[reactos.git] / reactos / dll / directx / wine / d3drm / material.c
1 /*
2 * Implementation of IDirect3DRMMaterial2 interface
3 *
4 * Copyright 2012 Christian Costa
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "d3drm_private.h"
22
23 struct color_rgb
24 {
25 D3DVALUE r;
26 D3DVALUE g;
27 D3DVALUE b;
28 };
29
30 struct d3drm_material
31 {
32 IDirect3DRMMaterial2 IDirect3DRMMaterial2_iface;
33 LONG ref;
34 struct color_rgb emissive;
35 struct color_rgb specular;
36 D3DVALUE power;
37 struct color_rgb ambient;
38 };
39
40 static inline struct d3drm_material *impl_from_IDirect3DRMMaterial2(IDirect3DRMMaterial2 *iface)
41 {
42 return CONTAINING_RECORD(iface, struct d3drm_material, IDirect3DRMMaterial2_iface);
43 }
44
45 static HRESULT WINAPI d3drm_material_QueryInterface(IDirect3DRMMaterial2 *iface, REFIID riid, void **out)
46 {
47 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
48
49 if (IsEqualGUID(riid, &IID_IDirect3DRMMaterial2)
50 || IsEqualGUID(riid, &IID_IDirect3DRMMaterial)
51 || IsEqualGUID(riid, &IID_IUnknown))
52 {
53 IDirect3DRMMaterial2_AddRef(iface);
54 *out = iface;
55 return S_OK;
56 }
57
58 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
59
60 *out = NULL;
61 return E_NOINTERFACE;
62 }
63
64 static ULONG WINAPI d3drm_material_AddRef(IDirect3DRMMaterial2 *iface)
65 {
66 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
67 ULONG refcount = InterlockedIncrement(&material->ref);
68
69 TRACE("%p increasing refcount to %u.\n", iface, refcount);
70
71 return refcount;
72 }
73
74 static ULONG WINAPI d3drm_material_Release(IDirect3DRMMaterial2 *iface)
75 {
76 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
77 ULONG refcount = InterlockedDecrement(&material->ref);
78
79 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
80
81 if (!refcount)
82 HeapFree(GetProcessHeap(), 0, material);
83
84 return refcount;
85 }
86
87 static HRESULT WINAPI d3drm_material_Clone(IDirect3DRMMaterial2 *iface,
88 IUnknown *outer, REFIID iid, void **out)
89 {
90 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
91
92 return E_NOTIMPL;
93 }
94
95 static HRESULT WINAPI d3drm_material_AddDestroyCallback(IDirect3DRMMaterial2 *iface,
96 D3DRMOBJECTCALLBACK cb, void *ctx)
97 {
98 FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
99
100 return E_NOTIMPL;
101 }
102
103 static HRESULT WINAPI d3drm_material_DeleteDestroyCallback(IDirect3DRMMaterial2 *iface,
104 D3DRMOBJECTCALLBACK cb, void *ctx)
105 {
106 FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
107
108 return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI d3drm_material_SetAppData(IDirect3DRMMaterial2 *iface, DWORD data)
112 {
113 FIXME("iface %p, data %#x stub!\n", iface, data);
114
115 return E_NOTIMPL;
116 }
117
118 static DWORD WINAPI d3drm_material_GetAppData(IDirect3DRMMaterial2 *iface)
119 {
120 FIXME("iface %p stub!\n", iface);
121
122 return 0;
123 }
124
125 static HRESULT WINAPI d3drm_material_SetName(IDirect3DRMMaterial2 *iface, const char *name)
126 {
127 FIXME("iface %p, name %s stub!\n", iface, debugstr_a(name));
128
129 return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI d3drm_material_GetName(IDirect3DRMMaterial2 *iface, DWORD *size, char *name)
133 {
134 FIXME("iface %p, size %p, name %p stub!\n", iface, size, name);
135
136 return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI d3drm_material_GetClassName(IDirect3DRMMaterial2 *iface, DWORD *size, char *name)
140 {
141 TRACE("iface %p, size %p, name %p.\n", iface, size, name);
142
143 if (!size || *size < strlen("Material") || !name)
144 return E_INVALIDARG;
145
146 strcpy(name, "Material");
147 *size = sizeof("Material");
148
149 return D3DRM_OK;
150 }
151
152 static HRESULT WINAPI d3drm_material_SetPower(IDirect3DRMMaterial2 *iface, D3DVALUE power)
153 {
154 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
155
156 TRACE("iface %p, power %.8e.\n", iface, power);
157
158 material->power = power;
159
160 return D3DRM_OK;
161 }
162
163 static HRESULT WINAPI d3drm_material_SetSpecular(IDirect3DRMMaterial2 *iface,
164 D3DVALUE r, D3DVALUE g, D3DVALUE b)
165 {
166 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
167
168 TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface, r, g, b);
169
170 material->specular.r = r;
171 material->specular.g = g;
172 material->specular.b = b;
173
174 return D3DRM_OK;
175 }
176
177 static HRESULT WINAPI d3drm_material_SetEmissive(IDirect3DRMMaterial2 *iface,
178 D3DVALUE r, D3DVALUE g, D3DVALUE b)
179 {
180 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
181
182 TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface, r, g, b);
183
184 material->emissive.r = r;
185 material->emissive.g = g;
186 material->emissive.b = b;
187
188 return D3DRM_OK;
189 }
190
191 static D3DVALUE WINAPI d3drm_material_GetPower(IDirect3DRMMaterial2 *iface)
192 {
193 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
194
195 TRACE("iface %p.\n", iface);
196
197 return material->power;
198 }
199
200 static HRESULT WINAPI d3drm_material_GetSpecular(IDirect3DRMMaterial2 *iface,
201 D3DVALUE *r, D3DVALUE *g, D3DVALUE *b)
202 {
203 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
204
205 TRACE("iface %p, r %p, g %p, b %p.\n", iface, r, g, b);
206
207 *r = material->specular.r;
208 *g = material->specular.g;
209 *b = material->specular.b;
210
211 return D3DRM_OK;
212 }
213
214 static HRESULT WINAPI d3drm_material_GetEmissive(IDirect3DRMMaterial2 *iface,
215 D3DVALUE *r, D3DVALUE *g, D3DVALUE *b)
216 {
217 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
218
219 TRACE("iface %p, r %p, g %p, b %p.\n", iface, r, g, b);
220
221 *r = material->emissive.r;
222 *g = material->emissive.g;
223 *b = material->emissive.b;
224
225 return D3DRM_OK;
226 }
227
228 static HRESULT WINAPI d3drm_material_GetAmbient(IDirect3DRMMaterial2 *iface,
229 D3DVALUE *r, D3DVALUE *g, D3DVALUE *b)
230 {
231 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
232
233 TRACE("iface %p, r %p, g %p, b %p.\n", iface, r, g, b);
234
235 *r = material->ambient.r;
236 *g = material->ambient.g;
237 *b = material->ambient.b;
238
239 return D3DRM_OK;
240 }
241
242 static HRESULT WINAPI d3drm_material_SetAmbient(IDirect3DRMMaterial2 *iface,
243 D3DVALUE r, D3DVALUE g, D3DVALUE b)
244 {
245 struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
246
247 TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface, r, g, b);
248
249 material->ambient.r = r;
250 material->ambient.g = g;
251 material->ambient.b = b;
252
253 return D3DRM_OK;
254 }
255
256 static const struct IDirect3DRMMaterial2Vtbl d3drm_material_vtbl =
257 {
258 d3drm_material_QueryInterface,
259 d3drm_material_AddRef,
260 d3drm_material_Release,
261 d3drm_material_Clone,
262 d3drm_material_AddDestroyCallback,
263 d3drm_material_DeleteDestroyCallback,
264 d3drm_material_SetAppData,
265 d3drm_material_GetAppData,
266 d3drm_material_SetName,
267 d3drm_material_GetName,
268 d3drm_material_GetClassName,
269 d3drm_material_SetPower,
270 d3drm_material_SetSpecular,
271 d3drm_material_SetEmissive,
272 d3drm_material_GetPower,
273 d3drm_material_GetSpecular,
274 d3drm_material_GetEmissive,
275 d3drm_material_GetAmbient,
276 d3drm_material_SetAmbient,
277 };
278
279 HRESULT Direct3DRMMaterial_create(IDirect3DRMMaterial2 **out)
280 {
281 struct d3drm_material *object;
282
283 TRACE("out %p.\n", out);
284
285 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
286 return E_OUTOFMEMORY;
287
288 object->IDirect3DRMMaterial2_iface.lpVtbl = &d3drm_material_vtbl;
289 object->ref = 1;
290
291 object->specular.r = 1.0f;
292 object->specular.g = 1.0f;
293 object->specular.b = 1.0f;
294
295 *out = &object->IDirect3DRMMaterial2_iface;
296
297 return S_OK;
298 }