nngn
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
graphics Directory Reference

Graphics back ends.

More...

Directory dependency graph for graphics:
src/graphics

Directories

 opengl
 
 terminal
 
 vulkan
 

Files

 glfw.cpp
 
 glfw.h
 
 graphics.cpp
 
 graphics.h
 
 lua_graphics.cpp
 
 lua_texture.cpp
 
 pseudo.cpp
 
 pseudo.h
 
 shaders.cpp
 
 stats.h
 
 texture.cpp
 
 texture.h
 

Detailed Description

Graphics back ends.

Several graphics back ends are supported, substitutable at runtime:

The following areas of the screenshots page show some of the graphics capabilities:

These are the low-level rendering operations. The higher-level layer is src/render.

Lua

The graphics back end is exposed to Lua via the nngn.graphics variable. It is only used for low-level control of the machine's graphics capabilities, however. See the documentation of src/render for how to perform higher-level rendering from Lua.

Initialization

A back end is chosen on default initialization (see src). For other cases, a specific back end can be initialized with:

nngn:set_graphics(Graphics.VULKAN_BACKEND, Graphics.vulkan_params {
version = {1, 2, 164},
debug = true,
})
Definition audio.cpp:7

A back end can also be partially initialized to query its capabilities (see demos/graphics/list.lua):

vk = Graphics.create_backend(...)
assert(vk:init_backend())
print(vk:version())
assert(vk:init_instance())
utils.pprint(vk:extensions())
utils.pprint(vk:device_infos())
assert(vk:init_device())
utils.pprint(vk:device_info(g:selected_device()))
assert
Definition debug.lua:3
local utils
Definition common.lua:1
local g
Definition gamma.lua:7
pprint
Definition utils.lua:50

Common operations are:

-- Get current window size.
x, y = nngn.graphics:window_size()
-- Query statistics.
s = nngn.graphics:stats()
-- Set cursor display mode.
nngn.graphics:set_cursor_mode(Graphics.CURSOR_MODE_DISABLED)
-- Set resource limits.
nngn.graphics:resize_textures(8)
nngn.graphics:set_shadow_map_size(512, 512)
-- Control v-sync.
nngn.graphics:set_swap_interval(0)
v[1]
Definition math.lua:22
local stats
Definition timeline.lua:5

Post-processing

Post-processing configuration is also done via the graphics back end:

nngn.graphics:set_HDR_mix(0.5)
nngn.graphics:set_exposure(2)
nngn.graphics:set_automatic_exposure(true)
nngn.graphics:set_bloom_blur_passes(4)
nngn.graphics:set_blur_size(2)