mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Read-from-memory fixes, render target improvements
This commit is contained in:
parent
818ca48759
commit
60988fda8f
13 changed files with 87 additions and 17 deletions
|
@ -13,6 +13,8 @@ namespace Beefy.gfx
|
||||||
#if !STUDIO_CLIENT
|
#if !STUDIO_CLIENT
|
||||||
public class DrawLayer
|
public class DrawLayer
|
||||||
{
|
{
|
||||||
|
public static List<DrawLayer> sDrawLayers = new .() ~ delete _;
|
||||||
|
|
||||||
[CallingConvention(.Stdcall), CLink]
|
[CallingConvention(.Stdcall), CLink]
|
||||||
static extern void* DrawLayer_Create(void* window);
|
static extern void* DrawLayer_Create(void* window);
|
||||||
|
|
||||||
|
@ -33,10 +35,12 @@ namespace Beefy.gfx
|
||||||
public this(BFWindow window)
|
public this(BFWindow window)
|
||||||
{
|
{
|
||||||
mNativeDrawLayer = DrawLayer_Create((window != null) ? (window.mNativeWindow) : null);
|
mNativeDrawLayer = DrawLayer_Create((window != null) ? (window.mNativeWindow) : null);
|
||||||
|
sDrawLayers.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
{
|
{
|
||||||
|
sDrawLayers.Remove(this);
|
||||||
DrawLayer_Delete(mNativeDrawLayer);
|
DrawLayer_Delete(mNativeDrawLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Beefy.geom;
|
||||||
using Beefy.utils;
|
using Beefy.utils;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using res;
|
||||||
|
|
||||||
namespace Beefy.gfx
|
namespace Beefy.gfx
|
||||||
{
|
{
|
||||||
|
@ -515,6 +516,14 @@ namespace Beefy.gfx
|
||||||
|
|
||||||
void GetFontPath(StringView fontName, String path)
|
void GetFontPath(StringView fontName, String path)
|
||||||
{
|
{
|
||||||
|
if (fontName.StartsWith('['))
|
||||||
|
{
|
||||||
|
path.Set(fontName);
|
||||||
|
if (FilePackManager.TryMakeMemoryString(path))
|
||||||
|
return;
|
||||||
|
path.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
if (fontName.Contains('.'))
|
if (fontName.Contains('.'))
|
||||||
{
|
{
|
||||||
Path.GetAbsolutePath(fontName, BFApp.sApp.mInstallDir, path);
|
Path.GetAbsolutePath(fontName, BFApp.sApp.mInstallDir, path);
|
||||||
|
@ -1014,6 +1023,8 @@ namespace Beefy.gfx
|
||||||
}
|
}
|
||||||
|
|
||||||
CharData charData = GetCharData(c);
|
CharData charData = GetCharData(c);
|
||||||
|
if (charData == null)
|
||||||
|
continue;
|
||||||
float drawX = curX + charData.mXOffset;
|
float drawX = curX + charData.mXOffset;
|
||||||
float drawY = curY + charData.mYOffset;
|
float drawY = curY + charData.mYOffset;
|
||||||
|
|
||||||
|
|
|
@ -561,9 +561,10 @@ static class FilePackManager
|
||||||
{
|
{
|
||||||
if (TryGetMemory(path) case .Ok(let val))
|
if (TryGetMemory(path) case .Ok(let val))
|
||||||
{
|
{
|
||||||
|
String prevPath = scope .()..Append(path);
|
||||||
|
|
||||||
var ext = Path.GetExtension(path, .. scope .());
|
var ext = Path.GetExtension(path, .. scope .());
|
||||||
path.Set(scope $"@{(int)(void*)val.Ptr:X}:{val.Length}");
|
path.Set(scope $"@{(int)(void*)val.Ptr:X}:{val.Length}:{prevPath}");
|
||||||
path.Append(ext);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Beefy.theme.dark
|
||||||
public float mLabelYOfs;
|
public float mLabelYOfs;
|
||||||
|
|
||||||
[DesignEditable(DefaultEditString=true)]
|
[DesignEditable(DefaultEditString=true)]
|
||||||
public String Label
|
public StringView Label
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,6 +69,7 @@ namespace Beefy.widgets
|
||||||
public bool mWantsUpdateF;
|
public bool mWantsUpdateF;
|
||||||
public bool mTempWantsUpdateF;
|
public bool mTempWantsUpdateF;
|
||||||
|
|
||||||
|
public Image mContentRenderTarget ~ delete _;
|
||||||
public int32 mContentClientWidth;
|
public int32 mContentClientWidth;
|
||||||
public int32 mContentClientHeight;
|
public int32 mContentClientHeight;
|
||||||
|
|
||||||
|
@ -230,10 +231,30 @@ namespace Beefy.widgets
|
||||||
{
|
{
|
||||||
base.PreDraw(g);
|
base.PreDraw(g);
|
||||||
|
|
||||||
|
if (mContentRenderTarget != null)
|
||||||
|
{
|
||||||
|
g.mMatrix.Set(Matrix.IdentityMatrix);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
g.mMatrix.Set(mScaleMatrix);
|
g.mMatrix.Set(mScaleMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
g.mMatrixStack[g.mMatrixStackIdx] = g.mMatrix;
|
g.mMatrixStack[g.mMatrixStackIdx] = g.mMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void PostDraw(Graphics g)
|
||||||
|
{
|
||||||
|
base.PostDraw(g);
|
||||||
|
|
||||||
|
if (mContentRenderTarget != null)
|
||||||
|
{
|
||||||
|
for (var drawLayer in DrawLayer.sDrawLayers)
|
||||||
|
drawLayer.DrawToRenderTarget(mContentRenderTarget);
|
||||||
|
g.DrawQuad(mContentRenderTarget, 0, 0, 0, 0, mClientWidth, mClientHeight, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void RehupSize()
|
public override void RehupSize()
|
||||||
{
|
{
|
||||||
base.RehupSize();
|
base.RehupSize();
|
||||||
|
@ -880,8 +901,14 @@ namespace Beefy.widgets
|
||||||
mMouseFlags = default;
|
mMouseFlags = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetContentSize(int width, int height)
|
public void SetContentSize(int width, int height, bool createRenderTarget = false)
|
||||||
{
|
{
|
||||||
|
DeleteAndNullify!(mContentRenderTarget);
|
||||||
|
if (createRenderTarget)
|
||||||
|
{
|
||||||
|
mContentRenderTarget = Image.CreateRenderTarget((.)width, (.)height);
|
||||||
|
}
|
||||||
|
|
||||||
mContentClientWidth = (.)width;
|
mContentClientWidth = (.)width;
|
||||||
mContentClientHeight = (.)height;
|
mContentClientHeight = (.)height;
|
||||||
RehupSize();
|
RehupSize();
|
||||||
|
|
|
@ -447,6 +447,7 @@ BF_EXPORT int BF_CALLTYPE BFWindow_GetDPI(BFWindow* window)
|
||||||
BF_EXPORT TextureSegment* BF_CALLTYPE Gfx_CreateRenderTarget(int width, int height, int destAlpha)
|
BF_EXPORT TextureSegment* BF_CALLTYPE Gfx_CreateRenderTarget(int width, int height, int destAlpha)
|
||||||
{
|
{
|
||||||
Texture* texture = gBFApp->mRenderDevice->CreateRenderTarget(width, height, destAlpha != 0);
|
Texture* texture = gBFApp->mRenderDevice->CreateRenderTarget(width, height, destAlpha != 0);
|
||||||
|
texture->mResetClear = true;
|
||||||
|
|
||||||
TextureSegment* aTextureSegment = new TextureSegment();
|
TextureSegment* aTextureSegment = new TextureSegment();
|
||||||
aTextureSegment->InitFromTexture(texture);
|
aTextureSegment->InitFromTexture(texture);
|
||||||
|
|
|
@ -1380,9 +1380,11 @@ void Beefy::BFFatalError(const char* message, const char* file, int line)
|
||||||
BFFatalError(String(message), String(file), line);
|
BFFatalError(String(message), String(file), line);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize)
|
bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize, StringImpl* outKey)
|
||||||
{
|
{
|
||||||
#ifndef BF_SMALL
|
#ifndef BF_SMALL
|
||||||
|
static int anonymousIdx = 0;
|
||||||
|
|
||||||
if (str.StartsWith("@"))
|
if (str.StartsWith("@"))
|
||||||
{
|
{
|
||||||
int colon = (int)str.IndexOf(':');
|
int colon = (int)str.IndexOf(':');
|
||||||
|
@ -1390,6 +1392,21 @@ bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize)
|
||||||
String lenStr = str.Substring(colon + 1);
|
String lenStr = str.Substring(colon + 1);
|
||||||
outPtr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16);
|
outPtr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16);
|
||||||
outSize = (int)strtol(lenStr.c_str(), NULL, 10);
|
outSize = (int)strtol(lenStr.c_str(), NULL, 10);
|
||||||
|
|
||||||
|
if (outKey != NULL)
|
||||||
|
{
|
||||||
|
int nextColon = (int)str.IndexOf(':', colon + 1);
|
||||||
|
if (nextColon > 0)
|
||||||
|
{
|
||||||
|
*outKey = str.Substring(nextColon + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int dotPos = (int)str.IndexOf('.', colon + 1);
|
||||||
|
*outKey = StrFormat("ANON_%d", anonymousIdx++) + str.Substring(dotPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -242,7 +242,7 @@ bool FileExists(const StringImpl& path, String* outActualName = NULL);
|
||||||
bool DirectoryExists(const StringImpl& path, String* outActualName = NULL);
|
bool DirectoryExists(const StringImpl& path, String* outActualName = NULL);
|
||||||
bool RecursiveCreateDirectory(const StringImpl& dirName);
|
bool RecursiveCreateDirectory(const StringImpl& dirName);
|
||||||
bool RecursiveDeleteDirectory(const StringImpl& dirName);
|
bool RecursiveDeleteDirectory(const StringImpl& dirName);
|
||||||
bool ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize);
|
bool ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize, StringImpl* outKey = NULL);
|
||||||
|
|
||||||
#define CHARTAG(val) FromBIGEndian(val)
|
#define CHARTAG(val) FromBIGEndian(val)
|
||||||
|
|
||||||
|
|
|
@ -136,13 +136,18 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
|
||||||
|
|
||||||
FTFontManager::Face* face = NULL;
|
FTFontManager::Face* face = NULL;
|
||||||
|
|
||||||
|
String key = fileName;
|
||||||
|
void* memPtr = NULL;
|
||||||
|
int memLen = 0;
|
||||||
|
bool isMemory = ParseMemorySpan(fileName, memPtr, memLen, &key);
|
||||||
|
|
||||||
FTFontManager::Face** facePtr = NULL;
|
FTFontManager::Face** facePtr = NULL;
|
||||||
if (gFTFontManager.mFaces.TryAdd(fileName, NULL, &facePtr))
|
if (gFTFontManager.mFaces.TryAdd(key, NULL, &facePtr))
|
||||||
{
|
{
|
||||||
face = new FTFontManager::Face();
|
face = new FTFontManager::Face();
|
||||||
*facePtr = face;
|
*facePtr = face;
|
||||||
|
|
||||||
face->mFileName = fileName;
|
face->mFileName = key;
|
||||||
FT_Face ftFace = NULL;
|
FT_Face ftFace = NULL;
|
||||||
|
|
||||||
String useFileName = fileName;
|
String useFileName = fileName;
|
||||||
|
@ -154,9 +159,7 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
|
||||||
useFileName.RemoveToEnd(atPos);
|
useFileName.RemoveToEnd(atPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* memPtr = NULL;
|
if (isMemory)
|
||||||
int memLen = 0;
|
|
||||||
if (ParseMemorySpan(fileName, memPtr, memLen))
|
|
||||||
{
|
{
|
||||||
FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace);
|
FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ RenderTarget::RenderTarget()
|
||||||
mHasBeenDrawnTo = false;
|
mHasBeenDrawnTo = false;
|
||||||
mHasBeenTargeted = false;
|
mHasBeenTargeted = false;
|
||||||
mResizeNum = 0;
|
mResizeNum = 0;
|
||||||
|
mWantsClear = true;
|
||||||
|
mResetClear = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderWindow::RenderWindow()
|
RenderWindow::RenderWindow()
|
||||||
|
|
|
@ -12,6 +12,8 @@ public:
|
||||||
int mResizeNum;
|
int mResizeNum;
|
||||||
bool mHasBeenTargeted;
|
bool mHasBeenTargeted;
|
||||||
bool mHasBeenDrawnTo;
|
bool mHasBeenDrawnTo;
|
||||||
|
bool mWantsClear;
|
||||||
|
bool mResetClear;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderTarget();
|
RenderTarget();
|
||||||
|
|
|
@ -648,7 +648,7 @@ void DXTexture::PhysSetAsTarget()
|
||||||
mRenderDevice->mD3DDeviceContext->RSSetViewports(1, &viewPort);
|
mRenderDevice->mD3DDeviceContext->RSSetViewports(1, &viewPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!mHasBeenDrawnTo)
|
if (mWantsClear)
|
||||||
{
|
{
|
||||||
float bgColor[4] = {1, (rand() % 256) / 256.0f, 0.5, 1};
|
float bgColor[4] = {1, (rand() % 256) / 256.0f, 0.5, 1};
|
||||||
mRenderDevice->mD3DDeviceContext->ClearRenderTargetView(mD3DRenderTargetView, bgColor);
|
mRenderDevice->mD3DDeviceContext->ClearRenderTargetView(mD3DRenderTargetView, bgColor);
|
||||||
|
@ -657,6 +657,8 @@ void DXTexture::PhysSetAsTarget()
|
||||||
|
|
||||||
//mRenderDevice->mD3DDevice->ClearRenderTargetView(mD3DRenderTargetView, D3DXVECTOR4(1, 0.5, 0.5, 1));
|
//mRenderDevice->mD3DDevice->ClearRenderTargetView(mD3DRenderTargetView, D3DXVECTOR4(1, 0.5, 0.5, 1));
|
||||||
mHasBeenDrawnTo = true;
|
mHasBeenDrawnTo = true;
|
||||||
|
if (mResetClear)
|
||||||
|
mWantsClear = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue