102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
graphics_private.h File Reference
#include <SDL3/SDL.h>
#include <dttr_mods.h>
#include <kvec.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <windows.h>

Go to the source code of this file.

Data Structures

struct  DTTR_Vertex
struct  DTTR_StagedTexture
struct  DTTR_UploadPoolSlot
 One reusable upload slot holding a transfer buffer for texture uploads. More...
struct  DTTR_Uniforms
struct  DTTR_PresentRect
 Game-image placement within the present target, in target pixels. More...
struct  DTTR_RendererVtbl
 Backend-specific operations dispatched through function pointers. More...
struct  DTTR_BatchRecord
 A recorded clear or draw command replayed during frame submission. More...
struct  DTTR_BackendState

Macros

#define DTTR_INVALID_TEXTURE   0
#define DTTR_D3DTOP_DISABLE   1
#define DTTR_D3DTOP_SELECTARG1   2
#define DTTR_D3DTOP_SELECTARG2   3
#define DTTR_D3DTOP_MODULATE   4
#define DTTR_D3DTA_DIFFUSE   0
#define DTTR_D3DTA_CURRENT   1
#define DTTR_D3DTA_TEXTURE   2
#define DTTR_CLEAR_COLOR   0x01
#define DTTR_CLEAR_DEPTH   0x02
#define DTTR_CLEAR_STENCIL   0x04
#define DTTR_MAX_STAGED_TEXTURES   4096
#define DTTR_UPLOAD_POOL_SIZE   256
#define DTTR_BLEND_OFF   0
#define DTTR_BLEND_ALPHA   1
#define DTTR_BLEND_ADDITIVE   2
#define DTTR_PIPELINE_COUNT   12
#define DTTR_PIPELINE_INDEX(bmode, dtest, dwrite)
#define DTTR_SAMPLER_COUNT   4
#define DTTR_MAX_ANISOTROPY   16.0f
#define DTTR_MAT4_SIZE   (sizeof(float) * 16)
#define DTTR_VERTEX_ATTRIBUTE_COUNT   4
#define DTTR_MAX_FRAME_VERTICES   262144
#define DTTR_VERTEX_SIZE   ((uint32_t)sizeof(DTTR_Vertex))

Typedefs

typedef uint32_t DTTR_Texture
typedef struct DTTR_BackendState DTTR_BackendState

Enumerations

enum  DTTR_PrimitiveType {
  DTTR_PRIM_POINTLIST = 1 , DTTR_PRIM_LINELIST = 2 , DTTR_PRIM_LINESTRIP = 3 , DTTR_PRIM_TRIANGLELIST = 4 ,
  DTTR_PRIM_TRIANGLESTRIP = 5 , DTTR_PRIM_TRIANGLEFAN = 6
}
enum  DTTR_BlendFactor {
  DTTR_BLEND_ZERO = 1 , DTTR_BLEND_ONE = 2 , DTTR_BLEND_SRCCOLOR = 3 , DTTR_BLEND_INVSRCCOLOR = 4 ,
  DTTR_BLEND_SRCALPHA = 5 , DTTR_BLEND_INVSRCALPHA = 6 , DTTR_BLEND_DESTALPHA = 7 , DTTR_BLEND_INVDESTALPHA = 8 ,
  DTTR_BLEND_DESTCOLOR = 9 , DTTR_BLEND_INVDESTCOLOR = 10
}
enum  DTTR_CompareFunc {
  DTTR_CMP_NEVER = 1 , DTTR_CMP_LESS = 2 , DTTR_CMP_EQUAL = 3 , DTTR_CMP_LESSEQUAL = 4 ,
  DTTR_CMP_GREATER = 5 , DTTR_CMP_NOTEQUAL = 6 , DTTR_CMP_GREATEREQUAL = 7 , DTTR_CMP_ALWAYS = 8
}
enum  DTTR_TextureAddress { DTTR_TEXADDR_WRAP = 1 , DTTR_TEXADDR_MIRROR = 2 , DTTR_TEXADDR_CLAMP = 3 , DTTR_TEXADDR_BORDER = 4 }
enum  DTTR_CullMode { DTTR_CULL_NONE = 1 , DTTR_CULL_CW = 2 , DTTR_CULL_CCW = 3 }
enum  DTTR_BackendType { DTTR_BACKEND_SDL_GPU , DTTR_BACKEND_OPENGL }
enum  DTTR_BatchRecordType { DTTR_BATCH_DRAW , DTTR_BATCH_CLEAR }

Functions

typedef kvec_t (int) DTTR_IntVector
typedef kvec_t (DTTR_BatchRecord) DTTR_BatchRecordVector
HWND dttr_graphics_init ()
void dttr_graphics_cleanup ()
SDL_Windowdttr_graphics_get_window ()
SDL_GPUDevice * dttr_graphics_get_device ()
void dttr_graphics_handle_window_resize (int width, int height)
bool dttr_graphics_present_video_frame_bgra (const uint8_t *pixels, int width, int height, int stride)
void dttr_graphics_begin_frame ()
void dttr_graphics_end_frame ()
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.
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.
static void dttr_graphics_mod_frame_begin (DTTR_BackendState *)
static void dttr_graphics_mod_before_game_frame (DTTR_BackendState *)
static void dttr_graphics_mod_after_game_frame (DTTR_BackendState *)
static void dttr_graphics_mod_before_present (DTTR_BackendState *, uint32_t, uint32_t, uint32_t, uint32_t, bool, bool)
static void dttr_graphics_mod_after_present (DTTR_BackendState *, uint32_t, uint32_t, uint32_t, uint32_t, bool, bool)
static void dttr_graphics_mod_frame_end (DTTR_BackendState *)
static void dttr_graphics_mod_window_created (DTTR_BackendState *)
static void dttr_graphics_mod_window_resized (DTTR_BackendState *)
static void dttr_graphics_mod_window_destroying (DTTR_BackendState *)
static void dttr_graphics_mod_device_created (DTTR_BackendState *)
static void dttr_graphics_mod_device_lost (DTTR_BackendState *)
static void dttr_graphics_mod_device_restored (DTTR_BackendState *)
static void dttr_graphics_mod_device_destroying (DTTR_BackendState *)
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)
void dttr_graphics_mod_present_rect_before (DTTR_BackendState *state, const DTTR_PresentRect *present)
void dttr_graphics_mod_present_rect_after (DTTR_BackendState *state, const DTTR_PresentRect *present, bool overlay_rendered)
bool dttr_graphics_ensure_staged_texture (DTTR_BackendState *state, DTTR_StagedTexture *st)
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)
void dttr_graphics_set_logical_resolution (int width, int height)
void dttr_graphics_surface_texture_cache_reset ()
bool dttr_graphics_sdl3gpu_init (DTTR_BackendState *state)
bool dttr_graphics_opengl_init (DTTR_BackendState *state)

Variables

DTTR_BackendState dttr_backend

Macro Definition Documentation

◆ DTTR_BLEND_ADDITIVE

#define DTTR_BLEND_ADDITIVE   2

Definition at line 182 of file graphics_private.h.

Referenced by d3d_device7_record_draw(), and replay_batch_records_gl().

◆ DTTR_BLEND_ALPHA

#define DTTR_BLEND_ALPHA   1

Definition at line 181 of file graphics_private.h.

Referenced by d3d_device7_record_draw().

◆ DTTR_BLEND_OFF

#define DTTR_BLEND_OFF   0

Definition at line 180 of file graphics_private.h.

Referenced by d3d_device7_record_draw(), and replay_batch_records_gl().

◆ DTTR_CLEAR_COLOR

#define DTTR_CLEAR_COLOR   0x01

◆ DTTR_CLEAR_DEPTH

#define DTTR_CLEAR_DEPTH   0x02

Definition at line 79 of file graphics_private.h.

Referenced by begin_clear_pass(), if(), and replay_batch_records_gl().

◆ DTTR_CLEAR_STENCIL

#define DTTR_CLEAR_STENCIL   0x04

Definition at line 80 of file graphics_private.h.

Referenced by if().

◆ DTTR_D3DTA_CURRENT

#define DTTR_D3DTA_CURRENT   1

Definition at line 68 of file graphics_private.h.

◆ DTTR_D3DTA_DIFFUSE

#define DTTR_D3DTA_DIFFUSE   0

Definition at line 67 of file graphics_private.h.

Referenced by init_common_state(), and present_video_frame_bgra().

◆ DTTR_D3DTA_TEXTURE

#define DTTR_D3DTA_TEXTURE   2

Definition at line 69 of file graphics_private.h.

Referenced by init_common_state(), and present_video_frame_bgra().

◆ DTTR_D3DTOP_DISABLE

#define DTTR_D3DTOP_DISABLE   1

Definition at line 62 of file graphics_private.h.

◆ DTTR_D3DTOP_MODULATE

#define DTTR_D3DTOP_MODULATE   4

Definition at line 65 of file graphics_private.h.

Referenced by init_common_state(), and present_video_frame_bgra().

◆ DTTR_D3DTOP_SELECTARG1

#define DTTR_D3DTOP_SELECTARG1   2

Definition at line 63 of file graphics_private.h.

Referenced by init_common_state(), and present_video_frame_bgra().

◆ DTTR_D3DTOP_SELECTARG2

#define DTTR_D3DTOP_SELECTARG2   3

Definition at line 64 of file graphics_private.h.

◆ DTTR_INVALID_TEXTURE

◆ DTTR_MAT4_SIZE

#define DTTR_MAT4_SIZE   (sizeof(float) * 16)

Definition at line 188 of file graphics_private.h.

Referenced by dttr_graphics_mat4_identity().

◆ DTTR_MAX_ANISOTROPY

#define DTTR_MAX_ANISOTROPY   16.0f

Definition at line 187 of file graphics_private.h.

Referenced by create_samplers().

◆ DTTR_MAX_FRAME_VERTICES

#define DTTR_MAX_FRAME_VERTICES   262144

◆ DTTR_MAX_STAGED_TEXTURES

◆ DTTR_PIPELINE_COUNT

#define DTTR_PIPELINE_COUNT   12

Definition at line 183 of file graphics_private.h.

Referenced by cleanup().

◆ DTTR_PIPELINE_INDEX

#define DTTR_PIPELINE_INDEX ( bmode,
dtest,
dwrite )
Value:
((bmode) * 4 + (dtest) * 2 + (dwrite))

Definition at line 184 of file graphics_private.h.

Referenced by create_graphics_pipelines(), and draw_batch_record().

◆ DTTR_SAMPLER_COUNT

#define DTTR_SAMPLER_COUNT   4

◆ DTTR_UPLOAD_POOL_SIZE

#define DTTR_UPLOAD_POOL_SIZE   256

Definition at line 103 of file graphics_private.h.

Referenced by acquire_upload_pool_slot(), cleanup(), and release_upload_pool_slot().

◆ DTTR_VERTEX_ATTRIBUTE_COUNT

#define DTTR_VERTEX_ATTRIBUTE_COUNT   4

Definition at line 189 of file graphics_private.h.

Referenced by create_graphics_pipelines().

◆ DTTR_VERTEX_SIZE

Typedef Documentation

◆ DTTR_BackendState

typedef struct DTTR_BackendState DTTR_BackendState

Definition at line 131 of file graphics_private.h.

◆ DTTR_Texture

typedef uint32_t DTTR_Texture

Definition at line 12 of file graphics_private.h.

Enumeration Type Documentation

◆ DTTR_BackendType

Enumerator
DTTR_BACKEND_SDL_GPU 
DTTR_BACKEND_OPENGL 

Definition at line 118 of file graphics_private.h.

◆ DTTR_BatchRecordType

