2016-08-29 22:31:11 +02:00
|
|
|
/*
|
2017-04-11 08:16:10 +02:00
|
|
|
* Copyright 2011-2017 Branimir Karadzic. All rights reserved.
|
2016-08-29 22:31:11 +02:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BGFX_UTILS_H_HEADER_GUARD
|
|
|
|
#define BGFX_UTILS_H_HEADER_GUARD
|
|
|
|
|
|
|
|
#include <bgfx/bgfx.h>
|
2017-04-11 08:16:10 +02:00
|
|
|
#include "image.h"
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void* load(const char* _filePath, uint32_t* _size = NULL);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void unload(void* _ptr);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
bgfx::ShaderHandle loadShader(const char* _name);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
bgfx::ImageContainer* imageLoad(const char* _filePath, bgfx::TextureFormat::Enum _dstFormat);
|
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices);
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
/// Returns true if both internal transient index and vertex buffer have
|
|
|
|
/// enough space.
|
|
|
|
///
|
|
|
|
/// @param[in] _numVertices Number of vertices.
|
|
|
|
/// @param[in] _decl Vertex declaration.
|
|
|
|
/// @param[in] _numIndices Number of indices.
|
|
|
|
///
|
|
|
|
inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexDecl& _decl, uint32_t _numIndices)
|
|
|
|
{
|
|
|
|
return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _decl)
|
|
|
|
&& _numIndices == bgfx::getAvailTransientIndexBuffer(_numIndices)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
struct MeshState
|
|
|
|
{
|
|
|
|
struct Texture
|
|
|
|
{
|
|
|
|
uint32_t m_flags;
|
|
|
|
bgfx::UniformHandle m_sampler;
|
|
|
|
bgfx::TextureHandle m_texture;
|
|
|
|
uint8_t m_stage;
|
|
|
|
};
|
|
|
|
|
|
|
|
Texture m_textures[4];
|
|
|
|
uint64_t m_state;
|
|
|
|
bgfx::ProgramHandle m_program;
|
|
|
|
uint8_t m_numTextures;
|
|
|
|
uint8_t m_viewId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Mesh;
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
Mesh* meshLoad(const char* _filePath);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void meshUnload(Mesh* _mesh);
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
MeshState* meshStateCreate();
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void meshStateDestroy(MeshState* _meshState);
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void meshSubmit(const Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state = BGFX_STATE_MASK);
|
2017-04-11 08:16:10 +02:00
|
|
|
|
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices = 1);
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
///
|
2016-08-29 22:31:11 +02:00
|
|
|
struct Args
|
|
|
|
{
|
|
|
|
Args(int _argc, char** _argv);
|
|
|
|
|
|
|
|
bgfx::RendererType::Enum m_type;
|
|
|
|
uint16_t m_pciId;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BGFX_UTILS_H_HEADER_GUARD
|