Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDAlexander77 committed May 27, 2020
1 parent 9ccca6b commit 84ee216
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
19 changes: 14 additions & 5 deletions Experiment/SimpleVulkanApp/src/appwindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ declare function create_window(title: string, parent_hwnd: intptr_t, handler: ca
declare function close_window(exitCode: uint32_t): void;
declare function destroy_window(hwnd: intptr_t): uint32_t;

declare function create_vulkan(hwnd: intptr_t): void;
declare function run_vulkan(): void;
declare function cleanup_vulkan(): void;

enum Messages {
Size = 0x0005,
Paint = 0x000F,
Expand All @@ -17,35 +21,40 @@ enum Messages {

enum Keys {
Escape = 0x1b,
Paint = 0x0f,
Erasebkgnd = 0x14,
Space = 0x20
}

export class AppWindow {

private handler_window: intptr_t;


constructor(parent_handler_window?: intptr_t) {
this.handler_window = create_window('Hello World!', parent_handler_window, this.onMessage);


vulkan.Instance.Create();
create_vulkan(this.handler_window);
}

protected onMessage(uMsg: uint64_t, wParam: uint64_t, lParam: uint64_t): uint32_t {
switch (uMsg) {
case Keys.Paint:
run_vulkan();
break;
case Keys.Erasebkgnd:
return 1;
case Messages.KeyDown: // key down
switch (wParam) {
case Keys.Escape: // key escape
close_window(0);
cleanup_vulkan();
return 0;
case Keys.Space: // key space
// open new window
return 0;
}

break;
}
}

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ struct VulkanApi {
&& load_gpu_and_queue_properties();
}

#ifdef WIN32
void create_surface_win32(HINSTANCE hInstance, HWND hwnd) {
auto const createInfo = vk::Win32SurfaceCreateInfoKHR().setHinstance(hInstance).setHwnd(hwnd);
auto result = inst.createWin32SurfaceKHR(&createInfo, nullptr, &surface);
VERIFY(result == vk::Result::eSuccess);
}
#endif

bool initialize_swapchain() {
return create_surface()
&& set_graphics_and_present_family_indexes()
Expand Down Expand Up @@ -415,7 +423,10 @@ struct VulkanApi {
}

bool create_surface() {
on_create_surface(inst, surface);
if (on_create_surface) {
on_create_surface(inst, surface);
}

return true;
}

Expand Down Expand Up @@ -1934,4 +1945,22 @@ struct VulkanApi {
std::cerr << group << ": " << msg << std::endl;
exit(1);
}
};
};

VulkanApi vulkanApi;
extern HINSTANCE instance;

void create_vulkan(intptr_t hwnd) {
vulkanApi.initialize();
vulkanApi.create_surface_win32(instance, (HWND) hwnd);
vulkanApi.initialize_swapchain();
vulkanApi.prepare();
}

void run_vulkan() {
vulkanApi.run();
}

void cleanup_vulkan() {
vulkanApi.cleanup();
}
7 changes: 3 additions & 4 deletions Experiment/SimpleVulkanApp/src/native/window.win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#undef max
#include "core.h"

static HINSTANCE instance;
static int cmdShow;
const TCHAR* CLASS_NAME = TEXT("Application Window");

HINSTANCE instance;
int cmdShow;

typedef std::function<uint32_t(uint64_t, uint64_t, uint64_t)> callback_function;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand Down Expand Up @@ -103,7 +104,5 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}

RedrawWindow(hwnd, nullptr, nullptr, RDW_INTERNALPAINT);

return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
2 changes: 0 additions & 2 deletions Experiment/SimpleVulkanApp/src/vulkanapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="./vulkan.win32.d.ts" />

module vulkan {
export class Instance {
static Create(): Instance {
Expand Down

0 comments on commit 84ee216

Please sign in to comment.