Isle
Loading...
Searching...
No Matches
legotextureinfo.cpp
Go to the documentation of this file.
1#include "legotextureinfo.h"
2
3#include "legovideomanager.h"
4#include "misc.h"
5#include "misc/legoimage.h"
6#include "misc/legotexture.h"
8#include "tgl/d3drm/impl.h"
9
11
12// FUNCTION: LEGO1 0x10065bf0
14{
15 m_name = NULL;
16 m_surface = NULL;
17 m_palette = NULL;
18 m_texture = NULL;
19}
20
21// FUNCTION: LEGO1 0x10065c00
23{
24 if (m_name) {
25 delete[] m_name;
26 m_name = NULL;
27 }
28
29 if (m_palette) {
30 m_palette->Release();
32 }
33
34 if (m_surface) {
35 m_surface->Release();
37 }
38
39 if (m_texture) {
40 m_texture->Release();
42 }
43}
44
45// FUNCTION: LEGO1 0x10065c60
46LegoTextureInfo* LegoTextureInfo::Create(const char* p_name, LegoTexture* p_texture)
47{
48 LegoTextureInfo* textureInfo = new LegoTextureInfo();
49
50 if (p_name == NULL || p_texture == NULL) {
51 return NULL;
52 }
53
54 if (p_name) {
55 textureInfo->m_name = new char[strlen(p_name) + 1];
56 strcpy(textureInfo->m_name, p_name);
57 }
58
59 LPDIRECTDRAW pDirectDraw = VideoManager()->GetDirect3D()->DirectDraw();
60 LegoImage* image = p_texture->GetImage();
61
62 DDSURFACEDESC desc;
63 memset(&desc, 0, sizeof(desc));
64 desc.dwSize = sizeof(desc);
66 desc.dwWidth = image->GetWidth();
67 desc.dwHeight = image->GetHeight();
69 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
72
73 MxS32 i;
74 const LegoU8* bits;
75 MxU8* surface;
76
77 if (pDirectDraw->CreateSurface(&desc, &textureInfo->m_surface, NULL) != DD_OK) {
78 goto done;
79 }
80
81 bits = image->GetBits();
82
83 memset(&desc, 0, sizeof(desc));
84 desc.dwSize = sizeof(desc);
85
86 if (textureInfo->m_surface->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR, NULL) != DD_OK) {
87 goto done;
88 }
89
90 surface = (MxU8*) desc.lpSurface;
91 if (desc.dwWidth == desc.lPitch) {
92 memcpy(surface, bits, desc.dwWidth * desc.dwHeight);
93 }
94 else {
95 for (i = 0; i < desc.dwHeight; i++) {
96 *(MxU32*) surface = *(MxU32*) bits;
97 surface += desc.lPitch;
98 bits += desc.dwWidth;
99 }
100 }
101
102 textureInfo->m_surface->Unlock(desc.lpSurface);
103
104 PALETTEENTRY entries[256];
105 memset(entries, 0, sizeof(entries));
106
107 for (i = 0; i < sizeOfArray(entries); i++) {
108 if (i < image->GetCount()) {
109 entries[i].peFlags = 0;
110 entries[i].peRed = image->GetPaletteEntry(i).GetRed();
111 entries[i].peGreen = image->GetPaletteEntry(i).GetGreen();
112 entries[i].peBlue = image->GetPaletteEntry(i).GetBlue();
113 }
114 else {
115 entries[i].peFlags = 0x80;
116 }
117 }
118
119 if (pDirectDraw->CreatePalette(DDPCAPS_ALLOW256 | DDPCAPS_8BIT, entries, &textureInfo->m_palette, NULL) != DD_OK) {
120 goto done;
121 }
122
123 textureInfo->m_surface->SetPalette(textureInfo->m_palette);
124
125 if (((TglImpl::RendererImpl*) VideoManager()->GetRenderer())
126 ->CreateTextureFromSurface(textureInfo->m_surface, &textureInfo->m_texture) != D3DRM_OK) {
127 goto done;
128 }
129
130 textureInfo->m_texture->SetAppData((DWORD) textureInfo);
131 return textureInfo;
132
133done:
134 if (textureInfo->m_name != NULL) {
135 delete[] textureInfo->m_name;
136 textureInfo->m_name = NULL;
137 }
138
139 if (textureInfo->m_palette != NULL) {
140 textureInfo->m_palette->Release();
141 textureInfo->m_palette = NULL;
142 }
143
144 if (textureInfo->m_surface != NULL) {
145 textureInfo->m_surface->Release();
146 textureInfo->m_surface = NULL;
147 }
148
149 if (textureInfo != NULL) {
150 delete textureInfo;
151 }
152
153 return NULL;
154}
155
156// FUNCTION: LEGO1 0x10065f60
158{
159 TglImpl::MeshImpl::MeshData* data = ((TglImpl::MeshImpl*) pMesh)->ImplementationData();
160 data->groupMesh->SetGroupTexture(data->groupIndex, p_textureInfo->m_texture);
161 return TRUE;
162}
163
164// FUNCTION: LEGO1 0x10065f90
166{
167 TglImpl::MeshImpl::MeshData* data = ((TglImpl::MeshImpl*) pMesh)->ImplementationData();
168
169 IDirect3DRMMesh* mesh = data->groupMesh;
170 D3DRMGROUPINDEX id = data->groupIndex;
171 LPDIRECT3DRMTEXTURE returnPtr = NULL;
172 LPDIRECT3DRMTEXTURE2 texture = NULL;
173
174 if (mesh->GetGroupTexture(id, &returnPtr) == D3DRM_OK) {
175 if (returnPtr->QueryInterface(IID_IDirect3DRMTexture2, (LPVOID*) &texture) == D3DRM_OK) {
176 p_textureInfo = (LegoTextureInfo*) texture->GetAppData();
177
178 texture->Release();
179 returnPtr->Release();
180 }
181
182 return TRUE;
183 }
184
185 return FALSE;
186}
187
188// FUNCTION: LEGO1 0x10066010
190{
191 if (m_surface != NULL && m_texture != NULL) {
192 DDSURFACEDESC desc;
193 memset(&desc, 0, sizeof(desc));
194 desc.dwSize = sizeof(desc);
195
196 if (m_surface->Lock(NULL, &desc, 0, NULL) == DD_OK) {
197 MxU8* surface = (MxU8*) desc.lpSurface;
198 const LegoU8* bits = p_bits;
199
200 if (desc.dwWidth == desc.lPitch) {
201 memcpy(desc.lpSurface, p_bits, desc.dwWidth * desc.dwHeight);
202 }
203 else {
204 for (MxS32 i = 0; i < desc.dwHeight; i++) {
205 memcpy(surface, bits, desc.dwWidth);
206 surface += desc.lPitch;
207 bits += desc.dwWidth;
208 }
209 }
210
211 m_surface->Unlock(desc.lpSurface);
212 m_texture->Changed(TRUE, FALSE);
213 return SUCCESS;
214 }
215 }
216
217 return FAILURE;
218}
[AI] Class representing an 8-bit palettized image with up to 256 palette entries and indexed pixel da...
Definition: legoimage.h:68
LegoU32 GetWidth()
[AI] Returns the current image width in pixels.
Definition: legoimage.h:82
LegoPaletteEntry & GetPaletteEntry(LegoU32 p_i)
[AI] Returns a reference to the palette entry at index p_i.
Definition: legoimage.h:107
LegoU8 * GetBits()
[AI] Returns pointer to the buffer containing indexed pixel data.
Definition: legoimage.h:116
LegoU32 GetHeight()
[AI] Returns the current image height in pixels.
Definition: legoimage.h:89
LegoU8 GetBlue()
[AI] Returns the blue color intensity of this palette entry.
Definition: legoimage.h:40
LegoU8 GetRed()
[AI] Returns the red color intensity of this palette entry.
Definition: legoimage.h:26
LegoU8 GetGreen()
[AI] Returns the green color intensity of this palette entry.
Definition: legoimage.h:33
[AI] Contains DirectDraw and Direct3DRM handles and metadata for a texture used in the LEGO Island re...
static BOOL GetGroupTexture(Tgl::Mesh *pMesh, LegoTextureInfo *&p_textureInfo)
[AI] Retrieves the LegoTextureInfo currently attached to the supplied mesh group.
static BOOL SetGroupTexture(Tgl::Mesh *pMesh, LegoTextureInfo *p_textureInfo)
[AI] Assigns a Direct3DRM texture group from a LegoTextureInfo to a mesh group via the Tgl/Microsoft ...
LegoTextureInfo()
[AI] Constructor.
LegoResult FUN_10066010(const LegoU8 *p_bits)
[AI] Updates the pixel bits for the current surface/texture with the provided bitmap data.
LPDIRECTDRAWPALETTE m_palette
[AI] DirectDraw palette object (8-bit) assigned to the m_surface.
LPDIRECTDRAWSURFACE m_surface
[AI] DirectDraw surface holding the 8-bit indexed image for the texture.
LPDIRECT3DRMTEXTURE2 m_texture
[AI] Direct3DRM texture object used by retained-mode rendering.
~LegoTextureInfo()
[AI] Destructor.
char * m_name
[AI] Pointer to the logical name string for this texture (allocated; e.g., "BROWN_ROOF").
static LegoTextureInfo * Create(const char *p_name, LegoTexture *p_texture)
[AI] Creates a new LegoTextureInfo for a given logical name and loaded LegoTexture.
[AI] Represents a texture which wraps a LegoImage and provides loading/saving functionality.
Definition: legotexture.h:15
LegoImage * GetImage()
[AI] Returns the associated image used by this texture.
Definition: legotexture.h:25
MxDirect3D * GetDirect3D()
[AI] Returns the active Direct3D wrapper (engine/utility) object.
IDirectDraw * DirectDraw()
Returns the DirectDraw device interface pointer.
Definition: mxdirectdraw.h:82
[AI] Implementation of Tgl::Mesh, manages a mesh object and geometry data with group index [AI]
Definition: impl.h:816
[AI] Implements Tgl::MeshBuilder; facilitates mesh construction [AI]
Definition: impl.h:55
[AI] Represents a renderable 3D mesh.
Definition: tgl.h:596
LPSTR LPSTR LPVOID
Definition: d3dcaps.h:216
#define D3DRM_OK
Definition: d3drm.h:197
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
LONG D3DRMGROUPINDEX
Definition: d3drmdef.h:334
#define DDSD_WIDTH
Definition: ddraw.h:1174
#define DDSD_PIXELFORMAT
Definition: ddraw.h:1205
#define DDCAPS_OVERLAY
Definition: ddraw.h:1610
#define DDPCAPS_ALLOW256
Definition: ddraw.h:2122
#define DDSD_HEIGHT
Definition: ddraw.h:1169
typedef DWORD(FAR PASCAL *LPCLIPPERCALLBACK)(LPDIRECTDRAWCLIPPER lpDDClipper
#define DDCAPS_OVERLAYCANTCLIP
Definition: ddraw.h:1615
#define DDPF_RGB
Definition: ddraw.h:2404
#define DD_OK
Definition: ddraw.h:3166
#define DDPF_PALETTEINDEXED8
Definition: ddraw.h:2399
#define DDPCAPS_8BIT
Definition: ddraw.h:2096
#define DDLOCK_SURFACEMEMORYPTR
Definition: ddraw.h:2909
struct IDirectDraw FAR * LPDIRECTDRAW
Definition: ddraw.h:72
#define DDSD_CAPS
Definition: ddraw.h:1164
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define sizeOfArray(arr)
Definition: decomp.h:23
typedef BOOL(FAR PASCAL *LPDIENUMDEVICEOBJECTSCALLBACKA)(LPCDIDEVICEOBJECTINSTANCEA
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
unsigned char LegoU8
[AI] Unsigned 8-bit integer type used throughout LEGO Island.
Definition: legotypes.h:47
LegoS32 LegoResult
[AI] Function result type (return code): typically SUCCESS (0) or FAILURE (-1).
Definition: legotypes.h:101
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
LegoVideoManager * VideoManager()
[AI] Accessor for the game's LegoVideoManager subsystem. Used for managing 3D/video hardware....
Definition: misc.cpp:29
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
[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
DWORD dwSize
Definition: ddraw.h:343
DWORD dwRGBBitCount
Definition: ddraw.h:348
DWORD dwFlags
Definition: ddraw.h:344
DWORD dwCaps
Definition: ddraw.h:196
DDSCAPS ddsCaps
Definition: ddraw.h:1158
LPVOID lpSurface
Definition: ddraw.h:1152
DDPIXELFORMAT ddpfPixelFormat
Definition: ddraw.h:1157
LONG lPitch
Definition: ddraw.h:1140
DWORD dwSize
Definition: ddraw.h:1134
DWORD dwFlags
Definition: ddraw.h:1135
DWORD dwWidth
Definition: ddraw.h:1137
DWORD dwHeight
Definition: ddraw.h:1136