Home

Awesome

CrossWindow-Graphics

cmake-img License

A header only library to simplify creating and managing data structures needed for graphics APIs such as a Vulkan vk::Surface, an OpenGL context, a DirectX IDXGISwapChain1, or Metal CAMetalLayer.

Supports

Installation

First add the repo as a submodule in your dependencies folder such as external/:

cd external
git submodule add https://github.com/alaingalvan/crosswindow-graphics.git

Then in your CMakeLists.txt file, include the following:

add_subdirectory(external/crosswindow-graphics)

target_link_libraries(
    ${PROJECT_NAME}
    CrossWindowGraphics
)

Usage

#include "CrossWindow/CrossWindow.h"
#include "CrossWindow/Graphics.h"

void xmain(int argc, char** argv)
{
  // 🖼️ Create your xwin::Window...
  xwin::Window window;
  
  // ...
  
#if defined(XGFX_VULKAN)
  
  // 🌋 Vulkan Surface
  vk::Surface surface = xwin::createSurface(&window, instance);

#elif defined(XGFX_OPENGL)

  // ⚪ OpenGL / OpenGL ES / 🌐 WebGL platform specific context data
  xgfx::OpenGLDesc desc;
  xgfx::OpenGLState state = xgfx::createContext(&window, desc);

  // ⬇️ Set the context
  xgfx::setContext(state);

  // 🔀 Refresh your window
  xgfx::swapBuffers(state);

  // ⬆️ Unset the context
  xgfx::unsetContext(state);

  // ⬅️ Destroy the context
  xgfx::destroyContext(state);

#elif defined(XGFX_DIRECTX12)

  // ❎ DirectX 12.x Swapchain
  IDXGISwapChain1* swapchain = xgfx::createSwapchain(window, factory, commandQueue, &swapchainDesc);

#elif defined(XGFX_DIRECTX11)

  // ✖️ DirectX 11.x Swapchain
  IDXGISwapChain* swapchain = xgfx::createSwapchain(window, factory, device, &swapchainDesc);

#elif defined(XWIN_METAL)

  // 🤖 Metal Layer
  xgfx::createMetalLayer(&window);

  // 🍮 Access the layer from your window
  CAMetalLayer* layer = (CAMetalLayer*)window.layer;

#endif
}

Preprocessor Definitions

CMake OptionsDescription
XGFX_APIThe graphics API you're targeting, defaults to VULKAN, can be can be VULKAN, OPENGL, DIRECTX12, METAL, or NONE.

Alternatively you can set the following preprocessor definitions manually:

DefinitionDescription
XGFX_VULKANVulkan
XGFX_OPENGLOpenGL / OpenGL ES / WebGL
XGFX_DIRECTX12DirectX 12.x
XGFX_DIRECTX11DirectX 11.x
XGFX_METALMetal

Design Decisions

The official Khronos Group's Vulkan Samples features an OpenGL driver info example and Vulkan cube example that the OpenGL/Vulkan portions of this library pull heavily from, but diverges with the decision to separate operating systems by protocol (similar to the design of CrossWindow).

You can read more in our docs.

License

CrossWindow is licensed as either MIT or Apache-2.0, whichever you would prefer.