Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set(CMAKE_CXX_STANDARD 17)

# Enable SDL Vulkan integration
set(PLUME_SDL_VULKAN_ENABLED ON CACHE BOOL "Enable SDL Vulkan integration" FORCE)
# Enable SDL Vulkan integration (Linux only)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(PLUME_SDL_VULKAN_ENABLED ON CACHE BOOL "Enable SDL Vulkan integration" FORCE)
endif()

# Find SDL2 (required for examples)
find_package(SDL2 REQUIRED)
Expand Down
81 changes: 56 additions & 25 deletions examples/cube/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,36 +507,28 @@ namespace plume {
ctx.m_commandQueue->waitForCommandFence(ctx.m_fence.get());
}

void CubeExample(RenderInterface* renderInterface, const std::string& apiName) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return;
}

uint32_t flags = SDL_WINDOW_RESIZABLE;
#if defined(__APPLE__)
flags |= SDL_WINDOW_METAL;
#endif

void CubeExample(RenderInterface* renderInterface, SDL_Window* window, const std::string& apiName) {
std::string windowTitle = "Plume Cube Texture Example (" + apiName + ")";
SDL_Window* window = SDL_CreateWindow(windowTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags);
if (!window) {
fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return;
}
SDL_SetWindowTitle(window, windowTitle.c_str());

CubeContext ctx;
#if PLUME_SDL_VULKAN_ENABLED
createContext(ctx, renderInterface, window, apiName);
#elif defined(__linux__)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);

CubeContext ctx;
#if defined(__linux__)
createContext(ctx, renderInterface, { wmInfo.info.x11.display, wmInfo.info.x11.window }, apiName);
#elif defined(__APPLE__)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
SDL_MetalView view = SDL_Metal_CreateView(window);
createContext(ctx, renderInterface, { wmInfo.info.cocoa.window, SDL_Metal_GetLayer(view) }, apiName);
#elif defined(WIN32)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
createContext(ctx, renderInterface, { wmInfo.info.win.window }, apiName);
#endif

Expand Down Expand Up @@ -577,38 +569,77 @@ namespace plume {
#if defined(__APPLE__)
SDL_Metal_DestroyView(view);
#endif
SDL_DestroyWindow(window);
SDL_Quit();
}
}

std::unique_ptr<plume::RenderInterface> CreateRenderInterface(std::string& apiName) {
std::unique_ptr<plume::RenderInterface> CreateRenderInterface(SDL_Window* window, std::string& apiName) {
const bool useVulkan = false;
#if defined(_WIN32)
if (useVulkan) {
apiName = "Vulkan";
#if PLUME_SDL_VULKAN_ENABLED
return plume::CreateVulkanInterface(window);
#else
return plume::CreateVulkanInterface();
#endif
} else {
apiName = "D3D12";
return plume::CreateD3D12Interface();
}
#elif defined(__APPLE__)
if (useVulkan) {
apiName = "Vulkan";
#if PLUME_SDL_VULKAN_ENABLED
return plume::CreateVulkanInterface(window);
#else
return plume::CreateVulkanInterface();
#endif
} else {
apiName = "Metal";
return plume::CreateMetalInterface();
}
#else
apiName = "Vulkan";
#if PLUME_SDL_VULKAN_ENABLED
return plume::CreateVulkanInterface(window);
#else
return plume::CreateVulkanInterface();
#endif
#endif
}

int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return 1;
}

uint32_t flags = SDL_WINDOW_RESIZABLE;
#if PLUME_SDL_VULKAN_ENABLED
flags |= SDL_WINDOW_VULKAN;
#elif defined(__APPLE__)
flags |= SDL_WINDOW_METAL;
#endif

