Render to imgui::image
This commit is contained in:
7
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
7
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
@@ -45,7 +45,7 @@ CommandBufferHandle requested_command_buffer;
|
|||||||
VkRenderPass GetVkRenderPass() {
|
VkRenderPass GetVkRenderPass() {
|
||||||
return wsi->get_device().request_render_pass(
|
return wsi->get_device().request_render_pass(
|
||||||
wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly), true
|
wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly), true
|
||||||
).get_render_pass();
|
).get_render_pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBuffer GetVkCommandBuffer() {
|
VkCommandBuffer GetVkCommandBuffer() {
|
||||||
@@ -171,7 +171,7 @@ void LoadParallelRDP(u8* rdram) {
|
|||||||
aligned_rdram -= offset;
|
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),
|
command_processor = new CommandProcessor(wsi->get_device(), reinterpret_cast<void *>(aligned_rdram),
|
||||||
offset, 8 * 1024 * 1024, 4 * 1024 * 1024, flags);
|
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();
|
Util::IntrusivePtr<CommandBuffer> cmd = wsi->get_device().request_command_buffer();
|
||||||
|
|
||||||
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly));
|
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();
|
cmd->end_render_pass();
|
||||||
wsi->get_device().submit(cmd);
|
wsi->get_device().submit(cmd);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ project(natsukashii)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
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})
|
file(COPY ${CMAKE_SOURCE_DIR}/../resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
add_subdirectory(n64)
|
add_subdirectory(n64)
|
||||||
|
|||||||
@@ -27,4 +27,5 @@ using m128 = __m128i;
|
|||||||
#define N64_CPU_FREQ 93750000
|
#define N64_CPU_FREQ 93750000
|
||||||
#define N64_CYCLES_PER_FRAME ((N64_CPU_FREQ) / 60)
|
#define N64_CYCLES_PER_FRAME ((N64_CPU_FREQ) / 60)
|
||||||
#define HALF_ADDRESS(addr) ((addr) ^ 2)
|
#define HALF_ADDRESS(addr) ((addr) ^ 2)
|
||||||
#define BYTE_ADDRESS(addr) ((addr) ^ 3)
|
#define BYTE_ADDRESS(addr) ((addr) ^ 3)
|
||||||
|
#define ASPECT_RATIO ((float)4/3)
|
||||||
@@ -132,11 +132,28 @@ void Window::InitImgui() {
|
|||||||
ImGui_ImplVulkan_CreateFontsTexture(commandBuffer);
|
ImGui_ImplVulkan_CreateFontsTexture(commandBuffer);
|
||||||
SubmitRequestedVkCommandBuffer();
|
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() {
|
Window::~Window() {
|
||||||
VkResult err = vkDeviceWaitIdle(device);
|
VkResult err = vkDeviceWaitIdle(device);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
|
vkDestroySampler(device, screenSampler, nullptr);
|
||||||
ImGui_ImplVulkan_Shutdown();
|
ImGui_ImplVulkan_Shutdown();
|
||||||
ImGui_ImplSDL2_Shutdown();
|
ImGui_ImplSDL2_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
@@ -145,18 +162,18 @@ Window::~Window() {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImDrawData* Window::Present(n64::Core& core) {
|
ImDrawData* Window::Present(const Util::IntrusivePtr<Vulkan::Image>& image, n64::Core& core) {
|
||||||
ImGui_ImplVulkan_NewFrame();
|
ImGui_ImplVulkan_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame(window);
|
ImGui_ImplSDL2_NewFrame(window);
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
Render(core);
|
Render(image, core);
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
return ImGui::GetDrawData();
|
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())) {
|
if(windowID == SDL_GetWindowID(SDL_GetMouseFocus())) {
|
||||||
ImGui::BeginMainMenuBar();
|
ImGui::BeginMainMenuBar();
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
@@ -188,4 +205,30 @@ void Window::Render(n64::Core& core) {
|
|||||||
}
|
}
|
||||||
ImGui::EndMainMenuBar();
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
struct Window {
|
struct Window {
|
||||||
explicit Window(n64::Core& core);
|
explicit Window(n64::Core& core);
|
||||||
~Window();
|
~Window();
|
||||||
ImDrawData* Present(n64::Core& core);
|
ImDrawData* Present(const Util::IntrusivePtr<Vulkan::Image>&, n64::Core& core);
|
||||||
|
|
||||||
[[nodiscard]] bool gotClosed(SDL_Event event);
|
[[nodiscard]] bool gotClosed(SDL_Event event);
|
||||||
private:
|
private:
|
||||||
@@ -18,9 +18,11 @@ private:
|
|||||||
u32 windowID;
|
u32 windowID;
|
||||||
void InitSDL();
|
void InitSDL();
|
||||||
void InitImgui();
|
void InitImgui();
|
||||||
void Render(n64::Core& core);
|
void Render(const Util::IntrusivePtr<Vulkan::Image>&, n64::Core& core);
|
||||||
|
|
||||||
VkPhysicalDevice physicalDevice{};
|
VkPhysicalDevice physicalDevice{};
|
||||||
|
VkSampler screenSampler{};
|
||||||
|
VkDescriptorSet screenTexture{};
|
||||||
VkDevice device{};
|
VkDevice device{};
|
||||||
uint32_t queueFamily{uint32_t(-1)};
|
uint32_t queueFamily{uint32_t(-1)};
|
||||||
VkQueue queue{};
|
VkQueue queue{};
|
||||||
|
|||||||
Reference in New Issue
Block a user