summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common')
-rw-r--r--3rdparty/bgfx/examples/common/bounds.cpp96
-rw-r--r--3rdparty/bgfx/examples/common/bounds.h6
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_sdl.cpp2
-rw-r--r--3rdparty/bgfx/examples/common/imgui/imgui.cpp7
-rw-r--r--3rdparty/bgfx/examples/common/imgui/imgui.h24
-rw-r--r--3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp10
6 files changed, 133 insertions, 12 deletions
diff --git a/3rdparty/bgfx/examples/common/bounds.cpp b/3rdparty/bgfx/examples/common/bounds.cpp
index d2228e7eb63..3937b550567 100644
--- a/3rdparty/bgfx/examples/common/bounds.cpp
+++ b/3rdparty/bgfx/examples/common/bounds.cpp
@@ -277,6 +277,102 @@ void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num
_sphere.m_radius = bx::fsqrt(maxDistSq);
}
+void buildFrustumPlanes(Plane* _result, const float* _viewProj)
+{
+ const float xw = _viewProj[ 3];
+ const float yw = _viewProj[ 7];
+ const float zw = _viewProj[11];
+ const float ww = _viewProj[15];
+
+ const float xz = _viewProj[ 2];
+ const float yz = _viewProj[ 6];
+ const float zz = _viewProj[10];
+ const float wz = _viewProj[14];
+
+ Plane& near = _result[0];
+ Plane& far = _result[1];
+ Plane& left = _result[2];
+ Plane& right = _result[3];
+ Plane& top = _result[4];
+ Plane& bottom = _result[5];
+
+ near.m_normal[0] = xw - xz;
+ near.m_normal[1] = yw - yz;
+ near.m_normal[2] = zw - zz;
+ near.m_dist = ww - wz;
+
+ far.m_normal[0] = xw + xz;
+ far.m_normal[1] = yw + yz;
+ far.m_normal[2] = zw + zz;
+ far.m_dist = ww + wz;
+
+ const float xx = _viewProj[ 0];
+ const float yx = _viewProj[ 4];
+ const float zx = _viewProj[ 8];
+ const float wx = _viewProj[12];
+
+ left.m_normal[0] = xw - xx;
+ left.m_normal[1] = yw - yx;
+ left.m_normal[2] = zw - zx;
+ left.m_dist = ww - wx;
+
+ right.m_normal[0] = xw + xx;
+ right.m_normal[1] = yw + yx;
+ right.m_normal[2] = zw + zx;
+ right.m_dist = ww + wx;
+
+ const float xy = _viewProj[ 1];
+ const float yy = _viewProj[ 5];
+ const float zy = _viewProj[ 9];
+ const float wy = _viewProj[13];
+
+ top.m_normal[0] = xw + xy;
+ top.m_normal[1] = yw + yy;
+ top.m_normal[2] = zw + zy;
+ top.m_dist = ww + wy;
+
+ bottom.m_normal[0] = xw - xy;
+ bottom.m_normal[1] = yw - yy;
+ bottom.m_normal[2] = zw - zy;
+ bottom.m_dist = ww - wy;
+
+ Plane* plane = _result;
+ for (uint32_t ii = 0; ii < 6; ++ii)
+ {
+ float invLen = 1.0f / bx::vec3Norm(plane->m_normal, plane->m_normal);
+ plane->m_dist *= invLen;
+ ++plane;
+ }
+}
+
+void intersectPlanes(float _result[3], const Plane& _pa, const Plane& _pb, const Plane& _pc)
+{
+ float axb[3];
+ bx::vec3Cross(axb, _pa.m_normal, _pb.m_normal);
+
+ float bxc[3];
+ bx::vec3Cross(bxc, _pb.m_normal, _pc.m_normal);
+
+ float cxa[3];
+ bx::vec3Cross(cxa, _pc.m_normal, _pa.m_normal);
+
+ float tmp0[3];
+ bx::vec3Mul(tmp0, bxc, _pa.m_dist);
+
+ float tmp1[3];
+ bx::vec3Mul(tmp1, cxa, _pb.m_dist);
+
+ float tmp2[3];
+ bx::vec3Mul(tmp2, axb, _pc.m_dist);
+
+ float tmp[3];
+ bx::vec3Add(tmp, tmp0, tmp1);
+ bx::vec3Add(tmp0, tmp, tmp2);
+
+ float denom = bx::vec3Dot(_pa.m_normal, bxc);
+ bx::vec3Mul(_result, tmp0, -1.0f/denom);
+}
+
Ray makeRay(float _x, float _y, const float* _invVp)
{
Ray ray;
diff --git a/3rdparty/bgfx/examples/common/bounds.h b/3rdparty/bgfx/examples/common/bounds.h
index f59c2b2230f..24f23414f10 100644
--- a/3rdparty/bgfx/examples/common/bounds.h
+++ b/3rdparty/bgfx/examples/common/bounds.h
@@ -94,6 +94,12 @@ void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num
/// Calculate minimum bounding sphere.
void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step = 0.01f);
+/// Returns 6 (near, far, left, right, top, bottom) planes representing frustum planes.
+void buildFrustumPlanes(Plane* _planes, const float* _viewProj);
+
+/// Returns point from 3 intersecting planes.
+void intersectPlanes(float _result[3], const Plane& _pa, const Plane& _pb, const Plane& _pc);
+
/// Make screen space ray from x, y coordinate and inverse view-projection matrix.
Ray makeRay(float _x, float _y, const float* _invVp);
diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
index 2bff902302c..989d0ae0667 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
@@ -218,6 +218,8 @@ namespace entry
return wmi.info.cocoa.window;
# elif BX_PLATFORM_WINDOWS
return wmi.info.win.window;
+# elif BX_PLATFORM_STEAMLINK
+ return wmi.info.vivante.window;
# endif // BX_PLATFORM_
}
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp
index 2655e6ce0a1..4cdc5f30fe5 100644
--- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp
+++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp
@@ -3572,3 +3572,10 @@ bool imguiMouseOverArea()
{
return s_imgui.m_insideArea;
}
+
+bgfx::ProgramHandle imguiGetImageProgram(uint8_t _mip)
+{
+ const float lodEnabled[4] = { float(_mip), 1.0f, 0.0f, 0.0f };
+ bgfx::setUniform(s_imgui.u_imageLodEnabled, lodEnabled);
+ return s_imgui.m_imageProgram;
+}
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.h b/3rdparty/bgfx/examples/common/imgui/imgui.h
index 75269500c85..0ab18cb9f8a 100644
--- a/3rdparty/bgfx/examples/common/imgui/imgui.h
+++ b/3rdparty/bgfx/examples/common/imgui/imgui.h
@@ -208,12 +208,13 @@ bool imguiMouseOverArea();
namespace ImGui
{
-#define IMGUI_FLAGS_NONE UINT16_C(0x0000)
-#define IMGUI_FLAGS_ALPHA_BLEND UINT16_C(0x0001)
+#define IMGUI_FLAGS_NONE UINT8_C(0x00)
+#define IMGUI_FLAGS_ALPHA_BLEND UINT8_C(0x01)
// Helper function for passing bgfx::TextureHandle to ImGui::Image.
inline void Image(bgfx::TextureHandle _handle
- , uint16_t _flags
+ , uint8_t _flags
+ , uint8_t _mip
, const ImVec2& _size
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
@@ -221,9 +222,10 @@ namespace ImGui
, const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
)
{
- union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture;
- texture.s.flags = _flags;
+ union { struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; ImTextureID ptr; } texture;
texture.s.handle = _handle;
+ texture.s.flags = _flags;
+ texture.s.mip = _mip;
Image(texture.ptr, _size, _uv0, _uv1, _tintCol, _borderCol);
}
@@ -236,12 +238,13 @@ namespace ImGui
, const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
)
{
- Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _tintCol, _borderCol);
+ Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _tintCol, _borderCol);
}
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
inline bool ImageButton(bgfx::TextureHandle _handle
- , uint16_t _flags
+ , uint8_t _flags
+ , uint8_t _mip
, const ImVec2& _size
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
@@ -250,9 +253,10 @@ namespace ImGui
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
)
{
- union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture;
- texture.s.flags = _flags;
+ union { struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; ImTextureID ptr; } texture;
texture.s.handle = _handle;
+ texture.s.flags = _flags;
+ texture.s.mip = _mip;
return ImageButton(texture.ptr, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
}
@@ -266,7 +270,7 @@ namespace ImGui
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
)
{
- return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
+ return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
}
} // namespace ImGui
diff --git a/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp b/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp
index 4545bb998a0..f6f0a4e2bdd 100644
--- a/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp
+++ b/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp
@@ -305,15 +305,21 @@ struct OcornutImguiContext
;
bgfx::TextureHandle th = m_texture;
+ bgfx::ProgramHandle program = m_program;
if (NULL != cmd->TextureId)
{
- union { ImTextureID ptr; struct { uint16_t flags; bgfx::TextureHandle handle; } s; } texture = { cmd->TextureId };
+ union { ImTextureID ptr; struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; } texture = { cmd->TextureId };
state |= 0 != (IMGUI_FLAGS_ALPHA_BLEND & texture.s.flags)
? BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
: BGFX_STATE_NONE
;
th = texture.s.handle;
+ if (0 != texture.s.mip)
+ {
+ extern bgfx::ProgramHandle imguiGetImageProgram(uint8_t _mip);
+ program = imguiGetImageProgram(texture.s.mip);
+ }
}
else
{
@@ -331,7 +337,7 @@ struct OcornutImguiContext
bgfx::setTexture(0, s_tex, th);
bgfx::setVertexBuffer(&tvb, 0, numVertices);
bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
- bgfx::submit(cmd->ViewId, m_program);
+ bgfx::submit(cmd->ViewId, program);
}
offset += cmd->ElemCount;