SDL_Window* window = SDL_CreateWindow("Plume Cube Texture Example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags);
if (!window) {
fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}

std::string apiName = "Unknown";
auto renderInterface = CreateRenderInterface(apiName);
plume::CubeExample(renderInterface.get(), apiName);
auto renderInterface = CreateRenderInterface(window, apiName);
if (!renderInterface) {
fprintf(stderr, "Failed to create render interface\n");
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}

plume::CubeExample(renderInterface.get(), window, apiName);

SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
2 changes: 1 addition & 1 deletion examples/cube/shaders/cube.frag.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Samples from a cubemap texture

[[vk::binding(0, 0)]] TextureCube<float4> cubeTexture : register(t0);
[[vk::binding(1, 0)]] SamplerState cubeSampler : register(s0);
[[vk::binding(1, 0)]] SamplerState cubeSampler : register(s1);

struct PSInput {
float4 position : SV_POSITION;
Expand Down
81 changes: 56 additions & 25 deletions examples/triangle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,36 +293,28 @@ namespace plume {
ctx.m_commandQueue->waitForCommandFence(ctx.m_fence.get());
}

void RenderInterfaceTest(RenderInterface* renderInterface, const std::string &apiName) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return;
}

uint32_t flags = SDL_WINDOW_RESIZABLE;
#if defined(__APPLE__)
flags |= SDL_WINDOW_METAL;
#endif

void RenderInterfaceTest(RenderInterface* renderInterface, SDL_Window* window, const std::string &apiName) {
std::string windowTitle = "Plume Example (" + apiName + ")";
SDL_Window* window = SDL_CreateWindow(windowTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags);
if (!window) {
fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return;
}
SDL_SetWindowTitle(window, windowTitle.c_str());

TestContext ctx;
#if PLUME_SDL_VULKAN_ENABLED
createContext(ctx, renderInterface, window, apiName);
#elif defined(__linux__)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);

TestContext ctx;
#if defined(__linux__)
createContext(ctx, renderInterface, { wmInfo.info.x11.display, wmInfo.info.x11.window }, apiName);
#elif defined(__APPLE__)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
SDL_MetalView view = SDL_Metal_CreateView(window);
createContext(ctx, renderInterface, { wmInfo.info.cocoa.window, SDL_Metal_GetLayer(view) }, apiName);
#elif defined(WIN32)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
createContext(ctx, renderInterface, { wmInfo.info.win.window }, apiName);
#endif

Expand Down Expand Up @@ -365,17 +357,19 @@ namespace plume {
#if defined(__APPLE__)
SDL_Metal_DestroyView(view);
#endif
SDL_DestroyWindow(window);
SDL_Quit();
}
}

std::unique_ptr<plume::RenderInterface> CreateRenderInterface(std::string &apiName) {
std::unique_ptr<plume::RenderInterface> CreateRenderInterface(SDL_Window* window, std::string &apiName) {
const bool useVulkan = false;
#if defined(_WIN32)
if (useVulkan) {
apiName = "Vulkan";
#if PLUME_SDL_VULKAN_ENABLED
return plume::CreateVulkanInterface(window);
#else
return plume::CreateVulkanInterface();
#endif
}
else {
apiName = "D3D12";
Expand All @@ -384,21 +378,58 @@ std::unique_ptr<plume::RenderInterface> CreateRenderInterface(std::string &apiNa
#elif defined(__APPLE__)
if (useVulkan) {
apiName = "Vulkan";
#if PLUME_SDL_VULKAN_ENABLED
return plume::CreateVulkanInterface(window);
#else
return plume::CreateVulkanInterface();
#endif
}
else {
apiName = "Metal";
return plume::CreateMetalInterface();
}
#else
apiName = "Vulkan";
#if PLUME_SDL_VULKAN_ENABLED
return plume::CreateVulkanInterface(window);
#else
return plume::CreateVulkanInterface();
#endif
#endif
}

int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return 1;
}

uint32_t flags = SDL_WINDOW_RESIZABLE;
#if PLUME_SDL_VULKAN_ENABLED
flags |= SDL_WINDOW_VULKAN;
#elif defined(__APPLE__)
flags |= SDL_WINDOW_METAL;
#endif

SDL_Window* window = SDL_CreateWindow("Plume Example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags);
if (!window) {
fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}

std::string apiName = "Unknown";
auto renderInterface = CreateRenderInterface(apiName);
plume::RenderInterfaceTest(renderInterface.get(), apiName);
auto renderInterface = CreateRenderInterface(window, apiName);
if (!renderInterface) {
fprintf(stderr, "Failed to create render interface\n");
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}

plume::RenderInterfaceTest(renderInterface.get(), window, apiName);

SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Loading
Loading