You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rnx #rb none #ROBOMERGE-OWNER: ryan.durand #ROBOMERGE-AUTHOR: ryan.durand #ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900 #ROBOMERGE-BOT: (v613-10869866) [CL 10870549 by ryan durand in Main branch]
149 lines
4.9 KiB
C++
149 lines
4.9 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Misc/ConfigCacheIni.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "Fonts/FontTypes.h"
|
|
#include "Fonts/FontCache.h"
|
|
#include "Rendering/RenderingCommon.h"
|
|
#include "Rendering/DrawElements.h"
|
|
#include "Rendering/SlateRenderer.h"
|
|
#include "Interfaces/ISlate3DRenderer.h"
|
|
#include "Interfaces/ISlateRHIRendererModule.h"
|
|
#include "SlateRHIFontTexture.h"
|
|
#include "SlateRHIResourceManager.h"
|
|
#include "SlateRHIRenderer.h"
|
|
#include "Slate3DRenderer.h"
|
|
#include "SlateUpdatableBuffer.h"
|
|
|
|
class FSlateRHIFontAtlasFactory : public ISlateFontAtlasFactory
|
|
{
|
|
public:
|
|
FSlateRHIFontAtlasFactory()
|
|
{
|
|
auto GetAtlasSizeFromConfig = [](const TCHAR* InConfigKey, const FString& InConfigFilename, int32& OutAtlasSize)
|
|
{
|
|
if (GConfig)
|
|
{
|
|
GConfig->GetInt(TEXT("SlateRenderer"), InConfigKey, OutAtlasSize, InConfigFilename);
|
|
if (GConfig->GetInt(TEXT("SlateRenderer"), TEXT("FontAtlasSize"), OutAtlasSize, InConfigFilename))
|
|
{
|
|
UE_LOG(LogCore, Warning, TEXT("The 'FontAtlasSize' setting for 'SlateRenderer' is deprecated. Use '%s' instead."), InConfigKey);
|
|
}
|
|
}
|
|
OutAtlasSize = FMath::Clamp(OutAtlasSize, 128, 2048);
|
|
};
|
|
|
|
GrayscaleAtlasSize = GIsEditor ? 2048 : 1024;
|
|
ColorAtlasSize = 512;
|
|
{
|
|
const FString& ConfigFilename = GIsEditor ? GEditorIni : GEngineIni;
|
|
GetAtlasSizeFromConfig(TEXT("GrayscaleFontAtlasSize"), ConfigFilename, GrayscaleAtlasSize);
|
|
GetAtlasSizeFromConfig(TEXT("ColorFontAtlasSize"), ConfigFilename, ColorAtlasSize);
|
|
}
|
|
}
|
|
|
|
virtual ~FSlateRHIFontAtlasFactory()
|
|
{
|
|
}
|
|
|
|
virtual FIntPoint GetAtlasSize(const bool InIsGrayscale) const override
|
|
{
|
|
return InIsGrayscale
|
|
? FIntPoint(GrayscaleAtlasSize, GrayscaleAtlasSize)
|
|
: FIntPoint(ColorAtlasSize, ColorAtlasSize);
|
|
}
|
|
|
|
virtual TSharedRef<FSlateFontAtlas> CreateFontAtlas(const bool InIsGrayscale) const override
|
|
{
|
|
const FIntPoint AtlasSize = GetAtlasSize(InIsGrayscale);
|
|
return MakeShareable(new FSlateFontAtlasRHI(AtlasSize.X, AtlasSize.Y, InIsGrayscale));
|
|
}
|
|
|
|
virtual TSharedPtr<ISlateFontTexture> CreateNonAtlasedTexture(const uint32 InWidth, const uint32 InHeight, const bool InIsGrayscale, const TArray<uint8>& InRawData) const override
|
|
{
|
|
if (GIsEditor)
|
|
{
|
|
const FIntPoint AtlasSize = GetAtlasSize(InIsGrayscale);
|
|
const uint32 MaxFontTextureDimension = FMath::Min(AtlasSize.Y * 4u, GetMax2DTextureDimension()); // Don't allow textures greater than 4x our atlas size, but still honor the platform limit
|
|
if (InWidth <= MaxFontTextureDimension && InHeight <= MaxFontTextureDimension)
|
|
{
|
|
return MakeShareable(new FSlateFontTextureRHI(InWidth, InHeight, InIsGrayscale, InRawData));
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
private:
|
|
/** Size of each font texture, width and height */
|
|
int32 GrayscaleAtlasSize;
|
|
int32 ColorAtlasSize;
|
|
};
|
|
|
|
|
|
/**
|
|
* Implements the Slate RHI Renderer module.
|
|
*/
|
|
class FSlateRHIRendererModule
|
|
: public ISlateRHIRendererModule
|
|
{
|
|
public:
|
|
|
|
// ISlateRHIRendererModule interface
|
|
virtual TSharedRef<FSlateRenderer> CreateSlateRHIRenderer( ) override
|
|
{
|
|
ConditionalCreateResources();
|
|
|
|
return MakeShareable( new FSlateRHIRenderer( SlateFontServices.ToSharedRef(), ResourceManager.ToSharedRef() ) );
|
|
}
|
|
|
|
virtual TSharedRef<ISlate3DRenderer, ESPMode::ThreadSafe> CreateSlate3DRenderer(bool bUseGammaCorrection) override
|
|
{
|
|
ConditionalCreateResources();
|
|
|
|
return MakeShareable(new FSlate3DRenderer(SlateFontServices.ToSharedRef(), ResourceManager.ToSharedRef(), bUseGammaCorrection), [=] (FSlate3DRenderer* Renderer) {
|
|
Renderer->Cleanup();
|
|
});
|
|
}
|
|
|
|
virtual TSharedRef<ISlateFontAtlasFactory> CreateSlateFontAtlasFactory() override
|
|
{
|
|
return MakeShareable(new FSlateRHIFontAtlasFactory);
|
|
}
|
|
|
|
virtual TSharedRef<ISlateUpdatableInstanceBuffer> CreateInstanceBuffer( int32 InitialInstanceCount ) override
|
|
{
|
|
return MakeShareable( new FSlateUpdatableInstanceBuffer(InitialInstanceCount) );
|
|
}
|
|
|
|
virtual void StartupModule( ) override { }
|
|
virtual void ShutdownModule( ) override { }
|
|
|
|
private:
|
|
/** Creates resource managers if they do not exist */
|
|
void ConditionalCreateResources()
|
|
{
|
|
if( !ResourceManager.IsValid() )
|
|
{
|
|
ResourceManager = MakeShareable( new FSlateRHIResourceManager );
|
|
}
|
|
|
|
if( !SlateFontServices.IsValid() )
|
|
{
|
|
const TSharedRef<FSlateFontCache> GameThreadFontCache = MakeShareable(new FSlateFontCache(MakeShareable(new FSlateRHIFontAtlasFactory), ESlateTextureAtlasThreadId::Game));
|
|
const TSharedRef<FSlateFontCache> RenderThreadFontCache = MakeShareable(new FSlateFontCache(MakeShareable(new FSlateRHIFontAtlasFactory), ESlateTextureAtlasThreadId::Render));
|
|
|
|
SlateFontServices = MakeShareable(new FSlateFontServices(GameThreadFontCache, RenderThreadFontCache));
|
|
}
|
|
}
|
|
private:
|
|
/** Resource manager used for all renderers */
|
|
TSharedPtr<FSlateRHIResourceManager> ResourceManager;
|
|
|
|
/** Font services used for all renderers */
|
|
TSharedPtr<FSlateFontServices> SlateFontServices;
|
|
};
|
|
|
|
|
|
IMPLEMENT_MODULE( FSlateRHIRendererModule, SlateRHIRenderer )
|