summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/bgfx_utils.h
diff options
context:
space:
mode:
author Julian Sikorski <belegdol+github@gmail.com>2019-10-13 13:50:38 +0200
committer R. Belmont <rb6502@users.noreply.github.com>2019-10-13 07:50:38 -0400
commit0837e7451a84f95c29dbdb9bd6b8b931fee1635d (patch)
tree626bcbd250a7fbebdf5958a288d2f438d4f9fb5a /3rdparty/bgfx/examples/common/bgfx_utils.h
parentc913ccb59d713ce0b91135520719ac5385e54358 (diff)
WIP: sync bgfx, bx and bimg with latest upstream (#5723)
* Sync with bgfx upstream revision b91d0b6 * Sync with bx upstream revision d60912b * Sync with bimg upstream revision bd81f60 * Add astc-codec decoder * Rename VertexDecl to VertexLayout * Rename UniformType enum Int1 to Sampler. * Add NVN stub * Fix unused-const-variable error on macOS * Drop redundant explicit language parameters buildoptions_cpp are only applied to c++ files and buildoptions_objcpp are only applied to objective c++ files. As such, hardcoding -x offers no benefit while preventing overrides (such as one needed by 3rdparty/bgfx/src/renderer_vk.cpp on macOS) from working. * Re-introduce -x c++ in places where C code is compiled as C++ to prevent clang from throwing a warning * Build bgfx as Objective-C++ on macOS It is needed due to included headers * Enable Direct3D12 and Vulkan bgfx rendering backends * Enable building of spirv shaders * Properly escape /c in cmd call * Comment out dx12 bgfx renderer * Honor VERBOSE setting during shaders build * Only invert hlsl shader XYZ_TO_sRGB matrix for opengl * Add spirv shaders * OpenGL ES needs transposed matrix too * Metal needs transposed matrix as well
Diffstat (limited to '3rdparty/bgfx/examples/common/bgfx_utils.h')
-rw-r--r--3rdparty/bgfx/examples/common/bgfx_utils.h63
1 files changed, 55 insertions, 8 deletions
diff --git a/3rdparty/bgfx/examples/common/bgfx_utils.h b/3rdparty/bgfx/examples/common/bgfx_utils.h
index 87799f2e2c4..25be9ffc642 100644
--- a/3rdparty/bgfx/examples/common/bgfx_utils.h
+++ b/3rdparty/bgfx/examples/common/bgfx_utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
@@ -9,6 +9,12 @@
#include <bx/pixelformat.h>
#include <bgfx/bgfx.h>
#include <bimg/bimg.h>
+#include "bounds.h"
+
+#include <tinystl/allocator.h>
+#include <tinystl/vector.h>
+namespace stl = tinystl;
+
///
void* load(const char* _filePath, uint32_t* _size = NULL);
@@ -23,24 +29,24 @@ bgfx::ShaderHandle loadShader(const char* _name);
bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName);
///
-bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_SAMPLER_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL, bimg::Orientation::Enum* _orientation = NULL);
+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);
///
bimg::ImageContainer* imageLoad(const char* _filePath, bgfx::TextureFormat::Enum _dstFormat);
///
-void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices);
+void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexLayout _layout, const uint16_t* _indices, uint32_t _numIndices);
/// 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] _layout Vertex layout.
/// @param[in] _numIndices Number of indices.
///
-inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexDecl& _decl, uint32_t _numIndices)
+inline bool checkAvailTransientBuffers(uint32_t _numVertices, const bgfx::VertexLayout& _layout, uint32_t _numIndices)
{
- return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _decl)
+ return _numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, _layout)
&& (0 == _numIndices || _numIndices == bgfx::getAvailTransientIndexBuffer(_numIndices) )
;
}
@@ -78,10 +84,51 @@ struct MeshState
bgfx::ViewId m_viewId;
};
-struct Mesh;
+struct Primitive
+{
+ uint32_t m_startIndex;
+ uint32_t m_numIndices;
+ uint32_t m_startVertex;
+ uint32_t m_numVertices;
+
+ Sphere m_sphere;
+ Aabb m_aabb;
+ Obb m_obb;
+};
+
+typedef stl::vector<Primitive> PrimitiveArray;
+
+struct Group
+{
+ Group();
+ void reset();
+
+ bgfx::VertexBufferHandle m_vbh;
+ bgfx::IndexBufferHandle m_ibh;
+ uint16_t m_numVertices;
+ uint8_t* m_vertices;
+ uint32_t m_numIndices;
+ uint16_t* m_indices;
+ Sphere m_sphere;
+ Aabb m_aabb;
+ Obb m_obb;
+ PrimitiveArray m_prims;
+};
+typedef stl::vector<Group> GroupArray;
+
+struct Mesh
+{
+ void load(bx::ReaderSeekerI* _reader, bool _ramcopy);
+ void unload();
+ void submit(bgfx::ViewId _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state) const;
+ void submit(const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices) const;
+
+ bgfx::VertexLayout m_layout;
+ GroupArray m_groups;
+};
///
-Mesh* meshLoad(const char* _filePath);
+Mesh* meshLoad(const char* _filePath, bool _ramcopy = false);
///
void meshUnload(Mesh* _mesh);