10#define DTTR_MESH_SEAM_FILL_PHYSICAL_PX 0.5f
11#define DTTR_MESH_SEAM_MAX_VERTEX_NUDGE_PHYSICAL_PX 0.75f
12#define DTTR_MESH_SEAM_MIN_AREA_PX 1.0e-4f
23 const SDL_GPUTextureCreateInfo tex_info = {
24 .type = SDL_GPU_TEXTURETYPE_2D,
25 .format = SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM,
26 .usage = SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET,
29 .layer_count_or_depth = 1,
33 st->gpu_tex = SDL_CreateGPUTexture(
state->device, &tex_info);
37 "Failed to create GPU texture %dx%d: %s",
64 if (stretch || src_w <= 0 || src_h <= 0) {
68 const float sx = (
float)dst_w / (
float)src_w;
69 const float sy = (
float)dst_h / (
float)src_h;
70 float scale = sx < sy ? sx : sy;
73 scale = fallback_scale;
76 if (integer_fit && scale >= 1.0f) {
77 scale = floorf(scale);
80 rect.w = (int)((
float)src_w * scale);
81 rect.h = (int)((
float)src_h * scale);
105 int d =
w >
h ?
w :
h;
118 m[0] = m[5] = m[10] = m[15] = 1.0f;
123 case SDL_GPU_SHADERFORMAT_SPIRV:
125 case SDL_GPU_SHADERFORMAT_DXIL:
127 case SDL_GPU_SHADERFORMAT_METALLIB:
129 case SDL_GPU_SHADERFORMAT_PRIVATE:
137 return SDL_GPU_SHADERFORMAT_SPIRV | SDL_GPU_SHADERFORMAT_DXIL;
141 if (formats & SDL_GPU_SHADERFORMAT_DXIL) {
142 return SDL_GPU_SHADERFORMAT_DXIL;
145 if (formats & SDL_GPU_SHADERFORMAT_SPIRV) {
146 return SDL_GPU_SHADERFORMAT_SPIRV;
149 return SDL_GPU_SHADERFORMAT_INVALID;
153 if (!driver || !driver[0]) {
154 return SDL_GPU_SHADERFORMAT_INVALID;
158 return SDL_GPU_SHADERFORMAT_DXIL;
162 return SDL_GPU_SHADERFORMAT_SPIRV;
165 return SDL_GPU_SHADERFORMAT_INVALID;
171 SDL_GPUShaderFormat formats
175 if ((preferred != SDL_GPU_SHADERFORMAT_INVALID) && (formats & preferred)) {
185 if (!
state->initialized) {
189 if (
state->gpu_thread_id == 0) {
193 return SDL_GetCurrentThreadID() ==
state->gpu_thread_id;
213 float logical_to_px_x,
214 float logical_to_px_y,
215 float px_to_logical_x,
216 float px_to_logical_y
224 for (
int i = 0; i < 3; i++) {
225 x[i] = tri[i].
x * logical_to_px_x;
226 y[i] = tri[i].
y * logical_to_px_y;
229 const float area_px = (
x[1] -
x[0]) * (
y[2] -
y[0]) - (
y[1] -
y[0]) * (
x[2] -
x[0]);
234 const float winding = area_px > 0.0f ? 1.0f : -1.0f;
235 for (
int i = 0; i < 3; i++) {
236 const int j = (i + 1) % 3;
237 const float dx =
x[j] -
x[i];
238 const float dy =
y[j] -
y[i];
239 const float len = sqrtf(dx * dx + dy * dy);
241 if (!isfinite(len) || len <= 1.0e-6f) {
245 nx[i] = winding * dy / len;
246 ny[i] = -winding * dx / len;
250 for (
int i = 0; i < 3; i++) {
251 const int prev = (i + 2) % 3;
252 const float det = nx[prev] * ny[i] - ny[prev] * nx[i];
254 if (!isfinite(det) || fabsf(det) <= 1.0e-6f) {
258 const float expanded_x = (
c[prev] * ny[i] - ny[prev] *
c[i]) / det;
259 const float expanded_y = (nx[prev] *
c[i] -
c[prev] * nx[i]) / det;
261 if (isfinite(expanded_x) && isfinite(expanded_y)) {
262 float dx = expanded_x -
x[i];
263 float dy = expanded_y -
y[i];
264 const float dist2 = dx * dx + dy * dy;
267 if (isfinite(dist2) && dist2 > max_dist * max_dist) {
268 const float scale = max_dist / sqrtf(dist2);
273 tri[i].
x = (
x[i] + dx) * px_to_logical_x;
274 tri[i].
y = (
y[i] + dy) * px_to_logical_y;
288 if (!verts ||
count < 3 || logical_width <= 0 || logical_height <= 0
289 || render_width <= 0 || render_height <= 0) {
293 const float logical_to_px_x = (
float)render_width / (
float)logical_width;
294 const float logical_to_px_y = (
float)render_height / (
float)logical_height;
295 const float px_to_logical_x = (
float)logical_width / (
float)render_width;
296 const float px_to_logical_y = (
float)logical_height / (
float)render_height;
298 for (uint32_t i = 0; i + 2 <
count; i += 3) {
DTTR_Graphics_COM_Direct3DDevice7 DWORD block DTTR_Graphics_COM_Direct3DDevice7 DWORD block DTTR_Graphics_COM_Direct3DDevice7 void void void void DWORD f DTTR_Graphics_COM_Direct3DDevice7 DWORD idx float
DTTR_Graphics_COM_Direct3DDevice7 void *status DTTR_Graphics_COM_Direct3DDevice7 DWORD DWORD void DWORD DWORD f DTTR_Graphics_COM_Direct3DDevice7 DWORD void DWORD st
DTTR_Graphics_COM_Direct3DDevice7 void DWORD flags DWORD count
DTTR_Graphics_COM_Direct3DDevice7 void *status DTTR_Graphics_COM_Direct3DDevice7 DWORD DWORD void * d
const DTTR_BackendState * state
const DTTR_PrimitiveType type
DTTR_Graphics_COM_Direct3DDevice7 void *status DTTR_Graphics_COM_Direct3DDevice7 DWORD DWORD void DWORD DWORD f DTTR_Graphics_COM_Direct3DDevice7 DWORD void DWORD DWORD DWORD f DTTR_Graphics_COM_Direct3DDevice7 void * c
DTTR_Graphics_COM_DirectDraw7 *self DWORD DWORD h
DTTR_Graphics_COM_DirectDraw7 *self DWORD w
DTTR_Graphics_COM_DirectDrawSurface7 DWORD x
DTTR_Graphics_COM_DirectDrawSurface7 DWORD DWORD y
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
@ DTTR_VERTEX_PRECISION_SUBPIXEL
#define DTTR_DRIVER_VULKAN
@ DTTR_SCALING_METHOD_LOGICAL
#define DTTR_DRIVER_DIRECT3D12
#define DTTR_LOG_WARN(...)
DTTR_BackendState dttr_backend
Game-image placement within the present target, in target pixels.
void dttr_graphics_fill_mesh_seams(DTTR_Vertex *verts, uint32_t count, int logical_width, int logical_height, int render_width, int render_height)
Expands triangle-list vertices by a tiny physical-pixel amount to hide mesh cracks.
void dttr_graphics_mat4_identity(float *m)
SDL_GPUShaderFormat dttr_graphics_select_shader_format_for_driver(const char *driver, SDL_GPUShaderFormat formats)
bool dttr_graphics_ensure_staged_texture(DTTR_BackendState *state, DTTR_StagedTexture *st)
bool dttr_graphics_is_gpu_thread()
SDL_GPUShaderFormat dttr_graphics_requested_shader_formats()
bool dttr_graphics_should_fill_mesh_seams(DTTR_PrimitiveType type, bool transformed, bool depth_test, bool blend_enabled)
Returns true when a draw call should receive subpixel logical-scaling seam fill.
SDL_GPUShaderFormat dttr_graphics_select_shader_format(SDL_GPUShaderFormat formats)
#define DTTR_MESH_SEAM_FILL_PHYSICAL_PX
SDL_GPUShaderFormat dttr_graphics_shader_format_for_driver(const char *driver)
static void fill_mesh_seam_triangle(DTTR_Vertex *tri, float logical_to_px_x, float logical_to_px_y, float px_to_logical_x, float px_to_logical_y)
DTTR_PresentRect dttr_graphics_compute_present_rect(int dst_w, int dst_h, int src_w, int src_h, bool stretch, bool integer_fit, float fallback_scale)
const char * dttr_graphics_shader_format_name(SDL_GPUShaderFormat format)
#define DTTR_MESH_SEAM_MAX_VERTEX_NUDGE_PHYSICAL_PX
int dttr_graphics_calc_mip_levels(int w, int h)
#define DTTR_MESH_SEAM_MIN_AREA_PX