Enumerator
DTTR_BATCH_DRAW 
DTTR_BATCH_CLEAR 

Definition at line 150 of file graphics_private.h.

◆ DTTR_BlendFactor

Enumerator
DTTR_BLEND_ZERO 
DTTR_BLEND_ONE 
DTTR_BLEND_SRCCOLOR 
DTTR_BLEND_INVSRCCOLOR 
DTTR_BLEND_SRCALPHA 
DTTR_BLEND_INVSRCALPHA 
DTTR_BLEND_DESTALPHA 
DTTR_BLEND_INVDESTALPHA 
DTTR_BLEND_DESTCOLOR 
DTTR_BLEND_INVDESTCOLOR 

Definition at line 25 of file graphics_private.h.

◆ DTTR_CompareFunc

Enumerator
DTTR_CMP_NEVER 
DTTR_CMP_LESS 
DTTR_CMP_EQUAL 
DTTR_CMP_LESSEQUAL 
DTTR_CMP_GREATER 
DTTR_CMP_NOTEQUAL 
DTTR_CMP_GREATEREQUAL 
DTTR_CMP_ALWAYS 

Definition at line 38 of file graphics_private.h.

◆ DTTR_CullMode

Enumerator
DTTR_CULL_NONE 
DTTR_CULL_CW 
DTTR_CULL_CCW 

Definition at line 56 of file graphics_private.h.

◆ DTTR_PrimitiveType

Enumerator
DTTR_PRIM_POINTLIST 
DTTR_PRIM_LINELIST 
DTTR_PRIM_LINESTRIP 
DTTR_PRIM_TRIANGLELIST 
DTTR_PRIM_TRIANGLESTRIP 
DTTR_PRIM_TRIANGLEFAN 

Definition at line 16 of file graphics_private.h.

◆ DTTR_TextureAddress

Enumerator
DTTR_TEXADDR_WRAP 
DTTR_TEXADDR_MIRROR 
DTTR_TEXADDR_CLAMP 
DTTR_TEXADDR_BORDER 

Definition at line 49 of file graphics_private.h.

Function Documentation

◆ dttr_graphics_begin_frame()

void dttr_graphics_begin_frame ( )

Definition at line 599 of file graphics.c.

References dttr_backend, and state.

Referenced by d3d_device7_record_clear(), and tick_main_loop().

◆ 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_cleanup()

◆ 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_end_frame()

void dttr_graphics_end_frame ( )

Definition at line 610 of file graphics.c.

References dttr_backend, and state.

Referenced by surface_present(), and tick_main_loop().

◆ 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_get_device()

SDL_GPUDevice * dttr_graphics_get_device ( )

Definition at line 583 of file graphics.c.

References dttr_backend.

Referenced by DTTR_Hook_WinMainCallback().

◆ dttr_graphics_get_window()

SDL_Window * dttr_graphics_get_window ( )

Definition at line 578 of file graphics.c.

References dttr_backend.

Referenced by DTTR_Hook_WinMainCallback(), and kvec_t().

◆ dttr_graphics_handle_window_resize()

void dttr_graphics_handle_window_resize ( int width,
int height )

◆ dttr_graphics_init()

◆ 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_mod_after_game_frame()

void dttr_graphics_mod_after_game_frame ( DTTR_BackendState * )
inlinestatic

Definition at line 349 of file graphics_private.h.

Referenced by end_frame(), and end_frame().

◆ dttr_graphics_mod_after_present()

void dttr_graphics_mod_after_present ( DTTR_BackendState * ,
uint32_t ,
uint32_t ,
uint32_t ,
uint32_t ,
bool ,
bool  )
inlinestatic

Definition at line 361 of file graphics_private.h.

Referenced by dttr_graphics_mod_present_rect_after().

◆ dttr_graphics_mod_before_game_frame()

void dttr_graphics_mod_before_game_frame ( DTTR_BackendState * )
inlinestatic

Definition at line 347 of file graphics_private.h.

Referenced by end_frame(), and end_frame().

