Render to imgui::image
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -27,4 +27,5 @@ using m128 = __m128i;
|
||||
#define N64_CPU_FREQ 93750000
|
||||
#define N64_CYCLES_PER_FRAME ((N64_CPU_FREQ) / 60)
|
||||
#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);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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{};
|
||||
|
||||
Reference in New Issue
Block a user