mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-06 01:11:11 +00:00
- fix use after delete of some textures
This commit is contained in:
parent
c2535519e8
commit
b6e00cb208
6 changed files with 30 additions and 17 deletions
|
@ -140,6 +140,7 @@ void PolyFrameBuffer::Update()
|
||||||
DrawerThreads::WaitForWorkers();
|
DrawerThreads::WaitForWorkers();
|
||||||
mFrameMemory.Clear();
|
mFrameMemory.Clear();
|
||||||
FrameDeleteList.Buffers.clear();
|
FrameDeleteList.Buffers.clear();
|
||||||
|
FrameDeleteList.Images.clear();
|
||||||
|
|
||||||
if (mCanvas)
|
if (mCanvas)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
struct DeleteList
|
struct DeleteList
|
||||||
{
|
{
|
||||||
std::vector<std::vector<uint32_t>> Buffers;
|
std::vector<std::vector<uint32_t>> Buffers;
|
||||||
|
std::vector<std::unique_ptr<DCanvas>> Images;
|
||||||
} FrameDeleteList;
|
} FrameDeleteList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,11 +34,15 @@ void PolyHardwareTexture::ResetAll()
|
||||||
|
|
||||||
void PolyHardwareTexture::Reset()
|
void PolyHardwareTexture::Reset()
|
||||||
{
|
{
|
||||||
|
if (auto fb = GetPolyFrameBuffer())
|
||||||
|
{
|
||||||
|
auto &deleteList = fb->FrameDeleteList;
|
||||||
|
if (mCanvas) deleteList.Images.push_back(std::move(mCanvas));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolyHardwareTexture::Precache(FMaterial *mat, int translation, int flags)
|
void PolyHardwareTexture::Precache(FMaterial *mat, int translation, int flags)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
int numLayers = mat->GetLayers();
|
int numLayers = mat->GetLayers();
|
||||||
GetImage(mat->tex, translation, flags);
|
GetImage(mat->tex, translation, flags);
|
||||||
for (int i = 1; i < numLayers; i++)
|
for (int i = 1; i < numLayers; i++)
|
||||||
|
@ -47,15 +51,16 @@ void PolyHardwareTexture::Precache(FMaterial *mat, int translation, int flags)
|
||||||
auto systex = static_cast<PolyHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
auto systex = static_cast<PolyHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
||||||
systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0);
|
systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DCanvas *PolyHardwareTexture::GetImage(const FMaterialState &state)
|
DCanvas *PolyHardwareTexture::GetImage(const FMaterialState &state)
|
||||||
{
|
{
|
||||||
|
FTexture *tex = state.mMaterial->tex;
|
||||||
|
if (tex->isHardwareCanvas()) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
|
||||||
|
|
||||||
if (!mCanvas)
|
if (!mCanvas)
|
||||||
{
|
{
|
||||||
FMaterial *mat = state.mMaterial;
|
FMaterial *mat = state.mMaterial;
|
||||||
FTexture *tex = state.mMaterial->tex;
|
|
||||||
int clampmode = state.mClampMode;
|
int clampmode = state.mClampMode;
|
||||||
int translation = state.mTranslation;
|
int translation = state.mTranslation;
|
||||||
|
|
||||||
|
@ -66,14 +71,19 @@ DCanvas *PolyHardwareTexture::GetImage(const FMaterialState &state)
|
||||||
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
|
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
|
||||||
int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0;
|
int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0;
|
||||||
|
|
||||||
if (tex->isHardwareCanvas()) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
|
return GetImage(tex, translation, flags);
|
||||||
|
|
||||||
CreateImage(tex, translation, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mCanvas.get();
|
return mCanvas.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DCanvas *PolyHardwareTexture::GetImage(FTexture *tex, int translation, int flags)
|
||||||
|
{
|
||||||
|
if (!mCanvas)
|
||||||
|
CreateImage(tex, translation, flags);
|
||||||
|
return mCanvas.get();
|
||||||
|
}
|
||||||
|
|
||||||
void PolyHardwareTexture::AllocateBuffer(int w, int h, int texelsize)
|
void PolyHardwareTexture::AllocateBuffer(int w, int h, int texelsize)
|
||||||
{
|
{
|
||||||
if (!mCanvas || mCanvas->GetWidth() != w || mCanvas->GetHeight() != h)
|
if (!mCanvas || mCanvas->GetWidth() != w || mCanvas->GetHeight() != h)
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
void Precache(FMaterial *mat, int translation, int flags);
|
void Precache(FMaterial *mat, int translation, int flags);
|
||||||
|
|
||||||
DCanvas *GetImage(const FMaterialState &state);
|
DCanvas *GetImage(const FMaterialState &state);
|
||||||
|
DCanvas *GetImage(FTexture *tex, int translation, int flags);
|
||||||
|
|
||||||
// Software renderer stuff
|
// Software renderer stuff
|
||||||
void AllocateBuffer(int w, int h, int texelsize) override;
|
void AllocateBuffer(int w, int h, int texelsize) override;
|
||||||
|
|
|
@ -166,8 +166,6 @@ void PolyRenderState::Apply()
|
||||||
drawcalls.Clock();
|
drawcalls.Clock();
|
||||||
auto fb = GetPolyFrameBuffer();
|
auto fb = GetPolyFrameBuffer();
|
||||||
|
|
||||||
PolyPushConstants constants;
|
|
||||||
|
|
||||||
int fogset = 0;
|
int fogset = 0;
|
||||||
if (mFogEnabled)
|
if (mFogEnabled)
|
||||||
{
|
{
|
||||||
|
@ -185,12 +183,16 @@ void PolyRenderState::Apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tempTM = TM_NORMAL;
|
ApplyMaterial();
|
||||||
if (mMaterial.mMaterial && mMaterial.mMaterial->tex && mMaterial.mMaterial->tex->isHardwareCanvas())
|
|
||||||
tempTM = TM_OPAQUE;
|
|
||||||
|
|
||||||
|
if (mVertexBuffer) PolyTriangleDrawer::SetVertexBuffer(fb->GetDrawCommands(), mVertexBuffer->Memory());
|
||||||
|
if (mIndexBuffer) PolyTriangleDrawer::SetIndexBuffer(fb->GetDrawCommands(), mIndexBuffer->Memory());
|
||||||
|
PolyTriangleDrawer::SetInputAssembly(fb->GetDrawCommands(), static_cast<PolyVertexBuffer*>(mVertexBuffer)->VertexFormat);
|
||||||
|
PolyTriangleDrawer::SetRenderStyle(fb->GetDrawCommands(), mRenderStyle);
|
||||||
|
|
||||||
|
PolyPushConstants constants;
|
||||||
constants.uFogEnabled = fogset;
|
constants.uFogEnabled = fogset;
|
||||||
constants.uTextureMode = mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode;
|
constants.uTextureMode = mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode;
|
||||||
constants.uLightDist = mLightParms[0];
|
constants.uLightDist = mLightParms[0];
|
||||||
constants.uLightFactor = mLightParms[1];
|
constants.uLightFactor = mLightParms[1];
|
||||||
constants.uFogDensity = mLightParms[2];
|
constants.uFogDensity = mLightParms[2];
|
||||||
|
@ -199,13 +201,8 @@ void PolyRenderState::Apply()
|
||||||
constants.uClipSplit = { mClipSplit[0], mClipSplit[1] };
|
constants.uClipSplit = { mClipSplit[0], mClipSplit[1] };
|
||||||
constants.uLightIndex = mLightIndex;
|
constants.uLightIndex = mLightIndex;
|
||||||
|
|
||||||
if (mVertexBuffer) PolyTriangleDrawer::SetVertexBuffer(fb->GetDrawCommands(), mVertexBuffer->Memory());
|
|
||||||
if (mIndexBuffer) PolyTriangleDrawer::SetIndexBuffer(fb->GetDrawCommands(), mIndexBuffer->Memory());
|
|
||||||
PolyTriangleDrawer::SetInputAssembly(fb->GetDrawCommands(), static_cast<PolyVertexBuffer*>(mVertexBuffer)->VertexFormat);
|
|
||||||
PolyTriangleDrawer::SetRenderStyle(fb->GetDrawCommands(), mRenderStyle);
|
|
||||||
PolyTriangleDrawer::PushStreamData(fb->GetDrawCommands(), mStreamData, constants);
|
PolyTriangleDrawer::PushStreamData(fb->GetDrawCommands(), mStreamData, constants);
|
||||||
ApplyMatrices();
|
ApplyMatrices();
|
||||||
ApplyMaterial();
|
|
||||||
|
|
||||||
if (mBias.mChanged)
|
if (mBias.mChanged)
|
||||||
{
|
{
|
||||||
|
@ -220,6 +217,8 @@ void PolyRenderState::ApplyMaterial()
|
||||||
{
|
{
|
||||||
if (mMaterial.mChanged && mMaterial.mMaterial)
|
if (mMaterial.mChanged && mMaterial.mMaterial)
|
||||||
{
|
{
|
||||||
|
mTempTM = mMaterial.mMaterial->tex->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL;
|
||||||
|
|
||||||
auto base = static_cast<PolyHardwareTexture*>(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation));
|
auto base = static_cast<PolyHardwareTexture*>(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation));
|
||||||
if (base)
|
if (base)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,4 +62,5 @@ private:
|
||||||
std::vector<std::unique_ptr<PolyVertexInputAssembly>> mVertexFormats;
|
std::vector<std::unique_ptr<PolyVertexInputAssembly>> mVertexFormats;
|
||||||
|
|
||||||
bool mDepthClamp = true;
|
bool mDepthClamp = true;
|
||||||
|
int mTempTM = TM_NORMAL;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue