You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
This addresses a crash when trying to draw text from the render thread. The extra font cache is managed by FEngineFontServices, and its creation is delayed until it is first needed. In Canvas you now use FEngineFontServices (rather than FSlateApplication directly) which will automatically return the correct cache for the current thread. #codereview Matt.Kuhlenschmidt [CL 2350206 by Jamie Dale in Main branch]
98 lines
2.3 KiB
C++
98 lines
2.3 KiB
C++
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "SlateRHIRendererPrivatePCH.h"
|
|
#include "Slate3DRenderer.h"
|
|
|
|
class FSlateRHIFontAtlasFactory : public ISlateFontAtlasFactory
|
|
{
|
|
public:
|
|
FSlateRHIFontAtlasFactory()
|
|
{
|
|
/** Size of each font texture, width and height */
|
|
AtlasSize = 1024;
|
|
if (!GIsEditor && GConfig)
|
|
{
|
|
GConfig->GetInt(TEXT("SlateRenderer"), TEXT("FontAtlasSize"), AtlasSize, GEngineIni);
|
|
AtlasSize = FMath::Clamp(AtlasSize, 0, 2048);
|
|
}
|
|
}
|
|
|
|
virtual ~FSlateRHIFontAtlasFactory()
|
|
{
|
|
}
|
|
|
|
|
|
virtual TSharedRef<FSlateFontAtlas> CreateFontAtlas() const override
|
|
{
|
|
return MakeShareable(new FSlateFontAtlasRHI(AtlasSize, AtlasSize));
|
|
}
|
|
private:
|
|
int32 AtlasSize;
|
|
};
|
|
|
|
|
|
/**
|
|
* Implements the Slate RHI Renderer module.
|
|
*/
|
|
class FSlateRHIRendererModule
|
|
: public ISlateRHIRendererModule
|
|
{
|
|
public:
|
|
|
|
// ISlateRHIRendererModule interface
|
|
virtual TSharedRef<FSlateRenderer> CreateSlateRHIRenderer( ) override
|
|
{
|
|
ConditionalCreateResources();
|
|
|
|
return MakeShareable( new FSlateRHIRenderer( ResourceManager, FontCache, FontMeasure ) );
|
|
}
|
|
|
|
virtual TSharedRef<ISlate3DRenderer> CreateSlate3DRenderer() override
|
|
{
|
|
ConditionalCreateResources();
|
|
|
|
return MakeShareable( new FSlate3DRenderer( ResourceManager, FontCache ) );
|
|
}
|
|
|
|
virtual TSharedRef<ISlateFontAtlasFactory> CreateSlateFontAtlasFactory() override
|
|
{
|
|
return MakeShareable(new FSlateRHIFontAtlasFactory);
|
|
}
|
|
|
|
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( !FontCache.IsValid() )
|
|
{
|
|
FontCache = MakeShareable(new FSlateFontCache(MakeShareable(new FSlateRHIFontAtlasFactory)));
|
|
}
|
|
|
|
if( !FontMeasure.IsValid() )
|
|
{
|
|
FontMeasure = FSlateFontMeasure::Create(FontCache.ToSharedRef());
|
|
}
|
|
|
|
}
|
|
private:
|
|
/** Resource manager used for all renderers */
|
|
TSharedPtr<FSlateRHIResourceManager> ResourceManager;
|
|
|
|
/** Font cache used for all renderers */
|
|
TSharedPtr<FSlateFontCache> FontCache;
|
|
|
|
/** Font measure interface used for all renderers */
|
|
TSharedPtr<FSlateFontMeasure> FontMeasure;
|
|
};
|
|
|
|
|
|
IMPLEMENT_MODULE( FSlateRHIRendererModule, SlateRHIRenderer )
|