Skip to content

Commit

Permalink
Merge pull request #583 from m0ppers/vulkan
Browse files Browse the repository at this point in the history
add vulkan demo
  • Loading branch information
riri authored Nov 13, 2023
2 parents bed81e2 + a3f0da0 commit a18175c
Show file tree
Hide file tree
Showing 13 changed files with 5,473 additions and 0 deletions.
4 changes: 4 additions & 0 deletions demo/glfw_vulkan/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
BasedOnStyle: LLVM
# same as .editorconfig
IndentWidth: 4
3 changes: 3 additions & 0 deletions demo/glfw_vulkan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/nuklearshaders/*.spv
src/nuklear_glfw_vulkan.h
shaders/*.spv
29 changes: 29 additions & 0 deletions demo/glfw_vulkan/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Install
BIN = demo

# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)

ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lglfw3 -lvulkan -lm
else
UNAME_S := $(shell uname -s)
GLFW3 := $(shell pkg-config --libs glfw3)
LIBS = $(GLFW3) -lvulkan -lm
endif


$(BIN): shaders/demo.vert.spv shaders/demo.frag.spv
@mkdir -p bin
rm -f bin/$(BIN) $(OBJS)
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)

shaders/demo.vert.spv: shaders/demo.vert
glslc --target-env=vulkan shaders/demo.vert -o shaders/demo.vert.spv

shaders/demo.frag.spv: shaders/demo.frag
glslc --target-env=vulkan shaders/demo.frag -o shaders/demo.frag.spv
52 changes: 52 additions & 0 deletions demo/glfw_vulkan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# nuklear glfw vulkan

## Theory of operation

The nuklear glfw vulkan integration creates an independent graphics pipeline that will render the nuklear UI to separate render targets.
The application is responsible to fully manage these render targets. So it must ensure they are properly sized (and resized when requested).

Furthermore it is assumed that you will have a swap chain in place and the number of nuklear overlay images and number of swap chain images match.

This is how you can integrate it in your application:

```
/*
Setup: overlay_images have been created and their number match with the number
of the swap_chain_images of your application. The overlay_images in this
example have the same format as your swap_chain images (optional)
*/
struct nk_context *ctx = nk_glfw3_init(
demo.win, demo.device, demo.physical_device, demo.indices.graphics,
demo.overlay_image_views, demo.swap_chain_images_len,
demo.swap_chain_image_format, NK_GLFW3_INSTALL_CALLBACKS,
MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
[...]
/*
in your draw loop draw you can then render to the overlay image at
`image_index`
your own application can then wait for the semaphore and produce
the swap_chain_image at `image_index`
this should simply sample from the overlay_image (see example)
*/
nk_semaphore semaphore =
nk_glfw3_render(demo.graphics_queue, image_index,
demo.image_available, NK_ANTI_ALIASING_ON);
if (!render(&demo, &bg, nk_semaphore, image_index)) {
fprintf(stderr, "render failed\n");
return false;
}
```

You must call `nk_glfw3_resize` whenever the size of the overlay_images resize.

## Using images

Images can be used by providing a VkImageView as an nk_image_ptr to nuklear:

```
img = nk_image_ptr(demo.demo_texture_image_view);
```

Note that they must have SHADER_READ_OPTIMAL layout

It is currently not possible to specify how they are being sampled. The nuklear glfw vulkan integration uses a fixed sampler that does linear filtering.
Loading

0 comments on commit a18175c

Please sign in to comment.