Graphics: Add DistanceAsSortKey function
This commit is contained in:
parent
9740db8fe2
commit
c3999d708f
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Copyright (C) 2020 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_ALGORITHM_GRAPHICS_HPP
|
||||||
|
#define NAZARA_ALGORITHM_GRAPHICS_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequisites.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
inline UInt32 DistanceAsSortKey(float distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/Algorithm.inl>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (C) 2020 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/Algorithm.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
#include <limits>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
inline UInt32 DistanceAsSortKey(float distance)
|
||||||
|
{
|
||||||
|
#if defined(arm) && \
|
||||||
|
((defined(__MAVERICK__) && defined(NAZARA_BIG_ENDIAN)) || \
|
||||||
|
(!defined(__SOFTFP__) && !defined(__VFP_FP__) && !defined(__MAVERICK__)))
|
||||||
|
#error The following code relies on native-endian IEEE-754 representation, which your platform does not guarantee
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static_assert(sizeof(float) == sizeof(UInt32));
|
||||||
|
static_assert(std::numeric_limits<float>::is_iec559);
|
||||||
|
|
||||||
|
if (std::isnan(distance))
|
||||||
|
return std::numeric_limits<UInt32>::max();
|
||||||
|
|
||||||
|
if (std::isinf(distance))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
UInt32 distanceInt;
|
||||||
|
std::memcpy(&distanceInt, &distance, sizeof(UInt32));
|
||||||
|
|
||||||
|
return ~distanceInt; //< Reverse distance to have back to front
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/RenderSpriteChain.hpp>
|
#include <Nazara/Graphics/RenderSpriteChain.hpp>
|
||||||
|
#include <Nazara/Graphics/Algorithm.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -32,19 +33,8 @@ namespace Nz
|
||||||
{
|
{
|
||||||
UInt64 matFlags = 1;
|
UInt64 matFlags = 1;
|
||||||
|
|
||||||
#if defined(arm) && \
|
float distanceNear = frustum.GetPlane(FrustumPlane::Near).Distance(m_worldInstance.GetWorldMatrix().GetTranslation());
|
||||||
((defined(__MAVERICK__) && defined(NAZARA_BIG_ENDIAN)) || \
|
UInt64 distance = DistanceAsSortKey(distanceNear);
|
||||||
(!defined(__SOFTFP__) && !defined(__VFP_FP__) && !defined(__MAVERICK__)))
|
|
||||||
#error The following code relies on native-endian IEEE-754 representation, which your platform does not guarantee
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static_assert(sizeof(float) == sizeof(UInt32));
|
|
||||||
|
|
||||||
float distanceNear = frustum.GetPlane(Nz::FrustumPlane::Near).Distance(m_worldInstance.GetWorldMatrix().GetTranslation());
|
|
||||||
UInt32 distanceInt;
|
|
||||||
std::memcpy(&distanceInt, &distanceNear, sizeof(UInt32));
|
|
||||||
|
|
||||||
UInt64 distance = static_cast<UInt64>(~distanceInt); //< Reverse distance to have back to front
|
|
||||||
|
|
||||||
// Transparent RQ index:
|
// Transparent RQ index:
|
||||||
// - Layer (8bits)
|
// - Layer (8bits)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/RenderSubmesh.hpp>
|
#include <Nazara/Graphics/RenderSubmesh.hpp>
|
||||||
|
#include <Nazara/Graphics/Algorithm.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -31,19 +32,8 @@ namespace Nz
|
||||||
{
|
{
|
||||||
UInt64 matFlags = 1;
|
UInt64 matFlags = 1;
|
||||||
|
|
||||||
#if defined(arm) && \
|
float distanceNear = frustum.GetPlane(FrustumPlane::Near).Distance(m_worldInstance.GetWorldMatrix().GetTranslation());
|
||||||
((defined(__MAVERICK__) && defined(NAZARA_BIG_ENDIAN)) || \
|
UInt64 distance = DistanceAsSortKey(distanceNear);
|
||||||
(!defined(__SOFTFP__) && !defined(__VFP_FP__) && !defined(__MAVERICK__)))
|
|
||||||
#error The following code relies on native-endian IEEE-754 representation, which your platform does not guarantee
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static_assert(sizeof(float) == sizeof(UInt32));
|
|
||||||
|
|
||||||
float distanceNear = frustum.GetPlane(Nz::FrustumPlane::Near).Distance(m_worldInstance.GetWorldMatrix().GetTranslation());
|
|
||||||
UInt32 distanceInt;
|
|
||||||
std::memcpy(&distanceInt, &distanceNear, sizeof(UInt32));
|
|
||||||
|
|
||||||
UInt64 distance = ~distanceInt; //< Reverse distance to have back to front
|
|
||||||
|
|
||||||
// Transparent RQ index:
|
// Transparent RQ index:
|
||||||
// - Layer (8bits)
|
// - Layer (8bits)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright (C) 2020 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/Algorithm.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue