diff --git a/src/ase/ase.c b/src/ase/ase.c index 23545927..04993e26 100644 --- a/src/ase/ase.c +++ b/src/ase/ase.c @@ -838,14 +838,10 @@ ASE_DecodedSheet ASE_DecodeSheet(Arena *arena, String encoded) u32 frame_tile_x = i % frames_x; u32 frame_tile_y = i / frames_x; - u32 frame_x1 = frame_tile_x * frame_width; - u32 frame_y1 = frame_tile_y * frame_height; - u32 frame_x2 = frame_x1 + frame_width; - u32 frame_y2 = frame_y1 + frame_height; - frame->x1 = frame_x1; - frame->y1 = frame_y1; - frame->x2 = frame_x2; - frame->y2 = frame_y2; + Vec2I32 frame_p0 = VEC2I32(frame_tile_x * frame_width, frame_tile_y * frame_height); + Vec2I32 frame_p1 = AddVec2I32(frame_p0, VEC2I32(frame_width, frame_height)); + frame->rect.p0 = frame_p0; + frame->rect.p1 = frame_p1; frame->index = i; frame->duration = frame_header.frame_duration_ms / 1000.0; @@ -934,10 +930,8 @@ ASE_DecodedSheet ASE_DecodeSheet(Arena *arena, String encoded) } slice->start = start; - slice->x1 = x; - slice->y1 = y; - slice->x2 = x + width; - slice->y2 = y + height; + slice->rect.p0 = VEC2I32(x, y); + slice->rect.p1 = VEC2I32(x + width, y + width); } ++num_slice_keys; diff --git a/src/ase/ase.h b/src/ase/ase.h index 490204ac..66f5d443 100644 --- a/src/ase/ase.h +++ b/src/ase/ase.h @@ -4,10 +4,7 @@ Struct(ASE_Slice) { u32 start; - i32 x1; - i32 y1; - i32 x2; - i32 y2; + Rng2I32 rect; ASE_Slice *next; }; @@ -22,10 +19,7 @@ Struct(ASE_Span) Struct(ASE_Frame) { u32 index; - u32 x1; - u32 y1; - u32 x2; - u32 y2; + Rng2I32 rect; f64 duration; ASE_Frame *next; }; diff --git a/src/base/base_math.c b/src/base/base_math.c index 966841ac..a170d0b4 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -1194,16 +1194,6 @@ Xform XformFromTrs(Trs trs) return xf; } -Xform XformFromRect(Rect rect) -{ - Vec2 half_size = MulVec2(rect.size, 0.5); - Xform xf = ZI; - xf.bx = VEC2(rect.size.x, 0); - xf.by = VEC2(0, rect.size.y); - xf.og = AddVec2(rect.pos, half_size); - return xf; -} - //- Translation Xform TranslateXform(Xform xf, Vec2 v) { @@ -1316,16 +1306,6 @@ Vec2 MulXformV2(Xform xf, Vec2 v) } -Quad MulXformQuad(Xform xf, Quad quad) -{ - Quad result; - result.p0 = MulXformV2(xf, quad.p0); - result.p1 = MulXformV2(xf, quad.p1); - result.p2 = MulXformV2(xf, quad.p2); - result.p3 = MulXformV2(xf, quad.p3); - return result; -} - Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v) { Xform inv = InvertXform(xf); @@ -1385,82 +1365,6 @@ Vec2 ScaleFromXform(Xform xf) return VEC2(Vec2Len(xf.bx), det_sign * Vec2Len(xf.by)); } -//////////////////////////////////////////////////////////// -//~ Quad operations - -Quad QuadFromRect(Rect rect) -{ - Quad result; - result.p0 = VEC2(rect.x, rect.y); /* Top left */ - result.p1 = VEC2(rect.x + rect.width, rect.y); /* Top right */ - result.p2 = VEC2(rect.x + rect.width, rect.y + rect.height); /* Bottom right */ - result.p3 = VEC2(rect.x, rect.y + rect.height); /* Bottom left */ - return result; -} - -Quad QuadFromAabb(Aabb aabb) -{ - Quad result; - result.p0 = VEC2(aabb.p0.x, aabb.p0.y); /* Top left */ - result.p1 = VEC2(aabb.p1.x, aabb.p0.y); /* Top right */ - result.p2 = VEC2(aabb.p1.x, aabb.p1.y); /* Bottom right */ - result.p3 = VEC2(aabb.p0.x, aabb.p1.y); /* Bottom left */ - return result; -} - -Quad QuadFromLine(Vec2 start, Vec2 end, f32 thickness) -{ - f32 width = thickness / 2.f; - - Vec2 dir = NormVec2(SubVec2(end, start)); - Vec2 dir_perp = PerpVec2(dir); - - Vec2 left = MulVec2(dir_perp, -width); - Vec2 right = MulVec2(dir_perp, width); - - Quad result; - result.p0 = AddVec2(start, left); - result.p1 = AddVec2(start, right); - result.p2 = AddVec2(end, right); - result.p3 = AddVec2(end, left); - return result; -} - -Quad QuadFromRay(Vec2 pos, Vec2 rel, f32 thickness) -{ - Vec2 end = AddVec2(pos, rel); - return QuadFromLine(pos, end, thickness); -} - -Quad ScaleQuad(Quad q, f32 s) -{ - q.p0 = MulVec2(q.p0, s); - q.p1 = MulVec2(q.p1, s); - q.p2 = MulVec2(q.p2, s); - q.p3 = MulVec2(q.p3, s); - return q; -} - -Quad RoundQuad(Quad quad) -{ - Quad result; - result.p0 = RoundVec2(quad.p0); - result.p1 = RoundVec2(quad.p1); - result.p2 = RoundVec2(quad.p2); - result.p3 = RoundVec2(quad.p3); - return result; -} - -Quad FloorQuad(Quad quad) -{ - Quad result; - result.p0 = FloorVec2(quad.p0); - result.p1 = FloorVec2(quad.p1); - result.p2 = FloorVec2(quad.p2); - result.p3 = FloorVec2(quad.p3); - return result; -} - //////////////////////////////////////////////////////////// //~ Spring operations diff --git a/src/base/base_math.h b/src/base/base_math.h index ffe4b042..0cf4694f 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -64,6 +64,17 @@ Struct(Vec4Array) u64 count; }; +//////////////////////////////////////////////////////////// +//~ Range types + +#define RNG2(p0, p1) (Rng2) { (p0), (p1) } +#define RNG2I32(p0, p1) (Rng2I32) { (p0), (p1) } +#define RNG2U32(p0, p1) (Rng2U32) { (p0), (p1) } + +Struct(Rng2) { Vec2 p0; Vec2 p1; }; +Struct(Rng2I32) { Vec2I32 p0; Vec2I32 p1; }; +Struct(Rng2U32) { Vec2U32 p0; Vec2U32 p1; }; + //////////////////////////////////////////////////////////// //~ Xform types @@ -82,42 +93,6 @@ Struct(Trs) f32 r; }; -//////////////////////////////////////////////////////////// -//~ Rect types - -Struct(Rect) { - union - { - struct { f32 x, y, width, height; }; - struct { Vec2 pos, size; }; - }; -}; - - -/* Values expected to be normalized 0.0 -> 1.0 */ -Struct(ClipRect) -{ - Vec2 p0, p1; -}; - -//////////////////////////////////////////////////////////// -//~ Axis aligned bounding box types - -Struct(Aabb) { - Vec2 p0, p1; -}; - -//////////////////////////////////////////////////////////// -//~ Quad types - -Struct(Quad) { - union - { - struct { Vec2 p0, p1, p2, p3; }; - struct { Vec2 e[4]; }; - }; -}; - //////////////////////////////////////////////////////////// //~ Spring types @@ -354,7 +329,6 @@ Xform XformFromPos(Vec2 v); Xform XformFromRot(f32 r); Xform XformFromScale(Vec2 scale); Xform XformFromTrs(Trs trs); -Xform XformFromRect(Rect rect); //- Translation Xform TranslateXform(Xform xf, Vec2 v); @@ -379,7 +353,6 @@ Xform InvertXform(Xform xf); //- Mul Vec2 MulXformV2(Xform xf, Vec2 v); Xform MulXform(Xform a, Xform b); -Quad MulXformQuad(Xform xf, Quad quad); Vec2 MulXformBasisV2(Xform xf, Vec2 v); Vec2 InvertXformMulV2(Xform xf, Vec2 v); Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v); @@ -397,27 +370,6 @@ Vec2 ScaleFromXform(Xform xf); //- Trs #define TRS(...) ((Trs) { .t = VEC2(0,0), .s = VEC2(1, 1), .r = 0, __VA_ARGS__ }) -//////////////////////////////////////////////////////////// -//~ Rect operations - -#define RectFromScalar(_x, _y, _width, _height) (Rect) { .x = (_x), .y = (_y), .width = (_width), .height = (_height) } -#define RectFromVec2(_pos, _size) (Rect) { .pos = (_pos), .size = (_size) } -#define AllClipped ((ClipRect) { { 0.0f, 0.0f }, { 1.0f, 1.0f } }) - -//////////////////////////////////////////////////////////// -//~ Quad operations - -#define UnitSquareQuad (Quad) { .p0 = VEC2(0, 0), .p1 = VEC2(0, 1), .p2 = VEC2(1, 1), .p3 = VEC2(1, 0) } -#define CenteredUnitSquareQuad (Quad) { .p0 = VEC2(-0.5f, -0.5f), .p1 = VEC2(0.5f, -0.5f), .p2 = VEC2(0.5f, 0.5f), .p3 = VEC2(-0.5f, 0.5f) } - -Quad QuadFromRect(Rect rect); -Quad QuadFromAabb(Aabb aabb); -Quad QuadFromLine(Vec2 start, Vec2 end, f32 thickness); -Quad QuadFromRay(Vec2 pos, Vec2 rel, f32 thickness); -Quad ScaleQuad(Quad q, f32 s); -Quad RoundQuad(Quad quad); -Quad FloorQuad(Quad quad); - //////////////////////////////////////////////////////////// //~ Spring operations diff --git a/src/gpu/gpu_core.h b/src/gpu/gpu_core.h index ef35ad65..19d42991 100644 --- a/src/gpu/gpu_core.h +++ b/src/gpu/gpu_core.h @@ -380,8 +380,8 @@ void GPU_QueueWait(GPU_QueueKind a, GPU_QueueKind b, i64 b_target_fence_value); //////////////////////////////////////////////////////////// //~ @hookdecl Rasterizer helpers -GPU_Viewport GPU_ViewportFromRect(Rect rect); -GPU_Scissor GPU_ScissorFromRect(Rect rect); +GPU_Viewport GPU_ViewportFromRect(Rng2 rect); +GPU_Scissor GPU_ScissorFromRect(Rng2 rect); //////////////////////////////////////////////////////////// //~ @hookdecl Resource operations diff --git a/src/gpu/gpu_dx12/gpu_dx12.c b/src/gpu/gpu_dx12/gpu_dx12.c index 2385236b..e81cf377 100644 --- a/src/gpu/gpu_dx12/gpu_dx12.c +++ b/src/gpu/gpu_dx12/gpu_dx12.c @@ -770,25 +770,25 @@ void GPU_QueueWait(GPU_QueueKind a, GPU_QueueKind b, i64 b_target_fence_value) //////////////////////////////////////////////////////////// //~ @hookdef Rasterizer helper hooks -GPU_Viewport GPU_ViewportFromRect(Rect rect) +GPU_Viewport GPU_ViewportFromRect(Rng2 rect) { GPU_Viewport viewport = ZI; - viewport.top_left_x = rect.x; - viewport.top_left_y = rect.y; - viewport.width = rect.width; - viewport.height = rect.height; - viewport.min_depth = 0.0f; - viewport.max_depth = 1.0f; + viewport.top_left_x = rect.p0.x; + viewport.top_left_y = rect.p0.y; + viewport.width = rect.p1.x - rect.p0.x; + viewport.height = rect.p1.y - rect.p0.y; + viewport.min_depth = 0.0f; + viewport.max_depth = 1.0f; return viewport; } -GPU_Scissor GPU_ScissorFromRect(Rect rect) +GPU_Scissor GPU_ScissorFromRect(Rng2 rect) { GPU_Scissor scissor = ZI; - scissor.left = rect.x; - scissor.top = rect.y; - scissor.right = rect.x + rect.width; - scissor.bottom = rect.y + rect.height; + scissor.left = rect.p0.x; + scissor.top = rect.p0.y; + scissor.right = rect.p1.x; + scissor.bottom = rect.p1.y; return scissor; } diff --git a/src/platform/platform.h b/src/platform/platform.h index 3711c9e5..2860a7e9 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -2,7 +2,6 @@ //~ Opaque types Struct(P_Watch); -Struct(P_Window); Struct(P_Sock); //////////////////////////////////////////////////////////// @@ -28,197 +27,6 @@ Struct(P_FileMap) b32 valid; }; -//////////////////////////////////////////////////////////// -//~ Window event types - -//- Button -Enum(P_Btn) -{ - P_Btn_None, - - P_Btn_M1, - P_Btn_M2, - P_Btn_M3, - P_Btn_M4, - P_Btn_M5, - - P_Btn_MWheelUp, - P_Btn_MWheelDown, - - P_Btn_ESC, - P_Btn_F1, - P_Btn_F2, - P_Btn_F3, - P_Btn_F4, - P_Btn_F5, - P_Btn_F6, - P_Btn_F7, - P_Btn_F8, - P_Btn_F9, - P_Btn_F10, - P_Btn_F11, - P_Btn_F12, - P_Btn_F13, - P_Btn_F14, - P_Btn_F15, - P_Btn_F16, - P_Btn_F17, - P_Btn_F18, - P_Btn_F19, - P_Btn_F20, - P_Btn_F21, - P_Btn_F22, - P_Btn_F23, - P_Btn_F24, - P_Btn_GraveAccent, - P_Btn_0, - P_Btn_1, - P_Btn_2, - P_Btn_3, - P_Btn_4, - P_Btn_5, - P_Btn_6, - P_Btn_7, - P_Btn_8, - P_Btn_9, - P_Btn_Minus, - P_Btn_Equal, - P_Btn_Backspace, - P_Btn_Delete, - P_Btn_Tab, - P_Btn_A, - P_Btn_B, - P_Btn_C, - P_Btn_D, - P_Btn_E, - P_Btn_F, - P_Btn_G, - P_Btn_H, - P_Btn_I, - P_Btn_J, - P_Btn_K, - P_Btn_L, - P_Btn_M, - P_Btn_N, - P_Btn_O, - P_Btn_P, - P_Btn_Q, - P_Btn_R, - P_Btn_S, - P_Btn_T, - P_Btn_U, - P_Btn_V, - P_Btn_W, - P_Btn_X, - P_Btn_Y, - P_Btn_Z, - P_Btn_Space, - P_Btn_Enter, - P_Btn_Ctrl, - P_Btn_Shift, - P_Btn_Alt, - P_Btn_Up, - P_Btn_Left, - P_Btn_Down, - P_Btn_Right, - P_Btn_PageUp, - P_Btn_PageDown, - P_Btn_Home, - P_Btn_End, - P_Btn_ForwardSlash, - P_Btn_Period, - P_Btn_Comma, - P_Btn_Quote, - P_Btn_LeftBracket, - P_Btn_RightBracket, - P_Btn_Insert, - P_Btn_Semicolon, - - P_Btn_Count -}; - -//- Window event -Enum(P_WindowEventKind) -{ - P_WindowEventKind_None, - - P_WindowEventKind_ButtonDown, - P_WindowEventKind_ButtonUp, - P_WindowEventKind_CursorMove, - P_WindowEventKind_MouseMove, - P_WindowEventKind_Text, - P_WindowEventKind_Quit, - - P_WindowEventKind_Count -}; - -Struct(P_WindowEvent) -{ - P_WindowEventKind kind; - - /* P_WindowEventKind_ButtonDown */ - /* P_WindowEventKind_ButtonUp */ - P_Btn button; - b32 is_repeat; - - /* P_WindowEventKind_Text */ - u32 text_codepoint; - - /* P_WindowEventKind_CursorMove */ - Vec2 cursor_position; - - /* P_WindowEventKind_MouseMove */ - Vec2 mouse_delta; -}; - -Struct(P_WindowEventArray) -{ - u64 count; - P_WindowEvent *events; -}; - -//////////////////////////////////////////////////////////// -//~ Window setting types - -/* NOTE: - * A window object can only be interacted with by the thread that created it. - * This restriction is in place because of how Win32 works, IE you cannot - * create a Win32 window in one thread and process its messages on another. */ - -Enum(P_WindowSettingsFlag) -{ - P_WindowSettingsFlag_None = 0x00, - P_WindowSettingsFlag_Fullscreen = 0x01, - - /* NOTE: Both maximized and minimized can be true at the same time. This - * means that the window was minimized from a maximized state, and will - * restore to being maximized once it's un-minimized. */ - P_WindowSettingsFlag_Maximized = 0x02, - P_WindowSettingsFlag_Minimized = 0x04 -}; - -Enum(P_WindowFlag) -{ - P_WindowFlag_None = 0x00, - P_WindowFlag_Showing = 0x02 -}; - -/* P_UpdateWindowSettings should be used when altering settings values */ -Struct(P_WindowSettings) -{ - char title[256]; - u32 flags; - - /* NOTE: Below fields are NOT representative of actual window dimensions. - * These values represent the window dimensions when the window is not - * maximized, minimized, or fullscreen. AKA 'floating'. Use - * `P_GetWindowSize` for rendering instead. */ - i32 floating_x; - i32 floating_y; - i32 floating_width; - i32 floating_height; -}; - //////////////////////////////////////////////////////////// //~ Address types @@ -296,31 +104,6 @@ P_FileMap P_OpenFileMap(P_File file); void P_CloseFileMap(P_FileMap map); String P_GetFileMapData(P_FileMap map); -//////////////////////////////////////////////////////////// -//~ @hookdecl Window hooks - -P_Window *P_AcquireWindow(void); -void P_ReleaseWindow(P_Window *window); - -//- Events -P_WindowEventArray P_PopWindowEvents(Arena *arena, P_Window *window); - -//- Settings -void P_UpdateWindowSettings(P_Window *window, P_WindowSettings *settings); -P_WindowSettings P_GetWindowSettings(P_Window *window); -void P_ShowWindow(P_Window *window); -void P_SetWindowCursorPos(P_Window *window, Vec2 pos); -void P_ShowWindowCursor(P_Window *window); -void P_HideWindowCursor(P_Window *window); -void P_EnableWindoweCursorClip(P_Window *window, Rect bounds); -void P_DisableWindoweCursorClip(P_Window *window); -void P_ToggleWindowTopmost(P_Window *window); - -//- Info -Vec2I32 P_GetWindowSize(P_Window *window); -Vec2I32 P_GetWindowMonitorSize(P_Window *window); -u64 P_GetInternalWindowHandle(P_Window *window); - //////////////////////////////////////////////////////////// //~ @hookdecl Address helper hooks diff --git a/src/proto/pp_vis/pp_vis.lay b/src/proto/pp_vis/pp_vis.lay index d3d6d9ac..f0309523 100644 --- a/src/proto/pp_vis/pp_vis.lay +++ b/src/proto/pp_vis/pp_vis.lay @@ -4,10 +4,6 @@ @Dep gpu @Dep sprite @Dep font -@Dep collider -@Dep net -@Dep mixer -@Dep playback @Dep platform @Dep window @Dep ui diff --git a/src/proto/pp_vis/pp_vis_core.c b/src/proto/pp_vis/pp_vis_core.c index c7574dd8..4383ac3e 100644 --- a/src/proto/pp_vis/pp_vis_core.c +++ b/src/proto/pp_vis/pp_vis_core.c @@ -391,8 +391,8 @@ JobDef(V_VisWorker, _, __) u64 dverts_count = GPU_GetBufferCount(dverts_buffer); u64 dvert_idx_count = GPU_GetBufferCount(dvert_idx_buffer); - GPU_Viewport viewport = GPU_ViewportFromRect(RectFromVec2(VEC2(0, 0), Vec2FromFields(draw_size))); - GPU_Scissor scissor = GPU_ScissorFromRect(RectFromVec2(VEC2(0, 0), Vec2FromFields(draw_size))); + GPU_Viewport viewport = GPU_ViewportFromRect(RNG2(VEC2(0, 0), Vec2FromFields(draw_size))); + GPU_Scissor scissor = GPU_ScissorFromRect(RNG2(VEC2(0, 0), Vec2FromFields(draw_size))); GPU_CommandList *cl = GPU_BeginCommandList(GPU_QueueKind_Direct); { diff --git a/src/sprite/sprite.c b/src/sprite/sprite.c index 0a3d37dd..b90fea9b 100644 --- a/src/sprite/sprite.c +++ b/src/sprite/sprite.c @@ -126,8 +126,8 @@ JobDef(SPR_LoadSheet, sig, _) SPR_Frame *dst = &sheet->frames[src->index]; dst->index = src->index; dst->duration = src->duration; - dst->clip.p0 = VEC2((f32)src->x1 / (f32)image_size.x, (f32)src->y1 / (f32)image_size.y); - dst->clip.p1 = VEC2((f32)src->x2 / (f32)image_size.x, (f32)src->y2 / (f32)image_size.y); + dst->clip.p0 = VEC2((f32)src->rect.p0.x / (f32)image_size.x, (f32)src->rect.p0.y / (f32)image_size.y); + dst->clip.p1 = VEC2((f32)src->rect.p1.x / (f32)image_size.x, (f32)src->rect.p1.y / (f32)image_size.y); } /* Init spans */ @@ -172,27 +172,27 @@ JobDef(SPR_LoadSheet, sig, _) /* Fill is_original slices */ for (ASE_Slice *src_slice = src_group->first_slice; src_slice; src_slice = src_slice->next) { - f32 x1_px = src_slice->x1; - f32 y1_px = src_slice->y1; - f32 x2_px = src_slice->x2; - f32 y2_px = src_slice->y2; - f32 width_px = x2_px - x1_px; - f32 height_px = y2_px - y1_px; + f32 x0_px = src_slice->rect.p0.x; + f32 y0_px = src_slice->rect.p0.y; + f32 x1_px = src_slice->rect.p1.x; + f32 y1_px = src_slice->rect.p1.y; + f32 width_px = x1_px - x0_px; + f32 height_px = y1_px - y0_px; + f32 x0 = (x0_px - frame_center.x) / frame_size.x; + f32 y0 = (y0_px - frame_center.y) / frame_size.y; f32 x1 = (x1_px - frame_center.x) / frame_size.x; f32 y1 = (y1_px - frame_center.y) / frame_size.y; - f32 x2 = (x2_px - frame_center.x) / frame_size.x; - f32 y2 = (y2_px - frame_center.y) / frame_size.y; - f32 width = x2 - x1; - f32 height = y2 - y1; + f32 width = x1 - x0; + f32 height = y1 - y0; /* Rect */ - Rect rect_px = RectFromScalar(x1_px, y1_px, width_px, height_px); - Rect rect = RectFromScalar(x1, y1, width, height); + Rng2 rect_px = RNG2(VEC2(x0_px, y0_px), VEC2(x1_px, y1_px)); + Rng2 rect = RNG2(VEC2(x0, y0), VEC2(x1, y1)); /* Center */ - Vec2 center_px = VEC2(x1_px + (width_px * 0.5f), y1_px + (height_px * 0.5f)); - Vec2 center = VEC2(x1 + (width * 0.5f), y1 + (height * 0.5f)); + Vec2 center_px = VEC2(x0_px + (width_px * 0.5f), y0_px + (height_px * 0.5f)); + Vec2 center = VEC2(x0 + (width * 0.5f), y0 + (height * 0.5f)); /* Dir */ Vec2 dir_px = VEC2(center_px.x, -1); diff --git a/src/sprite/sprite.h b/src/sprite/sprite.h index eaa01760..d2b1b8d8 100644 --- a/src/sprite/sprite.h +++ b/src/sprite/sprite.h @@ -32,7 +32,7 @@ Struct(SPR_Frame) { u32 index; f64 duration; - ClipRect clip; + Rng2 clip; }; Struct(SPR_Span) @@ -59,12 +59,12 @@ Struct(SPR_Slice) b32 has_dir; /* Values are in the range -0.5 (top / left edge) -> +0.5 (bottom / right edge) */ - Rect rect; + Rng2 rect; Vec2 center; Vec2 dir; /* '_px' values retain the original sprite pixel dimensions */ - Rect rect_px; + Rng2 rect_px; Vec2 center_px; Vec2 dir_px; }; diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 56cce306..edd7619a 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -683,7 +683,7 @@ i64 UI_EndFrame(UI_Frame frame) ZeroStruct(&g->eframe); g->eframe.layout_arena = old_eframe.layout_arena; g->eframe.rects_arena = old_eframe.rects_arena; - g->eframe.render_target = old_eframe.render_target; + g->eframe.draw_target = old_eframe.draw_target; g->eframe.swapchain = old_eframe.swapchain; g->eframe.gpu_submit_fence_target = old_eframe.gpu_submit_fence_target; g->eframe.draw_rects_tbuff = old_eframe.draw_rects_tbuff; @@ -701,21 +701,20 @@ i64 UI_EndFrame(UI_Frame frame) ////////////////////////////// //- Init render state - Vec2I32 draw_size = frame.window_frame.draw_size; Vec2I32 monitor_size = frame.window_frame.monitor_size; GPU_QueueKind gpu_render_queue = GPU_QueueKind_Direct; Fence *submit_fence = GPU_FenceFromQueue(gpu_render_queue); /* Acquire render target */ - if (g->eframe.render_target && !MatchVec2I32(monitor_size, GPU_GetTextureSize2D(g->eframe.render_target))) + if (g->eframe.draw_target && !MatchVec2I32(monitor_size, GPU_GetTextureSize2D(g->eframe.draw_target))) { __profn("Release ui render target"); YieldOnFence(submit_fence, g->eframe.gpu_submit_fence_target); - GPU_ReleaseResource(g->eframe.render_target, GPU_ReleaseFlag_None); - g->eframe.render_target = 0; + GPU_ReleaseResource(g->eframe.draw_target, GPU_ReleaseFlag_None); + g->eframe.draw_target = 0; } - if (!g->eframe.render_target) + if (!g->eframe.draw_target) { __profn("Acquire ui render target"); GPU_ResourceDesc desc = ZI; @@ -724,12 +723,12 @@ i64 UI_EndFrame(UI_Frame frame) // desc.texture.format = GPU_Format_R8G8B8A8_Unorm; desc.texture.format = GPU_Format_R16G16B16A16_Float; desc.texture.size = VEC3I32(monitor_size.x, monitor_size.y, 1); - g->eframe.render_target = GPU_AcquireResource(desc); + g->eframe.draw_target = GPU_AcquireResource(desc); } - Rect render_viewport = ZI; - render_viewport.pos = VEC2(0, 0); - render_viewport.size = VEC2(draw_size.x, draw_size.y); + Vec2I32 draw_size = frame.window_frame.draw_size; + Rng2 draw_viewport = ZI; + draw_viewport.p1 = Vec2FromFields(draw_size); ////////////////////////////// //- Process commands @@ -1440,8 +1439,8 @@ i64 UI_EndFrame(UI_Frame frame) { __profn("Clear target"); GPU_ProfN(cl, Lit("Clear target")); - GPU_TransitionToRenderable(cl, g->eframe.render_target, 0); - GPU_ClearRenderable(cl, g->eframe.render_target); + GPU_TransitionToRenderable(cl, g->eframe.draw_target, 0); + GPU_ClearRenderable(cl, g->eframe.draw_target); } //- Rect pass @@ -1450,13 +1449,13 @@ i64 UI_EndFrame(UI_Frame frame) __profn("UI rect pass"); GPU_ProfN(cl, Lit("UI rect pass")); - GPU_Viewport viewport = GPU_ViewportFromRect(render_viewport); - GPU_Scissor scissor = GPU_ScissorFromRect(render_viewport); + GPU_Viewport viewport = GPU_ViewportFromRect(draw_viewport); + GPU_Scissor scissor = GPU_ScissorFromRect(draw_viewport); /* Render rects */ { UI_DRectSig sig = ZI; - sig.viewport_size = RoundVec2ToVec2I32(render_viewport.size); + sig.viewport_size = draw_size; sig.sampler = GPU_SamplerStateRidFromResource(GPU_GetCommonPointSampler()); sig.rects = GPU_StructuredBufferRidFromResource(draw_rects_buffer); GPU_Rasterize(cl, @@ -1474,7 +1473,7 @@ i64 UI_EndFrame(UI_Frame frame) if (AnyBit(g->bframe.frame_flags, UI_FrameFlag_Debug)) { UI_DRectSig sig = ZI; - sig.viewport_size = RoundVec2ToVec2I32(render_viewport.size); + sig.viewport_size = draw_size; sig.sampler = GPU_SamplerStateRidFromResource(GPU_GetCommonPointSampler()); sig.rects = GPU_StructuredBufferRidFromResource(draw_rects_buffer); sig.debug_enabled = 1; @@ -1509,7 +1508,7 @@ i64 UI_EndFrame(UI_Frame frame) Vec2I32 dst_p1 = VEC2I32(0, 0); Vec2I32 src_p0 = VEC2I32(0, 0); Vec2I32 src_p1 = draw_size; - g->eframe.gpu_submit_fence_target = GPU_PresentSwapchain(g->eframe.swapchain, g->eframe.render_target, AnyBit(g->bframe.frame_flags, UI_FrameFlag_Vsync), backbuffer_size, dst_p0, dst_p1, src_p0, src_p1, LinearFromSrgb(g->bframe.swapchain_color)); + g->eframe.gpu_submit_fence_target = GPU_PresentSwapchain(g->eframe.swapchain, g->eframe.draw_target, AnyBit(g->bframe.frame_flags, UI_FrameFlag_Vsync), backbuffer_size, dst_p0, dst_p1, src_p0, src_p1, LinearFromSrgb(g->bframe.swapchain_color)); } WND_EndFrame(frame.window_frame); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 2300fe4a..00e935ed 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -376,7 +376,7 @@ Struct(UI_State) u64 tick; /* Render */ - GPU_Resource *render_target; + GPU_Resource *draw_target; GPU_Swapchain *swapchain; i64 gpu_submit_fence_target; GPU_TransientBuffer draw_rects_tbuff;