summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/27-terrain/terrain.cpp
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/27-terrain/terrain.cpp
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/27-terrain/terrain.cpp')
-rw-r--r--3rdparty/bgfx/examples/27-terrain/terrain.cpp55
1 files changed, 27 insertions, 28 deletions
diff --git a/3rdparty/bgfx/examples/27-terrain/terrain.cpp b/3rdparty/bgfx/examples/27-terrain/terrain.cpp
index 8ae06d56833..dcf6fbae12a 100644
--- a/3rdparty/bgfx/examples/27-terrain/terrain.cpp
+++ b/3rdparty/bgfx/examples/27-terrain/terrain.cpp
@@ -27,17 +27,17 @@ struct PosTexCoord0Vertex
static void init()
{
- ms_decl
+ ms_layout
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
.end();
}
- static bgfx::VertexDecl ms_decl;
+ static bgfx::VertexLayout ms_layout;
};
-bgfx::VertexDecl PosTexCoord0Vertex::ms_decl;
+bgfx::VertexLayout PosTexCoord0Vertex::ms_layout;
struct TerrainData
{
@@ -62,8 +62,8 @@ struct BrushData
class ExampleTerrain : public entry::AppI
{
public:
- ExampleTerrain(const char* _name, const char* _description)
- : entry::AppI(_name, _description)
+ExampleTerrain(const char* _name, const char* _description, const char* _url)
+ : entry::AppI(_name, _description, _url)
{
}
@@ -112,7 +112,7 @@ public:
m_dvbh.idx = bgfx::kInvalidHandle;
m_dibh.idx = bgfx::kInvalidHandle;
m_heightTexture.idx = bgfx::kInvalidHandle;
- s_heightTexture = bgfx::createUniform("s_heightTexture", bgfx::UniformType::Int1);
+ s_heightTexture = bgfx::createUniform("s_heightTexture", bgfx::UniformType::Sampler);
m_oldWidth = 0;
m_oldHeight = 0;
@@ -135,9 +135,8 @@ public:
cameraCreate();
- const float initialPos[3] = { s_terrainSize/2.0f, 100.0f, 0.0f };
- cameraSetPosition(initialPos);
- cameraSetVerticalAngle(-bx::kPi/4.0f);
+ cameraSetPosition({ s_terrainSize/2.0f, 100.0f, 0.0f });
+ cameraSetVerticalAngle(-bx::kPiQuarter);
}
virtual int shutdown() override
@@ -242,7 +241,7 @@ public:
}
mem = bgfx::makeRef(&m_terrain.m_vertices[0], sizeof(PosTexCoord0Vertex) * m_terrain.m_vertexCount);
- m_vbh = bgfx::createVertexBuffer(mem, PosTexCoord0Vertex::ms_decl);
+ m_vbh = bgfx::createVertexBuffer(mem, PosTexCoord0Vertex::ms_layout);
if (bgfx::isValid(m_ibh) )
{
bgfx::destroy(m_ibh);
@@ -257,7 +256,7 @@ public:
if (!bgfx::isValid(m_dvbh) )
{
- m_dvbh = bgfx::createDynamicVertexBuffer(m_terrain.m_vertexCount, PosTexCoord0Vertex::ms_decl);
+ m_dvbh = bgfx::createDynamicVertexBuffer(m_terrain.m_vertexCount, PosTexCoord0Vertex::ms_layout);
}
mem = bgfx::makeRef(&m_terrain.m_vertices[0], sizeof(PosTexCoord0Vertex) * m_terrain.m_vertexCount);
@@ -278,7 +277,7 @@ public:
updateTerrainMesh();
mem = bgfx::makeRef(&m_terrain.m_vertices[0], sizeof(PosTexCoord0Vertex) * m_terrain.m_vertexCount);
- m_vbh = bgfx::createVertexBuffer(mem, PosTexCoord0Vertex::ms_decl);
+ m_vbh = bgfx::createVertexBuffer(mem, PosTexCoord0Vertex::ms_layout);
mem = bgfx::makeRef(&m_terrain.m_indices[0], sizeof(uint16_t) * m_terrain.m_indexCount);
m_ibh = bgfx::createIndexBuffer(mem);
@@ -357,30 +356,25 @@ public:
float ray_world[4];
bx::vec4MulMtx(ray_world, ray_eye, invViewMtx);
- float ray_dir[3];
- bx::vec3Norm(ray_dir, ray_world);
- ray_dir[0] *= -1.0;
- ray_dir[1] *= -1.0;
- ray_dir[2] *= -1.0;
+ const bx::Vec3 rayDir = bx::mul(bx::normalize(bx::load<bx::Vec3>(ray_world) ), -1.0f);
- float pos[3];
- cameraGetPosition(pos);
+ bx::Vec3 pos = cameraGetPosition();
for (int i = 0; i < 1000; ++i)
{
- bx::vec3Add(pos, pos, ray_dir);
+ pos = bx::add(pos, rayDir);
- if (pos[0] < 0
- || pos[0] >= s_terrainSize
- || pos[2] < 0
- || pos[2] >= s_terrainSize)
+ if (pos.x < 0
+ || pos.x >= s_terrainSize
+ || pos.z < 0
+ || pos.z >= s_terrainSize)
{
continue;
}
- uint32_t heightMapPos = ( (uint32_t)pos[2] * s_terrainSize) + (uint32_t)pos[0];
- if ( pos[1] < m_terrain.m_heightMap[heightMapPos] )
+ uint32_t heightMapPos = ( (uint32_t)pos.z * s_terrainSize) + (uint32_t)pos.x;
+ if (pos.y < m_terrain.m_heightMap[heightMapPos])
{
- paintTerrainHeight( (uint32_t)pos[0], (uint32_t)pos[2]);
+ paintTerrainHeight( (uint32_t)pos.x, (uint32_t)pos.z);
return;
}
}
@@ -528,4 +522,9 @@ public:
} // namespace
-ENTRY_IMPLEMENT_MAIN(ExampleTerrain, "27-terrain", "Terrain painting example.");
+ENTRY_IMPLEMENT_MAIN(
+ ExampleTerrain
+ , "27-terrain"
+ , "Terrain painting example."
+ , "https://bkaradzic.github.io/bgfx/examples.html#terrain"
+ );