Unravel Engine C++ Reference
Loading...
Searching...
No Matches
bgfx_utils.h
Go to the documentation of this file.
1/*
2 * Copyright 2011-2023 Branimir Karadzic. All rights reserved.
3 * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
4 */
5
6#ifndef BGFX_UTILS_H_HEADER_GUARD
7#define BGFX_UTILS_H_HEADER_GUARD
8
9#include <bgfx/bgfx.h>
10#include <bimg/bimg.h>
11#include <bimg/encode.h>
12#include <bimg/decode.h>
13
14#include <bx/bounds.h>
15#include <bx/pixelformat.h>
16#include <bx/string.h>
17
18#include <tinystl/allocator.h>
19#include <tinystl/vector.h>
20namespace stl = tinystl;
21
22bool saveToFile(bgfx::ViewId viewId, const char* _filePath, bgfx::FrameBufferHandle fbo, uint32_t width, uint32_t height);
24void* load(const char* _filePath, uint32_t* _size = NULL);
25
27void unload(void* _ptr);
28
30bgfx::ShaderHandle loadShader(const char* _name);
31
33bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName);
34
36bgfx::TextureHandle loadTexture(const char* _name,
37 uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE,
38 uint8_t _skip = 0,
39 bgfx::TextureInfo* _info = NULL,
40 bimg::Orientation::Enum* _orientation = NULL);
41
43bimg::ImageContainer* imageLoad(const void* data, uint32_t size, bgfx::TextureFormat::Enum _dstFormat = bgfx::TextureFormat::Count);
44bimg::ImageContainer* imageLoad(const char* _filePath, bgfx::TextureFormat::Enum _dstFormat = bgfx::TextureFormat::Count);
45bool imageSave(const char* saveAs, bimg::ImageContainer* image);
46
48void calcTangents(void* _vertices,
49 uint16_t _numVertices,
50 bgfx::VertexLayout _layout,
51 const uint16_t* _indices,
52 uint32_t _numIndices);
53
61inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexLayout& _layout, uint32_t _numIndices)
62{
63 return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _layout) &&
64 (0 == _numIndices || _numIndices == bgfx::getAvailTransientIndexBuffer(_numIndices));
65}
66
68inline uint32_t encodeNormalRgba8(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f)
69{
70 const float src[] = {
71 _x * 0.5f + 0.5f,
72 _y * 0.5f + 0.5f,
73 _z * 0.5f + 0.5f,
74 _w * 0.5f + 0.5f,
75 };
76 uint32_t dst;
77 bx::packRgba8(&dst, src);
78 return dst;
79}
80
81#endif // BGFX_UTILS_H_HEADER_GUARD
uint32_t encodeNormalRgba8(float _x, float _y=0.0f, float _z=0.0f, float _w=0.0f)
Definition bgfx_utils.h:68
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)
bool imageSave(const char *saveAs, bimg::ImageContainer *image)
bgfx::TextureHandle loadTexture(const char *_name, uint64_t _flags=BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, uint8_t _skip=0, bgfx::TextureInfo *_info=NULL, bimg::Orientation::Enum *_orientation=NULL)
void * load(const char *_filePath, uint32_t *_size=NULL)
void unload(void *_ptr)
bgfx::ProgramHandle loadProgram(const char *_vsName, const char *_fsName)
bool saveToFile(bgfx::ViewId viewId, const char *_filePath, bgfx::FrameBufferHandle fbo, uint32_t width, uint32_t height)
bgfx::ShaderHandle loadShader(const char *_name)
bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexLayout &_layout, uint32_t _numIndices)
Definition bgfx_utils.h:61