diff --git a/cmake/FindBGFX.cmake b/cmake/FindBGFX.cmake new file mode 100644 index 0000000..16c9809 --- /dev/null +++ b/cmake/FindBGFX.cmake @@ -0,0 +1,8 @@ +find_path(BGFX_INCLUDE_DIR bgfx.h) +find_library(BGFX_LIBRARY NAMES bgfx) + +set(BGFX_INCLUDE_DIRS ${BGFX_INCLUDE_DIR}) +set(BGFX_LIBRARIES ${BGFX_LIBRARY}) + +find_package_handle_standard_args(BGFX DEFAULT_MSG BGFX_LIBRARY BGFX_INCLUDE_DIR) +mark_as_advanced(BGFX_FOUND BGFX_INCLUDE_DIR BGFX_LIBRARY) diff --git a/deps/include/bgfx.c99.h b/deps/include/bgfx.c99.h new file mode 100644 index 0000000..0ef6fce --- /dev/null +++ b/deps/include/bgfx.c99.h @@ -0,0 +1,775 @@ +/* + * Copyright 2011-2015 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + * + * vim: set tabstop=4 expandtab: + */ + +#ifndef BGFX_C99_H_HEADER_GUARD +#define BGFX_C99_H_HEADER_GUARD + +#include // va_list +#include // bool +#include // uint32_t +#include // size_t + +#include "bgfxdefines.h" + +typedef enum bgfx_renderer_type +{ + BGFX_RENDERER_TYPE_NULL, + BGFX_RENDERER_TYPE_DIRECT3D9, + BGFX_RENDERER_TYPE_DIRECT3D11, + BGFX_RENDERER_TYPE_DIRECT3D12, + BGFX_RENDERER_TYPE_METAL, + BGFX_RENDERER_TYPE_OPENGLES, + BGFX_RENDERER_TYPE_OPENGL, + BGFX_RENDERER_TYPE_VULKAN, + + BGFX_RENDERER_TYPE_COUNT + +} bgfx_renderer_type_t; + +typedef enum bgfx_access +{ + BGFX_ACCESS_READ, + BGFX_ACCESS_WRITE, + BGFX_ACCESS_READWRITE, + + BGFX_ACCESS_COUNT + +} bgfx_access_t; + +typedef enum bgfx_attrib +{ + BGFX_ATTRIB_POSITION, + BGFX_ATTRIB_NORMAL, + BGFX_ATTRIB_TANGENT, + BGFX_ATTRIB_BITANGENT, + BGFX_ATTRIB_COLOR0, + BGFX_ATTRIB_COLOR1, + BGFX_ATTRIB_INDICES, + BGFX_ATTRIB_WEIGHT, + BGFX_ATTRIB_TEXCOORD0, + BGFX_ATTRIB_TEXCOORD1, + BGFX_ATTRIB_TEXCOORD2, + BGFX_ATTRIB_TEXCOORD3, + BGFX_ATTRIB_TEXCOORD4, + BGFX_ATTRIB_TEXCOORD5, + BGFX_ATTRIB_TEXCOORD6, + BGFX_ATTRIB_TEXCOORD7, + + BGFX_ATTRIB_COUNT + +} bgfx_attrib_t; + +typedef enum bgfx_attrib_type +{ + BGFX_ATTRIB_TYPE_UINT8, + BGFX_ATTRIB_TYPE_UINT10, + BGFX_ATTRIB_TYPE_INT16, + BGFX_ATTRIB_TYPE_HALF, + BGFX_ATTRIB_TYPE_FLOAT, + + BGFX_ATTRIB_TYPE_COUNT + +} bgfx_attrib_type_t; + +typedef enum bgfx_texture_format +{ + BGFX_TEXTURE_FORMAT_BC1, + BGFX_TEXTURE_FORMAT_BC2, + BGFX_TEXTURE_FORMAT_BC3, + BGFX_TEXTURE_FORMAT_BC4, + BGFX_TEXTURE_FORMAT_BC5, + BGFX_TEXTURE_FORMAT_BC6H, + BGFX_TEXTURE_FORMAT_BC7, + BGFX_TEXTURE_FORMAT_ETC1, + BGFX_TEXTURE_FORMAT_ETC2, + BGFX_TEXTURE_FORMAT_ETC2A, + BGFX_TEXTURE_FORMAT_ETC2A1, + BGFX_TEXTURE_FORMAT_PTC12, + BGFX_TEXTURE_FORMAT_PTC14, + BGFX_TEXTURE_FORMAT_PTC12A, + BGFX_TEXTURE_FORMAT_PTC14A, + BGFX_TEXTURE_FORMAT_PTC22, + BGFX_TEXTURE_FORMAT_PTC24, + + BGFX_TEXTURE_FORMAT_UNKNOWN, + + BGFX_TEXTURE_FORMAT_R1, + BGFX_TEXTURE_FORMAT_A8, + BGFX_TEXTURE_FORMAT_R8, + BGFX_TEXTURE_FORMAT_R8I, + BGFX_TEXTURE_FORMAT_R8U, + BGFX_TEXTURE_FORMAT_R8S, + BGFX_TEXTURE_FORMAT_R16, + BGFX_TEXTURE_FORMAT_R16I, + BGFX_TEXTURE_FORMAT_R16U, + BGFX_TEXTURE_FORMAT_R16F, + BGFX_TEXTURE_FORMAT_R16S, + BGFX_TEXTURE_FORMAT_R32I, + BGFX_TEXTURE_FORMAT_R32U, + BGFX_TEXTURE_FORMAT_R32F, + BGFX_TEXTURE_FORMAT_RG8, + BGFX_TEXTURE_FORMAT_RG8I, + BGFX_TEXTURE_FORMAT_RG8U, + BGFX_TEXTURE_FORMAT_RG8S, + BGFX_TEXTURE_FORMAT_RG16, + BGFX_TEXTURE_FORMAT_RG16I, + BGFX_TEXTURE_FORMAT_RG16U, + BGFX_TEXTURE_FORMAT_RG16F, + BGFX_TEXTURE_FORMAT_RG16S, + BGFX_TEXTURE_FORMAT_RG32I, + BGFX_TEXTURE_FORMAT_RG32U, + BGFX_TEXTURE_FORMAT_RG32F, + BGFX_TEXTURE_FORMAT_BGRA8, + BGFX_TEXTURE_FORMAT_RGBA8, + BGFX_TEXTURE_FORMAT_RGBA8I, + BGFX_TEXTURE_FORMAT_RGBA8U, + BGFX_TEXTURE_FORMAT_RGBA8S, + BGFX_TEXTURE_FORMAT_RGBA16, + BGFX_TEXTURE_FORMAT_RGBA16I, + BGFX_TEXTURE_FORMAT_RGBA16U, + BGFX_TEXTURE_FORMAT_RGBA16F, + BGFX_TEXTURE_FORMAT_RGBA16S, + BGFX_TEXTURE_FORMAT_RGBA32I, + BGFX_TEXTURE_FORMAT_RGBA32U, + BGFX_TEXTURE_FORMAT_RGBA32F, + BGFX_TEXTURE_FORMAT_R5G6B5, + BGFX_TEXTURE_FORMAT_RGBA4, + BGFX_TEXTURE_FORMAT_RGB5A1, + BGFX_TEXTURE_FORMAT_RGB10A2, + BGFX_TEXTURE_FORMAT_R11G11B10F, + + BGFX_TEXTURE_FORMAT_UNKNOWN_DEPTH, + + BGFX_TEXTURE_FORMAT_D16, + BGFX_TEXTURE_FORMAT_D24, + BGFX_TEXTURE_FORMAT_D24S8, + BGFX_TEXTURE_FORMAT_D32, + BGFX_TEXTURE_FORMAT_D16F, + BGFX_TEXTURE_FORMAT_D24F, + BGFX_TEXTURE_FORMAT_D32F, + BGFX_TEXTURE_FORMAT_D0S8, + + BGFX_TEXTURE_FORMAT_COUNT + +} bgfx_texture_format_t; + +typedef enum bgfx_uniform_type +{ + BGFX_UNIFORM_TYPE_INT1, + BGFX_UNIFORM_TYPE_END, + + BGFX_UNIFORM_TYPE_VEC4, + BGFX_UNIFORM_TYPE_MAT3, + BGFX_UNIFORM_TYPE_MAT4, + + BGFX_UNIFORM_TYPE_COUNT + +} bgfx_uniform_type_t; + +typedef enum bgfx_backbuffer_ratio +{ + BGFX_BACKBUFFER_RATIO_EQUAL, + BGFX_BACKBUFFER_RATIO_HALF, + BGFX_BACKBUFFER_RATIO_QUARTER, + BGFX_BACKBUFFER_RATIO_EIGHTH, + BGFX_BACKBUFFER_RATIO_SIXTEENTH, + BGFX_BACKBUFFER_RATIO_DOUBLE, + + BGFX_BACKBUFFER_RATIO_COUNT + +} bgfx_backbuffer_ratio_t; + +#define BGFX_HANDLE_T(_name) \ + typedef struct _name { uint16_t idx; } _name##_t; + +BGFX_HANDLE_T(bgfx_indirect_buffer_handle); +BGFX_HANDLE_T(bgfx_dynamic_index_buffer_handle); +BGFX_HANDLE_T(bgfx_dynamic_vertex_buffer_handle); +BGFX_HANDLE_T(bgfx_frame_buffer_handle); +BGFX_HANDLE_T(bgfx_index_buffer_handle); +BGFX_HANDLE_T(bgfx_program_handle); +BGFX_HANDLE_T(bgfx_shader_handle); +BGFX_HANDLE_T(bgfx_texture_handle); +BGFX_HANDLE_T(bgfx_uniform_handle); +BGFX_HANDLE_T(bgfx_vertex_buffer_handle); +BGFX_HANDLE_T(bgfx_vertex_decl_handle); + +#undef BGFX_HANDLE_T + +/**/ +typedef void (*bgfx_release_fn_t)(void* _ptr, void* _userData); + +/**/ +typedef struct bgfx_memory +{ + uint8_t* data; + uint32_t size; + +} bgfx_memory_t; + +/**/ +typedef struct bgfx_transform +{ + float* data; + uint16_t num; + +} bgfx_transform_t; + +/**/ +typedef struct bgfx_hmd_eye +{ + float rotation[4]; + float translation[3]; + float fov[4]; + float adjust[3]; + float pixelsPerTanAngle[2]; + +} bgfx_hmd_eye_t; + +/**/ +typedef struct bgfx_hmd +{ + bgfx_hmd_eye_t eye[2]; + uint16_t width; + uint16_t height; + uint32_t deviceWidth; + uint32_t deviceHeight; + uint8_t flags; + +} bgfx_hmd_t; + +/**/ +typedef struct bgfx_stats +{ + uint64_t cpuTime; + uint64_t cpuTimerFreq; + + uint64_t gpuTime; + uint64_t gpuTimerFreq; + +} bgfx_stats_t; + +/**/ +typedef struct bgfx_vertex_decl +{ + uint32_t hash; + uint16_t stride; + uint16_t offset[BGFX_ATTRIB_COUNT]; + uint16_t attributes[BGFX_ATTRIB_COUNT]; + +} bgfx_vertex_decl_t; + +/**/ +typedef struct bgfx_transient_index_buffer +{ + uint8_t* data; + uint32_t size; + bgfx_index_buffer_handle_t handle; + uint32_t startIndex; + +} bgfx_transient_index_buffer_t; + +/**/ +typedef struct bgfx_transient_vertex_buffer +{ + uint8_t* data; + uint32_t size; + uint32_t startVertex; + uint16_t stride; + bgfx_vertex_buffer_handle_t handle; + bgfx_vertex_decl_handle_t decl; + +} bgfx_transient_vertex_buffer_t; + +/**/ +typedef struct bgfx_instance_data_buffer +{ + uint8_t* data; + uint32_t size; + uint32_t offset; + uint32_t num; + uint16_t stride; + bgfx_vertex_buffer_handle_t handle; + +} bgfx_instance_data_buffer_t; + +/**/ +typedef struct bgfx_texture_info +{ + bgfx_texture_format_t format; + uint32_t storageSize; + uint16_t width; + uint16_t height; + uint16_t depth; + uint8_t numMips; + uint8_t bitsPerPixel; + bool cubeMap; + +} bgfx_texture_info_t; + +/**/ +typedef struct bgfx_caps_gpu +{ + uint16_t vendorId; + uint16_t deviceId; + +} bgfx_caps_gpu_t; + +/**/ +typedef struct bgfx_caps +{ + bgfx_renderer_type_t rendererType; + + uint64_t supported; + + uint32_t maxDrawCalls; + uint16_t maxTextureSize; + uint16_t maxViews; + uint8_t maxFBAttachments; + uint8_t numGPUs; + + uint16_t vendorId; + uint16_t deviceId; + bgfx_caps_gpu_t gpu[4]; + + uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT]; + +} bgfx_caps_t; + +/**/ +typedef enum bgfx_fatal +{ + BGFX_FATAL_DEBUG_CHECK, + BGFX_FATAL_MINIMUM_REQUIRED_SPECS, + BGFX_FATAL_INVALID_SHADER, + BGFX_FATAL_UNABLE_TO_INITIALIZE, + BGFX_FATAL_UNABLE_TO_CREATE_TEXTURE, + BGFX_FATAL_DEVICE_LOST, + + BGFX_FATAL_COUNT + +} bgfx_fatal_t; + +#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 defined(_MSC_VER) +# if BGFX_SHARED_LIB_BUILD +# define BGFX_SHARED_LIB_API __declspec(dllexport) +# elif BGFX_SHARED_LIB_USE +# define BGFX_SHARED_LIB_API __declspec(dllimport) +# else +# define BGFX_SHARED_LIB_API +# endif // BGFX_SHARED_LIB_* +#else +# define BGFX_SHARED_LIB_API +#endif // defined(_MSC_VER) + +#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) + +/**/ +typedef struct bgfx_callback_interface +{ + const struct bgfx_callback_vtbl* vtbl; + +} bgfx_callback_interface_t; + +/**/ +typedef struct bgfx_callback_vtbl +{ + void (*fatal)(bgfx_callback_interface_t* _this, 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); + 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_reallocator_interface +{ + const struct bgfx_reallocator_vtbl* vtbl; + +} bgfx_reallocator_interface_t; + +/**/ +typedef struct bgfx_reallocator_vtbl +{ + void* (*alloc)(bgfx_reallocator_interface_t* _this, size_t _size, size_t _align, const char* _file, uint32_t _line); + void (*free)(bgfx_reallocator_interface_t* _this, void* _ptr, size_t _align, const char* _file, uint32_t _line); + void* (*realloc)(bgfx_reallocator_interface_t* _this, void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line); + +} bgfx_reallocator_vtbl_t; + +/**/ +BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer); + +/**/ +BGFX_C_API void bgfx_vertex_decl_add(bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); + +/**/ +BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _decl, uint8_t _num); + +/**/ +BGFX_C_API void bgfx_vertex_decl_end(bgfx_vertex_decl_t* _decl); + +/**/ +BGFX_C_API void bgfx_vertex_pack(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index); + +/**/ +BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index); + +/**/ +BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num); + +/**/ +BGFX_C_API uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon); + +/**/ +BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); + +/**/ +BGFX_C_API void bgfx_image_rgba8_downsample_2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); + +/**/ +BGFX_C_API uint8_t bgfx_get_supported_renderers(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]); + +/**/ +BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type); + +/**/ +BGFX_C_API bool bgfx_init(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_reallocator_interface_t* _allocator); + +/**/ +BGFX_C_API void bgfx_shutdown(); + +/**/ +BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags); + +/**/ +BGFX_C_API uint32_t bgfx_frame(); + +/**/ +BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type(); + +/**/ +BGFX_C_API const bgfx_caps_t* bgfx_get_caps(); + +/**/ +BGFX_C_API const bgfx_hmd_t* bgfx_get_hmd(); + +/**/ +BGFX_C_API const bgfx_stats_t* bgfx_get_stats(); + +/**/ +BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size); + +/**/ +BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size); + +/**/ +BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size); + +/**/ +BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData); + +/**/ +BGFX_C_API void bgfx_set_debug(uint32_t _debug); + +/**/ +BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small); + +/**/ +BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...); + +/**/ +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); + +/**/ +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags); + +/**/ +BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle); + +/**/ +BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags); + +/**/ +BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle); + +/**/ +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags); + +/**/ +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags); + +/**/ +BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem); + +/**/ +BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle); + +/**/ +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags); + +/**/ +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags); + +/**/ +BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem); + +/**/ +BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle); + +/**/ +BGFX_C_API bool bgfx_check_avail_transient_index_buffer(uint32_t _num); + +/**/ +BGFX_C_API bool bgfx_check_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl); + +/**/ +BGFX_C_API bool bgfx_check_avail_instance_data_buffer(uint32_t _num, uint16_t _stride); + +/**/ +BGFX_C_API bool bgfx_check_avail_transient_buffers(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices); + +/**/ +BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num); + +/**/ +BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl); + +/**/ +BGFX_C_API bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices); + +/**/ +BGFX_C_API const bgfx_instance_data_buffer_t* bgfx_alloc_instance_data_buffer(uint32_t _num, uint16_t _stride); + +/**/ +BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num); + +/**/ +BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle); + +/**/ +BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem); + +/**/ +BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max); + +/**/ +BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle); + +/**/ +BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders); + +/**/ +BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders); + +/**/ +BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle); + +/**/ +BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format); + +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info); + +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); + +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags); + +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); + +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); + +/**/ +BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); + +/**/ +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); + +/**/ +BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, 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); + +/**/ +BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle); + +/**/ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags); + +/**/ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags); + +/**/ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures); + +/**/ +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 _depthFormat); + +/**/ +BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle); + +/**/ +BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num); + +/**/ +BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle); + +/**/ +BGFX_C_API void bgfx_set_clear_color(uint8_t _index, const float _rgba[4]); + +/**/ +BGFX_C_API void bgfx_set_view_name(uint8_t _id, const char* _name); + +/**/ +BGFX_C_API void bgfx_set_view_rect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/**/ +BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/**/ +BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil); + +/**/ +BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7); + +/**/ +BGFX_C_API void bgfx_set_view_seq(uint8_t _id, bool _enabled); + +/**/ +BGFX_C_API void bgfx_set_view_frame_buffer(uint8_t _id, bgfx_frame_buffer_handle_t _handle); + +/**/ +BGFX_C_API void bgfx_set_view_transform(uint8_t _id, const void* _view, const void* _proj); + +/**/ +BGFX_C_API void bgfx_set_view_transform_stereo(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR); + +/**/ +BGFX_C_API void bgfx_set_view_remap(uint8_t _id, uint8_t _num, const void* _remap); + +/**/ +BGFX_C_API void bgfx_set_marker(const char* _marker); + +/**/ +BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba); + +/**/ +BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil); + +/**/ +BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); + +/**/ +BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache); + +/**/ +BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num); + +/**/ +BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num); + +/**/ +BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num); + +/**/ +BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num); + +/**/ +BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + +/**/ +BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); + +/**/ +BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices); + +/**/ +BGFX_C_API void bgfx_set_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); + +/**/ +BGFX_C_API void bgfx_set_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _numVertices); + +/**/ +BGFX_C_API void bgfx_set_transient_vertex_buffer(const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices); + +/**/ +BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _num); + +/**/ +BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/**/ +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); + +/**/ +BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); + +/**/ +BGFX_C_API void bgfx_set_texture_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags); + +/**/ +BGFX_C_API uint32_t bgfx_touch(uint8_t _id); + +/**/ +BGFX_C_API uint32_t bgfx_submit(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth); + +/**/ +BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth); + +/**/ +BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); + +/**/ +BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format); + +/**/ +BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API uint32_t bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags); + +/**/ +BGFX_C_API uint32_t bgfx_dispatch_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags); + +/**/ +BGFX_C_API void bgfx_discard(); + +/**/ +BGFX_C_API void bgfx_save_screen_shot(const char* _filePath); + +#endif // BGFX_C99_H_HEADER_GUARD diff --git a/deps/include/bgfx.h b/deps/include/bgfx.h new file mode 100644 index 0000000..d84698a --- /dev/null +++ b/deps/include/bgfx.h @@ -0,0 +1,2061 @@ +/* + * Copyright 2011-2015 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#ifndef BGFX_H_HEADER_GUARD +#define BGFX_H_HEADER_GUARD + +#include // va_list +#include // uint32_t +#include // size_t + +#include "bgfxdefines.h" + +/// +#define BGFX_HANDLE(_name) \ + struct _name { uint16_t idx; }; \ + inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; } + +#define BGFX_INVALID_HANDLE { bgfx::invalidHandle } + +namespace bx { struct ReallocatorI; } + +/// BGFX +namespace bgfx +{ + /// 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, + 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, + Half, + Quarter, + Eighth, + Sixteenth, + Double, + + 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(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. + /// + /// - `BGFX_CAPS_TEXTURE_COMPARE_LEQUAL` - Less equal texture + /// compare mode. + /// - `BGFX_CAPS_TEXTURE_COMPARE_ALL` - All texture compare modes. + /// - `BGFX_CAPS_TEXTURE_3D` - 3D textures. + /// - `BGFX_CAPS_VERTEX_ATTRIB_HALF` - AttribType::Half. + /// - `BGFX_CAPS_INSTANCING` - Vertex instancing. + /// - `BGFX_CAPS_RENDERER_MULTITHREADED` - Renderer on separate + /// thread. + /// - `BGFX_CAPS_FRAGMENT_DEPTH` - Fragment shader can modify depth + /// buffer value (gl_FragDepth). + /// - `BGFX_CAPS_BLEND_INDEPENDENT` - Multiple render targets can + /// have different blend mode set individually. + /// - `BGFX_CAPS_COMPUTE` - Renderer has compute shaders. + /// - `BGFX_CAPS_FRAGMENT_ORDERING` - Intel's pixel sync. + /// - `BGFX_CAPS_SWAP_CHAIN` - Multiple windows. + /// + 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. + + /// 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_COLOR` - supported + /// - `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated + /// - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture + uint8_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. + }; + + /// 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 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 cpuTime; //!< CPU frame time. + uint64_t cpuTimerFreq; //!< CPU timer frequency. + + uint64_t gpuTime; //!< GPU frame 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); + + /// 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. + /// - `BGFX_PCI_ID_AMD` - AMD. + /// - `BGFX_PCI_ID_INTEL` - Intel. + /// - `BGFX_PCI_ID_NVIDIA` - nVidia. + /// + /// @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 + /// icustom allocator is thread safe. + /// + /// @returns `true` if initialization is sucessful. + /// + /// @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::ReallocatorI* _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, 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); + + /// Destroy texture. + /// + /// @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, TextureHandle* _handles, 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 cannnot 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); + + /// Set clear color palette value. + /// + /// @param[in] _index Index into palette. + /// @param[in] _rgba Packed 32-bit RGBA value. + /// + /// @attention C99 equivalent is `bgfx_set_clear_color`. + /// + void setClearColor(uint8_t _index, uint32_t _rgba); + + /// Set clear color palette value. + /// + /// @param[in] _index Index into palette. + /// @param[in] _r, _g, _b, _a RGBA floating point values. + /// + /// @attention C99 equivalent is `bgfx_set_clear_color`. + /// + void setClearColor(uint8_t _index, float _r, float _g, float _b, float _a); + + /// Set clear color palette value. + /// + /// @param[in] _index Index into palette. + /// @param[in] _rgba RGBA floating point value. + /// + /// @attention C99 equivalent is `bgfx_set_clear_color`. + /// + void setClearColor(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); + + /// 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); + + /// 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 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. + /// @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 = 0, uint32_t _numIndices = UINT32_MAX); + + /// 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 = 0, uint32_t _numIndices = UINT32_MAX); + + /// 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. + /// @param[in] _numVertices Number of vertices to render. + /// + /// @attention C99 equivalent is `bgfx_set_dynamic_vertex_buffer`. + /// + void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX); + + /// 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 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); + + /// Touch view. + uint32_t touch(uint8_t _id); + + /// Submit primitive for rendering. + /// + /// @param[in] _id View id. + /// @param[in] _handle Program. + /// @param[in] _depth Depth for sorting. + /// @returns Number of draw calls. + /// + /// @attention C99 equivalent is `bgfx_submit`. + /// + uint32_t submit(uint8_t _id, ProgramHandle _handle, int32_t _depth = 0); + + /// Submit primitive for rendering with index and instance data info from + /// indirect buffer. + /// + /// @param[in] _id View id. + /// @param[in] _handle 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. + /// + /// @attention C99 equivalent is `bgfx_submit_indirect`. + /// + uint32_t submit(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, int32_t _depth = 0); + + /// 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 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(); + + /// 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 diff --git a/deps/include/bgfxdefines.h b/deps/include/bgfxdefines.h new file mode 100644 index 0000000..f88e050 --- /dev/null +++ b/deps/include/bgfxdefines.h @@ -0,0 +1,394 @@ +/* + * Copyright 2011-2015 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#ifndef BGFX_DEFINES_H_HEADER_GUARD +#define BGFX_DEFINES_H_HEADER_GUARD + +/// +#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. +#define BGFX_STATE_ALPHA_WRITE UINT64_C(0x0000000000000002) //!< Enable alpha write. +#define BGFX_STATE_DEPTH_WRITE UINT64_C(0x0000000000000004) //!< Enable depth write. + +#define BGFX_STATE_DEPTH_TEST_LESS UINT64_C(0x0000000000000010) //!< Enable depth test, less. +#define BGFX_STATE_DEPTH_TEST_LEQUAL UINT64_C(0x0000000000000020) //!< Enable depth test, less equal. +#define BGFX_STATE_DEPTH_TEST_EQUAL UINT64_C(0x0000000000000030) //!< +#define BGFX_STATE_DEPTH_TEST_GEQUAL UINT64_C(0x0000000000000040) //!< +#define BGFX_STATE_DEPTH_TEST_GREATER UINT64_C(0x0000000000000050) //!< +#define BGFX_STATE_DEPTH_TEST_NOTEQUAL UINT64_C(0x0000000000000060) //!< +#define BGFX_STATE_DEPTH_TEST_NEVER UINT64_C(0x0000000000000070) //!< +#define BGFX_STATE_DEPTH_TEST_ALWAYS UINT64_C(0x0000000000000080) //!< +#define BGFX_STATE_DEPTH_TEST_SHIFT 4 +#define BGFX_STATE_DEPTH_TEST_MASK UINT64_C(0x00000000000000f0) //!< Depth test state bit mask. + +#define BGFX_STATE_BLEND_ZERO UINT64_C(0x0000000000001000) //!< +#define BGFX_STATE_BLEND_ONE UINT64_C(0x0000000000002000) //!< +#define BGFX_STATE_BLEND_SRC_COLOR UINT64_C(0x0000000000003000) //!< +#define BGFX_STATE_BLEND_INV_SRC_COLOR UINT64_C(0x0000000000004000) //!< +#define BGFX_STATE_BLEND_SRC_ALPHA UINT64_C(0x0000000000005000) //!< +#define BGFX_STATE_BLEND_INV_SRC_ALPHA UINT64_C(0x0000000000006000) //!< +#define BGFX_STATE_BLEND_DST_ALPHA UINT64_C(0x0000000000007000) //!< +#define BGFX_STATE_BLEND_INV_DST_ALPHA UINT64_C(0x0000000000008000) //!< +#define BGFX_STATE_BLEND_DST_COLOR UINT64_C(0x0000000000009000) //!< +#define BGFX_STATE_BLEND_INV_DST_COLOR UINT64_C(0x000000000000a000) //!< +#define BGFX_STATE_BLEND_SRC_ALPHA_SAT UINT64_C(0x000000000000b000) //!< +#define BGFX_STATE_BLEND_FACTOR UINT64_C(0x000000000000c000) //!< +#define BGFX_STATE_BLEND_INV_FACTOR UINT64_C(0x000000000000d000) //!< +#define BGFX_STATE_BLEND_SHIFT 12 //!< Blend state bit shift. +#define BGFX_STATE_BLEND_MASK UINT64_C(0x000000000ffff000) //!< Blend state bit mask. + +#define BGFX_STATE_BLEND_EQUATION_ADD UINT64_C(0x0000000000000000) //!< +#define BGFX_STATE_BLEND_EQUATION_SUB UINT64_C(0x0000000010000000) //!< +#define BGFX_STATE_BLEND_EQUATION_REVSUB UINT64_C(0x0000000020000000) //!< +#define BGFX_STATE_BLEND_EQUATION_MIN UINT64_C(0x0000000030000000) //!< +#define BGFX_STATE_BLEND_EQUATION_MAX UINT64_C(0x0000000040000000) //!< +#define BGFX_STATE_BLEND_EQUATION_SHIFT 28 //!< Blend equation bit shift. +#define BGFX_STATE_BLEND_EQUATION_MASK UINT64_C(0x00000003f0000000) //!< Blend equation bit mask. + +#define BGFX_STATE_BLEND_INDEPENDENT UINT64_C(0x0000000400000000) //!< Enable blend independent. + +#define BGFX_STATE_CULL_CW UINT64_C(0x0000001000000000) //!< Cull clockwise triangles. +#define BGFX_STATE_CULL_CCW UINT64_C(0x0000002000000000) //!< Cull counter-clockwise triangles. +#define BGFX_STATE_CULL_SHIFT 36 //!< Culling mode bit shift. +#define BGFX_STATE_CULL_MASK UINT64_C(0x0000003000000000) //!< Culling mode bit mask. + +#define BGFX_STATE_ALPHA_REF_SHIFT 40 //!< +#define BGFX_STATE_ALPHA_REF_MASK UINT64_C(0x0000ff0000000000) //!< + +#define BGFX_STATE_PT_TRISTRIP UINT64_C(0x0001000000000000) //!< Tristrip. +#define BGFX_STATE_PT_LINES UINT64_C(0x0002000000000000) //!< Lines. +#define BGFX_STATE_PT_LINESTRIP UINT64_C(0x0003000000000000) //!< Line strip. +#define BGFX_STATE_PT_POINTS UINT64_C(0x0004000000000000) //!< Points. +#define BGFX_STATE_PT_SHIFT 48 //!< Primitive type bit shift. +#define BGFX_STATE_PT_MASK UINT64_C(0x0007000000000000) //!< Primitive type bit mask. + +#define BGFX_STATE_POINT_SIZE_SHIFT 52 //!< +#define BGFX_STATE_POINT_SIZE_MASK UINT64_C(0x0ff0000000000000) //!< + +/// Enable MSAA write when writing into MSAA frame buffer. This flag is ignored when not writing into +/// MSAA frame buffer. +#define BGFX_STATE_MSAA UINT64_C(0x1000000000000000) //!< + +#define BGFX_STATE_RESERVED_MASK UINT64_C(0xe000000000000000) //!< + +#define BGFX_STATE_NONE UINT64_C(0x0000000000000000) //!< +#define BGFX_STATE_MASK UINT64_C(0xffffffffffffffff) //!< + +/// Default state is write to RGB, alpha, and depth with depth test less enabled, with clockwise +/// culling and MSAA (when writing into MSAA frame buffer, otherwise this flag is ignored). +#define BGFX_STATE_DEFAULT (0 \ + | BGFX_STATE_RGB_WRITE \ + | BGFX_STATE_ALPHA_WRITE \ + | BGFX_STATE_DEPTH_TEST_LESS \ + | BGFX_STATE_DEPTH_WRITE \ + | BGFX_STATE_CULL_CW \ + | BGFX_STATE_MSAA \ + ) + +#define BGFX_STATE_ALPHA_REF(_ref) ( ( (uint64_t)(_ref )<>BGFX_STATE_BLEND_SHIFT) \ + | ( uint32_t( (_dst)>>BGFX_STATE_BLEND_SHIFT)<<4) ) \ + ) + +#define BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation) (0 \ + | BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) \ + | ( uint32_t( (_equation)>>BGFX_STATE_BLEND_EQUATION_SHIFT)<<8) \ + ) + +#define BGFX_STATE_BLEND_FUNC_RT_1(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<< 0) +#define BGFX_STATE_BLEND_FUNC_RT_2(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<<11) +#define BGFX_STATE_BLEND_FUNC_RT_3(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<<22) + +#define BGFX_STATE_BLEND_FUNC_RT_1E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<< 0) +#define BGFX_STATE_BLEND_FUNC_RT_2E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<<11) +#define BGFX_STATE_BLEND_FUNC_RT_3E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<<22) + +/// +#define BGFX_STENCIL_FUNC_REF_SHIFT 0 //!< +#define BGFX_STENCIL_FUNC_REF_MASK UINT32_C(0x000000ff) //!< +#define BGFX_STENCIL_FUNC_RMASK_SHIFT 8 //!< +#define BGFX_STENCIL_FUNC_RMASK_MASK UINT32_C(0x0000ff00) //!< + +#define BGFX_STENCIL_TEST_LESS UINT32_C(0x00010000) //!< Enable stencil test, less. +#define BGFX_STENCIL_TEST_LEQUAL UINT32_C(0x00020000) //!< +#define BGFX_STENCIL_TEST_EQUAL UINT32_C(0x00030000) //!< +#define BGFX_STENCIL_TEST_GEQUAL UINT32_C(0x00040000) //!< +#define BGFX_STENCIL_TEST_GREATER UINT32_C(0x00050000) //!< +#define BGFX_STENCIL_TEST_NOTEQUAL UINT32_C(0x00060000) //!< +#define BGFX_STENCIL_TEST_NEVER UINT32_C(0x00070000) //!< +#define BGFX_STENCIL_TEST_ALWAYS UINT32_C(0x00080000) //!< +#define BGFX_STENCIL_TEST_SHIFT 16 //!< +#define BGFX_STENCIL_TEST_MASK UINT32_C(0x000f0000) //!< + +#define BGFX_STENCIL_OP_FAIL_S_ZERO UINT32_C(0x00000000) //!< +#define BGFX_STENCIL_OP_FAIL_S_KEEP UINT32_C(0x00100000) //!< +#define BGFX_STENCIL_OP_FAIL_S_REPLACE UINT32_C(0x00200000) //!< +#define BGFX_STENCIL_OP_FAIL_S_INCR UINT32_C(0x00300000) //!< +#define BGFX_STENCIL_OP_FAIL_S_INCRSAT UINT32_C(0x00400000) //!< +#define BGFX_STENCIL_OP_FAIL_S_DECR UINT32_C(0x00500000) //!< +#define BGFX_STENCIL_OP_FAIL_S_DECRSAT UINT32_C(0x00600000) //!< +#define BGFX_STENCIL_OP_FAIL_S_INVERT UINT32_C(0x00700000) //!< +#define BGFX_STENCIL_OP_FAIL_S_SHIFT 20 //!< +#define BGFX_STENCIL_OP_FAIL_S_MASK UINT32_C(0x00f00000) //!< + +#define BGFX_STENCIL_OP_FAIL_Z_ZERO UINT32_C(0x00000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_KEEP UINT32_C(0x01000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_REPLACE UINT32_C(0x02000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_INCR UINT32_C(0x03000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_INCRSAT UINT32_C(0x04000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_DECR UINT32_C(0x05000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_DECRSAT UINT32_C(0x06000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_INVERT UINT32_C(0x07000000) //!< +#define BGFX_STENCIL_OP_FAIL_Z_SHIFT 24 //!< +#define BGFX_STENCIL_OP_FAIL_Z_MASK UINT32_C(0x0f000000) //!< + +#define BGFX_STENCIL_OP_PASS_Z_ZERO UINT32_C(0x00000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_KEEP UINT32_C(0x10000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_REPLACE UINT32_C(0x20000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_INCR UINT32_C(0x30000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_INCRSAT UINT32_C(0x40000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_DECR UINT32_C(0x50000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_DECRSAT UINT32_C(0x60000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_INVERT UINT32_C(0x70000000) //!< +#define BGFX_STENCIL_OP_PASS_Z_SHIFT 28 //!< +#define BGFX_STENCIL_OP_PASS_Z_MASK UINT32_C(0xf0000000) //!< + +#define BGFX_STENCIL_NONE UINT32_C(0x00000000) //!< +#define BGFX_STENCIL_MASK UINT32_C(0xffffffff) //!< +#define BGFX_STENCIL_DEFAULT UINT32_C(0x00000000) //!< + +/// Set stencil ref value. +#define BGFX_STENCIL_FUNC_REF(_ref) ( (uint32_t(_ref)< + +typedef enum bgfx_render_frame +{ + BGFX_RENDER_FRAME_NO_CONTEXT, + BGFX_RENDER_FRAME_RENDER, + BGFX_RENDER_FRAME_EXITING, + + BGFX_RENDER_FRAME_COUNT + +} bgfx_render_frame_t; + +/** + * 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. + */ +BGFX_C_API bgfx_render_frame_t bgfx_render_frame(); + +typedef struct bgfx_platform_data +{ + void* ndt; + void* nwh; + void* context; + void* backBuffer; + void* backBufferDS; + +} bgfx_platform_data_t; + +BGFX_C_API void bgfx_set_platform_data(bgfx_platform_data_t* _pd); + +#endif // BGFX_PLATFORM_C99_H_HEADER_GUARD diff --git a/deps/include/bgfxplatform.h b/deps/include/bgfxplatform.h new file mode 100644 index 0000000..920904a --- /dev/null +++ b/deps/include/bgfxplatform.h @@ -0,0 +1,269 @@ +/* + * Copyright 2011-2015 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#ifndef BGFX_PLATFORM_H_HEADER_GUARD +#define BGFX_PLATFORM_H_HEADER_GUARD + +// NOTICE: +// This header file contains platform specific interfaces. It is only +// necessary to use this header in conjunction with creating windows. + +#include + +namespace bgfx +{ + /// Render frame enum. + /// + /// @attention C99 equivalent is `bgfx_render_frame_t`. + /// + struct RenderFrame + { + enum Enum + { + NoContext, + Render, + Exiting, + + Count + }; + }; + + /// Render frame. + /// + /// @returns Current renderer state. See: `bgfx::RenderFrame`. + /// + /// @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. + RenderFrame::Enum renderFrame(); + + /// Platform data. + /// + /// @attention C99 equivalent is `bgfx_platform_data_t`. + /// + struct PlatformData + { + void* ndt; //!< Native display type + void* nwh; //!< Native window handle + void* context; //!< GL context, or D3D device + void* backBuffer; //!< GL backbuffer, or D3D render target view + void* backBufferDS; //!< Backbuffer depth/stencil. + }; + + /// Set platform data. + /// + /// @warning Must be called before `bgfx::init`. + /// + /// @attention C99 equivalent is `bgfx_set_platform_data`. + /// + void setPlatformData(const PlatformData& _hooks); + +} // namespace bgfx + +#if BX_PLATFORM_ANDROID +# include + +namespace bgfx +{ + /// + inline void androidSetWindow(::ANativeWindow* _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#elif BX_PLATFORM_IOS +namespace bgfx +{ + /// + inline void iosSetEaglLayer(void* _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI + +namespace bgfx +{ + /// + inline void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL) + { + PlatformData pd; + pd.ndt = _display; + pd.nwh = (void*)(uintptr_t)_window; + pd.context = _glx; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#elif BX_PLATFORM_NACL +# include +# include + +namespace bgfx +{ + typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); + + /// + bool naclSetInterfaces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn); + +} // namespace bgfx + +#elif BX_PLATFORM_OSX +namespace bgfx +{ + /// + inline void osxSetNSWindow(void* _window, void* _nsgl = NULL) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = _nsgl; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#elif BX_PLATFORM_WINDOWS +# include + +namespace bgfx +{ + /// + inline void winSetHwnd(::HWND _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#elif BX_PLATFORM_WINRT +# include + +namespace bgfx +{ + /// + inline void winrtSetWindow(::IUnknown* _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#endif // BX_PLATFORM_ + +#if defined(_SDL_syswm_h) +// If SDL_syswm.h is included before bgfxplatform.h we can enable SDL window +// interop convenience code. + +namespace bgfx +{ + /// + inline bool sdlSetWindow(SDL_Window* _window) + { + SDL_SysWMinfo wmi; + SDL_VERSION(&wmi.version); + if (!SDL_GetWindowWMInfo(_window, &wmi) ) + { + return false; + } + + PlatformData pd; +# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD + pd.ndt = wmi.info.x11.display; + pd.nwh = (void*)(uintptr_t)wmi.info.x11.window; +# elif BX_PLATFORM_OSX + pd.ndt = NULL; + pd.nwh = wmi.info.cocoa.window; +# elif BX_PLATFORM_WINDOWS + pd.ndt = NULL; + pd.nwh = wmi.info.win.window; +# endif // BX_PLATFORM_ + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + + return true; + } + +} // namespace bgfx + +#elif defined(_glfw3_h_) +// If GLFW/glfw3.h is included before bgfxplatform.h we can enable GLFW3 +// window interop convenience code. + +# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD +# define GLFW_EXPOSE_NATIVE_X11 +# define GLFW_EXPOSE_NATIVE_GLX +# elif BX_PLATFORM_OSX +# define GLFW_EXPOSE_NATIVE_COCOA +# define GLFW_EXPOSE_NATIVE_NSGL +# elif BX_PLATFORM_WINDOWS +# define GLFW_EXPOSE_NATIVE_WIN32 +# define GLFW_EXPOSE_NATIVE_WGL +# endif // +# include + +namespace bgfx +{ + inline void glfwSetWindow(GLFWwindow* _window) + { + PlatformData pd; +# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD + pd.ndt = glfwGetX11Display(); + pd.nwh = (void*)(uintptr_t)glfwGetX11Window(_window); + pd.context = glfwGetGLXContext(_window); +# elif BX_PLATFORM_OSX + pd.ndt = NULL; + pd.nwh = glfwGetCocoaWindow(_window); + pd.context = glfwGetNSGLContext(_window); +# elif BX_PLATFORM_WINDOWS + pd.ndt = NULL; + pd.nwh = glfwGetWin32Window(_window); + pd.context = NULL; +# endif // BX_PLATFORM_WINDOWS + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } + +} // namespace bgfx + +#endif // defined(_SDL_H) + +#endif // BGFX_PLATFORM_H_HEADER_GUARD diff --git a/deps/lib/linux-gcc/x64/libbgfx.a b/deps/lib/linux-gcc/x64/libbgfx.a new file mode 100644 index 0000000..b518b49 Binary files /dev/null and b/deps/lib/linux-gcc/x64/libbgfx.a differ diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index 046a306..c8c1d17 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -7,6 +7,7 @@ find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono) find_package(assimp REQUIRED) find_package(ZLIB REQUIRED) find_package(PNG REQUIRED) +find_package(BGFX REQUIRED) # GLM set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include) @@ -18,6 +19,7 @@ include_directories( ${Boost_INCLUDE_DIRS} ${assimp_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} + ${BGFX_INCLUDE_DIRS} ) file(GLOB SOURCE_FILES_Core @@ -68,6 +70,7 @@ target_link_libraries(game ${Boost_LIBRARIES} ${assimp_LIBRARIES} ${PNG_LIBRARIES} + ${BGFX_LIBRARIES} ) add_executable(breakout @@ -81,5 +84,6 @@ target_link_libraries(breakout ${Boost_LIBRARIES} ${assimp_LIBRARIES} ${PNG_LIBRARIES} + ${BGFX_LIBRARIES} )