45 uint32_t rotation_angle, uint32_t rotation_pivot_xy)
52 int32_t x = (int16_t)packed_xy, y = (int16_t)(packed_xy >> 16);
53 int32_t width = (int16_t)packed_wh, height = (int16_t)(packed_wh >> 16);
79 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
95 uint8_t *vertices = texture ? (uint8_t *)textured : (uint8_t *)plain;
96 size_t stride = texture ?
sizeof(textured[0]) :
sizeof(plain[0]);
104 int32_t max_u = texture_width - 1, max_v = texture_height - 1, start_u = 0, start_v = 0;
114 start_u = (texture_width >> 1) - sprite->
subrect_uv.
u - 1;
125 start_v = (texture_height >> 1) - sprite->
subrect_uv.
v - 1;
129 float du = (float)((
long double)(max_u + 1) / (texture_width * (max_u + 1)));
130 float dv = (float)((
long double)(max_v + 1) / (texture_height * (max_v + 1)));
132 {(float)((
long double)start_u * du), (float)((
long double)start_v * dv)},
133 {(float)((
long double)(start_u + max_u + 1) * du), (float)((
long double)start_v * dv)},
134 {(float)((
long double)(start_u + max_u + 1) * du), (float)((
long double)(start_v + max_v + 1) * dv)},
135 {(float)((
long double)start_u * du), (float)((
long double)(start_v + max_v + 1) * dv)}};
137 static const uint8_t uv_order[4][4] = {{0, 1, 3, 2}, {1, 0, 2, 3}, {3, 2, 0, 1}, {2, 3, 1, 0}};
141 for (
unsigned i = 0; i < 4; i++)
143 textured[i].u = uv[uv_order[rotation][i]][0];
144 textured[i].v = uv[uv_order[rotation][i]][1];
152 device->lpVtbl->SetTexture(device, 0, surface);
158 uint32_t top_color, bottom_color;
165 top_color = (alpha << 24) | ((top_color & 0xff) << 16) | (top_color & 0xff00) | ((top_color >> 16) & 0xff);
166 bottom_color = (alpha << 24) | ((bottom_color & 0xff) << 16) | (bottom_color & 0xff00) | ((bottom_color >> 16) & 0xff);
168 float positions[4][2] = {{x, y}, {x + width, y}, {x, y + height}, {x + width, y + height}};
170 if (rotation_angle & 0xfff)
172 int32_t pivot_x = (int16_t)rotation_pivot_xy, pivot_y = (int16_t)(rotation_pivot_xy >> 16);
173 int32_t sine = -(
Math_SinQ14(rotation_angle) >> 2);
174 int32_t cosine =
Math_SinQ14(0x400 - rotation_angle) >> 2;
176 for (
unsigned i = 0; i < 4; i++)
178 int32_t dx =
__ftol_msvc((
long double)positions[i][0] - pivot_x);
179 int32_t dy =
__ftol_msvc((
long double)positions[i][1] - pivot_y);
181 positions[i][0] = ((dx * cosine - dy * sine) >> 12) + pivot_x;
182 positions[i][1] = ((dy * cosine + dx * sine) >> 12) + pivot_y;
186 for (
unsigned i = 0; i < 4; i++)
188 float *vertex_components = (
float *)(vertices + i * stride);
190 vertex_components[0] = positions[i][0];
191 vertex_components[1] = positions[i][1];
195 memcpy(&vertex_components[2], &overlay_depth_bits, 4);
196 memcpy(&vertex_components[3], &overlay_depth_bits, 4);
198 uint32_t color = i < 2 ? top_color : bottom_color;
200 memcpy(&vertex_components[4], &color, 4);
203 device->lpVtbl->DrawPrimitive(device, D3DPT_TRIANGLESTRIP, (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | (texture ? D3DFVF_TEX1 : 0)), vertices, 4, 0);
206 device->lpVtbl->SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
214 int32_t *projected_slots[4];
224 int32_t vertex_slot = 3;
225 int16_t *fourth_projected_vertex;
226 int32_t **projected_slot_cursor = &projected_slots[3];
227 float *view_y_cursor = &view_xyz[10];
228 uint16_t *vertex_index_cursor = &variant_payload_ptr->
vertex_indices[3];
232 int32_t vertex_index = (uint16_t)(*(uint16_t *)vertex_index_cursor);
233 char cached_vertex_state = transformed_vertices[vertex_index].
vertex_state;
240 int32_t projected_vertex_index;
244 int32_t cached_local_z = (int32_t)source_vertex->
pos.
z;
245 int32_t cached_local_y = (int32_t)source_vertex->
pos.
y;
246 int32_t cached_local_x = (int32_t)source_vertex->
pos.
x;
249 projected_buffer = projected_vertices;
257 int32_t cached_view_z_q6 = ((cached_depth_x_product + cached_depth_y_product + cached_depth_z_product) >> 0xa) +
g_nodeViewTranslationZ;
259 *view_y_cursor = (float)((
long double)cached_view_y_q6 * (
long double)0.015625f);
260 projected_vertex_index = vertex_index;
261 view_y_cursor[1] = (float)((
long double)cached_view_z_q6 * (
long double)0.015625f);
265 int32_t local_z = (int32_t)source_vertex->
pos.
z;
266 int32_t local_y = (int32_t)source_vertex->
pos.
y;
267 int32_t local_x = (int32_t)source_vertex->
pos.
x;
275 projected_buffer = projected_vertices;
276 view_y_cursor[-1] = (float)((
long double)view_x_q6 * (
long double)0.015625f);
277 projected_vertex_index = vertex_index;
278 projected_buffer[projected_vertex_index].
screen_z = view_z_q6;
283 *view_y_cursor = (float)((
long double)view_y_q6 * (
long double)0.015625f);
284 view_y_cursor[1] = (float)((
long double)view_z_q6 * (
long double)0.015625f);
286 if (!behind_near_plane)
289 int32_t perspective_scale =
291 int64_t screen_x_product = (int64_t)perspective_scale * view_x_q6;
294 int64_t screen_y_product = (int64_t)perspective_scale * view_y_q6;
298 if (screen_x != (int32_t)(int16_t)screen_x || screen_y != (int32_t)(int16_t)screen_y)
299 projected_buffer[projected_vertex_index].
screen_z =
303 projected_buffer[projected_vertex_index].
screen.
x = (uint16_t)screen_x;
304 projected_buffer[projected_vertex_index].
screen.
y = (uint16_t)screen_y;
310 *projected_slot_cursor = (int32_t *)&projected_buffer[projected_vertex_index];
312 int32_t previous_vertex_slot = vertex_slot;
315 vertex_index_cursor -= 1;
316 projected_slot_cursor -= 1;
318 if (!previous_vertex_slot)
320 int32_t *second_projected_words = projected_slots[1];
322 fourth_projected_vertex = (int16_t *)projected_slots[3];
324 int16_t *second_projected_vertex = (int16_t *)second_projected_words;
326 int32_t *first_projected_words = projected_slots[0];
327 int32_t *third_projected_words = projected_slots[2];
328 int32_t winding_area;
334 winding_polygon = polygon_ref;
338 int16_t *third_projected_vertex = (int16_t *)third_projected_words;
343 winding_polygon = polygon_ref;
347 int16_t *quad_fourth_vertex = fourth_projected_vertex;
352 winding_polygon = polygon_ref;
356 int32_t third_screen_y = (int32_t)third_projected_vertex[1];
357 int32_t third_screen_x = (int32_t)*(int16_t *)third_projected_vertex;
358 int32_t second_screen_x = (int32_t)*(int16_t *)second_projected_vertex;
359 int32_t second_screen_y = (int32_t)second_projected_vertex[1];
360 int32_t fourth_screen_y = (int32_t)fourth_projected_vertex[1];
362 winding_area = (third_screen_x - second_screen_x) * (third_screen_y - fourth_screen_y) - (third_screen_x - (int32_t)*(int16_t *)quad_fourth_vertex) * (third_screen_y - second_screen_y);
363 winding_polygon = polygon_ref;
369 if (first_projected_words[1] <= projection_near_fp)
373 int32_t alternate_winding_product = (second_screen_y - (int32_t)((
struct Graphics_Render_ProjectedVertex *)first_projected_words)->screen.y) * (second_screen_x - (int32_t)*(int16_t *)fourth_projected_vertex);
375 winding_polygon = polygon_ref;
377 int32_t primary_winding_product = (second_screen_x - (int32_t)*(int16_t *)first_projected_words) * (second_screen_y - fourth_screen_y);
379 winding_area = primary_winding_product - alternate_winding_product;
381 if (primary_winding_product - alternate_winding_product < 0)
383 if (first_projected_words[1] <= projection_near_fp)
392 if (first_projected_words[1] <= projection_near_fp)
403 fourth_projected_vertex = NULL;
405 char *material_bytes = (
char *)winding_polygon->
material_ref;
409 int32_t saved_face_dot;
412 if (winding_area >= 0)
414 int32_t front_face_dot = (int32_t)winding_polygon->
depth_bias_q12 << 3;
416 saved_face_dot = front_face_dot;
417 face_dot = front_face_dot;
422 saved_face_dot = face_dot;
425 char *alternate_material = (
char *)((
struct Material_TableEntry *)material_bytes)->next_material_entry;
426 char *pending_material;
429 pending_material = NULL;
432 char *base_material = material_bytes;
434 material_bytes = alternate_material;
436 pending_material = base_material;
439 int32_t depth_bucket = 0;
446 int32_t first_depths_equal = 1;
447 long double three_vertex_depth_sum =
448 (
long double)view_xyz[8] + (
long double)view_xyz[5] + (
long double)view_xyz[2];
449 long double first_view_depth = (
long double)view_xyz[2];
450 long double second_view_depth = (
long double)view_xyz[5];
453 first_depths_equal = 0;
455 long double depth_equality_as_float = (
long double)first_depths_equal;
456 long double third_view_depth = (
long double)view_xyz[8];
458 long double scaled_sort_depth;
462 else if (!fourth_projected_vertex)
467 int32_t sort_depth =
__ftol_msvc(scaled_sort_depth);
469 if (sort_depth > 0x3fff)
472 depth_bucket = 0x3fff - sort_depth;
474 if (0x3fff - sort_depth < 1)
476 else if (0x3fff - sort_depth > 0x3fff)
477 depth_bucket = 0x3fff;
479 face_dot = saved_face_dot;
517 second_screen_depth - 0xc00;
519 bool is_triangle = !fourth_projected_vertex;
522 third_screen_depth - 0xc00;
531 for (
int k = 0; k < 3; ++k)
544 int32_t list_bucket = depth_bucket;
572 int32_t first_packed_screen = *(uint32_t *)first_projected_words;
575 (&
g_polygonBatchRecords)[batch_index].screen_vertices[0].screen.y = (uint16_t)((uint32_t)first_packed_screen >> 16);
577 first_projected_words[1];
579 int32_t second_packed_screen = *(uint32_t *)second_projected_words;
582 (&
g_polygonBatchRecords)[batch_index].screen_vertices[1].screen.y = (uint16_t)((uint32_t)second_packed_screen >> 16);
584 second_projected_words[1];
586 int32_t third_packed_screen = *(uint32_t *)third_projected_words;
589 (&
g_polygonBatchRecords)[batch_index].screen_vertices[2].screen.y = (uint16_t)((uint32_t)third_packed_screen >> 16);
591 int32_t third_projected_depth = third_projected_words[1];
596 third_projected_depth;
604 int16_t *fourth_screen_source = fourth_projected_vertex;
612 if (fourth_screen_source)
614 int32_t fourth_packed_screen = *(uint32_t *)fourth_screen_source;
617 (&
g_polygonBatchRecords)[batch_index].screen_vertices[3].screen.y = (uint16_t)((uint32_t)fourth_packed_screen >> 16);
619 float fourth_view_y = view_xyz[10];
633 uint32_t *out_colors;
645 color_override_flags;
656 if (override_blend_mode)
668 uint32_t first_color = *(uint32_t *)out_colors;
669 int32_t first_green = (uint8_t)((uint8_t)((uint32_t)first_color >> 8));
672 *(uint32_t *)out_colors = (((first_green * fade_scale_q12) & 0xff000) | ((uint32_t)(uint8_t)first_color * fade_scale_q12) >> 8) >> 4 | (((first_color >> 0xc & 0xff0) * fade_scale_q12) & 0xff0000);
674 int32_t second_green = (uint8_t)((uint8_t)((uint32_t)second_color >> 8));
678 (((second_green * fade_scale_q12) & 0xff000) | ((uint32_t)(uint8_t)second_color * fade_scale_q12) >> 8) >> 4 | (((second_color >> 0xc & 0xff0) * fade_scale_q12) & 0xff0000);
680 int32_t third_green = (uint8_t)((uint8_t)((uint32_t)third_color >> 8));
684 (((third_green * fade_scale_q12) & 0xff000) | ((uint32_t)(uint8_t)third_color * fade_scale_q12) >> 8) >> 4 | (((third_color >> 0xc & 0xff0) * fade_scale_q12) & 0xff0000);
686 int32_t fourth_green = (uint8_t)((uint8_t)((uint32_t)fourth_color >> 8));
689 (((fourth_green * fade_scale_q12) & 0xff000) | ((uint32_t)(uint8_t)fourth_color * fade_scale_q12) >> 8) >> 4 | (((fourth_color >> 0xc & 0xff0) * fade_scale_q12) & 0xff0000);
694 if (!pending_material)
698 pending_material = NULL;
699 face_dot = saved_face_dot;
708 variant_payload_ptr = &polygon_ref[1];
710 polygon_ref = variant_payload_ptr;
711 polygons_remaining -= 1;
712 }
while (polygons_remaining);