29 DDSURFACEDESC2 work_surface_desc;
30 memset(&work_surface_desc, 0, 0x7c);
33 work_surface_desc.dwSize = 0x7c;
34 work_surface_desc.dwFlags = 0;
36 if (!quadrant_surfaces)
38 Debug_Log(
"CopyMem_Texture(): lpTex == NULL!",
"Error");
44 DDSURFACEDESC2 source_surface_desc;
45 source_surface_desc.dwSize = 0x7c;
48 IDirectDrawSurface7 *source_surface = (IDirectDrawSurface7 *)(*(uint32_t *)quadrant_surfaces);
51 source_surface->lpVtbl->GetSurfaceDesc(source_surface, &source_surface_desc);
54 IDirectDrawSurface7 *work_surface =
59 Debug_Log(
"work surface is NULL!",
"Error");
65 error_code = work_surface->lpVtbl->Lock(work_surface, NULL, &work_surface_desc, DDLOCK_WAIT, NULL);
69 char *message =
"DirectX Error: Lock();";
77 void *lp_surface = work_surface_desc.lpSurface;
81 Debug_Log(
"Cannot get surface pointer!",
"DirectX Error");
86 uint16_t *dst_pixel = lp_surface;
87 int32_t pixel_index = 0;
97 }
while (++pixel_index < pixel_count);
99 work_surface->lpVtbl->Unlock(work_surface, NULL);
101 IDirectDrawSurface7 *top_left_surface = (IDirectDrawSurface7 *)(*(uint32_t *)quadrant_surfaces);
102 DDBLTFX *top_left_blit_effects = NULL;
104 DWORD top_left_blit_flags = DDBLT_WAIT;
107 RECT *top_left_source_rect = &source_rect;
108 source_rect = (RECT){
115 top_left_surface->lpVtbl->Blt(top_left_surface, NULL, work_surface, top_left_source_rect, top_left_blit_flags, top_left_blit_effects);
117 int32_t *top_right_surface = (int32_t *)(quadrant_surfaces[1]);
118 int32_t top_right_blit_effects = 0;
119 int32_t top_right_blit_flags = DDBLT_WAIT;
123 RECT *top_right_source_rect = &source_rect;
125 source_rect = (RECT){
131 ((IDirectDrawSurface7 *)top_right_surface)->lpVtbl->Blt((IDirectDrawSurface7 *)(top_right_surface), 0, work_surface, top_right_source_rect, top_right_blit_flags, (LPDDBLTFX)(top_right_blit_effects));
133 int32_t *bottom_right_surface = (int32_t *)(quadrant_surfaces[2]);
134 int32_t bottom_right_blit_effects = 0;
135 int32_t bottom_right_blit_flags = DDBLT_WAIT;
139 RECT *bottom_right_source_rect = &source_rect;
142 "\x41\x01\x00\x00\xf1\x00\x00\x00\x80\x02\x00\x00\xe0\x01\x00\x00", 0x10);
144 ((IDirectDrawSurface7 *)bottom_right_surface)->lpVtbl->Blt((IDirectDrawSurface7 *)(bottom_right_surface), 0, work_surface, bottom_right_source_rect, bottom_right_blit_flags, (LPDDBLTFX)(bottom_right_blit_effects));
146 int32_t *bottom_left_surface = (int32_t *)(quadrant_surfaces[3]);
147 int32_t bottom_left_blit_effects = 0;
148 int32_t bottom_left_blit_flags = DDBLT_WAIT;
150 RECT *bottom_left_source_rect = &source_rect;
151 source_rect = (RECT){
161 ((IDirectDrawSurface7 *)bottom_left_surface)->lpVtbl->Blt((IDirectDrawSurface7 *)(bottom_left_surface), 0, work_surface, bottom_left_source_rect, bottom_left_blit_flags, (LPDDBLTFX)(bottom_left_blit_effects));
162 work_surface->lpVtbl->Release(work_surface);
169 int32_t x = (int16_t)packed_xy, y = (int16_t)(packed_xy >> 16);
186 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
195 float reciprocal_height = (float)(1.0L / (height_minus_one + 1));
196 float u = (float)((1.0L / (width_minus_one + 1)) * width_minus_one);
197 float v = (float)((
long double)height_minus_one * reciprocal_height);
204 device->lpVtbl->SetTexture(device, 0, surface);
207 uint32_t packed_top_color = (uint32_t)alpha << 24 | (top_color & 0xff) << 16 | (top_color & 0xff00) | ((top_color >> 16) & 0xff);
208 uint32_t packed_bottom_color = (uint32_t)alpha << 24 | (bottom_color & 0xff) << 16 | (bottom_color & 0xff00) | ((bottom_color >> 16) & 0xff);
220 memcpy(&depth, &depth_bits,
sizeof depth);
222 for (
int i = 0; i < 4; ++i)
224 vertices[i].x = (float)(x + ((i & 1) ? quad_size : 0));
225 vertices[i].y = (float)(y + ((i & 2) ? quad_size : 0));
226 vertices[i].z = depth;
227 vertices[i].rhw = depth;
228 vertices[i].color = (i & 2) ? packed_bottom_color : packed_top_color;
229 vertices[i].u = (i & 1) ? u : 0.0f;
230 vertices[i].v = (i & 2) ? v : 0.0f;
233 device->lpVtbl->DrawPrimitive(device, D3DPT_TRIANGLESTRIP, (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1), vertices, 4, 0);
236 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
243 int32_t left = (int32_t)(int16_t)packed_xy;
245 int32_t top = (int32_t)(int16_t)(packed_xy >> 0x10);
246 uint32_t texture_descriptor_data;
251 int32_t material_width;
253 if (!material || !texture_descriptor_data)
259 material_width = material_width_minus_one + 1;
262 uint32_t texture_descriptor_data_height;
267 int32_t material_height;
269 if (!material || !texture_descriptor_data_height)
275 material_height = material_height_minus_one + 1;
280 char blend_mode = requested_blend_mode;
282 if (!requested_blend_mode)
298 disable_depth_device->lpVtbl->SetRenderState(disable_depth_device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
310 float reciprocal_texture_height = (float)((
long double)1.0f / (
long double)(uv_height_minus_one + 1));
311 long double maximum_u = (
long double)1.0f / (
long double)(uv_width_minus_one + 1) * (
long double)uv_width_minus_one;
312 float v1_u = (float)maximum_u;
313 long double maximum_v = (
long double)uv_height_minus_one * (
long double)reciprocal_texture_height;
314 float v2_v = (float)maximum_v;
315 float v3_u = (float)maximum_u;
316 float v3_v = (float)maximum_v;
324 texture_device->lpVtbl->SetTexture(texture_device, 0, texture_surface);
327 uint32_t alpha_bits = (uint32_t)blend_alpha << 8;
328 int32_t top_blue_byte = (uint8_t)((uint8_t)((uint32_t)top_color >> 16));
329 int32_t packed_top_color =
333 ((uint32_t)(uint8_t)top_color | alpha_bits) << 0x10 | top_blue_byte | (top_color & 0xff00);
334 long double left_precise = (
long double)left;
335 uint32_t v0_color = packed_top_color;
336 float v0_x = (float)left_precise;
337 long double top_precise = (
long double)top;
338 int32_t bottom_blue_byte = (uint8_t)((uint8_t)((uint32_t)bottom_color >> 16));
339 uint32_t v1_color = packed_top_color;
340 float v0_y = (float)top_precise;
344 long double right_precise = (
long double)(material_width + left);
345 int32_t packed_bottom_color =
349 ((uint32_t)(uint8_t)bottom_color | alpha_bits) << 0x10 | bottom_blue_byte | (bottom_color & 0xff00);
350 float v1_x = (float)right_precise;
351 float v1_y = (float)top_precise;
352 float v3_x = (float)right_precise;
353 float v2_x = (float)left_precise;
354 long double bottom_precise = (
long double)(material_height + top);
355 float v0_z = 9.99999997e-07f;
356 float v0_rhw = 9.99999997e-07f;
357 float v1_z = 9.99999997e-07f;
358 float v2_y = (float)bottom_precise;
359 float v3_y = (float)bottom_precise;
360 float v1_rhw = 9.99999997e-07f;
361 float v2_z = 9.99999997e-07f;
362 float v2_rhw = 9.99999997e-07f;
363 uint32_t v2_color = packed_bottom_color;
364 float v3_z = 9.99999997e-07f;
365 float v3_rhw = 9.99999997e-07f;
366 uint32_t v3_color = packed_bottom_color;
378 {v0_x, v0_y, v0_z, v0_rhw, v0_color, v0_u, v0_v},
379 {v1_x, v1_y, v1_z, v1_rhw, v1_color, v1_u, v1_v},
380 {v2_x, v2_y, v2_z, v2_rhw, v2_color, v2_u, v2_v},
381 {v3_x, v3_y, v3_z, v3_rhw, v3_color, v3_u, v3_v}};
383 draw_device->lpVtbl->DrawPrimitive(draw_device, D3DPT_TRIANGLESTRIP, (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1), vertices, 4, 0);
388 restore_depth_device->lpVtbl->SetRenderState(restore_depth_device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
394 return value > 255 ? 255 : value;
399 for (
unsigned i = 0; i < 4; ++i)
410 return count == 4 && slot >= 2 ? 5 - slot : slot;
416 device->lpVtbl->SetTextureStageState(device, 0, state, address);
437 for (
unsigned slot = 0; slot < count; ++slot)
440 vertices[slot].
uv.
u = (float)((
long double)polygon->
tex_uvs[i].
u * u_scale + inset);
441 vertices[slot].
uv.
v = (float)((
long double)polygon->
tex_uvs[i].
v * v_scale + inset);
449 device->lpVtbl->SetTexture(device, 0, surface);
461 for (
unsigned i = 0; i < 4; ++i)
467 for (
unsigned i = 0; i < count; ++i)
477 D3DPRIMITIVETYPE primitive,
unsigned count, uint8_t alpha, BOOL textured)
483 for (
unsigned slot = 0; slot < count; ++slot)
490 out->
depth = (float)(((
long double)polygon->
depth_bias + z) / 65536.0L);
498 out->
diffuse_color = ((uint32_t)alpha << 24) | (red << 16) | (green << 8) | blue;
499 out->
rhw = (float)((
long double)reciprocal_z / z);
502 if (primitive == D3DPT_LINESTRIP)
505 lines[count++] = lines[0];
510 for (
unsigned slot = 0; slot < count; ++slot)
511 vertices[slot]->
depth = (
float)((
long double)offset + vertices[slot]->
depth);
515 for (
unsigned slot = 0; slot < 4; ++slot)
516 if (vertices[slot]->
depth > 0.99f)
517 vertices[slot]->
depth = 0.99f;
519 DWORD format = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
521 format |= D3DFVF_TEX1;
523 device->lpVtbl->DrawPrimitive(device, primitive, format,
g_quadVertexPtrs, count, 0);
530 uint32_t flags = polygon->
flags;
542 for (
unsigned i = 0; i < 4; ++i)
554 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
561 BOOL textured = FALSE;
567 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_LINEPATTERN,
585 BOOL reverse_wire_vertices = FALSE;
599 for (
unsigned i = 0; i < 4; ++i)
622 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
631 int32_t left = (int32_t)(int16_t)packed_origin_xy;
632 uint8_t red = (uint8_t)rgb_color;
633 int32_t top = (int32_t)(int16_t)(packed_origin_xy >> 0x10);
635 int32_t rectangle_width = (int32_t)(int16_t)packed_size_wh;
637 int32_t rectangle_height = (int32_t)(int16_t)(packed_size_wh >> 0x10);
639 uint8_t green = (uint8_t)(rgb_color >> 8);
640 uint8_t blue = (uint8_t)(rgb_color >> 16);
643 requested_blend_mode = 0;
669 red = ((uint32_t)red * intensity_q12 + 0x800) >> 0xc;
671 (char)(((uint32_t)green * intensity_q12 + 0x800) >> 0xc);
672 blue = (char)(((uint32_t)blue * intensity_q12 + 0x800) >> 0xc);
688 disable_depth_device->lpVtbl->SetRenderState(disable_depth_device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
693 long double left_precise = (
long double)left;
694 float top_left_x = (float)left_precise;
695 long double top_precise = (
long double)top;
698 float top_left_y = (float)top_precise;
699 long double right_precise = (
long double)(rectangle_width + left);
700 float top_right_x = (float)right_precise;
701 float top_right_y = (float)top_precise;
702 float bottom_left_x = (float)left_precise;
703 uint32_t
diffuse_color = ((uint32_t)alpha << 24) | ((uint32_t)red << 16) | ((uint32_t)green << 8) | blue;
704 long double bottom_precise = (
long double)(rectangle_height + top);
705 float bottom_right_x = (float)right_precise;
706 float bottom_left_y = (float)bottom_precise;
707 float bottom_right_y = (float)bottom_precise;
716 {top_left_x, top_left_y, 9.99999997e-7f, 9.99999997e-7f, (uint32_t)
diffuse_color},
717 {top_right_x, top_right_y, 9.99999997e-7f, 9.99999997e-7f, (uint32_t)
diffuse_color},
718 {bottom_left_x, bottom_left_y, 9.99999997e-7f, 9.99999997e-7f, (uint32_t)
diffuse_color},
719 {bottom_right_x, bottom_right_y, 9.99999997e-7f, 9.99999997e-7f, (uint32_t)
diffuse_color}};
721 draw_device->lpVtbl->DrawPrimitive(draw_device, D3DPT_TRIANGLESTRIP, (D3DFVF_XYZRHW | D3DFVF_DIFFUSE), vertices, 4, 0);
726 restore_depth_device->lpVtbl->SetRenderState(restore_depth_device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
736 uint32_t depth_bits = 0x3f7fbe77;
739 __builtin_memcpy(&
depth, &depth_bits,
sizeof(
depth));
742 {{0.0f, 0.0f},
depth,
depth, 0xffffffff, {0.0f, 0.0f}},
743 {{half_width, 0.0f},
depth,
depth, 0xffffffff, {1.0f, 0.0f}},
744 {{0.0f, half_height},
depth,
depth, 0xffffffff, {0.0f, 1.0f}},
745 {{half_width, half_height},
depth,
depth, 0xffffffff, {1.0f, 1.0f}}};
747 for (
int quadrant = 0; quadrant < 4; ++quadrant)
750 IDirectDrawSurface7 *texture = texture_set->
quadrants[quadrant];
752 device->lpVtbl->SetTexture(device, 0, texture);
761 float left = quadrant == 3 ? 0.0f : half_width;
763 float top = quadrant == 1 ? 0.0f : half_height;
773 device->lpVtbl->DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, vertices, 4, 0);
785 top_right_color, bottom_left_color, bottom_right_color);
#define Camera_SetupClipPlanes_NearClipDistanceSource
void Debug_Log(char const *category, char const *message)
#define g_currentGameMode
#define GRAPHICS_CAP_DEPTH_BUFFER
#define GRAPHICS_STIPPLE_PATTERN
#define GRAPHICS_TRIANGLE_FOURTH_VERTEX
#define GRAPHICS_SCREEN_QUAD_DEPTH_BITS
#define GRAPHICS_DEFAULT_WIDTH
#define GRAPHICS_RECT_INTENSITY_MODE_MASK
#define GRAPHICS_RECT_INTENSITY_VALUE_MASK
#define BATCH_RENDER_FORCE_SOLID
@ GRAPHICS_VERTEX_LAYOUT_TEXTURED
@ GRAPHICS_VERTEX_LAYOUT_COLOR
#define SPRITE_RENDER_BLEND_MODE_SHIFT
@ GRAPHICS_BLEND_ADDITIVE_DIM
#define GRAPHICS_CAP_TEXTURE_REPEAT
#define GRAPHICS_DEFAULT_HEIGHT
#define BATCH_RENDER_WIREFRAME
#define SPRITE_RENDER_BLEND_MODE_MASK
#define GRAPHICS_RECT_BLACK_ALPHA_MODE
#define GRAPHICS_STIPPLE_PATTERN_SHIFT
#define GRAPHICS_CAP_WIREFRAME
#define BATCH_RENDER_STIPPLED
#define GRAPHICS_STIPPLE_REPEAT
#define GRAPHICS_CAP_DEPTH_BUFFER_SHIFT
void Graphics_EndRendering(void)
void Graphics_DrawFilledRectangleGradient(int32_t packed_origin_xy, int32_t packed_size_wh, uint32_t top_left_rgb, uint32_t top_right_rgb, uint32_t bottom_left_rgb, uint32_t bottom_right_rgb)
void Graphics_ClipAndDrawPolygon(struct Graphics_Render_PolygonBatchRecord *batch, struct D3D_TransformedVertex const *prepared_vertices, uint8_t alpha_byte, int32_t unused_batch_alias, int32_t brighten_colors)
int32_t Graphics_SelectTextureLOD(struct Graphics_Render_PolygonBatchRecord *batch)
void Graphics_IncrementPassCounter(void)
#define Graphics_WindowWidth
#define g_graphicsCapabilities_high_byte
#define g_quadVertexColorB
#define graphics_pixel_green_shift
#define g_quadVertexColorR
#define g_graphicsCapabilities
#define g_quadVertexColorG
#define Graphics_WindowHeight
#define graphics_text_rendering_mode
#define MATERIAL_BLEND_MODE_SHIFT
#define MATERIAL_BLEND_MODE_MASK
#define MATERIAL_DEPTH_SORT
#define MATERIAL_BLEND_ENABLED
#define MATERIAL_NEAR_LOD
static void Graphics_SetStageAddress(D3DTEXTURESTAGESTATETYPE state, D3DTEXTUREADDRESS address)
void Graphics_RenderTexturedQuad(uint32_t packed_xy, struct Material_TableEntry *material, uint32_t render_flags, uint32_t top_color, uint32_t bottom_color, int32_t quad_size)
static BOOL Graphics_PolygonNeedsClipping(const struct Graphics_Render_PolygonBatchRecord *polygon, unsigned count)
static unsigned Graphics_StripSourceIndex(unsigned slot, unsigned count)
void Graphics_RenderTexturedQuadMaterialSize(uint32_t packed_xy, struct Material_TableEntry *material, uint32_t render_flags, uint32_t top_color, uint32_t bottom_color)
static void Graphics_TintPolygonColors(const struct Graphics_Render_PolygonBatchRecord *polygon, uint32_t tint)
void Graphics_ClearScreenAndRenderRectangle(uint32_t top_left_color, uint32_t top_right_color, uint32_t bottom_left_color, uint32_t bottom_right_color)
static void Graphics_PreparePolygonTexture(struct Graphics_Render_PolygonBatchRecord *polygon, struct Material_RuntimeDescriptor *texture, unsigned lod)
void Graphics_DrawRectangle(int32_t packed_origin_xy, int32_t packed_size_wh, int32_t blend_flags, uint32_t rgb_color)
static uint32_t Graphics_ClampChannel(uint32_t value)
static void Graphics_SubmitProjectedPolygon(const struct Graphics_Render_PolygonBatchRecord *polygon, D3DPRIMITIVETYPE primitive, unsigned count, uint8_t alpha, BOOL textured)
void Graphics_DrawFullscreenTextureQuadrants(struct Material_BlendTextureSet *texture_set)
int32_t Graphics_DrawQuad(struct Graphics_Render_PolygonBatchRecord *polygon)
void Graphics_BlitTextureToQuadrants(IDirectDrawSurface7 **quadrant_surfaces, uint8_t *pixel_data, int32_t pixel_count, int32_t width, int32_t height)
struct Graphics_Render_ScreenVertexI16Z screen_vertices[0x4]
struct Material_RuntimeDescriptor * texture_desc
struct Graphics_Render_PolygonBatchRecord::@145031042204155336373271307321163127250224235021::@310256361111253022321370021321105232356207344074 texture_repeat_count
uint32_t render_state_flags
struct Math_UV8 tex_uvs[0x4]
struct Math_Vec3F view_vertices[0x4]
uint32_t vertex_colors[0x4]
struct Graphics_Render_ScreenVertexI16Z::@276010272006271151340046314217100172252315123166::@167176104245357063215260323150214177117323053225 screen
IDirectDrawSurface7 * quadrants[0x4]
uint32_t average_transparent_color
IDirectDrawSurface7 * texture_handles[0x19]
struct Math_SizeU8 dimensions_minus_1
struct Material_RuntimeDescriptor * texture_descriptor
#define g_greenBitsToDiscard
#define g_renderingStateFlag
#define g_currentVertexFormat
#define g_blueBitsToDiscard
#define g_redBitsToDiscard
#define g_untexturedVertexBuffer
#define g_renderFrameCount
#define g_currentBoundTextureSurface