Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
LegacyAssets.cpp
Go to the documentation of this file.
1#include "LegacyAssets.hpp"
2
3#include <cstring>
4#include <filesystem>
5#include <iostream>
6
8{
9 namespace
10 {
11 SDL_GPUDevice* gpuDevice = nullptr;
12
13 Texture2D background;
14
15
16 bool loadBMPTexture(
17 const std::filesystem::path& path,
19 {
21 SDL_LoadBMP(path.string().c_str());
22
23 if (source == nullptr)
24 {
25 std::cerr
26 << "Unable to load legacy BMP: "
27 << path.string()
28 << " : "
29 << SDL_GetError()
30 << '\n';
31
32 return false;
33 }
34
35 SDL_Surface* rgba =
37 source,
39 );
40
42
43 if (rgba == nullptr)
44 {
45 std::cerr
46 << "Unable to convert legacy BMP: "
47 << SDL_GetError()
48 << '\n';
49
50 return false;
51 }
52
53 const Uint32 width =
54 static_cast<Uint32>(rgba->w);
55
56 const Uint32 height =
57 static_cast<Uint32>(rgba->h);
58
59 const Uint32 bytesPerPixel = 4;
60
61 const Uint32 uploadSize =
62 width *
63 height *
65
66
68
69 textureInfo.type =
71
72 textureInfo.format =
74
75 textureInfo.usage =
77
78 textureInfo.width = width;
79 textureInfo.height = height;
80
81 textureInfo.layer_count_or_depth = 1;
82 textureInfo.num_levels = 1;
83
84 textureInfo.sample_count =
86
87
92 );
93
94 if (texture == nullptr)
95 {
96 std::cerr
97 << "SDL_CreateGPUTexture failed: "
98 << SDL_GetError()
99 << '\n';
100
101 SDL_DestroySurface(rgba);
102 return false;
103 }
104
105
107
108 transferInfo.usage =
110
111 transferInfo.size =
113
114
117 gpuDevice,
119 );
120
121 if (transfer == nullptr)
122 {
124 gpuDevice,
125 texture
126 );
127
128 SDL_DestroySurface(rgba);
129
130 return false;
131 }
132
133
134 void* mapped =
136 gpuDevice,
137 transfer,
138 false
139 );
140
141 if (mapped == nullptr)
142 {
144 gpuDevice,
146 );
147
149 gpuDevice,
150 texture
151 );
152
153 SDL_DestroySurface(rgba);
154
155 return false;
156 }
157
158
159 auto* destinationPixels =
160 static_cast<unsigned char*>(mapped);
161
162 const auto* sourcePixels =
163 static_cast<const unsigned char*>(
164 rgba->pixels
165 );
166
167 const std::size_t packedRowSize =
168 static_cast<std::size_t>(width) *
170
171 for (Uint32 y = 0; y < height; ++y)
172 {
173 std::memcpy(
175 static_cast<std::size_t>(y) *
177
179 static_cast<std::size_t>(y) *
180 rgba->pitch,
181
183 );
184 }
185
186
188 gpuDevice,
190 );
191
192 SDL_DestroySurface(rgba);
193
194
198 );
199
200 if (commandBuffer == nullptr)
201 {
203 gpuDevice,
205 );
206
208 gpuDevice,
209 texture
210 );
211
212 return false;
213 }
214
215
219 );
220
221 if (copyPass == nullptr)
222 {
225 );
226
228 gpuDevice,
230 );
231
233 gpuDevice,
234 texture
235 );
236
237 return false;
238 }
239
240
242
243 sourceInfo.transfer_buffer =
244 transfer;
245
246 sourceInfo.offset = 0;
247
248 sourceInfo.pixels_per_row =
249 width;
250
251 sourceInfo.rows_per_layer =
252 height;
253
254
256
257 destinationRegion.texture =
258 texture;
259
260 destinationRegion.mip_level = 0;
261 destinationRegion.layer = 0;
262
263 destinationRegion.x = 0;
264 destinationRegion.y = 0;
265 destinationRegion.z = 0;
266
269 destinationRegion.d = 1;
270
271
273 copyPass,
274 &sourceInfo,
276 false
277 );
278
280
281
284 {
286 gpuDevice,
288 );
289
291 gpuDevice,
292 texture
293 );
294
295 return false;
296 }
297
298
300 gpuDevice,
302 );
303
304
305 destination.texture =
306 texture;
307
308 destination.width =
309 width;
310
311 destination.height =
312 height;
313
314
316 gpuDevice,
317 texture,
318 "Legacy Monopoly 3D Background"
319 );
320
321 return true;
322 }
323 }
324
325
327 {
328 gpuDevice = device;
329
330 if (gpuDevice == nullptr)
331 {
332 return false;
333 }
334
335 const char* basePath =
337
338 if (basePath == nullptr)
339 {
340 return false;
341 }
342
343 const std::filesystem::path path =
344 std::filesystem::path(basePath) /
345 "assets" /
346 "legacy" /
347 "BackGround.bmp";
348
349
350 // display.cpp original :
351 //
352 // #if USA_VERSION
353 // wBmpID = IDB_BACKGROUND;
354 // #endif
355 //
356 // LE_REND3D_SetBackgroundSurface(1, ...)
357
358 return loadBMPTexture(
359 path,
360 background
361 );
362 }
363
364
365 void shutdown()
366 {
367 if (gpuDevice != nullptr &&
368 background.texture != nullptr)
369 {
371 gpuDevice,
372 background.texture
373 );
374 }
375
376 background = {};
377 gpuDevice = nullptr;
378 }
379
380
382 {
383 return background;
384 }
385}
std::shared_ptr< const data::HmdTextureImage > source
SDL_GPUTexture * texture
std::uint32_t height
std::uint32_t width
unsigned index
std::string path
const Texture2D & background3D()
bool initialize(SDL_GPUDevice *device)