nngn
graphics Directory Reference

Graphics back ends.

More...

Directory dependency graph for graphics:
src/graphics

Directories

directory  opengl
 
directory  vulkan
 

Files

file  glfw.cpp
 
file  glfw.h [code]
 
file  graphics.cpp
 
file  graphics.h [code]
 
file  lua_graphics.cpp
 
file  lua_texture.cpp
 
file  pseudo.cpp
 
file  pseudo.h [code]
 
file  shaders.cpp
 
file  stats.h [code]
 
file  terminal.cpp
 
file  texture.cpp
 
file  texture.h [code]
 

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,
})
debug
Definition: lua_render.cpp:29
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()))
std::tuple< float, float, float > g(const Camera &c)
Definition: lua_camera.cpp:11
auto version(Graphics &g)
Definition: lua_graphics.cpp:97
auto extensions(const Graphics &g, nngn::lua::state_arg lua)
Definition: lua_graphics.cpp:187
bool init_device(Graphics &g, std::optional< std::size_t > i)
Definition: lua_graphics.cpp:102
auto device_infos(const Graphics &g, nngn::lua::state_arg lua)
Definition: lua_graphics.cpp:201

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)
stats
Definition: lua_collision.cpp:56
auto window_size(const Graphics &g)
Definition: lua_graphics.cpp:249

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)