Unravel Engine C++ Reference
Loading...
Searching...
No Matches
bgfx_utils.h File Reference
#include <bgfx/bgfx.h>
#include <bimg/bimg.h>
#include <bimg/encode.h>
#include <bimg/decode.h>
#include <bx/bounds.h>
#include <bx/pixelformat.h>
#include <bx/string.h>
#include <bx/filepath.h>
#include <tinystl/allocator.h>
#include <tinystl/vector.h>
#include <functional>

Go to the source code of this file.

Typedefs

using TexturePreCreateFn = std::function<bool(const bgfx::TextureInfo& _info)>
 

Functions

bool saveToFile (bgfx::ViewId viewId, const bx::FilePath &_filePath, bgfx::FrameBufferHandle fbo, uint32_t width, uint32_t height)
 
void * load (const bx::FilePath &_filePath, uint32_t *_size=NULL)
 
void unload (void *_ptr)
 
bgfx::ShaderHandle loadShader (const bx::StringView &_name)
 
bgfx::ShaderHandle loadShader (const bx::FilePath &_filePath)
 
bgfx::ProgramHandle loadProgram (const bx::StringView &_vsName, const bx::StringView &_fsName)
 
bgfx::TextureHandle loadTexture (const bx::FilePath &_filePath, uint64_t _flags=BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, uint8_t _skip=0, bgfx::TextureInfo *_info=NULL, bimg::Orientation::Enum *_orientation=NULL, bx::Error *_err=NULL, const TexturePreCreateFn &_preCreate=nullptr)
 
bgfx::TextureHandle loadTexture (const void *_data, uint32_t _size, uint64_t _flags=BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, uint8_t _skip=0, bgfx::TextureInfo *_info=NULL, bimg::Orientation::Enum *_orientation=NULL, const char *_name=NULL, bx::Error *_err=NULL, const TexturePreCreateFn &_preCreate=nullptr)
 
bimg::ImageContainer * imageLoad (const void *data, uint32_t size, bgfx::TextureFormat::Enum _dstFormat=bgfx::TextureFormat::Count)
 
bimg::ImageContainer * imageLoad (const bx::FilePath &_filePath, bgfx::TextureFormat::Enum _dstFormat=bgfx::TextureFormat::Count)
 
bool imageParseInfo (const bx::FilePath &_filePath, bimg::ImageContainer &_info, bx::Error *_err=NULL)
 Parse image metadata without decoding pixel data.
 
bool imageParseInfo (const void *_data, uint32_t _size, bimg::ImageContainer &_info, bx::Error *_err=NULL)
 
bool imageSave (const char *saveAs, bimg::ImageContainer *image)
 
bool imageFlipTangentSpaceNormalY (bimg::ImageContainer *&_image)
 
bool imagePrepareNormalMapBakePng (bimg::ImageContainer *&_image)
 Prepare a flipped normal map for PNG bake export (RGBA8, opaque alpha when unused).
 
void calcTangents (void *_vertices, uint16_t _numVertices, bgfx::VertexLayout _layout, const uint16_t *_indices, uint32_t _numIndices)
 
bool checkAvailTransientBuffers (uint32_t _numVertices, const bgfx::VertexLayout &_layout, uint32_t _numIndices)
 
uint32_t encodeNormalRgba8 (float _x, float _y=0.0f, float _z=0.0f, float _w=0.0f)
 

Typedef Documentation

◆ TexturePreCreateFn

using TexturePreCreateFn = std::function<bool(const bgfx::TextureInfo& _info)>

Invoked after the image container has been parsed (with the texture info computed from its header) and right before the GPU texture is created. Return false to skip the GPU allocation.

Definition at line 28 of file bgfx_utils.h.

Function Documentation

◆ calcTangents()

void calcTangents ( void * _vertices,
uint16_t _numVertices,
bgfx::VertexLayout _layout,
const uint16_t * _indices,
uint32_t _numIndices )

Definition at line 628 of file bgfx_utils.cpp.

◆ checkAvailTransientBuffers()

bool checkAvailTransientBuffers ( uint32_t _numVertices,
const bgfx::VertexLayout & _layout,
uint32_t _numIndices )
inline

Returns true if both internal transient index and vertex buffer have enough space.

Parameters
[in]_numVerticesNumber of vertices.
[in]_layoutVertex layout.
[in]_numIndicesNumber of indices.

Definition at line 97 of file bgfx_utils.h.

