|
102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
|
#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 |
Variables | |
| DTTR_BackendState | dttr_backend |
| #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().
| #define DTTR_BLEND_ALPHA 1 |
Definition at line 181 of file graphics_private.h.
Referenced by d3d_device7_record_draw().
| #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().
| #define DTTR_CLEAR_COLOR 0x01 |
Definition at line 78 of file graphics_private.h.
Referenced by begin_clear_pass(), d3d_device7_record_clear(), if(), and replay_batch_records_gl().
| #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().
| #define DTTR_CLEAR_STENCIL 0x04 |
Definition at line 80 of file graphics_private.h.
Referenced by if().
| #define DTTR_D3DTA_CURRENT 1 |
Definition at line 68 of file graphics_private.h.
| #define DTTR_D3DTA_DIFFUSE 0 |
Definition at line 67 of file graphics_private.h.
Referenced by init_common_state(), and present_video_frame_bgra().
| #define DTTR_D3DTA_TEXTURE 2 |
Definition at line 69 of file graphics_private.h.
Referenced by init_common_state(), and present_video_frame_bgra().
| #define DTTR_D3DTOP_DISABLE 1 |
Definition at line 62 of file graphics_private.h.
| #define DTTR_D3DTOP_MODULATE 4 |
Definition at line 65 of file graphics_private.h.
Referenced by init_common_state(), and present_video_frame_bgra().
| #define DTTR_D3DTOP_SELECTARG1 2 |
Definition at line 63 of file graphics_private.h.
Referenced by init_common_state(), and present_video_frame_bgra().
| #define DTTR_D3DTOP_SELECTARG2 3 |
Definition at line 64 of file graphics_private.h.
| #define DTTR_INVALID_TEXTURE 0 |
Definition at line 13 of file graphics_private.h.
Referenced by d3d_device7_clear_bound_texture(), d3d_device7_texture_bind(), ddrawsurface7_blt(), surface_texture_cache_lookup_locked(), surface_texture_create_or_retain(), surface_texture_release(), and surface_upload_texture().
| #define DTTR_MAT4_SIZE (sizeof(float) * 16) |
Definition at line 188 of file graphics_private.h.
Referenced by dttr_graphics_mat4_identity().
| #define DTTR_MAX_ANISOTROPY 16.0f |
Definition at line 187 of file graphics_private.h.
Referenced by create_samplers().
| #define DTTR_MAX_FRAME_VERTICES 262144 |
Definition at line 191 of file graphics_private.h.
Referenced by create_frame_buffers(), d3d_device7_record_draw(), and dttr_graphics_opengl_init().
| #define DTTR_MAX_STAGED_TEXTURES 4096 |
Definition at line 102 of file graphics_private.h.
Referenced by cleanup(), collect_and_upload_pending(), defer_texture_destroy(), defer_texture_destroy(), replay_batch_records_gl(), surface_texture_create_or_retain(), and upload_pending_textures().
| #define DTTR_PIPELINE_COUNT 12 |
Definition at line 183 of file graphics_private.h.
Referenced by cleanup().
| #define DTTR_PIPELINE_INDEX | ( | bmode, | |
| dtest, | |||
| dwrite ) |
Definition at line 184 of file graphics_private.h.
Referenced by create_graphics_pipelines(), and draw_batch_record().
| #define DTTR_SAMPLER_COUNT 4 |
Definition at line 186 of file graphics_private.h.
Referenced by cleanup(), cleanup(), create_samplers(), and dttr_graphics_sdl3gpu_create_resources().
| #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().
| #define DTTR_VERTEX_ATTRIBUTE_COUNT 4 |
Definition at line 189 of file graphics_private.h.
Referenced by create_graphics_pipelines().
| #define DTTR_VERTEX_SIZE ((uint32_t)sizeof(DTTR_Vertex)) |
Definition at line 192 of file graphics_private.h.
Referenced by create_frame_buffers(), create_graphics_pipelines(), d3d_device7_copy_or_expand_primitive(), d3d_device7_record_draw(), dttr_graphics_opengl_init(), end_frame(), and end_frame().
| typedef struct DTTR_BackendState DTTR_BackendState |
Definition at line 131 of file graphics_private.h.
| typedef uint32_t DTTR_Texture |
Definition at line 12 of file graphics_private.h.
| enum DTTR_BackendType |
| Enumerator | |
|---|---|
| DTTR_BACKEND_SDL_GPU | |
| DTTR_BACKEND_OPENGL | |
Definition at line 118 of file graphics_private.h.
| enum DTTR_BatchRecordType |
| Enumerator | |
|---|---|
| DTTR_BATCH_DRAW | |
| DTTR_BATCH_CLEAR | |
Definition at line 150 of file graphics_private.h.
| enum DTTR_BlendFactor |
Definition at line 25 of file graphics_private.h.
| enum 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.
| enum DTTR_CullMode |
| Enumerator | |
|---|---|
| DTTR_CULL_NONE | |
| DTTR_CULL_CW | |
| DTTR_CULL_CCW | |
Definition at line 56 of file graphics_private.h.
| enum 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.
| enum DTTR_TextureAddress |
| Enumerator | |
|---|---|
| DTTR_TEXADDR_WRAP | |
| DTTR_TEXADDR_MIRROR | |
| DTTR_TEXADDR_CLAMP | |
| DTTR_TEXADDR_BORDER | |
Definition at line 49 of file graphics_private.h.
| 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().
| int dttr_graphics_calc_mip_levels | ( | int | w, |
| int | h ) |
| void dttr_graphics_cleanup | ( | ) |
Definition at line 638 of file graphics.c.
References destroy_window(), dttr_backend, dttr_graphics_mod_device_destroying(), dttr_graphics_mod_device_lost(), dttr_graphics_surface_texture_cache_reset(), NULL, and state.
Referenced by cleanup_runtime().
| 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.
Referenced by end_frame(), end_frame(), present_video_frame_bgra(), and present_video_frame_bgra().
| 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().
| 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().
| 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().
| SDL_GPUDevice * dttr_graphics_get_device | ( | ) |
Definition at line 583 of file graphics.c.
References dttr_backend.
Referenced by DTTR_Hook_WinMainCallback().
| 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().
| void dttr_graphics_handle_window_resize | ( | int | width, |
| int | height ) |
Definition at line 588 of file graphics.c.
References dttr_backend, dttr_graphics_mod_window_resized(), DTTR_MIN_WINDOW_DIM, refresh_render_resolution(), and update_window_title().
Referenced by dttr_sidecar_handle_sdl_event().
| HWND dttr_graphics_init | ( | ) |
Definition at line 482 of file graphics.c.
References backend_candidates, clamp_dim(), destroy_window(), dttr_backend, dttr_config, DTTR_Config_GraphicsAPIName(), DTTR_Errors_ShowMessage(), DTTR_GRAPHICS_API_AUTO, dttr_graphics_mod_device_created(), dttr_graphics_mod_device_restored(), dttr_graphics_mod_window_created(), DTTR_LOG_ERROR, DTTR_LOG_WARN, backend_range::end, get_hwnd(), init_common_state(), NULL, select_backend_range(), select_render_resolution(), backend_range::start, state, update_window_title(), WINDOW_HEIGHT, and WINDOW_WIDTH.
Referenced by dttr_graphics_hooks_init(), and DTTR_Hook_WinMainCallback().
| bool dttr_graphics_is_gpu_thread | ( | ) |
Definition at line 182 of file util.c.
References dttr_backend, and state.
Referenced by begin_frame(), d3d_device7_record_clear(), d3d_device7_record_draw(), d3d_device7_texture_bind(), and present_video_frame_bgra().
Definition at line 116 of file util.c.
References DTTR_MAT4_SIZE.
Referenced by init_common_state(), and present_video_frame_bgra().
|
inlinestatic |
Definition at line 349 of file graphics_private.h.
Referenced by end_frame(), and end_frame().
|
inlinestatic |
Definition at line 361 of file graphics_private.h.
Referenced by dttr_graphics_mod_present_rect_after().
|
inlinestatic |
Definition at line 347 of file graphics_private.h.
Referenced by end_frame(), and end_frame().
|
inlinestatic |
Definition at line 351 of file graphics_private.h.
Referenced by dttr_graphics_mod_present_rect_before().
|
inlinestatic |
Definition at line 379 of file graphics_private.h.
Referenced by dttr_graphics_init(), and DTTR_Hook_WinMainCallback().
|
inlinestatic |
Definition at line 385 of file graphics_private.h.
Referenced by dttr_graphics_cleanup().
|
inlinestatic |
Definition at line 381 of file graphics_private.h.
Referenced by dttr_graphics_cleanup().
|
inlinestatic |
Definition at line 383 of file graphics_private.h.
Referenced by dttr_graphics_init(), and DTTR_Hook_WinMainCallback().
|
inlinestatic |
Definition at line 345 of file graphics_private.h.
Referenced by begin_frame(), and begin_frame().
|
inlinestatic |
Definition at line 371 of file graphics_private.h.
Referenced by end_frame(), and end_frame().
| void dttr_graphics_mod_present_rect_after | ( | DTTR_BackendState * | state, |
| const DTTR_PresentRect * | present, | ||
| bool | overlay_rendered ) |
Definition at line 439 of file graphics.c.
References dttr_graphics_mod_after_present(), DTTR_PresentRect::h, state, DTTR_PresentRect::w, DTTR_PresentRect::x, and DTTR_PresentRect::y.
Referenced by end_frame(), and end_frame().
| void dttr_graphics_mod_present_rect_before | ( | DTTR_BackendState * | state, |
| const DTTR_PresentRect * | present ) |
Definition at line 424 of file graphics.c.
References dttr_graphics_mod_before_present(), DTTR_PresentRect::h, state, DTTR_PresentRect::w, DTTR_PresentRect::x, and DTTR_PresentRect::y.
Referenced by end_frame(), and end_frame().
|
inlinestatic |
Definition at line 373 of file graphics_private.h.
Referenced by dttr_graphics_init(), and DTTR_Hook_WinMainCallback().
|
inlinestatic |
Definition at line 377 of file graphics_private.h.
Referenced by destroy_window().
|
inlinestatic |
Definition at line 375 of file graphics_private.h.
Referenced by dttr_graphics_handle_window_resize().
| bool dttr_graphics_opengl_init | ( | DTTR_BackendState * | state | ) |
Definition at line 288 of file backend_opengl.c.
References create_fbo(), create_msaa_fbo(), create_program(), create_samplers(), destroy_msaa_fbo(), DTTR_BACKEND_OPENGL, DTTR_LOG_ERROR, DTTR_LOG_INFO, DTTR_LOG_WARN, DTTR_MAX_FRAME_VERTICES, DTTR_VERTEX_SIZE, opengl_backend_data::dummy_texture, free, opengl_backend_data::gl_context, opengl_backend_data::loc_alpha_arg1, opengl_backend_data::loc_alpha_arg2, opengl_backend_data::loc_alpha_op, opengl_backend_data::loc_color_arg1, opengl_backend_data::loc_color_arg2, opengl_backend_data::loc_color_op, opengl_backend_data::loc_has_texture, opengl_backend_data::loc_is_2d, opengl_backend_data::loc_mvp, opengl_backend_data::loc_screen_size, opengl_backend_data::loc_texture, NULL, opengl_backend_data::program, renderer, select_gl_msaa_samples(), state, stride, opengl_backend_data::vao, opengl_backend_data::vbo, and opengl_backend_data::vertex_staging.
| 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().
| SDL_GPUShaderFormat dttr_graphics_requested_shader_formats | ( | ) |
Definition at line 136 of file util.c.
Referenced by create_device().
| bool dttr_graphics_sdl3gpu_init | ( | DTTR_BackendState * | state | ) |
Definition at line 224 of file backend_sdl3gpu.c.
References cleanup(), create_device(), DTTR_BACKEND_SDL_GPU, dttr_config, dttr_graphics_sdl3gpu_create_pipelines(), dttr_graphics_sdl3gpu_create_resources(), dttr_graphics_shader_format_name(), DTTR_LOG_ERROR, DTTR_LOG_INFO, msaa_sample_count_to_int(), NULL, release_window_device(), renderer, select_msaa_sample_count(), and state.
| 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().
| SDL_GPUShaderFormat dttr_graphics_select_shader_format_for_driver | ( | const char * | driver, |
| SDL_GPUShaderFormat | formats ) |
Definition at line 169 of file util.c.
References dttr_graphics_select_shader_format(), and dttr_graphics_shader_format_for_driver().
Referenced by try_create_device_for_driver().
| void dttr_graphics_set_logical_resolution | ( | int | width, |
| int | height ) |
Definition at line 562 of file graphics.c.
References clamp_dim(), dttr_backend, refresh_render_resolution(), state, WINDOW_HEIGHT, and WINDOW_WIDTH.
| 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().
| 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().
| 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().
| 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().
| typedef kvec_t | ( | DTTR_BatchRecord | ) |
| typedef kvec_t | ( | int | ) |
|
extern |
Definition at line 8 of file util.c.
Referenced by create_shader(), d3d_device7_get_transform_state(), d3d_device7_record_clear(), d3d_device7_record_draw(), d3d_device7_set_blend_func(), d3d_device7_set_texture_address_u(), d3d_device7_set_texture_address_v(), d3d_device7_set_viewport(), d3d_device7_texture_bind(), d3ddevice7_gettexturestagestate(), d3ddevice7_getviewport(), d3ddevice7_setrenderstate(), d3ddevice7_settexturestagestate(), dttr_graphics_begin_frame(), dttr_graphics_cleanup(), dttr_graphics_end_frame(), dttr_graphics_get_device(), dttr_graphics_get_window(), dttr_graphics_handle_window_resize(), dttr_graphics_init(), dttr_graphics_is_gpu_thread(), dttr_graphics_present_video_frame_bgra(), dttr_graphics_sdl3gpu_create_pipelines(), dttr_graphics_sdl3gpu_create_resources(), dttr_graphics_sdl3gpu_resize_render_textures(), dttr_graphics_set_logical_resolution(), DTTR_Hook_WinMainCallback(), surface_present(), surface_texture_cache_lookup_locked(), surface_texture_create_or_retain(), surface_texture_refcount(), surface_texture_release(), surface_texture_retain(), surface_texture_update_unique(), and toggle_fullscreen().