API Reference¶
Note
If you’re just getting started with bgfx, you might get more out of these simple walkthroughs for how to use bgfx’s API:
General¶
Initialization and Shutdown¶
-
struct
bgfx
::
Init
¶ Initialization parameters used by
bgfx::init
.- Attention
C99’s equivalent binding is
bgfx_init_t
.
Public Members
-
RendererType::Enum
type
¶ Select rendering backend. When set to RendererType::Count a default rendering backend will be selected appropriate to the platform. See:
bgfx::RendererType
-
uint16_t
vendorId
¶ Vendor PCI id. If set to
BGFX_PCI_ID_NONE
it will select the first device.BGFX_PCI_ID_NONE
- Autoselect adapter.BGFX_PCI_ID_SOFTWARE_RASTERIZER
- Software rasterizer.BGFX_PCI_ID_AMD
- AMD adapter.BGFX_PCI_ID_INTEL
- Intel adapter.BGFX_PCI_ID_NVIDIA
- nVidia adapter.
-
uint16_t
deviceId
¶ Device id. If set to 0 it will select first device, or device with matching id.
-
uint64_t
capabilities
¶ Capabilities initialization mask (default: UINT64_MAX).
-
bool
debug
¶ Enable device for debugging.
-
bool
profile
¶ Enable device for profiling.
-
PlatformData
platformData
¶ Platform data.
-
Resolution
resolution
¶ Backbuffer resolution and reset parameters. See:
bgfx::Resolution
.
-
CallbackI *
callback
¶ Provide application specific callback interface. See:
bgfx::CallbackI
-
bx::AllocatorI *
allocator
¶ Custom allocator. When a custom allocator is not specified, bgfx uses the CRT allocator. Bgfx assumes custom allocator is thread safe.
-
struct
Limits
¶ Configurable runtime limits parameters.
- Attention
C99’s equivalent binding is
bgfx_init_limits_t
.
-
struct
bgfx
::
Resolution
¶ Backbuffer resolution and reset parameters.
- Attention
C99’s equivalent binding is
bgfx_resolution_t
.
-
bool
bgfx
::
init
(const Init &_init = {})¶ Initialize the bgfx library.
- Return
true
if initialization was successful.- Attention
C99’s equivalent binding is
bgfx_init
.- Parameters
[in] _init
: Initialization parameters. See:bgfx::Init
for more info.
-
BGFX_PCI_ID_NONE
¶ Autoselect adapter.
-
BGFX_PCI_ID_SOFTWARE_RASTERIZER
¶ Software rasterizer.
-
BGFX_PCI_ID_AMD
¶ AMD adapter.
-
BGFX_PCI_ID_INTEL
¶ Intel adapter.
-
BGFX_PCI_ID_NVIDIA
¶ nVidia adapter.
-
struct
bgfx
::
CallbackI
¶ Callback interface to implement application specific behavior. Cached items are currently used for OpenGL and Direct3D 12 binary shaders.
- Remark
’fatal’ and ‘trace’ callbacks can be called from any thread. Other callbacks are called from the render thread.
- Attention
C99’s equivalent binding is
bgfx_callback_interface_t
.
Public Functions
-
void
fatal
(const char *_filePath, uint16_t _line, Fatal::Enum _code, const char *_str) = 0¶ This callback is called on unrecoverable errors. It’s not safe to continue (Excluding _code
Fatal::DebugCheck
), inform the user and terminate the application.- Remark
Not thread safe and it can be called from any thread.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.fatal
.- Parameters
[in] _filePath
: File path where fatal message was generated.[in] _line
: Line where fatal message was generated.[in] _code
: Fatal error code.[in] _str
: More information about error.
-
void
traceVargs
(const char *_filePath, uint16_t _line, const char *_format, va_list _argList) = 0¶ Print debug message.
- Remark
Not thread safe and it can be called from any thread.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.trace_vargs
.- Parameters
[in] _filePath
: File path where debug message was generated.[in] _line
: Line where debug message was generated.[in] _format
:printf
style format.[in] _argList
: Variable arguments list initialized withva_start
.
-
void
profilerBegin
(const char *_name, uint32_t _abgr, const char *_filePath, uint16_t _line) = 0¶ Profiler region begin.
- Remark
Not thread safe and it can be called from any thread.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.profiler_begin
.- Parameters
[in] _name
: Region name, contains dynamic string.[in] _abgr
: Color of profiler region.[in] _filePath
: File path whereprofilerBegin
was called.[in] _line
: Line whereprofilerBegin
was called.
-
void
profilerBeginLiteral
(const char *_name, uint32_t _abgr, const char *_filePath, uint16_t _line) = 0¶ Profiler region begin with string literal name.
- Remark
Not thread safe and it can be called from any thread.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.profiler_begin_literal
.- Parameters
[in] _name
: Region name, contains string literal.[in] _abgr
: Color of profiler region.[in] _filePath
: File path whereprofilerBeginLiteral
was called.[in] _line
: Line whereprofilerBeginLiteral
was called.
-
void
profilerEnd
() = 0¶ Profiler region end.
- Remark
Not thread safe and it can be called from any thread.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.profiler_end
.
-
uint32_t
cacheReadSize
(uint64_t _id) = 0¶ Returns the size of a cached item. Returns 0 if no cached item was found.
- Return
Number of bytes to read.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.cache_read_size
.- Parameters
[in] _id
: Cache id.
-
bool
cacheRead
(uint64_t _id, void *_data, uint32_t _size) = 0¶ Read cached item.
- Return
True if data is read.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.cache_read
.- Parameters
[in] _id
: Cache id.[in] _data
: Buffer where to read data.[in] _size
: Size of data to read.
-
void
cacheWrite
(uint64_t _id, const void *_data, uint32_t _size) = 0¶ Write cached item.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.cache_write
.- Parameters
[in] _id
: Cache id.[in] _data
: Data to write.[in] _size
: Size of data to write.
-
void
screenShot
(const char *_filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void *_data, uint32_t _size, bool _yflip) = 0¶ Screenshot captured. Screenshot format is always 4-byte BGRA.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.screen_shot
.- Parameters
[in] _filePath
: File path.[in] _width
: Image width.[in] _height
: Image height.[in] _pitch
: Number of bytes to skip between the start of each horizontal line of the image.[in] _data
: Image data.[in] _size
: Image size.[in] _yflip
: If true, image origin is bottom left.
-
void
captureBegin
(uint32_t _width, uint32_t _height, uint32_t _pitch, TextureFormat::Enum _format, bool _yflip) = 0¶ Called when a video capture begins.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.capture_begin
.- Parameters
[in] _width
: Image width.[in] _height
: Image height.[in] _pitch
: Number of bytes to skip between the start of each horizontal line of the image.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _yflip
: If true, image origin is bottom left.
-
void
captureEnd
() = 0¶ Called when a video capture ends.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.capture_end
.
-
void
captureFrame
(const void *_data, uint32_t _size) = 0¶ Captured frame.
- Attention
C99’s equivalent binding is
bgfx_callback_vtbl.capture_frame
.- Parameters
[in] _data
: Image data.[in] _size
: Image size.
-
void
bgfx
::
shutdown
()¶ Shutdown bgfx library.
- Attention
C99’s equivalent binding is
bgfx_shutdown
.
Updating¶
Reset¶
-
void
bgfx
::
reset
(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE, TextureFormat::Enum _format = TextureFormat::Count)¶ Reset graphic settings and back-buffer size.
- Attention
This call doesn’t change the window size, it just resizes the back-buffer. Your windowing code controls the window size.
- Attention
C99’s equivalent binding is
bgfx_reset
.- Parameters
[in] _width
: Back-buffer width.[in] _height
: Back-buffer height.[in] _flags
: See:BGFX_RESET_*
for more info.BGFX_RESET_NONE
- No reset flags.BGFX_RESET_FULLSCREEN
- Not supported yet.BGFX_RESET_MSAA_X[2/4/8/16]
- Enable 2, 4, 8 or 16 x MSAA.BGFX_RESET_VSYNC
- Enable V-Sync.BGFX_RESET_MAXANISOTROPY
- Turn on/off max anisotropy.BGFX_RESET_CAPTURE
- Begin screen capture.BGFX_RESET_FLUSH_AFTER_RENDER
- Flush rendering after submitting to GPU.BGFX_RESET_FLIP_AFTER_RENDER
- This flag specifies where flip occurs. Default behavior is that flip occurs before rendering new frame. This flag only has effect whenBGFX_CONFIG_MULTITHREADED=0
.BGFX_RESET_SRGB_BACKBUFFER
- Enable sRGB back-buffer.
[in] _format
: Texture format. See:TextureFormat::Enum
.
-
BGFX_RESET_NONE
¶ No reset flags.
-
BGFX_RESET_FULLSCREEN
¶ Not supported yet.
-
BGFX_RESET_MSAA_X2
¶ Enable 2x MSAA.
-
BGFX_RESET_MSAA_X4
¶ Enable 4x MSAA.
-
BGFX_RESET_MSAA_X8
¶ Enable 8x MSAA.
-
BGFX_RESET_MSAA_X16
¶ Enable 16x MSAA.
-
BGFX_RESET_VSYNC
¶ Enable V-Sync.
-
BGFX_RESET_MAXANISOTROPY
¶ Turn on/off max anisotropy.
-
BGFX_RESET_CAPTURE
¶ Begin screen capture.
-
BGFX_RESET_FLUSH_AFTER_RENDER
¶ Flush rendering after submitting to GPU.
-
BGFX_RESET_FLIP_AFTER_RENDER
¶ This flag specifies where flip occurs. Default behaviour is that flip occurs before rendering new frame. This flag only has effect when
BGFX_CONFIG_MULTITHREADED=0
.
-
BGFX_RESET_SRGB_BACKBUFFER
¶ Enable sRGB backbuffer.
-
BGFX_RESET_HDR10
¶ Enable HDR10 rendering.
-
BGFX_RESET_HIDPI
¶ Enable HiDPI rendering.
-
BGFX_RESET_DEPTH_CLAMP
¶ Enable depth clamp.
Frame¶
-
uint32_t
bgfx
::
frame
(bool _capture = false)¶ 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.
- Return
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’s equivalent binding is
bgfx_frame
.- Parameters
[in] _capture
: Capture frame with graphics debugger.
Debug¶
Debug Features¶
-
void
bgfx
::
setDebug
(uint32_t _debug)¶ Set debug flags.
- Attention
C99’s equivalent binding is
bgfx_set_debug
.- Parameters
[in] _debug
: Available flags:BGFX_DEBUG_IFH
- Infinitely fast hardware. When this flag is set all rendering calls will be skipped. This is useful when profiling to quickly assess potential bottlenecks between CPU and GPU.BGFX_DEBUG_PROFILER
- Enable profiler.BGFX_DEBUG_STATS
- Display internal statistics.BGFX_DEBUG_TEXT
- Display debug text.BGFX_DEBUG_WIREFRAME
- Wireframe rendering. All rendering primitives will be rendered as lines.
Debug Flags¶
-
BGFX_DEBUG_NONE
¶ No debug.
-
BGFX_DEBUG_WIREFRAME
¶ Enable wireframe for all primitives.
-
BGFX_DEBUG_IFH
¶ Enable infinitely fast hardware test. No draw calls will be submitted to driver. It’s useful when profiling to quickly assess bottleneck between CPU and GPU.
-
BGFX_DEBUG_STATS
¶ Enable statistics display.
-
BGFX_DEBUG_TEXT
¶ Enable debug text display.
-
BGFX_DEBUG_PROFILER
¶ Enable profiler. This causes per-view statistics to be collected, available through
bgfx::Stats::ViewStats
. This is unrelated to the profiler functions inbgfx::CallbackI
.
Debug Text Display¶
-
void
bgfx
::
dbgTextClear
(uint8_t _attr = 0, bool _small = false)¶ Clear internal debug text buffer.
- Attention
C99’s equivalent binding is
bgfx_dbg_text_clear
.- Parameters
[in] _attr
: Background color.[in] _small
: Default 8x16 or 8x8 font.
-
void
bgfx
::
dbgTextPrintf
(uint16_t _x, uint16_t _y, uint8_t _attr, const char *_format, ...)¶ Print into internal debug text character-buffer (VGA-compatible text mode).
- Attention
C99’s equivalent binding is
bgfx_dbg_text_printf
.- Parameters
[in] _x[in] _y
: 2D position from top-left.[in] _attr
: Color palette. Where top 4-bits represent index of background, and bottom 4-bits represent foreground color from standard VGA text palette (ANSI escape codes).[in] _format
:printf
style format.
-
void
bgfx
::
dbgTextPrintfVargs
(uint16_t _x, uint16_t _y, uint8_t _attr, const char *_format, va_list _argList)¶ Print into internal debug text character-buffer (VGA-compatible text mode).
- Attention
C99’s equivalent binding is
bgfx_dbg_text_vprintf
.- Parameters
[in] _x[in] _y
: 2D position from top-left.[in] _attr
: Color palette. Where top 4-bits represent index of background, and bottom 4-bits represent foreground color from standard VGA text palette (ANSI escape codes).[in] _format
:printf
style format.[in] _argList
: additional arguments for format string
-
void
bgfx
::
dbgTextImage
(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void *_data, uint16_t _pitch)¶ Draw image into internal debug text buffer.
- Attention
C99’s equivalent binding is
bgfx_dbg_text_image
.- Parameters
[in] _x[in] _y
: 2D position from top-left.[in] _width[in] _height
: Image width and height.[in] _data
: Raw image data (character/attribute raw encoding).[in] _pitch
: Image pitch in bytes.
Querying information¶
Renderer¶
-
uint8_t
bgfx
::
getSupportedRenderers
(uint8_t _max = 0, RendererType::Enum *_enum = NULL)¶ Returns supported backend API renderers.
- Return
Number of supported renderers.
- Attention
C99’s equivalent binding is
bgfx_get_supported_renderers
.- Parameters
[in] _max
: Maximum number of elements in _enum array.[inout] _enum
: Array where supported renderers will be written.
-
RendererType::Enum
bgfx
::
getRendererType
()¶ Returns current renderer backend API type.
- Remark
Library must be initialized.
- Attention
C99’s equivalent binding is
bgfx_get_renderer_type
.
-
struct
bgfx
::
RendererType
¶ Renderer backend type enum.
- Attention
C99’s equivalent binding is
bgfx_renderer_type_t
.
Public Types
-
enum
Enum
¶ Renderer types:
Values:
-
enumerator
Noop
¶ No rendering.
-
enumerator
Agc
¶ AGC.
-
enumerator
Direct3D9
¶ Direct3D 9.0.
-
enumerator
Direct3D11
¶ Direct3D 11.0.
-
enumerator
Direct3D12
¶ Direct3D 12.0.
-
enumerator
Gnm
¶ GNM.
-
enumerator
Metal
¶ Metal.
-
enumerator
Nvn
¶ NVN.
-
enumerator
OpenGLES
¶ OpenGL ES 2.0+.
-
enumerator
OpenGL
¶ OpenGL 2.1+.
-
enumerator
Vulkan
¶ Vulkan.
-
enumerator
WebGPU
¶ WebGPU.
-
enumerator
Count
¶
-
enumerator
Capabilities¶
-
const Caps *
bgfx
::
getCaps
()¶ Returns renderer capabilities.
- Return
Pointer to static
bgfx::Caps
structure.- Remark
Library must be initialized.
- Attention
C99’s equivalent binding is
bgfx_get_caps
.
-
struct
bgfx
::
Caps
¶ Renderer capabilities.
- Attention
C99’s equivalent binding is
bgfx_caps_t
.
Public Members
-
RendererType::Enum
rendererType
¶ Renderer backend type. See:
bgfx::RendererType
-
uint64_t
supported
¶ Supported functionality.
- Attention
See
BGFX_CAPS_*
flags at https://bkaradzic.github.io/bgfx/bgfx.html#available-caps
-
bool
homogeneousDepth
¶ True when NDC depth is in [-1, 1] range, otherwise its [0, 1].
-
bool
originBottomLeft
¶ True when NDC origin is at bottom left.
-
uint8_t
numGPUs
¶ Number of enumerated GPUs.
-
uint16_t
formats
[Count
]¶ Supported texture format capabilities flags:
BGFX_CAPS_FORMAT_TEXTURE_NONE
- Texture format is not supported.BGFX_CAPS_FORMAT_TEXTURE_2D
- Texture format is supported.BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB
- Texture as sRGB format is supported.BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED
- Texture format is emulated.BGFX_CAPS_FORMAT_TEXTURE_3D
- Texture format is supported.BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB
- Texture as sRGB format is supported.BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED
- Texture format is emulated.BGFX_CAPS_FORMAT_TEXTURE_CUBE
- Texture format is supported.BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
- Texture as sRGB format is supported.BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED
- Texture format is emulated.BGFX_CAPS_FORMAT_TEXTURE_VERTEX
- Texture format can be used from vertex shader.BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ
- Texture format can be used as image and read from.BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE
- Texture format can be used as image and written to.BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
- Texture format can be used as frame buffer.BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
- Texture format can be used as MSAA frame buffer.BGFX_CAPS_FORMAT_TEXTURE_MSAA
- Texture can be sampled as MSAA.BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN
- Texture format supports auto-generated mips.
-
struct
Limits
¶ Renderer runtime limits.
- Attention
C99’s equivalent binding is
bgfx_caps_limits_t
.
Public Members
-
uint32_t
maxDrawCalls
¶ Maximum number of draw calls.
-
uint32_t
maxBlits
¶ Maximum number of blit calls.
-
uint32_t
maxTextureSize
¶ Maximum texture size.
-
uint32_t
maxTextureLayers
¶ Maximum texture layers.
-
uint32_t
maxViews
¶ Maximum number of views.
-
uint32_t
maxFrameBuffers
¶ Maximum number of frame buffer handles.
-
uint32_t
maxFBAttachments
¶ Maximum number of frame buffer attachments.
-
uint32_t
maxPrograms
¶ Maximum number of program handles.
-
uint32_t
maxShaders
¶ Maximum number of shader handles.
-
uint32_t
maxTextures
¶ Maximum number of texture handles.
-
uint32_t
maxTextureSamplers
¶ Maximum number of texture samplers.
-
uint32_t
maxComputeBindings
¶ Maximum number of compute bindings.
-
uint32_t
maxVertexLayouts
¶ Maximum number of vertex format layouts.
-
uint32_t
maxVertexStreams
¶ Maximum number of vertex streams.
-
uint32_t
maxIndexBuffers
¶ Maximum number of index buffer handles.
-
uint32_t
maxVertexBuffers
¶ Maximum number of vertex buffer handles.
-
uint32_t
maxDynamicIndexBuffers
¶ Maximum number of dynamic index buffer handles.
-
uint32_t
maxDynamicVertexBuffers
¶ Maximum number of dynamic vertex buffer handles.
-
uint32_t
maxUniforms
¶ Maximum number of uniform handles.
-
uint32_t
maxOcclusionQueries
¶ Maximum number of occlusion query handles.
-
uint32_t
maxEncoders
¶ Maximum number of encoder threads.
-
uint32_t
minResourceCbSize
¶ Minimum resource command buffer size.
-
uint32_t
transientVbSize
¶ Maximum transient vertex buffer size.
-
uint32_t
transientIbSize
¶ Maximum transient index buffer size.
Available Caps¶
-
BGFX_CAPS_ALPHA_TO_COVERAGE
¶ Alpha to coverage is supported.
-
BGFX_CAPS_BLEND_INDEPENDENT
¶ Blend independent is supported.
-
BGFX_CAPS_COMPUTE
¶ Compute shaders are supported.
-
BGFX_CAPS_CONSERVATIVE_RASTER
¶ Conservative rasterization is supported.
-
BGFX_CAPS_DRAW_INDIRECT
¶ Draw indirect is supported.
-
BGFX_CAPS_FRAGMENT_DEPTH
¶ Fragment depth is available in fragment shader.
-
BGFX_CAPS_FRAGMENT_ORDERING
¶ Fragment ordering is available in fragment shader.
-
BGFX_CAPS_GRAPHICS_DEBUGGER
¶ Graphics debugger is present.
-
BGFX_CAPS_HDR10
¶ HDR10 rendering is supported.
-
BGFX_CAPS_HIDPI
¶ HiDPI rendering is supported.
-
BGFX_CAPS_IMAGE_RW
¶ Image Read/Write is supported.
-
BGFX_CAPS_INDEX32
¶ 32-bit indices are supported.
-
BGFX_CAPS_INSTANCING
¶ Instancing is supported.
-
BGFX_CAPS_OCCLUSION_QUERY
¶ Occlusion query is supported.
-
BGFX_CAPS_RENDERER_MULTITHREADED
¶ Renderer is on separate thread.
-
BGFX_CAPS_SWAP_CHAIN
¶ Multiple windows are supported.
-
BGFX_CAPS_TEXTURE_2D_ARRAY
¶ 2D texture array is supported.
-
BGFX_CAPS_TEXTURE_3D
¶ 3D textures are supported.
-
BGFX_CAPS_TEXTURE_BLIT
¶ Texture blit is supported.
-
BGFX_CAPS_TEXTURE_COMPARE_ALL
¶
-
BGFX_CAPS_TEXTURE_COMPARE_LEQUAL
¶ Texture compare less equal mode is supported.
-
BGFX_CAPS_TEXTURE_CUBE_ARRAY
¶ Cubemap texture array is supported.
-
BGFX_CAPS_TEXTURE_DIRECT_ACCESS
¶ CPU direct access to GPU texture memory.
-
BGFX_CAPS_TEXTURE_READ_BACK
¶ Read-back texture is supported.
-
BGFX_CAPS_VERTEX_ATTRIB_HALF
¶ Vertex attribute half-float is supported.
-
BGFX_CAPS_VERTEX_ATTRIB_UINT10
¶ Vertex attribute 10_10_10_2 is supported.
-
BGFX_CAPS_VERTEX_ID
¶ Rendering with VertexID only is supported.
Statistics¶
-
const Stats *
bgfx
::
getStats
()¶ Returns performance counters.
- Attention
Pointer returned is valid until
bgfx::frame
is called.- Attention
C99’s equivalent binding is
bgfx_get_stats
.
-
struct
bgfx
::
Stats
¶ Renderer statistics data.
- Attention
C99’s equivalent binding is
bgfx_stats_t
.- Remark
All time values are high-resolution timestamps, while time frequencies define timestamps-per-second for that hardware.
Public Members
-
int64_t
cpuTimeFrame
¶ CPU time between two
bgfx::frame
calls.
-
int64_t
cpuTimeBegin
¶ Render thread CPU submit begin time.
-
int64_t
cpuTimeEnd
¶ Render thread CPU submit end time.
-
int64_t
cpuTimerFreq
¶ CPU timer frequency. Timestamps-per-second.
-
int64_t
gpuTimeBegin
¶ GPU frame begin time.
-
int64_t
gpuTimeEnd
¶ GPU frame end time.
-
int64_t
gpuTimerFreq
¶ GPU timer frequency.
-
int64_t
waitRender
¶ Time spent waiting for render backend thread to finish issuing draw commands to underlying graphics API.
-
int64_t
waitSubmit
¶ Time spent waiting for submit thread to advance to next frame.
-
uint32_t
numDraw
¶ Number of draw calls submitted.
-
uint32_t
numCompute
¶ Number of compute calls submitted.
-
uint32_t
numBlit
¶ Number of blit calls submitted.
-
uint32_t
maxGpuLatency
¶ GPU driver latency.
-
uint16_t
numDynamicIndexBuffers
¶ Number of used dynamic index buffers.
-
uint16_t
numDynamicVertexBuffers
¶ Number of used dynamic vertex buffers.
-
uint16_t
numFrameBuffers
¶ Number of used frame buffers.
-
uint16_t
numIndexBuffers
¶ Number of used index buffers.
-
uint16_t
numOcclusionQueries
¶ Number of used occlusion queries.
-
uint16_t
numPrograms
¶ Number of used programs.
-
uint16_t
numShaders
¶ Number of used shaders.
-
uint16_t
numTextures
¶ Number of used textures.
-
uint16_t
numUniforms
¶ Number of used uniforms.
-
uint16_t
numVertexBuffers
¶ Number of used vertex buffers.
-
uint16_t
numVertexLayouts
¶ Number of used vertex layouts.
-
int64_t
textureMemoryUsed
¶ Estimate of texture memory used.
-
int64_t
rtMemoryUsed
¶ Estimate of render target memory used.
-
int32_t
transientVbUsed
¶ Amount of transient vertex buffer used.
-
int32_t
transientIbUsed
¶ Amount of transient index buffer used.
-
uint32_t
numPrims
[Count
]¶ Number of primitives rendered.
-
int64_t
gpuMemoryMax
¶ Maximum available GPU memory for application.
-
int64_t
gpuMemoryUsed
¶ Amount of GPU memory used by the application.
-
uint16_t
width
¶ Backbuffer width in pixels.
-
uint16_t
height
¶ Backbuffer height in pixels.
-
uint16_t
textWidth
¶ Debug text width in characters.
-
uint16_t
textHeight
¶ Debug text height in characters.
-
uint16_t
numViews
¶ Number of view stats.
-
uint8_t
numEncoders
¶ Number of encoders used during frame.
-
EncoderStats *
encoderStats
¶ Array of encoder stats.
-
struct
bgfx
::
ViewStats
¶ View stats.
- Attention
C99’s equivalent binding is
bgfx_view_stats_t
.
Platform specific¶
These are platform specific APIs. It is only necessary to use these APIs in conjunction with creating windows.
-
RenderFrame::Enum
bgfx
::
renderFrame
(int32_t _msecs = -1)¶ Render frame.
- Return
Current renderer state. See:
bgfx::RenderFrame
.- Attention
bgfx::renderFrame
is blocking call. It waits forbgfx::frame
to be called from API thread to process frame. If timeout value is passed call will timeout and return even ifbgfx::frame
is not called.- Warning
This call should be only used on platforms that don’t allow creating separate rendering thread. If it is called before to bgfx::init, render thread won’t be created by bgfx::init call.
- Attention
C99’s equivalent binding is
bgfx_render_frame
.- Parameters
_msecs
: Timeout in milliseconds.
-
struct
RenderFrame
¶ Render frame enum.
- Attention
C99’s equivalent binding is
bgfx_render_frame_t
.
-
void
bgfx
::
setPlatformData
(const PlatformData &_data)¶ Set platform data.
- Warning
Must be called before
bgfx::init
.- Attention
C99’s equivalent binding is
bgfx_set_platform_data
.
-
struct
bgfx
::
PlatformData
¶ Platform data.
- Attention
C99’s equivalent binding is
bgfx_platform_data_t
.
Public Members
-
void *
ndt
¶ Native display type (*nix specific).
-
void *
nwh
¶ Native window handle. If
NULL
, bgfx will create a headless context/device, provided the rendering API supports it.
-
void *
context
¶ GL context, D3D device, or Vulkan device. If
NULL
, bgfx will create context/device.
-
void *
backBuffer
¶ GL back-buffer, or D3D render target view. If
NULL
bgfx will create back-buffer color surface.
-
void *
backBufferDS
¶ Backbuffer depth/stencil. If
NULL
, bgfx will create a back-buffer depth/stencil surface.
-
const InternalData *
bgfx
::
getInternalData
()¶ Get internal data for interop.
- Attention
It’s expected you understand some bgfx internals before you use this call.
- Warning
Must be called only on render thread.
- Attention
C99’s equivalent binding is
bgfx_get_internal_data
.
-
struct
bgfx
::
InternalData
¶ Internal data.
- Attention
C99’s equivalent binding is
bgfx_internal_data_t
.
-
uintptr_t
bgfx
::
overrideInternal
(TextureHandle _handle, uintptr_t _ptr)¶ Override internal texture with externally created texture. Previously created internal texture will released.
- Attention
It’s expected you understand some bgfx internals before you use this call.
- Return
Native API pointer to texture. If result is 0, texture is not created yet from the main thread.
- Warning
Must be called only on render thread.
- Attention
C99’s equivalent binding is
bgfx_override_internal_texture_ptr
.- Parameters
[in] _handle
: Texture handle.[in] _ptr
: Native API pointer to texture.
-
uintptr_t
bgfx
::
overrideInternal
(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE)¶ Override internal texture by creating new texture. Previously created internal texture will released.
- Attention
It’s expected you understand some bgfx internals before you use this call.
- Return
Native API pointer to texture. If result is 0, texture is not created yet from the main thread.
- Warning
Must be called only on render thread.
- Attention
C99’s equivalent binding is
bgfx_override_internal_texture
.- Parameters
[in] _handle
: Texture handle.[in] _width
: Width.[in] _height
: Height.[in] _numMips
: Number of mip-maps.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _flags
: Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
Miscellaneous¶
-
void
bgfx
::
vertexPack
(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexLayout &_layout, void *_data, uint32_t _index = 0)¶ Pack vertex attribute into vertex stream format.
- Attention
C99’s equivalent binding is
bgfx_vertex_pack
.- Parameters
[in] _input
: Value to be packed into vertex stream.[in] _inputNormalized
: True if input value is already normalized.[in] _attr
: Attribute to pack.[in] _layout
: Vertex stream layout.[in] _data
: Destination vertex stream where data will be packed.[in] _index
: Vertex index that will be modified.
-
void
bgfx
::
vertexUnpack
(float _output[4], Attrib::Enum _attr, const VertexLayout &_layout, const void *_data, uint32_t _index = 0)¶ Unpack vertex attribute from vertex stream format.
- Attention
C99’s equivalent binding is
bgfx_vertex_unpack
.- Parameters
[out] _output
: Result of unpacking.[in] _attr
: Attribute to unpack.[in] _layout
: Vertex stream layout.[in] _data
: Source vertex stream from where data will be unpacked.[in] _index
: Vertex index that will be unpacked.
-
void
bgfx
::
vertexConvert
(const VertexLayout &_destLayout, void *_destData, const VertexLayout &_srcLayout, const void *_srcData, uint32_t _num = 1)¶ Converts vertex stream data from one vertex stream format to another.
- Attention
C99’s equivalent binding is
bgfx_vertex_convert
.- Parameters
[in] _destLayout
: Destination vertex stream layout.[in] _destData
: Destination vertex stream.[in] _srcLayout
: Source vertex stream layout.[in] _srcData
: Source vertex stream data.[in] _num
: Number of vertices to convert from source to destination.
-
uint32_t
bgfx
::
weldVertices
(void *_output, const VertexLayout &_layout, const void *_data, uint32_t _num, bool _index32, float _epsilon = 0.001f)¶ Weld vertices.
- Return
Number of unique vertices after vertex welding.
- Attention
C99’s equivalent binding is
bgfx_weld_vertices
.- Parameters
[in] _output
: Welded vertices remapping table. The size of buffer must be the same as number of vertices.[in] _layout
: Vertex stream layout.[in] _data
: Vertex stream.[in] _num
: Number of vertices in vertex stream.[in] _index32
: Set totrue
if input indices are 32-bit.[in] _epsilon
: Error tolerance for vertex position comparison.
-
struct
bgfx
::
TopologyConvert
¶ Topology conversion function.
- Attention
C99’s equivalent binding is
bgfx_topology_convert_t
.
Public Types
-
enum
Enum
¶ Topology conversion functions:
Values:
-
enumerator
TriListFlipWinding
¶ Flip winding order of triangle list.
-
enumerator
TriStripFlipWinding
¶ Flip winding order of trinagle strip.
-
enumerator
TriListToLineList
¶ Convert triangle list to line list.
-
enumerator
TriStripToTriList
¶ Convert triangle strip to triangle list.
-
enumerator
LineStripToLineList
¶ Convert line strip to line list.
-
enumerator
Count
¶
-
enumerator
-
uint32_t
bgfx
::
topologyConvert
(TopologyConvert::Enum _conversion, void *_dst, uint32_t _dstSize, const void *_indices, uint32_t _numIndices, bool _index32)¶ Convert index buffer for use with different primitive topologies.
- Return
Number of output indices after conversion.
- Attention
C99’s equivalent binding is
bgfx_topology_convert
.- Parameters
[in] _conversion
: Conversion type, seeTopologyConvert::Enum
.[in] _dst
: Destination index buffer. If this argument is NULL function will return number of indices after conversion.[in] _dstSize
: Destination index buffer in bytes. It must be large enough to contain output indices. If destination size is insufficient index buffer will be truncated.[in] _indices
: Source indices.[in] _numIndices
: Number of input indices.[in] _index32
: Set totrue
if input indices are 32-bit.
-
struct
bgfx
::
TopologySort
¶ Topology sort order.
- Attention
C99’s equivalent binding is
bgfx_topology_sort_t
.
Public Types
-
enum
Enum
¶ Topology sort order:
Values:
-
enumerator
DirectionFrontToBackMin
¶
-
enumerator
DirectionFrontToBackAvg
¶
-
enumerator
DirectionFrontToBackMax
¶
-
enumerator
DirectionBackToFrontMin
¶
-
enumerator
DirectionBackToFrontAvg
¶
-
enumerator
DirectionBackToFrontMax
¶
-
enumerator
DistanceFrontToBackMin
¶
-
enumerator
DistanceFrontToBackAvg
¶
-
enumerator
DistanceFrontToBackMax
¶
-
enumerator
DistanceBackToFrontMin
¶
-
enumerator
DistanceBackToFrontAvg
¶
-
enumerator
DistanceBackToFrontMax
¶
-
enumerator
Count
¶
-
enumerator
-
void
bgfx
::
topologySortTriList
(TopologySort::Enum _sort, void *_dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void *_vertices, uint32_t _stride, const void *_indices, uint32_t _numIndices, bool _index32)¶ Sort indices.
- Attention
C99’s equivalent binding is
bgfx_topology_sort_tri_list
.- Parameters
[in] _sort
: Sort order, seeTopologySort::Enum
.[in] _dst
: Destination index buffer.[in] _dstSize
: Destination index buffer in bytes. It must be large enough to contain output indices. If destination size is insufficient index buffer will be truncated.[in] _dir
: Direction (vector must be normalized).[in] _pos
: Position.[in] _vertices
: Pointer to first vertex represented as float x, y, z. Must contain at least number of vertices referencende by index buffer.[in] _stride
: Vertex stride.[in] _indices
: Source indices.[in] _numIndices
: Number of input indices.[in] _index32
: Set totrue
if input indices are 32-bit.
-
void
bgfx
::
discard
(uint8_t _flags = BGFX_DISCARD_ALL)¶ Discard all previously set state for draw or compute call.
- Attention
C99’s equivalent binding is
bgfx_discard
.- Parameters
[in] _flags
: Draw/compute states to discard.
-
void
bgfx
::
touch
(ViewId _id)¶ Submit an empty primitive for rendering. Uniforms and draw state will be applied but no geometry will be submitted.
These empty draw calls will sort before ordinary draw calls.
- Attention
C99’s equivalent binding is
bgfx_touch
.- Parameters
[in] _id
: View id.
-
void
bgfx
::
setPaletteColor
(uint8_t _index, uint32_t _rgba)¶ Set palette color value.
- Attention
C99’s equivalent binding is
bgfx_set_palette_color
.- Parameters
[in] _index
: Index into palette.[in] _rgba
: Packed 32-bit RGBA value.
-
void
bgfx
::
setPaletteColor
(uint8_t _index, const float _rgba[4])¶ Set palette color value.
- Attention
C99’s equivalent binding is
bgfx_set_palette_color
.- Parameters
[in] _index
: Index into palette.[in] _rgba
: RGBA floating point value.
-
void
bgfx
::
setPaletteColor
(uint8_t _index, float _r, float _g, float _b, float _a)¶ Set palette color value.
- Attention
C99’s equivalent binding is
bgfx_set_palette_color
.- Parameters
[in] _index
: Index into palette.[in] _r[in] _g[in] _b[in] _a
: RGBA floating point values.
-
void
bgfx
::
requestScreenShot
(FrameBufferHandle _handle, const char *_filePath)¶ Request screen shot of window back buffer.
- Remark
bgfx::CallbackI::screenShot
must be implemented.- Attention
Frame buffer handle must be created with OS’ target native window handle.
- Attention
C99’s equivalent binding is
bgfx_request_screen_shot
.- Parameters
[in] _handle
: Frame buffer handle. If handle isBGFX_INVALID_HANDLE
request will be made for main window back buffer.[in] _filePath
: Will be passed tobgfx::CallbackI::screenShot
callback.
Views¶
Views are the primary sorting mechanism in bgfx. They represent buckets of draw and compute calls, or what are often known as ‘passes’.
When compute calls and draw calls occupy the same bucket, the compute calls will be sorted to execute first. Compute calls are always executed in order of submission, while draw calls are sorted by internal state if the View is not in sequential mode. In most cases where the z-buffer is used, this change in order does not affect the desired output. When draw call order needs to be preserved (e.g. when rendering GUIs), Views can be set to use sequential mode with bgfx::setViewMode. Sequential order is less efficient, because it doesn’t allow state change optimization, and should be avoided when possible.
By default, Views are sorted by their View ID, in ascending order. For dynamic renderers where the right order might not be known until the last moment, View IDs can be changed to use arbitrary ordering with bgfx::setViewOrder.
A View’s state is preserved between frames.
-
void
bgfx
::
setViewName
(ViewId _id, const char *_name)¶ Set view name.
In graphics debugger view name will appear as:
"nnnce <view name>" ^ ^^ ^ | |+-- eye (L/R) | +--- compute (C) +------ view id
- Remark
This is debug only feature.
- Parameters
[in] _id
: View id.[in] _name
: View name.
- Attention
C99’s equivalent binding is
bgfx_set_view_name
.
-
void
bgfx
::
setViewRect
(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)¶ Set view rectangle. Draw primitive outside view will be clipped.
- Attention
C99’s equivalent binding is
bgfx_set_view_rect
.- Parameters
[in] _id
: View id.[in] _x
: Position x from the left corner of the window.[in] _y
: Position y from the top corner of the window.[in] _width
: Width of view port region.[in] _height
: Height of view port region.
-
void
bgfx
::
setViewRect
(ViewId _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio)¶ Set view rectangle. Draw primitive outside view will be clipped.
- Attention
C99’s equivalent binding is
bgfx_set_view_rect_ratio
.- Parameters
[in] _id
: View id.[in] _x
: Position x from the left corner of the window.[in] _y
: Position y from the top corner of the window.[in] _ratio
: Width and height will be set in respect to back-buffer size. See:BackbufferRatio::Enum
.
-
void
bgfx
::
setViewScissor
(ViewId _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0)¶ Set view scissor. Draw primitive outside view will be clipped. When _x, _y, _width and _height are set to 0, scissor will be disabled.
- Attention
C99’s equivalent binding is
bgfx_set_view_scissor
.- Parameters
[in] _id
: View id.[in] _x
: Position x from the left corner of the window.[in] _y
: Position y from the top corner of the window.[in] _width
: Width of scissor region.[in] _height
: Height of scissor region.
-
void
bgfx
::
setViewClear
(ViewId _id, uint16_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0)¶ Set view clear flags.
- Attention
C99’s equivalent binding is
bgfx_set_view_clear
.- Parameters
[in] _id
: View id.[in] _flags
: Clear flags. UseBGFX_CLEAR_NONE
to remove any clear operation. See:BGFX_CLEAR_*
.[in] _rgba
: Color clear value.[in] _depth
: Depth clear value.[in] _stencil
: Stencil clear value.
-
void
bgfx
::
setViewClear
(ViewId _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 clear flags with different clear color for each frame buffer texture.
bgfx::setPaletteColor
must be used to set up a clear color palette.- Attention
C99’s equivalent binding is
bgfx_set_view_clear_mrt
.- Parameters
[in] _id
: View id.[in] _flags
: Clear flags. UseBGFX_CLEAR_NONE
to remove any clear operation. See:BGFX_CLEAR_*
.[in] _depth
: Depth clear value.[in] _stencil
: Stencil clear value.[in] _0
: Palette index for frame buffer attachment 0.[in] _1
: Palette index for frame buffer attachment 1.[in] _2
: Palette index for frame buffer attachment 2.[in] _3
: Palette index for frame buffer attachment 3.[in] _4
: Palette index for frame buffer attachment 4.[in] _5
: Palette index for frame buffer attachment 5.[in] _6
: Palette index for frame buffer attachment 6.[in] _7
: Palette index for frame buffer attachment 7.
-
struct
bgfx
::
ViewMode
¶ View mode sets draw call sort order.
- Attention
C99’s equivalent binding is
bgfx_view_mode_t
.
Public Types
-
enum
Enum
¶ View modes:
Values:
-
enumerator
Default
¶ Default sort order.
-
enumerator
Sequential
¶ Sort in the same order in which submit calls were called.
-
enumerator
DepthAscending
¶ Sort draw call depth in ascending order.
-
enumerator
DepthDescending
¶ Sort draw call depth in descending order.
-
enumerator
Count
¶
-
enumerator
-
void
bgfx
::
setViewMode
(ViewId _id, ViewMode::Enum _mode = ViewMode::Default)¶ Set view sorting mode.
- Remark
View mode must be set prior calling
bgfx::submit
for the view.- Attention
C99’s equivalent binding is
bgfx_set_view_mode
.- Parameters
[in] _id
: View id.[in] _mode
: View sort mode. SeeViewMode::Enum
.
-
void
bgfx
::
setViewFrameBuffer
(ViewId _id, FrameBufferHandle _handle)¶ Set view frame buffer.
- Remark
Not persistent after
bgfx::reset
call.- Attention
C99’s equivalent binding is
bgfx_set_view_frame_buffer
.- Parameters
[in] _id
: View id.[in] _handle
: Frame buffer handle. PassingBGFX_INVALID_HANDLE
as frame buffer handle will draw primitives from this view into default back buffer.
-
void
bgfx
::
setViewTransform
(ViewId _id, const void *_view, const void *_proj)¶ Set view’s view matrix and projection matrix, all draw primitives in this view will use these two matrices.
- Attention
C99’s equivalent binding is
bgfx_set_view_transform
.- Parameters
[in] _id
: View id.[in] _view
: View matrix.[in] _proj
: Projection matrix.
-
void
bgfx
::
setViewOrder
(ViewId _id = 0, uint16_t _num = UINT16_MAX, const ViewId *_remap = NULL)¶ Post submit view reordering.
- Attention
C99’s equivalent binding is
bgfx_set_view_order
.- Parameters
[in] _id
: First view id.[in] _num
: Number of views to remap.[in] _remap
: View remap id table. PassingNULL
will reset view ids to default state.
-
void
bgfx
::
resetView
(ViewId _id)¶ Reset all view settings to default.
- Attention
C99’s equivalent binding is
bgfx_reset_view
.- Parameters
[in] _id
: View id.
Encoder¶
Encoder¶
API for multi-threaded submission.
-
Encoder *
bgfx
::
begin
(bool _forThread = false)¶ Begin submitting draw calls from thread.
- Parameters
[in] _forThread
: Explicitly request an encoder for a worker thread.
-
struct
bgfx
::
Encoder
¶ Encoders are used for submitting draw calls from multiple threads. Only one encoder per thread should be used. Use
bgfx::begin()
to obtain an encoder for a thread.- Attention
C99’s equivalent binding is
bgfx_encoder
.
Public Functions
-
void
setMarker
(const char *_marker)¶ Sets a debug marker. This allows you to group graphics calls together for easy browsing in graphics debugging tools.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_marker
.
-
void
setState
(uint64_t _state, uint32_t _rgba = 0)¶ Set render states for draw primitive.
- Remark
To set up more complex states use:
BGFX_STATE_ALPHA_REF(_ref)
,BGFX_STATE_POINT_SIZE(_size)
,BGFX_STATE_BLEND_FUNC(_src, _dst)
,BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA)
,BGFX_STATE_BLEND_EQUATION(_equation)
,BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA)
BGFX_STATE_BLEND_EQUATION_ADD
is set when no other blend equation is specified.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_state
.- Parameters
[in] _state
: State flags. Default state for primitive type is triangles. See:BGFX_STATE_DEFAULT
.BGFX_STATE_DEPTH_TEST_*
- Depth test function.BGFX_STATE_BLEND_*
- See remark 1 about BGFX_STATE_BLEND_FUNC.BGFX_STATE_BLEND_EQUATION_*
- See remark 2.BGFX_STATE_CULL_*
- Backface culling mode.BGFX_STATE_WRITE_*
- Enable R, G, B, A or Z write.BGFX_STATE_MSAA
- Enable hardware multisample antialiasing.BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]
- Primitive type.
[in] _rgba
: Sets blend factor used byBGFX_STATE_BLEND_FACTOR
andBGFX_STATE_BLEND_INV_FACTOR
blend modes.
-
void
setCondition
(OcclusionQueryHandle _handle, bool _visible)¶ Set condition for rendering.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_condition
.- Parameters
[in] _handle
: Occlusion query handle.[in] _visible
: Render if occlusion query is visible.
-
void
setStencil
(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE)¶ Set stencil test state.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_stencil
.- Parameters
[in] _fstencil
: Front stencil state.[in] _bstencil
: Back stencil state. If back is set toBGFX_STENCIL_NONE
_fstencil is applied to both front and back facing primitives.
-
uint16_t
setScissor
(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)¶ Set scissor for draw primitive. To scissor for all primitives in view see
bgfx::setViewScissor
.- Return
Scissor cache index.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_scissor
.- Parameters
[in] _x
: Position x from the left side of the window.[in] _y
: Position y from the top of the window.[in] _width
: Width of scissor region.[in] _height
: Height of scissor region.
-
void
setScissor
(uint16_t _cache = UINT16_MAX)¶ Set scissor from cache for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_scissor_cached
.- Parameters
[in] _cache
: Index in scissor cache. Pass UINT16_MAX to have primitive use view scissor instead.
-
uint32_t
setTransform
(const void *_mtx, uint16_t _num = 1)¶ Set model matrix for draw primitive. If it is not called, model will be rendered with identity model matrix.
- Return
Index into matrix cache in case the same model matrix has to be used for other draw primitive call.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_transform
.- Parameters
[in] _mtx
: Pointer to first matrix in array.[in] _num
: Number of matrices in array.
-
uint32_t
allocTransform
(Transform *_transform, uint16_t _num)¶ Reserve
_num
matrices in internal matrix cache.- Return
Index into matrix cache.
- Attention
Pointer returned can be modified until
bgfx::frame
is called.- Attention
C99’s equivalent binding is
bgfx_encoder_alloc_transform
.- Parameters
[in] _transform
: Pointer toTransform
structure.[in] _num
: Number of matrices.
-
void
setTransform
(uint32_t _cache, uint16_t _num = 1)¶ Set model matrix from matrix cache for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_transform_cached
.- Parameters
[in] _cache
: Index in matrix cache.[in] _num
: Number of matrices from cache.
-
void
setUniform
(UniformHandle _handle, const void *_value, uint16_t _num = 1)¶ Set shader uniform parameter for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_uniform
.- Parameters
[in] _handle
: Uniform.[in] _value
: Pointer to uniform data.[in] _num
: Number of elements. PassingUINT16_MAX
will use the _num passed on uniform creation.
-
void
setIndexBuffer
(IndexBufferHandle _handle)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_index_buffer
.- Parameters
[in] _handle
: Index buffer.
-
void
setIndexBuffer
(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_index_buffer
.- Parameters
[in] _handle
: Index buffer.[in] _firstIndex
: First index to render.[in] _numIndices
: Number of indices to render.
-
void
setIndexBuffer
(DynamicIndexBufferHandle _handle)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_dynamic_index_buffer
.- Parameters
[in] _handle
: Dynamic index buffer.
-
void
setIndexBuffer
(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_dynamic_index_buffer
.- Parameters
[in] _handle
: Dynamic index buffer.[in] _firstIndex
: First index to render.[in] _numIndices
: Number of indices to render.
-
void
setIndexBuffer
(const TransientIndexBuffer *_tib)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_transient_index_buffer
.- Parameters
[in] _tib
: Transient index buffer.
-
void
setIndexBuffer
(const TransientIndexBuffer *_tib, uint32_t _firstIndex, uint32_t _numIndices)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_transient_index_buffer
.- Parameters
[in] _tib
: Transient index buffer.[in] _firstIndex
: First index to render.[in] _numIndices
: Number of indices to render.
-
void
setVertexBuffer
(uint8_t _stream, VertexBufferHandle _handle)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Vertex buffer.
-
void
setVertexBuffer
(uint8_t _stream, VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices, VertexLayoutHandle _layoutHandle = BGFX_INVALID_HANDLE)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Vertex buffer.[in] _startVertex
: First vertex to render.[in] _numVertices
: Number of vertices to render.[in] _layoutHandle
: Vertex layout for aliasing vertex buffer. If invalid handle is used, vertex layout used for creation of vertex buffer will be used.
-
void
setVertexBuffer
(uint8_t _stream, DynamicVertexBufferHandle _handle)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_dynamic_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Dynamic vertex buffer.
-
void
setVertexBuffer
(uint8_t _stream, DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices, VertexLayoutHandle _layoutHandle = BGFX_INVALID_HANDLE)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_dynamic_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Dynamic vertex buffer.[in] _startVertex
: First vertex to render.[in] _numVertices
: Number of vertices to render.[in] _layoutHandle
: Vertex layout for aliasing vertex buffer. If invalid handle is used, vertex layout used for creation of vertex buffer will be used.
-
void
setVertexBuffer
(uint8_t _stream, const TransientVertexBuffer *_tvb)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_transient_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _tvb
: Transient vertex buffer.
-
void
setVertexBuffer
(uint8_t _stream, const TransientVertexBuffer *_tvb, uint32_t _startVertex, uint32_t _numVertices, VertexLayoutHandle _layoutHandle = BGFX_INVALID_HANDLE)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_transient_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _tvb
: Transient vertex buffer.[in] _startVertex
: First vertex to render.[in] _numVertices
: Number of vertices to render.[in] _layoutHandle
: Vertex layout for aliasing vertex buffer. If invalid handle is used, vertex layout used for creation of vertex buffer will be used.
-
void
setVertexCount
(uint32_t _numVertices)¶ Set number of vertices for auto generated vertices use in conjunction with gl_VertexID.
- Attention
Availability depends on:
BGFX_CAPS_VERTEX_ID
.- Attention
C99’s equivalent binding is
bgfx_encoder_set_vertex_count
.- Parameters
[in] _numVertices
: Number of vertices.
-
void
setInstanceDataBuffer
(const InstanceDataBuffer *_idb)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_instance_data_buffer
.- Parameters
[in] _idb
: Transient instance data buffer.
-
void
setInstanceDataBuffer
(const InstanceDataBuffer *_idb, uint32_t _start, uint32_t _num)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_instance_data_buffer
.- Parameters
[in] _idb
: Transient instance data buffer.[in] _start
: First instance data.[in] _num
: Number of data instances.
-
void
setInstanceDataBuffer
(VertexBufferHandle _handle, uint32_t _start, uint32_t _num)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_instance_data_from_vertex_buffer
.- Parameters
[in] _handle
: Vertex buffer.[in] _start
: First instance data.[in] _num
: Number of data instances.
-
void
setInstanceDataBuffer
(DynamicVertexBufferHandle _handle, uint32_t _start, uint32_t _num)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_instance_data_from_dynamic_vertex_buffer
.- Parameters
[in] _handle
: Vertex buffer.[in] _start
: First instance data.[in] _num
: Number of data instances.
-
void
setInstanceCount
(uint32_t _numInstances)¶ Set number of instances for auto generated instances use in conjunction with gl_InstanceID.
- Attention
Availability depends on:
BGFX_CAPS_VERTEX_ID
.- Attention
C99’s equivalent binding is
bgfx_encoder_set_instance_count
.- Parameters
[in] _numInstances
: Number of instances.
-
void
setTexture
(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX)¶ Set texture stage for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_texture
.- Parameters
[in] _stage
: Texture unit.[in] _sampler
: Program sampler.[in] _handle
: Texture handle.[in] _flags
: Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
-
void
touch
(ViewId _id)¶ Submit an empty primitive for rendering. Uniforms and draw state will be applied but no geometry will be submitted. Useful in cases when no other draw/compute primitive is submitted to view, but it’s desired to execute clear view.
These empty draw calls will sort before ordinary draw calls.
- Attention
C99’s equivalent binding is
bgfx_encoder_touch
.- Parameters
[in] _id
: View id.
-
void
submit
(ViewId _id, ProgramHandle _program, uint32_t _depth = 0, uint8_t _flags = BGFX_DISCARD_ALL)¶ Submit primitive for rendering.
- Attention
C99’s equivalent binding is
bgfx_encoder_submit
.- Parameters
[in] _id
: View id.[in] _program
: Program.[in] _depth
: Depth for sorting.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
submit
(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth = 0, uint8_t _flags = BGFX_DISCARD_ALL)¶ Submit primitive with occlusion query for rendering.
- Attention
C99’s equivalent binding is
bgfx_encoder_submit_occlusion_query
.- Parameters
[in] _id
: View id.[in] _program
: Program.[in] _occlusionQuery
: Occlusion query.[in] _depth
: Depth for sorting.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
submit
(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, uint32_t _depth = 0, uint8_t _flags = BGFX_DISCARD_ALL)¶ Submit primitive for rendering with index and instance data info from indirect buffer.
- Attention
C99’s equivalent binding is
bgfx_encoder_submit_indirect
.- Parameters
[in] _id
: View id.[in] _program
: Program.[in] _indirectHandle
: Indirect buffer.[in] _start
: First element in indirect buffer.[in] _num
: Number of dispatches.[in] _depth
: Depth for sorting.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
setBuffer
(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access)¶ Set compute index buffer.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_compute_index_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Index buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
setBuffer
(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access)¶ Set compute vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_compute_vertex_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Vertex buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
setBuffer
(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access)¶ Set compute dynamic index buffer.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_compute_dynamic_index_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Dynamic index buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
setBuffer
(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access)¶ Set compute dynamic vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_compute_dynamic_vertex_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Dynamic vertex buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
setBuffer
(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access)¶ Set compute indirect buffer.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_compute_indirect_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Indirect buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
setImage
(uint8_t _stage, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format = TextureFormat::Count)¶ Set compute image from texture.
- Attention
C99’s equivalent binding is
bgfx_encoder_set_image
.- Parameters
[in] _stage
: Texture unit.[in] _handle
: Texture handle.[in] _mip
: Mip level.[in] _access
: Texture access. SeeAccess::Enum
.[in] _format
: Texture format. See:TextureFormat::Enum
.
-
void
dispatch
(ViewId _id, ProgramHandle _handle, uint32_t _numX = 1, uint32_t _numY = 1, uint32_t _numZ = 1, uint8_t _flags = BGFX_DISCARD_ALL)¶ Dispatch compute.
- Attention
C99’s equivalent binding is
bgfx_encoder_dispatch
.- Parameters
[in] _id
: View id.[in] _handle
: Compute program.[in] _numX
: Number of groups X.[in] _numY
: Number of groups Y.[in] _numZ
: Number of groups Z.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
dispatch
(ViewId _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, uint8_t _flags = BGFX_DISCARD_ALL)¶ Dispatch compute indirect.
- Attention
C99’s equivalent binding is
bgfx_encoder_dispatch_indirect
.- Parameters
[in] _id
: View id.[in] _handle
: Compute program.[in] _indirectHandle
: Indirect buffer.[in] _start
: First element in indirect buffer.[in] _num
: Number of dispatches.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
discard
(uint8_t _flags = BGFX_DISCARD_ALL)¶ Discard all previously set state for draw or compute call.
- Attention
C99’s equivalent binding is
bgfx_encoder_discard
.- Parameters
[in] _flags
: Draw/compute states to discard.
-
void
blit
(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX = 0, uint16_t _srcY = 0, uint16_t _width = UINT16_MAX, uint16_t _height = UINT16_MAX)¶ Blit texture 2D region between two 2D textures.
- Attention
Destination texture must be created with
BGFX_TEXTURE_BLIT_DST
flag.- Attention
Availability depends on:
BGFX_CAPS_TEXTURE_BLIT
.- Attention
C99’s equivalent binding is
bgfx_encoder_blit
.- Parameters
[in] _id
: View id.[in] _dst
: Destination texture handle.[in] _dstX
: Destination texture X position.[in] _dstY
: Destination texture Y position.[in] _src
: Source texture handle.[in] _srcX
: Source texture X position.[in] _srcY
: Source texture Y position.[in] _width
: Width of region.[in] _height
: Height of region.
-
void
blit
(ViewId _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip = 0, uint16_t _srcX = 0, uint16_t _srcY = 0, uint16_t _srcZ = 0, uint16_t _width = UINT16_MAX, uint16_t _height = UINT16_MAX, uint16_t _depth = UINT16_MAX)¶ Blit texture region between two textures.
- Attention
Destination texture must be created with
BGFX_TEXTURE_BLIT_DST
flag.- Attention
Availability depends on:
BGFX_CAPS_TEXTURE_BLIT
.- Attention
C99’s equivalent binding is
bgfx_encoder_blit
.- Parameters
[in] _id
: View id.[in] _dst
: Destination texture handle.[in] _dstMip
: Destination texture mip level.[in] _dstX
: Destination texture X position.[in] _dstY
: Destination texture Y position.[in] _dstZ
: If texture is 2D this argument should be 0. If destination texture is cube this argument represents destination texture cube face. For 3D texture this argument represents destination texture Z position.[in] _src
: Source texture handle.[in] _srcMip
: Source texture mip level.[in] _srcX
: Source texture X position.[in] _srcY
: Source texture Y position.[in] _srcZ
: If texture is 2D this argument should be 0. If source texture is cube this argument represents source texture cube face. For 3D texture this argument represents source texture Z position.[in] _width
: Width of region.[in] _height
: Height of region.[in] _depth
: If texture is 3D this argument represents depth of region, otherwise it’s unused.
Draw¶
Draw state is not preserved between two draw calls. All state is cleared after calling bgfx::submit.
State¶
Debug¶
-
void
bgfx
::
setMarker
(const char *_marker)¶ Sets debug marker.
- Attention
C99’s equivalent binding is
bgfx_set_marker
.
-
void
bgfx
::
setName
(ShaderHandle _handle, const char *_name, int32_t _len = INT32_MAX)¶ Set shader debug name.
- Attention
C99’s equivalent binding is
bgfx_set_shader_name
.- Parameters
[in] _handle
: Shader handle.[in] _name
: Shader name.[in] _len
: Shader name length (if length is INT32_MAX, it’s expected that _name is zero terminated string.
-
void
bgfx
::
setName
(TextureHandle _handle, const char *_name, int32_t _len = INT32_MAX)¶ Set texture debug name.
- Attention
C99’s equivalent binding is
bgfx_set_texture_name
.- Parameters
[in] _handle
: Texture handle.[in] _name
: Texture name.[in] _len
: Texture name length (if length is INT32_MAX, it’s expected that _name is zero terminated string.
State¶
-
void
bgfx
::
setState
(uint64_t _state, uint32_t _rgba = 0)¶ Set render states for draw primitive.
- Remark
To set up more complex states use:
BGFX_STATE_ALPHA_REF(_ref)
,BGFX_STATE_POINT_SIZE(_size)
,BGFX_STATE_BLEND_FUNC(_src, _dst)
,BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA)
BGFX_STATE_BLEND_EQUATION(_equation)
BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA)
BGFX_STATE_BLEND_EQUATION_ADD
is set when no other blend equation is specified.
- Attention
C99’s equivalent binding is
bgfx_set_state
.- Parameters
[in] _state
: State flags. Default state for primitive type is triangles. See:BGFX_STATE_DEFAULT
.BGFX_STATE_DEPTH_TEST_*
- Depth test function.BGFX_STATE_BLEND_*
- See remark 1 about BGFX_STATE_BLEND_FUNC.BGFX_STATE_BLEND_EQUATION_*
- See remark 2.BGFX_STATE_CULL_*
- Backface culling mode.BGFX_STATE_WRITE_*
- Enable R, G, B, A or Z write.BGFX_STATE_MSAA
- Enable MSAA.BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]
- Primitive type.
[in] _rgba
: Sets blend factor used byBGFX_STATE_BLEND_FACTOR
andBGFX_STATE_BLEND_INV_FACTOR
blend modes.
State Flags¶
Write
-
BGFX_STATE_WRITE_R
¶ Enable R write.
Color RGB/alpha/depth write. When it’s not specified write will be disabled.
-
BGFX_STATE_WRITE_G
¶ Enable G write.
-
BGFX_STATE_WRITE_B
¶ Enable B write.
-
BGFX_STATE_WRITE_RGB
¶
-
BGFX_STATE_WRITE_A
¶ Enable alpha write.
-
BGFX_STATE_WRITE_Z
¶ Enable depth write. Enable RGB write.
Depth Test
-
BGFX_STATE_DEPTH_TEST_LESS
¶ Enable depth test, less.
Depth test state. When
BGFX_STATE_DEPTH_
is not specified depth test will be disabled.
-
BGFX_STATE_DEPTH_TEST_LEQUAL
¶ Enable depth test, less or equal.
-
BGFX_STATE_DEPTH_TEST_EQUAL
¶ Enable depth test, equal.
-
BGFX_STATE_DEPTH_TEST_GEQUAL
¶ Enable depth test, greater or equal.
-
BGFX_STATE_DEPTH_TEST_GREATER
¶ Enable depth test, greater.
-
BGFX_STATE_DEPTH_TEST_NOTEQUAL
¶ Enable depth test, not equal.
-
BGFX_STATE_DEPTH_TEST_NEVER
¶ Enable depth test, never.
-
BGFX_STATE_DEPTH_TEST_ALWAYS
¶ Enable depth test, always.
Blend Mode
-
BGFX_STATE_BLEND_ZERO
¶ 0, 0, 0, 0
Use BGFX_STATE_BLEND_FUNC(_src, _dst) or BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA) helper macros.
-
BGFX_STATE_BLEND_ONE
¶ 1, 1, 1, 1
-
BGFX_STATE_BLEND_SRC_COLOR
¶ Rs, Gs, Bs, As.
-
BGFX_STATE_BLEND_INV_SRC_COLOR
¶ 1-Rs, 1-Gs, 1-Bs, 1-As
-
BGFX_STATE_BLEND_SRC_ALPHA
¶ As, As, As, As.
-
BGFX_STATE_BLEND_INV_SRC_ALPHA
¶ 1-As, 1-As, 1-As, 1-As
-
BGFX_STATE_BLEND_DST_ALPHA
¶ Ad, Ad, Ad, Ad.
-
BGFX_STATE_BLEND_INV_DST_ALPHA
¶ 1-Ad, 1-Ad, 1-Ad ,1-Ad
-
BGFX_STATE_BLEND_DST_COLOR
¶ Rd, Gd, Bd, Ad.
-
BGFX_STATE_BLEND_INV_DST_COLOR
¶ 1-Rd, 1-Gd, 1-Bd, 1-Ad
-
BGFX_STATE_BLEND_SRC_ALPHA_SAT
¶ f, f, f, 1; f = min(As, 1-Ad)
-
BGFX_STATE_BLEND_FACTOR
¶ Blend factor.
-
BGFX_STATE_BLEND_INV_FACTOR
¶ 1-Blend factor
Blend Equaation
-
BGFX_STATE_BLEND_EQUATION_ADD
¶ Blend add: src + dst.
Use BGFX_STATE_BLEND_EQUATION(_equation) or BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA) helper macros.
-
BGFX_STATE_BLEND_EQUATION_SUB
¶ Blend subtract: src - dst.
-
BGFX_STATE_BLEND_EQUATION_REVSUB
¶ Blend reverse subtract: dst - src.
-
BGFX_STATE_BLEND_EQUATION_MIN
¶ Blend min: min(src, dst).
-
BGFX_STATE_BLEND_EQUATION_MAX
¶ Blend max: max(src, dst).
Primitive Culling
-
BGFX_STATE_CULL_CW
¶ Cull clockwise triangles.
Cull state. When
BGFX_STATE_CULL_*
is not specified culling will be disabled.
-
BGFX_STATE_CULL_CCW
¶ Cull counter-clockwise triangles.
Primitive Type
-
BGFX_STATE_PT_TRISTRIP
¶ Tristrip.
-
BGFX_STATE_PT_LINES
¶ Lines.
-
BGFX_STATE_PT_LINESTRIP
¶ Line strip.
-
BGFX_STATE_PT_POINTS
¶ Points.
Misc
-
BGFX_STATE_BLEND_INDEPENDENT
¶ Enable blend independent.
-
BGFX_STATE_BLEND_ALPHA_TO_COVERAGE
¶ Enable alpha to coverage. 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).
-
BGFX_STATE_MSAA
¶ Enable MSAA rasterization.
Enable MSAA write when writing into MSAA frame buffer. This flag is ignored when not writing into MSAA frame buffer.
-
BGFX_STATE_LINEAA
¶ Enable line AA rasterization.
Stencil¶
-
void
bgfx
::
setStencil
(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE)¶ Set stencil test state.
- Attention
C99’s equivalent binding is
bgfx_set_stencil
.- Parameters
[in] _fstencil
: Front stencil state.[in] _bstencil
: Back stencil state. If back is set toBGFX_STENCIL_NONE
_fstencil is applied to both front and back facing primitives.
Scissor¶
If the Scissor rectangle needs to be changed for every draw call in a View, use bgfx::setScissor. Otherwise, use bgfx::setViewScissor.
-
uint16_t
bgfx
::
setScissor
(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)¶ Set scissor for draw primitive. For scissor for all primitives in view see
bgfx::setViewScissor
.- Return
Scissor cache index.
- Attention
C99’s equivalent binding is
bgfx_set_scissor
.- Parameters
[in] _x
: Position x from the left corner of the window.[in] _y
: Position y from the top corner of the window.[in] _width
: Width of scissor region.[in] _height
: Height of scissor region.
-
void
bgfx
::
setScissor
(uint16_t _cache = UINT16_MAX)¶ Set scissor from cache for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_scissor_cached
.- Parameters
[in] _cache
: Index in scissor cache. Passing UINT16_MAX unset primitive scissor and primitive will use view scissor instead.
Transform¶
-
uint32_t
bgfx
::
allocTransform
(Transform *_transform, uint16_t _num)¶ Reserve
_num
matrices in internal matrix cache.- Return
index into matrix cache.
- Attention
Pointer returned can be modified until
bgfx::frame
is called.- Attention
C99’s equivalent binding is
bgfx_alloc_transform
.- Parameters
[in] _transform
: Pointer toTransform
structure.[in] _num
: Number of matrices.
-
uint32_t
bgfx
::
setTransform
(const void *_mtx, uint16_t _num = 1)¶ Set model matrix for draw primitive. If it is not called, the model will be rendered with an identity model matrix.
- Return
index into matrix cache in case the same model matrix has to be used for other draw primitive call.
- Attention
C99’s equivalent binding is
bgfx_set_transform
.- Parameters
[in] _mtx
: Pointer to first matrix in array.[in] _num
: Number of matrices in array.
-
void
bgfx
::
setTransform
(uint32_t _cache, uint16_t _num = 1)¶ Set model matrix from matrix cache for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_transform_cached
.- Parameters
[in] _cache
: Index in matrix cache.[in] _num
: Number of matrices from cache.
Conditional Rendering¶
-
void
bgfx
::
setCondition
(OcclusionQueryHandle _handle, bool _visible)¶ Set condition for rendering.
- Attention
C99’s equivalent binding is
bgfx_set_condition
.- Parameters
[in] _handle
: Occlusion query handle.[in] _visible
: Render if occlusion query is visible.
Buffers¶
-
void
bgfx
::
setIndexBuffer
(IndexBufferHandle _handle)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_index_buffer
.- Parameters
[in] _handle
: Index buffer.
-
void
bgfx
::
setIndexBuffer
(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_index_buffer
.- Parameters
[in] _handle
: Index buffer.[in] _firstIndex
: First index to render.[in] _numIndices
: Number of indices to render.
-
void
bgfx
::
setIndexBuffer
(DynamicIndexBufferHandle _handle)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_dynamic_index_buffer
.- Parameters
[in] _handle
: Dynamic index buffer.
-
void
bgfx
::
setIndexBuffer
(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_dynamic_index_buffer
.- Parameters
[in] _handle
: Dynamic index buffer.[in] _firstIndex
: First index to render.[in] _numIndices
: Number of indices to render.
-
struct
bgfx
::
TransientIndexBuffer
¶ Transient index buffer.
- Attention
C99’s equivalent binding is
bgfx_transient_index_buffer_t
.
-
void
bgfx
::
setIndexBuffer
(const TransientIndexBuffer *_tib)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_transient_index_buffer
.- Parameters
[in] _tib
: Transient index buffer.
-
void
bgfx
::
setIndexBuffer
(const TransientIndexBuffer *_tib, uint32_t _firstIndex, uint32_t _numIndices)¶ Set index buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_transient_index_buffer
.- Parameters
[in] _tib
: Transient index buffer.[in] _firstIndex
: First index to render.[in] _numIndices
: Number of indices to render.
-
void
bgfx
::
setVertexBuffer
(uint8_t _stream, VertexBufferHandle _handle)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Vertex buffer.
-
void
bgfx
::
setVertexBuffer
(uint8_t _stream, VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices, VertexLayoutHandle _layoutHandle = BGFX_INVALID_HANDLE)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Vertex buffer.[in] _startVertex
: First vertex to render.[in] _numVertices
: Number of vertices to render.[in] _layoutHandle
: Vertex layout for aliasing vertex buffer. If invalid handle is used, vertex layout used for creation of vertex buffer will be used.
-
void
bgfx
::
setVertexBuffer
(uint8_t _stream, DynamicVertexBufferHandle _handle)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_dynamic_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Dynamic vertex buffer.
-
void
bgfx
::
setVertexBuffer
(uint8_t _stream, DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices, VertexLayoutHandle _layoutHandle = BGFX_INVALID_HANDLE)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_dynamic_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _handle
: Dynamic vertex buffer.[in] _startVertex
: First vertex to render.[in] _numVertices
: Number of vertices to render.[in] _layoutHandle
: Vertex layout for aliasing vertex buffer. If invalid handle is used, vertex layout used for creation of vertex buffer will be used.
-
struct
bgfx
::
TransientVertexBuffer
¶ Transient vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_transient_vertex_buffer_t
.
-
void
bgfx
::
setVertexBuffer
(uint8_t _stream, const TransientVertexBuffer *_tvb)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_transient_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _tvb
: Transient vertex buffer.
-
void
bgfx
::
setVertexBuffer
(uint8_t _stream, const TransientVertexBuffer *_tvb, uint32_t _startVertex, uint32_t _numVertices, VertexLayoutHandle _layoutHandle = BGFX_INVALID_HANDLE)¶ Set vertex buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_transient_vertex_buffer
.- Parameters
[in] _stream
: Vertex stream.[in] _tvb
: Transient vertex buffer.[in] _startVertex
: First vertex to render.[in] _numVertices
: Number of vertices to render.[in] _layoutHandle
: Vertex layout for aliasing vertex buffer. If invalid handle is used, vertex layout used for creation of vertex buffer will be used.
-
void
bgfx
::
setVertexCount
(uint32_t _numVertices)¶ Set number of vertices for auto generated vertices use in conjunction with gl_VertexID.
- Attention
Availability depends on:
BGFX_CAPS_VERTEX_ID
.- Attention
C99’s equivalent binding is
bgfx_set_vertex_count
.- Parameters
[in] _numVertices
: Number of vertices.
-
struct
bgfx
::
InstanceDataBuffer
¶ Instance data buffer info.
- Attention
C99’s equivalent binding is
bgfx_instance_data_buffer_t
.
-
void
bgfx
::
setInstanceDataBuffer
(const InstanceDataBuffer *_idb)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_instance_data_buffer
.- Parameters
[in] _idb
: Transient instance data buffer.
-
void
bgfx
::
setInstanceDataBuffer
(const InstanceDataBuffer *_idb, uint32_t _start, uint32_t _num)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_instance_data_buffer
.- Parameters
[in] _idb
: Transient instance data buffer.[in] _start
: First instance data.[in] _num
: Number of data instances.
-
void
bgfx
::
setInstanceDataBuffer
(VertexBufferHandle _handle, uint32_t _start, uint32_t _num)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_instance_data_from_vertex_buffer
.- Parameters
[in] _handle
: Vertex buffer.[in] _start
: First instance data.[in] _num
: Number of data instances.
-
void
bgfx
::
setInstanceDataBuffer
(DynamicVertexBufferHandle _handle, uint32_t _start, uint32_t _num)¶ Set instance data buffer for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_instance_data_from_dynamic_vertex_buffer
.- Parameters
[in] _handle
: Vertex buffer.[in] _start
: First instance data.[in] _num
: Number of data instances.
-
void
bgfx
::
setInstanceCount
(uint32_t _numInstances)¶ Set number of instances for auto generated instances use in conjunction with gl_InstanceID.
- Attention
Availability depends on:
BGFX_CAPS_VERTEX_ID
.- Attention
C99’s equivalent binding is
bgfx_set_instance_count
.- Parameters
[in] _numInstances
: Number of instances.
Textures¶
-
void
bgfx
::
setTexture
(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX)¶ Set texture stage for draw primitive.
- Attention
C99’s equivalent binding is
bgfx_set_texture
.- Parameters
[in] _stage
: Texture unit.[in] _sampler
: Program sampler.[in] _handle
: Texture handle.[in] _flags
: Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
Submit¶
In Views, all draw commands are executed after blit and compute commands.
-
void
bgfx
::
submit
(ViewId _id, ProgramHandle _program, uint32_t _depth = 0, uint8_t _flags = BGFX_DISCARD_ALL)¶ Submit primitive for rendering.
- Attention
C99’s equivalent binding is
bgfx_submit
.- Parameters
[in] _id
: View id.[in] _program
: Program.[in] _depth
: Depth for sorting.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
bgfx
::
submit
(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth = 0, uint8_t _flags = BGFX_DISCARD_ALL)¶ Submit primitive with occlusion query for rendering.
- Attention
C99’s equivalent binding is
bgfx_submit_occlusion_query
.- Parameters
[in] _id
: View id.[in] _program
: Program.[in] _occlusionQuery
: Occlusion query.[in] _depth
: Depth for sorting.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
bgfx
::
submit
(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, uint32_t _depth = 0, uint8_t _flags = BGFX_DISCARD_ALL)¶ Submit primitive for rendering with index and instance data info from indirect buffer.
- Attention
C99’s equivalent binding is
bgfx_submit_indirect
.- Parameters
[in] _id
: View id.[in] _program
: Program.[in] _indirectHandle
: Indirect buffer.[in] _start
: First element in indirect buffer.[in] _num
: Number of dispatches.[in] _depth
: Depth for sorting.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
Compute¶
Compute state is not preserved between compute dispatches; all state is cleared after calling bgfx::dispatch.
Buffers¶
-
void
bgfx
::
setBuffer
(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access)¶ Set compute index buffer.
- Attention
C99’s equivalent binding is
bgfx_set_compute_index_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Index buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
bgfx
::
setBuffer
(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access)¶ Set compute vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_set_compute_vertex_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Vertex buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
bgfx
::
setBuffer
(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access)¶ Set compute dynamic index buffer.
- Attention
C99’s equivalent binding is
bgfx_set_compute_dynamic_index_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Dynamic index buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
bgfx
::
setBuffer
(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access)¶ Set compute dynamic vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_set_compute_dynamic_vertex_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Dynamic vertex buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
-
void
bgfx
::
setBuffer
(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access)¶ Set compute indirect buffer.
- Attention
C99’s equivalent binding is
bgfx_set_compute_indirect_buffer
.- Parameters
[in] _stage
: Compute stage.[in] _handle
: Indirect buffer handle.[in] _access
: Buffer access. SeeAccess::Enum
.
Images¶
-
void
bgfx
::
setImage
(uint8_t _stage, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format = TextureFormat::Count)¶ Set compute image from texture.
- Attention
C99’s equivalent binding is
bgfx_set_image
.- Parameters
[in] _stage
: Texture unit.[in] _handle
: Texture handle.[in] _mip
: Mip level.[in] _access
: Texture access. SeeAccess::Enum
.[in] _format
: Texture format. See:TextureFormat::Enum
.
Dispatch¶
In Views, all draw commands are executed after blit and compute commands.
-
void
bgfx
::
dispatch
(ViewId _id, ProgramHandle _handle, uint32_t _numX = 1, uint32_t _numY = 1, uint32_t _numZ = 1, uint8_t _flags = BGFX_DISCARD_ALL)¶ Dispatch compute.
- Attention
C99’s equivalent binding is
bgfx_dispatch
.- Parameters
[in] _id
: View id.[in] _handle
: Compute program.[in] _numX
: Number of groups X.[in] _numY
: Number of groups Y.[in] _numZ
: Number of groups Z.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
-
void
bgfx
::
dispatch
(ViewId _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, uint8_t _flags = BGFX_DISCARD_ALL)¶ Dispatch compute indirect.
- Attention
C99’s equivalent binding is
bgfx_dispatch_indirect
.- Parameters
[in] _id
: View id.[in] _handle
: Compute program.[in] _indirectHandle
: Indirect buffer.[in] _start
: First element in indirect buffer.[in] _num
: Number of dispatches.[in] _flags
: Discard or preserve states. SeeBGFX_DISCARD_*
.
Blit¶
In Views, all draw commands are executed after blit and compute commands.
-
void
bgfx
::
blit
(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX = 0, uint16_t _srcY = 0, uint16_t _width = UINT16_MAX, uint16_t _height = UINT16_MAX)¶ Blit 2D texture region between two 2D textures.
- Attention
Destination texture must be created with
BGFX_TEXTURE_BLIT_DST
flag.- Attention
Availability depends on:
BGFX_CAPS_TEXTURE_BLIT
.- Attention
C99’s equivalent binding is
bgfx_blit
.- Parameters
[in] _id
: View id.[in] _dst
: Destination texture handle.[in] _dstX
: Destination texture X position.[in] _dstY
: Destination texture Y position.[in] _src
: Source texture handle.[in] _srcX
: Source texture X position.[in] _srcY
: Source texture Y position.[in] _width
: Width of region.[in] _height
: Height of region.
-
void
bgfx
::
blit
(ViewId _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip = 0, uint16_t _srcX = 0, uint16_t _srcY = 0, uint16_t _srcZ = 0, uint16_t _width = UINT16_MAX, uint16_t _height = UINT16_MAX, uint16_t _depth = UINT16_MAX)¶ Blit texture region between two textures.
- Attention
Destination texture must be created with
BGFX_TEXTURE_BLIT_DST
flag.- Attention
Availability depends on:
BGFX_CAPS_TEXTURE_BLIT
.- Attention
C99’s equivalent binding is
bgfx_blit
.- Parameters
[in] _id
: View id.[in] _dst
: Destination texture handle.[in] _dstMip
: Destination texture mip level.[in] _dstX
: Destination texture X position.[in] _dstY
: Destination texture Y position.[in] _dstZ
: If texture is 2D this argument should be 0. If destination texture is cube this argument represents destination texture cube face. For 3D texture this argument represents destination texture Z position.[in] _src
: Source texture handle.[in] _srcMip
: Source texture mip level.[in] _srcX
: Source texture X position.[in] _srcY
: Source texture Y position.[in] _srcZ
: If texture is 2D this argument should be 0. If source texture is cube this argument represents source texture cube face. For 3D texture this argument represents source texture Z position.[in] _width
: Width of region.[in] _height
: Height of region.[in] _depth
: If texture is 3D this argument represents depth of region, otherwise it’s unused.
Resources¶
-
struct
bgfx
::
Memory
¶ Memory must be obtained by calling
bgfx::alloc
,bgfx::copy
, orbgfx::makeRef
.- Attention
It is illegal to create this structure on stack and pass it to any bgfx API.
- Attention
C99’s equivalent binding is
bgfx_memory_t
.
-
const Memory *
bgfx
::
alloc
(uint32_t _size)¶ Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
- Attention
C99’s equivalent binding is
bgfx_alloc
.- Parameters
[in] _size
: Size to allocate.
-
const Memory *
bgfx
::
copy
(const void *_data, uint32_t _size)¶ Allocate buffer and copy data into it. Data will be freed inside bgfx.
- Attention
C99’s equivalent binding is
bgfx_copy
.- Parameters
[in] _data
: Pointer to data to be copied.[in] _size
: Size of data to be copied.
-
const Memory *
bgfx
::
makeRef
(const void *_data, uint32_t _size, ReleaseFn _releaseFn = NULL, void *_userData = NULL)¶ Make reference to data to pass to bgfx. Unlike
bgfx::alloc
, this call doesn’t allocate memory for data. It just copies the _data pointer. You can passReleaseFn
function pointer to release this memory after it’s consumed, otherwise you must make sure _data is available for at least 2bgfx::frame
calls.ReleaseFn
function must be able to be called from any thread.- Attention
Data passed must be available for at least 2
bgfx::frame
calls.- Attention
C99’s equivalent bindings are
bgfx_make_ref
,bgfx_make_ref_release
.- Parameters
[in] _data
: Pointer to data.[in] _size
: Size of data.[in] _releaseFn
: Callback function to release memory after use.[in] _userData
: User data to be passed to callback function.
Shaders and Programs¶
-
ShaderHandle
bgfx
::
createShader
(const Memory *_mem)¶ Create shader from memory buffer.
- Return
Shader handle.
- Attention
C99’s equivalent binding is
bgfx_create_shader
.
-
uint16_t
bgfx
::
getShaderUniforms
(ShaderHandle _handle, UniformHandle *_uniforms = NULL, uint16_t _max = 0)¶ Returns the number of uniforms and uniform handles used inside a shader.
- Return
Number of uniforms used by shader.
- Remark
Only non-predefined uniforms are returned.
- Attention
C99’s equivalent binding is
bgfx_get_shader_uniforms
.- Parameters
[in] _handle
: Shader handle.[in] _uniforms
: UniformHandle array where data will be stored.[in] _max
: Maximum capacity of array.
-
void
bgfx
::
destroy
(ShaderHandle _handle)¶ Destroy shader. Once a shader program is created with _handle, it is safe to destroy that shader.
- Attention
C99’s equivalent binding is
bgfx_destroy_shader
.- Parameters
[in] _handle
: Shader handle.
-
ProgramHandle
bgfx
::
createProgram
(ShaderHandle _vsh, ShaderHandle _fsh, bool _destroyShaders = false)¶ Create program with vertex and fragment shaders.
- Return
Program handle if vertex shader output and fragment shader input are matching, otherwise returns invalid program handle.
- Attention
C99’s equivalent binding is
bgfx_create_program
.- Parameters
[in] _vsh
: Vertex shader.[in] _fsh
: Fragment shader.[in] _destroyShaders
: If true, shaders will be destroyed when program is destroyed.
-
ProgramHandle
bgfx
::
createProgram
(ShaderHandle _csh, bool _destroyShader = false)¶ Create program with compute shader.
- Return
Program handle.
- Attention
C99’s equivalent binding is
bgfx_create_compute_program
.- Parameters
[in] _csh
: Compute shader.[in] _destroyShader
: If true, shader will be destroyed when program is destroyed.
-
void
bgfx
::
destroy
(ProgramHandle _handle)¶ Destroy program.
- Attention
C99’s equivalent binding is
bgfx_destroy_program
.- Parameters
[in] _handle
: Program handle.
Uniforms¶
-
UniformHandle
bgfx
::
createUniform
(const char *_name, UniformType::Enum _type, uint16_t _num = 1)¶ Create shader uniform parameter.
- Return
Handle to uniform object.
- Remark
Uniform names are unique. It’s valid to call
bgfx::createUniform
multiple times with the same uniform name. The library will always return the same handle, but the handle reference count will be incremented. This means that the same number ofbgfx::destroyUniform
must be called to properly destroy the uniform.Predefined uniforms (declared in
bgfx_shader.sh
):u_viewRect vec4(x, y, width, height)
- view rectangle for current view, in pixels.u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)
- inverse width and heightu_view mat4
- view matrixu_invView mat4
- inverted view matrixu_proj mat4
- projection matrixu_invProj mat4
- inverted projection matrixu_viewProj mat4
- concatenated view projection matrixu_invViewProj mat4
- concatenated inverted view projection matrixu_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’s equivalent binding is
bgfx_create_uniform
.- Parameters
[in] _name
: Uniform name in shader.[in] _type
: Type of uniform (See:bgfx::UniformType
).[in] _num
: Number of elements in array.
-
void
bgfx
::
getUniformInfo
(UniformHandle _handle, UniformInfo &_info)¶ Retrieve uniform info.
- Attention
C99’s equivalent binding is
bgfx_get_uniform_info
.- Parameters
[in] _handle
: Handle to uniform object.[out] _info
: Uniform info.
-
void
bgfx
::
destroy
(UniformHandle _handle)¶ Destroy shader uniform parameter.
- Attention
C99’s equivalent binding is
bgfx_destroy_uniform
.- Parameters
[in] _handle
: Handle to uniform object.
-
struct
bgfx
::
UniformType
¶ Uniform type enum.
- Attention
C99’s equivalent binding is
bgfx_uniform_type_t
.
Vertex Buffers¶
-
VertexLayoutHandle
bgfx
::
createVertexLayout
(const VertexLayout &_layout)¶ Create vertex layout.
- Attention
C99’s equivalent binding is
bgfx_create_vertex_layout
.
-
void
bgfx
::
destroy
(VertexLayoutHandle _handle)¶ Destroy vertex layout.
- Attention
C99’s equivalent binding is
bgfx_destroy_vertex_layout
.
-
VertexBufferHandle
bgfx
::
createVertexBuffer
(const Memory *_mem, const VertexLayout &_layout, uint16_t _flags = BGFX_BUFFER_NONE)¶ Create static vertex buffer.
- Return
Static vertex buffer handle.
- Attention
C99’s equivalent binding is
bgfx_create_vertex_buffer
.- Parameters
[in] _mem
: Vertex buffer data.[in] _layout
: Vertex layout.[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 withBGFX_BUFFER_COMPUTE_WRITE
flag it cannot be updated from CPU.BGFX_BUFFER_COMPUTE_READ_WRITE
- Buffer will be used for read/write by compute shader.BGFX_BUFFER_ALLOW_RESIZE
- Buffer will resize on buffer update if a different amount of data is passed. If this flag is not specified, and more data is passed on update, the buffer will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers.BGFX_BUFFER_INDEX32
- Buffer is using 32-bit indices. This flag has effect only on index buffers.
-
void
bgfx
::
setName
(VertexBufferHandle _handle, const char *_name, int32_t _len = INT32_MAX)¶ Set static vertex buffer debug name.
- Attention
C99’s equivalent binding is
bgfx_set_vertex_buffer_name
.- Parameters
[in] _handle
: Static vertex buffer handle.[in] _name
: Static vertex buffer name.[in] _len
: Static vertex buffer name length (if length is INT32_MAX, it’s expected that _name is zero terminated string.
-
void
bgfx
::
destroy
(VertexBufferHandle _handle)¶ Destroy static vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_destroy_vertex_buffer
.- Parameters
[in] _handle
: Static vertex buffer handle.
-
struct
bgfx
::
VertexLayout
¶ Vertex layout.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_t
.
Public Functions
-
VertexLayout &
begin
(RendererType::Enum _renderer = RendererType::Noop)¶ Start VertexLayout.
- Return
Returns itself.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_begin
.- Parameters
[in] _renderer
: Renderer backend type. See:bgfx::RendererType
-
void
end
()¶ End VertexLayout.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_end
.
-
VertexLayout &
add
(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false)¶ Add attribute to VertexLayout.
- Return
Returns itself.
- Remark
Must be called between begin/end.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_add
.- Parameters
[in] _attrib
: Attribute semantics. See:bgfx::Attrib
[in] _num
: Number of elements 1, 2, 3 or 4.[in] _type
: Element type.[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.[in] _asInt
: Packaging rule for vertexPack, vertexUnpack, and vertexConvert for AttribType::Uint8 and AttribType::Int16. Unpacking code must be implemented inside vertex shader.
-
VertexLayout &
skip
(uint8_t _num)¶ Skip _num bytes in vertex stream.
- Return
Returns itself.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_skip
.
-
void
decode
(Attrib::Enum _attrib, uint8_t &_num, AttribType::Enum &_type, bool &_normalized, bool &_asInt) const¶ Decode attribute.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_decode
.
-
bool
has
(Attrib::Enum _attrib) const¶ Returns
true
if VertexLayout contains attribute.- Return
True if VertexLayout contains attribute.
- Attention
C99’s equivalent binding is
bgfx_vertex_layout_has
.- Parameters
[in] _attrib
: Attribute semantics. See:bgfx::Attrib
-
uint16_t
getOffset
(Attrib::Enum _attrib) const¶ Returns relative attribute offset from the vertex.
- Return
Relative attribute offset from the vertex.
- Parameters
[in] _attrib
: Attribute semantics. See:bgfx::Attrib
-
uint16_t
getStride
() const¶ Returns vertex stride.
- Return
Vertex stride.
-
uint32_t
getSize
(uint32_t _num) const¶ Returns size of vertex buffer for number of vertices.
- Return
Size of vertex buffer for number of vertices.
- Parameters
[in] _num
: Number of vertices.
-
struct
bgfx
::
Attrib
¶ Vertex attribute enum.
- Attention
C99’s equivalent binding is
bgfx_attrib_t
.
Public Types
-
enum
Enum
¶ Corresponds to vertex shader attribute.
Values:
-
enumerator
Position
¶ a_position
-
enumerator
Normal
¶ a_normal
-
enumerator
Tangent
¶ a_tangent
-
enumerator
Bitangent
¶ a_bitangent
-
enumerator
Color0
¶ a_color0
-
enumerator
Color1
¶ a_color1
-
enumerator
Color2
¶ a_color2
-
enumerator
Color3
¶ a_color3
-
enumerator
Indices
¶ a_indices
-
enumerator
Weight
¶ a_weight
-
enumerator
TexCoord0
¶ a_texcoord0
-
enumerator
TexCoord1
¶ a_texcoord1
-
enumerator
TexCoord2
¶ a_texcoord2
-
enumerator
TexCoord3
¶ a_texcoord3
-
enumerator
TexCoord4
¶ a_texcoord4
-
enumerator
TexCoord5
¶ a_texcoord5
-
enumerator
TexCoord6
¶ a_texcoord6
-
enumerator
TexCoord7
¶ a_texcoord7
-
enumerator
Count
¶
-
enumerator
-
struct
bgfx
::
AttribType
¶ Vertex attribute type enum.
- Attention
C99’s equivalent binding is
bgfx_attrib_type_t
.
Public Types
-
DynamicVertexBufferHandle
bgfx
::
createDynamicVertexBuffer
(uint32_t _num, const VertexLayout &_layout, uint16_t _flags = BGFX_BUFFER_NONE)¶ Create empty dynamic vertex buffer.
- Return
Dynamic vertex buffer handle.
- Attention
C99’s equivalent binding is
bgfx_create_dynamic_vertex_buffer
.- Parameters
[in] _num
: Number of vertices.[in] _layout
: Vertex layout.[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 withBGFX_BUFFER_COMPUTE_WRITE
flag it cannot be updated from CPU.BGFX_BUFFER_COMPUTE_READ_WRITE
- Buffer will be used for read/write by compute shader.BGFX_BUFFER_ALLOW_RESIZE
- Buffer will resize on buffer update if a different amount of data is passed. If this flag is not specified, and more data is passed on update, the buffer will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers.BGFX_BUFFER_INDEX32
- Buffer is using 32-bit indices. This flag has effect only on index buffers.
-
DynamicVertexBufferHandle
bgfx
::
createDynamicVertexBuffer
(const Memory *_mem, const VertexLayout &_layout, uint16_t _flags = BGFX_BUFFER_NONE)¶ Create dynamic vertex buffer and initialize it.
- Return
Dynamic vertex buffer handle.
- Attention
C99’s equivalent binding is
bgfx_create_dynamic_vertex_buffer_mem
.- Parameters
[in] _mem
: Vertex buffer data.[in] _layout
: Vertex layout.[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 withBGFX_BUFFER_COMPUTE_WRITE
flag it cannot be updated from CPU.BGFX_BUFFER_COMPUTE_READ_WRITE
- Buffer will be used for read/write by compute shader.BGFX_BUFFER_ALLOW_RESIZE
- Buffer will resize on buffer update if a different amount of data is passed. If this flag is not specified, and more data is passed on update, the buffer will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers.BGFX_BUFFER_INDEX32
- Buffer is using 32-bit indices. This flag has effect only on index buffers.
-
void
bgfx
::
update
(DynamicVertexBufferHandle _handle, uint32_t _startVertex, const Memory *_mem)¶ Update dynamic vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_update_dynamic_vertex_buffer
.- Parameters
[in] _handle
: Dynamic vertex buffer handle.[in] _startVertex
: Start vertex.[in] _mem
: Vertex buffer data.
-
void
bgfx
::
destroy
(DynamicVertexBufferHandle _handle)¶ Destroy dynamic vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_destroy_dynamic_vertex_buffer
.- Parameters
[in] _handle
: Dynamic vertex buffer handle.
-
uint32_t
bgfx
::
getAvailTransientVertexBuffer
(uint32_t _num, const VertexLayout &_layout)¶ Returns number of requested or maximum available vertices.
- Attention
C99’s equivalent binding is
bgfx_get_avail_transient_vertex_buffer
.- Parameters
[in] _num
: Number of required vertices.[in] _layout
: Vertex layout.
-
void
bgfx
::
allocTransientVertexBuffer
(TransientVertexBuffer *_tvb, uint32_t _num, const VertexLayout &_layout)¶ Allocate transient vertex buffer.
- Attention
C99’s equivalent binding is
bgfx_alloc_transient_vertex_buffer
.- Parameters
[out] _tvb
: TransientVertexBuffer structure will be filled, and will be valid for the duration of frame, and can be reused for multiple draw calls.[in] _num
: Number of vertices to allocate.[in] _layout
: Vertex layout.
Index Buffers¶
-
IndexBufferHandle
bgfx
::
createIndexBuffer
(const Memory *_mem, uint16_t _flags = BGFX_BUFFER_NONE)¶ Create static index buffer.
- Attention
C99’s equivalent binding is
bgfx_create_index_buffer
.- Parameters
[in] _mem
: Index buffer data.[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 withBGFX_BUFFER_COMPUTE_WRITE
flag it cannot be updated from CPU.BGFX_BUFFER_COMPUTE_READ_WRITE
- Buffer will be used for read/write by compute shader.BGFX_BUFFER_ALLOW_RESIZE
- Buffer will resize on buffer update if a different amount of data is passed. If this flag is not specified, and more data is passed on update, the buffer will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers.BGFX_BUFFER_INDEX32
- Buffer is using 32-bit indices. This flag has effect only on index buffers.
-
void
bgfx
::
setName
(IndexBufferHandle _handle, const char *_name, int32_t _len = INT32_MAX)¶ Set static index buffer debug name.
- Attention
C99’s equivalent binding is
bgfx_set_index_buffer_name
.- Parameters
[in] _handle
: Static index buffer handle.[in] _name
: Static index buffer name.[in] _len
: Static index buffer name length (if length is INT32_MAX, it’s expected that _name is zero terminated string.
-
void
bgfx
::
destroy
(IndexBufferHandle _handle)¶ Destroy static index buffer.
- Attention
C99’s equivalent binding is
bgfx_destroy_index_buffer
.- Parameters
[in] _handle
: Static index buffer handle.
-
DynamicIndexBufferHandle
bgfx
::
createDynamicIndexBuffer
(uint32_t _num, uint16_t _flags = BGFX_BUFFER_NONE)¶ Create empty dynamic index buffer.
- Return
Dynamic index buffer handle.
- Attention
C99’s equivalent binding is
bgfx_create_dynamic_index_buffer
.- Parameters
[in] _num
: Number of indices.[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 withBGFX_BUFFER_COMPUTE_WRITE
flag it cannot be updated from CPU.BGFX_BUFFER_COMPUTE_READ_WRITE
- Buffer will be used for read/write by compute shader.BGFX_BUFFER_ALLOW_RESIZE
- Buffer will resize on buffer update if a different amount of data is passed. If this flag is not specified, and more data is passed on update, the buffer will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers.BGFX_BUFFER_INDEX32
- Buffer is using 32-bit indices. This flag has effect only on index buffers.
-
DynamicIndexBufferHandle
bgfx
::
createDynamicIndexBuffer
(const Memory *_mem, uint16_t _flags = BGFX_BUFFER_NONE)¶ Create a dynamic index buffer and initialize it.
- Return
Dynamic index buffer handle.
- Attention
C99’s equivalent binding is
bgfx_create_dynamic_index_buffer_mem
.- Parameters
[in] _mem
: Index buffer data.[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 withBGFX_BUFFER_COMPUTE_WRITE
flag it cannot be updated from CPU.BGFX_BUFFER_COMPUTE_READ_WRITE
- Buffer will be used for read/write by compute shader.BGFX_BUFFER_ALLOW_RESIZE
- Buffer will resize on buffer update if a different amount of data is passed. If this flag is not specified, and more data is passed on update, the buffer will be trimmed to fit the existing buffer size. This flag has effect only on dynamic buffers.BGFX_BUFFER_INDEX32
- Buffer is using 32-bit indices. This flag has effect only on index buffers.
-
void
bgfx
::
update
(DynamicIndexBufferHandle _handle, uint32_t _startIndex, const Memory *_mem)¶ Update dynamic index buffer.
- Attention
C99’s equivalent binding is
bgfx_update_dynamic_index_buffer
.- Parameters
[in] _handle
: Dynamic index buffer handle.[in] _startIndex
: Start index.[in] _mem
: Index buffer data.
-
void
bgfx
::
destroy
(DynamicIndexBufferHandle _handle)¶ Destroy dynamic index buffer.
- Attention
C99’s equivalent binding is
bgfx_destroy_dynamic_index_buffer
.- Parameters
[in] _handle
: Dynamic index buffer handle.
-
uint32_t
bgfx
::
getAvailTransientIndexBuffer
(uint32_t _num, bool _index32 = false)¶ Returns number of requested or maximum available indices.
- Attention
C99’s equivalent binding is
bgfx_get_avail_transient_index_buffer
.- Parameters
[in] _num
: Number of required indices.[in] _index32
: Set totrue
if input indices will be 32-bit.
-
void
bgfx
::
allocTransientIndexBuffer
(TransientIndexBuffer *_tib, uint32_t _num, bool _index32 = false)¶ Allocate transient index buffer.
- Attention
C99’s equivalent binding is
bgfx_alloc_transient_index_buffer
.- Parameters
[out] _tib
: TransientIndexBuffer structure will be filled, and will be valid for the duration of frame, and can be reused for multiple draw calls.[in] _num
: Number of indices to allocate.[in] _index32
: Set totrue
if input indices will be 32-bit.
Textures¶
-
struct
bgfx
::
TextureFormat
¶ 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’s equivalent binding is
bgfx_texture_format_t
.
Public Types
-
enum
Enum
¶ Texture formats:
Values:
-
enumerator
BC1
¶ DXT1 R5G6B5A1.
-
enumerator
BC2
¶ DXT3 R5G6B5A4.
-
enumerator
BC3
¶ DXT5 R5G6B5A8.
-
enumerator
BC4
¶ LATC1/ATI1 R8.
-
enumerator
BC5
¶ LATC2/ATI2 RG8.
-
enumerator
BC6H
¶ BC6H RGB16F.
-
enumerator
BC7
¶ BC7 RGB 4-7 bits per color channel, 0-8 bits alpha.
-
enumerator
ETC1
¶ ETC1 RGB8.
-
enumerator
ETC2
¶ ETC2 RGB8.
-
enumerator
ETC2A
¶ ETC2 RGBA8.
-
enumerator
ETC2A1
¶ ETC2 RGB8A1.
-
enumerator
PTC12
¶ PVRTC1 RGB 2BPP.
-
enumerator
PTC14
¶ PVRTC1 RGB 4BPP.
-
enumerator
PTC12A
¶ PVRTC1 RGBA 2BPP.
-
enumerator
PTC14A
¶ PVRTC1 RGBA 4BPP.
-
enumerator
PTC22
¶ PVRTC2 RGBA 2BPP.
-
enumerator
PTC24
¶ PVRTC2 RGBA 4BPP.
-
enumerator
ATC
¶ ATC RGB 4BPP.
-
enumerator
ATCE
¶ ATCE RGBA 8 BPP explicit alpha.
-
enumerator
ATCI
¶ ATCI RGBA 8 BPP interpolated alpha.
-
enumerator
ASTC4x4
¶ ASTC 4x4 8.0 BPP.
-
enumerator
ASTC5x5
¶ ASTC 5x5 5.12 BPP.
-
enumerator
ASTC6x6
¶ ASTC 6x6 3.56 BPP.
-
enumerator
ASTC8x5
¶ ASTC 8x5 3.20 BPP.
-
enumerator
ASTC8x6
¶ ASTC 8x6 2.67 BPP.
-
enumerator
ASTC10x5
¶ ASTC 10x5 2.56 BPP.
-
enumerator
Unknown
¶
-
enumerator
R1
¶
-
enumerator
A8
¶
-
enumerator
R8
¶
-
enumerator
R8I
¶
-
enumerator
R8U
¶
-
enumerator
R8S
¶
-
enumerator
R16
¶
-
enumerator
R16I
¶
-
enumerator
R16U
¶
-
enumerator
R16F
¶
-
enumerator
R16S
¶
-
enumerator
R32I
¶
-
enumerator
R32U
¶
-
enumerator
R32F
¶
-
enumerator
RG8
¶
-
enumerator
RG8I
¶
-
enumerator
RG8U
¶
-
enumerator
RG8S
¶
-
enumerator
RG16
¶
-
enumerator
RG16I
¶
-
enumerator
RG16U
¶
-
enumerator
RG16F
¶
-
enumerator
RG16S
¶
-
enumerator
RG32I
¶
-
enumerator
RG32U
¶
-
enumerator
RG32F
¶
-
enumerator
RGB8
¶
-
enumerator
RGB8I
¶
-
enumerator
RGB8U
¶
-
enumerator
RGB8S
¶
-
enumerator
RGB9E5F
¶
-
enumerator
BGRA8
¶
-
enumerator
RGBA8
¶
-
enumerator
RGBA8I
¶
-
enumerator
RGBA8U
¶
-
enumerator
RGBA8S
¶
-
enumerator
RGBA16
¶
-
enumerator
RGBA16I
¶
-
enumerator
RGBA16U
¶
-
enumerator
RGBA16F
¶
-
enumerator
RGBA16S
¶
-
enumerator
RGBA32I
¶
-
enumerator
RGBA32U
¶
-
enumerator
RGBA32F
¶
-
enumerator
R5G6B5
¶
-
enumerator
RGBA4
¶
-
enumerator
RGB5A1
¶
-
enumerator
RGB10A2
¶
-
enumerator
RG11B10F
¶
-
enumerator
UnknownDepth
¶
-
enumerator
D16
¶
-
enumerator
D24
¶
-
enumerator
D24S8
¶
-
enumerator
D32
¶
-
enumerator
D16F
¶
-
enumerator
D24F
¶
-
enumerator
D32F
¶
-
enumerator
D0S8
¶
-
enumerator
Count
¶
-
enumerator
-
bool
bgfx
::
isTextureValid
(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags)¶ Validate texture parameters.
- Return
True if a texture with the same parameters can be created.
- Attention
C99’s equivalent binding is
bgfx_is_texture_valid
.- Parameters
[in] _depth
: Depth dimension of volume texture.[in] _cubeMap
: Indicates that texture contains cubemap.[in] _numLayers
: Number of layers in texture array.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _flags
: Texture flags. SeeBGFX_TEXTURE_*
.
-
struct
bgfx
::
TextureInfo
¶ Texture info.
- Attention
C99’s equivalent binding is
bgfx_texture_info_t
.
Public Members
-
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.
-
uint16_t
numLayers
¶ Number of layers in texture array.
-
uint8_t
numMips
¶ Number of MIP maps.
-
uint8_t
bitsPerPixel
¶ Format bits per pixel.
-
bool
cubeMap
¶ Texture is cubemap.
-
void
bgfx
::
calcTextureSize
(TextureInfo &_info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format)¶ Calculate amount of memory required for texture.
- Attention
C99’s equivalent binding is
bgfx_calc_texture_size
.- Parameters
[out] _info
: Resulting texture info structure. See:TextureInfo
.[in] _width
: Width.[in] _height
: Height.[in] _depth
: Depth dimension of volume texture.[in] _cubeMap
: Indicates that texture contains cubemap.[in] _hasMips
: Indicates that texture contains full mip-map chain.[in] _numLayers
: Number of layers in texture array.[in] _format
: Texture format. See:TextureFormat::Enum
.
-
TextureHandle
bgfx
::
createTexture
(const Memory *_mem, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, uint8_t _skip = 0, TextureInfo *_info = NULL)¶ Create texture from memory buffer.
- Return
Texture handle.
- Attention
C99’s equivalent binding is
bgfx_create_texture
.- Parameters
[in] _mem
: DDS, KTX or PVR texture data.[in] _flags
: Texture creation (seeBGFX_TEXTURE_*
.), and sampler (seeBGFX_SAMPLER_*
) flags. Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
[in] _skip
: Skip top level mips when parsing texture.[out] _info
: When non-NULL
is specified it returns parsed texture information.
-
TextureHandle
bgfx
::
createTexture2D
(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, const Memory *_mem = NULL)¶ Create 2D texture.
- Attention
C99’s equivalent binding is
bgfx_create_texture_2d
.- Parameters
[in] _width
: Width.[in] _height
: Height.[in] _hasMips
: Indicates that texture contains full mip-map chain.[in] _numLayers
: Number of layers in texture array. Must be 1 if capsBGFX_CAPS_TEXTURE_2D_ARRAY
flag is not set.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _flags
: Texture creation (seeBGFX_TEXTURE_*
.), and sampler (seeBGFX_SAMPLER_*
) flags. Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
[in] _mem
: Texture data. If_mem
is non-NULL, created texture will be immutable. If_mem
is NULL content of the texture is uninitialized. When_numLayers
is more than 1, expected memory layout is texture and all mips together for each array element.
-
TextureHandle
bgfx
::
createTexture2D
(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE)¶ Create texture with size based on back-buffer ratio. Texture will maintain ratio if back buffer resolution changes.
- Attention
C99’s equivalent binding is
bgfx_create_texture_2d_scaled
.- Parameters
[in] _ratio
: Frame buffer size in respect to back-buffer size. See:BackbufferRatio::Enum
.[in] _hasMips
: Indicates that texture contains full mip-map chain.[in] _numLayers
: Number of layers in texture array. Must be 1 if capsBGFX_CAPS_TEXTURE_2D_ARRAY
flag is not set.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _flags
: Texture creation (seeBGFX_TEXTURE_*
.), and sampler (seeBGFX_SAMPLER_*
) flags. Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
-
void
bgfx
::
updateTexture2D
(TextureHandle _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory *_mem, uint16_t _pitch = UINT16_MAX)¶ Update 2D texture.
- Attention
It’s valid to update only mutable texture. See
bgfx::createTexture2D
for more info.- Attention
C99’s equivalent binding is
bgfx_update_texture_2d
.- Parameters
[in] _handle
: Texture handle.[in] _layer
: Layers in texture array.[in] _mip
: Mip level.[in] _x
: X offset in texture.[in] _y
: Y offset in texture.[in] _width
: Width of texture block.[in] _height
: Height of texture block.[in] _mem
: Texture update data.[in] _pitch
: Pitch of input image (bytes). When _pitch is set to UINT16_MAX, it will be calculated internally based on _width.
-
TextureHandle
bgfx
::
createTexture3D
(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, TextureFormat::Enum _format, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, const Memory *_mem = NULL)¶ Create 3D texture.
- Attention
C99’s equivalent binding is
bgfx_create_texture_3d
.- Parameters
[in] _width
: Width.[in] _height
: Height.[in] _depth
: Depth.[in] _hasMips
: Indicates that texture contains full mip-map chain.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _flags
: Texture creation (seeBGFX_TEXTURE_*
.), and sampler (seeBGFX_SAMPLER_*
) flags. Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
[in] _mem
: Texture data. If_mem
is non-NULL, created texture will be immutable. If_mem
is NULL content of the texture is uninitialized.
-
void
bgfx
::
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 3D texture.
- Attention
It’s valid to update only mutable texture. See
bgfx::createTexture3D
for more info.- Attention
C99’s equivalent binding is
bgfx_update_texture_3d
.- Parameters
[in] _handle
: Texture handle.[in] _mip
: Mip level.[in] _x
: X offset in texture.[in] _y
: Y offset in texture.[in] _z
: Z offset in texture.[in] _width
: Width of texture block.[in] _height
: Height of texture block.[in] _depth
: Depth of texture block.[in] _mem
: Texture update data.
-
TextureHandle
bgfx
::
createTextureCube
(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, const Memory *_mem = NULL)¶ Create Cube texture.
- Attention
C99’s equivalent binding is
bgfx_create_texture_cube
.- Parameters
[in] _size
: Cube side size.[in] _hasMips
: Indicates that texture contains full mip-map chain.[in] _numLayers
: Number of layers in texture array. Must be 1 if capsBGFX_CAPS_TEXTURE_CUBE_ARRAY
flag is not set.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _flags
: Texture creation (seeBGFX_TEXTURE_*
.), and sampler (seeBGFX_SAMPLER_*
) flags. Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
[in] _mem
: Texture data. If_mem
is non-NULL, created texture will be immutable. If_mem
is NULL content of the texture is uninitialized. When_numLayers
is more than 1, expected memory layout is texture and all mips together for each array element.
-
void
bgfx
::
updateTextureCube
(TextureHandle _handle, uint16_t _layer, 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)¶ Update Cube texture.
- Attention
It’s valid to update only mutable texture. See
bgfx::createTextureCube
for more info.- Attention
C99’s equivalent binding is
bgfx_update_texture_cube
.- Parameters
[in] _handle
: Texture handle.[in] _layer
: Layers in texture array.[in] _side
: Cubemap sideBGFX_CUBE_MAP_<POSITIVE or NEGATIVE>_<X, Y or Z>
, where 0 is +X, 1 is -X, 2 is +Y, 3 is -Y, 4 is +Z, and 5 is -Z.+----------+ |-z 2| | ^ +y | | | | Unfolded cube: | +---->+x | +----------+----------+----------+----------+ |+y 1|+y 4|+y 0|+y 5| | ^ -x | ^ +z | ^ +x | ^ -z | | | | | | | | | | | +---->+z | +---->+x | +---->-z | +---->-x | +----------+----------+----------+----------+ |+z 3| | ^ -y | | | | | +---->+x | +----------+
[in] _mip
: Mip level.[in] _x
: X offset in texture.[in] _y
: Y offset in texture.[in] _width
: Width of texture block.[in] _height
: Height of texture block.[in] _mem
: Texture update data.[in] _pitch
: Pitch of input image (bytes). When _pitch is set to UINT16_MAX, it will be calculated internally based on _width.
-
uint32_t
bgfx
::
readTexture
(TextureHandle _handle, void *_data, uint8_t _mip = 0)¶ Read back texture content.
- Return
Frame number when the result will be available. See:
bgfx::frame
.- Attention
Texture must be created with
BGFX_TEXTURE_READ_BACK
flag.- Attention
Availability depends on:
BGFX_CAPS_TEXTURE_READ_BACK
.- Attention
C99’s equivalent binding is
bgfx_read_texture
.- Parameters
[in] _handle
: Texture handle.[in] _data
: Destination buffer.[in] _mip
: Mip level.
-
void *
bgfx
::
getDirectAccessPtr
(TextureHandle _handle)¶ Returns texture direct access pointer.
- Return
Pointer to texture memory. If returned pointer is
NULL
direct access is not available for this texture. If pointer isUINTPTR_MAX
sentinel value it means texture is pending creation. Pointer returned can be cached and it will be valid until texture is destroyed.- Attention
Availability depends on:
BGFX_CAPS_TEXTURE_DIRECT_ACCESS
. This feature is available on GPUs that have unified memory architecture (UMA) support.- Attention
C99’s equivalent binding is
bgfx_get_direct_access_ptr
.- Parameters
[in] _handle
: Texture handle.
-
void
bgfx
::
destroy
(TextureHandle _handle)¶ Destroy texture.
- Attention
C99’s equivalent binding is
bgfx_destroy_texture
.- Parameters
[in] _handle
: Texture handle.
Frame Buffers¶
-
struct
bgfx
::
Attachment
¶ Frame buffer texture attachment info.
- Attention
C99’s equivalent binding is
bgfx_attachment_t
.
Public Functions
-
void
init
(TextureHandle _handle, Access::Enum _access = Access::Write, uint16_t _layer = 0, uint16_t _numLayers = 1, uint16_t _mip = 0, uint8_t _resolve = BGFX_RESOLVE_AUTO_GEN_MIPS)¶ Init attachment.
- Parameters
[in] _handle
: Render target texture handle.[in] _access
: Access. SeeAccess::Enum
.[in] _layer
: Cubemap side or depth layer/slice to use.[in] _numLayers
: Number of texture layer/slice(s) in array to use.[in] _mip
: Mip level.[in] _resolve
: Resolve flags. See:BGFX_RESOLVE_*
Public Members
-
Access::Enum
access
¶ Attachment access. See
Access::Enum
.
-
TextureHandle
handle
¶ Render target texture handle.
-
uint16_t
mip
¶ Mip level.
-
uint16_t
layer
¶ Cubemap side or depth layer/slice to use.
-
uint16_t
numLayers
¶ Number of texture layer/slice(s) in array to use.
-
uint8_t
resolve
¶ Resolve flags. See:
BGFX_RESOLVE_*
-
bool
bgfx
::
isFrameBufferValid
(uint8_t _num, const Attachment *_attachment)¶ Validate frame buffer parameters.
- Return
True if a frame buffer with the same parameters can be created.
- Parameters
[in] _num
: Number of attachments.[in] _attachment
: Attachment texture info. See:bgfx::Attachment
.
-
FrameBufferHandle
bgfx
::
createFrameBuffer
(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint64_t _textureFlags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP)¶ Create frame buffer (simple).
- Return
Handle to frame buffer object.
- Attention
C99’s equivalent binding is
bgfx_create_frame_buffer
.- Parameters
[in] _width
: Texture width.[in] _height
: Texture height.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _textureFlags
: Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
-
FrameBufferHandle
bgfx
::
createFrameBuffer
(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint64_t _textureFlags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP)¶ Create frame buffer with size based on back-buffer ratio. Frame buffer will maintain ratio if back buffer resolution changes.
- Return
Handle to frame buffer object.
- Attention
C99’s equivalent binding is
bgfx_create_frame_buffer_scaled
.- Parameters
[in] _ratio
: Frame buffer size in respect to back-buffer size. See:BackbufferRatio::Enum
.[in] _format
: Texture format. See:TextureFormat::Enum
.[in] _textureFlags
: Default texture sampling mode is linear, and wrap mode is repeat.BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]
- Mirror or clamp to edge wrap mode.BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]
- Point or anisotropic sampling.
-
FrameBufferHandle
bgfx
::
createFrameBuffer
(uint8_t _num, const TextureHandle *_handles, bool _destroyTextures = false)¶ Create MRT frame buffer from texture handles (simple).
- Return
Handle to frame buffer object.
- Attention
C99’s equivalent binding is
bgfx_create_frame_buffer_from_handles
.- Parameters
[in] _num
: Number of texture attachments.[in] _handles
: Texture attachments.[in] _destroyTextures
: If true, textures will be destroyed when frame buffer is destroyed.
-
FrameBufferHandle
bgfx
::
createFrameBuffer
(void *_nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _format = TextureFormat::Count, TextureFormat::Enum _depthFormat = TextureFormat::Count)¶ Create frame buffer for multiple window rendering.
- Return
Handle to frame buffer object.
- Remark
Frame buffer cannot be used for sampling.
- Attention
C99’s equivalent binding is
bgfx_create_frame_buffer_from_nwh
.- Parameters
[in] _nwh
: OS’ target native window handle.[in] _width
: Window back buffer width.[in] _height
: Window back buffer height.[in] _format
: Window back buffer color format.[in] _depthFormat
: Window back buffer depth format.
-
FrameBufferHandle
bgfx
::
createFrameBuffer
(uint8_t _num, const Attachment *_attachment, bool _destroyTextures = false)¶ Create MRT frame buffer from texture handles with specific layer and mip level.
- Return
Handle to frame buffer object.
- Attention
C99’s equivalent binding is
bgfx_create_frame_buffer_from_attachment
.- Parameters
[in] _num
: Number of texture attachments.[in] _attachment
: Attachment texture info. See:bgfx::Attachment
.[in] _destroyTextures
: If true, textures will be destroyed when frame buffer is destroyed.
-
TextureHandle
bgfx
::
getTexture
(FrameBufferHandle _handle, uint8_t _attachment = 0)¶ Obtain texture handle of frame buffer attachment.
- Return
Returns invalid texture handle if attachment index is not correct, or frame buffer is created with native window handle.
- Attention
C99’s equivalent binding is
bgfx_get_texture
.- Parameters
[in] _handle
: Frame buffer handle.[in] _attachment
: Frame buffer attachment index.
-
void
bgfx
::
setName
(FrameBufferHandle _handle, const char *_name, int32_t _len = INT32_MAX)¶ Set frame buffer debug name.
- Attention
C99’s equivalent binding is
bgfx_set_frame_buffer_name
.- Parameters
[in] _handle
: frame buffer handle.[in] _name
: frame buffer name.[in] _len
: frame buffer name length (if length is INT32_MAX, it’s expected that _name is zero terminated string.
-
void
bgfx
::
destroy
(FrameBufferHandle _handle)¶ Destroy frame buffer.
- Attention
C99’s equivalent binding is
bgfx_destroy_frame_buffer
.- Parameters
[in] _handle
: Frame buffer handle.
Instance Buffer¶
-
uint32_t
bgfx
::
getAvailInstanceDataBuffer
(uint32_t _num, uint16_t _stride)¶ Returns number of requested or maximum available instance buffer slots.
- Attention
C99’s equivalent binding is
bgfx_get_avail_instance_data_buffer
.- Parameters
[in] _num
: Number of required instances.[in] _stride
: Stride per instance.
-
void
bgfx
::
allocInstanceDataBuffer
(InstanceDataBuffer *_idb, uint32_t _num, uint16_t _stride)¶ Allocate instance data buffer.
- Attention
C99’s equivalent binding is
bgfx_alloc_instance_data_buffer
.- Parameters
[out] _idb
: InstanceDataBuffer structure will be filled, and will be valid for the duration of frame, and can be reused for multiple draw calls.[in] _num
: Number of instances.[in] _stride
: Instance stride. Must be multiple of 16.
Indirect Buffer¶
-
IndirectBufferHandle
bgfx
::
createIndirectBuffer
(uint32_t _num)¶ Create draw indirect buffer.
- Return
Indirect buffer handle.
- Attention
C99’s equivalent binding is
bgfx_create_indirect_buffer
.- Parameters
[in] _num
: Number of indirect calls.
-
void
bgfx
::
destroy
(IndirectBufferHandle _handle)¶ Destroy draw indirect buffer.
- Attention
C99’s equivalent binding is
bgfx_destroy_indirect_buffer
.- Parameters
[in] _handle
: Indirect buffer handle.
Occlusion Query¶
-
OcclusionQueryHandle
bgfx
::
createOcclusionQuery
()¶ Create occlusion query.
- Return
Handle to occlusion query object.
- Attention
C99’s equivalent binding is
bgfx_create_occlusion_query
.
-
struct
bgfx
::
OcclusionQueryResult
¶ Occlusion query result.
- Attention
C99’s equivalent binding is
bgfx_occlusion_query_result_t
.
-
OcclusionQueryResult::Enum
bgfx
::
getResult
(OcclusionQueryHandle _handle, int32_t *_result = NULL)¶ Retrieve occlusion query result from previous frame.
- Return
Occlusion query result.
- Attention
C99’s equivalent binding is
bgfx_get_result
.- Parameters
[in] _handle
: Handle to occlusion query object.[out] _result
: Number of pixels that passed test. This argument can beNULL
if result of occlusion query is not needed.
-
void
bgfx
::
destroy
(OcclusionQueryHandle _handle)¶ Destroy occlusion query.
- Attention
C99’s equivalent binding is
bgfx_destroy_occlusion_query
.- Parameters
[in] _handle
: Handle to occlusion query object.