◆ encodeNormalRgba8()

uint32_t encodeNormalRgba8 ( float _x,
float _y = 0.0f,
float _z = 0.0f,
float _w = 0.0f )
inline

Definition at line 104 of file bgfx_utils.h.

◆ imageFlipTangentSpaceNormalY()

bool imageFlipTangentSpaceNormalY ( bimg::ImageContainer *& _image)

Flip tangent-space normal map Y (tangent-space +Y / green channel via bimg unpack/pack). Preserves the container format for uncompressed sources. Compressed inputs are decoded to RGBA8 and left as RGBA8 (no lossy re-encode back to BC).

Definition at line 439 of file bgfx_utils.cpp.

◆ imageLoad() [1/2]

bimg::ImageContainer * imageLoad ( const bx::FilePath & _filePath,
bgfx::TextureFormat::Enum _dstFormat = bgfx::TextureFormat::Count )

Definition at line 588 of file bgfx_utils.cpp.

◆ imageLoad() [2/2]

bimg::ImageContainer * imageLoad ( const void * data,
uint32_t size,
bgfx::TextureFormat::Enum _dstFormat = bgfx::TextureFormat::Count )

Definition at line 583 of file bgfx_utils.cpp.

◆ imageParseInfo() [1/2]

bool imageParseInfo ( const bx::FilePath & _filePath,
bimg::ImageContainer & _info,
bx::Error * _err = NULL )

Parse image metadata without decoding pixel data.

Definition at line 613 of file bgfx_utils.cpp.

◆ imageParseInfo() [2/2]

bool imageParseInfo ( const void * _data,
uint32_t _size,
bimg::ImageContainer & _info,
bx::Error * _err = NULL )

Definition at line 603 of file bgfx_utils.cpp.

◆ imagePrepareNormalMapBakePng()

bool imagePrepareNormalMapBakePng ( bimg::ImageContainer *& _image)

Prepare a flipped normal map for PNG bake export (RGBA8, opaque alpha when unused).

Definition at line 467 of file bgfx_utils.cpp.

◆ imageSave()

bool imageSave ( const char * saveAs,
bimg::ImageContainer * image )

Definition at line 789 of file bgfx_utils.cpp.

◆ load()

void * load ( const bx::FilePath & _filePath,
uint32_t * _size = NULL )

Definition at line 103 of file bgfx_utils.cpp.

◆ loadProgram()

bgfx::ProgramHandle loadProgram ( const bx::StringView & _vsName,
const bx::StringView & _fsName )

Definition at line 211 of file bgfx_utils.cpp.

◆ loadShader() [1/2]

bgfx::ShaderHandle loadShader ( const bx::FilePath & _filePath)

Definition at line 191 of file bgfx_utils.cpp.

◆ loadShader() [2/2]

bgfx::ShaderHandle loadShader ( const bx::StringView & _name)

Definition at line 185 of file bgfx_utils.cpp.

◆ loadTexture() [1/2]

bgfx::TextureHandle loadTexture ( const bx::FilePath & _filePath,
uint64_t _flags = BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE,
uint8_t _skip = 0,
bgfx::TextureInfo * _info = NULL,
bimg::Orientation::Enum * _orientation = NULL,
bx::Error * _err = NULL,
const TexturePreCreateFn & _preCreate = nullptr )

Definition at line 571 of file bgfx_utils.cpp.

◆ loadTexture() [2/2]

bgfx::TextureHandle loadTexture ( const void * _data,
uint32_t _size,
uint64_t _flags = BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE,
uint8_t _skip = 0,
bgfx::TextureInfo * _info = NULL,
bimg::Orientation::Enum * _orientation = NULL,
const char * _name = NULL,
bx::Error * _err = NULL,
const TexturePreCreateFn & _preCreate = nullptr )

Load a texture from memory (DDS, KTX, PNG, etc.). _name is optional debug label. _preCreate is invoked after the image header has been parsed, right before the GPU texture is created.

Definition at line 491 of file bgfx_utils.cpp.

◆ saveToFile()

bool saveToFile ( bgfx::ViewId viewId,
const bx::FilePath & _filePath,
bgfx::FrameBufferHandle fbo,
uint32_t width,
uint32_t height )

Definition at line 729 of file bgfx_utils.cpp.

◆ unload()

void unload ( void * _ptr)

Definition at line 109 of file bgfx_utils.cpp.