Git Product home page Git Product logo

crosswindow-graphics's Introduction

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

  • ๐ŸŒ‹ Vulkan
  • โšช OpenGL
  • โšช OpenGL ES
  • ๐ŸŒ WebGL
  • โŽ DirectX 12.x
  • โœ–๏ธ DirectX 11.x
  • ๐Ÿค– Metal

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
  xwin::OpenGLDesc desc;
  xwin::OpenGLState state = xwin::createContext(&window, desc);

  // โฌ‡๏ธ Set the context
  xwin::setContext(state);

  // ๐Ÿ”€ Refresh your window
  xwin::swapBuffers(state);

  // โฌ†๏ธ Unset the context
  xwin::unsetContext(state);

  // โฌ…๏ธ Destroy the context
  xwin::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
  xwin::createMetalLayer(&window);

  // ๐Ÿฎ Access the layer from your window
  CAMetalLayer* layer = (CAMetalLayer*)window.layer;

#endif
}

Preprocessor Definitions

CMake Options Description
XGFX_API The 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:

Definition Description
XGFX_VULKAN Vulkan
XGFX_OPENGL OpenGL / OpenGL ES / WebGL
XGFX_DIRECTX12 DirectX 12.x
XGFX_DIRECTX11 DirectX 11.x
XGFX_METAL Metal

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.

crosswindow-graphics's People

Contributors

alaingalvan avatar gideongrinberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.