diff --git a/.gitignore b/.gitignore index 3027f82e..59e02bfc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ old_scripts/ *.cap *.bin *.ilk +*.bc *.DS_Store trusslog.txt shader_errors.txt diff --git a/cmake/terra.cmake b/cmake/terra.cmake index b5e4a8ed..a801c6cc 100644 --- a/cmake/terra.cmake +++ b/cmake/terra.cmake @@ -1,29 +1,32 @@ include(ExternalProject) # Use this version of terra. -set(terra_RELEASE_DATE "1.0.0-beta3") -set(terra_RELEASE_HASH "e4ec5d1") +set(terra_RELEASE_DATE "1.0.0-beta4") +set(terra_RELEASE_HASH "868748e") if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") set(terra_SYSTEM_NAME "Windows") set(terra_SHARED_LIBS_DIR "bin") set(terra_LIBRARY_NAME "terra.dll") set(terra_IMPLIB_NAME "terra.lib") + set(terra_RELEASE_EXT ".7z") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") set(terra_SYSTEM_NAME "OSX") set(terra_SHARED_LIBS_DIR "lib") set(terra_LIBRARY_NAME "terra.dylib") + set(terra_RELEASE_EXT ".tar.xz") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") set(terra_SYSTEM_NAME "Linux") set(terra_SHARED_LIBS_DIR "lib") set(terra_LIBRARY_NAME "libterra.so") + set(terra_RELEASE_EXT ".tar.xz") else() message(FATAL_ERROR "Terra does not have precompiled binaries for '${CMAKE_SYSTEM_NAME}'.") endif() # Download `terra` and unzip its binaries. ExternalProject_Add(terra_EXTERNAL - URL "https://github.com/zdevito/terra/releases/download/release-${terra_RELEASE_DATE}/terra-${terra_SYSTEM_NAME}-x86_64-${terra_RELEASE_HASH}.zip" + URL "https://github.com/zdevito/terra/releases/download/release-${terra_RELEASE_DATE}/terra-${terra_SYSTEM_NAME}-x86_64-${terra_RELEASE_HASH}${terra_RELEASE_EXT}" URL_MD5 "${terra_MD5}" CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/dist/include/bgfx/bgfx.h b/dist/include/bgfx/bgfx.h index eda902ce..40f43e9c 100644 --- a/dist/include/bgfx/bgfx.h +++ b/dist/include/bgfx/bgfx.h @@ -1,2741 +1,3758 @@ /* - * Copyright 2011-2016 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + * Copyright 2011-2021 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ -#ifndef BGFX_H_HEADER_GUARD -#define BGFX_H_HEADER_GUARD +/* + * + * AUTO GENERATED FROM IDL! DO NOT EDIT! (source : temp.bgfx.h) + * + * More info about IDL: + * https://gist.github.com/bkaradzic/05a1c86a6dd57bf86e2d828878e88dc2#bgfx-is-switching-to-idl-to-generate-api + * + */ + +#ifndef BGFX_C99_H_HEADER_GUARD +#define BGFX_C99_H_HEADER_GUARD + +#include // va_list +#include // bool +#include // uint32_t +#include // size_t + +#include + +#if !defined(BGFX_INVALID_HANDLE) +# define BGFX_INVALID_HANDLE { UINT16_MAX } +#endif // !defined(BGFX_INVALID_HANDLE) + +#ifndef BGFX_SHARED_LIB_BUILD +# define BGFX_SHARED_LIB_BUILD 0 +#endif // BGFX_SHARED_LIB_BUILD + +#ifndef BGFX_SHARED_LIB_USE +# define BGFX_SHARED_LIB_USE 0 +#endif // BGFX_SHARED_LIB_USE + +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +# define BGFX_SYMBOL_EXPORT __declspec(dllexport) +# define BGFX_SYMBOL_IMPORT __declspec(dllimport) +#else +# define BGFX_SYMBOL_EXPORT __attribute__((visibility("default"))) +# define BGFX_SYMBOL_IMPORT +#endif // BX_PLATFORM_WINDOWS + +#if BGFX_SHARED_LIB_BUILD +# define BGFX_SHARED_LIB_API BGFX_SYMBOL_EXPORT +#elif BGFX_SHARED_LIB_USE +# define BGFX_SHARED_LIB_API BGFX_SYMBOL_IMPORT +#else +# define BGFX_SHARED_LIB_API +#endif // BGFX_SHARED_LIB_* + +#if defined(__cplusplus) +# define BGFX_C_API extern "C" BGFX_SHARED_LIB_API +#else +# define BGFX_C_API BGFX_SHARED_LIB_API +#endif // defined(__cplusplus) + +#include "../defines.h" + +/** + * Fatal error enum. + * + */ +typedef enum bgfx_fatal +{ + BGFX_FATAL_DEBUG_CHECK, /** ( 0) */ + BGFX_FATAL_INVALID_SHADER, /** ( 1) */ + BGFX_FATAL_UNABLE_TO_INITIALIZE, /** ( 2) */ + BGFX_FATAL_UNABLE_TO_CREATE_TEXTURE, /** ( 3) */ + BGFX_FATAL_DEVICE_LOST, /** ( 4) */ + + BGFX_FATAL_COUNT + +} bgfx_fatal_t; + +/** + * Renderer backend type enum. + * + */ +typedef enum bgfx_renderer_type +{ + BGFX_RENDERER_TYPE_NOOP, /** ( 0) No rendering. */ + BGFX_RENDERER_TYPE_DIRECT3D9, /** ( 1) Direct3D 9.0 */ + BGFX_RENDERER_TYPE_DIRECT3D11, /** ( 2) Direct3D 11.0 */ + BGFX_RENDERER_TYPE_DIRECT3D12, /** ( 3) Direct3D 12.0 */ + BGFX_RENDERER_TYPE_GNM, /** ( 4) GNM */ + BGFX_RENDERER_TYPE_METAL, /** ( 5) Metal */ + BGFX_RENDERER_TYPE_NVN, /** ( 6) NVN */ + BGFX_RENDERER_TYPE_OPENGLES, /** ( 7) OpenGL ES 2.0+ */ + BGFX_RENDERER_TYPE_OPENGL, /** ( 8) OpenGL 2.1+ */ + BGFX_RENDERER_TYPE_VULKAN, /** ( 9) Vulkan */ + BGFX_RENDERER_TYPE_WEBGPU, /** (10) WebGPU */ + + BGFX_RENDERER_TYPE_COUNT + +} bgfx_renderer_type_t; + +/** + * Access mode enum. + * + */ +typedef enum bgfx_access +{ + BGFX_ACCESS_READ, /** ( 0) Read. */ + BGFX_ACCESS_WRITE, /** ( 1) Write. */ + BGFX_ACCESS_READWRITE, /** ( 2) Read and write. */ + + BGFX_ACCESS_COUNT + +} bgfx_access_t; + +/** + * Vertex attribute enum. + * + */ +typedef enum bgfx_attrib +{ + BGFX_ATTRIB_POSITION, /** ( 0) a_position */ + BGFX_ATTRIB_NORMAL, /** ( 1) a_normal */ + BGFX_ATTRIB_TANGENT, /** ( 2) a_tangent */ + BGFX_ATTRIB_BITANGENT, /** ( 3) a_bitangent */ + BGFX_ATTRIB_COLOR0, /** ( 4) a_color0 */ + BGFX_ATTRIB_COLOR1, /** ( 5) a_color1 */ + BGFX_ATTRIB_COLOR2, /** ( 6) a_color2 */ + BGFX_ATTRIB_COLOR3, /** ( 7) a_color3 */ + BGFX_ATTRIB_INDICES, /** ( 8) a_indices */ + BGFX_ATTRIB_WEIGHT, /** ( 9) a_weight */ + BGFX_ATTRIB_TEXCOORD0, /** (10) a_texcoord0 */ + BGFX_ATTRIB_TEXCOORD1, /** (11) a_texcoord1 */ + BGFX_ATTRIB_TEXCOORD2, /** (12) a_texcoord2 */ + BGFX_ATTRIB_TEXCOORD3, /** (13) a_texcoord3 */ + BGFX_ATTRIB_TEXCOORD4, /** (14) a_texcoord4 */ + BGFX_ATTRIB_TEXCOORD5, /** (15) a_texcoord5 */ + BGFX_ATTRIB_TEXCOORD6, /** (16) a_texcoord6 */ + BGFX_ATTRIB_TEXCOORD7, /** (17) a_texcoord7 */ + + BGFX_ATTRIB_COUNT + +} bgfx_attrib_t; + +/** + * Vertex attribute type enum. + * + */ +typedef enum bgfx_attrib_type +{ + BGFX_ATTRIB_TYPE_UINT8, /** ( 0) Uint8 */ + BGFX_ATTRIB_TYPE_UINT10, /** ( 1) Uint10, availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_UINT10`. */ + BGFX_ATTRIB_TYPE_INT16, /** ( 2) Int16 */ + BGFX_ATTRIB_TYPE_HALF, /** ( 3) Half, availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_HALF`. */ + BGFX_ATTRIB_TYPE_FLOAT, /** ( 4) Float */ + + BGFX_ATTRIB_TYPE_COUNT + +} bgfx_attrib_type_t; + +/** + * Texture format enum. + * Notation: + * RGBA16S + * ^ ^ ^ + * | | +-- [ ]Unorm + * | | [F]loat + * | | [S]norm + * | | [I]nt + * | | [U]int + * | +---- Number of bits per component + * +-------- Components + * @attention Availability depends on Caps (see: formats). + * + */ +typedef enum bgfx_texture_format +{ + BGFX_TEXTURE_FORMAT_BC1, /** ( 0) DXT1 R5G6B5A1 */ + BGFX_TEXTURE_FORMAT_BC2, /** ( 1) DXT3 R5G6B5A4 */ + BGFX_TEXTURE_FORMAT_BC3, /** ( 2) DXT5 R5G6B5A8 */ + BGFX_TEXTURE_FORMAT_BC4, /** ( 3) LATC1/ATI1 R8 */ + BGFX_TEXTURE_FORMAT_BC5, /** ( 4) LATC2/ATI2 RG8 */ + BGFX_TEXTURE_FORMAT_BC6H, /** ( 5) BC6H RGB16F */ + BGFX_TEXTURE_FORMAT_BC7, /** ( 6) BC7 RGB 4-7 bits per color channel, 0-8 bits alpha */ + BGFX_TEXTURE_FORMAT_ETC1, /** ( 7) ETC1 RGB8 */ + BGFX_TEXTURE_FORMAT_ETC2, /** ( 8) ETC2 RGB8 */ + BGFX_TEXTURE_FORMAT_ETC2A, /** ( 9) ETC2 RGBA8 */ + BGFX_TEXTURE_FORMAT_ETC2A1, /** (10) ETC2 RGB8A1 */ + BGFX_TEXTURE_FORMAT_PTC12, /** (11) PVRTC1 RGB 2BPP */ + BGFX_TEXTURE_FORMAT_PTC14, /** (12) PVRTC1 RGB 4BPP */ + BGFX_TEXTURE_FORMAT_PTC12A, /** (13) PVRTC1 RGBA 2BPP */ + BGFX_TEXTURE_FORMAT_PTC14A, /** (14) PVRTC1 RGBA 4BPP */ + BGFX_TEXTURE_FORMAT_PTC22, /** (15) PVRTC2 RGBA 2BPP */ + BGFX_TEXTURE_FORMAT_PTC24, /** (16) PVRTC2 RGBA 4BPP */ + BGFX_TEXTURE_FORMAT_ATC, /** (17) ATC RGB 4BPP */ + BGFX_TEXTURE_FORMAT_ATCE, /** (18) ATCE RGBA 8 BPP explicit alpha */ + BGFX_TEXTURE_FORMAT_ATCI, /** (19) ATCI RGBA 8 BPP interpolated alpha */ + BGFX_TEXTURE_FORMAT_ASTC4X4, /** (20) ASTC 4x4 8.0 BPP */ + BGFX_TEXTURE_FORMAT_ASTC5X5, /** (21) ASTC 5x5 5.12 BPP */ + BGFX_TEXTURE_FORMAT_ASTC6X6, /** (22) ASTC 6x6 3.56 BPP */ + BGFX_TEXTURE_FORMAT_ASTC8X5, /** (23) ASTC 8x5 3.20 BPP */ + BGFX_TEXTURE_FORMAT_ASTC8X6, /** (24) ASTC 8x6 2.67 BPP */ + BGFX_TEXTURE_FORMAT_ASTC10X5, /** (25) ASTC 10x5 2.56 BPP */ + BGFX_TEXTURE_FORMAT_UNKNOWN, /** (26) Compressed formats above. */ + BGFX_TEXTURE_FORMAT_R1, /** (27) */ + BGFX_TEXTURE_FORMAT_A8, /** (28) */ + BGFX_TEXTURE_FORMAT_R8, /** (29) */ + BGFX_TEXTURE_FORMAT_R8I, /** (30) */ + BGFX_TEXTURE_FORMAT_R8U, /** (31) */ + BGFX_TEXTURE_FORMAT_R8S, /** (32) */ + BGFX_TEXTURE_FORMAT_R16, /** (33) */ + BGFX_TEXTURE_FORMAT_R16I, /** (34) */ + BGFX_TEXTURE_FORMAT_R16U, /** (35) */ + BGFX_TEXTURE_FORMAT_R16F, /** (36) */ + BGFX_TEXTURE_FORMAT_R16S, /** (37) */ + BGFX_TEXTURE_FORMAT_R32I, /** (38) */ + BGFX_TEXTURE_FORMAT_R32U, /** (39) */ + BGFX_TEXTURE_FORMAT_R32F, /** (40) */ + BGFX_TEXTURE_FORMAT_RG8, /** (41) */ + BGFX_TEXTURE_FORMAT_RG8I, /** (42) */ + BGFX_TEXTURE_FORMAT_RG8U, /** (43) */ + BGFX_TEXTURE_FORMAT_RG8S, /** (44) */ + BGFX_TEXTURE_FORMAT_RG16, /** (45) */ + BGFX_TEXTURE_FORMAT_RG16I, /** (46) */ + BGFX_TEXTURE_FORMAT_RG16U, /** (47) */ + BGFX_TEXTURE_FORMAT_RG16F, /** (48) */ + BGFX_TEXTURE_FORMAT_RG16S, /** (49) */ + BGFX_TEXTURE_FORMAT_RG32I, /** (50) */ + BGFX_TEXTURE_FORMAT_RG32U, /** (51) */ + BGFX_TEXTURE_FORMAT_RG32F, /** (52) */ + BGFX_TEXTURE_FORMAT_RGB8, /** (53) */ + BGFX_TEXTURE_FORMAT_RGB8I, /** (54) */ + BGFX_TEXTURE_FORMAT_RGB8U, /** (55) */ + BGFX_TEXTURE_FORMAT_RGB8S, /** (56) */ + BGFX_TEXTURE_FORMAT_RGB9E5F, /** (57) */ + BGFX_TEXTURE_FORMAT_BGRA8, /** (58) */ + BGFX_TEXTURE_FORMAT_RGBA8, /** (59) */ + BGFX_TEXTURE_FORMAT_RGBA8I, /** (60) */ + BGFX_TEXTURE_FORMAT_RGBA8U, /** (61) */ + BGFX_TEXTURE_FORMAT_RGBA8S, /** (62) */ + BGFX_TEXTURE_FORMAT_RGBA16, /** (63) */ + BGFX_TEXTURE_FORMAT_RGBA16I, /** (64) */ + BGFX_TEXTURE_FORMAT_RGBA16U, /** (65) */ + BGFX_TEXTURE_FORMAT_RGBA16F, /** (66) */ + BGFX_TEXTURE_FORMAT_RGBA16S, /** (67) */ + BGFX_TEXTURE_FORMAT_RGBA32I, /** (68) */ + BGFX_TEXTURE_FORMAT_RGBA32U, /** (69) */ + BGFX_TEXTURE_FORMAT_RGBA32F, /** (70) */ + BGFX_TEXTURE_FORMAT_R5G6B5, /** (71) */ + BGFX_TEXTURE_FORMAT_RGBA4, /** (72) */ + BGFX_TEXTURE_FORMAT_RGB5A1, /** (73) */ + BGFX_TEXTURE_FORMAT_RGB10A2, /** (74) */ + BGFX_TEXTURE_FORMAT_RG11B10F, /** (75) */ + BGFX_TEXTURE_FORMAT_UNKNOWNDEPTH, /** (76) Depth formats below. */ + BGFX_TEXTURE_FORMAT_D16, /** (77) */ + BGFX_TEXTURE_FORMAT_D24, /** (78) */ + BGFX_TEXTURE_FORMAT_D24S8, /** (79) */ + BGFX_TEXTURE_FORMAT_D32, /** (80) */ + BGFX_TEXTURE_FORMAT_D16F, /** (81) */ + BGFX_TEXTURE_FORMAT_D24F, /** (82) */ + BGFX_TEXTURE_FORMAT_D32F, /** (83) */ + BGFX_TEXTURE_FORMAT_D0S8, /** (84) */ + + BGFX_TEXTURE_FORMAT_COUNT + +} bgfx_texture_format_t; + +/** + * Uniform type enum. + * + */ +typedef enum bgfx_uniform_type +{ + BGFX_UNIFORM_TYPE_SAMPLER, /** ( 0) Sampler. */ + BGFX_UNIFORM_TYPE_END, /** ( 1) Reserved, do not use. */ + BGFX_UNIFORM_TYPE_VEC4, /** ( 2) 4 floats vector. */ + BGFX_UNIFORM_TYPE_MAT3, /** ( 3) 3x3 matrix. */ + BGFX_UNIFORM_TYPE_MAT4, /** ( 4) 4x4 matrix. */ + + BGFX_UNIFORM_TYPE_COUNT + +} bgfx_uniform_type_t; + +/** + * Backbuffer ratio enum. + * + */ +typedef enum bgfx_backbuffer_ratio +{ + BGFX_BACKBUFFER_RATIO_EQUAL, /** ( 0) Equal to backbuffer. */ + BGFX_BACKBUFFER_RATIO_HALF, /** ( 1) One half size of backbuffer. */ + BGFX_BACKBUFFER_RATIO_QUARTER, /** ( 2) One quarter size of backbuffer. */ + BGFX_BACKBUFFER_RATIO_EIGHTH, /** ( 3) One eighth size of backbuffer. */ + BGFX_BACKBUFFER_RATIO_SIXTEENTH, /** ( 4) One sixteenth size of backbuffer. */ + BGFX_BACKBUFFER_RATIO_DOUBLE, /** ( 5) Double size of backbuffer. */ + + BGFX_BACKBUFFER_RATIO_COUNT + +} bgfx_backbuffer_ratio_t; + +/** + * Occlusion query result. + * + */ +typedef enum bgfx_occlusion_query_result +{ + BGFX_OCCLUSION_QUERY_RESULT_INVISIBLE, /** ( 0) Query failed test. */ + BGFX_OCCLUSION_QUERY_RESULT_VISIBLE, /** ( 1) Query passed test. */ + BGFX_OCCLUSION_QUERY_RESULT_NORESULT, /** ( 2) Query result is not available yet. */ + + BGFX_OCCLUSION_QUERY_RESULT_COUNT + +} bgfx_occlusion_query_result_t; + +/** + * Primitive topology. + * + */ +typedef enum bgfx_topology +{ + BGFX_TOPOLOGY_TRI_LIST, /** ( 0) Triangle list. */ + BGFX_TOPOLOGY_TRI_STRIP, /** ( 1) Triangle strip. */ + BGFX_TOPOLOGY_LINE_LIST, /** ( 2) Line list. */ + BGFX_TOPOLOGY_LINE_STRIP, /** ( 3) Line strip. */ + BGFX_TOPOLOGY_POINT_LIST, /** ( 4) Point list. */ + + BGFX_TOPOLOGY_COUNT + +} bgfx_topology_t; + +/** + * Topology conversion function. + * + */ +typedef enum bgfx_topology_convert +{ + BGFX_TOPOLOGY_CONVERT_TRI_LIST_FLIP_WINDING, /** ( 0) Flip winding order of triangle list. */ + BGFX_TOPOLOGY_CONVERT_TRI_STRIP_FLIP_WINDING, /** ( 1) Flip winding order of triangle strip. */ + BGFX_TOPOLOGY_CONVERT_TRI_LIST_TO_LINE_LIST, /** ( 2) Convert triangle list to line list. */ + BGFX_TOPOLOGY_CONVERT_TRI_STRIP_TO_TRI_LIST, /** ( 3) Convert triangle strip to triangle list. */ + BGFX_TOPOLOGY_CONVERT_LINE_STRIP_TO_LINE_LIST, /** ( 4) Convert line strip to line list. */ + + BGFX_TOPOLOGY_CONVERT_COUNT + +} bgfx_topology_convert_t; + +/** + * Topology sort order. + * + */ +typedef enum bgfx_topology_sort +{ + BGFX_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_MIN, /** ( 0) */ + BGFX_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_AVG, /** ( 1) */ + BGFX_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_MAX, /** ( 2) */ + BGFX_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_MIN, /** ( 3) */ + BGFX_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_AVG, /** ( 4) */ + BGFX_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_MAX, /** ( 5) */ + BGFX_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_MIN, /** ( 6) */ + BGFX_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_AVG, /** ( 7) */ + BGFX_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_MAX, /** ( 8) */ + BGFX_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_MIN, /** ( 9) */ + BGFX_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_AVG, /** (10) */ + BGFX_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_MAX, /** (11) */ + + BGFX_TOPOLOGY_SORT_COUNT + +} bgfx_topology_sort_t; + +/** + * View mode sets draw call sort order. + * + */ +typedef enum bgfx_view_mode +{ + BGFX_VIEW_MODE_DEFAULT, /** ( 0) Default sort order. */ + BGFX_VIEW_MODE_SEQUENTIAL, /** ( 1) Sort in the same order in which submit calls were called. */ + BGFX_VIEW_MODE_DEPTH_ASCENDING, /** ( 2) Sort draw call depth in ascending order. */ + BGFX_VIEW_MODE_DEPTH_DESCENDING, /** ( 3) Sort draw call depth in descending order. */ + + BGFX_VIEW_MODE_COUNT + +} bgfx_view_mode_t; + +/** + * Render frame enum. + * + */ +typedef enum bgfx_render_frame +{ + BGFX_RENDER_FRAME_NO_CONTEXT, /** ( 0) Renderer context is not created yet. */ + BGFX_RENDER_FRAME_RENDER, /** ( 1) Renderer context is created and rendering. */ + BGFX_RENDER_FRAME_TIMEOUT, /** ( 2) Renderer context wait for main thread signal timed out without rendering. */ + BGFX_RENDER_FRAME_EXITING, /** ( 3) Renderer context is getting destroyed. */ + + BGFX_RENDER_FRAME_COUNT + +} bgfx_render_frame_t; + + +/**/ +typedef uint16_t bgfx_view_id_t; + +/**/ +typedef struct bgfx_allocator_interface_s +{ + const struct bgfx_allocator_vtbl_s* vtbl; + +} bgfx_allocator_interface_t; + +/**/ +typedef struct bgfx_allocator_vtbl_s +{ + void* (*realloc)(bgfx_allocator_interface_t* _this, void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line); + +} bgfx_allocator_vtbl_t; + +/**/ +typedef struct bgfx_interface_vtbl bgfx_interface_vtbl_t; + +/**/ +typedef struct bgfx_callback_interface_s +{ + const struct bgfx_callback_vtbl_s* vtbl; + +} bgfx_callback_interface_t; + +/**/ +typedef struct bgfx_callback_vtbl_s +{ + void (*fatal)(bgfx_callback_interface_t* _this, const char* _filePath, uint16_t _line, bgfx_fatal_t _code, const char* _str); + void (*trace_vargs)(bgfx_callback_interface_t* _this, const char* _filePath, uint16_t _line, const char* _format, va_list _argList); + void (*profiler_begin)(bgfx_callback_interface_t* _this, const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line); + void (*profiler_begin_literal)(bgfx_callback_interface_t* _this, const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line); + void (*profiler_end)(bgfx_callback_interface_t* _this); + uint32_t (*cache_read_size)(bgfx_callback_interface_t* _this, uint64_t _id); + bool (*cache_read)(bgfx_callback_interface_t* _this, uint64_t _id, void* _data, uint32_t _size); + void (*cache_write)(bgfx_callback_interface_t* _this, uint64_t _id, const void* _data, uint32_t _size); + void (*screen_shot)(bgfx_callback_interface_t* _this, const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip); + void (*capture_begin)(bgfx_callback_interface_t* _this, uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx_texture_format_t _format, bool _yflip); + void (*capture_end)(bgfx_callback_interface_t* _this); + void (*capture_frame)(bgfx_callback_interface_t* _this, const void* _data, uint32_t _size); + +} bgfx_callback_vtbl_t; + +typedef struct bgfx_dynamic_index_buffer_handle_s { uint16_t idx; } bgfx_dynamic_index_buffer_handle_t; + +typedef struct bgfx_dynamic_vertex_buffer_handle_s { uint16_t idx; } bgfx_dynamic_vertex_buffer_handle_t; + +typedef struct bgfx_frame_buffer_handle_s { uint16_t idx; } bgfx_frame_buffer_handle_t; + +typedef struct bgfx_index_buffer_handle_s { uint16_t idx; } bgfx_index_buffer_handle_t; + +typedef struct bgfx_indirect_buffer_handle_s { uint16_t idx; } bgfx_indirect_buffer_handle_t; + +typedef struct bgfx_occlusion_query_handle_s { uint16_t idx; } bgfx_occlusion_query_handle_t; + +typedef struct bgfx_program_handle_s { uint16_t idx; } bgfx_program_handle_t; + +typedef struct bgfx_shader_handle_s { uint16_t idx; } bgfx_shader_handle_t; + +typedef struct bgfx_texture_handle_s { uint16_t idx; } bgfx_texture_handle_t; + +typedef struct bgfx_uniform_handle_s { uint16_t idx; } bgfx_uniform_handle_t; + +typedef struct bgfx_vertex_buffer_handle_s { uint16_t idx; } bgfx_vertex_buffer_handle_t; + +typedef struct bgfx_vertex_layout_handle_s { uint16_t idx; } bgfx_vertex_layout_handle_t; + + +#define BGFX_HANDLE_IS_VALID(h) ((h).idx != UINT16_MAX) + +/** + * Memory release callback. + * + * @param[in] _ptr Pointer to allocated data. + * @param[in] _userData User defined data if needed. + * + */ +typedef void (*bgfx_release_fn_t)(void* _ptr, void* _userData); + +/** + * GPU info. + * + */ +typedef struct bgfx_caps_gpu_s +{ + uint16_t vendorId; /** Vendor PCI id. See `BGFX_PCI_ID_*`. */ + uint16_t deviceId; /** Device id. */ + +} bgfx_caps_gpu_t; + +/** + * Renderer runtime limits. + * + */ +typedef struct bgfx_caps_limits_s +{ + uint32_t maxDrawCalls; /** Maximum number of draw calls. */ + uint32_t maxBlits; /** Maximum number of blit calls. */ + uint32_t maxTextureSize; /** Maximum texture size. */ + uint32_t maxTextureLayers; /** Maximum texture layers. */ + uint32_t maxViews; /** Maximum number of views. */ + uint32_t maxFrameBuffers; /** Maximum number of frame buffer handles. */ + uint32_t maxFBAttachments; /** Maximum number of frame buffer attachments. */ + uint32_t maxPrograms; /** Maximum number of program handles. */ + uint32_t maxShaders; /** Maximum number of shader handles. */ + uint32_t maxTextures; /** Maximum number of texture handles. */ + uint32_t maxTextureSamplers; /** Maximum number of texture samplers. */ + uint32_t maxComputeBindings; /** Maximum number of compute bindings. */ + uint32_t maxVertexLayouts; /** Maximum number of vertex format layouts. */ + uint32_t maxVertexStreams; /** Maximum number of vertex streams. */ + uint32_t maxIndexBuffers; /** Maximum number of index buffer handles. */ + uint32_t maxVertexBuffers; /** Maximum number of vertex buffer handles. */ + uint32_t maxDynamicIndexBuffers; /** Maximum number of dynamic index buffer handles. */ + uint32_t maxDynamicVertexBuffers; /** Maximum number of dynamic vertex buffer handles. */ + uint32_t maxUniforms; /** Maximum number of uniform handles. */ + uint32_t maxOcclusionQueries; /** Maximum number of occlusion query handles. */ + uint32_t maxEncoders; /** Maximum number of encoder threads. */ + uint32_t minResourceCbSize; /** Minimum resource command buffer size. */ + uint32_t transientVbSize; /** Maximum transient vertex buffer size. */ + uint32_t transientIbSize; /** Maximum transient index buffer size. */ + +} bgfx_caps_limits_t; + +/** + * Renderer capabilities. + * + */ +typedef struct bgfx_caps_s +{ + bgfx_renderer_type_t rendererType; /** Renderer backend type. See: `bgfx::RendererType` */ + + /** + * Supported functionality. + * @attention See `BGFX_CAPS_*` flags at https://bkaradzic.github.io/bgfx/bgfx.html#available-caps + */ + uint64_t supported; + uint16_t vendorId; /** Selected GPU vendor PCI id. */ + uint16_t deviceId; /** Selected GPU device id. */ + bool homogeneousDepth; /** True when NDC depth is in [-1, 1] range, otherwise its [0, 1]. */ + bool originBottomLeft; /** True when NDC origin is at bottom left. */ + uint8_t numGPUs; /** Number of enumerated GPUs. */ + bgfx_caps_gpu_t gpu[4]; /** Enumerated GPUs. */ + bgfx_caps_limits_t limits; /** Renderer runtime limits. */ + + /** + * Supported texture format capabilities flags: + * - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - Texture format is not supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_2D` - Texture format is supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB` - Texture as sRGB format is supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED` - Texture format is emulated. + * - `BGFX_CAPS_FORMAT_TEXTURE_3D` - Texture format is supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB` - Texture as sRGB format is supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED` - Texture format is emulated. + * - `BGFX_CAPS_FORMAT_TEXTURE_CUBE` - Texture format is supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB` - Texture as sRGB format is supported. + * - `BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED` - Texture format is emulated. + * - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - Texture format can be used from vertex shader. + * - `BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ` - Texture format can be used as image + * and read from. + * - `BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE` - Texture format can be used as image + * and written to. + * - `BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER` - Texture format can be used as frame + * buffer. + * - `BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA` - Texture format can be used as MSAA + * frame buffer. + * - `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA. + * - `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated + * mips. + */ + uint16_t formats[BGFX_TEXTURE_FORMAT_COUNT]; + +} bgfx_caps_t; + +/** + * Internal data. + * + */ +typedef struct bgfx_internal_data_s +{ + const bgfx_caps_t* caps; /** Renderer capabilities. */ + void* context; /** GL context, or D3D device. */ + +} bgfx_internal_data_t; + +/** + * Platform data. + * + */ +typedef struct bgfx_platform_data_s +{ + void* ndt; /** Native display type (*nix specific). */ + + /** + * Native window handle. If `NULL` bgfx will create headless + * context/device if renderer API supports it. + */ + void* nwh; + void* context; /** GL context, or D3D device. If `NULL`, bgfx will create context/device. */ + + /** + * GL back-buffer, or D3D render target view. If `NULL` bgfx will + * create back-buffer color surface. + */ + void* backBuffer; + + /** + * Backbuffer depth/stencil. If `NULL` bgfx will create back-buffer + * depth/stencil surface. + */ + void* backBufferDS; + +} bgfx_platform_data_t; + +/** + * Backbuffer resolution and reset parameters. + * + */ +typedef struct bgfx_resolution_s +{ + bgfx_texture_format_t format; /** Backbuffer format. */ + uint32_t width; /** Backbuffer width. */ + uint32_t height; /** Backbuffer height. */ + uint32_t reset; /** Reset parameters. */ + uint8_t numBackBuffers; /** Number of back buffers. */ + uint8_t maxFrameLatency; /** Maximum frame latency. */ + +} bgfx_resolution_t; + +/** + * Configurable runtime limits parameters. + * + */ +typedef struct bgfx_init_limits_s +{ + uint16_t maxEncoders; /** Maximum number of encoder threads. */ + uint32_t minResourceCbSize; /** Minimum resource command buffer size. */ + uint32_t transientVbSize; /** Maximum transient vertex buffer size. */ + uint32_t transientIbSize; /** Maximum transient index buffer size. */ + +} bgfx_init_limits_t; + +/** + * Initialization parameters used by `bgfx::init`. + * + */ +typedef struct bgfx_init_s +{ + + /** + * Select rendering backend. When set to RendererType::Count + * a default rendering backend will be selected appropriate to the platform. + * See: `bgfx::RendererType` + */ + bgfx_renderer_type_t type; + + /** + * Vendor PCI id. If set to `BGFX_PCI_ID_NONE` it will select the first + * device. + * - `BGFX_PCI_ID_NONE` - Autoselect adapter. + * - `BGFX_PCI_ID_SOFTWARE_RASTERIZER` - Software rasterizer. + * - `BGFX_PCI_ID_AMD` - AMD adapter. + * - `BGFX_PCI_ID_INTEL` - Intel adapter. + * - `BGFX_PCI_ID_NVIDIA` - nVidia adapter. + */ + uint16_t vendorId; + + /** + * Device id. If set to 0 it will select first device, or device with + * matching id. + */ + uint16_t deviceId; + uint64_t capabilities; /** Capabilities initialization mask (default: UINT64_MAX). */ + bool debug; /** Enable device for debuging. */ + bool profile; /** Enable device for profiling. */ + bgfx_platform_data_t platformData; /** Platform data. */ + bgfx_resolution_t resolution; /** Backbuffer resolution and reset parameters. See: `bgfx::Resolution`. */ + bgfx_init_limits_t limits; /** Configurable runtime limits parameters. */ + + /** + * Provide application specific callback interface. + * See: `bgfx::CallbackI` + */ + bgfx_callback_interface_t* callback; + + /** + * Custom allocator. When a custom allocator is not + * specified, bgfx uses the CRT allocator. Bgfx assumes + * custom allocator is thread safe. + */ + bgfx_allocator_interface_t* allocator; + +} bgfx_init_t; + +/** + * Memory must be obtained by calling `bgfx::alloc`, `bgfx::copy`, or `bgfx::makeRef`. + * @attention It is illegal to create this structure on stack and pass it to any bgfx API. + * + */ +typedef struct bgfx_memory_s +{ + uint8_t* data; /** Pointer to data. */ + uint32_t size; /** Data size. */ + +} bgfx_memory_t; + +/** + * Transient index buffer. + * + */ +typedef struct bgfx_transient_index_buffer_s +{ + uint8_t* data; /** Pointer to data. */ + uint32_t size; /** Data size. */ + uint32_t startIndex; /** First index. */ + bgfx_index_buffer_handle_t handle; /** Index buffer handle. */ + bool isIndex16; /** Index buffer format is 16-bits if true, otherwise it is 32-bit. */ + +} bgfx_transient_index_buffer_t; + +/** + * Transient vertex buffer. + * + */ +typedef struct bgfx_transient_vertex_buffer_s +{ + uint8_t* data; /** Pointer to data. */ + uint32_t size; /** Data size. */ + uint32_t startVertex; /** First vertex. */ + uint16_t stride; /** Vertex stride. */ + bgfx_vertex_buffer_handle_t handle; /** Vertex buffer handle. */ + bgfx_vertex_layout_handle_t layoutHandle; /** Vertex layout handle. */ + +} bgfx_transient_vertex_buffer_t; + +/** + * Instance data buffer info. + * + */ +typedef struct bgfx_instance_data_buffer_s +{ + uint8_t* data; /** Pointer to data. */ + uint32_t size; /** Data size. */ + uint32_t offset; /** Offset in vertex buffer. */ + uint32_t num; /** Number of instances. */ + uint16_t stride; /** Vertex buffer stride. */ + bgfx_vertex_buffer_handle_t handle; /** Vertex buffer object handle. */ + +} bgfx_instance_data_buffer_t; + +/** + * Texture info. + * + */ +typedef struct bgfx_texture_info_s +{ + bgfx_texture_format_t format; /** Texture format. */ + uint32_t storageSize; /** Total amount of bytes required to store texture. */ + uint16_t width; /** Texture width. */ + uint16_t height; /** Texture height. */ + uint16_t depth; /** Texture depth. */ + uint16_t numLayers; /** Number of layers in texture array. */ + uint8_t numMips; /** Number of MIP maps. */ + uint8_t bitsPerPixel; /** Format bits per pixel. */ + bool cubeMap; /** Texture is cubemap. */ + +} bgfx_texture_info_t; + +/** + * Uniform info. + * + */ +typedef struct bgfx_uniform_info_s +{ + char name[256]; /** Uniform name. */ + bgfx_uniform_type_t type; /** Uniform type. */ + uint16_t num; /** Number of elements in array. */ + +} bgfx_uniform_info_t; + +/** + * Frame buffer texture attachment info. + * + */ +typedef struct bgfx_attachment_s +{ + bgfx_access_t access; /** Attachment access. See `Access::Enum`. */ + bgfx_texture_handle_t handle; /** Render target texture handle. */ + uint16_t mip; /** Mip level. */ + uint16_t layer; /** Cubemap side or depth layer/slice to use. */ + uint16_t numLayers; /** Number of texture layer/slice(s) in array to use. */ + uint8_t resolve; /** Resolve flags. See: `BGFX_RESOLVE_*` */ + +} bgfx_attachment_t; + +/** + * Transform data. + * + */ +typedef struct bgfx_transform_s +{ + float* data; /** Pointer to first 4x4 matrix. */ + uint16_t num; /** Number of matrices. */ + +} bgfx_transform_t; + +/** + * View stats. + * + */ +typedef struct bgfx_view_stats_s +{ + char name[256]; /** View name. */ + bgfx_view_id_t view; /** View id. */ + int64_t cpuTimeBegin; /** CPU (submit) begin time. */ + int64_t cpuTimeEnd; /** CPU (submit) end time. */ + int64_t gpuTimeBegin; /** GPU begin time. */ + int64_t gpuTimeEnd; /** GPU end time. */ + +} bgfx_view_stats_t; + +/** + * Encoder stats. + * + */ +typedef struct bgfx_encoder_stats_s +{ + int64_t cpuTimeBegin; /** Encoder thread CPU submit begin time. */ + int64_t cpuTimeEnd; /** Encoder thread CPU submit end time. */ + +} bgfx_encoder_stats_t; -#include // va_list -#include // uint32_t -#include // NULL +/** + * Renderer statistics data. + * @remarks All time values are high-resolution timestamps, while + * time frequencies define timestamps-per-second for that hardware. + * + */ +typedef struct bgfx_stats_s +{ + int64_t cpuTimeFrame; /** CPU time between two `bgfx::frame` calls. */ + int64_t cpuTimeBegin; /** Render thread CPU submit begin time. */ + int64_t cpuTimeEnd; /** Render thread CPU submit end time. */ + int64_t cpuTimerFreq; /** CPU timer frequency. Timestamps-per-second */ + int64_t gpuTimeBegin; /** GPU frame begin time. */ + int64_t gpuTimeEnd; /** GPU frame end time. */ + int64_t gpuTimerFreq; /** GPU timer frequency. */ + int64_t waitRender; /** Time spent waiting for render backend thread to finish issuing draw commands to underlying graphics API. */ + int64_t waitSubmit; /** Time spent waiting for submit thread to advance to next frame. */ + uint32_t numDraw; /** Number of draw calls submitted. */ + uint32_t numCompute; /** Number of compute calls submitted. */ + uint32_t numBlit; /** Number of blit calls submitted. */ + uint32_t maxGpuLatency; /** GPU driver latency. */ + uint16_t numDynamicIndexBuffers; /** Number of used dynamic index buffers. */ + uint16_t numDynamicVertexBuffers; /** Number of used dynamic vertex buffers. */ + uint16_t numFrameBuffers; /** Number of used frame buffers. */ + uint16_t numIndexBuffers; /** Number of used index buffers. */ + uint16_t numOcclusionQueries; /** Number of used occlusion queries. */ + uint16_t numPrograms; /** Number of used programs. */ + uint16_t numShaders; /** Number of used shaders. */ + uint16_t numTextures; /** Number of used textures. */ + uint16_t numUniforms; /** Number of used uniforms. */ + uint16_t numVertexBuffers; /** Number of used vertex buffers. */ + uint16_t numVertexLayouts; /** Number of used vertex layouts. */ + int64_t textureMemoryUsed; /** Estimate of texture memory used. */ + int64_t rtMemoryUsed; /** Estimate of render target memory used. */ + int32_t transientVbUsed; /** Amount of transient vertex buffer used. */ + int32_t transientIbUsed; /** Amount of transient index buffer used. */ + uint32_t numPrims[BGFX_TOPOLOGY_COUNT]; /** Number of primitives rendered. */ + int64_t gpuMemoryMax; /** Maximum available GPU memory for application. */ + int64_t gpuMemoryUsed; /** Amount of GPU memory used by the application. */ + uint16_t width; /** Backbuffer width in pixels. */ + uint16_t height; /** Backbuffer height in pixels. */ + uint16_t textWidth; /** Debug text width in characters. */ + uint16_t textHeight; /** Debug text height in characters. */ + uint16_t numViews; /** Number of view stats. */ + bgfx_view_stats_t* viewStats; /** Array of View stats. */ + uint8_t numEncoders; /** Number of encoders used during frame. */ + bgfx_encoder_stats_t* encoderStats; /** Array of encoder stats. */ + +} bgfx_stats_t; + +/** + * Vertex layout. + * + */ +typedef struct bgfx_vertex_layout_s +{ + uint32_t hash; /** Hash. */ + uint16_t stride; /** Stride. */ + uint16_t offset[BGFX_ATTRIB_COUNT]; /** Attribute offsets. */ + uint16_t attributes[BGFX_ATTRIB_COUNT]; /** Used attributes. */ -#include +} bgfx_vertex_layout_t; -/// -#define BGFX_HANDLE(_name) \ - struct _name { uint16_t idx; }; \ - inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; } +/** + * Encoders are used for submitting draw calls from multiple threads. Only one encoder + * per thread should be used. Use `bgfx::begin()` to obtain an encoder for a thread. + * + */ +struct bgfx_encoder_s; +typedef struct bgfx_encoder_s bgfx_encoder_t; -#define BGFX_INVALID_HANDLE { bgfx::invalidHandle } -namespace bx { struct AllocatorI; } -/// BGFX -namespace bgfx +/** + * Init attachment. + * + * @param[in] _handle Render target texture handle. + * @param[in] _access Access. See `Access::Enum`. + * @param[in] _layer Cubemap side or depth layer/slice to use. + * @param[in] _numLayers Number of texture layer/slice(s) in array to use. + * @param[in] _mip Mip level. + * @param[in] _resolve Resolve flags. See: `BGFX_RESOLVE_*` + * + */ +BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve); + +/** + * Start VertexLayout. + * + * @param[in] _rendererType Renderer backend type. See: `bgfx::RendererType` + * + * @returns Returns itself. + * + */ +BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_begin(bgfx_vertex_layout_t* _this, bgfx_renderer_type_t _rendererType); + +/** + * Add attribute to VertexLayout. + * @remarks Must be called between begin/end. + * + * @param[in] _attrib Attribute semantics. See: `bgfx::Attrib` + * @param[in] _num Number of elements 1, 2, 3 or 4. + * @param[in] _type Element type. + * @param[in] _normalized When using fixed point AttribType (f.e. Uint8) + * value will be normalized for vertex shader usage. When normalized + * is set to true, AttribType::Uint8 value in range 0-255 will be + * in range 0.0-1.0 in vertex shader. + * @param[in] _asInt Packaging rule for vertexPack, vertexUnpack, and + * vertexConvert for AttribType::Uint8 and AttribType::Int16. + * Unpacking code must be implemented inside vertex shader. + * + * @returns Returns itself. + * + */ +BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_add(bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); + +/** + * Decode attribute. + * + * @param[in] _attrib Attribute semantics. See: `bgfx::Attrib` + * @param[out] _num Number of elements. + * @param[out] _type Element type. + * @param[out] _normalized Attribute is normalized. + * @param[out] _asInt Attribute is packed as int. + * + */ +BGFX_C_API void bgfx_vertex_layout_decode(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t * _num, bgfx_attrib_type_t * _type, bool * _normalized, bool * _asInt); + +/** + * Returns `true` if VertexLayout contains attribute. + * + * @param[in] _attrib Attribute semantics. See: `bgfx::Attrib` + * + * @returns True if VertexLayout contains attribute. + * + */ +BGFX_C_API bool bgfx_vertex_layout_has(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib); + +/** + * Skip `_num` bytes in vertex stream. + * + * @param[in] _num Number of bytes to skip. + * + * @returns Returns itself. + * + */ +BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_skip(bgfx_vertex_layout_t* _this, uint8_t _num); + +/** + * End VertexLayout. + * + */ +BGFX_C_API void bgfx_vertex_layout_end(bgfx_vertex_layout_t* _this); + +/** + * Pack vertex attribute into vertex stream format. + * + * @param[in] _input Value to be packed into vertex stream. + * @param[in] _inputNormalized `true` if input value is already normalized. + * @param[in] _attr Attribute to pack. + * @param[in] _layout Vertex stream layout. + * @param[in] _data Destination vertex stream where data will be packed. + * @param[in] _index Vertex index that will be modified. + * + */ +BGFX_C_API void bgfx_vertex_pack(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, void* _data, uint32_t _index); + +/** + * Unpack vertex attribute from vertex stream format. + * + * @param[out] _output Result of unpacking. + * @param[in] _attr Attribute to unpack. + * @param[in] _layout Vertex stream layout. + * @param[in] _data Source vertex stream from where data will be unpacked. + * @param[in] _index Vertex index that will be unpacked. + * + */ +BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _index); + +/** + * Converts vertex stream data from one vertex stream format to another. + * + * @param[in] _dstLayout Destination vertex stream layout. + * @param[in] _dstData Destination vertex stream. + * @param[in] _srcLayout Source vertex stream layout. + * @param[in] _srcData Source vertex stream data. + * @param[in] _num Number of vertices to convert from source to destination. + * + */ +BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_layout_t * _dstLayout, void* _dstData, const bgfx_vertex_layout_t * _srcLayout, const void* _srcData, uint32_t _num); + +/** + * Weld vertices. + * + * @param[in] _output Welded vertices remapping table. The size of buffer + * must be the same as number of vertices. + * @param[in] _layout Vertex stream layout. + * @param[in] _data Vertex stream. + * @param[in] _num Number of vertices in vertex stream. + * @param[in] _index32 Set to `true` if input indices are 32-bit. + * @param[in] _epsilon Error tolerance for vertex position comparison. + * + * @returns Number of unique vertices after vertex welding. + * + */ +BGFX_C_API uint32_t bgfx_weld_vertices(void* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon); + +/** + * Convert index buffer for use with different primitive topologies. + * + * @param[in] _conversion Conversion type, see `TopologyConvert::Enum`. + * @param[out] _dst Destination index buffer. If this argument is NULL + * function will return number of indices after conversion. + * @param[in] _dstSize Destination index buffer in bytes. It must be + * large enough to contain output indices. If destination size is + * insufficient index buffer will be truncated. + * @param[in] _indices Source indices. + * @param[in] _numIndices Number of input indices. + * @param[in] _index32 Set to `true` if input indices are 32-bit. + * + * @returns Number of output indices after conversion. + * + */ +BGFX_C_API uint32_t bgfx_topology_convert(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32); + +/** + * Sort indices. + * + * @param[in] _sort Sort order, see `TopologySort::Enum`. + * @param[out] _dst Destination index buffer. + * @param[in] _dstSize Destination index buffer in bytes. It must be + * large enough to contain output indices. If destination size is + * insufficient index buffer will be truncated. + * @param[in] _dir Direction (vector must be normalized). + * @param[in] _pos Position. + * @param[in] _vertices Pointer to first vertex represented as + * float x, y, z. Must contain at least number of vertices + * referencende by index buffer. + * @param[in] _stride Vertex stride. + * @param[in] _indices Source indices. + * @param[in] _numIndices Number of input indices. + * @param[in] _index32 Set to `true` if input indices are 32-bit. + * + */ +BGFX_C_API void bgfx_topology_sort_tri_list(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32); + +/** + * Returns supported backend API renderers. + * + * @param[in] _max Maximum number of elements in _enum array. + * @param[inout] _enum Array where supported renderers will be written. + * + * @returns Number of supported renderers. + * + */ +BGFX_C_API uint8_t bgfx_get_supported_renderers(uint8_t _max, bgfx_renderer_type_t* _enum); + +/** + * Returns name of renderer. + * + * @param[in] _type Renderer backend type. See: `bgfx::RendererType` + * + * @returns Name of renderer. + * + */ +BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type); +BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init); + +/** + * Initialize bgfx library. + * + * @param[in] _init Initialization parameters. See: `bgfx::Init` for more info. + * + * @returns `true` if initialization was successful. + * + */ +BGFX_C_API bool bgfx_init(const bgfx_init_t * _init); + +/** + * Shutdown bgfx library. + * + */ +BGFX_C_API void bgfx_shutdown(void); + +/** + * Reset graphic settings and back-buffer size. + * @attention This call doesn't actually change window size, it just + * resizes back-buffer. Windowing code has to change window size. + * + * @param[in] _width Back-buffer width. + * @param[in] _height Back-buffer height. + * @param[in] _flags See: `BGFX_RESET_*` for more info. + * - `BGFX_RESET_NONE` - No reset flags. + * - `BGFX_RESET_FULLSCREEN` - Not supported yet. + * - `BGFX_RESET_MSAA_X[2/4/8/16]` - Enable 2, 4, 8 or 16 x MSAA. + * - `BGFX_RESET_VSYNC` - Enable V-Sync. + * - `BGFX_RESET_MAXANISOTROPY` - Turn on/off max anisotropy. + * - `BGFX_RESET_CAPTURE` - Begin screen capture. + * - `BGFX_RESET_FLUSH_AFTER_RENDER` - Flush rendering after submitting to GPU. + * - `BGFX_RESET_FLIP_AFTER_RENDER` - This flag specifies where flip + * occurs. Default behaviour is that flip occurs before rendering new + * frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`. + * - `BGFX_RESET_SRGB_BACKBUFFER` - Enable sRGB backbuffer. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * + */ +BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags, bgfx_texture_format_t _format); + +/** + * Advance to next frame. When using multithreaded renderer, this call + * just swaps internal buffers, kicks render thread, and returns. In + * singlethreaded renderer this call does frame rendering. + * + * @param[in] _capture Capture frame with graphics debugger. + * + * @returns Current frame number. This might be used in conjunction with + * double/multi buffering data outside the library and passing it to + * library via `bgfx::makeRef` calls. + * + */ +BGFX_C_API uint32_t bgfx_frame(bool _capture); + +/** + * Returns current renderer backend API type. + * @remarks + * Library must be initialized. + * + */ +BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type(void); + +/** + * Returns renderer capabilities. + * @remarks + * Library must be initialized. + * + */ +BGFX_C_API const bgfx_caps_t* bgfx_get_caps(void); + +/** + * Returns performance counters. + * @attention Pointer returned is valid until `bgfx::frame` is called. + * + */ +BGFX_C_API const bgfx_stats_t* bgfx_get_stats(void); + +/** + * Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx. + * + * @param[in] _size Size to allocate. + * + * @returns Allocated memory. + * + */ +BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size); + +/** + * Allocate buffer and copy data into it. Data will be freed inside bgfx. + * + * @param[in] _data Pointer to data to be copied. + * @param[in] _size Size of data to be copied. + * + * @returns Allocated memory. + * + */ +BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size); + +/** + * Make reference to data to pass to bgfx. Unlike `bgfx::alloc`, this call + * doesn't allocate memory for data. It just copies the _data pointer. You + * can pass `ReleaseFn` function pointer to release this memory after it's + * consumed, otherwise you must make sure _data is available for at least 2 + * `bgfx::frame` calls. `ReleaseFn` function must be able to be called + * from any thread. + * @attention Data passed must be available for at least 2 `bgfx::frame` calls. + * + * @param[in] _data Pointer to data. + * @param[in] _size Size of data. + * + * @returns Referenced memory. + * + */ +BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size); + +/** + * Make reference to data to pass to bgfx. Unlike `bgfx::alloc`, this call + * doesn't allocate memory for data. It just copies the _data pointer. You + * can pass `ReleaseFn` function pointer to release this memory after it's + * consumed, otherwise you must make sure _data is available for at least 2 + * `bgfx::frame` calls. `ReleaseFn` function must be able to be called + * from any thread. + * @attention Data passed must be available for at least 2 `bgfx::frame` calls. + * + * @param[in] _data Pointer to data. + * @param[in] _size Size of data. + * @param[in] _releaseFn Callback function to release memory after use. + * @param[in] _userData User data to be passed to callback function. + * + * @returns Referenced memory. + * + */ +BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData); + +/** + * Set debug flags. + * + * @param[in] _debug Available flags: + * - `BGFX_DEBUG_IFH` - Infinitely fast hardware. When this flag is set + * all rendering calls will be skipped. This is useful when profiling + * to quickly assess potential bottlenecks between CPU and GPU. + * - `BGFX_DEBUG_PROFILER` - Enable profiler. + * - `BGFX_DEBUG_STATS` - Display internal statistics. + * - `BGFX_DEBUG_TEXT` - Display debug text. + * - `BGFX_DEBUG_WIREFRAME` - Wireframe rendering. All rendering + * primitives will be rendered as lines. + * + */ +BGFX_C_API void bgfx_set_debug(uint32_t _debug); + +/** + * Clear internal debug text buffer. + * + * @param[in] _attr Background color. + * @param[in] _small Default 8x16 or 8x8 font. + * + */ +BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small); + +/** + * Print formatted data to internal debug text character-buffer (VGA-compatible text mode). + * + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _attr Color palette. Where top 4-bits represent index of background, and bottom + * 4-bits represent foreground color from standard VGA text palette (ANSI escape codes). + * @param[in] _format `printf` style format. + * @param[in] + * + */ +BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ... ); + +/** + * Print formatted data from variable argument list to internal debug text character-buffer (VGA-compatible text mode). + * + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _attr Color palette. Where top 4-bits represent index of background, and bottom + * 4-bits represent foreground color from standard VGA text palette (ANSI escape codes). + * @param[in] _format `printf` style format. + * @param[in] _argList Variable arguments list for format string. + * + */ +BGFX_C_API void bgfx_dbg_text_vprintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList); + +/** + * Draw image into internal debug text buffer. + * + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _width Image width. + * @param[in] _height Image height. + * @param[in] _data Raw image data (character/attribute raw encoding). + * @param[in] _pitch Image pitch in bytes. + * + */ +BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch); + +/** + * Create static index buffer. + * + * @param[in] _mem Index buffer data. + * @param[in] _flags Buffer creation flags. + * - `BGFX_BUFFER_NONE` - No flags. + * - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. + * - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer + * is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. + * - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. + * - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if a different amount of + * data is passed. If this flag is not specified, and more data is passed on update, the buffer + * will be trimmed to fit the existing buffer size. This flag has effect only on dynamic + * buffers. + * - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on + * index buffers. + * + */ +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags); + +/** + * Set static index buffer debug name. + * + * @param[in] _handle Static index buffer handle. + * @param[in] _name Static index buffer name. + * @param[in] _len Static index buffer name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. + * + */ +BGFX_C_API void bgfx_set_index_buffer_name(bgfx_index_buffer_handle_t _handle, const char* _name, int32_t _len); + +/** + * Destroy static index buffer. + * + * @param[in] _handle Static index buffer handle. + * + */ +BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle); + +/** + * Create vertex layout. + * + * @param[in] _layout Vertex layout. + * + */ +BGFX_C_API bgfx_vertex_layout_handle_t bgfx_create_vertex_layout(const bgfx_vertex_layout_t * _layout); + +/** + * Destroy vertex layout. + * + * @param[in] _layoutHandle Vertex layout handle. + * + */ +BGFX_C_API void bgfx_destroy_vertex_layout(bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Create static vertex buffer. + * + * @param[in] _mem Vertex buffer data. + * @param[in] _layout Vertex layout. + * @param[in] _flags Buffer creation flags. + * - `BGFX_BUFFER_NONE` - No flags. + * - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. + * - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer + * is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. + * - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. + * - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if a different amount of + * data is passed. If this flag is not specified, and more data is passed on update, the buffer + * will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers. + * - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on index buffers. + * + * @returns Static vertex buffer handle. + * + */ +BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_layout_t * _layout, uint16_t _flags); + +/** + * Set static vertex buffer debug name. + * + * @param[in] _handle Static vertex buffer handle. + * @param[in] _name Static vertex buffer name. + * @param[in] _len Static vertex buffer name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. + * + */ +BGFX_C_API void bgfx_set_vertex_buffer_name(bgfx_vertex_buffer_handle_t _handle, const char* _name, int32_t _len); + +/** + * Destroy static vertex buffer. + * + * @param[in] _handle Static vertex buffer handle. + * + */ +BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle); + +/** + * Create empty dynamic index buffer. + * + * @param[in] _num Number of indices. + * @param[in] _flags Buffer creation flags. + * - `BGFX_BUFFER_NONE` - No flags. + * - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. + * - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer + * is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. + * - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. + * - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if a different amount of + * data is passed. If this flag is not specified, and more data is passed on update, the buffer + * will be trimmed to fit the existing buffer size. This flag has effect only on dynamic + * buffers. + * - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on + * index buffers. + * + * @returns Dynamic index buffer handle. + * + */ +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags); + +/** + * Create dynamic index buffer and initialized it. + * + * @param[in] _mem Index buffer data. + * @param[in] _flags Buffer creation flags. + * - `BGFX_BUFFER_NONE` - No flags. + * - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. + * - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer + * is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. + * - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. + * - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if a different amount of + * data is passed. If this flag is not specified, and more data is passed on update, the buffer + * will be trimmed to fit the existing buffer size. This flag has effect only on dynamic + * buffers. + * - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on + * index buffers. + * + * @returns Dynamic index buffer handle. + * + */ +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags); + +/** + * Update dynamic index buffer. + * + * @param[in] _handle Dynamic index buffer handle. + * @param[in] _startIndex Start index. + * @param[in] _mem Index buffer data. + * + */ +BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem); + +/** + * Destroy dynamic index buffer. + * + * @param[in] _handle Dynamic index buffer handle. + * + */ +BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle); + +/** + * Create empty dynamic vertex buffer. + * + * @param[in] _num Number of vertices. + * @param[in] _layout Vertex layout. + * @param[in] _flags Buffer creation flags. + * - `BGFX_BUFFER_NONE` - No flags. + * - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. + * - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer + * is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. + * - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. + * - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if a different amount of + * data is passed. If this flag is not specified, and more data is passed on update, the buffer + * will be trimmed to fit the existing buffer size. This flag has effect only on dynamic + * buffers. + * - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on + * index buffers. + * + * @returns Dynamic vertex buffer handle. + * + */ +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_layout_t* _layout, uint16_t _flags); + +/** + * Create dynamic vertex buffer and initialize it. + * + * @param[in] _mem Vertex buffer data. + * @param[in] _layout Vertex layout. + * @param[in] _flags Buffer creation flags. + * - `BGFX_BUFFER_NONE` - No flags. + * - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. + * - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer + * is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. + * - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. + * - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if a different amount of + * data is passed. If this flag is not specified, and more data is passed on update, the buffer + * will be trimmed to fit the existing buffer size. This flag has effect only on dynamic + * buffers. + * - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on + * index buffers. + * + * @returns Dynamic vertex buffer handle. + * + */ +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_layout_t* _layout, uint16_t _flags); + +/** + * Update dynamic vertex buffer. + * + * @param[in] _handle Dynamic vertex buffer handle. + * @param[in] _startVertex Start vertex. + * @param[in] _mem Vertex buffer data. + * + */ +BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem); + +/** + * Destroy dynamic vertex buffer. + * + * @param[in] _handle Dynamic vertex buffer handle. + * + */ +BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle); + +/** + * Returns number of requested or maximum available indices. + * + * @param[in] _num Number of required indices. + * @param[in] _index32 Set to `true` if input indices will be 32-bit. + * + * @returns Number of requested or maximum available indices. + * + */ +BGFX_C_API uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num, bool _index32); + +/** + * Returns number of requested or maximum available vertices. + * + * @param[in] _num Number of required vertices. + * @param[in] _layout Vertex layout. + * + * @returns Number of requested or maximum available vertices. + * + */ +BGFX_C_API uint32_t bgfx_get_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_layout_t * _layout); + +/** + * Returns number of requested or maximum available instance buffer slots. + * + * @param[in] _num Number of required instances. + * @param[in] _stride Stride per instance. + * + * @returns Number of requested or maximum available instance buffer slots. + * + */ +BGFX_C_API uint32_t bgfx_get_avail_instance_data_buffer(uint32_t _num, uint16_t _stride); + +/** + * Allocate transient index buffer. + * + * @param[out] _tib TransientIndexBuffer structure is filled and is valid + * for the duration of frame, and it can be reused for multiple draw + * calls. + * @param[in] _num Number of indices to allocate. + * @param[in] _index32 Set to `true` if input indices will be 32-bit. + * + */ +BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num, bool _index32); + +/** + * Allocate transient vertex buffer. + * + * @param[out] _tvb TransientVertexBuffer structure is filled and is valid + * for the duration of frame, and it can be reused for multiple draw + * calls. + * @param[in] _num Number of vertices to allocate. + * @param[in] _layout Vertex layout. + * + */ +BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_layout_t * _layout); + +/** + * Check for required space and allocate transient vertex and index + * buffers. If both space requirements are satisfied function returns + * true. + * + * @param[out] _tvb TransientVertexBuffer structure is filled and is valid + * for the duration of frame, and it can be reused for multiple draw + * calls. + * @param[in] _layout Vertex layout. + * @param[in] _numVertices Number of vertices to allocate. + * @param[out] _tib TransientIndexBuffer structure is filled and is valid + * for the duration of frame, and it can be reused for multiple draw + * calls. + * @param[in] _numIndices Number of indices to allocate. + * @param[in] _index32 Set to `true` if input indices will be 32-bit. + * + */ +BGFX_C_API bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_layout_t * _layout, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices, bool _index32); + +/** + * Allocate instance data buffer. + * + * @param[out] _idb InstanceDataBuffer structure is filled and is valid + * for duration of frame, and it can be reused for multiple draw + * calls. + * @param[in] _num Number of instances. + * @param[in] _stride Instance stride. Must be multiple of 16. + * + */ +BGFX_C_API void bgfx_alloc_instance_data_buffer(bgfx_instance_data_buffer_t* _idb, uint32_t _num, uint16_t _stride); + +/** + * Create draw indirect buffer. + * + * @param[in] _num Number of indirect calls. + * + * @returns Indirect buffer handle. + * + */ +BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num); + +/** + * Destroy draw indirect buffer. + * + * @param[in] _handle Indirect buffer handle. + * + */ +BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle); + +/** + * Create shader from memory buffer. + * + * @param[in] _mem Shader binary. + * + * @returns Shader handle. + * + */ +BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem); + +/** + * Returns the number of uniforms and uniform handles used inside a shader. + * @remarks + * Only non-predefined uniforms are returned. + * + * @param[in] _handle Shader handle. + * @param[out] _uniforms UniformHandle array where data will be stored. + * @param[in] _max Maximum capacity of array. + * + * @returns Number of uniforms used by shader. + * + */ +BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max); + +/** + * Set shader debug name. + * + * @param[in] _handle Shader handle. + * @param[in] _name Shader name. + * @param[in] _len Shader name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string). + * + */ +BGFX_C_API void bgfx_set_shader_name(bgfx_shader_handle_t _handle, const char* _name, int32_t _len); + +/** + * Destroy shader. + * @remark Once a shader program is created with _handle, + * it is safe to destroy that shader. + * + * @param[in] _handle Shader handle. + * + */ +BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle); + +/** + * Create program with vertex and fragment shaders. + * + * @param[in] _vsh Vertex shader. + * @param[in] _fsh Fragment shader. + * @param[in] _destroyShaders If true, shaders will be destroyed when program is destroyed. + * + * @returns Program handle if vertex shader output and fragment shader + * input are matching, otherwise returns invalid program handle. + * + */ +BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders); + +/** + * Create program with compute shader. + * + * @param[in] _csh Compute shader. + * @param[in] _destroyShaders If true, shaders will be destroyed when program is destroyed. + * + * @returns Program handle. + * + */ +BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders); + +/** + * Destroy program. + * + * @param[in] _handle Program handle. + * + */ +BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle); + +/** + * Validate texture parameters. + * + * @param[in] _depth Depth dimension of volume texture. + * @param[in] _cubeMap Indicates that texture contains cubemap. + * @param[in] _numLayers Number of layers in texture array. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _flags Texture flags. See `BGFX_TEXTURE_*`. + * + * @returns True if texture can be successfully created. + * + */ +BGFX_C_API bool bgfx_is_texture_valid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags); + +/** + * Validate frame buffer parameters. + * + * @param[in] _num Number of attachments. + * @param[in] _attachment Attachment texture info. See: `bgfx::Attachment`. + * + * @returns True if frame buffer can be successfully created. + * + */ +BGFX_C_API bool bgfx_is_frame_buffer_valid(uint8_t _num, const bgfx_attachment_t* _attachment); + +/** + * Calculate amount of memory required for texture. + * + * @param[out] _info Resulting texture info structure. See: `TextureInfo`. + * @param[in] _width Width. + * @param[in] _height Height. + * @param[in] _depth Depth dimension of volume texture. + * @param[in] _cubeMap Indicates that texture contains cubemap. + * @param[in] _hasMips Indicates that texture contains full mip-map chain. + * @param[in] _numLayers Number of layers in texture array. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * + */ +BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t * _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format); + +/** + * Create texture from memory buffer. + * + * @param[in] _mem DDS, KTX or PVR texture binary data. + * @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * @param[in] _skip Skip top level mips when parsing texture. + * @param[out] _info When non-`NULL` is specified it returns parsed texture information. + * + * @returns Texture handle. + * + */ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint64_t _flags, uint8_t _skip, bgfx_texture_info_t* _info); + +/** + * Create 2D texture. + * + * @param[in] _width Width. + * @param[in] _height Height. + * @param[in] _hasMips Indicates that texture contains full mip-map chain. + * @param[in] _numLayers Number of layers in texture array. Must be 1 if caps + * `BGFX_CAPS_TEXTURE_2D_ARRAY` flag is not set. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * @param[in] _mem Texture data. If `_mem` is non-NULL, created texture will be immutable. If + * `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than + * 1, expected memory layout is texture and all mips together for each array element. + * + * @returns Texture handle. + * + */ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem); + +/** + * Create texture with size based on backbuffer ratio. Texture will maintain ratio + * if back buffer resolution changes. + * + * @param[in] _ratio Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`. + * @param[in] _hasMips Indicates that texture contains full mip-map chain. + * @param[in] _numLayers Number of layers in texture array. Must be 1 if caps + * `BGFX_CAPS_TEXTURE_2D_ARRAY` flag is not set. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * + * @returns Texture handle. + * + */ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags); + +/** + * Create 3D texture. + * + * @param[in] _width Width. + * @param[in] _height Height. + * @param[in] _depth Depth. + * @param[in] _hasMips Indicates that texture contains full mip-map chain. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * @param[in] _mem Texture data. If `_mem` is non-NULL, created texture will be immutable. If + * `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than + * 1, expected memory layout is texture and all mips together for each array element. + * + * @returns Texture handle. + * + */ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem); + +/** + * Create Cube texture. + * + * @param[in] _size Cube side size. + * @param[in] _hasMips Indicates that texture contains full mip-map chain. + * @param[in] _numLayers Number of layers in texture array. Must be 1 if caps + * `BGFX_CAPS_TEXTURE_2D_ARRAY` flag is not set. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * @param[in] _mem Texture data. If `_mem` is non-NULL, created texture will be immutable. If + * `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than + * 1, expected memory layout is texture and all mips together for each array element. + * + * @returns Texture handle. + * + */ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem); + +/** + * Update 2D texture. + * @attention It's valid to update only mutable texture. See `bgfx::createTexture2D` for more info. + * + * @param[in] _handle Texture handle. + * @param[in] _layer Layer in texture array. + * @param[in] _mip Mip level. + * @param[in] _x X offset in texture. + * @param[in] _y Y offset in texture. + * @param[in] _width Width of texture block. + * @param[in] _height Height of texture block. + * @param[in] _mem Texture update data. + * @param[in] _pitch Pitch of input image (bytes). When _pitch is set to + * UINT16_MAX, it will be calculated internally based on _width. + * + */ +BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); + +/** + * Update 3D texture. + * @attention It's valid to update only mutable texture. See `bgfx::createTexture3D` for more info. + * + * @param[in] _handle Texture handle. + * @param[in] _mip Mip level. + * @param[in] _x X offset in texture. + * @param[in] _y Y offset in texture. + * @param[in] _z Z offset in texture. + * @param[in] _width Width of texture block. + * @param[in] _height Height of texture block. + * @param[in] _depth Depth of texture block. + * @param[in] _mem Texture update data. + * + */ +BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem); + +/** + * Update Cube texture. + * @attention It's valid to update only mutable texture. See `bgfx::createTextureCube` for more info. + * + * @param[in] _handle Texture handle. + * @param[in] _layer Layer in texture array. + * @param[in] _side Cubemap side `BGFX_CUBE_MAP__`, + * where 0 is +X, 1 is -X, 2 is +Y, 3 is -Y, 4 is +Z, and 5 is -Z. + * +----------+ + * |-z 2| + * | ^ +y | + * | | | Unfolded cube: + * | +---->+x | + * +----------+----------+----------+----------+ + * |+y 1|+y 4|+y 0|+y 5| + * | ^ -x | ^ +z | ^ +x | ^ -z | + * | | | | | | | | | + * | +---->+z | +---->+x | +---->-z | +---->-x | + * +----------+----------+----------+----------+ + * |+z 3| + * | ^ -y | + * | | | + * | +---->+x | + * +----------+ + * @param[in] _mip Mip level. + * @param[in] _x X offset in texture. + * @param[in] _y Y offset in texture. + * @param[in] _width Width of texture block. + * @param[in] _height Height of texture block. + * @param[in] _mem Texture update data. + * @param[in] _pitch Pitch of input image (bytes). When _pitch is set to + * UINT16_MAX, it will be calculated internally based on _width. + * + */ +BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); + +/** + * Read back texture content. + * @attention Texture must be created with `BGFX_TEXTURE_READ_BACK` flag. + * @attention Availability depends on: `BGFX_CAPS_TEXTURE_READ_BACK`. + * + * @param[in] _handle Texture handle. + * @param[in] _data Destination buffer. + * @param[in] _mip Mip level. + * + * @returns Frame number when the result will be available. See: `bgfx::frame`. + * + */ +BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip); + +/** + * Set texture debug name. + * + * @param[in] _handle Texture handle. + * @param[in] _name Texture name. + * @param[in] _len Texture name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. + * + */ +BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char* _name, int32_t _len); + +/** + * Returns texture direct access pointer. + * @attention Availability depends on: `BGFX_CAPS_TEXTURE_DIRECT_ACCESS`. This feature + * is available on GPUs that have unified memory architecture (UMA) support. + * + * @param[in] _handle Texture handle. + * + * @returns Pointer to texture memory. If returned pointer is `NULL` direct access + * is not available for this texture. If pointer is `UINTPTR_MAX` sentinel value + * it means texture is pending creation. Pointer returned can be cached and it + * will be valid until texture is destroyed. + * + */ +BGFX_C_API void* bgfx_get_direct_access_ptr(bgfx_texture_handle_t _handle); + +/** + * Destroy texture. + * + * @param[in] _handle Texture handle. + * + */ +BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle); + +/** + * Create frame buffer (simple). + * + * @param[in] _width Texture width. + * @param[in] _height Texture height. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _textureFlags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * + * @returns Frame buffer handle. + * + */ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint64_t _textureFlags); + +/** + * Create frame buffer with size based on backbuffer ratio. Frame buffer will maintain ratio + * if back buffer resolution changes. + * + * @param[in] _ratio Frame buffer size in respect to back-buffer size. See: + * `BackbufferRatio::Enum`. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _textureFlags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * + * @returns Frame buffer handle. + * + */ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint64_t _textureFlags); + +/** + * Create MRT frame buffer from texture handles (simple). + * + * @param[in] _num Number of texture handles. + * @param[in] _handles Texture attachments. + * @param[in] _destroyTexture If true, textures will be destroyed when + * frame buffer is destroyed. + * + * @returns Frame buffer handle. + * + */ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTexture); + +/** + * Create MRT frame buffer from texture handles with specific layer and + * mip level. + * + * @param[in] _num Number of attachments. + * @param[in] _attachment Attachment texture info. See: `bgfx::Attachment`. + * @param[in] _destroyTexture If true, textures will be destroyed when + * frame buffer is destroyed. + * + * @returns Frame buffer handle. + * + */ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_attachment(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTexture); + +/** + * Create frame buffer for multiple window rendering. + * @remarks + * Frame buffer cannot be used for sampling. + * @attention Availability depends on: `BGFX_CAPS_SWAP_CHAIN`. + * + * @param[in] _nwh OS' target native window handle. + * @param[in] _width Window back buffer width. + * @param[in] _height Window back buffer height. + * @param[in] _format Window back buffer color format. + * @param[in] _depthFormat Window back buffer depth format. + * + * @returns Frame buffer handle. + * + */ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, bgfx_texture_format_t _depthFormat); + +/** + * Set frame buffer debug name. + * + * @param[in] _handle Frame buffer handle. + * @param[in] _name Frame buffer name. + * @param[in] _len Frame buffer name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. + * + */ +BGFX_C_API void bgfx_set_frame_buffer_name(bgfx_frame_buffer_handle_t _handle, const char* _name, int32_t _len); + +/** + * Obtain texture handle of frame buffer attachment. + * + * @param[in] _handle Frame buffer handle. + * @param[in] _attachment + * + */ +BGFX_C_API bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment); + +/** + * Destroy frame buffer. + * + * @param[in] _handle Frame buffer handle. + * + */ +BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle); + +/** + * Create shader uniform parameter. + * @remarks + * 1. Uniform names are unique. It's valid to call `bgfx::createUniform` + * multiple times with the same uniform name. The library will always + * return the same handle, but the handle reference count will be + * incremented. This means that the same number of `bgfx::destroyUniform` + * must be called to properly destroy the uniform. + * 2. Predefined uniforms (declared in `bgfx_shader.sh`): + * - `u_viewRect vec4(x, y, width, height)` - view rectangle for current + * view, in pixels. + * - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse + * width and height + * - `u_view mat4` - view matrix + * - `u_invView mat4` - inverted view matrix + * - `u_proj mat4` - projection matrix + * - `u_invProj mat4` - inverted projection matrix + * - `u_viewProj mat4` - concatenated view projection matrix + * - `u_invViewProj mat4` - concatenated inverted view projection matrix + * - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices. + * - `u_modelView mat4` - concatenated model view matrix, only first + * model matrix from array is used. + * - `u_modelViewProj mat4` - concatenated model view projection matrix. + * - `u_alphaRef float` - alpha reference value for alpha test. + * + * @param[in] _name Uniform name in shader. + * @param[in] _type Type of uniform (See: `bgfx::UniformType`). + * @param[in] _num Number of elements in array. + * + * @returns Handle to uniform object. + * + */ +BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num); + +/** + * Retrieve uniform info. + * + * @param[in] _handle Handle to uniform object. + * @param[out] _info Uniform info. + * + */ +BGFX_C_API void bgfx_get_uniform_info(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t * _info); + +/** + * Destroy shader uniform parameter. + * + * @param[in] _handle Handle to uniform object. + * + */ +BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle); + +/** + * Create occlusion query. + * + */ +BGFX_C_API bgfx_occlusion_query_handle_t bgfx_create_occlusion_query(void); + +/** + * Retrieve occlusion query result from previous frame. + * + * @param[in] _handle Handle to occlusion query object. + * @param[out] _result Number of pixels that passed test. This argument + * can be `NULL` if result of occlusion query is not needed. + * + * @returns Occlusion query result. + * + */ +BGFX_C_API bgfx_occlusion_query_result_t bgfx_get_result(bgfx_occlusion_query_handle_t _handle, int32_t* _result); + +/** + * Destroy occlusion query. + * + * @param[in] _handle Handle to occlusion query object. + * + */ +BGFX_C_API void bgfx_destroy_occlusion_query(bgfx_occlusion_query_handle_t _handle); + +/** + * Set palette color value. + * + * @param[in] _index Index into palette. + * @param[in] _rgba RGBA floating point values. + * + */ +BGFX_C_API void bgfx_set_palette_color(uint8_t _index, const float _rgba[4]); + +/** + * Set palette color value. + * + * @param[in] _index Index into palette. + * @param[in] _rgba Packed 32-bit RGBA value. + * + */ +BGFX_C_API void bgfx_set_palette_color_rgba8(uint8_t _index, uint32_t _rgba); + +/** + * Set view name. + * @remarks + * This is debug only feature. + * In graphics debugger view name will appear as: + * "nnnc " + * ^ ^ ^ + * | +--- compute (C) + * +------ view id + * + * @param[in] _id View id. + * @param[in] _name View name. + * + */ +BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name); + +/** + * Set view rectangle. Draw primitive outside view will be clipped. + * + * @param[in] _id View id. + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _width Width of view port region. + * @param[in] _height Height of view port region. + * + */ +BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/** + * Set view rectangle. Draw primitive outside view will be clipped. + * + * @param[in] _id View id. + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _ratio Width and height will be set in respect to back-buffer size. + * See: `BackbufferRatio::Enum`. + * + */ +BGFX_C_API void bgfx_set_view_rect_ratio(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio); + +/** + * Set view scissor. Draw primitive outside view will be clipped. When + * _x, _y, _width and _height are set to 0, scissor will be disabled. + * + * @param[in] _id View id. + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _width Width of view scissor region. + * @param[in] _height Height of view scissor region. + * + */ +BGFX_C_API void bgfx_set_view_scissor(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/** + * Set view clear flags. + * + * @param[in] _id View id. + * @param[in] _flags Clear flags. Use `BGFX_CLEAR_NONE` to remove any clear + * operation. See: `BGFX_CLEAR_*`. + * @param[in] _rgba Color clear value. + * @param[in] _depth Depth clear value. + * @param[in] _stencil Stencil clear value. + * + */ +BGFX_C_API void bgfx_set_view_clear(bgfx_view_id_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil); + +/** + * Set view clear flags with different clear color for each + * frame buffer texture. Must use `bgfx::setPaletteColor` to setup clear color + * palette. + * + * @param[in] _id View id. + * @param[in] _flags Clear flags. Use `BGFX_CLEAR_NONE` to remove any clear + * operation. See: `BGFX_CLEAR_*`. + * @param[in] _depth Depth clear value. + * @param[in] _stencil Stencil clear value. + * @param[in] _c0 Palette index for frame buffer attachment 0. + * @param[in] _c1 Palette index for frame buffer attachment 1. + * @param[in] _c2 Palette index for frame buffer attachment 2. + * @param[in] _c3 Palette index for frame buffer attachment 3. + * @param[in] _c4 Palette index for frame buffer attachment 4. + * @param[in] _c5 Palette index for frame buffer attachment 5. + * @param[in] _c6 Palette index for frame buffer attachment 6. + * @param[in] _c7 Palette index for frame buffer attachment 7. + * + */ +BGFX_C_API void bgfx_set_view_clear_mrt(bgfx_view_id_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _c0, uint8_t _c1, uint8_t _c2, uint8_t _c3, uint8_t _c4, uint8_t _c5, uint8_t _c6, uint8_t _c7); + +/** + * Set view sorting mode. + * @remarks + * View mode must be set prior calling `bgfx::submit` for the view. + * + * @param[in] _id View id. + * @param[in] _mode View sort mode. See `ViewMode::Enum`. + * + */ +BGFX_C_API void bgfx_set_view_mode(bgfx_view_id_t _id, bgfx_view_mode_t _mode); + +/** + * Set view frame buffer. + * @remarks + * Not persistent after `bgfx::reset` call. + * + * @param[in] _id View id. + * @param[in] _handle Frame buffer handle. Passing `BGFX_INVALID_HANDLE` as + * frame buffer handle will draw primitives from this view into + * default back buffer. + * + */ +BGFX_C_API void bgfx_set_view_frame_buffer(bgfx_view_id_t _id, bgfx_frame_buffer_handle_t _handle); + +/** + * Set view view and projection matrices, all draw primitives in this + * view will use these matrices. + * + * @param[in] _id View id. + * @param[in] _view View matrix. + * @param[in] _proj Projection matrix. + * + */ +BGFX_C_API void bgfx_set_view_transform(bgfx_view_id_t _id, const void* _view, const void* _proj); + +/** + * Post submit view reordering. + * + * @param[in] _id First view id. + * @param[in] _num Number of views to remap. + * @param[in] _order View remap id table. Passing `NULL` will reset view ids + * to default state. + * + */ +BGFX_C_API void bgfx_set_view_order(bgfx_view_id_t _id, uint16_t _num, const bgfx_view_id_t* _order); + +/** + * Reset all view settings to default. + * + * @param[in] _id + * + */ +BGFX_C_API void bgfx_reset_view(bgfx_view_id_t _id); + +/** + * Begin submitting draw calls from thread. + * + * @param[in] _forThread Explicitly request an encoder for a worker thread. + * + * @returns Encoder. + * + */ +BGFX_C_API bgfx_encoder_t* bgfx_encoder_begin(bool _forThread); + +/** + * End submitting draw calls from thread. + * + * @param[in] _encoder Encoder. + * + */ +BGFX_C_API void bgfx_encoder_end(bgfx_encoder_t* _encoder); + +/** + * Sets a debug marker. This allows you to group graphics calls together for easy browsing in + * graphics debugging tools. + * + * @param[in] _marker Marker string. + * + */ +BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_t* _this, const char* _marker); + +/** + * Set render states for draw primitive. + * @remarks + * 1. To setup more complex states use: + * `BGFX_STATE_ALPHA_REF(_ref)`, + * `BGFX_STATE_POINT_SIZE(_size)`, + * `BGFX_STATE_BLEND_FUNC(_src, _dst)`, + * `BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA)`, + * `BGFX_STATE_BLEND_EQUATION(_equation)`, + * `BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA)` + * 2. `BGFX_STATE_BLEND_EQUATION_ADD` is set when no other blend + * equation is specified. + * + * @param[in] _state State flags. Default state for primitive type is + * triangles. See: `BGFX_STATE_DEFAULT`. + * - `BGFX_STATE_DEPTH_TEST_*` - Depth test function. + * - `BGFX_STATE_BLEND_*` - See remark 1 about BGFX_STATE_BLEND_FUNC. + * - `BGFX_STATE_BLEND_EQUATION_*` - See remark 2. + * - `BGFX_STATE_CULL_*` - Backface culling mode. + * - `BGFX_STATE_WRITE_*` - Enable R, G, B, A or Z write. + * - `BGFX_STATE_MSAA` - Enable hardware multisample antialiasing. + * - `BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]` - Primitive type. + * @param[in] _rgba Sets blend factor used by `BGFX_STATE_BLEND_FACTOR` and + * `BGFX_STATE_BLEND_INV_FACTOR` blend modes. + * + */ +BGFX_C_API void bgfx_encoder_set_state(bgfx_encoder_t* _this, uint64_t _state, uint32_t _rgba); + +/** + * Set condition for rendering. + * + * @param[in] _handle Occlusion query handle. + * @param[in] _visible Render if occlusion query is visible. + * + */ +BGFX_C_API void bgfx_encoder_set_condition(bgfx_encoder_t* _this, bgfx_occlusion_query_handle_t _handle, bool _visible); + +/** + * Set stencil test state. + * + * @param[in] _fstencil Front stencil state. + * @param[in] _bstencil Back stencil state. If back is set to `BGFX_STENCIL_NONE` + * _fstencil is applied to both front and back facing primitives. + * + */ +BGFX_C_API void bgfx_encoder_set_stencil(bgfx_encoder_t* _this, uint32_t _fstencil, uint32_t _bstencil); + +/** + * Set scissor for draw primitive. + * @remark + * To scissor for all primitives in view see `bgfx::setViewScissor`. + * + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _width Width of view scissor region. + * @param[in] _height Height of view scissor region. + * + * @returns Scissor cache index. + * + */ +BGFX_C_API uint16_t bgfx_encoder_set_scissor(bgfx_encoder_t* _this, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/** + * Set scissor from cache for draw primitive. + * @remark + * To scissor for all primitives in view see `bgfx::setViewScissor`. + * + * @param[in] _cache Index in scissor cache. + * + */ +BGFX_C_API void bgfx_encoder_set_scissor_cached(bgfx_encoder_t* _this, uint16_t _cache); + +/** + * Set model matrix for draw primitive. If it is not called, + * the model will be rendered with an identity model matrix. + * + * @param[in] _mtx Pointer to first matrix in array. + * @param[in] _num Number of matrices in array. + * + * @returns Index into matrix cache in case the same model matrix has + * to be used for other draw primitive call. + * + */ +BGFX_C_API uint32_t bgfx_encoder_set_transform(bgfx_encoder_t* _this, const void* _mtx, uint16_t _num); + +/** + * Set model matrix from matrix cache for draw primitive. + * + * @param[in] _cache Index in matrix cache. + * @param[in] _num Number of matrices from cache. + * + */ +BGFX_C_API void bgfx_encoder_set_transform_cached(bgfx_encoder_t* _this, uint32_t _cache, uint16_t _num); + +/** + * Reserve matrices in internal matrix cache. + * @attention Pointer returned can be modifed until `bgfx::frame` is called. + * + * @param[out] _transform Pointer to `Transform` structure. + * @param[in] _num Number of matrices. + * + * @returns Index in matrix cache. + * + */ +BGFX_C_API uint32_t bgfx_encoder_alloc_transform(bgfx_encoder_t* _this, bgfx_transform_t* _transform, uint16_t _num); + +/** + * Set shader uniform parameter for draw primitive. + * + * @param[in] _handle Uniform. + * @param[in] _value Pointer to uniform data. + * @param[in] _num Number of elements. Passing `UINT16_MAX` will + * use the _num passed on uniform creation. + * + */ +BGFX_C_API void bgfx_encoder_set_uniform(bgfx_encoder_t* _this, bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num); + +/** + * Set index buffer for draw primitive. + * + * @param[in] _handle Index buffer. + * @param[in] _firstIndex First index to render. + * @param[in] _numIndices Number of indices to render. + * + */ +BGFX_C_API void bgfx_encoder_set_index_buffer(bgfx_encoder_t* _this, bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + +/** + * Set index buffer for draw primitive. + * + * @param[in] _handle Dynamic index buffer. + * @param[in] _firstIndex First index to render. + * @param[in] _numIndices Number of indices to render. + * + */ +BGFX_C_API void bgfx_encoder_set_dynamic_index_buffer(bgfx_encoder_t* _this, bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + +/** + * Set index buffer for draw primitive. + * + * @param[in] _tib Transient index buffer. + * @param[in] _firstIndex First index to render. + * @param[in] _numIndices Number of indices to render. + * + */ +BGFX_C_API void bgfx_encoder_set_transient_index_buffer(bgfx_encoder_t* _this, const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * + */ +BGFX_C_API void bgfx_encoder_set_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * @param[in] _layoutHandle Vertex layout for aliasing vertex buffer. If invalid + * handle is used, vertex layout used for creation + * of vertex buffer will be used. + * + */ +BGFX_C_API void bgfx_encoder_set_vertex_buffer_with_layout(bgfx_encoder_t* _this, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Dynamic vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * + */ +BGFX_C_API void bgfx_encoder_set_dynamic_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); +BGFX_C_API void bgfx_encoder_set_dynamic_vertex_buffer_with_layout(bgfx_encoder_t* _this, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _tvb Transient vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * + */ +BGFX_C_API void bgfx_encoder_set_transient_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _tvb Transient vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * @param[in] _layoutHandle Vertex layout for aliasing vertex buffer. If invalid + * handle is used, vertex layout used for creation + * of vertex buffer will be used. + * + */ +BGFX_C_API void bgfx_encoder_set_transient_vertex_buffer_with_layout(bgfx_encoder_t* _this, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Set number of vertices for auto generated vertices use in conjuction + * with gl_VertexID. + * @attention Availability depends on: `BGFX_CAPS_VERTEX_ID`. + * + * @param[in] _numVertices Number of vertices. + * + */ +BGFX_C_API void bgfx_encoder_set_vertex_count(bgfx_encoder_t* _this, uint32_t _numVertices); + +/** + * Set instance data buffer for draw primitive. + * + * @param[in] _idb Transient instance data buffer. + * @param[in] _start First instance data. + * @param[in] _num Number of data instances. + * + */ +BGFX_C_API void bgfx_encoder_set_instance_data_buffer(bgfx_encoder_t* _this, const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num); + +/** + * Set instance data buffer for draw primitive. + * + * @param[in] _handle Vertex buffer. + * @param[in] _startVertex First instance data. + * @param[in] _num Number of data instances. + * Set instance data buffer for draw primitive. + * + */ +BGFX_C_API void bgfx_encoder_set_instance_data_from_vertex_buffer(bgfx_encoder_t* _this, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/** + * Set instance data buffer for draw primitive. + * + * @param[in] _handle Dynamic vertex buffer. + * @param[in] _startVertex First instance data. + * @param[in] _num Number of data instances. + * + */ +BGFX_C_API void bgfx_encoder_set_instance_data_from_dynamic_vertex_buffer(bgfx_encoder_t* _this, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/** + * Set number of instances for auto generated instances use in conjuction + * with gl_InstanceID. + * @attention Availability depends on: `BGFX_CAPS_VERTEX_ID`. + * + * @param[in] _numInstances + * + */ +BGFX_C_API void bgfx_encoder_set_instance_count(bgfx_encoder_t* _this, uint32_t _numInstances); + +/** + * Set texture stage for draw primitive. + * + * @param[in] _stage Texture unit. + * @param[in] _sampler Program sampler. + * @param[in] _handle Texture handle. + * @param[in] _flags Texture sampling mode. Default value UINT32_MAX uses + * texture sampling settings from the texture. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * + */ +BGFX_C_API void bgfx_encoder_set_texture(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); + +/** + * Submit an empty primitive for rendering. Uniforms and draw state + * will be applied but no geometry will be submitted. Useful in cases + * when no other draw/compute primitive is submitted to view, but it's + * desired to execute clear view. + * @remark + * These empty draw calls will sort before ordinary draw calls. + * + * @param[in] _id View id. + * + */ +BGFX_C_API void bgfx_encoder_touch(bgfx_encoder_t* _this, bgfx_view_id_t _id); + +/** + * Submit primitive for rendering. + * + * @param[in] _id View id. + * @param[in] _program Program. + * @param[in] _depth Depth for sorting. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_encoder_submit(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags); + +/** + * Submit primitive with occlusion query for rendering. + * + * @param[in] _id View id. + * @param[in] _program Program. + * @param[in] _occlusionQuery Occlusion query. + * @param[in] _depth Depth for sorting. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_encoder_submit_occlusion_query(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags); + +/** + * Submit primitive for rendering with index and instance data info from + * indirect buffer. + * + * @param[in] _id View id. + * @param[in] _program Program. + * @param[in] _indirectHandle Indirect buffer. + * @param[in] _start First element in indirect buffer. + * @param[in] _num Number of dispatches. + * @param[in] _depth Depth for sorting. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_encoder_submit_indirect(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags); + +/** + * Set compute index buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Index buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_encoder_set_compute_index_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute vertex buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Vertex buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_encoder_set_compute_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute dynamic index buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Dynamic index buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_encoder_set_compute_dynamic_index_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute dynamic vertex buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Dynamic vertex buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_encoder_set_compute_dynamic_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute indirect buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Indirect buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_encoder_set_compute_indirect_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute image from texture. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Texture handle. + * @param[in] _mip Mip level. + * @param[in] _access Image access. See `Access::Enum`. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * + */ +BGFX_C_API void bgfx_encoder_set_image(bgfx_encoder_t* _this, uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); + +/** + * Dispatch compute. + * + * @param[in] _id View id. + * @param[in] _program Compute program. + * @param[in] _numX Number of groups X. + * @param[in] _numY Number of groups Y. + * @param[in] _numZ Number of groups Z. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_encoder_dispatch(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags); + +/** + * Dispatch compute indirect. + * + * @param[in] _id View id. + * @param[in] _program Compute program. + * @param[in] _indirectHandle Indirect buffer. + * @param[in] _start First element in indirect buffer. + * @param[in] _num Number of dispatches. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_encoder_dispatch_indirect(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags); + +/** + * Discard previously set state for draw or compute call. + * + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_t* _this, uint8_t _flags); + +/** + * Blit 2D texture region between two 2D textures. + * @attention Destination texture must be created with `BGFX_TEXTURE_BLIT_DST` flag. + * @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. + * + * @param[in] _id View id. + * @param[in] _dst Destination texture handle. + * @param[in] _dstMip Destination texture mip level. + * @param[in] _dstX Destination texture X position. + * @param[in] _dstY Destination texture Y position. + * @param[in] _dstZ If texture is 2D this argument should be 0. If destination texture is cube + * this argument represents destination texture cube face. For 3D texture this argument + * represents destination texture Z position. + * @param[in] _src Source texture handle. + * @param[in] _srcMip Source texture mip level. + * @param[in] _srcX Source texture X position. + * @param[in] _srcY Source texture Y position. + * @param[in] _srcZ If texture is 2D this argument should be 0. If source texture is cube + * this argument represents source texture cube face. For 3D texture this argument + * represents source texture Z position. + * @param[in] _width Width of region. + * @param[in] _height Height of region. + * @param[in] _depth If texture is 3D this argument represents depth of region, otherwise it's + * unused. + * + */ +BGFX_C_API void bgfx_encoder_blit(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth); + +/** + * Request screen shot of window back buffer. + * @remarks + * `bgfx::CallbackI::screenShot` must be implemented. + * @attention Frame buffer handle must be created with OS' target native window handle. + * + * @param[in] _handle Frame buffer handle. If handle is `BGFX_INVALID_HANDLE` request will be + * made for main window back buffer. + * @param[in] _filePath Will be passed to `bgfx::CallbackI::screenShot` callback. + * + */ +BGFX_C_API void bgfx_request_screen_shot(bgfx_frame_buffer_handle_t _handle, const char* _filePath); + +/** + * Render frame. + * @attention `bgfx::renderFrame` is blocking call. It waits for + * `bgfx::frame` to be called from API thread to process frame. + * If timeout value is passed call will timeout and return even + * if `bgfx::frame` is not called. + * @warning This call should be only used on platforms that don't + * allow creating separate rendering thread. If it is called before + * to bgfx::init, render thread won't be created by bgfx::init call. + * + * @param[in] _msecs Timeout in milliseconds. + * + * @returns Current renderer context state. See: `bgfx::RenderFrame`. + * + */ +BGFX_C_API bgfx_render_frame_t bgfx_render_frame(int32_t _msecs); + +/** + * Set platform data. + * @warning Must be called before `bgfx::init`. + * + * @param[in] _data Platform data. + * + */ +BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t * _data); + +/** + * Get internal data for interop. + * @attention It's expected you understand some bgfx internals before you + * use this call. + * @warning Must be called only on render thread. + * + */ +BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data(void); + +/** + * Override internal texture with externally created texture. Previously + * created internal texture will released. + * @attention It's expected you understand some bgfx internals before you + * use this call. + * @warning Must be called only on render thread. + * + * @param[in] _handle Texture handle. + * @param[in] _ptr Native API pointer to texture. + * + * @returns Native API pointer to texture. If result is 0, texture is not created + * yet from the main thread. + * + */ +BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr); + +/** + * Override internal texture by creating new texture. Previously created + * internal texture will released. + * @attention It's expected you understand some bgfx internals before you + * use this call. + * @returns Native API pointer to texture. If result is 0, texture is not created yet from the + * main thread. + * @warning Must be called only on render thread. + * + * @param[in] _handle Texture handle. + * @param[in] _width Width. + * @param[in] _height Height. + * @param[in] _numMips Number of mip-maps. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) + * flags. Default texture sampling mode is linear, and wrap mode is repeat. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * + * @returns Native API pointer to texture. If result is 0, texture is not created + * yet from the main thread. + * + */ +BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint64_t _flags); + +/** + * Sets a debug marker. This allows you to group graphics calls together for easy browsing in + * graphics debugging tools. + * + * @param[in] _marker Marker string. + * + */ +BGFX_C_API void bgfx_set_marker(const char* _marker); + +/** + * Set render states for draw primitive. + * @remarks + * 1. To setup more complex states use: + * `BGFX_STATE_ALPHA_REF(_ref)`, + * `BGFX_STATE_POINT_SIZE(_size)`, + * `BGFX_STATE_BLEND_FUNC(_src, _dst)`, + * `BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA)`, + * `BGFX_STATE_BLEND_EQUATION(_equation)`, + * `BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA)` + * 2. `BGFX_STATE_BLEND_EQUATION_ADD` is set when no other blend + * equation is specified. + * + * @param[in] _state State flags. Default state for primitive type is + * triangles. See: `BGFX_STATE_DEFAULT`. + * - `BGFX_STATE_DEPTH_TEST_*` - Depth test function. + * - `BGFX_STATE_BLEND_*` - See remark 1 about BGFX_STATE_BLEND_FUNC. + * - `BGFX_STATE_BLEND_EQUATION_*` - See remark 2. + * - `BGFX_STATE_CULL_*` - Backface culling mode. + * - `BGFX_STATE_WRITE_*` - Enable R, G, B, A or Z write. + * - `BGFX_STATE_MSAA` - Enable hardware multisample antialiasing. + * - `BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]` - Primitive type. + * @param[in] _rgba Sets blend factor used by `BGFX_STATE_BLEND_FACTOR` and + * `BGFX_STATE_BLEND_INV_FACTOR` blend modes. + * + */ +BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba); + +/** + * Set condition for rendering. + * + * @param[in] _handle Occlusion query handle. + * @param[in] _visible Render if occlusion query is visible. + * + */ +BGFX_C_API void bgfx_set_condition(bgfx_occlusion_query_handle_t _handle, bool _visible); + +/** + * Set stencil test state. + * + * @param[in] _fstencil Front stencil state. + * @param[in] _bstencil Back stencil state. If back is set to `BGFX_STENCIL_NONE` + * _fstencil is applied to both front and back facing primitives. + * + */ +BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil); + +/** + * Set scissor for draw primitive. + * @remark + * To scissor for all primitives in view see `bgfx::setViewScissor`. + * + * @param[in] _x Position x from the left corner of the window. + * @param[in] _y Position y from the top corner of the window. + * @param[in] _width Width of view scissor region. + * @param[in] _height Height of view scissor region. + * + * @returns Scissor cache index. + * + */ +BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/** + * Set scissor from cache for draw primitive. + * @remark + * To scissor for all primitives in view see `bgfx::setViewScissor`. + * + * @param[in] _cache Index in scissor cache. + * + */ +BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache); + +/** + * Set model matrix for draw primitive. If it is not called, + * the model will be rendered with an identity model matrix. + * + * @param[in] _mtx Pointer to first matrix in array. + * @param[in] _num Number of matrices in array. + * + * @returns Index into matrix cache in case the same model matrix has + * to be used for other draw primitive call. + * + */ +BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num); + +/** + * Set model matrix from matrix cache for draw primitive. + * + * @param[in] _cache Index in matrix cache. + * @param[in] _num Number of matrices from cache. + * + */ +BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num); + +/** + * Reserve matrices in internal matrix cache. + * @attention Pointer returned can be modifed until `bgfx::frame` is called. + * + * @param[out] _transform Pointer to `Transform` structure. + * @param[in] _num Number of matrices. + * + * @returns Index in matrix cache. + * + */ +BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num); + +/** + * Set shader uniform parameter for draw primitive. + * + * @param[in] _handle Uniform. + * @param[in] _value Pointer to uniform data. + * @param[in] _num Number of elements. Passing `UINT16_MAX` will + * use the _num passed on uniform creation. + * + */ +BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num); + +/** + * Set index buffer for draw primitive. + * + * @param[in] _handle Index buffer. + * @param[in] _firstIndex First index to render. + * @param[in] _numIndices Number of indices to render. + * + */ +BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + +/** + * Set index buffer for draw primitive. + * + * @param[in] _handle Dynamic index buffer. + * @param[in] _firstIndex First index to render. + * @param[in] _numIndices Number of indices to render. + * + */ +BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + +/** + * Set index buffer for draw primitive. + * + * @param[in] _tib Transient index buffer. + * @param[in] _firstIndex First index to render. + * @param[in] _numIndices Number of indices to render. + * + */ +BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * + */ +BGFX_C_API void bgfx_set_vertex_buffer(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * @param[in] _layoutHandle Vertex layout for aliasing vertex buffer. If invalid + * handle is used, vertex layout used for creation + * of vertex buffer will be used. + * + */ +BGFX_C_API void bgfx_set_vertex_buffer_with_layout(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Dynamic vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * + */ +BGFX_C_API void bgfx_set_dynamic_vertex_buffer(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _handle Dynamic vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * @param[in] _layoutHandle Vertex layout for aliasing vertex buffer. If invalid + * handle is used, vertex layout used for creation + * of vertex buffer will be used. + * + */ +BGFX_C_API void bgfx_set_dynamic_vertex_buffer_with_layout(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _tvb Transient vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * + */ +BGFX_C_API void bgfx_set_transient_vertex_buffer(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices); + +/** + * Set vertex buffer for draw primitive. + * + * @param[in] _stream Vertex stream. + * @param[in] _tvb Transient vertex buffer. + * @param[in] _startVertex First vertex to render. + * @param[in] _numVertices Number of vertices to render. + * @param[in] _layoutHandle Vertex layout for aliasing vertex buffer. If invalid + * handle is used, vertex layout used for creation + * of vertex buffer will be used. + * + */ +BGFX_C_API void bgfx_set_transient_vertex_buffer_with_layout(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + +/** + * Set number of vertices for auto generated vertices use in conjuction + * with gl_VertexID. + * @attention Availability depends on: `BGFX_CAPS_VERTEX_ID`. + * + * @param[in] _numVertices Number of vertices. + * + */ +BGFX_C_API void bgfx_set_vertex_count(uint32_t _numVertices); + +/** + * Set instance data buffer for draw primitive. + * + * @param[in] _idb Transient instance data buffer. + * @param[in] _start First instance data. + * @param[in] _num Number of data instances. + * + */ +BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num); + +/** + * Set instance data buffer for draw primitive. + * + * @param[in] _handle Vertex buffer. + * @param[in] _startVertex First instance data. + * @param[in] _num Number of data instances. + * Set instance data buffer for draw primitive. + * + */ +BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/** + * Set instance data buffer for draw primitive. + * + * @param[in] _handle Dynamic vertex buffer. + * @param[in] _startVertex First instance data. + * @param[in] _num Number of data instances. + * + */ +BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/** + * Set number of instances for auto generated instances use in conjuction + * with gl_InstanceID. + * @attention Availability depends on: `BGFX_CAPS_VERTEX_ID`. + * + * @param[in] _numInstances + * + */ +BGFX_C_API void bgfx_set_instance_count(uint32_t _numInstances); + +/** + * Set texture stage for draw primitive. + * + * @param[in] _stage Texture unit. + * @param[in] _sampler Program sampler. + * @param[in] _handle Texture handle. + * @param[in] _flags Texture sampling mode. Default value UINT32_MAX uses + * texture sampling settings from the texture. + * - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap + * mode. + * - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic + * sampling. + * + */ +BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); + +/** + * Submit an empty primitive for rendering. Uniforms and draw state + * will be applied but no geometry will be submitted. + * @remark + * These empty draw calls will sort before ordinary draw calls. + * + * @param[in] _id View id. + * + */ +BGFX_C_API void bgfx_touch(bgfx_view_id_t _id); + +/** + * Submit primitive for rendering. + * + * @param[in] _id View id. + * @param[in] _program Program. + * @param[in] _depth Depth for sorting. + * @param[in] _flags Which states to discard for next draw. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_submit(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags); + +/** + * Submit primitive with occlusion query for rendering. + * + * @param[in] _id View id. + * @param[in] _program Program. + * @param[in] _occlusionQuery Occlusion query. + * @param[in] _depth Depth for sorting. + * @param[in] _flags Which states to discard for next draw. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_submit_occlusion_query(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags); + +/** + * Submit primitive for rendering with index and instance data info from + * indirect buffer. + * + * @param[in] _id View id. + * @param[in] _program Program. + * @param[in] _indirectHandle Indirect buffer. + * @param[in] _start First element in indirect buffer. + * @param[in] _num Number of dispatches. + * @param[in] _depth Depth for sorting. + * @param[in] _flags Which states to discard for next draw. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_submit_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags); + +/** + * Set compute index buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Index buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute vertex buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Vertex buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute dynamic index buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Dynamic index buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute dynamic vertex buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Dynamic vertex buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute indirect buffer. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Indirect buffer handle. + * @param[in] _access Buffer access. See `Access::Enum`. + * + */ +BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access); + +/** + * Set compute image from texture. + * + * @param[in] _stage Compute stage. + * @param[in] _handle Texture handle. + * @param[in] _mip Mip level. + * @param[in] _access Image access. See `Access::Enum`. + * @param[in] _format Texture format. See: `TextureFormat::Enum`. + * + */ +BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); + +/** + * Dispatch compute. + * + * @param[in] _id View id. + * @param[in] _program Compute program. + * @param[in] _numX Number of groups X. + * @param[in] _numY Number of groups Y. + * @param[in] _numZ Number of groups Z. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_dispatch(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags); + +/** + * Dispatch compute indirect. + * + * @param[in] _id View id. + * @param[in] _program Compute program. + * @param[in] _indirectHandle Indirect buffer. + * @param[in] _start First element in indirect buffer. + * @param[in] _num Number of dispatches. + * @param[in] _flags Discard or preserve states. See `BGFX_DISCARD_*`. + * + */ +BGFX_C_API void bgfx_dispatch_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags); + +/** + * Discard previously set state for draw or compute call. + * + * @param[in] _flags Draw/compute states to discard. + * + */ +BGFX_C_API void bgfx_discard(uint8_t _flags); + +/** + * Blit 2D texture region between two 2D textures. + * @attention Destination texture must be created with `BGFX_TEXTURE_BLIT_DST` flag. + * @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. + * + * @param[in] _id View id. + * @param[in] _dst Destination texture handle. + * @param[in] _dstMip Destination texture mip level. + * @param[in] _dstX Destination texture X position. + * @param[in] _dstY Destination texture Y position. + * @param[in] _dstZ If texture is 2D this argument should be 0. If destination texture is cube + * this argument represents destination texture cube face. For 3D texture this argument + * represents destination texture Z position. + * @param[in] _src Source texture handle. + * @param[in] _srcMip Source texture mip level. + * @param[in] _srcX Source texture X position. + * @param[in] _srcY Source texture Y position. + * @param[in] _srcZ If texture is 2D this argument should be 0. If source texture is cube + * this argument represents source texture cube face. For 3D texture this argument + * represents source texture Z position. + * @param[in] _width Width of region. + * @param[in] _height Height of region. + * @param[in] _depth If texture is 3D this argument represents depth of region, otherwise it's + * unused. + * + */ +BGFX_C_API void bgfx_blit(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth); + +/**/ +typedef enum bgfx_function_id +{ + BGFX_FUNCTION_ID_ATTACHMENT_INIT, + BGFX_FUNCTION_ID_VERTEX_LAYOUT_BEGIN, + BGFX_FUNCTION_ID_VERTEX_LAYOUT_ADD, + BGFX_FUNCTION_ID_VERTEX_LAYOUT_DECODE, + BGFX_FUNCTION_ID_VERTEX_LAYOUT_HAS, + BGFX_FUNCTION_ID_VERTEX_LAYOUT_SKIP, + BGFX_FUNCTION_ID_VERTEX_LAYOUT_END, + BGFX_FUNCTION_ID_VERTEX_PACK, + BGFX_FUNCTION_ID_VERTEX_UNPACK, + BGFX_FUNCTION_ID_VERTEX_CONVERT, + BGFX_FUNCTION_ID_WELD_VERTICES, + BGFX_FUNCTION_ID_TOPOLOGY_CONVERT, + BGFX_FUNCTION_ID_TOPOLOGY_SORT_TRI_LIST, + BGFX_FUNCTION_ID_GET_SUPPORTED_RENDERERS, + BGFX_FUNCTION_ID_GET_RENDERER_NAME, + BGFX_FUNCTION_ID_INIT_CTOR, + BGFX_FUNCTION_ID_INIT, + BGFX_FUNCTION_ID_SHUTDOWN, + BGFX_FUNCTION_ID_RESET, + BGFX_FUNCTION_ID_FRAME, + BGFX_FUNCTION_ID_GET_RENDERER_TYPE, + BGFX_FUNCTION_ID_GET_CAPS, + BGFX_FUNCTION_ID_GET_STATS, + BGFX_FUNCTION_ID_ALLOC, + BGFX_FUNCTION_ID_COPY, + BGFX_FUNCTION_ID_MAKE_REF, + BGFX_FUNCTION_ID_MAKE_REF_RELEASE, + BGFX_FUNCTION_ID_SET_DEBUG, + BGFX_FUNCTION_ID_DBG_TEXT_CLEAR, + BGFX_FUNCTION_ID_DBG_TEXT_PRINTF, + BGFX_FUNCTION_ID_DBG_TEXT_VPRINTF, + BGFX_FUNCTION_ID_DBG_TEXT_IMAGE, + BGFX_FUNCTION_ID_CREATE_INDEX_BUFFER, + BGFX_FUNCTION_ID_SET_INDEX_BUFFER_NAME, + BGFX_FUNCTION_ID_DESTROY_INDEX_BUFFER, + BGFX_FUNCTION_ID_CREATE_VERTEX_LAYOUT, + BGFX_FUNCTION_ID_DESTROY_VERTEX_LAYOUT, + BGFX_FUNCTION_ID_CREATE_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_VERTEX_BUFFER_NAME, + BGFX_FUNCTION_ID_DESTROY_VERTEX_BUFFER, + BGFX_FUNCTION_ID_CREATE_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_CREATE_DYNAMIC_INDEX_BUFFER_MEM, + BGFX_FUNCTION_ID_UPDATE_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_DESTROY_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_CREATE_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_CREATE_DYNAMIC_VERTEX_BUFFER_MEM, + BGFX_FUNCTION_ID_UPDATE_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_DESTROY_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_GET_AVAIL_TRANSIENT_INDEX_BUFFER, + BGFX_FUNCTION_ID_GET_AVAIL_TRANSIENT_VERTEX_BUFFER, + BGFX_FUNCTION_ID_GET_AVAIL_INSTANCE_DATA_BUFFER, + BGFX_FUNCTION_ID_ALLOC_TRANSIENT_INDEX_BUFFER, + BGFX_FUNCTION_ID_ALLOC_TRANSIENT_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ALLOC_TRANSIENT_BUFFERS, + BGFX_FUNCTION_ID_ALLOC_INSTANCE_DATA_BUFFER, + BGFX_FUNCTION_ID_CREATE_INDIRECT_BUFFER, + BGFX_FUNCTION_ID_DESTROY_INDIRECT_BUFFER, + BGFX_FUNCTION_ID_CREATE_SHADER, + BGFX_FUNCTION_ID_GET_SHADER_UNIFORMS, + BGFX_FUNCTION_ID_SET_SHADER_NAME, + BGFX_FUNCTION_ID_DESTROY_SHADER, + BGFX_FUNCTION_ID_CREATE_PROGRAM, + BGFX_FUNCTION_ID_CREATE_COMPUTE_PROGRAM, + BGFX_FUNCTION_ID_DESTROY_PROGRAM, + BGFX_FUNCTION_ID_IS_TEXTURE_VALID, + BGFX_FUNCTION_ID_IS_FRAME_BUFFER_VALID, + BGFX_FUNCTION_ID_CALC_TEXTURE_SIZE, + BGFX_FUNCTION_ID_CREATE_TEXTURE, + BGFX_FUNCTION_ID_CREATE_TEXTURE_2D, + BGFX_FUNCTION_ID_CREATE_TEXTURE_2D_SCALED, + BGFX_FUNCTION_ID_CREATE_TEXTURE_3D, + BGFX_FUNCTION_ID_CREATE_TEXTURE_CUBE, + BGFX_FUNCTION_ID_UPDATE_TEXTURE_2D, + BGFX_FUNCTION_ID_UPDATE_TEXTURE_3D, + BGFX_FUNCTION_ID_UPDATE_TEXTURE_CUBE, + BGFX_FUNCTION_ID_READ_TEXTURE, + BGFX_FUNCTION_ID_SET_TEXTURE_NAME, + BGFX_FUNCTION_ID_GET_DIRECT_ACCESS_PTR, + BGFX_FUNCTION_ID_DESTROY_TEXTURE, + BGFX_FUNCTION_ID_CREATE_FRAME_BUFFER, + BGFX_FUNCTION_ID_CREATE_FRAME_BUFFER_SCALED, + BGFX_FUNCTION_ID_CREATE_FRAME_BUFFER_FROM_HANDLES, + BGFX_FUNCTION_ID_CREATE_FRAME_BUFFER_FROM_ATTACHMENT, + BGFX_FUNCTION_ID_CREATE_FRAME_BUFFER_FROM_NWH, + BGFX_FUNCTION_ID_SET_FRAME_BUFFER_NAME, + BGFX_FUNCTION_ID_GET_TEXTURE, + BGFX_FUNCTION_ID_DESTROY_FRAME_BUFFER, + BGFX_FUNCTION_ID_CREATE_UNIFORM, + BGFX_FUNCTION_ID_GET_UNIFORM_INFO, + BGFX_FUNCTION_ID_DESTROY_UNIFORM, + BGFX_FUNCTION_ID_CREATE_OCCLUSION_QUERY, + BGFX_FUNCTION_ID_GET_RESULT, + BGFX_FUNCTION_ID_DESTROY_OCCLUSION_QUERY, + BGFX_FUNCTION_ID_SET_PALETTE_COLOR, + BGFX_FUNCTION_ID_SET_PALETTE_COLOR_RGBA8, + BGFX_FUNCTION_ID_SET_VIEW_NAME, + BGFX_FUNCTION_ID_SET_VIEW_RECT, + BGFX_FUNCTION_ID_SET_VIEW_RECT_RATIO, + BGFX_FUNCTION_ID_SET_VIEW_SCISSOR, + BGFX_FUNCTION_ID_SET_VIEW_CLEAR, + BGFX_FUNCTION_ID_SET_VIEW_CLEAR_MRT, + BGFX_FUNCTION_ID_SET_VIEW_MODE, + BGFX_FUNCTION_ID_SET_VIEW_FRAME_BUFFER, + BGFX_FUNCTION_ID_SET_VIEW_TRANSFORM, + BGFX_FUNCTION_ID_SET_VIEW_ORDER, + BGFX_FUNCTION_ID_RESET_VIEW, + BGFX_FUNCTION_ID_ENCODER_BEGIN, + BGFX_FUNCTION_ID_ENCODER_END, + BGFX_FUNCTION_ID_ENCODER_SET_MARKER, + BGFX_FUNCTION_ID_ENCODER_SET_STATE, + BGFX_FUNCTION_ID_ENCODER_SET_CONDITION, + BGFX_FUNCTION_ID_ENCODER_SET_STENCIL, + BGFX_FUNCTION_ID_ENCODER_SET_SCISSOR, + BGFX_FUNCTION_ID_ENCODER_SET_SCISSOR_CACHED, + BGFX_FUNCTION_ID_ENCODER_SET_TRANSFORM, + BGFX_FUNCTION_ID_ENCODER_SET_TRANSFORM_CACHED, + BGFX_FUNCTION_ID_ENCODER_ALLOC_TRANSFORM, + BGFX_FUNCTION_ID_ENCODER_SET_UNIFORM, + BGFX_FUNCTION_ID_ENCODER_SET_INDEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_TRANSIENT_INDEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_VERTEX_BUFFER_WITH_LAYOUT, + BGFX_FUNCTION_ID_ENCODER_SET_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_DYNAMIC_VERTEX_BUFFER_WITH_LAYOUT, + BGFX_FUNCTION_ID_ENCODER_SET_TRANSIENT_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_TRANSIENT_VERTEX_BUFFER_WITH_LAYOUT, + BGFX_FUNCTION_ID_ENCODER_SET_VERTEX_COUNT, + BGFX_FUNCTION_ID_ENCODER_SET_INSTANCE_DATA_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_INSTANCE_DATA_FROM_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_INSTANCE_DATA_FROM_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_INSTANCE_COUNT, + BGFX_FUNCTION_ID_ENCODER_SET_TEXTURE, + BGFX_FUNCTION_ID_ENCODER_TOUCH, + BGFX_FUNCTION_ID_ENCODER_SUBMIT, + BGFX_FUNCTION_ID_ENCODER_SUBMIT_OCCLUSION_QUERY, + BGFX_FUNCTION_ID_ENCODER_SUBMIT_INDIRECT, + BGFX_FUNCTION_ID_ENCODER_SET_COMPUTE_INDEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_COMPUTE_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_COMPUTE_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_COMPUTE_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_COMPUTE_INDIRECT_BUFFER, + BGFX_FUNCTION_ID_ENCODER_SET_IMAGE, + BGFX_FUNCTION_ID_ENCODER_DISPATCH, + BGFX_FUNCTION_ID_ENCODER_DISPATCH_INDIRECT, + BGFX_FUNCTION_ID_ENCODER_DISCARD, + BGFX_FUNCTION_ID_ENCODER_BLIT, + BGFX_FUNCTION_ID_REQUEST_SCREEN_SHOT, + BGFX_FUNCTION_ID_RENDER_FRAME, + BGFX_FUNCTION_ID_SET_PLATFORM_DATA, + BGFX_FUNCTION_ID_GET_INTERNAL_DATA, + BGFX_FUNCTION_ID_OVERRIDE_INTERNAL_TEXTURE_PTR, + BGFX_FUNCTION_ID_OVERRIDE_INTERNAL_TEXTURE, + BGFX_FUNCTION_ID_SET_MARKER, + BGFX_FUNCTION_ID_SET_STATE, + BGFX_FUNCTION_ID_SET_CONDITION, + BGFX_FUNCTION_ID_SET_STENCIL, + BGFX_FUNCTION_ID_SET_SCISSOR, + BGFX_FUNCTION_ID_SET_SCISSOR_CACHED, + BGFX_FUNCTION_ID_SET_TRANSFORM, + BGFX_FUNCTION_ID_SET_TRANSFORM_CACHED, + BGFX_FUNCTION_ID_ALLOC_TRANSFORM, + BGFX_FUNCTION_ID_SET_UNIFORM, + BGFX_FUNCTION_ID_SET_INDEX_BUFFER, + BGFX_FUNCTION_ID_SET_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_SET_TRANSIENT_INDEX_BUFFER, + BGFX_FUNCTION_ID_SET_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_VERTEX_BUFFER_WITH_LAYOUT, + BGFX_FUNCTION_ID_SET_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_DYNAMIC_VERTEX_BUFFER_WITH_LAYOUT, + BGFX_FUNCTION_ID_SET_TRANSIENT_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_TRANSIENT_VERTEX_BUFFER_WITH_LAYOUT, + BGFX_FUNCTION_ID_SET_VERTEX_COUNT, + BGFX_FUNCTION_ID_SET_INSTANCE_DATA_BUFFER, + BGFX_FUNCTION_ID_SET_INSTANCE_DATA_FROM_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_INSTANCE_DATA_FROM_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_INSTANCE_COUNT, + BGFX_FUNCTION_ID_SET_TEXTURE, + BGFX_FUNCTION_ID_TOUCH, + BGFX_FUNCTION_ID_SUBMIT, + BGFX_FUNCTION_ID_SUBMIT_OCCLUSION_QUERY, + BGFX_FUNCTION_ID_SUBMIT_INDIRECT, + BGFX_FUNCTION_ID_SET_COMPUTE_INDEX_BUFFER, + BGFX_FUNCTION_ID_SET_COMPUTE_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_COMPUTE_DYNAMIC_INDEX_BUFFER, + BGFX_FUNCTION_ID_SET_COMPUTE_DYNAMIC_VERTEX_BUFFER, + BGFX_FUNCTION_ID_SET_COMPUTE_INDIRECT_BUFFER, + BGFX_FUNCTION_ID_SET_IMAGE, + BGFX_FUNCTION_ID_DISPATCH, + BGFX_FUNCTION_ID_DISPATCH_INDIRECT, + BGFX_FUNCTION_ID_DISCARD, + BGFX_FUNCTION_ID_BLIT, + + BGFX_FUNCTION_ID_COUNT + +} bgfx_function_id_t; + +/**/ +struct bgfx_interface_vtbl { - /// Fatal error enum. - /// - /// @attention C99 equivalent is `bgfx_fatal_t`. - /// - struct Fatal - { - enum Enum - { - DebugCheck, - MinimumRequiredSpecs, - InvalidShader, - UnableToInitialize, - UnableToCreateTexture, - DeviceLost, - - Count - }; - }; - - /// Renderer backend type enum. - /// - /// @attention C99 equivalent is `bgfx_renderer_type_t`. - /// - struct RendererType - { - /// Renderer types: - enum Enum - { - Null, //!< No rendering. - Direct3D9, //!< Direct3D 9.0 - Direct3D11, //!< Direct3D 11.0 - Direct3D12, //!< Direct3D 12.0 - Metal, //!< Metal - OpenGLES, //!< OpenGL ES 2.0+ - OpenGL, //!< OpenGL 2.1+ - Vulkan, //!< Vulkan - - Count - }; - }; - - /// Access mode enum. - /// - /// @attention C99 equivalent is `bgfx_access_t`. - /// - struct Access - { - /// Access: - enum Enum - { - Read, - Write, - ReadWrite, - - Count - }; - }; - - /// Vertex attribute enum. - /// - /// @attention C99 equivalent is `bgfx_attrib_t`. - /// - struct Attrib - { - /// Corresponds to vertex shader attribute. Attributes: - enum Enum - { - Position, //!< a_position - Normal, //!< a_normal - Tangent, //!< a_tangent - Bitangent, //!< a_bitangent - Color0, //!< a_color0 - Color1, //!< a_color1 - Indices, //!< a_indices - Weight, //!< a_weight - TexCoord0, //!< a_texcoord0 - TexCoord1, //!< a_texcoord1 - TexCoord2, //!< a_texcoord2 - TexCoord3, //!< a_texcoord3 - TexCoord4, //!< a_texcoord4 - TexCoord5, //!< a_texcoord5 - TexCoord6, //!< a_texcoord6 - TexCoord7, //!< a_texcoord7 - - Count - }; - }; - - /// Vertex attribute type enum. - /// - /// @attention C99 equivalent is `bgfx_attrib_type_t`. - /// - struct AttribType - { - /// Attribute types: - enum Enum - { - Uint8, //!< Uint8 - Uint10, //!< Uint10, availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_UINT10`. - Int16, //!< Int16 - Half, //!< Half, availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_HALF`. - Float, //!< Float - - Count - }; - }; - - /// Texture format enum. - /// - /// Notation: - /// - /// RGBA16S - /// ^ ^ ^ - /// | | +-- [ ]Unorm - /// | | [F]loat - /// | | [S]norm - /// | | [I]nt - /// | | [U]int - /// | +---- Number of bits per component - /// +-------- Components - /// - /// @attention Availability depends on Caps (see: formats). - /// - /// @attention C99 equivalent is `bgfx_texture_format_t`. - /// - struct TextureFormat - { - /// Texture formats: - enum Enum - { - BC1, //!< DXT1 - BC2, //!< DXT3 - BC3, //!< DXT5 - BC4, //!< LATC1/ATI1 - BC5, //!< LATC2/ATI2 - BC6H, //!< BC6H - BC7, //!< BC7 - ETC1, //!< ETC1 RGB8 - ETC2, //!< ETC2 RGB8 - ETC2A, //!< ETC2 RGBA8 - ETC2A1, //!< ETC2 RGB8A1 - PTC12, //!< PVRTC1 RGB 2BPP - PTC14, //!< PVRTC1 RGB 4BPP - PTC12A, //!< PVRTC1 RGBA 2BPP - PTC14A, //!< PVRTC1 RGBA 4BPP - PTC22, //!< PVRTC2 RGBA 2BPP - PTC24, //!< PVRTC2 RGBA 4BPP - - Unknown, // Compressed formats above. - - R1, - A8, - R8, - R8I, - R8U, - R8S, - R16, - R16I, - R16U, - R16F, - R16S, - R32I, - R32U, - R32F, - RG8, - RG8I, - RG8U, - RG8S, - RG16, - RG16I, - RG16U, - RG16F, - RG16S, - RG32I, - RG32U, - RG32F, - RGB8, - RGB8I, - RGB8U, - RGB8S, - RGB9E5F, - BGRA8, - RGBA8, - RGBA8I, - RGBA8U, - RGBA8S, - RGBA16, - RGBA16I, - RGBA16U, - RGBA16F, - RGBA16S, - RGBA32I, - RGBA32U, - RGBA32F, - R5G6B5, - RGBA4, - RGB5A1, - RGB10A2, - R11G11B10F, - - UnknownDepth, // Depth formats below. - - D16, - D24, - D24S8, - D32, - D16F, - D24F, - D32F, - D0S8, - - Count - }; - }; - - /// Uniform type enum. - /// - /// @attention C99 equivalent is `bgfx_uniform_type_t`. - /// - struct UniformType - { - /// Uniform types: - enum Enum - { - Int1, - End, - - Vec4, - Mat3, - Mat4, - - Count - }; - }; - - /// Backbuffer ratio enum. - /// - /// @attention C99 equivalent is `bgfx_backbuffer_ratio_t`. - /// - struct BackbufferRatio - { - /// Backbuffer ratios: - enum Enum - { - Equal, //!< Equal to backbuffer. - Half, //!< One half size of backbuffer. - Quarter, //!< One quarter size of backbuffer. - Eighth, //!< One eighth size of backbuffer. - Sixteenth, //!< One sixteenth size of backbuffer. - Double, //!< Double size of backbuffer. - - Count - }; - }; - - /// Occlusion query result. - /// - /// @attention C99 equivalent is `bgfx_occlusion_query_result_t`. - /// - struct OcclusionQueryResult - { - enum Enum - { - Invisible, //!< Query failed test. - Visible, //!< Query passed test. - NoResult, //!< Query result is not available yet. - - Count - }; - }; - - /// Topology conversion function. - /// - /// @attention C99 equivalent is `bgfx_topology_convert_t`. - /// - struct TopologyConvert - { - enum Enum - { - TriListFlipWinding, //!< Flip winding order of triangle list. - TriListToLineList, //!< Convert triangle list to line list. - TriStripToTriList, //!< Convert triangle strip to triangle list. - LineStripToLineList, //!< Convert line strip to line list. - - Count - }; - }; - - static const uint16_t invalidHandle = UINT16_MAX; - - BGFX_HANDLE(DynamicIndexBufferHandle); - BGFX_HANDLE(DynamicVertexBufferHandle); - BGFX_HANDLE(FrameBufferHandle); - BGFX_HANDLE(IndexBufferHandle); - BGFX_HANDLE(IndirectBufferHandle); - BGFX_HANDLE(OcclusionQueryHandle); - BGFX_HANDLE(ProgramHandle); - BGFX_HANDLE(ShaderHandle); - BGFX_HANDLE(TextureHandle); - BGFX_HANDLE(UniformHandle); - BGFX_HANDLE(VertexBufferHandle); - BGFX_HANDLE(VertexDeclHandle); - - /// Callback interface to implement application specific behavior. - /// Cached items are currently used for OpenGL and Direct3D 12 binary - /// shaders. - /// - /// @remarks - /// 'fatal' and 'trace' callbacks can be called from any thread. Other - /// callbacks are called from the render thread. - /// - /// @attention C99 equivalent is `bgfx_callback_interface_t`. - /// - struct CallbackI - { - virtual ~CallbackI() = 0; - - /// If fatal code code is not Fatal::DebugCheck this callback is - /// called on unrecoverable error. It's not safe to continue, inform - /// user and terminate application from this call. - /// - /// @param[in] _code Fatal error code. - /// @param[in] _str More information about error. - /// - /// @remarks - /// Not thread safe and it can be called from any thread. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.fatal`. - /// - virtual void fatal(Fatal::Enum _code, const char* _str) = 0; - - /// Print debug message. - /// - /// @param[in] _filePath File path where debug message was generated. - /// @param[in] _line Line where debug message was generated. - /// @param[in] _format `printf` style format. - /// @param[in] _argList Variable arguments list initialized with - /// `va_start`. - /// - /// @remarks - /// Not thread safe and it can be called from any thread. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.trace_vargs`. - /// - virtual void traceVargs( - const char* _filePath - , uint16_t _line - , const char* _format - , va_list _argList - ) = 0; - - /// Return size of for cached item. Return 0 if no cached item was - /// found. - /// - /// @param[in] _id Cache id. - /// @returns Number of bytes to read. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.cache_read_size`. - /// - virtual uint32_t cacheReadSize(uint64_t _id) = 0; - - /// Read cached item. - /// - /// @param[in] _id Cache id. - /// @param[in] _data Buffer where to read data. - /// @param[in] _size Size of data to read. - /// - /// @returns True if data is read. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.cache_read`. - /// - virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0; - - /// Write cached item. - /// - /// @param[in] _id Cache id. - /// @param[in] _data Data to write. - /// @param[in] _size Size of data to write. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.cache_write`. - /// - virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0; - - /// Screenshot captured. Screenshot format is always 4-byte BGRA. - /// - /// @param[in] _filePath File path. - /// @param[in] _width Image width. - /// @param[in] _height Image height. - /// @param[in] _pitch Number of bytes to skip to next line. - /// @param[in] _data Image data. - /// @param[in] _size Image size. - /// @param[in] _yflip If true image origin is bottom left. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.screen_shot`. - /// - virtual void screenShot( - const char* _filePath - , uint32_t _width - , uint32_t _height - , uint32_t _pitch - , const void* _data - , uint32_t _size - , bool _yflip - ) = 0; - - /// Called when capture begins. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.capture_begin`. - /// - virtual void captureBegin( - uint32_t _width - , uint32_t _height - , uint32_t _pitch - , TextureFormat::Enum _format - , bool _yflip - ) = 0; - - /// Called when capture ends. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.capture_end`. - /// - virtual void captureEnd() = 0; - - /// Captured frame. - /// - /// @param[in] _data Image data. - /// @param[in] _size Image size. - /// - /// @attention C99 equivalent is `bgfx_callback_vtbl.capture_frame`. - /// - virtual void captureFrame(const void* _data, uint32_t _size) = 0; - }; - - inline CallbackI::~CallbackI() - { - } - - /// Memory release callback. - /// - /// @attention C99 equivalent is `bgfx_release_fn_t`. - /// - typedef void (*ReleaseFn)(void* _ptr, void* _userData); - - /// Memory obtained by calling `bgfx::alloc`, `bgfx::copy`, or `bgfx::makeRef`. - /// - /// @attention C99 equivalent is `bgfx_memory_t`. - /// - struct Memory - { - uint8_t* data; - uint32_t size; - }; - - /// Renderer capabilities. - /// - /// @attention C99 equivalent is `bgfx_caps_t`. - /// - struct Caps - { - /// Renderer backend type. See: `bgfx::RendererType` - RendererType::Enum rendererType; - - /// Supported functionality. - /// - /// @attention See BGFX_CAPS_* flags at https://bkaradzic.github.io/bgfx/bgfx.html#available-caps - /// - uint64_t supported; - - uint32_t maxDrawCalls; //!< Maximum draw calls. - uint16_t maxTextureSize; //!< Maximum texture size. - uint16_t maxViews; //!< Maximum views. - uint8_t maxFBAttachments; //!< Maximum frame buffer attachments. - uint8_t numGPUs; //!< Number of enumerated GPUs. - uint16_t vendorId; //!< Selected GPU vendor id. - uint16_t deviceId; //!< Selected GPU device id. - bool homogeneousDepth; //!< True when NDC depth is in [-1, 1] range. - bool originBottomLeft; //!< True when NDC origin is at bottom left. - - /// GPU info. - /// - /// @attention C99 equivalent is `bgfx_caps_gpu_t`. - /// - struct GPU - { - uint16_t vendorId; - uint16_t deviceId; - }; - - GPU gpu[4]; //!< Enumerated GPUs. - - /// Supported texture formats. - /// - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported - /// - `BGFX_CAPS_FORMAT_TEXTURE_2D` - supported - /// - `BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED` - emulated - /// - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture - uint16_t formats[TextureFormat::Count]; - }; - - /// Transient index buffer. - /// - /// @attention C99 equivalent is `bgfx_transient_index_buffer_t`. - /// - struct TransientIndexBuffer - { - uint8_t* data; //!< Pointer to data. - uint32_t size; //!< Data size. - uint32_t startIndex; //!< First index. - IndexBufferHandle handle; //!< Index buffer handle. - }; - - /// Transient vertex buffer. - /// - /// @attention C99 equivalent is `bgfx_transient_vertex_buffer_t`. - /// - struct TransientVertexBuffer - { - uint8_t* data; //!< Pointer to data. - uint32_t size; //!< Data size. - uint32_t startVertex; //!< First vertex. - uint16_t stride; //!< Vertex stride. - VertexBufferHandle handle; //!< Vertex buffer handle. - VertexDeclHandle decl; //!< Vertex declaration handle. - }; - - /// Instance data buffer info. - /// - /// @attention C99 equivalent is `bgfx_texture_info_t`. - /// - struct InstanceDataBuffer - { - uint8_t* data; //!< Pointer to data. - uint32_t size; //!< Data size. - uint32_t offset; //!< Offset in vertex buffer. - uint32_t num; //!< Number of instances. - uint16_t stride; //!< Vertex buffer stride. - VertexBufferHandle handle; //!< Vertex buffer object handle. - }; - - /// Texture info. - /// - /// @attention C99 equivalent is `bgfx_texture_info_t`. - /// - struct TextureInfo - { - TextureFormat::Enum format; //!< Texture format. - uint32_t storageSize; //!< Total amount of bytes required to store texture. - uint16_t width; //!< Texture width. - uint16_t height; //!< Texture height. - uint16_t depth; //!< Texture depth. - uint8_t numMips; //!< Number of MIP maps. - uint8_t bitsPerPixel; //!< Format bits per pixel. - bool cubeMap; //!< Texture is cubemap. - }; - - /// Frame buffer texture attachemnt info. - /// - /// @attention C99 equivalent is `bgfx_attachment_t`. - /// - struct Attachment - { - TextureHandle handle; //!< Texture handle. - uint16_t mip; //!< Mip level. - uint16_t layer; //!< Cubemap side or depth layer/slice. - }; - - /// Transform data. - /// - /// @attention C99 equivalent is `bgfx_transform_t`. - /// - struct Transform - { - float* data; //!< Pointer to first matrix. - uint16_t num; //!< Number of matrices. - }; - - /// HMD info. - /// - /// @attention C99 equivalent is `bgfx_hmd_t`. - /// - struct HMD - { - /// Eye - /// - /// @attention C99 equivalent is `bgfx_hmd_eye_t`. - /// - struct Eye - { - float rotation[4]; //!< Eye rotation represented as quaternion. - float translation[3]; //!< Eye translation. - float fov[4]; //!< Field of view (up, down, left, right). - float viewOffset[3]; //!< Eye view matrix translation adjustment. - float projection[16]; //!< Eye projection matrix - float pixelsPerTanAngle[2]; //!< - }; - - Eye eye[2]; - uint16_t width; //!< Framebuffer width. - uint16_t height; //!< Framebuffer width. - uint32_t deviceWidth; //!< Device resolution width - uint32_t deviceHeight; //!< Device resolution height - uint8_t flags; //!< Status flags - }; - - /// Renderer statistics data. - /// - /// @attention C99 equivalent is `bgfx_stats_t`. - /// - struct Stats - { - uint64_t cpuTimeBegin; //!< CPU frame begin time. - uint64_t cpuTimeEnd; //!< CPU frame end time. - uint64_t cpuTimerFreq; //!< CPU timer frequency. - - uint64_t gpuTimeBegin; //!< GPU frame begin time. - uint64_t gpuTimeEnd; //!< GPU frame end time. - uint64_t gpuTimerFreq; //!< GPU timer frequency. - }; - - /// Vertex declaration. - /// - /// @attention C99 equivalent is `bgfx_vertex_decl_t`. - /// - struct VertexDecl - { - VertexDecl(); - - /// Start VertexDecl. - /// - /// @attention C99 equivalent is `bgfx_vertex_decl_begin`. - /// - VertexDecl& begin(RendererType::Enum _renderer = RendererType::Null); - - /// End VertexDecl. - /// - /// @attention C99 equivalent is `bgfx_vertex_decl_begin`. - /// - void end(); - - /// Add attribute to VertexDecl. - /// - /// @param[in] _attrib Attribute semantics. See: `bgfx::Attrib` - /// @param[in] _num Number of elements 1, 2, 3 or 4. - /// @param[in] _type Element type. - /// @param[in] _normalized When using fixed point AttribType (f.e. Uint8) - /// value will be normalized for vertex shader usage. When normalized - /// is set to true, AttribType::Uint8 value in range 0-255 will be - /// in range 0.0-1.0 in vertex shader. - /// @param[in] _asInt Packaging rule for vertexPack, vertexUnpack, and - /// vertexConvert for AttribType::Uint8 and AttribType::Int16. - /// Unpacking code must be implemented inside vertex shader. - /// - /// @remarks - /// Must be called between begin/end. - /// - /// @attention C99 equivalent is `bgfx_vertex_decl_add`. - /// - VertexDecl& add( - Attrib::Enum _attrib - , uint8_t _num - , AttribType::Enum _type - , bool _normalized = false - , bool _asInt = false - ); - - /// Skip _num bytes in vertex stream. - /// - /// @attention C99 equivalent is `bgfx_vertex_decl_skip`. - /// - VertexDecl& skip(uint8_t _num); - - /// Decode attribute. - /// - /// @attention C99 equivalent is ``. - /// - void decode( - Attrib::Enum _attrib - , uint8_t& _num - , AttribType::Enum& _type - , bool& _normalized - , bool& _asInt - ) const; - - /// Returns true if VertexDecl contains attribute. - bool has(Attrib::Enum _attrib) const { return UINT16_MAX != m_attributes[_attrib]; } - - /// Returns relative attribute offset from the vertex. - uint16_t getOffset(Attrib::Enum _attrib) const { return m_offset[_attrib]; } - - /// Returns vertex stride. - uint16_t getStride() const { return m_stride; } - - /// Returns size of vertex buffer for number of vertices. - uint32_t getSize(uint32_t _num) const { return _num*m_stride; } - - uint32_t m_hash; - uint16_t m_stride; - uint16_t m_offset[Attrib::Count]; - uint16_t m_attributes[Attrib::Count]; - }; - - /// Pack vec4 into vertex stream format. - /// - /// @attention C99 equivalent is `bgfx_vertex_pack`. - /// - void vertexPack( - const float _input[4] - , bool _inputNormalized - , Attrib::Enum _attr - , const VertexDecl& _decl - , void* _data - , uint32_t _index = 0 - ); - - /// Unpack vec4 from vertex stream format. - /// - /// @attention C99 equivalent is `bgfx_vertex_unpack`. - /// - void vertexUnpack( - float _output[4] - , Attrib::Enum _attr - , const VertexDecl& _decl - , const void* _data - , uint32_t _index = 0 - ); - - /// Converts vertex stream data from one vertex stream format to another. - /// - /// @param[in] _destDecl Destination vertex stream declaration. - /// @param[in] _destData Destination vertex stream. - /// @param[in] _srcDecl Source vertex stream declaration. - /// @param[in] _srcData Source vertex stream data. - /// @param[in] _num Number of vertices to convert from source to destination. - /// - /// @attention C99 equivalent is `bgfx_vertex_convert`. - /// - void vertexConvert( - const VertexDecl& _destDecl - , void* _destData - , const VertexDecl& _srcDecl - , const void* _srcData - , uint32_t _num = 1 - ); - - /// Weld vertices. - /// - /// @param[in] _output Welded vertices remapping table. The size of buffer - /// must be the same as number of vertices. - /// @param[in] _decl Vertex stream declaration. - /// @param[in] _data Vertex stream. - /// @param[in] _num Number of vertices in vertex stream. - /// @param[in] _epsilon Error tolerance for vertex position comparison. - /// @returns Number of unique vertices after vertex welding. - /// - /// @attention C99 equivalent is `bgfx_weld_vertices`. - /// - uint16_t weldVertices( - uint16_t* _output - , const VertexDecl& _decl - , const void* _data - , uint16_t _num - , float _epsilon = 0.001f - ); - - /// Convert index buffer for use with different primitive topologies. - /// - /// @param[in] _conversion Conversion type, see `TopologyConvert::Enum`. - /// @param[in] _dst Destination index buffer. If this argument it NULL - /// function will return number of indices after conversion. - /// @param[in] _dstSize Destination index buffer in bytes. It must be - /// large enough to contain output indices. If destination size is - /// insufficient index buffer will be truncated. - /// @param[in] _indices Source indices. - /// @param[in] _numIndices Number of input indices. - /// @param[in] _index32 Set to `true` if input indices are 32-bit. - /// - /// @returns Number of output indices after conversion. - /// - /// @attention C99 equivalent is `bgfx_topology_convert`. - /// - uint32_t topologyConvert( - TopologyConvert::Enum _conversion - , void* _dst - , uint32_t _dstSize - , const void* _indices - , uint32_t _numIndices - , bool _index32 - ); - - /// Swizzle RGBA8 image to BGRA8. - /// - /// @param[in] _width Width of input image (pixels). - /// @param[in] _height Height of input image (pixels). - /// @param[in] _pitch Pitch of input image (bytes). - /// @param[in] _src Source image. - /// @param[in] _dst Destination image. Must be the same size as input image. - /// _dst might be pointer to the same memory as _src. - /// - /// @attention C99 equivalent is `bgfx_image_swizzle_bgra8`. - /// - void imageSwizzleBgra8( - uint32_t _width - , uint32_t _height - , uint32_t _pitch - , const void* _src - , void* _dst - ); - - /// Downsample RGBA8 image with 2x2 pixel average filter. - /// - /// @param[in] _width Width of input image (pixels). - /// @param[in] _height Height of input image (pixels). - /// @param[in] _pitch Pitch of input image (bytes). - /// @param[in] _src Source image. - /// @param[in] _dst Destination image. Must be at least quarter size of - /// input image. _dst might be pointer to the same memory as _src. - /// - /// @attention C99 equivalent is `bgfx_image_rgba8_downsample_2x2`. - /// - void imageRgba8Downsample2x2( - uint32_t _width - , uint32_t _height - , uint32_t _pitch - , const void* _src - , void* _dst - ); - - /// Returns supported backend API renderers. - /// - /// @attention C99 equivalent is `bgfx_get_supported_renderers`. - /// - uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]); - - /// Returns name of renderer. - /// - /// @attention C99 equivalent is `bgfx_get_renderer_name`. - /// - const char* getRendererName(RendererType::Enum _type); - - /// Initialize bgfx library. - /// - /// @param[in] _type Select rendering backend. When set to RendererType::Count - /// default rendering backend will be selected. - /// See: `bgfx::RendererType` - /// - /// @param[in] _vendorId Vendor PCI id. If set to `BGFX_PCI_ID_NONE` it will select the first - /// device. - /// - `BGFX_PCI_ID_NONE` - Autoselect adapter. - /// - `BGFX_PCI_ID_SOFTWARE_RASTERIZER` - Software rasterizer. - /// - `BGFX_PCI_ID_AMD` - AMD adapter. - /// - `BGFX_PCI_ID_INTEL` - Intel adapter. - /// - `BGFX_PCI_ID_NVIDIA` - nVidia adapter. - /// - /// @param[in] _deviceId Device id. If set to 0 it will select first device, or device with - /// matching id. - /// - /// @param[in] _callback Provide application specific callback interface. - /// See: `bgfx::CallbackI` - /// - /// @param[in] _reallocator Custom allocator. When custom allocator is not - /// specified, library uses default CRT allocator. The library assumes - /// custom allocator is thread safe. - /// - /// @returns `true` if initialization was successful. - /// - /// @attention C99 equivalent is `bgfx_init`. - /// - bool init( - RendererType::Enum _type = RendererType::Count - , uint16_t _vendorId = BGFX_PCI_ID_NONE - , uint16_t _deviceId = 0 - , CallbackI* _callback = NULL - , bx::AllocatorI* _reallocator = NULL - ); - - /// Shutdown bgfx library. - /// - /// @attention C99 equivalent is `bgfx_shutdown`. - /// - void shutdown(); - - /// Reset graphic settings and back-buffer size. - /// - /// @param[in] _width Back-buffer width. - /// @param[in] _height Back-buffer height. - /// @param[in] _flags See: `BGFX_RESET_*` for more info. - /// - `BGFX_RESET_NONE` - No reset flags. - /// - `BGFX_RESET_FULLSCREEN` - Not supported yet. - /// - `BGFX_RESET_MSAA_X[2/4/8/16]` - Enable 2, 4, 8 or 16 x MSAA. - /// - `BGFX_RESET_VSYNC` - Enable V-Sync. - /// - `BGFX_RESET_MAXANISOTROPY` - Turn on/off max anisotropy. - /// - `BGFX_RESET_CAPTURE` - Begin screen capture. - /// - `BGFX_RESET_HMD` - HMD stereo rendering. - /// - `BGFX_RESET_HMD_DEBUG` - HMD stereo rendering debug mode. - /// - `BGFX_RESET_HMD_RECENTER` - HMD calibration. - /// - `BGFX_RESET_FLUSH_AFTER_RENDER` - Flush rendering after submitting to GPU. - /// - `BGFX_RESET_FLIP_AFTER_RENDER` - This flag specifies where flip - /// occurs. Default behavior is that flip occurs before rendering new - /// frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`. - /// - `BGFX_RESET_SRGB_BACKBUFFER` - Enable sRGB backbuffer. - /// - /// @attention This call doesn't actually change window size, it just - /// resizes back-buffer. Windowing code has to change window size. - /// - /// @attention C99 equivalent is `bgfx_reset`. - /// - void reset(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE); - - /// Advance to next frame. When using multithreaded renderer, this call - /// just swaps internal buffers, kicks render thread, and returns. In - /// singlethreaded renderer this call does frame rendering. - /// - /// @returns Current frame number. This might be used in conjunction with - /// double/multi buffering data outside the library and passing it to - /// library via `bgfx::makeRef` calls. - /// - /// @attention C99 equivalent is `bgfx_frame`. - /// - uint32_t frame(); - - /// Returns current renderer backend API type. - /// - /// @remarks - /// Library must be initialized. - /// - /// @attention C99 equivalent is `bgfx_get_renderer_type`. - /// - RendererType::Enum getRendererType(); - - /// Returns renderer capabilities. - /// - /// @returns Pointer to static `bgfx::Caps` structure. - /// - /// @remarks - /// Library must be initialized. - /// - /// @attention C99 equivalent is `bgfx_get_caps`. - /// - const Caps* getCaps(); - - /// Returns HMD info. - /// - /// @attention C99 equivalent is `bgfx_get_hmd`. - /// - const HMD* getHMD(); - - /// Returns performance counters. - /// - const Stats* getStats(); - - /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx. - /// - /// @attention C99 equivalent is `bgfx_alloc`. - /// - const Memory* alloc(uint32_t _size); - - /// Allocate buffer and copy data into it. Data will be freed inside bgfx. - /// - /// @attention C99 equivalent is `bgfx_copy`. - /// - const Memory* copy(const void* _data, uint32_t _size); - - /// Make reference to data to pass to bgfx. Unlike `bgfx::alloc` this call - /// doesn't allocate memory for data. It just copies pointer to data. You - /// can pass `ReleaseFn` function pointer to release this memory after it's - /// consumed, or you must make sure data is available for at least 2 - /// `bgfx::frame` calls. `ReleaseFn` function must be able to be called - /// called from any thread. - /// - /// @attention C99 equivalent are `bgfx_make_ref`, `bgfx_make_ref_release`. - /// - const Memory* makeRef( - const void* _data - , uint32_t _size - , ReleaseFn _releaseFn = NULL - , void* _userData = NULL - ); - - /// Set debug flags. - /// - /// @param[in] _debug Available flags: - /// - `BGFX_DEBUG_IFH` - Infinitely fast hardware. When this flag is set - /// all rendering calls will be skipped. It's useful when profiling - /// to quickly assess bottleneck between CPU and GPU. - /// - `BGFX_DEBUG_STATS` - Display internal statistics. - /// - `BGFX_DEBUG_TEXT` - Display debug text. - /// - `BGFX_DEBUG_WIREFRAME` - Wireframe rendering. All rendering - /// primitives will be rendered as lines. - /// - /// @attention C99 equivalent is `bgfx_set_debug`. - /// - void setDebug(uint32_t _debug); - - /// Clear internal debug text buffer. - /// - /// @attention C99 equivalent is `bgfx_dbg_text_clear`. - /// - void dbgTextClear(uint8_t _attr = 0, bool _small = false); - - /// Print into internal debug text buffer. - /// - /// @attention C99 equivalent is `bgfx_dbg_text_printf`. - /// - void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...); - - /// Draw image into internal debug text buffer. - /// - /// @param[in] _x X position from top-left. - /// @param[in] _y Y position from top-left. - /// @param[in] _width Image width. - /// @param[in] _height Image height. - /// @param[in] _data Raw image data (character/attribute raw encoding). - /// @param[in] _pitch Image pitch in bytes. - /// - /// @attention C99 equivalent is `bgfx_dbg_text_image`. - /// - void dbgTextImage( - uint16_t _x - , uint16_t _y - , uint16_t _width - , uint16_t _height - , const void* _data - , uint16_t _pitch - ); - - /// Create static index buffer. - /// - /// @param[in] _mem Index buffer data. - /// @param[in] _flags Buffer creation flags. - /// - `BGFX_BUFFER_NONE` - No flags. - /// - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. - /// - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer - /// is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. - /// - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. - /// - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if different amount of - /// data is passed. If this flag is not specified if more data is passed on update buffer - /// will be trimmed to fit existing buffer size. This flag has effect only on dynamic - /// buffers. - /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on - /// index buffers. - /// - /// @attention C99 equivalent is `bgfx_create_index_buffer`. - /// - IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags = BGFX_BUFFER_NONE); - - /// Destroy static index buffer. - /// - /// @attention C99 equivalent is `bgfx_destroy_index_buffer`. - /// - void destroyIndexBuffer(IndexBufferHandle _handle); - - /// Create static vertex buffer. - /// - /// @param[in] _mem Vertex buffer data. - /// @param[in] _decl Vertex declaration. - /// @param[in] _flags Buffer creation flags. - /// - `BGFX_BUFFER_NONE` - No flags. - /// - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. - /// - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer - /// is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. - /// - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. - /// - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if different amount of - /// data is passed. If this flag is not specified if more data is passed on update buffer - /// will be trimmed to fit existing buffer size. This flag has effect only on dynamic - /// buffers. - /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on - /// index buffers. - /// @returns Static vertex buffer handle. - /// - /// @attention C99 equivalent is `bgfx_create_vertex_buffer`. - /// - VertexBufferHandle createVertexBuffer( - const Memory* _mem - , const VertexDecl& _decl - , uint16_t _flags = BGFX_BUFFER_NONE - ); - - /// Destroy static vertex buffer. - /// - /// @param[in] _handle Static vertex buffer handle. - /// - /// @attention C99 equivalent is `bgfx_destroy_vertex_buffer`. - /// - void destroyVertexBuffer(VertexBufferHandle _handle); - - /// Create empty dynamic index buffer. - /// - /// @param[in] _num Number of indices. - /// @param[in] _flags Buffer creation flags. - /// - `BGFX_BUFFER_NONE` - No flags. - /// - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. - /// - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer - /// is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. - /// - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. - /// - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if different amount of - /// data is passed. If this flag is not specified if more data is passed on update buffer - /// will be trimmed to fit existing buffer size. This flag has effect only on dynamic - /// buffers. - /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on - /// index buffers. - /// - /// @attention C99 equivalent is `bgfx_create_dynamic_index_buffer`. - /// - DynamicIndexBufferHandle createDynamicIndexBuffer( - uint32_t _num - , uint16_t _flags = BGFX_BUFFER_NONE - ); - - /// Create dynamic index buffer and initialized it. - /// - /// @param[in] _mem Index buffer data. - /// @param[in] _flags Buffer creation flags. - /// - `BGFX_BUFFER_NONE` - No flags. - /// - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. - /// - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer - /// is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. - /// - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. - /// - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if different amount of - /// data is passed. If this flag is not specified if more data is passed on update buffer - /// will be trimmed to fit existing buffer size. This flag has effect only on dynamic - /// buffers. - /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on - /// index buffers. - /// - /// @attention C99 equivalent is `bgfx_create_dynamic_index_buffer_mem`. - /// - DynamicIndexBufferHandle createDynamicIndexBuffer( - const Memory* _mem - , uint16_t _flags = BGFX_BUFFER_NONE - ); - - /// Update dynamic index buffer. - /// - /// @param[in] _handle Dynamic index buffer handle. - /// @param[in] _startIndex Start index. - /// @param[in] _mem Index buffer data. - /// - /// @attention C99 equivalent is `bgfx_update_dynamic_index_buffer`. - /// - void updateDynamicIndexBuffer( - DynamicIndexBufferHandle _handle - , uint32_t _startIndex - , const Memory* _mem - ); - - /// Destroy dynamic index buffer. - /// - /// @param[in] _handle Dynamic index buffer handle. - /// - /// @attention C99 equivalent is `bgfx_destroy_dynamic_index_buffer`. - /// - void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle); - - /// Create empty dynamic vertex buffer. - /// - /// @param[in] _num Number of vertices. - /// @param[in] _decl Vertex declaration. - /// @param[in] _flags Buffer creation flags. - /// - `BGFX_BUFFER_NONE` - No flags. - /// - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. - /// - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer - /// is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. - /// - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. - /// - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if different amount of - /// data is passed. If this flag is not specified if more data is passed on update buffer - /// will be trimmed to fit existing buffer size. This flag has effect only on dynamic - /// buffers. - /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on - /// index buffers. - /// - /// @attention C99 equivalent is `bgfx_create_dynamic_vertex_buffer`. - /// - DynamicVertexBufferHandle createDynamicVertexBuffer( - uint32_t _num - , const VertexDecl& _decl - , uint16_t _flags = BGFX_BUFFER_NONE - ); - - /// Create dynamic vertex buffer and initialize it. - /// - /// @param[in] _mem Vertex buffer data. - /// @param[in] _decl Vertex declaration. - /// @param[in] _flags Buffer creation flags. - /// - `BGFX_BUFFER_NONE` - No flags. - /// - `BGFX_BUFFER_COMPUTE_READ` - Buffer will be read from by compute shader. - /// - `BGFX_BUFFER_COMPUTE_WRITE` - Buffer will be written into by compute shader. When buffer - /// is created with `BGFX_BUFFER_COMPUTE_WRITE` flag it cannot be updated from CPU. - /// - `BGFX_BUFFER_COMPUTE_READ_WRITE` - Buffer will be used for read/write by compute shader. - /// - `BGFX_BUFFER_ALLOW_RESIZE` - Buffer will resize on buffer update if different amount of - /// data is passed. If this flag is not specified if more data is passed on update buffer - /// will be trimmed to fit existing buffer size. This flag has effect only on dynamic - /// buffers. - /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on - /// index buffers. - /// - /// @attention C99 equivalent is `bgfx_create_dynamic_vertex_buffer_mem`. - /// - DynamicVertexBufferHandle createDynamicVertexBuffer( - const Memory* _mem - , const VertexDecl& _decl - , uint16_t _flags = BGFX_BUFFER_NONE - ); - - /// Update dynamic vertex buffer. - /// - /// @param[in] _handle Dynamic vertex buffer handle. - /// @param[in] _startVertex Start vertex. - /// @param[in] _mem Vertex buffer data. - /// - /// @attention C99 equivalent is `bgfx_update_dynamic_vertex_buffer`. - /// - void updateDynamicVertexBuffer( - DynamicVertexBufferHandle _handle - , uint32_t _startVertex - , const Memory* _mem - ); - - /// Destroy dynamic vertex buffer. - /// - /// @attention C99 equivalent is `bgfx_destroy_dynamic_vertex_buffer`. - /// - void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle); - - /// Returns true if internal transient index buffer has enough space. - /// - /// @param[in] _num Number of indices. - /// - /// @attention C99 equivalent is `bgfx_check_avail_transient_index_buffer`. - /// - bool checkAvailTransientIndexBuffer(uint32_t _num); - - /// Returns true if internal transient vertex buffer has enough space. - /// - /// @param[in] _num Number of vertices. - /// @param[in] _decl Vertex declaration. - /// - /// @attention C99 equivalent is `bgfx_check_avail_transient_vertex_buffer`. - /// - bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl); - - /// Returns true if internal instance data buffer has enough space. - /// - /// @param[in] _num Number of instances. - /// @param[in] _stride Stride per instance. - /// - /// @attention C99 equivalent is `bgfx_check_avail_instance_data_buffer`. - /// - bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride); - - /// Returns true if both internal transient index and vertex buffer have - /// enough space. - /// - /// @param[in] _numVertices Number of vertices. - /// @param[in] _decl Vertex declaration. - /// @param[in] _numIndices Number of indices. - /// - /// @attention C99 equivalent is `bgfx_check_avail_transient_buffers`. - /// - bool checkAvailTransientBuffers( - uint32_t _numVertices - , const VertexDecl& _decl - , uint32_t _numIndices - ); - - /// Allocate transient index buffer. - /// - /// @param[out] _tib TransientIndexBuffer structure is filled and is valid - /// for the duration of frame, and it can be reused for multiple draw - /// calls. - /// @param[in] _num Number of indices to allocate. - /// - /// @remarks - /// 1. You must call setIndexBuffer after alloc in order to avoid memory - /// leak. - /// 2. Only 16-bit index buffer is supported. - /// - /// @attention C99 equivalent is `bgfx_alloc_transient_index_buffer`. - /// - void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num); - - /// Allocate transient vertex buffer. - /// - /// @param[out] _tvb TransientVertexBuffer structure is filled and is valid - /// for the duration of frame, and it can be reused for multiple draw - /// calls. - /// @param[in] _num Number of vertices to allocate. - /// @param[in] _decl Vertex declaration. - /// - /// @remarks - /// You must call setVertexBuffer after alloc in order to avoid memory - /// leak. - /// - /// @attention C99 equivalent is `bgfx_alloc_transient_vertex_buffer`. - /// - void allocTransientVertexBuffer(TransientVertexBuffer* _tvb - , uint32_t _num - , const VertexDecl& _decl - ); - - /// Check for required space and allocate transient vertex and index - /// buffers. If both space requirements are satisfied function returns - /// true. - /// - /// @remarks - /// Only 16-bit index buffer is supported. - /// - /// @attention C99 equivalent is `bgfx_alloc_transient_buffers`. - /// - bool allocTransientBuffers(TransientVertexBuffer* _tvb - , const VertexDecl& _decl - , uint32_t _numVertices - , TransientIndexBuffer* _tib - , uint32_t _numIndices - ); - - /// Allocate instance data buffer. - /// - /// @remarks - /// You must call setInstanceDataBuffer after alloc in order to avoid - /// memory leak. - /// - /// @attention C99 equivalent is `bgfx_alloc_instance_data_buffer`. - /// - const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride); - - /// Create draw indirect buffer. - /// - /// @attention C99 equivalent is `bgfx_create_indirect_buffer`. - /// - IndirectBufferHandle createIndirectBuffer(uint32_t _num); - - /// Destroy draw indirect buffer. - /// - /// @attention C99 equivalent is `bgfx_destroy_indirect_buffer`. - /// - void destroyIndirectBuffer(IndirectBufferHandle _handle); - - /// Create shader from memory buffer. - /// - /// @attention C99 equivalent is `bgfx_create_shader`. - /// - ShaderHandle createShader(const Memory* _mem); - - /// Returns num of uniforms, and uniform handles used inside shader. - /// - /// @param[in] _handle Shader handle. - /// @param[in] _uniforms UniformHandle array where data will be stored. - /// @param[in] _max Maximum capacity of array. - /// @returns Number of uniforms used by shader. - /// - /// @remarks - /// Only non-predefined uniforms are returned. - /// - /// @attention C99 equivalent is `bgfx_get_shader_uniforms`. - /// - uint16_t getShaderUniforms( - ShaderHandle _handle - , UniformHandle* _uniforms = NULL - , uint16_t _max = 0 - ); - - /// Destroy shader. Once program is created with shader it is safe to - /// destroy shader. - /// - /// @attention C99 equivalent is `bgfx_destroy_shader`. - /// - void destroyShader(ShaderHandle _handle); - - /// Create program with vertex and fragment shaders. - /// - /// @param[in] _vsh Vertex shader. - /// @param[in] _fsh Fragment shader. - /// @param[in] _destroyShaders If true, shaders will be destroyed when - /// program is destroyed. - /// @returns Program handle if vertex shader output and fragment shader - /// input are matching, otherwise returns invalid program handle. - /// - /// @attention C99 equivalent is `bgfx_create_program`. - /// - ProgramHandle createProgram( - ShaderHandle _vsh - , ShaderHandle _fsh - , bool _destroyShaders = false - ); - - /// Create program with compute shader. - /// - /// @param[in] _csh Compute shader. - /// @param[in] _destroyShader If true, shader will be destroyed when - /// program is destroyed. - /// @returns Program handle. - /// - /// @attention C99 equivalent is `bgfx_create_compute_program`. - /// - ProgramHandle createProgram( - ShaderHandle _csh - , bool _destroyShader = false - ); - - /// Destroy program. - /// - /// @attention C99 equivalent is `bgfx_destroy_program`. - /// - void destroyProgram(ProgramHandle _handle); - - /// Calculate amount of memory required for texture. - /// - /// @attention C99 equivalent is `bgfx_calc_texture_size`. - /// - void calcTextureSize( - TextureInfo& _info - , uint16_t _width - , uint16_t _height - , uint16_t _depth - , bool _cubeMap - , uint8_t _numMips - , TextureFormat::Enum _format - ); - - /// Create texture from memory buffer. - /// - /// @param[in] _mem DDS, KTX or PVR texture data. - /// @param[in] _flags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @param[in] _skip Skip top level mips when parsing texture. - /// @param[out] _info When non-`NULL` is specified it returns parsed texture information. - /// @returns Texture handle. - /// - /// @attention C99 equivalent is `bgfx_create_texture`. - /// - TextureHandle createTexture( - const Memory* _mem - , uint32_t _flags = BGFX_TEXTURE_NONE - , uint8_t _skip = 0 - , TextureInfo* _info = NULL - ); - - /// Create 2D texture. - /// - /// @param[in] _width Width. - /// @param[in] _height Height. - /// @param[in] _numMips Number of mip-maps. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// @param[in] _flags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @param[in] _mem Texture data. If `_mem` is non-NULL, created texture will be immutable. - /// - /// @attention C99 equivalent is `bgfx_create_texture_2d`. - /// - TextureHandle createTexture2D( - uint16_t _width - , uint16_t _height - , uint8_t _numMips - , TextureFormat::Enum _format - , uint32_t _flags = BGFX_TEXTURE_NONE - , const Memory* _mem = NULL - ); - - /// Create frame buffer with size based on backbuffer ratio. Frame buffer will maintain ratio - /// if back buffer resolution changes. - /// - /// @param[in] _ratio Frame buffer size in respect to back-buffer size. See: - /// `BackbufferRatio::Enum`. - /// @param[in] _numMips Number of mip-maps. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// @param[in] _flags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @attention C99 equivalent is `bgfx_create_texture_2d_scaled`. - /// - TextureHandle createTexture2D( - BackbufferRatio::Enum _ratio - , uint8_t _numMips - , TextureFormat::Enum _format - , uint32_t _flags = BGFX_TEXTURE_NONE - ); - - /// Create 3D texture. - /// - /// @param[in] _width Width. - /// @param[in] _height Height. - /// @param[in] _depth Depth. - /// @param[in] _numMips Number of mip-maps. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// @param[in] _flags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @param[in] _mem Texture data. If `_mem` is non-NULL, created texture will be immutable. - /// - /// @attention C99 equivalent is `bgfx_create_texture_3d`. - /// - TextureHandle createTexture3D( - uint16_t _width - , uint16_t _height - , uint16_t _depth - , uint8_t _numMips - , TextureFormat::Enum _format - , uint32_t _flags = BGFX_TEXTURE_NONE - , const Memory* _mem = NULL - ); - - /// Create Cube texture. - /// - /// @param[in] _size Cube side size. - /// @param[in] _numMips Number of mip-maps. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// @param[in] _flags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @param[in] _mem Texture data. If `_mem` is non-NULL, created texture will be immutable. - /// - /// @attention C99 equivalent is `bgfx_create_texture_cube`. - /// - TextureHandle createTextureCube( - uint16_t _size - , uint8_t _numMips - , TextureFormat::Enum _format - , uint32_t _flags = BGFX_TEXTURE_NONE - , const Memory* _mem = NULL - ); - - /// Update 2D texture. - /// - /// @param[in] _handle Texture handle. - /// @param[in] _mip Mip level. - /// @param[in] _x X offset in texture. - /// @param[in] _y Y offset in texture. - /// @param[in] _width Width of texture block. - /// @param[in] _height Height of texture block. - /// @param[in] _mem Texture update data. - /// @param[in] _pitch Pitch of input image (bytes). When _pitch is set to - /// UINT16_MAX, it will be calculated internally based on _width. - /// - /// @attention C99 equivalent is `bgfx_update_texture_2d`. - /// - void updateTexture2D( - TextureHandle _handle - , uint8_t _mip - , uint16_t _x - , uint16_t _y - , uint16_t _width - , uint16_t _height - , const Memory* _mem - , uint16_t _pitch = UINT16_MAX - ); - - /// Update 3D texture. - /// - /// @param[in] _handle Texture handle. - /// @param[in] _mip Mip level. - /// @param[in] _x X offset in texture. - /// @param[in] _y Y offset in texture. - /// @param[in] _z Z offset in texture. - /// @param[in] _width Width of texture block. - /// @param[in] _height Height of texture block. - /// @param[in] _depth Depth of texture block. - /// @param[in] _mem Texture update data. - /// - /// @attention C99 equivalent is `bgfx_update_texture_3d`. - /// - void updateTexture3D( - TextureHandle _handle - , uint8_t _mip - , uint16_t _x - , uint16_t _y - , uint16_t _z - , uint16_t _width - , uint16_t _height - , uint16_t _depth - , const Memory* _mem - ); - - /// Update Cube texture. - /// - /// @param[in] _handle Texture handle. - /// @param[in] _side Cubemap side `BGFX_CUBE_MAP__`, - /// where 0 is +X, 1 is -X, 2 is +Y, 3 is -Y, 4 is +Z, and 5 is -Z. - /// - /// +----------+ - /// |-z 2| - /// | ^ +y | - /// | | | - /// | +---->+x | - /// +----------+----------+----------+----------+ - /// |+y 1|+y 4|+y 0|+y 5| - /// | ^ -x | ^ +z | ^ +x | ^ -z | - /// | | | | | | | | | - /// | +---->+z | +---->+x | +---->-z | +---->-x | - /// +----------+----------+----------+----------+ - /// |+z 3| - /// | ^ -y | - /// | | | - /// | +---->+x | - /// +----------+ - /// - /// @param[in] _mip Mip level. - /// @param[in] _x X offset in texture. - /// @param[in] _y Y offset in texture. - /// @param[in] _width Width of texture block. - /// @param[in] _height Height of texture block. - /// @param[in] _mem Texture update data. - /// @param[in] _pitch Pitch of input image (bytes). When _pitch is set to - /// UINT16_MAX, it will be calculated internally based on _width. - /// - /// @attention C99 equivalent is `bgfx_update_texture_cube`. - /// - void updateTextureCube( - TextureHandle _handle - , uint8_t _side - , uint8_t _mip - , uint16_t _x - , uint16_t _y - , uint16_t _width - , uint16_t _height - , const Memory* _mem - , uint16_t _pitch = UINT16_MAX - ); - - /// Read back texture content. - /// - /// @param[in] _handle Texture handle. - /// @param[in] _data Destination buffer. - /// - /// @attention Texture must be created with `BGFX_TEXTURE_READ_BACK` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_READ_BACK`. - /// @attention C99 equivalent is `bgfx_read_texture`. - /// - void readTexture(TextureHandle _handle, void* _data); - - /// Read back texture content. - /// - /// @param[in] _handle Frame buffer handle. - /// @param[in] _attachment Frame buffer attachment index. - /// @param[in] _data Destination buffer. - /// - /// @attention Texture must be created with `BGFX_TEXTURE_READ_BACK` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_READ_BACK`. - /// @attention C99 equivalent is `bgfx_read_frame_buffer`. - /// - void readTexture(FrameBufferHandle _handle, uint8_t _attachment, void* _data); - - /// Destroy texture. - /// - /// @param[in] _handle Texture handle. - /// - /// @attention C99 equivalent is `bgfx_destroy_texture`. - /// - void destroyTexture(TextureHandle _handle); - - /// Create frame buffer (simple). - /// - /// @param[in] _width Texture width. - /// @param[in] _height Texture height. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// @param[in] _textureFlags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @attention C99 equivalent is `bgfx_create_frame_buffer`. - /// - FrameBufferHandle createFrameBuffer( - uint16_t _width - , uint16_t _height - , TextureFormat::Enum _format - , uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP - ); - - /// Create frame buffer with size based on backbuffer ratio. Frame buffer will maintain ratio - /// if back buffer resolution changes. - /// - /// @param[in] _ratio Frame buffer size in respect to back-buffer size. See: - /// `BackbufferRatio::Enum`. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// @param[in] _textureFlags Default texture sampling mode is linear, and wrap mode - /// is repeat. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @attention C99 equivalent is `bgfx_create_frame_buffer_scaled`. - /// - FrameBufferHandle createFrameBuffer( - BackbufferRatio::Enum _ratio - , TextureFormat::Enum _format - , uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP - ); - - /// Create frame buffer. - /// - /// @param[in] _num Number of texture attachments. - /// @param[in] _handles Texture attachments. - /// @param[in] _destroyTextures If true, textures will be destroyed when - /// frame buffer is destroyed. - /// - /// @attention C99 equivalent is `bgfx_create_frame_buffer_from_handles`. - /// - FrameBufferHandle createFrameBuffer( - uint8_t _num - , const TextureHandle* _handles - , bool _destroyTextures = false - ); - - /// Create frame buffer. - /// - /// @param[in] _num Number of texture attachments. - /// @param[in] _attachment Attachment texture info. See: `Attachment`. - /// @param[in] _destroyTextures If true, textures will be destroyed when - /// frame buffer is destroyed. - /// - /// @attention C99 equivalent is `bgfx_create_frame_buffer_from_handles`. - /// - FrameBufferHandle createFrameBuffer( - uint8_t _num - , const Attachment* _attachment - , bool _destroyTextures = false - ); - - /// Create frame buffer for multiple window rendering. - /// - /// @param[in] _nwh OS' target native window handle. - /// @param[in] _width Window back buffer width. - /// @param[in] _height Window back buffer height. - /// @param[in] _depthFormat Window back buffer depth format. - /// - /// @returns Handle to frame buffer object. - /// - /// @remarks - /// Frame buffer cannot be used for sampling. - /// - /// @attention C99 equivalent is `bgfx_create_frame_buffer_from_nwh`. - /// - FrameBufferHandle createFrameBuffer( - void* _nwh - , uint16_t _width - , uint16_t _height - , TextureFormat::Enum _depthFormat = TextureFormat::UnknownDepth - ); - - /// Destroy frame buffer. - /// - /// @attention C99 equivalent is `bgfx_destroy_frame_buffer`. - /// - void destroyFrameBuffer(FrameBufferHandle _handle); - - /// Create shader uniform parameter. - /// - /// @param[in] _name Uniform name in shader. - /// @param[in] _type Type of uniform (See: `bgfx::UniformType`). - /// @param[in] _num Number of elements in array. - /// - /// @returns Handle to uniform object. - /// - /// @remarks - /// Predefined uniforms (declared in `bgfx_shader.sh`): - /// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current - /// view. - /// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse - /// width and height - /// - `u_view mat4` - view matrix - /// - `u_invView mat4` - inverted view matrix - /// - `u_proj mat4` - projection matrix - /// - `u_invProj mat4` - inverted projection matrix - /// - `u_viewProj mat4` - concatenated view projection matrix - /// - `u_invViewProj mat4` - concatenated inverted view projection matrix - /// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices. - /// - `u_modelView mat4` - concatenated model view matrix, only first - /// model matrix from array is used. - /// - `u_modelViewProj mat4` - concatenated model view projection matrix. - /// - `u_alphaRef float` - alpha reference value for alpha test. - /// - /// @attention C99 equivalent is `bgfx_create_uniform`. - /// - UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1); - - /// Destroy shader uniform parameter. - /// - /// @param[in] _handle Handle to uniform object. - /// - /// @attention C99 equivalent is `bgfx_destroy_uniform`. - /// - void destroyUniform(UniformHandle _handle); - - /// Create occlusion query. - /// - /// @returns Handle to occlusion query object. - /// - /// @attention C99 equivalent is `bgfx_create_occlusion_query`. - /// - OcclusionQueryHandle createOcclusionQuery(); - - /// Retrieve occlusion query result from previous frame. - /// - /// @param[in] _handle Handle to occlusion query object. - /// @returns Occlusion query result. - /// - /// @attention C99 equivalent is `bgfx_get_result`. - /// - OcclusionQueryResult::Enum getResult(OcclusionQueryHandle _handle); - - /// Destroy occlusion query. - /// - /// @param[in] _handle Handle to occlusion query object. - /// - /// @attention C99 equivalent is `bgfx_destroy_occlusion_query`. - /// - void destroyOcclusionQuery(OcclusionQueryHandle _handle); - - /// Set palette color value. - /// - /// @param[in] _index Index into palette. - /// @param[in] _rgba Packed 32-bit RGBA value. - /// - /// @attention C99 equivalent is `bgfx_set_palette_color`. - /// - void setPaletteColor(uint8_t _index, uint32_t _rgba); - - /// Set palette color value. - /// - /// @param[in] _index Index into palette. - /// @param[in] _r, _g, _b, _a RGBA floating point values. - /// - /// @attention C99 equivalent is `bgfx_set_palette_color`. - /// - void setPaletteColor(uint8_t _index, float _r, float _g, float _b, float _a); - - /// Set palette color value. - /// - /// @param[in] _index Index into palette. - /// @param[in] _rgba RGBA floating point value. - /// - /// @attention C99 equivalent is `bgfx_set_palette_color`. - /// - void setPaletteColor(uint8_t _index, const float _rgba[4]); - - /// Set view name. - /// - /// @param[in] _id View id. - /// @param[in] _name View name. - /// - /// @remarks - /// This is debug only feature. - /// - /// In graphics debugger view name will appear as: - /// - /// "nnnce " - /// ^ ^^ ^ - /// | |+-- eye (L/R) - /// | +--- compute (C) - /// +------ view id - /// - /// @attention C99 equivalent is `bgfx_set_view_name`. - /// - void setViewName(uint8_t _id, const char* _name); - - /// Set view rectangle. Draw primitive outside view will be clipped. - /// - /// @param[in] _id View id. - /// @param[in] _x Position x from the left corner of the window. - /// @param[in] _y Position y from the top corner of the window. - /// @param[in] _width Width of view port region. - /// @param[in] _height Height of view port region. - /// - /// @attention C99 equivalent is `bgfx_set_view_rect`. - /// - void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); - - /// @attention C99 equivalent is `bgfx_set_view_rect_auto`. - /// - void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio); - - /// Set view scissor. Draw primitive outside view will be clipped. When - /// _x, _y, _width and _height are set to 0, scissor will be disabled. - /// - /// @param[in] _id View id. - /// @param[in] _x Position x from the left corner of the window. - /// @param[in] _y Position y from the top corner of the window. - /// @param[in] _width Width of scissor region. - /// @param[in] _height Height of scissor region. - /// - /// @attention C99 equivalent is `bgfx_set_view_scissor`. - /// - void setViewScissor( - uint8_t _id - , uint16_t _x = 0 - , uint16_t _y = 0 - , uint16_t _width = 0 - , uint16_t _height = 0 - ); - - /// Set view clear flags. - /// - /// @param[in] _id View id. - /// @param[in] _flags Clear flags. Use `BGFX_CLEAR_NONE` to remove any clear - /// operation. See: `BGFX_CLEAR_*`. - /// @param[in] _rgba Color clear value. - /// @param[in] _depth Depth clear value. - /// @param[in] _stencil Stencil clear value. - /// - /// @attention C99 equivalent is `bgfx_set_view_clear`. - /// - void setViewClear( - uint8_t _id - , uint16_t _flags - , uint32_t _rgba = 0x000000ff - , float _depth = 1.0f - , uint8_t _stencil = 0 - ); - - /// Set view clear flags with different clear color for each - /// frame buffer texture. Must use setClearColor to setup clear color - /// palette. - /// - /// @param[in] _id View id. - /// @param[in] _flags Clear flags. Use `BGFX_CLEAR_NONE` to remove any clear - /// operation. See: `BGFX_CLEAR_*`. - /// @param[in] _depth Depth clear value. - /// @param[in] _stencil Stencil clear value. - /// @param[in] _0 Palette index for frame buffer attachment 0. - /// @param[in] _1 Palette index for frame buffer attachment 1. - /// @param[in] _2 Palette index for frame buffer attachment 2. - /// @param[in] _3 Palette index for frame buffer attachment 3. - /// @param[in] _4 Palette index for frame buffer attachment 4. - /// @param[in] _5 Palette index for frame buffer attachment 5. - /// @param[in] _6 Palette index for frame buffer attachment 6. - /// @param[in] _7 Palette index for frame buffer attachment 7. - /// - /// @attention C99 equivalent is `bgfx_set_view_clear_mrt`. - /// - void setViewClear( - uint8_t _id - , uint16_t _flags - , float _depth - , uint8_t _stencil - , uint8_t _0 = UINT8_MAX - , uint8_t _1 = UINT8_MAX - , uint8_t _2 = UINT8_MAX - , uint8_t _3 = UINT8_MAX - , uint8_t _4 = UINT8_MAX - , uint8_t _5 = UINT8_MAX - , uint8_t _6 = UINT8_MAX - , uint8_t _7 = UINT8_MAX - ); - - /// Set view into sequential mode. Draw calls will be sorted in the same - /// order in which submit calls were called. - /// - /// @attention C99 equivalent is `bgfx_set_view_seq`. - /// - void setViewSeq(uint8_t _id, bool _enabled); - - /// Set view frame buffer. - /// - /// @param[in] _id View id. - /// @param[in] _handle Frame buffer handle. Passing `BGFX_INVALID_HANDLE` as - /// frame buffer handle will draw primitives from this view into - /// default back buffer. - /// - /// @remarks - /// Not persistent after `bgfx::reset` call. - /// - /// @attention C99 equivalent is `bgfx_set_view_frame_buffer`. - /// - void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle); - - /// Set view view and projection matrices, all draw primitives in this - /// view will use these matrices. - /// - /// @param[in] _id View id. - /// @param[in] _view View matrix. - /// @param[in] _projL Projection matrix. When using stereo rendering this projection matrix - /// represent projection matrix for left eye. - /// @param[in] _flags View flags. Use - /// - `BGFX_VIEW_NONE` - View will be rendered only once if stereo mode is enabled. - /// - `BGFX_VIEW_STEREO` - View will be rendered for both eyes if stereo mode is enabled. When - /// stereo mode is disabled this flag doesn't have effect. - /// @param[in] _projR Projection matrix for right eye in stereo mode. - /// - /// @attention C99 equivalent are `bgfx_set_view_transform`, `bgfx_set_view_transform_stereo`. - /// - void setViewTransform( - uint8_t _id - , const void* _view - , const void* _projL - , uint8_t _flags = BGFX_VIEW_STEREO - , const void* _projR = NULL - ); - - /// Post submit view reordering. - /// - /// @param[in] _id First view id. - /// @param[in] _num Number of views to remap. - /// @param[in] _remap View remap id table. Passing `NULL` will reset view ids - /// to default state. - /// - /// @attention C99 equivalent is `bgfx_set_view_remap`. - /// - void setViewRemap(uint8_t _id = 0, uint8_t _num = UINT8_MAX, const void* _remap = NULL); - - /// Reset all view settings to default. - /// - /// @param[in] _id View id. - /// - /// @attention C99 equivalent is `bgfx_reset_view`. - /// - void resetView(uint8_t _id); - - /// Sets debug marker. - /// - /// @attention C99 equivalent is `bgfx_set_marker`. - /// - void setMarker(const char* _marker); - - /// Set render states for draw primitive. - /// - /// @param[in] _state State flags. Default state for primitive type is - /// triangles. See: `BGFX_STATE_DEFAULT`. - /// - `BGFX_STATE_ALPHA_WRITE` - Enable alpha write. - /// - `BGFX_STATE_DEPTH_WRITE` - Enable depth write. - /// - `BGFX_STATE_DEPTH_TEST_*` - Depth test function. - /// - `BGFX_STATE_BLEND_*` - See remark 1 about BGFX_STATE_BLEND_FUNC. - /// - `BGFX_STATE_BLEND_EQUATION_*` - See remark 2. - /// - `BGFX_STATE_CULL_*` - Backface culling mode. - /// - `BGFX_STATE_RGB_WRITE` - Enable RGB write. - /// - `BGFX_STATE_MSAA` - Enable MSAA. - /// - `BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]` - Primitive type. - /// - /// @param[in] _rgba Sets blend factor used by `BGFX_STATE_BLEND_FACTOR` and - /// `BGFX_STATE_BLEND_INV_FACTOR` blend modes. - /// - /// @remarks - /// 1. Use `BGFX_STATE_ALPHA_REF`, `BGFX_STATE_POINT_SIZE` and - /// `BGFX_STATE_BLEND_FUNC` macros to setup more complex states. - /// 2. `BGFX_STATE_BLEND_EQUATION_ADD` is set when no other blend - /// equation is specified. - /// - /// @attention C99 equivalent is `bgfx_set_state`. - /// - void setState(uint64_t _state, uint32_t _rgba = 0); - - /// Set condition for rendering. - /// - /// @param[in] _handle Occlusion query handle. - /// @param[in] _visible Render if occlusion query is visible. - /// - /// @attention C99 equivalent is `bgfx_set_condition`. - /// - void setCondition(OcclusionQueryHandle _handle, bool _visible); - - /// Set stencil test state. - /// - /// @param[in] _fstencil Front stencil state. - /// @param[in] _bstencil Back stencil state. If back is set to `BGFX_STENCIL_NONE` - /// _fstencil is applied to both front and back facing primitives. - /// - /// @attention C99 equivalent is `bgfx_set_stencil`. - /// - void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE); - - /// Set scissor for draw primitive. For scissor for all primitives in - /// view see `bgfx::setViewScissor`. - /// - /// @param[in] _x Position x from the left corner of the window. - /// @param[in] _y Position y from the top corner of the window. - /// @param[in] _width Width of scissor region. - /// @param[in] _height Height of scissor region. - /// @returns Scissor cache index. - /// - /// @attention C99 equivalent is `bgfx_set_scissor`. - /// - uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); - - /// Set scissor from cache for draw primitive. - /// - /// @param[in] _cache Index in scissor cache. Passing UINT16_MAX unset primitive - /// scissor and primitive will use view scissor instead. - /// - /// @attention C99 equivalent is `bgfx_set_scissor_cached`. - /// - void setScissor(uint16_t _cache = UINT16_MAX); - - /// Set model matrix for draw primitive. If it is not called model will - /// be rendered with identity model matrix. - /// - /// @param[in] _mtx Pointer to first matrix in array. - /// @param[in] _num Number of matrices in array. - /// @returns index into matrix cache in case the same model matrix has - /// to be used for other draw primitive call. - /// - /// @attention C99 equivalent is `bgfx_set_transform`. - /// - uint32_t setTransform(const void* _mtx, uint16_t _num = 1); - - /// Reserve `_num` matrices in internal matrix cache. Pointer returned - /// can be modifed until `bgfx::frame` is called. - /// - /// @param[in] _transform Pointer to `Transform` structure. - /// @param[in] _num Number of matrices. - /// @returns index into matrix cache. - /// - /// @attention C99 equivalent is `bgfx_alloc_transform`. - /// - uint32_t allocTransform(Transform* _transform, uint16_t _num); - - /// Set model matrix from matrix cache for draw primitive. - /// - /// @param[in] _cache Index in matrix cache. - /// @param[in] _num Number of matrices from cache. - /// - /// @attention C99 equivalent is `bgfx_set_transform_cached`. - /// - void setTransform(uint32_t _cache, uint16_t _num = 1); - - /// Set shader uniform parameter for draw primitive. - /// - /// @param[in] _handle Uniform. - /// @param[in] _value Pointer to uniform data. - /// @param[in] _num Number of elements. - /// - /// @attention C99 equivalent is `bgfx_set_uniform`. - /// - void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1); - - /// Set index buffer for draw primitive. - /// - /// @param[in] _handle Index buffer. - /// - /// @attention C99 equivalent is `bgfx_set_index_buffer`. - /// - void setIndexBuffer(IndexBufferHandle _handle); - - /// Set index buffer for draw primitive. - /// - /// @param[in] _handle Index buffer. - /// @param[in] _firstIndex First index to render. - /// @param[in] _numIndices Number of indices to render. - /// - /// @attention C99 equivalent is `bgfx_set_index_buffer`. - /// - void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices); - - /// Set index buffer for draw primitive. - /// - /// @param[in] _handle Dynamic index buffer. - /// - /// @attention C99 equivalent is `bgfx_set_dynamic_index_buffer`. - /// - void setIndexBuffer(DynamicIndexBufferHandle _handle); - - /// Set index buffer for draw primitive. - /// - /// @param[in] _handle Dynamic index buffer. - /// @param[in] _firstIndex First index to render. - /// @param[in] _numIndices Number of indices to render. - /// - /// @attention C99 equivalent is `bgfx_set_dynamic_index_buffer`. - /// - void setIndexBuffer( - DynamicIndexBufferHandle _handle - , uint32_t _firstIndex - , uint32_t _numIndices - ); - - /// Set index buffer for draw primitive. - /// - /// @param[in] _tib Transient index buffer. - /// - /// @attention C99 equivalent is `bgfx_set_transient_index_buffer`. - /// - void setIndexBuffer(const TransientIndexBuffer* _tib); - - /// Set index buffer for draw primitive. - /// - /// @param[in] _tib Transient index buffer. - /// @param[in] _firstIndex First index to render. - /// @param[in] _numIndices Number of indices to render. - /// - /// @attention C99 equivalent is `bgfx_set_transient_index_buffer`. - /// - void setIndexBuffer( - const TransientIndexBuffer* _tib - , uint32_t _firstIndex - , uint32_t _numIndices - ); - - /// Set vertex buffer for draw primitive. - /// - /// @param[in] _handle Vertex buffer. - /// - /// @attention C99 equivalent is `bgfx_set_vertex_buffer`. - /// - void setVertexBuffer(VertexBufferHandle _handle); - - /// Set vertex buffer for draw primitive. - /// - /// @param[in] _handle Vertex buffer. - /// @param[in] _startVertex First vertex to render. - /// @param[in] _numVertices Number of vertices to render. - /// - /// @attention C99 equivalent is `bgfx_set_vertex_buffer`. - /// - void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices); - - /// Set vertex buffer for draw primitive. - /// - /// @param[in] _handle Dynamic vertex buffer. - /// - /// @attention C99 equivalent is `bgfx_set_dynamic_vertex_buffer`. - /// - void setVertexBuffer(DynamicVertexBufferHandle _handle); - - /// Set vertex buffer for draw primitive. - /// - /// @param[in] _handle Dynamic vertex buffer. - /// @param[in] _startVertex First vertex to render. - /// @param[in] _numVertices Number of vertices to render. - /// - /// @attention C99 equivalent is `bgfx_set_dynamic_vertex_buffer`. - /// - void setVertexBuffer( - DynamicVertexBufferHandle _handle - , uint32_t _startVertex - , uint32_t _numVertices - ); - - /// Set vertex buffer for draw primitive. - /// - /// @param[in] _tvb Transient vertex buffer. - /// - /// @attention C99 equivalent is `bgfx_set_transient_vertex_buffer`. - /// - void setVertexBuffer(const TransientVertexBuffer* _tvb); - - /// Set vertex buffer for draw primitive. - /// - /// @param[in] _tvb Transient vertex buffer. - /// @param[in] _startVertex First vertex to render. - /// @param[in] _numVertices Number of vertices to render. - /// - /// @attention C99 equivalent is `bgfx_set_transient_vertex_buffer`. - /// - void setVertexBuffer( - const TransientVertexBuffer* _tvb - , uint32_t _startVertex - , uint32_t _numVertices - ); - - /// Set instance data buffer for draw primitive. - /// - /// @attention C99 equivalent is `bgfx_set_instance_data_buffer`. - /// - void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _num = UINT32_MAX); - - /// Set instance data buffer for draw primitive. - /// - /// @attention C99 equivalent is `bgfx_set_instance_data_from_vertex_buffer`. - /// - void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num); - - /// Set instance data buffer for draw primitive. - /// - /// @attention C99 equivalent is `bgfx_set_instance_data_from_dynamic_vertex_buffer`. - /// - void setInstanceDataBuffer( - DynamicVertexBufferHandle _handle - , uint32_t _startVertex - , uint32_t _num - ); - - /// Set texture stage for draw primitive. - /// - /// @param[in] _stage Texture unit. - /// @param[in] _sampler Program sampler. - /// @param[in] _handle Texture handle. - /// @param[in] _flags Texture sampling mode. Default value UINT32_MAX uses - /// texture sampling settings from the texture. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @param[in] _flags Texture sampler filtering flags. UINT32_MAX use the - /// sampler filtering mode set by texture. - /// - /// @attention C99 equivalent is `bgfx_set_texture`. - /// - void setTexture( - uint8_t _stage - , UniformHandle _sampler - , TextureHandle _handle - , uint32_t _flags = UINT32_MAX - ); - - /// Set texture stage for draw primitive. - /// - /// @param[in] _stage Texture unit. - /// @param[in] _sampler Program sampler. - /// @param[in] _handle Frame buffer handle. - /// @param[in] _attachment Frame buffer attachment index. - /// @param[in] _flags Texture sampling mode. Default value UINT32_MAX uses - /// texture sampling settings from the texture. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @attention C99 equivalent is `bgfx_set_texture_from_frame_buffer`. - /// - void setTexture( - uint8_t _stage - , UniformHandle _sampler - , FrameBufferHandle _handle - , uint8_t _attachment = 0 - , uint32_t _flags = UINT32_MAX - ); - - /// Submit an empty primitive for rendering. Uniforms and draw state - /// will be applied but no geometry will be submitted. - /// - /// These empty draw calls will sort before ordinary draw calls. - /// - /// @param[in] _id View id. - /// @returns Number of draw calls. - /// - uint32_t touch(uint8_t _id); - - /// Submit primitive for rendering. - /// - /// @param[in] _id View id. - /// @param[in] _program Program. - /// @param[in] _depth Depth for sorting. - /// @param[in] _preserveState Preserve internal draw state for next draw - /// call submit. - /// @returns Number of draw calls. - /// - /// @attention C99 equivalent is `bgfx_submit`. - /// - uint32_t submit( - uint8_t _id - , ProgramHandle _program - , int32_t _depth = 0 - , bool _preserveState = false - ); - - /// Submit primitive with occlusion query for rendering. - /// - /// @param[in] _id View id. - /// @param[in] _program Program. - /// @param[in] _occlusionQuery Occlusion query. - /// @param[in] _depth Depth for sorting. - /// @param[in] _preserveState Preserve internal draw state for next draw - /// call submit. - /// @returns Number of draw calls. - /// - /// @attention C99 equivalent is `bgfx_submit_occlusion_query. - /// - uint32_t submit( - uint8_t _id - , ProgramHandle _program - , OcclusionQueryHandle _occlusionQuery - , int32_t _depth = 0 - , bool _preserveState = false - ); - - /// Submit primitive for rendering with index and instance data info from - /// indirect buffer. - /// - /// @param[in] _id View id. - /// @param[in] _program Program. - /// @param[in] _indirectHandle Indirect buffer. - /// @param[in] _start First element in indirect buffer. - /// @param[in] _num Number of dispatches. - /// @param[in] _depth Depth for sorting. - /// @param[in] _preserveState Preserve internal draw state for next draw - /// call submit. - /// @returns Number of draw calls. - /// - /// @attention C99 equivalent is `bgfx_submit_indirect`. - /// - uint32_t submit( - uint8_t _id - , ProgramHandle _program - , IndirectBufferHandle _indirectHandle - , uint16_t _start = 0 - , uint16_t _num = 1 - , int32_t _depth = 0 - , bool _preserveState = false - ); - - /// Set compute index buffer. - /// - /// @param[in] _stage Compute stage. - /// @param[in] _handle Index buffer handle. - /// @param[in] _access Buffer access. See `Access::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_compute_index_buffer`. - /// - void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access); - - /// Set compute vertex buffer. - /// - /// @param[in] _stage Compute stage. - /// @param[in] _handle Vertex buffer handle. - /// @param[in] _access Buffer access. See `Access::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_compute_vertex_buffer`. - /// - void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access); - - /// Set compute dynamic index buffer. - /// - /// @param[in] _stage Compute stage. - /// @param[in] _handle Dynamic index buffer handle. - /// @param[in] _access Buffer access. See `Access::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_compute_dynamic_index_buffer`. - /// - void setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access); - - /// Set compute dynamic vertex buffer. - /// - /// @param[in] _stage Compute stage. - /// @param[in] _handle Dynamic vertex buffer handle. - /// @param[in] _access Buffer access. See `Access::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_compute_dynamic_vertex_buffer`. - /// - void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access); - - /// Set compute indirect buffer. - /// - /// @param[in] _stage Compute stage. - /// @param[in] _handle Indirect buffer handle. - /// @param[in] _access Buffer access. See `Access::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_compute_indirect_buffer`. - /// - void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access); - - /// Set compute image from texture. - /// - /// @param[in] _stage Texture unit. - /// @param[in] _sampler Program sampler. - /// @param[in] _handle Texture handle. - /// @param[in] _mip Mip level. - /// @param[in] _access Texture access. See `Access::Enum`. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_image`. - /// - void setImage( - uint8_t _stage - , UniformHandle _sampler - , TextureHandle _handle - , uint8_t _mip - , Access::Enum _access - , TextureFormat::Enum _format = TextureFormat::Count - ); - - /// Set compute image from frame buffer texture. - /// - /// @param[in] _stage Texture unit. - /// @param[in] _sampler Program sampler. - /// @param[in] _handle Frame buffer handle. - /// @param[in] _attachment Frame buffer attachment index. - /// @param[in] _access Texture access. See `Access::Enum`. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_image_from_frame_buffer`. - /// - void setImage( - uint8_t _stage - , UniformHandle _sampler - , FrameBufferHandle _handle - , uint8_t _attachment - , Access::Enum _access - , TextureFormat::Enum _format = TextureFormat::Count - ); - - /// Dispatch compute. - /// - /// @param[in] _id View id. - /// @param[in] _handle Compute program. - /// @param[in] _numX Number of groups X. - /// @param[in] _numY Number of groups Y. - /// @param[in] _numZ Number of groups Z. - /// @param[in] _flags View flags. Use - /// - `BGFX_VIEW_NONE` - View will be rendered only once if stereo mode is enabled. - /// - `BGFX_VIEW_STEREO` - View will be rendered for both eyes if stereo mode is enabled. When - /// stereo mode is disabled this flag doesn't have effect. - /// - /// @attention C99 equivalent is `bgfx_dispatch`. - /// - uint32_t dispatch( - uint8_t _id - , ProgramHandle _handle - , uint16_t _numX = 1 - , uint16_t _numY = 1 - , uint16_t _numZ = 1 - , uint8_t _flags = BGFX_SUBMIT_EYE_FIRST - ); - - /// Dispatch compute indirect. - /// - /// @param[in] _id View id. - /// @param[in] _handle Compute program. - /// @param[in] _indirectHandle Indirect buffer. - /// @param[in] _start First element in indirect buffer. - /// @param[in] _num Number of dispatches. - /// @param[in] _flags View flags. Use - /// - `BGFX_VIEW_NONE` - View will be rendered only once if stereo mode is enabled. - /// - `BGFX_VIEW_STEREO` - View will be rendered for both eyes if stereo mode is enabled. When - /// stereo mode is disabled this flag doesn't have effect. - /// - /// @attention C99 equivalent is `bgfx_dispatch_indirect`. - /// - uint32_t dispatch( - uint8_t _id - , ProgramHandle _handle - , IndirectBufferHandle _indirectHandle - , uint16_t _start = 0 - , uint16_t _num = 1 - , uint8_t _flags = BGFX_SUBMIT_EYE_FIRST - ); - - /// Discard all previously set state for draw or compute call. - /// - /// @attention C99 equivalent is `bgfx_discard`. - /// - void discard(); - - /// Blit texture 2D region between two 2D textures. - /// - /// @param[in] _id View id. - /// @param[in] _dst Destination texture handle. - /// @param[in] _dstX Destination texture X position. - /// @param[in] _dstY Destination texture Y position. - /// @param[in] _src Source texture handle. - /// @param[in] _srcX Source texture X position. - /// @param[in] _srcY Source texture Y position. - /// @param[in] _width Width of region. - /// @param[in] _height Height of region. - /// - /// @attention Destination texture must be create with `BGFX_TEXTURE_BLIT_DST` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. - /// @attention C99 equivalent is `bgfx_blit`. - /// - void blit( - uint8_t _id - , TextureHandle _dst - , uint16_t _dstX - , uint16_t _dstY - , TextureHandle _src - , uint16_t _srcX = 0 - , uint16_t _srcY = 0 - , uint16_t _width = UINT16_MAX - , uint16_t _height = UINT16_MAX - ); - - /// Blit texture 2D region between 2D frame buffer and 2D texture. - /// - /// @param[in] _id View id. - /// @param[in] _dst Destination texture handle. - /// @param[in] _dstX Destination texture X position. - /// @param[in] _dstY Destination texture Y position. - /// @param[in] _src Source frame buffer handle. - /// @param[in] _attachment Source frame buffer attachment index. - /// @param[in] _srcX Source texture X position. - /// @param[in] _srcY Source texture Y position. - /// @param[in] _width Width of region. - /// @param[in] _height Height of region. - /// - /// @attention Destination texture must be create with `BGFX_TEXTURE_BLIT_DST` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. - /// @attention C99 equivalent is `bgfx_blit`. - /// - void blit( - uint8_t _id - , TextureHandle _dst - , uint16_t _dstX - , uint16_t _dstY - , FrameBufferHandle _src - , uint8_t _attachment = 0 - , uint16_t _srcX = 0 - , uint16_t _srcY = 0 - , uint16_t _width = UINT16_MAX - , uint16_t _height = UINT16_MAX - ); - - /// Blit texture region between two textures. - /// - /// @param[in] _id View id. - /// @param[in] _dst Destination texture handle. - /// @param[in] _dstMip Destination texture mip level. - /// @param[in] _dstX Destination texture X position. - /// @param[in] _dstY Destination texture Y position. - /// @param[in] _dstZ If texture is 2D this argument should be 0. If destination texture is cube - /// this argument represent destination texture cube face. For 3D texture this argument - /// represent destination texture Z position. - /// @param[in] _src Source texture handle. - /// @param[in] _srcMip Source texture mip level. - /// @param[in] _srcX Source texture X position. - /// @param[in] _srcY Source texture Y position. - /// @param[in] _srcZ If texture is 2D this argument should be 0. If source texture is cube - /// this argument represent source texture cube face. For 3D texture this argument - /// represent source texture Z position. - /// @param[in] _width Width of region. - /// @param[in] _height Height of region. - /// @param[in] _depth If texture is 3D this argument represent depth of region, otherwise is - /// unused. - /// - /// @attention Destination texture must be create with `BGFX_TEXTURE_BLIT_DST` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. - /// @attention C99 equivalent is `bgfx_blit`. - /// - void blit( - uint8_t _id - , TextureHandle _dst - , uint8_t _dstMip - , uint16_t _dstX - , uint16_t _dstY - , uint16_t _dstZ - , TextureHandle _src - , uint8_t _srcMip = 0 - , uint16_t _srcX = 0 - , uint16_t _srcY = 0 - , uint16_t _srcZ = 0 - , uint16_t _width = UINT16_MAX - , uint16_t _height = UINT16_MAX - , uint16_t _depth = UINT16_MAX - ); - - /// Blit texture region between frame buffer and texture. - /// - /// @param[in] _id View id. - /// @param[in] _dst Destination texture handle. - /// @param[in] _dstMip Destination texture mip level. - /// @param[in] _dstX Destination texture X position. - /// @param[in] _dstY Destination texture Y position. - /// @param[in] _dstZ If texture is 2D this argument should be 0. If destination texture is cube - /// this argument represent destination texture cube face. For 3D texture this argument - /// represent destination texture Z position. - /// @param[in] _src Source frame buffer handle. - /// @param[in] _attachment Source frame buffer attachment index. - /// @param[in] _srcMip Source texture mip level. - /// @param[in] _srcX Source texture X position. - /// @param[in] _srcY Source texture Y position. - /// @param[in] _srcZ If texture is 2D this argument should be 0. If source texture is cube - /// this argument represent source texture cube face. For 3D texture this argument - /// represent source texture Z position. - /// @param[in] _width Width of region. - /// @param[in] _height Height of region. - /// @param[in] _depth If texture is 3D this argument represent depth of region, otherwise is - /// unused. - /// - /// @attention Destination texture must be create with `BGFX_TEXTURE_BLIT_DST` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. - /// @attention C99 equivalent is `bgfx_blit`. - /// - void blit( - uint8_t _id - , TextureHandle _dst - , uint8_t _dstMip - , uint16_t _dstX - , uint16_t _dstY - , uint16_t _dstZ - , FrameBufferHandle _src - , uint8_t _attachment = 0 - , uint8_t _srcMip = 0 - , uint16_t _srcX = 0 - , uint16_t _srcY = 0 - , uint16_t _srcZ = 0 - , uint16_t _width = UINT16_MAX - , uint16_t _height = UINT16_MAX - , uint16_t _depth = UINT16_MAX - ); - - /// Request screen shot. - /// - /// @param[in] _filePath Will be passed to `bgfx::CallbackI::screenShot` callback. - /// - /// @remarks - /// `bgfx::CallbackI::screenShot` must be implemented. - /// - /// @attention C99 equivalent is `bgfx_save_screen_shot`. - /// - void saveScreenShot(const char* _filePath); - -} // namespace bgfx - -#endif // BGFX_H_HEADER_GUARD + void (*attachment_init)(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve); + bgfx_vertex_layout_t* (*vertex_layout_begin)(bgfx_vertex_layout_t* _this, bgfx_renderer_type_t _rendererType); + bgfx_vertex_layout_t* (*vertex_layout_add)(bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); + void (*vertex_layout_decode)(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t * _num, bgfx_attrib_type_t * _type, bool * _normalized, bool * _asInt); + bool (*vertex_layout_has)(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib); + bgfx_vertex_layout_t* (*vertex_layout_skip)(bgfx_vertex_layout_t* _this, uint8_t _num); + void (*vertex_layout_end)(bgfx_vertex_layout_t* _this); + void (*vertex_pack)(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, void* _data, uint32_t _index); + void (*vertex_unpack)(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _index); + void (*vertex_convert)(const bgfx_vertex_layout_t * _dstLayout, void* _dstData, const bgfx_vertex_layout_t * _srcLayout, const void* _srcData, uint32_t _num); + uint32_t (*weld_vertices)(void* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon); + uint32_t (*topology_convert)(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32); + void (*topology_sort_tri_list)(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32); + uint8_t (*get_supported_renderers)(uint8_t _max, bgfx_renderer_type_t* _enum); + const char* (*get_renderer_name)(bgfx_renderer_type_t _type); + void (*init_ctor)(bgfx_init_t* _init); + bool (*init)(const bgfx_init_t * _init); + void (*shutdown)(void); + void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags, bgfx_texture_format_t _format); + uint32_t (*frame)(bool _capture); + bgfx_renderer_type_t (*get_renderer_type)(void); + const bgfx_caps_t* (*get_caps)(void); + const bgfx_stats_t* (*get_stats)(void); + const bgfx_memory_t* (*alloc)(uint32_t _size); + const bgfx_memory_t* (*copy)(const void* _data, uint32_t _size); + const bgfx_memory_t* (*make_ref)(const void* _data, uint32_t _size); + const bgfx_memory_t* (*make_ref_release)(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData); + void (*set_debug)(uint32_t _debug); + void (*dbg_text_clear)(uint8_t _attr, bool _small); + void (*dbg_text_printf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ... ); + void (*dbg_text_vprintf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList); + void (*dbg_text_image)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch); + bgfx_index_buffer_handle_t (*create_index_buffer)(const bgfx_memory_t* _mem, uint16_t _flags); + void (*set_index_buffer_name)(bgfx_index_buffer_handle_t _handle, const char* _name, int32_t _len); + void (*destroy_index_buffer)(bgfx_index_buffer_handle_t _handle); + bgfx_vertex_layout_handle_t (*create_vertex_layout)(const bgfx_vertex_layout_t * _layout); + void (*destroy_vertex_layout)(bgfx_vertex_layout_handle_t _layoutHandle); + bgfx_vertex_buffer_handle_t (*create_vertex_buffer)(const bgfx_memory_t* _mem, const bgfx_vertex_layout_t * _layout, uint16_t _flags); + void (*set_vertex_buffer_name)(bgfx_vertex_buffer_handle_t _handle, const char* _name, int32_t _len); + void (*destroy_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle); + bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer)(uint32_t _num, uint16_t _flags); + bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer_mem)(const bgfx_memory_t* _mem, uint16_t _flags); + void (*update_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem); + void (*destroy_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle); + bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer)(uint32_t _num, const bgfx_vertex_layout_t* _layout, uint16_t _flags); + bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer_mem)(const bgfx_memory_t* _mem, const bgfx_vertex_layout_t* _layout, uint16_t _flags); + void (*update_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem); + void (*destroy_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle); + uint32_t (*get_avail_transient_index_buffer)(uint32_t _num, bool _index32); + uint32_t (*get_avail_transient_vertex_buffer)(uint32_t _num, const bgfx_vertex_layout_t * _layout); + uint32_t (*get_avail_instance_data_buffer)(uint32_t _num, uint16_t _stride); + void (*alloc_transient_index_buffer)(bgfx_transient_index_buffer_t* _tib, uint32_t _num, bool _index32); + void (*alloc_transient_vertex_buffer)(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_layout_t * _layout); + bool (*alloc_transient_buffers)(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_layout_t * _layout, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices, bool _index32); + void (*alloc_instance_data_buffer)(bgfx_instance_data_buffer_t* _idb, uint32_t _num, uint16_t _stride); + bgfx_indirect_buffer_handle_t (*create_indirect_buffer)(uint32_t _num); + void (*destroy_indirect_buffer)(bgfx_indirect_buffer_handle_t _handle); + bgfx_shader_handle_t (*create_shader)(const bgfx_memory_t* _mem); + uint16_t (*get_shader_uniforms)(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max); + void (*set_shader_name)(bgfx_shader_handle_t _handle, const char* _name, int32_t _len); + void (*destroy_shader)(bgfx_shader_handle_t _handle); + bgfx_program_handle_t (*create_program)(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders); + bgfx_program_handle_t (*create_compute_program)(bgfx_shader_handle_t _csh, bool _destroyShaders); + void (*destroy_program)(bgfx_program_handle_t _handle); + bool (*is_texture_valid)(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags); + bool (*is_frame_buffer_valid)(uint8_t _num, const bgfx_attachment_t* _attachment); + void (*calc_texture_size)(bgfx_texture_info_t * _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format); + bgfx_texture_handle_t (*create_texture)(const bgfx_memory_t* _mem, uint64_t _flags, uint8_t _skip, bgfx_texture_info_t* _info); + bgfx_texture_handle_t (*create_texture_2d)(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem); + bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags); + bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem); + bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem); + void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); + void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem); + void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); + uint32_t (*read_texture)(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip); + void (*set_texture_name)(bgfx_texture_handle_t _handle, const char* _name, int32_t _len); + void* (*get_direct_access_ptr)(bgfx_texture_handle_t _handle); + void (*destroy_texture)(bgfx_texture_handle_t _handle); + bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint64_t _textureFlags); + bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint64_t _textureFlags); + bgfx_frame_buffer_handle_t (*create_frame_buffer_from_handles)(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTexture); + bgfx_frame_buffer_handle_t (*create_frame_buffer_from_attachment)(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTexture); + bgfx_frame_buffer_handle_t (*create_frame_buffer_from_nwh)(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, bgfx_texture_format_t _depthFormat); + void (*set_frame_buffer_name)(bgfx_frame_buffer_handle_t _handle, const char* _name, int32_t _len); + bgfx_texture_handle_t (*get_texture)(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment); + void (*destroy_frame_buffer)(bgfx_frame_buffer_handle_t _handle); + bgfx_uniform_handle_t (*create_uniform)(const char* _name, bgfx_uniform_type_t _type, uint16_t _num); + void (*get_uniform_info)(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t * _info); + void (*destroy_uniform)(bgfx_uniform_handle_t _handle); + bgfx_occlusion_query_handle_t (*create_occlusion_query)(void); + bgfx_occlusion_query_result_t (*get_result)(bgfx_occlusion_query_handle_t _handle, int32_t* _result); + void (*destroy_occlusion_query)(bgfx_occlusion_query_handle_t _handle); + void (*set_palette_color)(uint8_t _index, const float _rgba[4]); + void (*set_palette_color_rgba8)(uint8_t _index, uint32_t _rgba); + void (*set_view_name)(bgfx_view_id_t _id, const char* _name); + void (*set_view_rect)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + void (*set_view_rect_ratio)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio); + void (*set_view_scissor)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + void (*set_view_clear)(bgfx_view_id_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil); + void (*set_view_clear_mrt)(bgfx_view_id_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _c0, uint8_t _c1, uint8_t _c2, uint8_t _c3, uint8_t _c4, uint8_t _c5, uint8_t _c6, uint8_t _c7); + void (*set_view_mode)(bgfx_view_id_t _id, bgfx_view_mode_t _mode); + void (*set_view_frame_buffer)(bgfx_view_id_t _id, bgfx_frame_buffer_handle_t _handle); + void (*set_view_transform)(bgfx_view_id_t _id, const void* _view, const void* _proj); + void (*set_view_order)(bgfx_view_id_t _id, uint16_t _num, const bgfx_view_id_t* _order); + void (*reset_view)(bgfx_view_id_t _id); + bgfx_encoder_t* (*encoder_begin)(bool _forThread); + void (*encoder_end)(bgfx_encoder_t* _encoder); + void (*encoder_set_marker)(bgfx_encoder_t* _this, const char* _marker); + void (*encoder_set_state)(bgfx_encoder_t* _this, uint64_t _state, uint32_t _rgba); + void (*encoder_set_condition)(bgfx_encoder_t* _this, bgfx_occlusion_query_handle_t _handle, bool _visible); + void (*encoder_set_stencil)(bgfx_encoder_t* _this, uint32_t _fstencil, uint32_t _bstencil); + uint16_t (*encoder_set_scissor)(bgfx_encoder_t* _this, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + void (*encoder_set_scissor_cached)(bgfx_encoder_t* _this, uint16_t _cache); + uint32_t (*encoder_set_transform)(bgfx_encoder_t* _this, const void* _mtx, uint16_t _num); + void (*encoder_set_transform_cached)(bgfx_encoder_t* _this, uint32_t _cache, uint16_t _num); + uint32_t (*encoder_alloc_transform)(bgfx_encoder_t* _this, bgfx_transform_t* _transform, uint16_t _num); + void (*encoder_set_uniform)(bgfx_encoder_t* _this, bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num); + void (*encoder_set_index_buffer)(bgfx_encoder_t* _this, bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + void (*encoder_set_dynamic_index_buffer)(bgfx_encoder_t* _this, bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + void (*encoder_set_transient_index_buffer)(bgfx_encoder_t* _this, const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices); + void (*encoder_set_vertex_buffer)(bgfx_encoder_t* _this, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + void (*encoder_set_vertex_buffer_with_layout)(bgfx_encoder_t* _this, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + void (*encoder_set_dynamic_vertex_buffer)(bgfx_encoder_t* _this, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + void (*encoder_set_dynamic_vertex_buffer_with_layout)(bgfx_encoder_t* _this, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + void (*encoder_set_transient_vertex_buffer)(bgfx_encoder_t* _this, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices); + void (*encoder_set_transient_vertex_buffer_with_layout)(bgfx_encoder_t* _this, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + void (*encoder_set_vertex_count)(bgfx_encoder_t* _this, uint32_t _numVertices); + void (*encoder_set_instance_data_buffer)(bgfx_encoder_t* _this, const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num); + void (*encoder_set_instance_data_from_vertex_buffer)(bgfx_encoder_t* _this, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + void (*encoder_set_instance_data_from_dynamic_vertex_buffer)(bgfx_encoder_t* _this, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + void (*encoder_set_instance_count)(bgfx_encoder_t* _this, uint32_t _numInstances); + void (*encoder_set_texture)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); + void (*encoder_touch)(bgfx_encoder_t* _this, bgfx_view_id_t _id); + void (*encoder_submit)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags); + void (*encoder_submit_occlusion_query)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags); + void (*encoder_submit_indirect)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags); + void (*encoder_set_compute_index_buffer)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); + void (*encoder_set_compute_vertex_buffer)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); + void (*encoder_set_compute_dynamic_index_buffer)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); + void (*encoder_set_compute_dynamic_vertex_buffer)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access); + void (*encoder_set_compute_indirect_buffer)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access); + void (*encoder_set_image)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); + void (*encoder_dispatch)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags); + void (*encoder_dispatch_indirect)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags); + void (*encoder_discard)(bgfx_encoder_t* _this, uint8_t _flags); + void (*encoder_blit)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth); + void (*request_screen_shot)(bgfx_frame_buffer_handle_t _handle, const char* _filePath); + bgfx_render_frame_t (*render_frame)(int32_t _msecs); + void (*set_platform_data)(const bgfx_platform_data_t * _data); + const bgfx_internal_data_t* (*get_internal_data)(void); + uintptr_t (*override_internal_texture_ptr)(bgfx_texture_handle_t _handle, uintptr_t _ptr); + uintptr_t (*override_internal_texture)(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint64_t _flags); + void (*set_marker)(const char* _marker); + void (*set_state)(uint64_t _state, uint32_t _rgba); + void (*set_condition)(bgfx_occlusion_query_handle_t _handle, bool _visible); + void (*set_stencil)(uint32_t _fstencil, uint32_t _bstencil); + uint16_t (*set_scissor)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + void (*set_scissor_cached)(uint16_t _cache); + uint32_t (*set_transform)(const void* _mtx, uint16_t _num); + void (*set_transform_cached)(uint32_t _cache, uint16_t _num); + uint32_t (*alloc_transform)(bgfx_transform_t* _transform, uint16_t _num); + void (*set_uniform)(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num); + void (*set_index_buffer)(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + void (*set_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + void (*set_transient_index_buffer)(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices); + void (*set_vertex_buffer)(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + void (*set_vertex_buffer_with_layout)(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + void (*set_dynamic_vertex_buffer)(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + void (*set_dynamic_vertex_buffer_with_layout)(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + void (*set_transient_vertex_buffer)(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices); + void (*set_transient_vertex_buffer_with_layout)(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle); + void (*set_vertex_count)(uint32_t _numVertices); + void (*set_instance_data_buffer)(const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num); + void (*set_instance_data_from_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + void (*set_instance_data_from_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + void (*set_instance_count)(uint32_t _numInstances); + void (*set_texture)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); + void (*touch)(bgfx_view_id_t _id); + void (*submit)(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags); + void (*submit_occlusion_query)(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags); + void (*submit_indirect)(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags); + void (*set_compute_index_buffer)(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); + void (*set_compute_vertex_buffer)(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); + void (*set_compute_dynamic_index_buffer)(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); + void (*set_compute_dynamic_vertex_buffer)(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access); + void (*set_compute_indirect_buffer)(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access); + void (*set_image)(uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); + void (*dispatch)(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags); + void (*dispatch_indirect)(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags); + void (*discard)(uint8_t _flags); + void (*blit)(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth); +}; + +/**/ +typedef bgfx_interface_vtbl_t* (*PFN_BGFX_GET_INTERFACE)(uint32_t _version); + +/**/ +BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version); + +#endif // BGFX_C99_H_HEADER_GUARD diff --git a/dist/include/bgfx/cimgui_terra.h b/dist/include/bgfx/cimgui_terra.h index f271ee11..c1c6e7eb 100644 --- a/dist/include/bgfx/cimgui_terra.h +++ b/dist/include/bgfx/cimgui_terra.h @@ -67,10 +67,6 @@ CIMGUI_API void igBGFXEndFrame(); CIMGUI_API void igBGFXPushFont(uint32_t _fontid); -// TODO: figure out the complicated includes for this -// Note that in practice `ImTextureID` is a void* -// CIMGUI_API ImTextureID igBGFXTexToId(bgfx_texture_handle_t _handle, uint8_t _flags, uint8_t _mip); - typedef struct { // private data @@ -3465,6 +3461,9 @@ CIMGUI_API void igImFontAtlasBuildRender32bppRectFromString(ImFontAtlas* atlas,i CIMGUI_API void igImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256],float in_multiply_factor); CIMGUI_API void igImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256],unsigned char* pixels,int x,int y,int w,int h,int stride); +// Just manually define a bgfx texture handle here +typedef struct bgfx_texture_handle { uint16_t idx; } bgfx_texture_handle_t; +CIMGUI_API ImTextureID igBGFXTexToId(bgfx_texture_handle_t _handle, uint8_t _flags, uint8_t _mip); /////////////////////////hand written functions //no LogTextV diff --git a/dist/include/bgfx/shader/bgfx_compute.sh b/dist/include/bgfx/shader/bgfx_compute.sh index d05b2328..5c1945b6 100644 --- a/dist/include/bgfx/shader/bgfx_compute.sh +++ b/dist/include/bgfx/shader/bgfx_compute.sh @@ -92,6 +92,7 @@ # define COMP_rg8 float2 # define COMP_r8 float #endif // BGFX_SHADER_LANGUAGE_HLSL +#define COMP_rg32f float2 #define COMP_rgba32f float4 #define IMAGE2D_RO( _name, _format, _reg) \ diff --git a/dist/include/compat/stdio.h b/dist/include/compat/stdio.h index 5d884485..733d2f5e 100644 --- a/dist/include/compat/stdio.h +++ b/dist/include/compat/stdio.h @@ -22,7 +22,7 @@ int sscanf(const char *, const char *, ...); typedef struct FILE FILE; size_t fread(void* ptr, size_t size, size_t count, FILE* stream); -size_t fwrite(void *ptr, size_t size, size_t count, FILE *stream); +size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream); FILE* fopen(const char* filename, const char* mode); int fclose(FILE* stream); int fseek(FILE* stream, long int offset, int origin); diff --git a/dist/include/sdl/sdl_minimal.h b/dist/include/sdl/sdl_minimal.h index 5a7a71fd..89faa216 100755 --- a/dist/include/sdl/sdl_minimal.h +++ b/dist/include/sdl/sdl_minimal.h @@ -1728,10 +1728,8 @@ typedef enum SDL_SYSWM_ANDROID } SDL_SYSWM_TYPE; -// eh just hack these in for now -typedef void* HWND; -typedef void* HDC; - +// Define all of these with void pointers because that's what +// we're casting to anyway typedef struct SDL_SysWMinfo { SDL_version version; @@ -1740,9 +1738,26 @@ typedef struct SDL_SysWMinfo { struct { - HWND window; /**< The window handle */ - HDC hdc; /**< The window device context */ + void* window; /**< The window handle */ + void* hdc; /**< The window device context */ } win; + struct + { + void* display; /**< The X11 display */ + void* window; /**< The X11 window */ + } x11; + struct + { + struct wl_display* display; /**< Wayland display */ + struct wl_surface* surface; /**< Wayland surface */ + void* shell_surface; /**< DEPRECATED Wayland shell_surface (window manager handle) */ + struct wl_egl_window* egl_window; /**< Wayland EGL window (native window) */ + struct xdg_surface* xdg_surface; /**< Wayland xdg surface (window manager handle) */ + } wl; + struct + { + void* window; /**< The cocoa display */ + } cocoa; /* Can't have an empty union */ int dummy; } info; diff --git a/dist/scripts/app/immediateapp.t b/dist/scripts/app/immediateapp.t index 4ba3b650..6cf5bbe1 100644 --- a/dist/scripts/app/immediateapp.t +++ b/dist/scripts/app/immediateapp.t @@ -2,84 +2,35 @@ -- -- a convenience class for immediate-mode only rendering -local class = require('class') -local math = require("math") -local gfx = require("gfx") -local ecs = require("ecs") local graphics = require("graphics") -local imrender = require("gfx/imrender.t") +--local immediate = require("graphics/imrender.t") -local ImmediateApp = class('ImmediateApp') - -function ImmediateApp:init(options) - log.debug("ImmediateApp: init") - options = options or {} - self.headless = options.headless - if not self.headless then - local sdl = require("addon/sdl.t") - sdl.create_window(options.width or 1280, options.height or 720, - options.title or 'truss', - options.fullscreen and 1, - options.display or 0) - self.width, self.height = sdl.get_window_size() - self.stats = options.stats - options.debugtext = options.stats - options.window = sdl - end - gfx.init_gfx(options) - log.debug("ImmediateApp: window+gfx initialized") - if (not self.headless) and options.error_console ~= false then - self:install_console() - end - self._init_options = options +local app = require("app/app.t") +local m = {} - self:init_ecs() - self:init_pipeline(options) -end +local ImmediateApp = app.App:extend("ImmediateApp") +m.ImmediateApp = ImmediateApp -function ImmediateApp:install_console() - require("dev/miniconsole.t").install() +local function terminate(msg) + if msg then print(msg) end + truss.quit() end -function ImmediateApp:init_ecs() - -- create ecs - local ECS = ecs.ECS() - self.ECS = ECS - if not self.headless then - ECS:add_system(require("input/sdl_input.t").SDLInputSystem()) - ECS.systems.input:on("keydown", self, self.keydown) - end - ECS:add_system(ecs.System("update", "update")) - if self.async ~= false then - ECS:add_system(require("async").AsyncSystem()) +function ImmediateApp:init(options) + ImmediateApp.super.init(self, options) + if options.func then + self.imstage:run(options.func, terminate, terminate) end - ECS:add_system(graphics.RenderSystem()) - if self.stats then ECS:add_system(graphics.DebugTextStats()) end end -- this creates a pipeline with nothing but an immediate state function ImmediateApp:init_pipeline(options) local p = graphics.Pipeline({verbose = true}) - self.imstage = p:add_stage(imrender.ImmediateStage{ - num_views = options.num_views or 32, - func = options.immediate_func + self.imstage = p:add_stage(graphics.ImmediateStage{ + num_views = options.num_views or 32 }) self.pipeline = p self.ECS.systems.render:set_pipeline(p) end -function ImmediateApp:keydown(evtname, evt) - local keyname, modifiers = evt.keyname, evt.modifiers - if keyname == "F12" then - print("Saving screenshot!") - gfx.save_screenshot("screenshot.png") - end -end - -function ImmediateApp:update() - self.ECS:update() -end - -local m = {} -m.ImmediateApp = ImmediateApp return m diff --git a/dist/scripts/core/build.t b/dist/scripts/core/build.t new file mode 100644 index 00000000..b6af8271 --- /dev/null +++ b/dist/scripts/core/build.t @@ -0,0 +1,57 @@ +-- building/cross-compilation functions +local m = {} + +function m.is_native() + return (not _modroot) or (_modroot.cross_target == nil) +end + +function m.target_name() + if m.is_native() then + return truss.os + else + return _modroot.cross_target_name or "Unknown" + end +end + +function m.includec(filename, args, target) + if not m.is_native() then + assert(target == nil, "cannot cross-compile within a cross-compilation context!") + args = _modroot.cross_args + target = _modroot.cross_target + end + print("including c [native? ", m.is_native(), "]: ", filename) + return terralib.includec(filename, args, target) +end + +function m.includecstring(str, args, target) + if not m.is_native() then + assert(target == nil, "cannot cross-compile within a cross-compilation context!") + args = _modroot.cross_args + target = _modroot.cross_target + end + print("including cstr [native? ", m.is_native(), "]: ", str:sub(1, 80)) + return terralib.includecstring(str, args, target) +end + +function m.linklibrary(fn) + if not m.is_native() then return end + return terralib.linklibrary(fn) +end + +function m.truss_link_library(...) + if not m.is_native() then return end + return truss.link_library(...) +end + +function m.create_cross_compilation_root(options) + local resolve = require("core/resolve.t") + local root = resolve.create_root{ + module_env = truss.clean_subenv + } + root.cross_args = options.include_args + root.cross_target = options.target + root.cross_target_name = options.target_name + return root +end + +return m diff --git a/dist/scripts/core/core.t b/dist/scripts/core/core.t index 8f5d7f05..a7144c28 100644 --- a/dist/scripts/core/core.t +++ b/dist/scripts/core/core.t @@ -341,6 +341,7 @@ local function create_module_env(module_name, file_name, options) modenv._module_name = module_name local path = find_path(file_name) modenv._path = path + modenv._modroot = false modenv.require = create_module_require(path) modenv._env = modenv if not options.allow_globals then diff --git a/dist/scripts/core/resolve.t b/dist/scripts/core/resolve.t new file mode 100644 index 00000000..01f3645a --- /dev/null +++ b/dist/scripts/core/resolve.t @@ -0,0 +1,181 @@ +-- creates a require system +-- TODO: have main require use this +local m = {} + +local function find_path(file_name) + local spos = 0 + for i = #file_name, 1, -1 do + if file_name:sub(i, i) == "/" then + spos = i - 1 + break + end + end + return file_name:sub(1, spos) +end + +local function expand_name(name, path) + if name:sub(1,2) == "./" then + return path .. "/" .. name:sub(3) + elseif name:sub(1,1) == "/" then + return name:sub(2) + else + return name + end +end + +local disallow_globals_mt = { + __newindex = function (t,k,v) + error("Module " .. t._module_name .. " tried to create global '" .. k .. "'") + end, + __index = function (t,k) + error("Module " .. t._module_name .. " tried to access nil global '" .. k .. "'") + end +} + +function m.create_root(options) + options = options or {} + local root = options.root or {} + root._module_env = options.module_env or truss.extend_table({}, _G) + root._loaders = options.loaders or { + [".t"] = terralib.load, + [".lua"] = load, + } + local loaded_libs = {} + root._loaded_libs = loaded_libs + root._script_path = options.script_path or "scripts/" + local error = options.error or truss.error + + local function create_module_require(path) + return function(_modname, options) + local expanded_name = expand_name(_modname, path) + return root.require(expanded_name, options) + end + end + + local function create_module_env(module_name, file_name, options) + local modenv = truss.extend_table({}, root._module_env) + modenv._module_name = module_name + local path = find_path(file_name) + modenv._path = path + modenv.require = create_module_require(path) + modenv._env = modenv + modenv._modroot = root + if not options.allow_globals then + setmetatable(modenv, disallow_globals_mt) + end + return modenv + end + + local function select_loader(fn) + for extension, loader in pairs(root._loaders) do + if fn:sub(-(#extension)) == extension then + return loader + end + end + return root._loaders.default + end + + function root.require(modname, options) + options = options or {} + if type(options) == 'boolean' then + error("Require now takes options table: require(fn, {force=true})") + end + if loaded_libs[modname] == false then + error("require [" .. modname .. "] : cyclical require") + return nil + end + if loaded_libs[modname] == nil or options.force then + local oldmodule = loaded_libs[modname] -- only relevant if force==true + loaded_libs[modname] = false -- prevent possible infinite recursion + + -- if the filename is actually a directory, try to load init.t + local filename = modname + local fullpath = root._script_path .. filename + if truss.C.check_file(fullpath) == 2 then + fullpath = fullpath .. "/init.t" + filename = filename .. "/init.t" + log.info("Required directory; trying to load [" .. fullpath .. "]") + end + + local t0 = truss.tic() + local funcsource = truss.load_script_from_file(fullpath) + if not funcsource then + error("require('" .. filename .. "'): file does not exist.") + return nil + end + local loader = select_loader(fullpath) + if not loader then + error("No loader for " .. fullpath) + end + local module_def, loaderror = truss.load_named_string(funcsource, filename, loader) + if not module_def then + error("require('" .. modname .. "'): syntax error: " .. loaderror) + return nil + end + local modenv = options.env or create_module_env(modname, filename, options) + rawset(modenv, "_preregister", function(v) + if loaded_libs[modname] then + error("Multiple preregs for [" .. modname .. "]") + end + loaded_libs[modname] = v + return v + end) + setfenv(module_def, modenv) + local evaluated_module = module_def() + rawset(modenv, "_preregister", nil) + if not (evaluated_module or options.allow_globals) then + error("Module [" .. modname .. "] did not return a table!") + end + local modtab = evaluated_module or modenv + if loaded_libs[modname] and (loaded_libs[modname] ~= modtab) then + error("Module [" .. modname .. "] did not return preregistered table!") + end + loaded_libs[modname] = modtab + log.info(string.format("Loaded [%s] in %.2f ms", + modname, truss.toc(t0) * 1000.0)) + end + return loaded_libs[modname] + end + root._module_env.require = root.require + + function root.check_module_exists(filename) + if loaded_libs[filename] then return true end + local fullpath = root._script_path .. filename + return truss.C.check_file(fullpath) ~= 0 + end + + function root.require_as(filename, libname, options) + log.info("Loading [" .. filename .. "] as [" .. libname .. "]") + local temp = root.require(filename, options) + loaded_libs[libname] = temp + return temp + end + + -- just directly inserts a module + function root.insert_module(libname, libtable) + loaded_libs[libname] = libtable + end + + if not options.no_default_libs then + -- alias standard lua/luajit libraries so they can be 'required' + root.insert_module("ffi", ffi) + root.insert_module("bit", bit) + root.insert_module("string", string) + root.insert_module("io", io) + root.insert_module("os", os) + root.insert_module("table", table) + -- hmmm: should 3rd party libraries requiring math get truss math? + root.insert_module("luamath", math) + root.insert_module("package", package) + root.insert_module("debug", debug) + root.insert_module("coroutine", coroutine) + root.insert_module("jit", jit) + + -- alias core/30log.lua to class so we can just require("class") + root.require_as("core/30log.lua", "class") + end + + return root +end + +return m diff --git a/dist/scripts/dev/downloadlibs.t b/dist/scripts/dev/downloadlibs.t index fd71a044..ad81fdf5 100644 --- a/dist/scripts/dev/downloadlibs.t +++ b/dist/scripts/dev/downloadlibs.t @@ -3,9 +3,9 @@ -- (mainly useful for CI situations, since you can use -- truss itself to run this) -local LIB_URL_PATH = "https://github.com/PyryM/trusslibs/releases/download/v0.0.3/" +local LIB_URL_PATH = "https://github.com/PyryM/trusslibs/releases/download/v0.0.6-five/" local ZIP_NAMES = { - Windows = "trusslibs_windows-latest.zip", + Windows = "trusslibs_windows-2019.zip", Linux = "trusslibs_ubuntu-latest.zip" } diff --git a/dist/scripts/examples/headless.t b/dist/scripts/examples/headless.t index 35045201..7422d1e7 100644 --- a/dist/scripts/examples/headless.t +++ b/dist/scripts/examples/headless.t @@ -66,7 +66,7 @@ function init() backend = "vulkan", width = 1280, height = 720, -- doesn't matter in headless num_views = 32, - immediate_func = render, + func = render, } end diff --git a/dist/scripts/examples/headless_caps.t b/dist/scripts/examples/headless_caps.t index 9c381ff8..d4aa5c9e 100644 --- a/dist/scripts/examples/headless_caps.t +++ b/dist/scripts/examples/headless_caps.t @@ -6,7 +6,7 @@ function init() backend = truss.args[3], lowlatency = true, width = 256, height = 256, - cb_ptr = require("addon/sdl.t").get_bgfx_callback() -- for callback traces? + --cb_ptr = require("addon/sdl.t").get_bgfx_callback() -- for callback traces? } for capname, supported in pairs(gfx.get_caps().features) do log.info(capname, supported) diff --git a/dist/scripts/examples/immediate_texture.t b/dist/scripts/examples/immediate_texture.t new file mode 100644 index 00000000..6c1d2709 --- /dev/null +++ b/dist/scripts/examples/immediate_texture.t @@ -0,0 +1,67 @@ +local math = require("math") +local Vector = math.Vector +local imapp = require("app/immediateapp.t") +local gfx = require("gfx") + +local function update_tex(tex, t) + local data = tex.cdata + local p = 0 + for r = 0, tex.height-1 do + for c = 0, tex.width-1 do + data[p] = 128+127*math.sin(r*0.1+t) + data[p+1] = 128+127*math.cos(r*0.1+t) + data[p+2] = 128+127*math.sin((r+c)*0.15+t) + data[p+3] = 255 + p = p + 4 + end + end +end + +local function render(ctx) + local tex = gfx.Texture2d{ + width = 512, + height = 512, + dynamic = true, + allocate = true, + format = assert(gfx.TEX_RGBA8) + } + tex:commit() + + local mat = gfx.anonymous_material{ + uniforms = {s_srcTex = {0, tex}}, + state = {cull = false, depth_test = false, depth_write = false}, + program = {"vs_fullscreen", "fs_fullscreen_copy"} + } + + local f = 0 + while true do + f = f + 1 + ctx:await_frame() + ctx:await_view{ + proj_matrix = math.Matrix4():orthographic_projection( + 0, 1, + 0, 1, + -1.0, 1.0, false + ), + view_matrix = math.Matrix4():identity(), + clear = {color = 0xffffffff, depth = 1.0}, + render_target = gfx.BACKBUFFER + } + update_tex(tex, f*0.1) + tex:update() + ctx:draw_fullscreen(mat) + end + truss.quit() +end + +function init() + app = imapp.ImmediateApp{ + width = 512, height = 512, + num_views = 32, + func = render, + } +end + +function update() + app:update() +end \ No newline at end of file diff --git a/dist/scripts/examples/wasm_helloworld.t b/dist/scripts/examples/wasm_helloworld.t new file mode 100644 index 00000000..bd376a2e --- /dev/null +++ b/dist/scripts/examples/wasm_helloworld.t @@ -0,0 +1,18 @@ +local WASM_HEADER = [[ +int printf (const char *, ... ); +]] + +local OUTFN = "helloworld.bc" + +function init() + local triple = "wasm32-wasi" + local cross_target = terralib.newtarget{Triple = triple} + + local io = terralib.includecstring(WASM_HEADER, nil, cross_target) + local terra helloworld() + io.printf("Hello World!\n") + end + + terralib.saveobj(OUTFN, {helloworld=helloworld}, nil, cross_target) + print("Exported llvm wasm bitcode ->", OUTFN) +end \ No newline at end of file diff --git a/dist/scripts/gfx/bgfx.t b/dist/scripts/gfx/bgfx.t index 12ee7e3b..6f3bdd12 100644 --- a/dist/scripts/gfx/bgfx.t +++ b/dist/scripts/gfx/bgfx.t @@ -3,8 +3,9 @@ -- bgfx C api local modutils = require("core/module.t") +local build = require("core/build.t") -local bgfx_c = terralib.includec("bgfx/bgfx_truss.c99.h") +local bgfx_c = build.includec("bgfx/bgfx_truss.c99.h") local bgfx_const = require("./bgfx_constants.t") local bgfx = {} @@ -17,6 +18,6 @@ function bgfx.check_handle(h) return h.idx ~= bgfx.INVALID_HANDLE end -truss.link_library("lib", "bgfx-shared-libRelease") +build.truss_link_library("lib", "bgfx-shared-libRelease") return bgfx diff --git a/dist/scripts/gfx/imageload.t b/dist/scripts/gfx/imageload.t index 7f85f55e..5418d1a9 100644 --- a/dist/scripts/gfx/imageload.t +++ b/dist/scripts/gfx/imageload.t @@ -1,8 +1,9 @@ local bgfx = require("./bgfx.t") -- make sure bgfx is loaded +local build = require("core/build.t") local m = {} -local C = terralib.includec("bgfx/bgfx_imageutil.h") +local C = build.includec("bgfx/bgfx_imageutil.h") m.C = C function m.release_image(imgdata) @@ -10,6 +11,7 @@ function m.release_image(imgdata) end function m.load_image_from_file(fn) + assert(build.is_native(), "cannot actually call image load functions in cross-compilation context!") local data = truss.C.load_file(fn) if data == nil then return nil end local imdata = terralib.new(C.bgfx_util_imagedata) diff --git a/dist/scripts/gfx/imrender.t b/dist/scripts/gfx/imrender.t index 61c42b4c..f8ee2369 100644 --- a/dist/scripts/gfx/imrender.t +++ b/dist/scripts/gfx/imrender.t @@ -108,9 +108,13 @@ function ImmediateContext:_assert_view() end end +function ImmediateContext:set_globals(globals) + self._globals = globals +end + function ImmediateContext:draw_dc(dc, tf) self:_assert_view() - dc:static_submit(self._current_view._viewid, {}, tf or self._identity_matrix) + dc:static_submit(self._current_view._viewid, self._globals or {}, tf or self._identity_matrix) end function ImmediateContext:draw_mesh(geo, mat, tf) diff --git a/dist/scripts/gfx/nanovg.t b/dist/scripts/gfx/nanovg.t index 322691c8..33efbc31 100644 --- a/dist/scripts/gfx/nanovg.t +++ b/dist/scripts/gfx/nanovg.t @@ -2,11 +2,12 @@ -- -- nanovg +local build = require("core/build.t") local modutils = require("core/module.t") local class = require("class") local m = {} -local nanovg_c_raw = terralib.includec("bgfx/nanovg_terra.h") +local nanovg_c_raw = build.includec("bgfx/nanovg_terra.h") local nvg_c_funcs = {} local nvg_c = {} diff --git a/dist/scripts/gfx/texture.t b/dist/scripts/gfx/texture.t index 04ffd147..0ef2538b 100644 --- a/dist/scripts/gfx/texture.t +++ b/dist/scripts/gfx/texture.t @@ -147,7 +147,7 @@ end function Texture:async_read_rt(view, mip) local rt = self.read_source.rt local layer = self.read_source.layer - self:raw_blit_copy(rt:get_layer_handle(layer), view or 0) + self:raw_blit_copy(rt:get_layer_handle(layer), view or 255) return self:async_read_back(mip or 0) end diff --git a/dist/scripts/graphics/immediate.t b/dist/scripts/graphics/immediate.t index 9dafe1cf..d535fd98 100644 --- a/dist/scripts/graphics/immediate.t +++ b/dist/scripts/graphics/immediate.t @@ -30,7 +30,7 @@ function ImmediateStage:bind(start_id, num_views) end function ImmediateStage:run(f, next, err) - async.run(function() + return async.run(function() self.ctx:await_frame() f(self.ctx) end):next(next or print, err or print) diff --git a/dist/scripts/graphics/init.t b/dist/scripts/graphics/init.t index c9645b9f..661c708a 100644 --- a/dist/scripts/graphics/init.t +++ b/dist/scripts/graphics/init.t @@ -18,7 +18,8 @@ moduleutils.include_submodules({ "graphics/line.t", "graphics/nanovg.t", "graphics/taskstage.t", - "graphics/canvas.t" + "graphics/canvas.t", + "graphics/immediate.t" }, graphics) return graphics diff --git a/dist/scripts/imgui/databar.t b/dist/scripts/imgui/databar.t index cde9f7a2..b7a60859 100644 --- a/dist/scripts/imgui/databar.t +++ b/dist/scripts/imgui/databar.t @@ -83,6 +83,37 @@ local function gen_progress(finfo, settings, field_q, io_q) end end +local function gen_list(finfo, settings, field_q, io_q) + local label = assert(finfo.label or finfo.name) + local choices = assert(finfo.choices) + local items = terralib.constant(`arrayof([&int8], [choices])) + local nitems = #choices + local maxheight = math.min(nitems, finfo.max_height or 10) + return quote + IG.ListBox_Str_arr(label, &field_q, items, nitems, maxheight) + end +end + +local function gen_cumulative_list(finfo, settings, field_q, io_q) + local label = assert(finfo.label or finfo.name) + local choices = assert(finfo.choices) + local items = terralib.constant(`arrayof([&int8], [choices])) + local nitems = #choices + local maxheight = math.min(nitems, finfo.max_height or 10) + return quote + --IG.Combo_Str_arr(label, &field_q, items, nitems, maxheight) + var height = IG.GetTextLineHeightWithSpacing() * maxheight + if not IG.BeginListBox(label, IG.Vec2{0.0, height}) then return end + for idx = 0, nitems do + var selected = field_q >= idx + if IG.Selectable_Bool(items[idx], selected, 0, IG.Vec2{0.0, 0.0}) then + field_q = idx + end + end + IG.EndListBox() + end +end + local struct Color { r: float; g: float; @@ -120,6 +151,8 @@ KINDS["color"] = { } KINDS["progress"] = {ctype = float, default = 0.0, gen_draw = gen_progress} KINDS["choice"] = {ctype = int32, default = 0, gen_draw = gen_choice} +KINDS["list"] = {ctype = int32, default = 0, gen_draw = gen_list} +KINDS["cumulative_list"] = {ctype = int32, default = 0, gen_draw = gen_cumulative_list} KINDS["bool"] = {ctype = bool, default = false, gen_draw = gen_checkbox} KINDS["button"] = {ctype = int32, default = 0, gen_draw = gen_button} KINDS["divider"] = {ctype = nil, gen_draw = gen_divider} @@ -144,7 +177,12 @@ end function DatabarBuilder:field(options) local name = options[1] or options.name local kind = options[2] or options.kind or name -- to avoid {"divider", "divider"} - local kind_info = KINDS[kind] + local kind_info + if type(kind) == 'string' then + kind_info = KINDS[kind] + elseif type(kind) == 'table' then + kind_info = kind + end if not kind_info then truss.error("Unknown Databar field kind: " .. kind) end diff --git a/dist/scripts/imgui/imgui.t b/dist/scripts/imgui/imgui.t index 0c094a9e..0d1fe6c5 100644 --- a/dist/scripts/imgui/imgui.t +++ b/dist/scripts/imgui/imgui.t @@ -2,12 +2,13 @@ -- -- imgui +local build = require("core/build.t") local modutils = require("core/module.t") local class = require("class") local clib = require("native/clib.t") local m = {} -local imgui_c_raw = terralib.includec("bgfx/cimgui_terra.h") +local imgui_c_raw = build.includec("bgfx/cimgui_terra.h") m.C_raw = imgui_c_raw local C = {} diff --git a/dist/scripts/input/sdl.t b/dist/scripts/input/sdl.t index 620d1d49..0b283936 100644 --- a/dist/scripts/input/sdl.t +++ b/dist/scripts/input/sdl.t @@ -1,16 +1,19 @@ +local build = require("core/build.t") local modutils = require("core/module.t") -local sdl_c_raw = terralib.includec("sdl/sdl_minimal.h") +local sdl_c_raw = build.includec("sdl/sdl_minimal.h") local sdl_c = modutils.reexport_without_prefix(sdl_c_raw, "SDL_") sdl_c.raw = sdl_c_raw -if truss.os == "Windows" then - terralib.linklibrary("SDL2") -elseif truss.os == "OSX" then - -- HMM not sure why I need to do it this way - terralib.linklibrary("lib/libSDL2-2.0.dylib") -else - terralib.linklibrary("libSDL2") +if build.is_native() then + if truss.os == "Windows" then + build.linklibrary("SDL2") + elseif truss.os == "OSX" then + -- HMM not sure why I need to do it this way + build.linklibrary("lib/libSDL2-2.0.dylib") + else + build.linklibrary("lib/libSDL2-2.0.so") + end end return sdl_c diff --git a/dist/scripts/input/sixense.t b/dist/scripts/input/sixense.t deleted file mode 100644 index e3214026..00000000 --- a/dist/scripts/input/sixense.t +++ /dev/null @@ -1,81 +0,0 @@ --- sixense.t --- --- a wrapper for the sixense (razer hydra) sdk - --- ffi bitops to get button states -local bit = bit - --- link the dynamic library (should only happen once ideally) -terralib.linklibrary("sixense") -local sixense_ = terralib.includec("sixense.h") - -local m = {} -m.data = terralib.new(sixense_.sixenseAllControllerData) -m.sixense_ = sixense_ -m.controllers = {} - -function m.init() - local result = sixense_.sixenseInit() - if result ~= sixense_.SIXENSE_SUCCESS then - log.error("Unable to init sixense sdk!") - return false - else - log.info("Sixense SDK connected") - end - -- update with SIXENSE_MAX_CONTROLLERS just to populate the - -- m.controllers structure for all the possible controllers - -- (unused controllers will just be filled with zeroes) - local maxcontrollers = sixense_.SIXENSE_MAX_CONTROLLERS - log.info("Max controllers: " .. maxcontrollers) - m.updateControllers_(maxcontrollers) - return true -end - -function m.update() - sixense_.sixenseGetAllNewestData(m.data) - m.updateControllers_(m.numControllers()) -end - -local function interpretController(src, dest) - -- motion sensing position - dest.pos = {src.pos[0], src.pos[1], src.pos[2]} - dest.quat = {src.rot_quat[0], src.rot_quat[1], - src.rot_quat[2], src.rot_quat[3]} - - -- joystick - dest.joy = {src.joystick_x, src.joystick_y} - dest.trigger = src.trigger - - -- buttons - local bstate = src.buttons - local band = bit.band - dest.button1 = band(bstate, sixense_.SIXENSE_BUTTON_1) - dest.button2 = band(bstate, sixense_.SIXENSE_BUTTON_2) - dest.button3 = band(bstate, sixense_.SIXENSE_BUTTON_3) - dest.button4 = band(bstate, sixense_.SIXENSE_BUTTON_4) - dest.buttonStart = band(bstate, sixense_.SIXENSE_BUTTON_START) - dest.buttonJoy = band(bstate, sixense_.SIXENSE_BUTTON_JOYSTICK) - dest.buttonBumper = band(bstate, sixense_.SIXENSE_BUTTON_BUMPER) - - -- info - dest.docked = src.is_docked > 0 - dest.hand = src.which_hand - dest.enabled = src.enabled -end - -function m.updateControllers_(nControllers) - for i = 1, nControllers do - m.controllers[i] = m.controllers[i] or {} - interpretController(m.data.controllers[i-1], m.controllers[i]) - end -end - -function m.numControllers() - return sixense_.sixenseGetNumActiveControllers() -end - -function m.exit() - sixense_.sixenseExit() -end - -return m \ No newline at end of file diff --git a/dist/scripts/input/windowing.t b/dist/scripts/input/windowing.t index 12f08f76..c4218e04 100644 --- a/dist/scripts/input/windowing.t +++ b/dist/scripts/input/windowing.t @@ -98,10 +98,21 @@ local function platform_specific_bgfx_setup(pd, wmi) end elseif truss.os == "OSX" then return quote - -- hack: the cocoa pointer is unioned to the same spot - -- and we're casting to void pointer anyway - pd.nwh = wmi.info.win.window - --wmi.info.cocoa.window + pd.nwh = wmi.info.cocoa.window + end + elseif truss.os == "Linux" then + -- do we need to care about Wayland? + return quote + if false and wmi.subsystem == SDL.SYSWM_WAYLAND then + -- this may not actually work, the bgfx entry example + -- really wants to actually create an egl window itself + -- for some reason + pd.nwh = wmi.info.wl.egl_window + pd.ndt = wmi.info.wl.display + else + pd.nwh = wmi.info.x11.window + pd.ndt = wmi.info.x11.display + end end else truss.error("Windowing not yet implemented for " .. truss.os) diff --git a/dist/scripts/io/zmq.t b/dist/scripts/io/zmq.t index 105b0787..4a255b2b 100644 --- a/dist/scripts/io/zmq.t +++ b/dist/scripts/io/zmq.t @@ -2,6 +2,7 @@ -- -- zeromq bindings +local build = require("core/build.t") local modutils = require("core/module.t") local class = require("class") local m = {} @@ -196,8 +197,8 @@ else end -- link the dynamic library (should only happen once ideally) -truss.link_library("libzmq") -local zmq_c = terralib.includecstring(header) +build.truss_link_library("libzmq") +local zmq_c = build.includecstring(header) m.C_raw = zmq_c local C = {} modutils.reexport_without_prefix(zmq_c, "zmq_", C) diff --git a/dist/scripts/math/cmath.t b/dist/scripts/math/cmath.t index 6878fd28..ef0ba974 100644 --- a/dist/scripts/math/cmath.t +++ b/dist/scripts/math/cmath.t @@ -2,4 +2,5 @@ -- -- just a stub to include the c "math.h" -return terralib.includec("math.h") +local build = require("core/build.t") +return build.includec("math.h") diff --git a/dist/scripts/math/colorspaces.t b/dist/scripts/math/colorspaces.t index 9a17faac..36fb903e 100644 --- a/dist/scripts/math/colorspaces.t +++ b/dist/scripts/math/colorspaces.t @@ -18,17 +18,17 @@ terra m.lab2rgb(lab: &float, rgb: &float, normalize: bool) var x: double = lab[1] / 500.0 + y var z: double = y - lab[2] / 200.0 - x = 0.95047 * terralib.select(x * x * x > 0.008856, x * x * x, (x - 16/116) / 7.787) - y = 1.00000 * terralib.select(y * y * y > 0.008856, y * y * y, (y - 16/116) / 7.787) - z = 1.08883 * terralib.select(z * z * z > 0.008856, z * z * z, (z - 16/116) / 7.787) + x = 0.95047 * terralib.select(x * x * x > 0.008856, x * x * x, (x - 16.0/116.0) / 7.787) + y = 1.00000 * terralib.select(y * y * y > 0.008856, y * y * y, (y - 16.0/116.0) / 7.787) + z = 1.08883 * terralib.select(z * z * z > 0.008856, z * z * z, (z - 16.0/116.0) / 7.787) var r = x * 3.2406 + y * -1.5372 + z * -0.4986 var g = x * -0.9689 + y * 1.8758 + z * 0.0415 var b = x * 0.0557 + y * -0.2040 + z * 1.0570 - r = terralib.select(r > 0.0031308, 1.055 * cmath.pow(r, 1/2.4) - 0.055, 12.92 * r) - g = terralib.select(g > 0.0031308, 1.055 * cmath.pow(g, 1/2.4) - 0.055, 12.92 * g) - b = terralib.select(b > 0.0031308, 1.055 * cmath.pow(b, 1/2.4) - 0.055, 12.92 * b) + r = terralib.select(r > 0.0031308, 1.055 * cmath.pow(r, 1.0/2.4) - 0.055, 12.92 * r) + g = terralib.select(g > 0.0031308, 1.055 * cmath.pow(g, 1.0/2.4) - 0.055, 12.92 * g) + b = terralib.select(b > 0.0031308, 1.055 * cmath.pow(b, 1.0/2.4) - 0.055, 12.92 * b) rgb[0] = clamp(r, 0.0, 1.0) rgb[1] = clamp(g, 0.0, 1.0) diff --git a/dist/scripts/native/buffer.t b/dist/scripts/native/buffer.t index af079231..73ef3f5a 100644 --- a/dist/scripts/native/buffer.t +++ b/dist/scripts/native/buffer.t @@ -102,6 +102,15 @@ local Buffer = terralib.memoize(function(T) return self.data[self.used_count] end + terra _Buffer:push_new(): &T + if self.used_count >= self.count then + return nil + end + var ret: &T = &(self.data[self.used_count]) + self.used_count = self.used_count + 1 + return ret + end + terra _Buffer:push_single(val: T): bool if self.used_count >= self.count then return false diff --git a/dist/scripts/native/cfile.t b/dist/scripts/native/cfile.t index 220a4adc..a84d1263 100644 --- a/dist/scripts/native/cfile.t +++ b/dist/scripts/native/cfile.t @@ -24,12 +24,20 @@ local function build_file(opts) local VERBOSE = opts.verbose local DBGPRINT = opts.DBGPRINT or default_print + local size_t = c.io.size_t + local struct CFile { file: &c.io.FILE; - length: uint64; + length: size_t; } + terra CFile:init() + self.file = nil + self.length = 0 + end + terra CFile:open(fn: &int8, write: bool): bool + self.length = 0 if write then self.file = c.io.fopen(fn, "wb") else @@ -39,7 +47,6 @@ local function build_file(opts) c.io.printf(errformat, fn) return false end - self.length = 0 if not write then c.io.fseek(self.file, 0, c.io.SEEK_END) self.length = c.io.ftell(self.file) @@ -48,12 +55,35 @@ local function build_file(opts) return true end + terra CFile:seek_end(): size_t + if self.file == nil then return 0 end + c.io.fseek(self.file, 0, c.io.SEEK_END) + return c.io.ftell(self.file) + end + terra CFile:close() c.io.fclose(self.file) self.file = nil end - terra CFile:read_into(target: &ByteBuffer, pos: uint64, len: uint64): bool + terra CFile:read_raw(target: &uint8, targetsize: size_t, nread: size_t): size_t + if self.file == nil then + [DBGPRINT("Tried to read from nil file")] + return 0 + end + if nread > self.length then + [DBGPRINT("Out of bounds read: %d > %d", nread, `self.length)] + return 0 + end + if nread > targetsize then + [DBGPRINT("Buffer too small: %d < %d", `targetsize, nread)] + return 0 + end + c.io.fread(target, 1, nread, self.file) + return nread + end + + terra CFile:read_into(target: &ByteBuffer, pos: size_t, len: size_t): bool if self.file == nil then [DBGPRINT("Tried to read from nil file")] return false @@ -68,6 +98,7 @@ local function build_file(opts) end c.io.fseek(self.file, pos, c.io.SEEK_SET) c.io.fread(target.data, 1, len, self.file) + target.used_count = len return true end @@ -86,7 +117,20 @@ local function build_file(opts) return buff end - terra CFile:write(data: &uint8, datasize: uint32) + terra CFile:seek(pos: size_t) + if self.file == nil then return end + c.io.fseek(self.file, pos, c.io.SEEK_SET) + end + + terra CFile:write_append(data: &uint8, datasize: size_t) + if self.file == nil then return end + c.io.fseek(self.file, 0, c.io.SEEK_END) + self.length = c.io.ftell(self.file) + c.io.fwrite(data, 1, datasize, self.file) + self.length = self.length + datasize + end + + terra CFile:write(data: &uint8, datasize: size_t) if self.file == nil then return end c.io.fwrite(data, 1, datasize, self.file) end diff --git a/dist/scripts/native/clib.t b/dist/scripts/native/clib.t index 77965c00..75bb4b7b 100644 --- a/dist/scripts/native/clib.t +++ b/dist/scripts/native/clib.t @@ -1,8 +1,10 @@ -- wrapper around common C includes +local build = require("core/build.t") + return { - std = terralib.includec("stdlib.h"), - io = terralib.includec("stdio.h"), - str = terralib.includec("string.h"), + std = build.includec("stdlib.h"), + io = build.includec("stdio.h"), + str = build.includec("string.h"), math = require("math/cmath.t") } \ No newline at end of file diff --git a/dist/scripts/native/cstd.t b/dist/scripts/native/cstd.t deleted file mode 100644 index f86f215a..00000000 --- a/dist/scripts/native/cstd.t +++ /dev/null @@ -1,7 +0,0 @@ --- native/cstd.t --- --- just a wrapper around c standard headers to avoid repeated --- parsing/inclusion of the same headers - -local Cstd = terralib.includec("stdlib.h") -return Cstd \ No newline at end of file diff --git a/dist/scripts/native/timing.t b/dist/scripts/native/timing.t index e7342f24..0af1bfaa 100644 --- a/dist/scripts/native/timing.t +++ b/dist/scripts/native/timing.t @@ -2,10 +2,13 @@ -- -- high-performance timing junk +local build = require("core/build.t") local m = {} -if truss.os == "Windows" then - local C = terralib.includecstring[[ +local target = build.target_name() + +if target == "Windows" then + local C = build.includecstring[[ #include "stdint.h" typedef int BOOL; BOOL QueryPerformanceFrequency(int64_t* lpFrequency); @@ -24,8 +27,8 @@ if truss.os == "Windows" then return ret end --elseif truss.os == "OSX" then -else -- hope this works on linux - local C = terralib.includecstring[[ +else -- hope this works on linux/osx/wasm + local C = build.includecstring[[ #include "stdint.h" typedef enum { CLOCK_REALTIME = 0, diff --git a/dist/scripts/procgen/marchingcubes.t b/dist/scripts/procgen/marchingcubes.t index 38cb706f..27ad7fad 100644 --- a/dist/scripts/procgen/marchingcubes.t +++ b/dist/scripts/procgen/marchingcubes.t @@ -6,9 +6,9 @@ local m = {} local math = require("math") local vec4 = require("math/types.t").vec4_ -local cmath = require("math/cmath.t") - -local C = terralib.includec("stdio.h") +local clib = require("native/clib.t") +local cmath = clib.math +local cio = clib.io local struct index_list { n_indices: uint8; diff --git a/dist/scripts/sound/soloud.t b/dist/scripts/sound/soloud.t index c6bde226..0bc7527b 100644 --- a/dist/scripts/sound/soloud.t +++ b/dist/scripts/sound/soloud.t @@ -8,7 +8,7 @@ local modutils = require("core/module.t") -- link the dynamic library (should only happen once ideally) terralib.linklibrary("soloud_x64") -local C_raw = terralib.includec("soloud_c.h") +local C_raw = terralib.includec("soloud/soloud_c.h") local C = modutils.reexport_without_prefix(C_raw, "Soloud_") m.C = C diff --git a/dist/scripts/sound/soloud_test.t b/dist/scripts/sound/soloud_test.t index d149bcb9..985244c2 100644 --- a/dist/scripts/sound/soloud_test.t +++ b/dist/scripts/sound/soloud_test.t @@ -10,12 +10,10 @@ local orbitcam = require("graphics/orbitcam.t") local grid = require("graphics/grid.t") local config = require("util/config.t") local soloud = require('sound/soloud.t') - -local stdlib = terralib.includec("stdlib.h") -local stdio = terralib.includec("stdio.h") +local clib = require("native/clib.t") local terra test_alloc(): &float - var x = [&float](stdlib.malloc(sizeof(float))) + var x = [&float](clib.std.malloc(sizeof(float))) return x end diff --git a/dist/shaders/raw/depth/fs_float_depth.sc b/dist/shaders/raw/depth/fs_float_depth.sc new file mode 100644 index 00000000..25f32c5c --- /dev/null +++ b/dist/shaders/raw/depth/fs_float_depth.sc @@ -0,0 +1,14 @@ +$input v_vpos + +/* + * Copyright 2015 Pyry Matikainen + * MIT License + */ + +#include "common.sh" + +void main() +{ + float rawDepth = v_vpos.z; + gl_FragColor = vec4(rawDepth, 0.0, 0.0, 0.0); +} diff --git a/dist/shaders/raw/depth/fs_worldspace.sc b/dist/shaders/raw/depth/fs_worldspace.sc new file mode 100644 index 00000000..5851632d --- /dev/null +++ b/dist/shaders/raw/depth/fs_worldspace.sc @@ -0,0 +1,13 @@ +$input v_vpos + +/* + * Copyright 2015 Pyry Matikainen + * MIT License + */ + +#include "common.sh" + +void main() +{ + gl_FragColor = vec4(v_vpos.xyz, 1.0); +} diff --git a/dist/shaders/raw/depth/vs_worldspace.sc b/dist/shaders/raw/depth/vs_worldspace.sc new file mode 100644 index 00000000..04c11c4f --- /dev/null +++ b/dist/shaders/raw/depth/vs_worldspace.sc @@ -0,0 +1,15 @@ +$input a_position +$output v_vpos + +/* + * Copyright 2021 Pyry Matikainen + * MIT License + */ + +#include "common.sh" + +void main() +{ + v_vpos = mul(u_model[0], vec4(a_position, 1.0) ); + gl_Position = mul(u_viewProj, vec4(v_vpos.xyz, 1.0)); +} \ No newline at end of file diff --git a/dist/shaders/raw/unwrap/fs_unwrap_worldpos.sc b/dist/shaders/raw/unwrap/fs_unwrap_worldpos.sc new file mode 100644 index 00000000..e767305c --- /dev/null +++ b/dist/shaders/raw/unwrap/fs_unwrap_worldpos.sc @@ -0,0 +1,8 @@ +$input v_wpos, v_uv + +#include "common.sh" + +void main() +{ + gl_FragColor = vec4(v_wpos.xyz, 1.0); +} diff --git a/dist/shaders/raw/unwrap/varying.def.sc b/dist/shaders/raw/unwrap/varying.def.sc new file mode 100644 index 00000000..4acdf4e0 --- /dev/null +++ b/dist/shaders/raw/unwrap/varying.def.sc @@ -0,0 +1,5 @@ +vec3 v_wpos : TEXCOORD1 = vec3(0.0, 0.0, 0.0); +vec2 v_uv : TEXCOORD2 = vec2(0.0, 0.0); + +vec3 a_position : POSITION; +vec2 a_texcoord0 : TEXCOORD0; \ No newline at end of file diff --git a/dist/shaders/raw/unwrap/vs_unwrap.sc b/dist/shaders/raw/unwrap/vs_unwrap.sc new file mode 100644 index 00000000..d0045314 --- /dev/null +++ b/dist/shaders/raw/unwrap/vs_unwrap.sc @@ -0,0 +1,15 @@ +$input a_position, a_texcoord0 +$output v_wpos, v_uv + +#include "common.sh" + +void main() +{ + v_wpos = mul(u_model[0], vec4(a_position, 1.0) ).xyz; + v_uv = a_texcoord0; + //v_uv += vec2(0.5/2048.0, 0.5/2048.0); + //v_uv.x = 1.0 - v_uv.x; + //v_uv.y = 1.0 - v_uv.y; // flip vertically + + gl_Position = vec4(v_uv.xy * 2.0 - vec2(1.0, 1.0), 0.5, 1.0); +} diff --git a/dist/vulkan_env_setup.sh b/dist/vulkan_env_setup.sh new file mode 100755 index 00000000..1a883c1d --- /dev/null +++ b/dist/vulkan_env_setup.sh @@ -0,0 +1,2 @@ +#! /bin/bash +export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json \ No newline at end of file diff --git a/src/trussapi.h b/src/trussapi.h index 30229a7c..bc6f4b7d 100644 --- a/src/trussapi.h +++ b/src/trussapi.h @@ -6,7 +6,7 @@ #ifndef TRUSSAPI_H_HEADER_GUARD #define TRUSSAPI_H_HEADER_GUARD -#define TRUSS_VERSION_STRING "0.2.1" +#define TRUSS_VERSION_STRING "0.2.2" #include // Needed for uint64_t etc. #include // Needed for size_t etc.