mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-13 05:41:10 +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();
|
||||
mFrameMemory.Clear();
|
||||
FrameDeleteList.Buffers.clear();
|
||||
FrameDeleteList.Images.clear();
|
||||
|
||||
if (mCanvas)
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
struct DeleteList
|
||||
{
|
||||
std::vector<std::vector<uint32_t>> Buffers;
|
||||
std::vector<std::unique_ptr<DCanvas>> Images;
|
||||
} FrameDeleteList;
|
||||
|
||||
private:
|
||||
|
|
|
@ -34,11 +34,15 @@ void PolyHardwareTexture::ResetAll()
|
|||
|
||||
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)
|
||||
{
|
||||
#if 0
|
||||
int numLayers = mat->GetLayers();
|
||||
GetImage(mat->tex, translation, flags);
|
||||
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));
|
||||
systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DCanvas *PolyHardwareTexture::GetImage(const FMaterialState &state)
|
||||
{
|
||||
FTexture *tex = state.mMaterial->tex;
|
||||
if (tex->isHardwareCanvas()) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
|
||||
|
||||
if (!mCanvas)
|
||||
{
|
||||
FMaterial *mat = state.mMaterial;
|
||||
FTexture *tex = state.mMaterial->tex;
|
||||
int clampmode = state.mClampMode;
|
||||
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.
|
||||
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();
|
||||
|
||||
CreateImage(tex, translation, flags);
|
||||
return GetImage(tex, translation, flags);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!mCanvas || mCanvas->GetWidth() != w || mCanvas->GetHeight() != h)
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
void Precache(FMaterial *mat, int translation, int flags);
|
||||
|
||||
DCanvas *GetImage(const FMaterialState &state);
|
||||
DCanvas *GetImage(FTexture *tex, int translation, int flags);
|
||||
|
||||
// Software renderer stuff
|
||||
void AllocateBuffer(int w, int h, int texelsize) override;
|
||||
|
|
|
@ -166,8 +166,6 @@ void PolyRenderState::Apply()
|
|||
drawcalls.Clock();
|
||||
auto fb = GetPolyFrameBuffer();
|
||||
|
||||
PolyPushConstants constants;
|
||||
|
||||
int fogset = 0;
|
||||
if (mFogEnabled)
|
||||
{
|
||||
|
@ -185,12 +183,16 @@ void PolyRenderState::Apply()
|
|||
}
|
||||
}
|
||||
|
||||
int tempTM = TM_NORMAL;
|
||||
if (mMaterial.mMaterial && mMaterial.mMaterial->tex && mMaterial.mMaterial->tex->isHardwareCanvas())
|
||||
tempTM = TM_OPAQUE;
|
||||
ApplyMaterial();
|
||||
|
||||
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.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.uLightFactor = mLightParms[1];
|
||||
constants.uFogDensity = mLightParms[2];
|
||||
|
@ -199,13 +201,8 @@ void PolyRenderState::Apply()
|
|||
constants.uClipSplit = { mClipSplit[0], mClipSplit[1] };
|
||||
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);
|
||||
ApplyMatrices();
|
||||
ApplyMaterial();
|
||||
|
||||
if (mBias.mChanged)
|
||||
{
|
||||
|
@ -220,6 +217,8 @@ void PolyRenderState::ApplyMaterial()
|
|||
{
|
||||
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));
|
||||
if (base)
|
||||
{
|
||||
|
|
|
@ -62,4 +62,5 @@ private:
|
|||
std::vector<std::unique_ptr<PolyVertexInputAssembly>> mVertexFormats;
|
||||
|
||||
bool mDepthClamp = true;
|
||||
int mTempTM = TM_NORMAL;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue