bgfx_utils.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2011-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #ifndef BGFX_UTILS_H_HEADER_GUARD
  6. #define BGFX_UTILS_H_HEADER_GUARD
  7. #include <bgfx/bgfx.h>
  8. void* load(const char* _filePath, uint32_t* _size = NULL);
  9. void unload(void* _ptr);
  10. bgfx::ShaderHandle loadShader(const char* _name);
  11. bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName);
  12. bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL);
  13. void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices);
  14. /// Returns true if both internal transient index and vertex buffer have
  15. /// enough space.
  16. ///
  17. /// @param[in] _numVertices Number of vertices.
  18. /// @param[in] _decl Vertex declaration.
  19. /// @param[in] _numIndices Number of indices.
  20. ///
  21. inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexDecl& _decl, uint32_t _numIndices)
  22. {
  23. return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _decl)
  24. && _numIndices == bgfx::getAvailTransientIndexBuffer(_numIndices)
  25. ;
  26. }
  27. struct MeshState
  28. {
  29. struct Texture
  30. {
  31. uint32_t m_flags;
  32. bgfx::UniformHandle m_sampler;
  33. bgfx::TextureHandle m_texture;
  34. uint8_t m_stage;
  35. };
  36. Texture m_textures[4];
  37. uint64_t m_state;
  38. bgfx::ProgramHandle m_program;
  39. uint8_t m_numTextures;
  40. uint8_t m_viewId;
  41. };
  42. struct Mesh;
  43. Mesh* meshLoad(const char* _filePath);
  44. void meshUnload(Mesh* _mesh);
  45. MeshState* meshStateCreate();
  46. void meshStateDestroy(MeshState* _meshState);
  47. void meshSubmit(const Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state = BGFX_STATE_MASK);
  48. void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices = 1);
  49. struct Args
  50. {
  51. Args(int _argc, char** _argv);
  52. bgfx::RendererType::Enum m_type;
  53. uint16_t m_pciId;
  54. };
  55. #endif // BGFX_UTILS_H_HEADER_GUARD