6#ifndef BGFX_UTILS_H_HEADER_GUARD
7#define BGFX_UTILS_H_HEADER_GUARD
11#include <bimg/encode.h>
12#include <bimg/decode.h>
15#include <bx/pixelformat.h>
17#include <bx/filepath.h>
19#include <tinystl/allocator.h>
20#include <tinystl/vector.h>
24namespace stl = tinystl;
30bool saveToFile(bgfx::ViewId viewId,
const bx::FilePath& _filePath, bgfx::FrameBufferHandle fbo, uint32_t
width, uint32_t
height);
32void*
load(
const bx::FilePath& _filePath, uint32_t* _size = NULL);
38bgfx::ShaderHandle
loadShader(
const bx::StringView& _name);
39bgfx::ShaderHandle
loadShader(
const bx::FilePath& _filePath);
41bgfx::ProgramHandle
loadProgram(
const bx::StringView& _vsName,
const bx::StringView& _fsName);
44bgfx::TextureHandle
loadTexture(
const bx::FilePath& _filePath,
45 uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE,
47 bgfx::TextureInfo* _info = NULL,
48 bimg::Orientation::Enum* _orientation = NULL,
49 bx::Error* _err = NULL,
57 uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE,
59 bgfx::TextureInfo* _info = NULL,
60 bimg::Orientation::Enum* _orientation = NULL,
61 const char* _name = NULL,
62 bx::Error* _err = NULL,
66bimg::ImageContainer*
imageLoad(
const void* data, uint32_t
size, bgfx::TextureFormat::Enum _dstFormat = bgfx::TextureFormat::Count);
67bimg::ImageContainer*
imageLoad(
const bx::FilePath& _filePath, bgfx::TextureFormat::Enum _dstFormat = bgfx::TextureFormat::Count);
70bool imageParseInfo(
const bx::FilePath& _filePath, bimg::ImageContainer& _info, bx::Error* _err = NULL);
71bool imageParseInfo(
const void* _data, uint32_t _size, bimg::ImageContainer& _info, bx::Error* _err = NULL);
73bool imageSave(
const char* saveAs, bimg::ImageContainer* image);
85 uint16_t _numVertices,
86 bgfx::VertexLayout _layout,
87 const uint16_t* _indices,
88 uint32_t _numIndices);
99 return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _layout) &&
100 (0 == _numIndices || _numIndices == bgfx::getAvailTransientIndexBuffer(_numIndices));
106 const float src[] = {
113 bx::packRgba8(&dst, src);
uint32_t encodeNormalRgba8(float _x, float _y=0.0f, float _z=0.0f, float _w=0.0f)
bgfx::ShaderHandle loadShader(const bx::StringView &_name)
bimg::ImageContainer * imageLoad(const void *data, uint32_t size, bgfx::TextureFormat::Enum _dstFormat=bgfx::TextureFormat::Count)
void calcTangents(void *_vertices, uint16_t _numVertices, bgfx::VertexLayout _layout, const uint16_t *_indices, uint32_t _numIndices)
std::function< bool(const bgfx::TextureInfo &_info)> TexturePreCreateFn
bgfx::ProgramHandle loadProgram(const bx::StringView &_vsName, const bx::StringView &_fsName)
bool imageParseInfo(const bx::FilePath &_filePath, bimg::ImageContainer &_info, bx::Error *_err=NULL)
Parse image metadata without decoding pixel data.
bool imageSave(const char *saveAs, bimg::ImageContainer *image)
bool imageFlipTangentSpaceNormalY(bimg::ImageContainer *&_image)
void * load(const bx::FilePath &_filePath, uint32_t *_size=NULL)
bool imagePrepareNormalMapBakePng(bimg::ImageContainer *&_image)
Prepare a flipped normal map for PNG bake export (RGBA8, opaque alpha when unused).
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)
bool saveToFile(bgfx::ViewId viewId, const bx::FilePath &_filePath, bgfx::FrameBufferHandle fbo, uint32_t width, uint32_t height)
bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexLayout &_layout, uint32_t _numIndices)