102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
util.c File Reference
#include "graphics_private.h"
#include <dttr_config.h>
#include <dttr_log.h>
#include <math.h>
#include <string.h>

Go to the source code of this file.

Macros

#define DTTR_MESH_SEAM_FILL_PHYSICAL_PX   0.5f
#define DTTR_MESH_SEAM_MAX_VERTEX_NUDGE_PHYSICAL_PX   0.75f
#define DTTR_MESH_SEAM_MIN_AREA_PX   1.0e-4f

Functions

bool dttr_graphics_ensure_staged_texture (DTTR_BackendState *state, DTTR_StagedTexture *st)
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)
int dttr_graphics_calc_mip_levels (int w, int h)
void dttr_graphics_mat4_identity (float *m)
const char * dttr_graphics_shader_format_name (SDL_GPUShaderFormat format)
SDL_GPUShaderFormat dttr_graphics_requested_shader_formats ()
SDL_GPUShaderFormat dttr_graphics_select_shader_format (SDL_GPUShaderFormat formats)
SDL_GPUShaderFormat dttr_graphics_shader_format_for_driver (const char *driver)
SDL_GPUShaderFormat dttr_graphics_select_shader_format_for_driver (const char *driver, SDL_GPUShaderFormat formats)
bool dttr_graphics_is_gpu_thread ()
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.
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)
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.

Variables

DTTR_BackendState dttr_backend

Macro Definition Documentation

◆ DTTR_MESH_SEAM_FILL_PHYSICAL_PX

#define DTTR_MESH_SEAM_FILL_PHYSICAL_PX   0.5f

Definition at line 10 of file util.c.

Referenced by fill_mesh_seam_triangle().

◆ DTTR_MESH_SEAM_MAX_VERTEX_NUDGE_PHYSICAL_PX

#define DTTR_MESH_SEAM_MAX_VERTEX_NUDGE_PHYSICAL_PX   0.75f

Definition at line 11 of file util.c.

Referenced by fill_mesh_seam_triangle().

◆ DTTR_MESH_SEAM_MIN_AREA_PX

#define DTTR_MESH_SEAM_MIN_AREA_PX   1.0e-4f

Definition at line 12 of file util.c.

Referenced by fill_mesh_seam_triangle().

Function Documentation

◆ dttr_graphics_calc_mip_levels()

int dttr_graphics_calc_mip_levels ( int w,
int h )

Definition at line 104 of file util.c.

References d, h, and w.

Referenced by dttr_graphics_ensure_staged_texture().

◆ dttr_graphics_compute_present_rect()

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 )

Definition at line 48 of file util.c.

References float, and rect.

Referenced by end_frame(), end_frame(), present_video_frame_bgra(), and present_video_frame_bgra().

◆ dttr_graphics_ensure_staged_texture()

bool dttr_graphics_ensure_staged_texture ( DTTR_BackendState * state,
DTTR_StagedTexture * st )

Definition at line 14 of file util.c.

References dttr_graphics_calc_mip_levels(), DTTR_LOG_WARN, NULL, st, and state.

Referenced by collect_and_upload_pending(), and d3d_device7_texture_bind().

◆ dttr_graphics_fill_mesh_seams()

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.

Definition at line 280 of file util.c.

References count, fill_mesh_seam_triangle(), and float.

Referenced by d3d_device7_record_draw().

◆ dttr_graphics_is_gpu_thread()

bool dttr_graphics_is_gpu_thread ( )

◆ dttr_graphics_mat4_identity()

void dttr_graphics_mat4_identity ( float * m)

Definition at line 116 of file util.c.

References DTTR_MAT4_SIZE.

Referenced by init_common_state(), and present_video_frame_bgra().

◆ dttr_graphics_requested_shader_formats()

SDL_GPUShaderFormat dttr_graphics_requested_shader_formats ( )

Definition at line 136 of file util.c.

Referenced by create_device().

◆ dttr_graphics_select_shader_format()

SDL_GPUShaderFormat dttr_graphics_select_shader_format ( SDL_GPUShaderFormat formats)

Definition at line 140 of file util.c.

Referenced by dttr_graphics_select_shader_format_for_driver().

◆ dttr_graphics_select_shader_format_for_driver()

SDL_GPUShaderFormat dttr_graphics_select_shader_format_for_driver ( const char * driver,
SDL_GPUShaderFormat formats )

◆ dttr_graphics_shader_format_for_driver()

SDL_GPUShaderFormat dttr_graphics_shader_format_for_driver ( const char * driver)

Definition at line 152 of file util.c.

References DTTR_DRIVER_DIRECT3D12, and DTTR_DRIVER_VULKAN.

Referenced by dttr_graphics_select_shader_format_for_driver().

◆ dttr_graphics_shader_format_name()

const char * dttr_graphics_shader_format_name ( SDL_GPUShaderFormat format)

Definition at line 121 of file util.c.

Referenced by create_shader(), and dttr_graphics_sdl3gpu_init().

◆ dttr_graphics_should_fill_mesh_seams()

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.

Definition at line 198 of file util.c.

References dttr_config, DTTR_PRIM_TRIANGLELIST, DTTR_SCALING_METHOD_LOGICAL, DTTR_VERTEX_PRECISION_SUBPIXEL, and type.

Referenced by d3d_device7_record_draw().

◆ fill_mesh_seam_triangle()

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 )
static

Variable Documentation

◆ dttr_backend