Render to imgui::image

This commit is contained in:
CocoSimone
2022-08-23 02:24:45 +02:00
parent bcde8570b6
commit 7c338f4f0c
5 changed files with 56 additions and 11 deletions

View File

@@ -45,7 +45,7 @@ CommandBufferHandle requested_command_buffer;
VkRenderPass GetVkRenderPass() {
return wsi->get_device().request_render_pass(
wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly), true
).get_render_pass();
).get_render_pass();
}
VkCommandBuffer GetVkCommandBuffer() {
@@ -171,7 +171,7 @@ void LoadParallelRDP(u8* rdram) {
aligned_rdram -= offset;
}
CommandProcessorFlags flags = COMMAND_PROCESSOR_FLAG_UPSCALING_8X_BIT; // TODO configurable scaling
CommandProcessorFlags flags = COMMAND_PROCESSOR_FLAG_UPSCALING_4X_BIT;
command_processor = new CommandProcessor(wsi->get_device(), reinterpret_cast<void *>(aligned_rdram),
offset, 8 * 1024 * 1024, 4 * 1024 * 1024, flags);
@@ -253,9 +253,8 @@ void UpdateScreen(n64::Core& core, Window& imguiWindow, Util::IntrusivePtr<Image
Util::IntrusivePtr<CommandBuffer> cmd = wsi->get_device().request_command_buffer();
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly));
DrawFullscreenTexturedQuad(image, cmd);
ImGui_ImplVulkan_RenderDrawData(imguiWindow.Present(core), cmd->get_command_buffer());
ImGui_ImplVulkan_RenderDrawData(imguiWindow.Present(image, core), cmd->get_command_buffer());
cmd->end_render_pass();
wsi->get_device().submit(cmd);

View File

@@ -3,7 +3,7 @@ project(natsukashii)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)
add_compile_definitions(VULKAN_DEBUG)
#add_compile_definitions(VULKAN_DEBUG)
file(COPY ${CMAKE_SOURCE_DIR}/../resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(n64)

View File

@@ -28,3 +28,4 @@ using m128 = __m128i;
#define N64_CYCLES_PER_FRAME ((N64_CPU_FREQ) / 60)
#define HALF_ADDRESS(addr) ((addr) ^ 2)
#define BYTE_ADDRESS(addr) ((addr) ^ 3)
#define ASPECT_RATIO ((float)4/3)

View File

@@ -132,11 +132,28 @@ void Window::InitImgui() {
ImGui_ImplVulkan_CreateFontsTexture(commandBuffer);
SubmitRequestedVkCommandBuffer();
}
VkSamplerCreateInfo samplerCreateInfo {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.magFilter = VK_FILTER_NEAREST,
.minFilter = VK_FILTER_NEAREST,
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
.maxAnisotropy = 1.0f,
.minLod = -1000,
.maxLod = 1000,
};
VkSampler sampler;
err = vkCreateSampler(device, &samplerCreateInfo, allocator, &sampler);
check_vk_result(err);
}
Window::~Window() {
VkResult err = vkDeviceWaitIdle(device);
check_vk_result(err);
vkDestroySampler(device, screenSampler, nullptr);
ImGui_ImplVulkan_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
@@ -145,18 +162,18 @@ Window::~Window() {
SDL_Quit();
}
ImDrawData* Window::Present(n64::Core& core) {
ImDrawData* Window::Present(const Util::IntrusivePtr<Vulkan::Image>& image, n64::Core& core) {
ImGui_ImplVulkan_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
Render(core);
Render(image, core);
ImGui::Render();
return ImGui::GetDrawData();
}
void Window::Render(n64::Core& core) {
void Window::Render(const Util::IntrusivePtr<Vulkan::Image>& image, n64::Core& core) {
if(windowID == SDL_GetWindowID(SDL_GetMouseFocus())) {
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("File")) {
@@ -188,4 +205,30 @@ void Window::Render(n64::Core& core) {
}
ImGui::EndMainMenuBar();
}
ImGui::Begin("Screen");
if(core.romLoaded && !core.pause) {
auto size = ImGui::GetContentRegionAvail();
float current_aspect_ratio = size.x / size.y;
if (ASPECT_RATIO > current_aspect_ratio) {
size.y = size.x / ASPECT_RATIO;
}
else {
size.x = size.y * ASPECT_RATIO;
}
ImGui::SetCursorPos({
(ImGui::GetContentRegionAvail().x / 2) - (size.x / 2),
(ImGui::GetContentRegionAvail().y / 2) - (size.y / 2) + 24
});
ImGui::Image(
ImGui_ImplVulkan_AddTexture(
screenSampler,
image->get_view().get_view(),
image->get_layout(VK_IMAGE_LAYOUT_GENERAL)
),
size
);
}
ImGui::End();
}

View File

@@ -10,7 +10,7 @@
struct Window {
explicit Window(n64::Core& core);
~Window();
ImDrawData* Present(n64::Core& core);
ImDrawData* Present(const Util::IntrusivePtr<Vulkan::Image>&, n64::Core& core);
[[nodiscard]] bool gotClosed(SDL_Event event);
private:
@@ -18,9 +18,11 @@ private:
u32 windowID;
void InitSDL();
void InitImgui();
void Render(n64::Core& core);
void Render(const Util::IntrusivePtr<Vulkan::Image>&, n64::Core& core);
VkPhysicalDevice physicalDevice{};
VkSampler screenSampler{};
VkDescriptorSet screenTexture{};
VkDevice device{};
uint32_t queueFamily{uint32_t(-1)};
VkQueue queue{};