◆ dttr_graphics_mod_before_present()

void dttr_graphics_mod_before_present ( DTTR_BackendState * ,
uint32_t ,
uint32_t ,
uint32_t ,
uint32_t ,
bool ,
bool  )
inlinestatic

Definition at line 351 of file graphics_private.h.

Referenced by dttr_graphics_mod_present_rect_before().

◆ dttr_graphics_mod_device_created()

void dttr_graphics_mod_device_created ( DTTR_BackendState * )
inlinestatic

Definition at line 379 of file graphics_private.h.

Referenced by dttr_graphics_init(), and DTTR_Hook_WinMainCallback().

◆ dttr_graphics_mod_device_destroying()

void dttr_graphics_mod_device_destroying ( DTTR_BackendState * )
inlinestatic

Definition at line 385 of file graphics_private.h.

Referenced by dttr_graphics_cleanup().

◆ dttr_graphics_mod_device_lost()

void dttr_graphics_mod_device_lost ( DTTR_BackendState * )
inlinestatic

Definition at line 381 of file graphics_private.h.

Referenced by dttr_graphics_cleanup().

◆ dttr_graphics_mod_device_restored()

void dttr_graphics_mod_device_restored ( DTTR_BackendState * )
inlinestatic

Definition at line 383 of file graphics_private.h.

Referenced by dttr_graphics_init(), and DTTR_Hook_WinMainCallback().

◆ dttr_graphics_mod_frame_begin()

void dttr_graphics_mod_frame_begin ( DTTR_BackendState * )
inlinestatic

Definition at line 345 of file graphics_private.h.

Referenced by begin_frame(), and begin_frame().

◆ dttr_graphics_mod_frame_end()

void dttr_graphics_mod_frame_end ( DTTR_BackendState * )
inlinestatic

Definition at line 371 of file graphics_private.h.

Referenced by end_frame(), and end_frame().

◆ dttr_graphics_mod_present_rect_after()

void dttr_graphics_mod_present_rect_after ( DTTR_BackendState * state,
const DTTR_PresentRect * present,
bool overlay_rendered )

◆ dttr_graphics_mod_present_rect_before()

void dttr_graphics_mod_present_rect_before ( DTTR_BackendState * state,
const DTTR_PresentRect * present )

◆ dttr_graphics_mod_window_created()

void dttr_graphics_mod_window_created ( DTTR_BackendState * )
inlinestatic

Definition at line 373 of file graphics_private.h.

Referenced by dttr_graphics_init(), and DTTR_Hook_WinMainCallback().

◆ dttr_graphics_mod_window_destroying()

void dttr_graphics_mod_window_destroying ( DTTR_BackendState * )
inlinestatic

Definition at line 377 of file graphics_private.h.

Referenced by destroy_window().

◆ dttr_graphics_mod_window_resized()

void dttr_graphics_mod_window_resized ( DTTR_BackendState * )
inlinestatic

Definition at line 375 of file graphics_private.h.

Referenced by dttr_graphics_handle_window_resize().

◆ dttr_graphics_opengl_init()

◆ dttr_graphics_present_video_frame_bgra()

bool dttr_graphics_present_video_frame_bgra ( const uint8_t * pixels,
int width,
int height,
int stride )

Definition at line 621 of file graphics.c.

References dttr_backend, state, and stride.

Referenced by dttr_movies_tick().

◆ 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_sdl3gpu_init()

◆ 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_set_logical_resolution()

void dttr_graphics_set_logical_resolution ( int width,
int height )

◆ 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().

◆ dttr_graphics_surface_texture_cache_reset()

void dttr_graphics_surface_texture_cache_reset ( )

Definition at line 158 of file com_directdrawsurface7.c.

References NULL.

Referenced by dttr_graphics_cleanup(), and init_common_state().

◆ kvec_t() [1/2]

typedef kvec_t ( DTTR_BatchRecord )

◆ kvec_t() [2/2]

typedef kvec_t ( int )

Variable Documentation

◆ dttr_backend