Isle
Loading...
Searching...
No Matches
renderer.cpp
Go to the documentation of this file.
1#include "impl.h"
2
3#include <assert.h>
4
5using namespace TglImpl;
6
7// FUNCTION: LEGO1 0x100a15e0
9{
10 RendererImpl* renderer = new RendererImpl();
11 if (!renderer->Create()) {
12 delete renderer;
13 renderer = NULL;
14 }
15 return renderer;
16}
17
18namespace TglImpl
19{
20// GLOBAL: LEGO1 0x1010103c
21IDirect3DRM2* g_pD3DRM = NULL;
22} // namespace TglImpl
23
24// Inlined only
26{
27 if (g_pD3DRM) {
28 g_pD3DRM->AddRef();
29 }
30 else {
31 LPDIRECT3DRM handle;
32 Direct3DRMCreate(&handle);
33 handle->QueryInterface(IID_IDirect3DRM2, (LPVOID*) &g_pD3DRM);
34 }
35 m_data = g_pD3DRM;
36 return (m_data != NULL) ? Success : Error;
37}
38
39// FUNCTION: BETA10 0x1016cf00
41 IDirect3DRM2* pD3DRM,
42 const DeviceDirect3DCreateData& rCreateData,
43 IDirect3DRMDevice2*& rpDevice
44)
45{
46 Result result =
47 ResultVal(pD3DRM->CreateDeviceFromD3D(rCreateData.m_pDirect3D, rCreateData.m_pDirect3DDevice, &rpDevice));
48 return result;
49}
50
51// FUNCTION: BETA10 0x1016ce60
53{
54 assert(m_data);
55 assert(!rDevice.ImplementationData());
56
57 return RendererCreateDevice(m_data, rCreateData, rDevice.ImplementationData());
58}
59
60// FUNCTION: LEGO1 0x100a1830
61// FUNCTION: BETA10 0x10169d90
63{
64 assert(m_data);
65 DeviceImpl* device = new DeviceImpl();
66
67 if (!CreateDevice(data, *device)) {
68 delete device;
69 device = NULL;
70 }
71
72 return device;
73}
74
75// FUNCTION: BETA10 0x1016cfe0
77 IDirect3DRM2* pD3DRM,
78 const DeviceDirectDrawCreateData& rCreateData,
79 IDirect3DRMDevice2*& rpDevice
80)
81{
82 Result result = ResultVal(pD3DRM->CreateDeviceFromSurface(
83 const_cast<GUID*>(rCreateData.m_driverGUID),
84 rCreateData.m_pDirectDraw,
85 rCreateData.m_pBackBuffer,
86 &rpDevice
87 ));
88
89 if (Succeeded(result)) {
90 if (rCreateData.m_pBackBuffer) {
91 // LEGO1 0x10101040
92 // GLOBAL: BETA10 0x102055f4
93 static int g_setBufferCount = 1;
94 if (g_setBufferCount) {
95 Result result2 = ResultVal(rpDevice->SetBufferCount(2));
96 assert(Succeeded(result));
97 }
98 }
99 }
100
101 return result;
102}
103
104// FUNCTION: BETA10 0x1016cf40
106{
107 assert(m_data);
108 assert(!rDevice.ImplementationData());
109
110 return RendererCreateDevice(m_data, rCreateData, rDevice.ImplementationData());
111}
112
113// FUNCTION: LEGO1 0x100a1900
114// FUNCTION: BETA10 0x10169ea0
116{
117 assert(m_data);
118 DeviceImpl* device = new DeviceImpl();
119
120 if (!CreateDevice(data, *device)) {
121 delete device;
122 device = NULL;
123 }
124
125 return device;
126}
127
128// FUNCTION: BETA10 0x1016d1d0
130 IDirect3DRM2* pRenderer,
131 const IDirect3DRMDevice2* pDevice,
132 const IDirect3DRMFrame2* pCamera,
133 unsigned long x,
134 unsigned long y,
135 unsigned long width,
136 unsigned long height,
137 IDirect3DRMViewport*& rpView
138)
139{
140 Result result = ResultVal(pRenderer->CreateViewport(
141 const_cast<IDirect3DRMDevice2*>(pDevice),
142 const_cast<IDirect3DRMFrame2*>(pCamera),
143 x,
144 y,
145 width,
146 height,
147 &rpView
148 ));
149
150 if (Succeeded(result)) {
151 result = ViewImpl::ViewportCreateAppData(pRenderer, rpView, const_cast<IDirect3DRMFrame2*>(pCamera));
152 if (!Succeeded(result)) {
153 rpView->Release();
154 rpView = NULL;
155 }
156 }
157
158 return result;
159}
160
161// FUNCTION: BETA10 0x1016d0b0
163 const DeviceImpl& rDevice,
164 const CameraImpl& rCamera,
165 unsigned long x,
166 unsigned long y,
167 unsigned long width,
168 unsigned long height,
169 ViewImpl& rView
170)
171{
172 assert(m_data);
173 assert(rDevice.ImplementationData());
174 assert(rCamera.ImplementationData());
175 assert(!rView.ImplementationData());
176
177 return RendererCreateView(
178 m_data,
179 rDevice.ImplementationData(),
180 rCamera.ImplementationData(),
181 x,
182 y,
183 width,
184 height,
185 rView.ImplementationData()
186 );
187}
188
189// FUNCTION: LEGO1 0x100a1a00
190// FUNCTION: BETA10 0x10169fb0
192 const Device* pDevice,
193 const Camera* pCamera,
194 unsigned long x,
195 unsigned long y,
196 unsigned long width,
197 unsigned long height
198)
199{
200 assert(m_data);
201 assert(pDevice);
202 assert(pCamera);
203
204 ViewImpl* view = new ViewImpl();
205 if (!CreateView(
206 *static_cast<const DeviceImpl*>(pDevice),
207 *static_cast<const CameraImpl*>(pCamera),
208 x,
209 y,
210 width,
211 height,
212 *view
213 )) {
214 delete view;
215 view = NULL;
216 }
217
218 return view;
219}
220
221inline Result RendererCreateGroup(IDirect3DRM2* pRenderer, IDirect3DRMFrame2* pParent, IDirect3DRMFrame2*& rpGroup)
222{
223 Result result = ResultVal(pRenderer->CreateFrame(NULL, &rpGroup));
224 if (Succeeded(result) && pParent) {
225 result = ResultVal(pParent->AddVisual(rpGroup));
226 if (!Succeeded(result)) {
227 rpGroup->Release();
228 rpGroup = NULL;
229 }
230 }
231 return result;
232}
233
234// FUNCTION: LEGO1 0x100a1b20
236{
237 GroupImpl* group = new GroupImpl();
238 Result result =
239 RendererCreateGroup(m_data, pParent ? static_cast<const GroupImpl*>(pParent)->m_data : NULL, group->m_data);
240 if (!result) {
241 delete group;
242 group = NULL;
243 }
244 return group;
245}
246
247// FUNCTION: BETA10 0x1016d4b0
248inline Result RendererCreateCamera(IDirect3DRM2* pD3DRM, IDirect3DRMFrame2*& rpCamera)
249{
250 return ResultVal(pD3DRM->CreateFrame(NULL, &rpCamera));
251}
252
253// FUNCTION: BETA10 0x1016d420
255{
256 assert(m_data);
257 assert(!rCamera.ImplementationData());
258
259 return RendererCreateCamera(m_data, rCamera.ImplementationData());
260}
261
262// FUNCTION: LEGO1 0x100a1c30
263// FUNCTION: BETA10 0x1016a980
265{
266 assert(m_data);
267 CameraImpl* camera = new CameraImpl();
268
269 if (!CreateCamera(*camera)) {
270 delete camera;
271 camera = NULL;
272 }
273
274 return camera;
275}
276
277// FUNCTION: BETA10 0x1016d580
279 IDirect3DRM2* pD3DRM,
280 LightType type,
281 float r,
282 float g,
283 float b,
284 IDirect3DRMFrame2*& rpLight
285)
286{
287 D3DRMLIGHTTYPE lightType = Translate(type);
288 IDirect3DRMFrame2* pLightFrame;
289 IDirect3DRMLight* pLight;
290 Result result;
291
292 result = ResultVal(pD3DRM->CreateFrame(NULL, &pLightFrame));
293 assert(Succeeded(result));
294 if (!Succeeded(result)) {
295 return result;
296 }
297 // pLightFrame ref count is now 1
298 assert((pLightFrame->AddRef(), pLightFrame->Release()) == 1);
299
300 result = ResultVal(pD3DRM->CreateLightRGB(lightType, D3DVAL(r), D3DVAL(g), D3DVAL(b), &pLight));
301 assert(Succeeded(result));
302 if (!Succeeded(result)) {
303 pLightFrame->Release();
304 return result;
305 }
306 // pLight ref count is now 1
307 assert((pLight->AddRef(), pLight->Release()) == 1);
308
309 result = ResultVal(pLightFrame->AddLight(pLight));
310 assert(Succeeded(result));
311 if (!Succeeded(result)) {
312 pLightFrame->Release();
313 pLight->Release();
314 return result;
315 }
316 // pLightFrame ref count is still 1
317 assert((pLightFrame->AddRef(), pLightFrame->Release()) == 1);
318
319 // pLight ref count is now 2
320 assert((pLight->AddRef(), pLight->Release()) == 2);
321
322 // Release() pLight so it gets deleted when pLightFrame is Release()
323 pLight->Release();
324
325 rpLight = pLightFrame;
326
327 return result;
328}
329
330// FUNCTION: BETA10 0x1016d4e0
331inline Result RendererImpl::CreateLight(LightType type, float r, float g, float b, LightImpl& rLight)
332{
333 assert(m_data);
334 assert(!rLight.ImplementationData());
335
336 return RendererCreateLight(m_data, type, r, g, b, rLight.ImplementationData());
337}
338
339// FUNCTION: LEGO1 0x100a1cf0
340// FUNCTION: BETA10 0x1016aa90
341Light* RendererImpl::CreateLight(LightType type, float r, float g, float b)
342{
343 assert(m_data);
344
345 LightImpl* pLightImpl = new LightImpl;
346
347 if (!CreateLight(type, r, g, b, *pLightImpl)) {
348 delete pLightImpl;
349 pLightImpl = 0;
350 }
351
352 return pLightImpl;
353}
354
355// FUNCTION: BETA10 0x1016d8e0
356inline Result RendererCreateMeshBuilder(IDirect3DRM2* pD3DRM, IDirect3DRMMesh*& rpMesh)
357{
358 return ResultVal(pD3DRM->CreateMesh(&rpMesh));
359}
360
361// FUNCTION: BETA10 0x1016d850
363{
364 assert(m_data);
365 assert(!rMesh.ImplementationData());
366
367 return RendererCreateMeshBuilder(m_data, rMesh.ImplementationData());
368}
369
370// FUNCTION: LEGO1 0x100a1e90
371// FUNCTION: BETA10 0x1016abf0
373{
374 assert(m_data);
375 MeshBuilderImpl* meshBuilder = new MeshBuilderImpl();
376
377 if (!CreateMeshBuilder(*static_cast<MeshBuilderImpl*>(meshBuilder))) {
378 delete meshBuilder;
379 meshBuilder = NULL;
380 }
381
382 return meshBuilder;
383}
384
385// FUNCTION: BETA10 0x1016d9c0
387 IDirect3DRM2* pRenderer,
388 int width,
389 int height,
390 int bytesPerPixel,
391 void* pBuffer,
392 int useBuffer,
393 int paletteSize,
394 PaletteEntry* pEntries,
395 IDirect3DRMTexture*& rpTexture
396)
397{
398 Result result;
399
400 TglD3DRMIMAGE* pImage = new TglD3DRMIMAGE(width, height, bytesPerPixel, pBuffer, useBuffer, paletteSize, pEntries);
401 assert(pImage);
402
403 // TODO: LPDIRECT3DRMTEXTURE2?
404 result = ResultVal(pRenderer->CreateTexture(&pImage->m_image, (LPDIRECT3DRMTEXTURE2*) &rpTexture));
405 assert(Succeeded(result));
406 assert((rpTexture->AddRef(), rpTexture->Release()) == 1);
407
408 if (Succeeded(result)) {
409 result = TextureImpl::SetImage(rpTexture, pImage);
410 assert(Succeeded(result));
411
412 if (!Succeeded(result)) {
413 rpTexture->Release();
414 rpTexture = NULL;
415 delete pImage;
416 }
417 }
418 else {
419 delete pImage;
420 }
421
422 return result;
423}
424
425// FUNCTION: BETA10 0x1016d910
427 TextureImpl& rTexture,
428 int width,
429 int height,
430 int bitsPerTexel,
431 const void* pTexels,
432 int texelsArePersistent,
433 int paletteEntryCount,
434 const PaletteEntry* pEntries
435)
436{
437 assert(m_data);
438 assert(!rTexture.ImplementationData());
439
441 m_data,
442 width,
443 height,
444 bitsPerTexel,
445 const_cast<void*>(pTexels),
446 texelsArePersistent,
447 paletteEntryCount,
448 const_cast<PaletteEntry*>(pEntries),
449 rTexture.ImplementationData()
450 );
451}
452
453// FUNCTION: LEGO1 0x100a1f50
454// FUNCTION: BETA10 0x1016ad00
456 int width,
457 int height,
458 int bitsPerTexel,
459 const void* pTexels,
460 int texelsArePersistent,
461 int paletteEntryCount,
462 const PaletteEntry* pEntries
463)
464{
465 assert(m_data);
466
467 TextureImpl* texture = new TextureImpl();
468 if (!CreateTexture(
469 *texture,
470 width,
471 height,
472 bitsPerTexel,
473 const_cast<void*>(pTexels),
474 texelsArePersistent,
475 paletteEntryCount,
476 const_cast<PaletteEntry*>(pEntries)
477 )) {
478 delete texture;
479 texture = NULL;
480 }
481 return texture;
482}
483
484// FUNCTION: BETA10 0x1016dcb0
485inline Result RendererCreateTexture(IDirect3DRM2* pRenderer, IDirect3DRMTexture*& rpTexture)
486{
487 return RendererCreateTexture(pRenderer, 0, 0, 0, NULL, FALSE, 0, NULL, rpTexture);
488}
489
490// FUNCTION: BETA10 0x1016dc20
492{
493 assert(m_data);
494 assert(!rTexture.ImplementationData());
495
496 return RendererCreateTexture(m_data, rTexture.ImplementationData());
497}
498
499// FUNCTION: LEGO1 0x100a20d0
500// FUNCTION: BETA10 0x1016ae20
502{
503 assert(m_data);
504
505 TextureImpl* texture = new TextureImpl();
506 if (!CreateTexture(*texture)) {
507 delete texture;
508 texture = NULL;
509 }
510
511 return texture;
512}
513
514// FUNCTION: LEGO1 0x100a2270
516{
517 return ResultVal(m_data->SetDefaultTextureShades(shadeCount));
518}
519
520// FUNCTION: LEGO1 0x100a2290
522{
523 return ResultVal(m_data->SetDefaultTextureColors(colorCount));
524}
525
526// FUNCTION: LEGO1 0x100a22b0
527// FUNCTION: BETA10 0x1016b050
529{
530 return reinterpret_cast<void*>(&m_data);
531}
[AI] Implementation of Tgl::Camera, wraps a Direct3DRMFrame2 and provides transformation management [...
Definition: impl.h:666
const CameraDataType & ImplementationData() const
Retrieves camera pointer (const) [AI].
Definition: impl.h:692
[AI] Implements the Tgl::Device interface, encapsulates Direct3DRMDevice2 and provides rendering devi...
Definition: impl.h:322
const DeviceDataType & ImplementationData() const
Retrieves the device pointer (const) [AI].
Definition: impl.h:397
[AI] Implementation of Tgl::Group, wraps a Direct3DRMFrame2 and provides scene graph and transformati...
Definition: impl.h:944
[AI] Implementation of Tgl::Light, wraps a Direct3DRMFrame2 and color data [AI]
Definition: impl.h:737
const LightDataType & ImplementationData() const
Retrieves light pointer (const) [AI].
Definition: impl.h:771
[AI] Implements Tgl::MeshBuilder, manages mesh construction and provides the interface for creating g...
Definition: impl.h:1081
const MeshBuilderDataType & ImplementationData() const
Gets mesh builder pointer (const) [AI].
Definition: impl.h:1138
[AI] Implements Tgl::MeshBuilder; facilitates mesh construction [AI]
Definition: impl.h:55
Device * CreateDevice(const DeviceDirectDrawCreateData &) override
Creates a device from DirectDraw configuration [AI].
Definition: renderer.cpp:115
Result SetTextureDefaultShadeCount(unsigned long) override
Sets the number of default texture shades used [AI].
Definition: renderer.cpp:515
Camera * CreateCamera() override
Creates a camera object [AI].
Definition: renderer.cpp:264
MeshBuilder * CreateMeshBuilder() override
Creates a mesh builder for assembling geometry [AI].
Definition: renderer.cpp:372
Light * CreateLight(LightType, float r, float g, float b) override
Creates a light source with color and type [AI].
Definition: renderer.cpp:341
Texture * CreateTexture() override
Creates an empty texture [AI].
Definition: renderer.cpp:501
void * ImplementationDataPtr() override
Returns implementation-specific data pointer (Direct3DRM2) [AI].
Definition: renderer.cpp:528
View * CreateView(const Device *, const Camera *, unsigned long x, unsigned long y, unsigned long width, unsigned long height) override
Creates a view using provided device and camera [AI].
Definition: renderer.cpp:191
Group * CreateGroup(const Group *pParent) override
Creates a new group under parent group [AI].
Definition: renderer.cpp:235
Result SetTextureDefaultColorCount(unsigned long) override
Sets the number of default texture colors used [AI].
Definition: renderer.cpp:521
Result Create()
Initializes Direct3DRM2 [AI].
Definition: renderer.cpp:25
[AI] Implements Tgl::Texture using a Direct3DRMTexture; provides upload and palette control [AI]
Definition: impl.h:1268
static Result SetImage(IDirect3DRMTexture *pSelf, TglD3DRMIMAGE *pImage)
Copies palette/texel data from TglD3DRMIMAGE to Direct3DRMTexture [AI].
Definition: texture.cpp:16
const TextureDataType & ImplementationData() const
Gets Direct3DRMTexture pointer (const) [AI].
Definition: impl.h:1337
[AI] Simple wrapper for D3DRMIMAGE; manages pixel buffer and palette for Direct3DRM textures [AI]
Definition: impl.h:1207
D3DRMIMAGE m_image
[AI] Underlying D3DRM image struct [AI]
Definition: impl.h:1260
[AI] Implementation of Tgl::View backed by Direct3DRMViewport, handles scene rendering,...
Definition: impl.h:449
static Result ViewportCreateAppData(IDirect3DRM2 *, IDirect3DRMViewport *, IDirect3DRMFrame2 *)
Associates user app data with a viewport/frame [AI].
Definition: view.cpp:68
const ViewDataType & ImplementationData() const
Gets internal viewport pointer, const [AI].
Definition: impl.h:571
[AI] Represents a viewpoint in the 3D scene.
Definition: tgl.h:531
[AI] Represents a rendering device/context for the Tgl renderer.
Definition: tgl.h:318
[AI] Scene graph node for parental transforms/color/material/texture; can hold meshes or other groups...
Definition: tgl.h:669
[AI] Represents a source of lighting in the 3D scene.
Definition: tgl.h:559
[AI] Builder class for assembling mesh data and extracting mesh objects.
Definition: tgl.h:768
[AI] Main interface/factory for rendering resources and scene graphs.
Definition: tgl.h:188
[AI] Represents a GPU or system memory texture for use in rendering.
Definition: tgl.h:826
[AI] Represents a rendering viewport and drawing context.
Definition: tgl.h:397
LPSTR LPSTR LPVOID
Definition: d3dcaps.h:216
STDAPI Direct3DRMCreate(LPDIRECT3DRM FAR *lplpDirect3DRM)
enum _D3DRMLIGHTTYPE D3DRMLIGHTTYPE
#define FALSE
Definition: d3drmdef.h:27
#define D3DVAL(val)
Definition: d3dtypes.h:27
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
[AI] Forward declaration for Direct3DRMTexture interface [AI]
Definition: impl.h:23
Result ResultVal(HRESULT result)
Returns a Tgl Result value for HRESULT [AI].
Definition: impl.h:35
D3DRMRENDERQUALITY Translate(ShadingModel tglShadingModel)
Converts Tgl shading model enum to D3DRM enum [AI].
Definition: impl.h:1398
IDirect3DRM2 * g_pD3DRM
[AI] Global pointer to Direct3DRM2, used to manage lifecycle [AI]
Definition: renderer.cpp:21
Renderer * CreateRenderer()
[AI] Instantiates and returns a new Tgl::Renderer implementation.
Definition: renderer.cpp:8
int Succeeded(Result result)
[AI] Returns whether a Tgl::Result indicates success.
Definition: tgl.h:136
Result
[AI] Result type used throughout the Tgl API to report operation success or failure.
Definition: tgl.h:126
@ Success
[AI] Operation succeeded. [AI]
Definition: tgl.h:128
@ Error
[AI] Operation failed. [AI]
Definition: tgl.h:127
LightType
[AI] Types of lights supported in the renderer.
Definition: tgl.h:42
Result RendererCreateView(IDirect3DRM2 *pRenderer, const IDirect3DRMDevice2 *pDevice, const IDirect3DRMFrame2 *pCamera, unsigned long x, unsigned long y, unsigned long width, unsigned long height, IDirect3DRMViewport *&rpView)
Definition: renderer.cpp:129
Result RendererCreateCamera(IDirect3DRM2 *pD3DRM, IDirect3DRMFrame2 *&rpCamera)
Definition: renderer.cpp:248
Result RendererCreateMeshBuilder(IDirect3DRM2 *pD3DRM, IDirect3DRMMesh *&rpMesh)
Definition: renderer.cpp:356
Result RendererCreateDevice(IDirect3DRM2 *pD3DRM, const DeviceDirect3DCreateData &rCreateData, IDirect3DRMDevice2 *&rpDevice)
Definition: renderer.cpp:40
Result RendererCreateGroup(IDirect3DRM2 *pRenderer, IDirect3DRMFrame2 *pParent, IDirect3DRMFrame2 *&rpGroup)
Definition: renderer.cpp:221
Result RendererCreateTexture(IDirect3DRM2 *pRenderer, int width, int height, int bytesPerPixel, void *pBuffer, int useBuffer, int paletteSize, PaletteEntry *pEntries, IDirect3DRMTexture *&rpTexture)
Definition: renderer.cpp:386
Result RendererCreateLight(IDirect3DRM2 *pD3DRM, LightType type, float r, float g, float b, IDirect3DRMFrame2 *&rpLight)
Definition: renderer.cpp:278
[AI] Contains Direct3D-specific data needed to create a rendering device.
Definition: tgl.h:97
IDirect3D2 * m_pDirect3D
[AI] Direct3D interface pointer. [AI]
Definition: tgl.h:98
IDirect3DDevice2 * m_pDirect3DDevice
[AI] Direct3D device interface pointer. [AI]
Definition: tgl.h:99
[AI] Contains DirectDraw-specific params for creating a rendering device.
Definition: tgl.h:107
IDirectDrawSurface * m_pBackBuffer
[AI] Secondary (offscreen) buffer for flipping/rendering. [AI]
Definition: tgl.h:112
IDirectDraw * m_pDirectDraw
[AI] DirectDraw interface pointer. [AI]
Definition: tgl.h:110
const GUID * m_driverGUID
[AI] GUID of the DirectDraw driver to use. [AI]
Definition: tgl.h:108
[AI] Represents a single color entry in a palette.
Definition: tgl.h:86