type alias refactor
This commit is contained in:
@@ -170,17 +170,17 @@ struct FrameContext {
|
||||
|
||||
struct Renderer {
|
||||
HWND hwnd;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t frame_count;
|
||||
S32 width;
|
||||
S32 height;
|
||||
S32 frame_count;
|
||||
UINT frame_index;
|
||||
|
||||
ID3D12Device *device;
|
||||
ID3D12CommandQueue *command_queue;
|
||||
IDXGISwapChain3 *swap_chain;
|
||||
HANDLE swap_chain_waitable;
|
||||
bool swap_chain_occluded;
|
||||
bool tearing_support;
|
||||
B32 swap_chain_occluded;
|
||||
B32 tearing_support;
|
||||
|
||||
ID3D12DescriptorHeap *rtv_heap;
|
||||
ID3D12DescriptorHeap *srv_heap;
|
||||
@@ -198,7 +198,7 @@ struct Renderer {
|
||||
ID3D12RootSignature *root_signature;
|
||||
ID3D12PipelineState *pipeline_state;
|
||||
|
||||
// Per-frame vertex/index buffers (double-buffered)
|
||||
// Per-frame vertex/index buffers (F64-buffered)
|
||||
ID3D12Resource *vertex_buffers[NUM_BACK_BUFFERS];
|
||||
ID3D12Resource *index_buffers[NUM_BACK_BUFFERS];
|
||||
void *vb_mapped[NUM_BACK_BUFFERS];
|
||||
@@ -220,15 +220,15 @@ struct Renderer {
|
||||
F32 measure_font_size;
|
||||
|
||||
// Clear color
|
||||
float clear_r = 0.12f;
|
||||
float clear_g = 0.12f;
|
||||
float clear_b = 0.13f;
|
||||
F32 clear_r = 0.12f;
|
||||
F32 clear_g = 0.12f;
|
||||
F32 clear_b = 0.13f;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// DX12 infrastructure
|
||||
|
||||
static bool create_device(Renderer *r) {
|
||||
static B32 create_device(Renderer *r) {
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
ID3D12Debug *debug = nullptr;
|
||||
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debug)))) {
|
||||
@@ -254,7 +254,7 @@ static bool create_device(Renderer *r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool create_command_queue(Renderer *r) {
|
||||
static B32 create_command_queue(Renderer *r) {
|
||||
D3D12_COMMAND_QUEUE_DESC desc = {};
|
||||
desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
@@ -262,7 +262,7 @@ static bool create_command_queue(Renderer *r) {
|
||||
return r->device->CreateCommandQueue(&desc, IID_PPV_ARGS(&r->command_queue)) == S_OK;
|
||||
}
|
||||
|
||||
static bool create_descriptor_heaps(Renderer *r) {
|
||||
static B32 create_descriptor_heaps(Renderer *r) {
|
||||
// RTV heap
|
||||
{
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||
@@ -275,7 +275,7 @@ static bool create_descriptor_heaps(Renderer *r) {
|
||||
|
||||
SIZE_T rtv_size = r->device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = r->rtv_heap->GetCPUDescriptorHandleForHeapStart();
|
||||
for (int i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
for (S32 i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
r->rtv_descriptors[i] = handle;
|
||||
handle.ptr += rtv_size;
|
||||
}
|
||||
@@ -294,8 +294,8 @@ static bool create_descriptor_heaps(Renderer *r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool create_frame_resources(Renderer *r) {
|
||||
for (int i = 0; i < r->frame_count; i++) {
|
||||
static B32 create_frame_resources(Renderer *r) {
|
||||
for (S32 i = 0; i < r->frame_count; i++) {
|
||||
if (r->device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
IID_PPV_ARGS(&r->frames[i].command_allocator)) != S_OK)
|
||||
return false;
|
||||
@@ -315,7 +315,7 @@ static bool create_frame_resources(Renderer *r) {
|
||||
return r->fence_event != nullptr;
|
||||
}
|
||||
|
||||
static bool create_swap_chain(Renderer *r) {
|
||||
static B32 create_swap_chain(Renderer *r) {
|
||||
DXGI_SWAP_CHAIN_DESC1 sd = {};
|
||||
sd.BufferCount = NUM_BACK_BUFFERS;
|
||||
sd.Width = 0;
|
||||
@@ -413,7 +413,7 @@ static void ensure_measure_font(Renderer *r, F32 font_size) {
|
||||
if (r->measure_font) DeleteObject(r->measure_font);
|
||||
|
||||
r->measure_font = CreateFontW(
|
||||
-(int)(font_size + 0.5f), 0, 0, 0,
|
||||
-(S32)(font_size + 0.5f), 0, 0, 0,
|
||||
FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
|
||||
CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
|
||||
@@ -423,18 +423,18 @@ static void ensure_measure_font(Renderer *r, F32 font_size) {
|
||||
SelectObject(r->measure_dc, r->measure_font);
|
||||
}
|
||||
|
||||
static bool create_font_atlas(Renderer *r, F32 font_size) {
|
||||
const int SS = 2; // supersample factor
|
||||
static B32 create_font_atlas(Renderer *r, F32 font_size) {
|
||||
const S32 SS = 2; // supersample factor
|
||||
F32 render_size = font_size * SS;
|
||||
int render_w = FONT_ATLAS_W * SS;
|
||||
int render_h = FONT_ATLAS_H * SS;
|
||||
S32 render_w = FONT_ATLAS_W * SS;
|
||||
S32 render_h = FONT_ATLAS_H * SS;
|
||||
|
||||
r->font_atlas_size = font_size;
|
||||
|
||||
// Create a GDI bitmap to render glyphs at supersampled resolution
|
||||
HDC dc = CreateCompatibleDC(nullptr);
|
||||
HFONT font = CreateFontW(
|
||||
-(int)(render_size + 0.5f), 0, 0, 0,
|
||||
-(S32)(render_size + 0.5f), 0, 0, 0,
|
||||
FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
|
||||
ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
|
||||
@@ -468,16 +468,16 @@ static bool create_font_atlas(Renderer *r, F32 font_size) {
|
||||
SetBkMode(dc, TRANSPARENT);
|
||||
|
||||
// Render each glyph at supersampled resolution
|
||||
int pen_x = SS, pen_y = SS;
|
||||
int row_height = 0;
|
||||
S32 pen_x = SS, pen_y = SS;
|
||||
S32 row_height = 0;
|
||||
|
||||
for (int i = 0; i < GLYPH_COUNT; i++) {
|
||||
for (S32 i = 0; i < GLYPH_COUNT; i++) {
|
||||
char ch = (char)(GLYPH_FIRST + i);
|
||||
SIZE ch_size = {};
|
||||
GetTextExtentPoint32A(dc, &ch, 1, &ch_size);
|
||||
|
||||
int gw = ch_size.cx + 2 * SS; // padding scaled by SS
|
||||
int gh = ch_size.cy + 2 * SS;
|
||||
S32 gw = ch_size.cx + 2 * SS; // padding scaled by SS
|
||||
S32 gh = ch_size.cy + 2 * SS;
|
||||
|
||||
if (pen_x + gw >= render_w) {
|
||||
pen_x = SS;
|
||||
@@ -507,16 +507,16 @@ static bool create_font_atlas(Renderer *r, F32 font_size) {
|
||||
// Box-filter downsample from supersampled resolution to atlas resolution
|
||||
U8 *atlas_data = (U8 *)malloc(FONT_ATLAS_W * FONT_ATLAS_H);
|
||||
U8 *src = (U8 *)dib_bits;
|
||||
for (int y = 0; y < FONT_ATLAS_H; y++) {
|
||||
for (int x = 0; x < FONT_ATLAS_W; x++) {
|
||||
int sum = 0;
|
||||
for (int sy = 0; sy < SS; sy++) {
|
||||
for (int sx = 0; sx < SS; sx++) {
|
||||
int src_idx = ((y * SS + sy) * render_w + (x * SS + sx)) * 4;
|
||||
for (S32 y = 0; y < FONT_ATLAS_H; y++) {
|
||||
for (S32 x = 0; x < FONT_ATLAS_W; x++) {
|
||||
S32 sum = 0;
|
||||
for (S32 sy = 0; sy < SS; sy++) {
|
||||
for (S32 sx = 0; sx < SS; sx++) {
|
||||
S32 src_idx = ((y * SS + sy) * render_w + (x * SS + sx)) * 4;
|
||||
sum += src[src_idx + 2]; // R channel from BGRA
|
||||
}
|
||||
}
|
||||
float a = (float)sum / (float)(SS * SS * 255);
|
||||
F32 a = (F32)sum / (F32)(SS * SS * 255);
|
||||
a = powf(a, 0.55f);
|
||||
atlas_data[y * FONT_ATLAS_W + x] = (U8)(a * 255.0f + 0.5f);
|
||||
}
|
||||
@@ -573,7 +573,7 @@ static bool create_font_atlas(Renderer *r, F32 font_size) {
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
upload_buf->Map(0, &read_range, &mapped);
|
||||
U8 *dst = (U8 *)mapped;
|
||||
for (int y = 0; y < FONT_ATLAS_H; y++) {
|
||||
for (S32 y = 0; y < FONT_ATLAS_H; y++) {
|
||||
memcpy(dst + y * footprint.Footprint.RowPitch,
|
||||
atlas_data + y * FONT_ATLAS_W,
|
||||
FONT_ATLAS_W);
|
||||
@@ -631,7 +631,7 @@ static bool create_font_atlas(Renderer *r, F32 font_size) {
|
||||
////////////////////////////////
|
||||
// UI rendering pipeline setup
|
||||
|
||||
static bool create_ui_pipeline(Renderer *r) {
|
||||
static B32 create_ui_pipeline(Renderer *r) {
|
||||
ID3DBlob *vs_blob = nullptr;
|
||||
ID3DBlob *ps_blob = nullptr;
|
||||
ID3DBlob *error_blob = nullptr;
|
||||
@@ -769,11 +769,11 @@ static bool create_ui_pipeline(Renderer *r) {
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
static bool create_ui_buffers(Renderer *r) {
|
||||
static B32 create_ui_buffers(Renderer *r) {
|
||||
D3D12_HEAP_PROPERTIES heap_props = {};
|
||||
heap_props.Type = D3D12_HEAP_TYPE_UPLOAD;
|
||||
|
||||
for (int i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
for (S32 i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
D3D12_RESOURCE_DESC buf_desc = {};
|
||||
buf_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
buf_desc.Width = MAX_VERTICES * sizeof(UIVertex);
|
||||
@@ -792,7 +792,7 @@ static bool create_ui_buffers(Renderer *r) {
|
||||
r->vertex_buffers[i]->Map(0, &read_range, &r->vb_mapped[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
for (S32 i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
D3D12_RESOURCE_DESC buf_desc = {};
|
||||
buf_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
buf_desc.Width = MAX_INDICES * sizeof(U32);
|
||||
@@ -817,7 +817,7 @@ static bool create_ui_buffers(Renderer *r) {
|
||||
////////////////////////////////
|
||||
// Text measurement callback for UI system
|
||||
|
||||
Vec2F32 renderer_measure_text(const char *text, int32_t length, float font_size, void *user_data) {
|
||||
Vec2F32 renderer_measure_text(const char *text, S32 length, F32 font_size, void *user_data) {
|
||||
Renderer *r = (Renderer *)user_data;
|
||||
if (!r || length == 0) return v2f32(0, font_size);
|
||||
|
||||
@@ -839,12 +839,12 @@ struct DrawBatch {
|
||||
};
|
||||
|
||||
static void emit_quad(DrawBatch *batch,
|
||||
float x0, float y0, float x1, float y1,
|
||||
float u0, float v0, float u1, float v1,
|
||||
float cr, float cg, float cb, float ca,
|
||||
float rmin_x, float rmin_y, float rmax_x, float rmax_y,
|
||||
float cr_tl, float cr_tr, float cr_br, float cr_bl,
|
||||
float border_thickness, float softness, float mode)
|
||||
F32 x0, F32 y0, F32 x1, F32 y1,
|
||||
F32 u0, F32 v0, F32 u1, F32 v1,
|
||||
F32 cr, F32 cg, F32 cb, F32 ca,
|
||||
F32 rmin_x, F32 rmin_y, F32 rmax_x, F32 rmax_y,
|
||||
F32 cr_tl, F32 cr_tr, F32 cr_br, F32 cr_bl,
|
||||
F32 border_thickness, F32 softness, F32 mode)
|
||||
{
|
||||
if (batch->vertex_count + 4 > MAX_VERTICES || batch->index_count + 6 > MAX_INDICES)
|
||||
return;
|
||||
@@ -853,9 +853,9 @@ static void emit_quad(DrawBatch *batch,
|
||||
UIVertex *v = &batch->vertices[base];
|
||||
|
||||
// For SDF mode, expand quad slightly for anti-aliasing
|
||||
float px0 = x0, py0 = y0, px1 = x1, py1 = y1;
|
||||
F32 px0 = x0, py0 = y0, px1 = x1, py1 = y1;
|
||||
if (mode < 0.5f) {
|
||||
float pad = softness + 1.0f;
|
||||
F32 pad = softness + 1.0f;
|
||||
px0 -= pad; py0 -= pad; px1 += pad; py1 += pad;
|
||||
}
|
||||
|
||||
@@ -864,7 +864,7 @@ static void emit_quad(DrawBatch *batch,
|
||||
v[2].pos[0] = px1; v[2].pos[1] = py1; v[2].uv[0] = u1; v[2].uv[1] = v1;
|
||||
v[3].pos[0] = px0; v[3].pos[1] = py1; v[3].uv[0] = u0; v[3].uv[1] = v1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (S32 i = 0; i < 4; i++) {
|
||||
v[i].col[0] = cr; v[i].col[1] = cg; v[i].col[2] = cb; v[i].col[3] = ca;
|
||||
v[i].rect_min[0] = rmin_x; v[i].rect_min[1] = rmin_y;
|
||||
v[i].rect_max[0] = rmax_x; v[i].rect_max[1] = rmax_y;
|
||||
@@ -884,10 +884,10 @@ static void emit_quad(DrawBatch *batch,
|
||||
}
|
||||
|
||||
static void emit_quad_rotated(DrawBatch *batch,
|
||||
float x0, float y0, float x1, float y1,
|
||||
float u0, float v0, float u1, float v1,
|
||||
float cr, float cg, float cb, float ca,
|
||||
float angle_rad)
|
||||
F32 x0, F32 y0, F32 x1, F32 y1,
|
||||
F32 u0, F32 v0, F32 u1, F32 v1,
|
||||
F32 cr, F32 cg, F32 cb, F32 ca,
|
||||
F32 angle_rad)
|
||||
{
|
||||
if (batch->vertex_count + 4 > MAX_VERTICES || batch->index_count + 6 > MAX_INDICES)
|
||||
return;
|
||||
@@ -895,13 +895,13 @@ static void emit_quad_rotated(DrawBatch *batch,
|
||||
U32 base = batch->vertex_count;
|
||||
UIVertex *v = &batch->vertices[base];
|
||||
|
||||
float cx = (x0 + x1) * 0.5f;
|
||||
float cy = (y0 + y1) * 0.5f;
|
||||
float cosA = cosf(angle_rad);
|
||||
float sinA = sinf(angle_rad);
|
||||
F32 cx = (x0 + x1) * 0.5f;
|
||||
F32 cy = (y0 + y1) * 0.5f;
|
||||
F32 cosA = cosf(angle_rad);
|
||||
F32 sinA = sinf(angle_rad);
|
||||
|
||||
float dx0 = x0 - cx, dy0 = y0 - cy;
|
||||
float dx1 = x1 - cx, dy1 = y1 - cy;
|
||||
F32 dx0 = x0 - cx, dy0 = y0 - cy;
|
||||
F32 dx1 = x1 - cx, dy1 = y1 - cy;
|
||||
|
||||
v[0].pos[0] = cx + dx0 * cosA - dy0 * sinA;
|
||||
v[0].pos[1] = cy + dx0 * sinA + dy0 * cosA;
|
||||
@@ -919,7 +919,7 @@ static void emit_quad_rotated(DrawBatch *batch,
|
||||
v[3].pos[1] = cy + dx0 * sinA + dy1 * cosA;
|
||||
v[3].uv[0] = u0; v[3].uv[1] = v1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (S32 i = 0; i < 4; i++) {
|
||||
v[i].col[0] = cr; v[i].col[1] = cg; v[i].col[2] = cb; v[i].col[3] = ca;
|
||||
v[i].rect_min[0] = 0; v[i].rect_min[1] = 0;
|
||||
v[i].rect_max[0] = 0; v[i].rect_max[1] = 0;
|
||||
@@ -939,10 +939,10 @@ static void emit_quad_rotated(DrawBatch *batch,
|
||||
}
|
||||
|
||||
static void emit_rect(DrawBatch *batch,
|
||||
float x0, float y0, float x1, float y1,
|
||||
float cr, float cg, float cb, float ca,
|
||||
float cr_tl, float cr_tr, float cr_br, float cr_bl,
|
||||
float border_thickness, float softness)
|
||||
F32 x0, F32 y0, F32 x1, F32 y1,
|
||||
F32 cr, F32 cg, F32 cb, F32 ca,
|
||||
F32 cr_tl, F32 cr_tr, F32 cr_br, F32 cr_bl,
|
||||
F32 border_thickness, F32 softness)
|
||||
{
|
||||
emit_quad(batch, x0, y0, x1, y1,
|
||||
0, 0, 0, 0,
|
||||
@@ -953,11 +953,11 @@ static void emit_rect(DrawBatch *batch,
|
||||
}
|
||||
|
||||
static void emit_rect_vgradient(DrawBatch *batch,
|
||||
float x0, float y0, float x1, float y1,
|
||||
float tr, float tg, float tb, float ta,
|
||||
float br, float bg, float bb_, float ba,
|
||||
float cr_tl, float cr_tr, float cr_br, float cr_bl,
|
||||
float softness)
|
||||
F32 x0, F32 y0, F32 x1, F32 y1,
|
||||
F32 tr, F32 tg, F32 tb, F32 ta,
|
||||
F32 br, F32 bg, F32 bb_, F32 ba,
|
||||
F32 cr_tl, F32 cr_tr, F32 cr_br, F32 cr_bl,
|
||||
F32 softness)
|
||||
{
|
||||
if (batch->vertex_count + 4 > MAX_VERTICES || batch->index_count + 6 > MAX_INDICES)
|
||||
return;
|
||||
@@ -965,8 +965,8 @@ static void emit_rect_vgradient(DrawBatch *batch,
|
||||
U32 base = batch->vertex_count;
|
||||
UIVertex *v = &batch->vertices[base];
|
||||
|
||||
float pad = softness + 1.0f;
|
||||
float px0 = x0 - pad, py0 = y0 - pad, px1 = x1 + pad, py1 = y1 + pad;
|
||||
F32 pad = softness + 1.0f;
|
||||
F32 px0 = x0 - pad, py0 = y0 - pad, px1 = x1 + pad, py1 = y1 + pad;
|
||||
|
||||
v[0].pos[0] = px0; v[0].pos[1] = py0; v[0].uv[0] = 0; v[0].uv[1] = 0;
|
||||
v[1].pos[0] = px1; v[1].pos[1] = py0; v[1].uv[0] = 0; v[1].uv[1] = 0;
|
||||
@@ -979,7 +979,7 @@ static void emit_rect_vgradient(DrawBatch *batch,
|
||||
v[2].col[0] = br; v[2].col[1] = bg; v[2].col[2] = bb_; v[2].col[3] = ba;
|
||||
v[3].col[0] = br; v[3].col[1] = bg; v[3].col[2] = bb_; v[3].col[3] = ba;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (S32 i = 0; i < 4; i++) {
|
||||
v[i].rect_min[0] = x0; v[i].rect_min[1] = y0;
|
||||
v[i].rect_max[0] = x1; v[i].rect_max[1] = y1;
|
||||
v[i].corner_radii[0] = cr_tl; v[i].corner_radii[1] = cr_tr;
|
||||
@@ -998,16 +998,16 @@ static void emit_rect_vgradient(DrawBatch *batch,
|
||||
}
|
||||
|
||||
static void emit_text_glyphs(DrawBatch *batch, Renderer *r,
|
||||
Clay_BoundingBox bbox, Clay_Color color, const char *text, int32_t text_len,
|
||||
uint16_t font_size)
|
||||
Clay_BoundingBox bbox, Clay_Color color, const char *text, S32 text_len,
|
||||
U16 font_size)
|
||||
{
|
||||
if (text_len == 0 || color.a < 0.1f) return;
|
||||
|
||||
// Color is 0-255 in Clay convention, normalize to 0-1
|
||||
float cr = color.r / 255.f;
|
||||
float cg = color.g / 255.f;
|
||||
float cb = color.b / 255.f;
|
||||
float ca = color.a / 255.f;
|
||||
F32 cr = color.r / 255.f;
|
||||
F32 cg = color.g / 255.f;
|
||||
F32 cb = color.b / 255.f;
|
||||
F32 ca = color.a / 255.f;
|
||||
|
||||
F32 scale = (F32)font_size / r->font_atlas_size;
|
||||
F32 text_h = r->font_line_height * scale;
|
||||
@@ -1016,18 +1016,18 @@ static void emit_text_glyphs(DrawBatch *batch, Renderer *r,
|
||||
F32 x = floorf(bbox.x + 0.5f);
|
||||
F32 y = floorf(bbox.y + (bbox.height - text_h) * 0.5f + 0.5f);
|
||||
|
||||
for (int32_t i = 0; i < text_len; i++) {
|
||||
for (S32 i = 0; i < text_len; i++) {
|
||||
char ch = text[i];
|
||||
if (ch < GLYPH_FIRST || ch > GLYPH_LAST) {
|
||||
if (ch == ' ') {
|
||||
int gi = ' ' - GLYPH_FIRST;
|
||||
S32 gi = ' ' - GLYPH_FIRST;
|
||||
if (gi >= 0 && gi < GLYPH_COUNT)
|
||||
x += r->glyphs[gi].x_advance * scale;
|
||||
continue;
|
||||
}
|
||||
ch = '?';
|
||||
}
|
||||
int gi = ch - GLYPH_FIRST;
|
||||
S32 gi = ch - GLYPH_FIRST;
|
||||
if (gi < 0 || gi >= GLYPH_COUNT) continue;
|
||||
|
||||
GlyphInfo *g = &r->glyphs[gi];
|
||||
@@ -1056,7 +1056,7 @@ static void flush_batch(Renderer *r, DrawBatch *batch, UINT buf_idx, U32 *flush_
|
||||
r->command_list->SetPipelineState(r->pipeline_state);
|
||||
r->command_list->SetGraphicsRootSignature(r->root_signature);
|
||||
|
||||
float constants[4] = { (float)r->width, (float)r->height, 0, 0 };
|
||||
F32 constants[4] = { (F32)r->width, (F32)r->height, 0, 0 };
|
||||
r->command_list->SetGraphicsRoot32BitConstants(0, 4, constants, 0);
|
||||
|
||||
// Bind texture (font or icon)
|
||||
@@ -1122,7 +1122,7 @@ void renderer_destroy(Renderer *r) {
|
||||
|
||||
wait_for_pending(r);
|
||||
|
||||
for (int i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
for (S32 i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
if (r->vertex_buffers[i]) r->vertex_buffers[i]->Release();
|
||||
if (r->index_buffers[i]) r->index_buffers[i]->Release();
|
||||
}
|
||||
@@ -1139,7 +1139,7 @@ void renderer_destroy(Renderer *r) {
|
||||
|
||||
if (r->swap_chain) { r->swap_chain->SetFullscreenState(false, nullptr); r->swap_chain->Release(); }
|
||||
if (r->swap_chain_waitable) CloseHandle(r->swap_chain_waitable);
|
||||
for (int i = 0; i < r->frame_count; i++)
|
||||
for (S32 i = 0; i < r->frame_count; i++)
|
||||
if (r->frames[i].command_allocator) r->frames[i].command_allocator->Release();
|
||||
if (r->command_queue) r->command_queue->Release();
|
||||
if (r->command_list) r->command_list->Release();
|
||||
@@ -1160,7 +1160,7 @@ void renderer_destroy(Renderer *r) {
|
||||
delete r;
|
||||
}
|
||||
|
||||
bool renderer_begin_frame(Renderer *r) {
|
||||
B32 renderer_begin_frame(Renderer *r) {
|
||||
if ((r->swap_chain_occluded && r->swap_chain->Present(0, DXGI_PRESENT_TEST) == DXGI_STATUS_OCCLUDED)
|
||||
|| IsIconic(r->hwnd))
|
||||
{
|
||||
@@ -1188,7 +1188,7 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
r->command_list->ResourceBarrier(1, &barrier);
|
||||
|
||||
const float clear_color[4] = { r->clear_r, r->clear_g, r->clear_b, 1.0f };
|
||||
const F32 clear_color[4] = { r->clear_r, r->clear_g, r->clear_b, 1.0f };
|
||||
r->command_list->ClearRenderTargetView(r->rtv_descriptors[back_buffer_idx], clear_color, 0, nullptr);
|
||||
r->command_list->OMSetRenderTargets(1, &r->rtv_descriptors[back_buffer_idx], FALSE, nullptr);
|
||||
|
||||
@@ -1210,7 +1210,7 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
batch.index_count = 0;
|
||||
|
||||
// Track which texture is currently bound (0 = font, 1 = icon)
|
||||
int bound_texture = 0;
|
||||
S32 bound_texture = 0;
|
||||
U32 flush_index_start = 0;
|
||||
|
||||
auto bind_font = [&]() {
|
||||
@@ -1228,7 +1228,7 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
}
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < render_commands.length; i++) {
|
||||
for (S32 i = 0; i < render_commands.length; i++) {
|
||||
Clay_RenderCommand *cmd = Clay_RenderCommandArray_Get(&render_commands, i);
|
||||
Clay_BoundingBox bb = cmd->boundingBox;
|
||||
|
||||
@@ -1247,15 +1247,15 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
case CLAY_RENDER_COMMAND_TYPE_BORDER: {
|
||||
Clay_BorderRenderData *border = &cmd->renderData.border;
|
||||
Clay_Color c = border->color;
|
||||
float cr_norm = c.r / 255.f;
|
||||
float cg_norm = c.g / 255.f;
|
||||
float cb_norm = c.b / 255.f;
|
||||
float ca_norm = c.a / 255.f;
|
||||
F32 cr_norm = c.r / 255.f;
|
||||
F32 cg_norm = c.g / 255.f;
|
||||
F32 cb_norm = c.b / 255.f;
|
||||
F32 ca_norm = c.a / 255.f;
|
||||
|
||||
// Use SDF rounded border when corner radius is present and widths are uniform
|
||||
Clay_CornerRadius cr = border->cornerRadius;
|
||||
bool has_radius = cr.topLeft > 0 || cr.topRight > 0 || cr.bottomLeft > 0 || cr.bottomRight > 0;
|
||||
bool uniform = border->width.top == border->width.bottom &&
|
||||
B32 has_radius = cr.topLeft > 0 || cr.topRight > 0 || cr.bottomLeft > 0 || cr.bottomRight > 0;
|
||||
B32 uniform = border->width.top == border->width.bottom &&
|
||||
border->width.top == border->width.left &&
|
||||
border->width.top == border->width.right &&
|
||||
border->width.top > 0;
|
||||
@@ -1265,7 +1265,7 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
bb.x, bb.y, bb.x + bb.width, bb.y + bb.height,
|
||||
cr_norm, cg_norm, cb_norm, ca_norm,
|
||||
cr.topLeft, cr.topRight, cr.bottomRight, cr.bottomLeft,
|
||||
(float)border->width.top, 1.0f);
|
||||
(F32)border->width.top, 1.0f);
|
||||
} else {
|
||||
if (border->width.top > 0) {
|
||||
emit_rect(&batch, bb.x, bb.y, bb.x + bb.width, bb.y + border->width.top,
|
||||
@@ -1335,8 +1335,8 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
bind_icon();
|
||||
CustomIconData *icon = (CustomIconData *)custom->customData;
|
||||
Clay_Color c = icon->color;
|
||||
float cr = c.r / 255.f, cg = c.g / 255.f;
|
||||
float cb = c.b / 255.f, ca = c.a / 255.f;
|
||||
F32 cr = c.r / 255.f, cg = c.g / 255.f;
|
||||
F32 cb = c.b / 255.f, ca = c.a / 255.f;
|
||||
UI_IconInfo *info = &g_icons[icon->icon_id];
|
||||
emit_quad(&batch,
|
||||
bb.x, bb.y, bb.x + bb.width, bb.y + bb.height,
|
||||
@@ -1349,8 +1349,8 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
bind_icon();
|
||||
CustomRotatedIconData *ri = (CustomRotatedIconData *)custom->customData;
|
||||
Clay_Color c = ri->color;
|
||||
float cr = c.r / 255.f, cg = c.g / 255.f;
|
||||
float cb = c.b / 255.f, ca = c.a / 255.f;
|
||||
F32 cr = c.r / 255.f, cg = c.g / 255.f;
|
||||
F32 cb = c.b / 255.f, ca = c.a / 255.f;
|
||||
UI_IconInfo *info = &g_icons[ri->icon_id];
|
||||
emit_quad_rotated(&batch,
|
||||
bb.x, bb.y, bb.x + bb.width, bb.y + bb.height,
|
||||
@@ -1386,7 +1386,7 @@ void renderer_end_frame(Renderer *r, Clay_RenderCommandArray render_commands) {
|
||||
r->frame_index++;
|
||||
}
|
||||
|
||||
void renderer_create_icon_atlas(Renderer *r, const uint8_t *data, int32_t w, int32_t h) {
|
||||
void renderer_create_icon_atlas(Renderer *r, const U8 *data, S32 w, S32 h) {
|
||||
// Create texture resource
|
||||
D3D12_HEAP_PROPERTIES heap_props = {};
|
||||
heap_props.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
@@ -1431,7 +1431,7 @@ void renderer_create_icon_atlas(Renderer *r, const uint8_t *data, int32_t w, int
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
upload_buf->Map(0, &read_range, &mapped);
|
||||
U8 *dst = (U8 *)mapped;
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (S32 y = 0; y < h; y++) {
|
||||
memcpy(dst + y * footprint.Footprint.RowPitch, data + y * w * 4, w * 4);
|
||||
}
|
||||
upload_buf->Unmap(0, nullptr);
|
||||
@@ -1481,7 +1481,7 @@ void renderer_create_icon_atlas(Renderer *r, const uint8_t *data, int32_t w, int
|
||||
&srv_view, r->icon_srv_heap->GetCPUDescriptorHandleForHeapStart());
|
||||
}
|
||||
|
||||
void renderer_resize(Renderer *r, int32_t width, int32_t height) {
|
||||
void renderer_resize(Renderer *r, S32 width, S32 height) {
|
||||
if (width <= 0 || height <= 0) return;
|
||||
|
||||
wait_for_pending(r);
|
||||
@@ -1497,14 +1497,14 @@ void renderer_resize(Renderer *r, int32_t width, int32_t height) {
|
||||
r->height = height;
|
||||
}
|
||||
|
||||
void renderer_set_clear_color(Renderer *r, float cr, float cg, float cb) {
|
||||
void renderer_set_clear_color(Renderer *r, F32 cr, F32 cg, F32 cb) {
|
||||
r->clear_r = cr;
|
||||
r->clear_g = cg;
|
||||
r->clear_b = cb;
|
||||
}
|
||||
|
||||
void renderer_set_font_scale(Renderer *r, float scale) {
|
||||
float target_size = 15.0f * scale;
|
||||
void renderer_set_font_scale(Renderer *r, F32 scale) {
|
||||
F32 target_size = 15.0f * scale;
|
||||
if (fabsf(target_size - r->font_atlas_size) < 0.1f) return;
|
||||
wait_for_pending(r);
|
||||
if (r->font_texture) { r->font_texture->Release(); r->font_texture = nullptr; }
|
||||
|
||||
Reference in New Issue
Block a user