102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
textures.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
11#include "pcdogs/math/types.h"
13#include <math.h>
14#include <stdarg.h>
15#include <string.h>
16
17// Original pcdogs.exe: 0x413b00
18// Creates four loading-screen texture surfaces and uploads the source image into their quadrants. Allocation failures are logged but do not stop the upload path.
20{
21 // Creates first blend texture surface with mipmaps
24 g_loadingScreenTexture.quadrants[0] = top_left_surface;
25
26 if (!top_left_surface)
27 // Creates second blend texture surface with mipmaps
28 Debug_Log("lpTex[0] = NULL.", "Error");
29
30 // Creates third blend texture surface with mipmaps
32 g_loadingScreenTexture.quadrants[1] = top_right_surface;
33
34 if (!top_right_surface)
35 // Creates fourth blend texture surface with mipmaps
36 Debug_Log("lpTex[1] = NULL.", "Error");
37
39 g_loadingScreenTexture.quadrants[2] = bottom_right_surface;
40
41 if (!bottom_right_surface)
42 Debug_Log("lpTex[2] = NULL.", "Error");
43
45 g_loadingScreenTexture.quadrants[3] = bottom_left_surface;
46
47 if (!bottom_left_surface)
48 Debug_Log("lpTex[3] = NULL.", "Error");
49
51
53}
54
55// Original pcdogs.exe: 0x4175c0
56// Selects a texture variant from polygon depth, material flags and graphics capabilities. Minus one requests the average-color untextured fallback rather than skipping the polygon.
58{
59 uint32_t capabilities = g_graphicsCapabilities;
60 bool near_lod = (capabilities & (GRAPHICS_CAP_NEAR_LOD | GRAPHICS_CAP_DEPTH_BUFFER)) == GRAPHICS_CAP_NEAR_LOD &&
61 (polygon->flags & MATERIAL_NEAR_LOD);
62 bool far_lod = (capabilities & GRAPHICS_CAP_FAR_LOD) && (polygon->flags & MATERIAL_FAR_LOD);
63 if (!near_lod && !far_lod)
64 return !(capabilities & GRAPHICS_CAP_DEPTH_BUFFER);
65
66 /* A triangle contributes its first depth twice to the four-slot average. */
68 int32_t depth_sum = polygon->screen_vertices[0].z + polygon->screen_vertices[1].z +
69 polygon->screen_vertices[2].z + polygon->screen_vertices[triangle ? 0 : 3].z;
70 int32_t average_depth = depth_sum >> 2;
71 int32_t scale = render_list_state->dynamic_level_scale;
72 int32_t near_threshold = scale / 4;
73 int32_t far_threshold = scale / 2;
74 int32_t interval = far_threshold - near_threshold;
75 int32_t lod = 1;
76 if (average_depth <= near_threshold)
77 return lod;
78
79 if (near_lod)
80 {
81 if (average_depth >= far_threshold)
82 return -1;
83 lod += ((average_depth - near_threshold) * 8) / interval;
84 }
85 if (far_lod)
86 lod += average_depth > near_threshold + interval / 2 ? 16 : 8;
87 return lod;
88}
89
90// Original pcdogs.exe: 0x42cda0
91// Loads the four loading-screen textures and returns their shared texture-set descriptor.
98
99// Original pcdogs.exe: 0x42cdb0
100// Releases each of the four texture surfaces in the supplied set without clearing its entries.
102{
103 Material_ReleaseSingleTexture(blend_textures->quadrants[0]);
104 Material_ReleaseSingleTexture(blend_textures->quadrants[1]);
105 Material_ReleaseSingleTexture(blend_textures->quadrants[2]);
106 Material_ReleaseSingleTexture(blend_textures->quadrants[3]);
107}
void Debug_Log(char const *category, char const *message)
Definition diagnostics.c:17
#define GRAPHICS_CAP_DEPTH_BUFFER
Definition constants.h:16
#define GRAPHICS_TRIANGLE_FOURTH_VERTEX
Definition constants.h:30
#define GRAPHICS_TEXTURE_MAX_DIMENSION
Definition constants.h:28
#define GRAPHICS_DEFAULT_WIDTH
Definition constants.h:25
#define GRAPHICS_DEFAULT_HEIGHT
Definition constants.h:26
#define GRAPHICS_CAP_FAR_LOD
Definition constants.h:22
#define GRAPHICS_CAP_NEAR_LOD
Definition constants.h:19
void Graphics_BlitTextureToQuadrants(IDirectDrawSurface7 **quadrant_surfaces, uint8_t *pixel_data, int32_t pixel_count, int32_t width, int32_t height)
Definition primitives.c:27
#define graphics_tex_needs_alpha
Definition globals.h:236
#define g_graphicsCapabilities
Definition globals.h:284
#define render_list_state
Definition globals.h:152
void Graphics_FreeTextureBlend(struct Material_BlendTextureSet *blend_textures)
Definition textures.c:101
struct Material_BlendTextureSet * Graphics_InitializeTextureBlendTextures(uint8_t *pixel_data)
Definition textures.c:92
int32_t Graphics_SelectTextureLOD(struct Graphics_Render_PolygonBatchRecord *polygon)
Definition textures.c:57
struct Material_BlendTextureSet * Graphics_LoadAndUploadTexture(uint8_t *pixel_data)
Definition textures.c:19
#define MATERIAL_FAR_LOD
Definition constants.h:37
#define MATERIAL_NEAR_LOD
Definition constants.h:31
void Material_ReleaseSingleTexture(IDirectDrawSurface7 *texture_surface)
Definition textures.c:49
#define g_loadingScreenTexture
Definition globals.h:9
IDirectDrawSurface7 * D3D_CreateTextureSurface(uint32_t width, uint32_t height)
struct Graphics_Render_ScreenVertexI16Z screen_vertices[0x4]
Definition types.h:512
IDirectDrawSurface7 * quadrants[0x4]
Definition types.h:38