xref: /reactos/dll/directx/wine/d3drm/d3drm_private.h (revision bae2bac6)
1 /*
2  *      Direct3DRM private interfaces (D3DRM.DLL)
3  *
4  * Copyright 2010 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 #ifndef __D3DRM_PRIVATE_INCLUDED__
22 #define __D3DRM_PRIVATE_INCLUDED__
23 
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #define COBJMACROS
27 #include <assert.h>
28 #include <math.h>
29 #include "dxfile.h"
30 #include "d3drmwin.h"
31 #include "rmxfguid.h"
32 #include "wine/debug.h"
33 #include "wine/heap.h"
34 #include "wine/list.h"
35 
36 #ifndef ARRAY_SIZE
37 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
38 #endif
39 
40 struct d3drm_object
41 {
42     LONG ref;
43     DWORD appdata;
44     struct list destroy_callbacks;
45     const char *classname;
46     char *name;
47 };
48 
49 struct d3drm_texture
50 {
51     struct d3drm_object obj;
52     IDirect3DRMTexture IDirect3DRMTexture_iface;
53     IDirect3DRMTexture2 IDirect3DRMTexture2_iface;
54     IDirect3DRMTexture3 IDirect3DRMTexture3_iface;
55     IDirect3DRM *d3drm;
56     D3DRMIMAGE *image;
57     IDirectDrawSurface *surface;
58 };
59 
60 struct d3drm_frame
61 {
62     struct d3drm_object obj;
63     IDirect3DRMFrame IDirect3DRMFrame_iface;
64     IDirect3DRMFrame2 IDirect3DRMFrame2_iface;
65     IDirect3DRMFrame3 IDirect3DRMFrame3_iface;
66     IDirect3DRM *d3drm;
67     LONG ref;
68     struct d3drm_frame *parent;
69     SIZE_T nb_children;
70     SIZE_T children_size;
71     IDirect3DRMFrame3 **children;
72     SIZE_T nb_visuals;
73     SIZE_T visuals_size;
74     IDirect3DRMVisual **visuals;
75     SIZE_T nb_lights;
76     SIZE_T lights_size;
77     IDirect3DRMLight **lights;
78     D3DRMMATRIX4D transform;
79     D3DCOLOR scenebackground;
80     DWORD traversal_options;
81 };
82 
83 struct d3drm_viewport
84 {
85     struct d3drm_object obj;
86     struct d3drm_device *device;
87     IDirect3DRMFrame *camera;
88     IDirect3DRMViewport IDirect3DRMViewport_iface;
89     IDirect3DRMViewport2 IDirect3DRMViewport2_iface;
90     IDirect3DViewport *d3d_viewport;
91     IDirect3DMaterial *material;
92     IDirect3DRM *d3drm;
93     D3DVALUE back;
94     D3DVALUE front;
95     D3DVALUE field;
96     D3DRMPROJECTIONTYPE projection;
97 };
98 
99 struct d3drm_device
100 {
101     struct d3drm_object obj;
102     IDirect3DRMDevice IDirect3DRMDevice_iface;
103     IDirect3DRMDevice2 IDirect3DRMDevice2_iface;
104     IDirect3DRMDevice3 IDirect3DRMDevice3_iface;
105     IDirect3DRMWinDevice IDirect3DRMWinDevice_iface;
106     IDirect3DRM *d3drm;
107     IDirectDraw *ddraw;
108     IDirectDrawSurface *primary_surface, *render_target;
109     IDirectDrawClipper *clipper;
110     IDirect3DDevice *device;
111     BOOL dither;
112     D3DRMRENDERQUALITY quality;
113     DWORD rendermode;
114     DWORD height;
115     DWORD width;
116 };
117 
118 struct d3drm_face
119 {
120     struct d3drm_object obj;
121     IDirect3DRMFace IDirect3DRMFace_iface;
122     IDirect3DRMFace2 IDirect3DRMFace2_iface;
123     LONG ref;
124     D3DCOLOR color;
125 };
126 
127 struct d3drm_mesh_builder
128 {
129     struct d3drm_object obj;
130     IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
131     IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
132     LONG ref;
133     IDirect3DRM *d3drm;
134     SIZE_T nb_vertices;
135     SIZE_T vertices_size;
136     D3DVECTOR *vertices;
137     SIZE_T nb_normals;
138     SIZE_T normals_size;
139     D3DVECTOR *normals;
140     DWORD nb_faces;
141     DWORD face_data_size;
142     void *pFaceData;
143     DWORD nb_coords2d;
144     struct coords_2d *pCoords2d;
145     D3DCOLOR color;
146     IDirect3DRMMaterial2 *material;
147     IDirect3DRMTexture3 *texture;
148     DWORD nb_materials;
149     struct mesh_material *materials;
150     DWORD *material_indices;
151 };
152 
153 struct mesh_group
154 {
155     unsigned nb_vertices;
156     D3DRMVERTEX* vertices;
157     unsigned nb_faces;
158     unsigned vertex_per_face;
159     DWORD face_data_size;
160     unsigned* face_data;
161     D3DCOLOR color;
162     IDirect3DRMMaterial2* material;
163     IDirect3DRMTexture3* texture;
164 };
165 
166 struct d3drm_mesh
167 {
168     struct d3drm_object obj;
169     IDirect3DRMMesh IDirect3DRMMesh_iface;
170     LONG ref;
171     IDirect3DRM *d3drm;
172     SIZE_T nb_groups;
173     SIZE_T groups_size;
174     struct mesh_group *groups;
175 };
176 
177 struct d3drm_light
178 {
179     struct d3drm_object obj;
180     IDirect3DRMLight IDirect3DRMLight_iface;
181     LONG ref;
182     IDirect3DRM *d3drm;
183     D3DRMLIGHTTYPE type;
184     D3DCOLOR color;
185     D3DVALUE range;
186     D3DVALUE cattenuation;
187     D3DVALUE lattenuation;
188     D3DVALUE qattenuation;
189     D3DVALUE umbra;
190     D3DVALUE penumbra;
191 };
192 
193 struct color_rgb
194 {
195     D3DVALUE r;
196     D3DVALUE g;
197     D3DVALUE b;
198 };
199 
200 struct d3drm_material
201 {
202     struct d3drm_object obj;
203     IDirect3DRMMaterial2 IDirect3DRMMaterial2_iface;
204     LONG ref;
205     IDirect3DRM *d3drm;
206     struct color_rgb emissive;
207     struct color_rgb specular;
208     D3DVALUE power;
209     struct color_rgb ambient;
210 };
211 
212 struct d3drm_animation_key
213 {
214     D3DVALUE time;
215     union
216     {
217         D3DVECTOR position;
218         D3DVECTOR scale;
219         D3DRMQUATERNION rotate;
220     } u;
221 };
222 
223 struct d3drm_animation_keys
224 {
225     struct d3drm_animation_key *keys;
226     SIZE_T count;
227     SIZE_T size;
228 };
229 
230 struct d3drm_animation
231 {
232     struct d3drm_object obj;
233     IDirect3DRMAnimation2 IDirect3DRMAnimation2_iface;
234     IDirect3DRMAnimation IDirect3DRMAnimation_iface;
235     LONG ref;
236     IDirect3DRM *d3drm;
237     IDirect3DRMFrame3 *frame;
238     D3DRMANIMATIONOPTIONS options;
239     struct d3drm_animation_keys position;
240     struct d3drm_animation_keys scale;
241     struct d3drm_animation_keys rotate;
242 };
243 
244 struct d3drm_wrap
245 {
246     struct d3drm_object obj;
247     IDirect3DRMWrap IDirect3DRMWrap_iface;
248     LONG ref;
249 };
250 
251 HRESULT d3drm_device_create(struct d3drm_device **device, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
252 HRESULT d3drm_device_create_surfaces_from_clipper(struct d3drm_device *object, IDirectDraw *ddraw,
253         IDirectDrawClipper *clipper, int width, int height, IDirectDrawSurface **surface) DECLSPEC_HIDDEN;
254 void d3drm_device_destroy(struct d3drm_device *device) DECLSPEC_HIDDEN;
255 HRESULT d3drm_device_init(struct d3drm_device *device, UINT version, IDirectDraw *ddraw,
256         IDirectDrawSurface *surface, BOOL create_z_surface) DECLSPEC_HIDDEN;
257 
258 void d3drm_object_init(struct d3drm_object *object, const char *classname) DECLSPEC_HIDDEN;
259 HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx) DECLSPEC_HIDDEN;
260 HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx) DECLSPEC_HIDDEN;
261 HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name) DECLSPEC_HIDDEN;
262 HRESULT d3drm_object_get_name(struct d3drm_object *object, DWORD *size, char *name) DECLSPEC_HIDDEN;
263 HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name) DECLSPEC_HIDDEN;
264 void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object) DECLSPEC_HIDDEN;
265 
266 struct d3drm_frame *unsafe_impl_from_IDirect3DRMFrame(IDirect3DRMFrame *iface) DECLSPEC_HIDDEN;
267 struct d3drm_device *unsafe_impl_from_IDirect3DRMDevice3(IDirect3DRMDevice3 *iface) DECLSPEC_HIDDEN;
268 
269 HRESULT d3drm_texture_create(struct d3drm_texture **texture, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
270 HRESULT d3drm_frame_create(struct d3drm_frame **frame, IUnknown *parent_frame, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
271 HRESULT d3drm_face_create(struct d3drm_face **face) DECLSPEC_HIDDEN;
272 HRESULT d3drm_viewport_create(struct d3drm_viewport **viewport, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
273 HRESULT d3drm_mesh_builder_create(struct d3drm_mesh_builder **mesh_builder, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
274 HRESULT d3drm_light_create(struct d3drm_light **light, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
275 HRESULT d3drm_material_create(struct d3drm_material **material, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
276 HRESULT d3drm_mesh_create(struct d3drm_mesh **mesh, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
277 HRESULT d3drm_animation_create(struct d3drm_animation **animation, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
278 HRESULT d3drm_wrap_create(struct d3drm_wrap **wrap, IDirect3DRM *d3drm) DECLSPEC_HIDDEN;
279 
280 HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *data,
281                        D3DRMLOADTEXTURECALLBACK load_texture_proc, void *arg) DECLSPEC_HIDDEN;
282 
283 struct d3drm_file_header
284 {
285     WORD major;
286     WORD minor;
287     DWORD flags;
288 };
289 
290 extern char templates[] DECLSPEC_HIDDEN;
291 
292 static inline BYTE d3drm_color_component(float c)
293 {
294     if (c <= 0.0f)
295         return 0u;
296     if (c >= 1.0f)
297         return 0xffu;
298     return floor(c * 255.0f);
299 }
300 
301 static inline void d3drm_set_color(D3DCOLOR *color, float r, float g, float b, float a)
302 {
303     *color = RGBA_MAKE(d3drm_color_component(r), d3drm_color_component(g),
304             d3drm_color_component(b), d3drm_color_component(a));
305 }
306 
307 BOOL d3drm_array_reserve(void **elements, SIZE_T *capacity, SIZE_T element_count, SIZE_T element_size) DECLSPEC_HIDDEN;
308 
309 #endif /* __D3DRM_PRIVATE_INCLUDED__ */
310