Isle
Loading...
Searching...
No Matches
mesh.cpp
Go to the documentation of this file.
1#include "impl.h"
2
3#include <assert.h>
4
5using namespace TglImpl;
6
8
11
12// FUNCTION: LEGO1 0x100a3ed0
13// FUNCTION: BETA10 0x101704d0
15{
16 return reinterpret_cast<void*>(&m_data);
17}
18
19// FUNCTION: LEGO1 0x100a3ee0
20Result MeshImpl::SetColor(float r, float g, float b, float a)
21{
22 // The first instruction makes no sense here:
23 // cmp dword ptr [esp + 0x10], 0
24 // This compares a, which we know is a float because it immediately
25 // gets passed into D3DRMCreateColorRGBA, but does the comparison
26 // as though it's an int??
27 if (*reinterpret_cast<int*>(&a) > 0) {
28 D3DCOLOR color = D3DRMCreateColorRGBA(r, g, b, a);
29 return ResultVal(m_data->groupMesh->SetGroupColor(m_data->groupIndex, color));
30 }
31 else {
32 return ResultVal(m_data->groupMesh->SetGroupColorRGB(m_data->groupIndex, r, g, b));
33 }
34}
35
36// FUNCTION: LEGO1 0x100a3f50
38{
39 IDirect3DRMTexture* texture = pTexture ? static_cast<const TextureImpl*>(pTexture)->ImplementationData() : NULL;
40 return ResultVal(m_data->groupMesh->SetGroupTexture(m_data->groupIndex, texture));
41}
42
43// FUNCTION: LEGO1 0x100a3f80
45{
46 if (mode == PerspectiveCorrect) {
47 return ResultVal(m_data->groupMesh->SetGroupMapping(m_data->groupIndex, D3DRMMAP_PERSPCORRECT));
48 }
49 else {
50 return ResultVal(m_data->groupMesh->SetGroupMapping(m_data->groupIndex, 0));
51 }
52}
53
54// FUNCTION: BETA10 0x10170750
56{
57 D3DRMRENDERQUALITY mode = Translate(model);
58 return ResultVal(pMesh->groupMesh->SetGroupQuality(pMesh->groupIndex, mode));
59}
60
61// FUNCTION: LEGO1 0x100a3fc0
62// FUNCTION: BETA10 0x101706f0
64{
65 assert(m_data);
66 return MeshSetShadingModel(m_data, model);
67}
68
69// FUNCTION: BETA10 0x101714e0
70inline Result MeshDeepClone(MeshImpl::MeshData* pSource, MeshImpl::MeshData*& rpTarget, IDirect3DRMMesh* pMesh)
71{
72 rpTarget = new MeshImpl::MeshData();
73 rpTarget->groupMesh = pMesh;
74
75 // Query information from old group
76 DWORD dataSize;
77 unsigned int vcount, fcount, vperface;
78
79 Result result =
80 ResultVal(pSource->groupMesh->GetGroup(pSource->groupIndex, &vcount, &fcount, &vperface, &dataSize, NULL));
81 assert(Succeeded(result));
82
83 unsigned int* faceBuffer = new unsigned int[dataSize];
84 result =
85 ResultVal(pSource->groupMesh->GetGroup(pSource->groupIndex, &vcount, &fcount, &vperface, &dataSize, faceBuffer)
86 );
87 assert(Succeeded(result));
88
89 // We expect vertex to be sized 0x24, checked at start of file.
90 D3DRMVERTEX* vertexBuffer = new D3DRMVERTEX[vcount];
91 result = ResultVal(pSource->groupMesh->GetVertices(pSource->groupIndex, 0, vcount, vertexBuffer));
92 assert(Succeeded(result));
93
94 LPDIRECT3DRMTEXTURE textureRef;
95 result = ResultVal(pSource->groupMesh->GetGroupTexture(pSource->groupIndex, &textureRef));
96 assert(Succeeded(result));
97
98 D3DRMMAPPING mapping = pSource->groupMesh->GetGroupMapping(pSource->groupIndex);
99 D3DRMRENDERQUALITY quality = pSource->groupMesh->GetGroupQuality(pSource->groupIndex);
100 D3DCOLOR color = pSource->groupMesh->GetGroupColor(pSource->groupIndex);
101
102 // Push information to new group
103 D3DRMGROUPINDEX index;
104 result = ResultVal(pMesh->AddGroup(vcount, fcount, 3, faceBuffer, &index));
105 assert(Succeeded(result));
106
107 rpTarget->groupIndex = index;
108 result = ResultVal(pMesh->SetVertices(index, 0, vcount, vertexBuffer));
109 assert(Succeeded(result));
110
111 result = ResultVal(pMesh->SetGroupTexture(index, textureRef));
112 assert(Succeeded(result));
113
114 result = ResultVal(pMesh->SetGroupMapping(index, mapping));
115 assert(Succeeded(result));
116
117 result = ResultVal(pMesh->SetGroupQuality(index, quality));
118 assert(Succeeded(result));
119
120 result = ResultVal(pMesh->SetGroupColor(index, color));
121 assert(Succeeded(result));
122
123 // Cleanup
124 if (faceBuffer) {
125 delete[] faceBuffer;
126 }
127
128 if (vertexBuffer) {
129 delete[] vertexBuffer;
130 }
131
132 return result;
133}
134
135// FUNCTION: BETA10 0x10171360
137{
138 assert(m_data);
139 assert(rMesh.ImplementationData());
140
141 MeshImpl* clone = new MeshImpl();
142 assert(!clone->ImplementationData());
143
144 if (!MeshDeepClone(m_data, clone->ImplementationData(), rMesh.ImplementationData())) {
145 delete clone;
146 clone = NULL;
147 }
148
149 return clone;
150}
151
152// FUNCTION: LEGO1 0x100a4030
153// FUNCTION: BETA10 0x101707a0
155{
156 assert(m_data);
157 assert(pMesh);
158
159 return DeepClone(*static_cast<MeshBuilderImpl*>(pMesh));
160}
161
162// FUNCTION: LEGO1 0x100a4240
164{
165 MeshImpl* newGroup = new MeshImpl();
166 MeshData* newData = new MeshData();
167 newGroup->m_data = newData;
168 if (newData) {
169 newData->groupIndex = m_data->groupIndex;
170 newData->groupMesh = static_cast<MeshBuilderImpl*>(pMeshBuilder)->ImplementationData();
171 }
172 else {
173 delete newGroup;
174 newGroup = NULL;
175 }
176 return newGroup;
177}
178
179// FUNCTION: LEGO1 0x100a4330
181{
182 IDirect3DRMTexture* texture;
183 TextureImpl* holder = new TextureImpl();
184 Result result = ResultVal(m_data->groupMesh->GetGroupTexture(m_data->groupIndex, &texture));
185 if (result) {
186 // Seems to actually call the first virtual method of holder here
187 // but that doesn't make any sense since it passes three arguments
188 // to the method (self + string constant? + an offset?).
189
190 // This line makes the start of the function match and is what I
191 // would expect to see there but it clearly isn't what's actually
192 // there.
193 holder->SetImplementation(texture);
194 }
195 rpTexture = holder;
196 return Success;
197}
[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] Implementation of Tgl::Mesh, manages a mesh object and geometry data with group index [AI]
Definition: impl.h:816
Result SetColor(float r, float g, float b, float a) override
Sets the color for this mesh [AI].
Definition: mesh.cpp:20
Result SetTextureMappingMode(TextureMappingMode) override
Sets the mesh texturing mode (UV/cylindrical/etc.) [AI].
Definition: mesh.cpp:44
void * ImplementationDataPtr() override
Returns pointer to mesh implementation data [AI].
Definition: mesh.cpp:14
Result GetTexture(Texture *&) override
Retrieves the texture currently assigned to this mesh [AI].
Definition: mesh.cpp:180
const MeshDataType & ImplementationData() const
Gets mesh implementation data (const) [AI].
Definition: impl.h:893
MeshImpl()
[AI] Initializes mesh data pointer [AI]
Definition: impl.h:819
Mesh * ShallowClone(MeshBuilder *) override
Creates a shallow copy of this mesh using a mesh builder [AI].
Definition: mesh.cpp:163
Mesh * DeepClone(MeshBuilder *) override
Creates a deep copy of this mesh using a mesh builder [AI].
Definition: mesh.cpp:154
Result SetTexture(const Texture *) override
Assigns a texture to this mesh [AI].
Definition: mesh.cpp:37
Result SetShadingModel(ShadingModel) override
Sets mesh shading model (flat, Gouraud, etc.) [AI].
Definition: mesh.cpp:63
[AI] Implements Tgl::Texture using a Direct3DRMTexture; provides upload and palette control [AI]
Definition: impl.h:1268
void SetImplementation(IDirect3DRMTexture *pData)
Replaces implementation pointer [AI].
Definition: impl.h:1349
[AI] Builder class for assembling mesh data and extracting mesh objects.
Definition: tgl.h:768
[AI] Represents a renderable 3D mesh.
Definition: tgl.h:596
[AI] Represents a GPU or system memory texture for use in rendering.
Definition: tgl.h:826
DWORD D3DRMMAPPING
Definition: d3drmdef.h:322
D3DCOLOR D3DRMAPI D3DRMCreateColorRGBA(D3DVALUE red, D3DVALUE green, D3DVALUE blue, D3DVALUE alpha)
DWORD D3DRMRENDERQUALITY
Definition: d3drmdef.h:88
LONG D3DRMGROUPINDEX
Definition: d3drmdef.h:334
DWORD D3DCOLOR
Definition: d3dtypes.h:103
typedef DWORD(FAR PASCAL *LPCLIPPERCALLBACK)(LPDIRECTDRAWCLIPPER lpDDClipper
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
Result MeshSetShadingModel(MeshImpl::MeshData *pMesh, ShadingModel model)
Definition: mesh.cpp:55
Result MeshDeepClone(MeshImpl::MeshData *pSource, MeshImpl::MeshData *&rpTarget, IDirect3DRMMesh *pMesh)
Definition: mesh.cpp:70
[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
int Succeeded(Result result)
[AI] Returns whether a Tgl::Result indicates success.
Definition: tgl.h:136
ShadingModel
[AI] Represents shading models available for rendering geometry.
Definition: tgl.h:29
TextureMappingMode
[AI] Methods for mapping textures onto geometry.
Definition: tgl.h:65
@ PerspectiveCorrect
[AI] Perspective-correct mapping (higher quality). [AI]
Definition: tgl.h:67
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
[AI] Holds D3DRMMesh pointer and group index for referencing geometry [AI]
Definition: impl.h:883
D3DRMGROUPINDEX groupIndex
[AI] Index within mesh group [AI]
Definition: impl.h:885
IDirect3DRMMesh * groupMesh
[AI] D3DRM mesh pointer [AI]
Definition: impl.h:884