MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / imgui_create_fonts

Function imgui_create_fonts

modules/render/imgui/src/skr_imgui_rg.cpp:314–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312namespace skr::imgui
313{
314void imgui_create_fonts(CGPUQueueId queue)
315{
316 ImGuiIO& io = ImGui::GetIO();
317 unsigned char* pixels;
318 int width, height;
319 io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
320 size_t upload_size = width * height * 4 * sizeof(char);
321 // create texture
322 CGPUTextureDescriptor tex_desc = {};
323 tex_desc.name = u8"imgui_font";
324 tex_desc.width = static_cast<uint32_t>(width);
325 tex_desc.height = static_cast<uint32_t>(height);
326 tex_desc.depth = 1;
327 tex_desc.descriptors = CGPU_RESOURCE_TYPE_TEXTURE;
328 tex_desc.array_size = 1;
329 tex_desc.flags = CGPU_TCF_NONE;
330 tex_desc.mip_levels = 1;
331 tex_desc.format = CGPU_FORMAT_R8G8B8A8_UNORM;
332 tex_desc.start_state = CGPU_RESOURCE_STATE_COPY_DEST;
333 tex_desc.owner_queue = queue;
334 font_texture = cgpu_create_texture(queue->device, &tex_desc);
335 CGPUCommandPoolDescriptor cmd_pool_desc = {};
336 CGPUCommandBufferDescriptor cmd_desc = {};
337 CGPUBufferDescriptor upload_buffer_desc = {};
338 upload_buffer_desc.name = u8"IMGUI_FontUploadBuffer";
339 upload_buffer_desc.flags = CGPU_BCF_PERSISTENT_MAP_BIT;
340 upload_buffer_desc.descriptors = CGPU_RESOURCE_TYPE_NONE;
341 upload_buffer_desc.memory_usage = CGPU_MEM_USAGE_CPU_ONLY;
342 upload_buffer_desc.size = upload_size;
343 CGPUBufferId tex_upload_buffer = cgpu_create_buffer(queue->device, &upload_buffer_desc);
344 {
345 memcpy(tex_upload_buffer->info->cpu_mapped_address, pixels, upload_size);
346 }
347 auto cpy_cmd_pool = cgpu_create_command_pool(queue, &cmd_pool_desc);
348 auto cpy_cmd = cgpu_create_command_buffer(cpy_cmd_pool, &cmd_desc);
349 cgpu_cmd_begin(cpy_cmd);
350 CGPUBufferToTextureTransfer b2t = {};
351 b2t.src = tex_upload_buffer;
352 b2t.src_offset = 0;
353 b2t.dst = font_texture;
354 b2t.dst_subresource.mip_level = 0;
355 b2t.dst_subresource.base_array_layer = 0;
356 b2t.dst_subresource.layer_count = 1;
357 cgpu_cmd_transfer_buffer_to_texture(cpy_cmd, &b2t);
358 CGPUTextureBarrier srv_barrier = {};
359 srv_barrier.texture = font_texture;
360 srv_barrier.src_state = CGPU_RESOURCE_STATE_COPY_DEST;
361 srv_barrier.dst_state = CGPU_RESOURCE_STATE_SHADER_RESOURCE;
362 CGPUResourceBarrierDescriptor barrier_desc1 = {};
363 barrier_desc1.texture_barriers = &srv_barrier;
364 barrier_desc1.texture_barriers_count = 1;
365 cgpu_cmd_resource_barrier(cpy_cmd, &barrier_desc1);
366 cgpu_cmd_end(cpy_cmd);
367 CGPUQueueSubmitDescriptor cpy_submit = {};
368 cpy_submit.cmds = &cpy_cmd;
369 cpy_submit.cmds_count = 1;
370 cgpu_submit_queue(queue, &cpy_submit);
371 cgpu_wait_queue_idle(queue);

Callers 1

Calls 15

cgpu_create_textureFunction · 0.85
cgpu_create_bufferFunction · 0.85
memcpyFunction · 0.85
cgpu_create_command_poolFunction · 0.85
cgpu_cmd_beginFunction · 0.85
cgpu_cmd_endFunction · 0.85
cgpu_submit_queueFunction · 0.85
cgpu_wait_queue_idleFunction · 0.85
cgpu_free_command_bufferFunction · 0.85

Tested by

no test coverage detected