diff --git a/src/base/base_math.c b/src/base/base_math.c index 338c0f73..f2b33758 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -1002,6 +1002,11 @@ Vec2 LerpVec2(Vec2 val0, Vec2 val1, f32 t) return VEC2(LerpF32(val0.x, val1.x, t), LerpF32(val0.y, val1.y, t)); } +Vec2 LerpVec2Vec2(Vec2 val0, Vec2 val1, Vec2 t) +{ + return VEC2(LerpF32(val0.x, val1.x, t.x), LerpF32(val0.y, val1.y, t.y)); +} + /* Interpolate direction vectors (spherical lerp) */ Vec2 SlerpVec2(Vec2 val0, Vec2 val1, f32 t) { @@ -1123,7 +1128,7 @@ Xform WorldRotateXformBasis(Xform xf, f32 r) return xf; } -Xform XformWIthWorldRotation(Xform xf, f32 r) +Xform XformWithWorldRotation(Xform xf, f32 r) { return WorldRotateXformBasis(xf, r - RotationFromXform(xf)); } diff --git a/src/base/base_math.h b/src/base/base_math.h index 88f5edef..a005361c 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -257,7 +257,7 @@ i64 LerpI64(i64 val0, i64 val1, f64 t); //////////////////////////////////////////////////////////// //~ Vec2 operations -#define Vec2FromVec(v) VEC2((v).x, (v).y) +#define Vec2FromFields(v) VEC2((v).x, (v).y) b32 IsVec2Zero(Vec2 a); b32 EqVec2(Vec2 a, Vec2 b); @@ -309,6 +309,7 @@ Vec2 ClosestPointFromRay(Vec2 ray_pos, Vec2 ray_dir_norm, Vec2 p); //- Lerp Vec2 LerpVec2(Vec2 val0, Vec2 val1, f32 t); +Vec2 LerpVec2Vec2(Vec2 val0, Vec2 val1, Vec2 t); Vec2 SlerpVec2(Vec2 val0, Vec2 val1, f32 t); //////////////////////////////////////////////////////////// @@ -341,7 +342,7 @@ Xform WorldTranslateXform(Xform xf, Vec2 v); Xform RotateXform(Xform xf, f32 r); Xform WorldRotateXform(Xform xf, f32 r); Xform WorldRotateXformBasis(Xform xf, f32 r); -Xform XformWIthWorldRotation(Xform xf, f32 r); +Xform XformWithWorldRotation(Xform xf, f32 r); //- Scale Xform ScaleXform(Xform xf, Vec2 scale); diff --git a/src/pp/pp.c b/src/pp/pp.c index 50db4eca..a2c30735 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -464,21 +464,15 @@ void UpdateUser(P_Window *window) //- Begin UI UI_BeginBuild(); PushGameUiStyle(); - UI_Box *pp_root_box = UI_BuildBox(UI_BoxFlag_DrawImage, UI_NilKey); + UI_Box *pp_root_box = UI_BuildBox(0, UI_NilKey); UI_Push(Parent, pp_root_box); //- Init render data buffers if (!g->material_instances_arena) { g->material_instances_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(MaterialInstance)); - g->ui_rect_instances_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(UiRectInstance)); - g->ui_shape_verts_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(UiShapeVert)); - g->ui_shape_indices_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(u32)); g->grids_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(MaterialGrid)); g->material_instances_arena = AcquireArena(Gibi(64)); - g->ui_rect_instances_arena = AcquireArena(Gibi(64)); - g->ui_shape_verts_arena = AcquireArena(Gibi(64)); - g->ui_shape_indices_arena = AcquireArena(Gibi(64)); g->grids_arena = AcquireArena(Gibi(64)); } @@ -869,7 +863,7 @@ void UpdateUser(P_Window *window) if (g->debug_camera) { - g->world_to_ui_xf = XformWIthWorldRotation(g->world_to_ui_xf, 0); + g->world_to_ui_xf = XformWithWorldRotation(g->world_to_ui_xf, 0); Vec2 world_cursor = InvertXformMulV2(g->world_to_ui_xf, g->ui_cursor); @@ -941,6 +935,7 @@ void UpdateUser(P_Window *window) //- Update world to render xform from world to ui xform b32 effects_disabled = 0; + // b32 effects_disabled = 1; g->render_size = RoundVec2ToVec2I32(VEC2(RENDER_WIDTH, RENDER_HEIGHT)); if (g->debug_camera) @@ -2287,28 +2282,10 @@ void UpdateUser(P_Window *window) g->shade_target = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); } - /* Acquire ui buffers */ - if (g->ui_target && !EqVec2I32(g->ui_size, GPU_GetTextureSize2D(g->ui_target))) - { - YieldOnFence(render_fence, g->gpu_render_fence_target); - GPU_ReleaseResource(g->ui_target, GPU_ReleaseFlag_None); - g->ui_target = 0; - } - if (!g->ui_target) - { - g->ui_target = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->ui_size); - } - /* Upload transient buffers */ GPU_Resource *material_instances_buffer = GPU_UploadTransientBufferFromArena(&g->material_instances_tbuff, g->material_instances_arena); - GPU_Resource *ui_rect_instances_buffer = GPU_UploadTransientBufferFromArena(&g->ui_rect_instances_tbuff, g->ui_rect_instances_arena); - GPU_Resource *ui_shape_verts_buffer = GPU_UploadTransientBufferFromArena(&g->ui_shape_verts_tbuff, g->ui_shape_verts_arena); - GPU_Resource *ui_shape_indices_buffer = GPU_UploadTransientBufferFromArena(&g->ui_shape_indices_tbuff, g->ui_shape_indices_arena); GPU_Resource *grids_buffer = GPU_UploadTransientBufferFromArena(&g->grids_tbuff, g->grids_arena); u64 material_instances_count = GPU_GetBufferCount(material_instances_buffer); - u64 ui_rect_instances_count = GPU_GetBufferCount(ui_rect_instances_buffer); - u64 ui_shape_verts_count = GPU_GetBufferCount(ui_shape_verts_buffer); - u64 ui_shape_indices_count = GPU_GetBufferCount(ui_shape_indices_buffer); u64 grids_count = GPU_GetBufferCount(grids_buffer); GPU_CommandList *cl = GPU_BeginCommandList(gpu_render_queue); @@ -2463,108 +2440,30 @@ void UpdateUser(P_Window *window) g->shade_target = swp; } - //- Prep ui pass - { - __profn("Clear ui target"); - GPU_ProfN(cl, Lit("Clear ui target")); - GPU_FlushWritable(cl, g->shade_read); - GPU_TransitionToRenderable(cl, g->ui_target, 0); - GPU_ClearRenderable(cl, g->ui_target); - } - - //- Ui blit pass - { - __profn("UI blit pass"); - GPU_ProfN(cl, Lit("UI blit pass")); - - GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport); - GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport); - - UiBlitSig sig = ZI; - sig.sampler = GPU_SamplerStateRidFromResource(GPU_GetCommonPointSampler()); - sig.src = GPU_Texture2DRidFromResource(g->shade_read); - sig.projection = blit_vp_matrix; - // sig.flags = UiBlitFlag_ToneMap | UiBlitFlag_GammaCorrect; - sig.exposure = 2.0; - sig.gamma = (f32)2.2; - GPU_Rasterize(cl, - &sig, - UiBlitVS, UiBlitPS, - 1, - viewport, - scissor, - 1, - GPU_GetCommonQuadIndices(), - GPU_RasterizeMode_TriangleList); - } - - //- Ui rect pass - { - __profn("UI rect pass"); - GPU_ProfN(cl, Lit("UI rect pass")); - - GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport); - GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport); - - UiRectSig sig = ZI; - sig.projection = ui_vp_matrix; - sig.sampler = GPU_SamplerStateRidFromResource(GPU_GetCommonPointSampler()); - sig.instances = GPU_StructuredBufferRidFromResource(ui_rect_instances_buffer); - GPU_Rasterize(cl, - &sig, - UiRectVS, UiRectPS, - 1, - viewport, - scissor, - ui_rect_instances_count, - GPU_GetCommonQuadIndices(), - GPU_RasterizeMode_TriangleList); - } - - //- Ui shape pass - { - __profn("UI shape pass"); - GPU_ProfN(cl, Lit("UI shape pass")); - - GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport); - GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport); - - UiShapeSig sig = ZI; - sig.projection = ui_vp_matrix; - sig.verts = GPU_StructuredBufferRidFromResource(ui_shape_verts_buffer); - GPU_Rasterize(cl, - &sig, - UiShapeVS, UiShapePS, - 1, - viewport, - scissor, - 1, - ui_shape_indices_buffer, - GPU_RasterizeMode_TriangleList); - } - //- Transition target to readable before UI pass - GPU_TransitionToReadable(cl, g->ui_target); - + GPU_TransitionToReadable(cl, g->shade_read); + GPU_TransitionToReadable(cl, g->shade_target); } g->gpu_render_fence_target = GPU_EndCommandList(cl); /* Reset render data */ GPU_ResetTransientBuffer(&g->material_instances_tbuff, g->gpu_render_fence_target); - GPU_ResetTransientBuffer(&g->ui_rect_instances_tbuff, g->gpu_render_fence_target); - GPU_ResetTransientBuffer(&g->ui_shape_verts_tbuff, g->gpu_render_fence_target); - GPU_ResetTransientBuffer(&g->ui_shape_indices_tbuff, g->gpu_render_fence_target); GPU_ResetTransientBuffer(&g->grids_tbuff, g->gpu_render_fence_target); ResetArena(g->material_instances_arena); - ResetArena(g->ui_rect_instances_arena); - ResetArena(g->ui_shape_verts_arena); - ResetArena(g->ui_shape_indices_arena); ResetArena(g->grids_arena); } + /* Set root background texture to game texture */ + { + pp_root_box->background_texture = g->shade_read; + Xform ui_to_render_xf = InvertXform(g->render_to_ui_xf); + Vec2 p0 = MulXformV2(ui_to_render_xf, VEC2(0, 0)); + Vec2 p1 = MulXformV2(ui_to_render_xf, Vec2FromFields(g->ui_size)); + pp_root_box->background_texture_uv0 = DivVec2Vec2(p0, Vec2FromFields(g->render_size)); + pp_root_box->background_texture_uv1 = DivVec2Vec2(p1, Vec2FromFields(g->render_size)); + } + /* Render UI */ - UI_SetDisplayImage(pp_root_box, g->ui_target); - // UI_SetDisplayImage(pp_root_box, F_LoadFontWait(UI_GetDefaultFontResource(), 12.0)->texture); GPU_Resource *ui_render = UI_EndBuild(ui_viewport); ////////////////////////////// diff --git a/src/pp/pp.h b/src/pp/pp.h index 7d6c9b9c..3e7a295f 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -179,18 +179,11 @@ Struct(SharedUserState) GPU_Resource *emittance_flood_target; GPU_Resource *shade_read; GPU_Resource *shade_target; - GPU_Resource *ui_target; //- Renderer transient buffers GPU_TransientBuffer material_instances_tbuff; - GPU_TransientBuffer ui_rect_instances_tbuff; - GPU_TransientBuffer ui_shape_verts_tbuff; - GPU_TransientBuffer ui_shape_indices_tbuff; GPU_TransientBuffer grids_tbuff; Arena *material_instances_arena; - Arena *ui_rect_instances_arena; - Arena *ui_shape_verts_arena; - Arena *ui_shape_indices_arena; Arena *grids_arena; //- Renderer state diff --git a/src/pp/pp.lay b/src/pp/pp.lay index 8c7af611..43a04fc6 100644 --- a/src/pp/pp.lay +++ b/src/pp/pp.lay @@ -38,12 +38,6 @@ @PixelShader MaterialPS @ComputeShader FloodCS @ComputeShader ShadeCS -@VertexShader UiBlitVS -@PixelShader UiBlitPS -@VertexShader UiRectVS -@PixelShader UiRectPS -@VertexShader UiShapeVS -@PixelShader UiShapePS //- Startup @Startup StartupSim diff --git a/src/pp/pp_draw.gpu b/src/pp/pp_draw.gpu index a9ccec80..8dfaf4f3 100644 --- a/src/pp/pp_draw.gpu +++ b/src/pp/pp_draw.gpu @@ -1,9 +1,6 @@ ConstantBuffer mat_sig : register (b0); ConstantBuffer flood_sig : register (b0); ConstantBuffer shade_sig : register (b0); -ConstantBuffer ui_blit_sig : register (b0); -ConstantBuffer ui_rect_sig : register (b0); -ConstantBuffer ui_shape_sig : register (b0); //////////////////////////////////////////////////////////// //~ Material @@ -190,7 +187,7 @@ void CSDef(FloodCS, Semantic(Vec3U32, sv_dispatchthreadid)) //- Lighting -f32 RandAngle(Vec2U32 pos, u32 ray_index) +f32 RandAngleFromPos(Vec2U32 pos, u32 ray_index) { ConstantBuffer sig = shade_sig; Texture3D noise_tex = UniformResourceFromRid(sig.noise); @@ -204,7 +201,7 @@ f32 RandAngle(Vec2U32 pos, u32 ray_index) return ((f32)noise / (f32)0xFFFF) * Tau; } -Vec3 ColorFromDir(Vec2U32 ray_start, Vec2 ray_dir) +Vec3 LightFromDir(Vec2U32 ray_start, Vec2 ray_dir) { ConstantBuffer sig = shade_sig; Texture2D flood_tex = UniformResourceFromRid(sig.emittance_flood); @@ -241,21 +238,21 @@ Vec3 ColorFromDir(Vec2U32 ray_start, Vec2 ray_dir) return result; } -Vec3 ColorFromPos(Vec2U32 pos) +Vec3 AccumulatedLightFromPos(Vec2U32 pos) { Vec3 result = 0; for (u32 i = 0; i < LightSamples; ++i) { - f32 angle = RandAngle(pos, i); + f32 angle = RandAngleFromPos(pos, i); Vec2 dir = Vec2(cos(angle), sin(angle)); - Vec3 light_in_dir = ColorFromDir(pos, dir); + Vec3 light_in_dir = LightFromDir(pos, dir); result += light_in_dir; } result /= LightSamples; return result; } -//- Tone mappign +//- Tone mapping /* ACES approximation by Krzysztof Narkowicz * https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ */ @@ -284,7 +281,7 @@ void CSDef(ShadeCS, Semantic(Vec3U32, sv_dispatchthreadid)) /* Apply lighting */ if (!(sig.flags & ShadeFlag_DisableEffects)) { - color.rgb *= ColorFromPos(id); + color.rgb *= AccumulatedLightFromPos(id); } /* Apply tone mapping */ @@ -305,146 +302,3 @@ void CSDef(ShadeCS, Semantic(Vec3U32, sv_dispatchthreadid)) target_tex[id] = color; } } - -//////////////////////////////////////////////////////////// -//~ Ui Blit - -Struct(UiBlitPS_Input) -{ - Semantic(Vec4, sv_position); - Semantic(Vec2, tex_uv); -}; - -Struct(UiBlitPS_Output) -{ - Semantic(Vec4, sv_target); -}; - -//- Vertex shader - -UiBlitPS_Input VSDef(UiBlitVS, Semantic(u32, sv_vertexid)) -{ - ConstantBuffer sig = ui_blit_sig; - Vec2 tex_uv = RectUvFromVertexId(sv_vertexid); - Vec2 tex_uv_centered = tex_uv - 0.5; - - UiBlitPS_Input result; - result.sv_position = mul(sig.projection, Vec4(tex_uv_centered, 0, 1)); - result.tex_uv = tex_uv; - return result; -} - -//- Pixel shader - -UiBlitPS_Output PSDef(UiBlitPS, UiBlitPS_Input input) -{ - ConstantBuffer sig = ui_blit_sig; - SamplerState sampler = UniformSamplerFromRid(sig.sampler); - - UiBlitPS_Output result; - Texture2D tex = UniformResourceFromRid(sig.src); - Vec4 color = tex.Sample(sampler, input.tex_uv); - - /* Apply tone map */ - if (sig.flags & UiBlitFlag_ToneMap) - { - /* TODO: Dynamic exposure based on average scene luminance */ - color.rgb *= sig.exposure; - color.rgb = ToneMap(color.rgb); - } - - result.sv_target = color; - return result; -} - -//////////////////////////////////////////////////////////// -//~ Ui rect - -Struct(UiRectPS_Input) -{ - Semantic(Vec4, sv_position); - Semantic(nointerpolation Texture2DRid, tex); - Semantic(Vec2, tex_uv); - Semantic(Vec4, tint_srgb); -}; - -Struct(UiRectPS_Output) -{ - Semantic(Vec4, sv_target0); -}; - -//- Vertex shader - -UiRectPS_Input VSDef(UiRectVS, Semantic(u32, sv_instanceid), Semantic(u32, sv_vertexid)) -{ - ConstantBuffer sig = ui_rect_sig; - StructuredBuffer instances = UniformResourceFromRid(sig.instances); - UiRectInstance instance = instances[sv_instanceid]; - - Vec2 rect_uv = RectUvFromVertexId(sv_vertexid); - Vec2 rect_uv_centered = rect_uv - 0.5; - Vec2 world_pos = mul(instance.xf, Vec3(rect_uv_centered, 1)).xy; - - UiRectPS_Input result; - result.sv_position = mul(sig.projection, Vec4(world_pos, 0, 1)); - result.tex = instance.tex; - result.tex_uv = lerp(instance.tex_uv0, instance.tex_uv1, rect_uv); - result.tint_srgb = Vec4NormFromU32(instance.tint_srgb); - return result; -} - -//- Pixel shader - -UiRectPS_Output PSDef(UiRectPS, UiRectPS_Input input) -{ - ConstantBuffer sig = ui_rect_sig; - UiRectPS_Output result; - Vec4 color = input.tint_srgb; - - /* Texture */ - if (input.tex < 0xFFFFFFFF) - { - Texture2D tex = NonUniformResourceFromRid(input.tex); - SamplerState sampler = UniformSamplerFromRid(sig.sampler); - color *= tex.Sample(sampler, input.tex_uv); - } - - result.sv_target0 = color; - return result; -} - -//////////////////////////////////////////////////////////// -//~ Ui shape - -Struct(UiShapePS_Input) -{ - Semantic(Vec4, sv_position); - Semantic(Vec4, color_srgb); -}; - -Struct(UiShapePS_Output) -{ - Semantic(Vec4, sv_target); -}; - -//- Vertex shader - -UiShapePS_Input VSDef(UiShapeVS, Semantic(u32, sv_vertexid)) -{ - ConstantBuffer sig = ui_shape_sig; - StructuredBuffer verts = UniformResourceFromRid(sig.verts); - UiShapeVert vert = verts[sv_vertexid]; - UiShapePS_Input result; - result.sv_position = mul(sig.projection, Vec4(vert.pos.xy, 0, 1)); - result.color_srgb = Vec4NormFromU32(vert.color_srgb); - return result; -} - -//- Pixel shader - -UiShapePS_Output PSDef(UiShapePS, UiShapePS_Input input) -{ - UiShapePS_Output result; - result.sv_target = input.color_srgb; - return result; -} diff --git a/src/pp/pp_draw.h b/src/pp/pp_draw.h index 0a051273..7b536589 100644 --- a/src/pp/pp_draw.h +++ b/src/pp/pp_draw.h @@ -103,76 +103,3 @@ Struct(ShadeSig) /* ----------------------------------------------------- */ }; AssertRootConst(ShadeSig, 20); - -//////////////////////////////////////////////////////////// -//~ Ui blit types - -#define UiBlitFlag_None (0) -#define UiBlitFlag_ToneMap (1 << 0) -#define UiBlitFlag_GammaCorrect (1 << 1) - -Struct(UiBlitSig) -{ - /* ----------------------------------------------------- */ - Mat4x4 projection; /* 16 consts */ - /* ----------------------------------------------------- */ - u32 flags; /* 01 consts */ - Texture2DRid src; /* 01 consts */ - f32 exposure; /* 01 consts */ - f32 gamma; /* 01 consts */ - /* ----------------------------------------------------- */ - SamplerStateRid sampler; /* 01 consts */ - u32 _pad0; /* 01 consts (padding) */ - u32 _pad1; /* 01 consts (padding) */ - u32 _pad2; /* 01 consts (padding) */ - /* ----------------------------------------------------- */ -}; -AssertRootConst(UiBlitSig, 24); - - -//////////////////////////////////////////////////////////// -//~ Ui rect types - -Struct(UiRectSig) -{ - /* ----------------------------------------------------- */ - Mat4x4 projection; /* 16 consts */ - /* ----------------------------------------------------- */ - StructuredBufferRid instances; /* 01 consts */ - SamplerStateRid sampler; /* 01 consts */ - u32 _pad0; /* 01 consts (padding) */ - u32 _pad1; /* 01 consts (padding) */ - /* ----------------------------------------------------- */ -}; -AssertRootConst(UiRectSig, 20); - -Struct(UiRectInstance) -{ - Texture2DRid tex; - Xform xf; - Vec2 tex_uv0; - Vec2 tex_uv1; - u32 tint_srgb; -}; - -//////////////////////////////////////////////////////////// -//~ Ui shape types - -Struct(UiShapeSig) -{ - /* ----------------------------------------------------- */ - Mat4x4 projection; /* 16 consts */ - /* ----------------------------------------------------- */ - StructuredBufferRid verts; /* 01 consts */ - u32 _pad0; /* 01 consts (padding) */ - u32 _pad1; /* 01 consts (padding) */ - u32 _pad2; /* 01 consts (padding) */ - /* ----------------------------------------------------- */ -}; -AssertRootConst(UiShapeSig, 20); - -Struct(UiShapeVert) -{ - Vec2 pos; - u32 color_srgb; -}; diff --git a/src/pp/pp_step.c b/src/pp/pp_step.c index 14d35070..a777b5a1 100644 --- a/src/pp/pp_step.c +++ b/src/pp/pp_step.c @@ -1370,7 +1370,7 @@ void StepSim(SimStepCtx *ctx) Xform xf = LocalXformFromEntity(ent); xf.og = attach_pos; - xf = XformWIthWorldRotation(xf, AngleFromVec2(attach_dir) + Pi / 2); + xf = XformWithWorldRotation(xf, AngleFromVec2(attach_dir) + Pi / 2); SetLocalXform(ent, xf); } @@ -1690,7 +1690,7 @@ void StepSim(SimStepCtx *ctx) f32 forward_hold_angle_offset; { - Xform xf_unrotated = XformWIthWorldRotation(xf, 0); + Xform xf_unrotated = XformWithWorldRotation(xf, 0); Vec2 hold_pos_unrotated = MulXformV2(xf_unrotated, MulXformV2(ent->sprite_local_xform, sprite_hold_pos)); forward_hold_angle_offset = AngleFromVec2Dirs(VEC2(0, -1), SubVec2(hold_pos_unrotated, xf_unrotated.og)); } diff --git a/src/ui/ui.c b/src/ui/ui.c index 5538b31e..db12483c 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -191,16 +191,16 @@ UI_Box *UI_BuildBox(UI_BoxFlag flags, UI_Key key) box->flags = flags; /* Pull from style stack */ - box->parent = UI_UseTop(Parent); - box->pref_size[Axis_X] = UI_UseTop(Width); - box->pref_size[Axis_Y] = UI_UseTop(Height); - box->layout_axis = UI_UseTop(LayoutAxis); - box->background_color = UI_UseTop(BackgroundColor); - box->border_color = UI_UseTop(BorderColor); - box->border = UI_UseTop(Border); - box->font_resource = UI_UseTop(Font); - box->font_size = UI_UseTop(FontSize); - box->text_padding = UI_UseTop(TextPadding); + box->parent = UI_UseTop(Parent); + box->pref_size[Axis_X] = UI_UseTop(Width); + box->pref_size[Axis_Y] = UI_UseTop(Height); + box->layout_axis = UI_UseTop(LayoutAxis); + box->background_color = UI_UseTop(BackgroundColor); + box->border_color = UI_UseTop(BorderColor); + box->border = UI_UseTop(Border); + box->font_resource = UI_UseTop(Font); + box->font_size = UI_UseTop(FontSize); + box->text_padding = UI_UseTop(TextPadding); /* Prefetch font */ if (box->flags & UI_BoxFlag_DrawText) @@ -221,11 +221,6 @@ void UI_SetDisplayText(UI_Box *box, String str) box->display_text = text; } -void UI_SetDisplayImage(UI_Box *box, GPU_Resource *img) -{ - box->display_image = img; -} - //////////////////////////////////////////////////////////// //~ Begin build @@ -490,7 +485,7 @@ GPU_Resource *UI_EndBuild(Rect render_viewport) /* Push box rect */ { UI_RectInstance *rect = PushStruct(g->draw_rects_arena, UI_RectInstance); - rect->flags |= UI_RectFlag_DrawTexture * !!(box->flags & UI_BoxFlag_DrawImage); + rect->flags |= UI_RectFlag_DrawTexture * !!(box->background_texture != 0); rect->p0 = box->p0; rect->p1 = box->p1; rect->tex_uv0 = VEC2(0, 0); @@ -508,10 +503,11 @@ GPU_Resource *UI_EndBuild(Rect render_viewport) } #endif - - if ((box->flags & UI_BoxFlag_DrawImage) && box->display_image) + if (box->background_texture != 0) { - rect->tex = GPU_Texture2DRidFromResource(box->display_image); + rect->tex = GPU_Texture2DRidFromResource(box->background_texture); + rect->tex_uv0 = box->background_texture_uv0; + rect->tex_uv1 = box->background_texture_uv1; } } /* Push text rects */ @@ -533,8 +529,8 @@ GPU_Resource *UI_EndBuild(Rect render_viewport) for (u64 i = 0; i < run.count; ++i) { F_RunRect rr = run.rects[i]; - Vec2 atlas_p0 = Vec2FromVec(rr.atlas_p0); - Vec2 atlas_p1 = Vec2FromVec(rr.atlas_p1); + Vec2 atlas_p0 = Vec2FromFields(rr.atlas_p0); + Vec2 atlas_p1 = Vec2FromFields(rr.atlas_p1); Vec2 glyph_size = SubVec2(atlas_p1, atlas_p0); if (glyph_size.x != 0 || glyph_size.y != 0) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 1d3076b7..88ba2003 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -34,9 +34,8 @@ Struct(UI_Size) Enum(UI_BoxFlag) { - UI_BoxFlag_None = 0, - UI_BoxFlag_DrawText = (1 << 0), - UI_BoxFlag_DrawImage = (1 << 1), + UI_BoxFlag_None = 0, + UI_BoxFlag_DrawText = (1 << 0), }; Struct(UI_Box) @@ -60,7 +59,10 @@ Struct(UI_Box) UI_BoxFlag flags; String display_text; - GPU_Resource *display_image; + + GPU_Resource *background_texture; + Vec2 background_texture_uv0; + Vec2 background_texture_uv1; Axis layout_axis; @@ -92,19 +94,19 @@ Struct(UI_BoxBin) //////////////////////////////////////////////////////////// //~ Style types -#define UI_StyleKindsXMacro(x) \ - x(Tag, u64) \ - x(Parent, UI_Box *) \ - x(LayoutAxis, Axis) \ - x(Width, UI_Size) \ - x(Height, UI_Size) \ - x(BackgroundColor, u32) \ - x(BorderColor, u32) \ - x(Border, f32) \ - x(Font, Resource) \ - x(FontSize, u32) \ - x(TextPadding, f32) \ -/* ----------------------------------- */ +#define UI_StyleKindsXMacro(x) \ + x(Tag, u64) \ + x(Parent, UI_Box *) \ + x(LayoutAxis, Axis) \ + x(Width, UI_Size) \ + x(Height, UI_Size) \ + x(BackgroundColor, u32) \ + x(BorderColor, u32) \ + x(Border, f32) \ + x(Font, Resource) \ + x(FontSize, u32) \ + x(TextPadding, f32) \ +/* ---------------------------------------- */ Enum(UI_StyleKind) { @@ -230,12 +232,6 @@ UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use); UI_Box *UI_BuildBox(UI_BoxFlag flags, UI_Key key); void UI_SetDisplayText(UI_Box *box, String str); -void UI_SetDisplayImage(UI_Box *box, GPU_Resource *img); - -//////////////////////////////////////////////////////////// -//~ Image - -void UI_SetDisplayImage(UI_Box *box, GPU_Resource *img); //////////////////////////////////////////////////////////// //~ Begin build