Fix some engine API to be exposed for C++ scripting
This commit is contained in:
@@ -36,7 +36,7 @@ bool PreviewsCache::FlushTask::Run()
|
||||
return true;
|
||||
}
|
||||
auto mipData = _data.GetData(0, 0);
|
||||
ASSERT(mipData->DepthPitch == CalculateTextureMemoryUsage(_cache->GetTexture()->Format(), _cache->Width(), _cache->Height(), 1));
|
||||
ASSERT(mipData->DepthPitch == RenderTools::CalculateTextureMemoryUsage(_cache->GetTexture()->Format(), _cache->Width(), _cache->Height(), 1));
|
||||
|
||||
ScopeLock lock(_cache->Locker);
|
||||
|
||||
@@ -250,7 +250,7 @@ CreateAssetResult PreviewsCache::create(CreateAssetContext& context)
|
||||
context.Data.CustomData.Copy(&textureHeader);
|
||||
|
||||
// Create blank image (chunk 0)
|
||||
uint64 imageSize = CalculateTextureMemoryUsage(ASSETS_ICONS_ATLAS_FORMAT, ASSETS_ICONS_ATLAS_SIZE, ASSETS_ICONS_ATLAS_SIZE, 1);
|
||||
uint64 imageSize = RenderTools::CalculateTextureMemoryUsage(ASSETS_ICONS_ATLAS_FORMAT, ASSETS_ICONS_ATLAS_SIZE, ASSETS_ICONS_ATLAS_SIZE, 1);
|
||||
ASSERT(imageSize <= MAX_int32);
|
||||
if (context.AllocateChunk(0))
|
||||
return CreateAssetResult::CannotAllocateChunk;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Foliage instanced mesh instance. Packed data with very little of logic. Managed by the foliage chunks and foliage actor itself.
|
||||
/// </summary>
|
||||
API_STRUCT(NoPod) struct FoliageInstance
|
||||
API_STRUCT(NoPod) struct FLAXENGINE_API FoliageInstance
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(FoliageInstance);
|
||||
|
||||
|
||||
@@ -395,6 +395,35 @@ void RenderTools::UpdateModelLODTransition(byte& lodTransition)
|
||||
lodTransition = static_cast<byte>(Math::Min<int32>(newProgress, 255));
|
||||
}
|
||||
|
||||
uint64 RenderTools::CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels)
|
||||
{
|
||||
uint64 result = 0;
|
||||
|
||||
if (mipLevels == 0)
|
||||
mipLevels = 69;
|
||||
|
||||
uint32 rowPitch, slicePitch;
|
||||
while (mipLevels > 0 && (width >= 1 || height >= 1))
|
||||
{
|
||||
ComputePitch(format, width, height, rowPitch, slicePitch);
|
||||
result += slicePitch;
|
||||
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
if (height > 1)
|
||||
height >>= 1;
|
||||
|
||||
mipLevels--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64 RenderTools::CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels)
|
||||
{
|
||||
return CalculateTextureMemoryUsage(format, width, height, mipLevels) * depth;
|
||||
}
|
||||
|
||||
float RenderTools::ComputeBoundsScreenRadiusSquared(const Vector3& origin, float radius, const Vector3& viewOrigin, const Matrix& projectionMatrix)
|
||||
{
|
||||
const float screenMultiple = 0.5f * Math::Max(projectionMatrix.Values[0][0], projectionMatrix.Values[1][1]);
|
||||
@@ -452,35 +481,6 @@ int32 RenderTools::ComputeSkinnedModelLOD(const SkinnedModel* model, const Vecto
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels)
|
||||
{
|
||||
uint64 result = 0;
|
||||
|
||||
if (mipLevels == 0)
|
||||
mipLevels = 69;
|
||||
|
||||
uint32 rowPitch, slicePitch;
|
||||
while (mipLevels > 0 && (width >= 1 || height >= 1))
|
||||
{
|
||||
RenderTools::ComputePitch(format, width, height, rowPitch, slicePitch);
|
||||
result += slicePitch;
|
||||
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
if (height > 1)
|
||||
height >>= 1;
|
||||
|
||||
mipLevels--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels)
|
||||
{
|
||||
return CalculateTextureMemoryUsage(format, width, height, mipLevels) * depth;
|
||||
}
|
||||
|
||||
int32 MipLevelsCount(int32 width, bool useMipLevels)
|
||||
{
|
||||
if (!useMipLevels)
|
||||
|
||||
@@ -18,7 +18,7 @@ PACK_STRUCT(struct QuadShaderData
|
||||
/// <summary>
|
||||
/// Set of utilities for rendering.
|
||||
/// </summary>
|
||||
API_CLASS(Static) class RenderTools
|
||||
API_CLASS(Static) class FLAXENGINE_API RenderTools
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(RenderTools);
|
||||
public:
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
public:
|
||||
|
||||
static void UpdateModelLODTransition(byte& lodTransition);
|
||||
static uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels);
|
||||
static uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the bounds screen radius squared.
|
||||
@@ -110,23 +112,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Get texture memory usage
|
||||
// @param format Surface pixels format type
|
||||
// @param width Width in pixels
|
||||
// @param height Height in pixels
|
||||
// @param mipLevels Amount of mip levels
|
||||
// @returns Memory usage in bytes
|
||||
extern uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels);
|
||||
|
||||
// Get texture memory usage
|
||||
// @param format Surface pixels format type
|
||||
// @param width Width in pixels
|
||||
// @param height Height in pixels
|
||||
// @param depth Depth in pixels
|
||||
// @param mipLevels Amount of mip levels
|
||||
// @returns Memory usage in bytes
|
||||
extern uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels);
|
||||
|
||||
// Calculate mip levels count for a texture 1D
|
||||
// @param width Most detailed mip width
|
||||
// @param useMipLevels True if use mip levels, otherwise false (use only 1 mip)
|
||||
|
||||
@@ -561,7 +561,7 @@ bool GPUTexture::Resize(int32 width, int32 height, int32 depth)
|
||||
|
||||
uint64 GPUTexture::calculateMemoryUsage() const
|
||||
{
|
||||
return CalculateTextureMemoryUsage(Format(), Width(), Height(), Depth(), MipLevels()) * ArraySize();
|
||||
return RenderTools::CalculateTextureMemoryUsage(Format(), Width(), Height(), Depth(), MipLevels()) * ArraySize();
|
||||
}
|
||||
|
||||
String GPUTexture::ToString() const
|
||||
|
||||
@@ -144,7 +144,7 @@ void StreamingTexture::UnloadTexture()
|
||||
uint64 StreamingTexture::GetTotalMemoryUsage() const
|
||||
{
|
||||
const uint64 arraySize = _header.IsCubeMap ? 6 : 1;
|
||||
return CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize;
|
||||
return RenderTools::CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize;
|
||||
}
|
||||
|
||||
String StreamingTexture::ToString() const
|
||||
|
||||
@@ -231,9 +231,9 @@ bool GPUSwapChainDX11::Resize(int32 width, int32 height)
|
||||
_width = width;
|
||||
_height = height;
|
||||
#if PLATFORM_WINDOWS
|
||||
_memoryUsage = CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.BufferDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount;
|
||||
_memoryUsage = RenderTools::CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.BufferDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount;
|
||||
#else
|
||||
_memoryUsage = CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount;
|
||||
_memoryUsage = RenderTools::CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount;
|
||||
#endif
|
||||
|
||||
getBackBuffer();
|
||||
|
||||
@@ -231,7 +231,7 @@ bool GPUSwapChainDX12::Resize(int32 width, int32 height)
|
||||
_currentFrameIndex = _swapChain->GetCurrentBackBufferIndex();
|
||||
_width = width;
|
||||
_height = height;
|
||||
_memoryUsage = CalculateTextureMemoryUsage(_format, _width, _height, 1) * swapChainDesc.BufferCount;
|
||||
_memoryUsage = RenderTools::CalculateTextureMemoryUsage(_format, _width, _height, 1) * swapChainDesc.BufferCount;
|
||||
|
||||
getBackBuffer();
|
||||
#endif
|
||||
|
||||
@@ -415,7 +415,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height)
|
||||
}
|
||||
|
||||
// Calculate memory usage
|
||||
_memoryUsage = CalculateTextureMemoryUsage(_format, _width, _height, 1) * _backBuffers.Count();
|
||||
_memoryUsage = RenderTools::CalculateTextureMemoryUsage(_format, _width, _height, 1) * _backBuffers.Count();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="index">Lightmap index</param>
|
||||
/// <returns>Lightmap or null if missing or not ready</returns>
|
||||
Lightmap* GetReadyLightmap(int32 index);
|
||||
FLAXENGINE_API Lightmap* GetReadyLightmap(int32 index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets lightmaps array
|
||||
|
||||
@@ -207,8 +207,8 @@ class RenderListAllocation
|
||||
{
|
||||
public:
|
||||
|
||||
static void* Allocate(uintptr size);
|
||||
static void Free(void* ptr, uintptr size);
|
||||
static FLAXENGINE_API void* Allocate(uintptr size);
|
||||
static FLAXENGINE_API void Free(void* ptr, uintptr size);
|
||||
|
||||
template<typename T>
|
||||
class Data
|
||||
|
||||
Reference in New Issue
Block a user