mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- moved several members from FTexture to FGameTexture.
This commit is contained in:
parent
42304d9680
commit
7641da8b7b
7 changed files with 59 additions and 46 deletions
|
@ -126,7 +126,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
||||||
mScaleFlags = scaleflags;
|
mScaleFlags = scaleflags;
|
||||||
|
|
||||||
mTextureLayers.ShrinkToFit();
|
mTextureLayers.ShrinkToFit();
|
||||||
imgtex->Material[scaleflags] = this;
|
tx->Material[scaleflags] = this;
|
||||||
if (tx->isHardwareCanvas()) tx->SetTranslucent(false);
|
if (tx->isHardwareCanvas()) tx->SetTranslucent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,10 +167,9 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool
|
||||||
{
|
{
|
||||||
if (gtex && gtex->isValid())
|
if (gtex && gtex->isValid())
|
||||||
{
|
{
|
||||||
auto tex = gtex->GetTexture();
|
|
||||||
if (!gtex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand;
|
if (!gtex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand;
|
||||||
|
|
||||||
FMaterial *hwtex = tex->Material[scaleflags];
|
FMaterial *hwtex = gtex->Material[scaleflags];
|
||||||
if (hwtex == NULL && create)
|
if (hwtex == NULL && create)
|
||||||
{
|
{
|
||||||
hwtex = new FMaterial(gtex, scaleflags);
|
hwtex = new FMaterial(gtex, scaleflags);
|
||||||
|
|
|
@ -152,17 +152,6 @@ FTexture::~FTexture ()
|
||||||
{
|
{
|
||||||
if (areas != nullptr) delete[] areas;
|
if (areas != nullptr) delete[] areas;
|
||||||
areas = nullptr;
|
areas = nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
if (Material[i] != nullptr) DeleteMaterial(Material[i]);
|
|
||||||
Material[i] = nullptr;
|
|
||||||
}
|
|
||||||
if (SoftwareTexture != nullptr)
|
|
||||||
{
|
|
||||||
delete SoftwareTexture;
|
|
||||||
SoftwareTexture = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
@ -861,10 +850,10 @@ void FGameTexture::SetupSpriteData()
|
||||||
{
|
{
|
||||||
// Since this is only needed for real sprites it gets allocated on demand.
|
// Since this is only needed for real sprites it gets allocated on demand.
|
||||||
// It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance.
|
// It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance.
|
||||||
if (Base->spi == nullptr) Base->spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo));
|
if (spi == nullptr) spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo));
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
auto& spi = Base->spi[i];
|
auto& spi = this->spi[i];
|
||||||
spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f;
|
spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f;
|
||||||
spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f;
|
spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f;
|
||||||
spi.spriteWidth = GetTexelWidth();
|
spi.spriteWidth = GetTexelWidth();
|
||||||
|
@ -889,7 +878,7 @@ void FGameTexture::SetupSpriteData()
|
||||||
void FGameTexture::SetSpriteRect()
|
void FGameTexture::SetSpriteRect()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!Base->spi) return;
|
if (!spi) return;
|
||||||
auto leftOffset = GetLeftOffsetHW();
|
auto leftOffset = GetLeftOffsetHW();
|
||||||
auto topOffset = GetTopOffsetHW();
|
auto topOffset = GetTopOffsetHW();
|
||||||
|
|
||||||
|
@ -898,7 +887,7 @@ void FGameTexture::SetSpriteRect()
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
auto& spi = Base->spi[i];
|
auto& spi = this->spi[i];
|
||||||
|
|
||||||
// mSpriteRect is for positioning the sprite in the scene.
|
// mSpriteRect is for positioning the sprite in the scene.
|
||||||
spi.mSpriteRect.left = -leftOffset / fxScale;
|
spi.mSpriteRect.left = -leftOffset / fxScale;
|
||||||
|
@ -1087,8 +1076,17 @@ FGameTexture::~FGameTexture()
|
||||||
{
|
{
|
||||||
FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump());
|
FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump());
|
||||||
if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr);
|
if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr);
|
||||||
auto str = GetName();
|
if (SoftwareTexture != nullptr)
|
||||||
Printf("Deleting texture %s\n", str.GetChars());
|
{
|
||||||
|
delete SoftwareTexture;
|
||||||
|
SoftwareTexture = nullptr;
|
||||||
|
}
|
||||||
|
for (auto &mat : Material)
|
||||||
|
{
|
||||||
|
if (mat != nullptr) DeleteMaterial(mat);
|
||||||
|
mat = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGameTexture::isUserContent() const
|
bool FGameTexture::isUserContent() const
|
||||||
|
|
|
@ -119,8 +119,8 @@ void FTextureManager::FlushAll()
|
||||||
for (int j = 0; j < 2; j++)
|
for (int j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
Textures[i].Texture->GetTexture()->CleanHardwareTextures(true);
|
Textures[i].Texture->GetTexture()->CleanHardwareTextures(true);
|
||||||
delete Textures[i].Texture->GetTexture()->SoftwareTexture;
|
delete Textures[i].Texture->GetSoftwareTexture();
|
||||||
Textures[i].Texture->GetTexture()->SoftwareTexture = nullptr;
|
Textures[i].Texture->SetSoftwareTexture(nullptr);
|
||||||
calcShouldUpscale(Textures[i].Texture);
|
calcShouldUpscale(Textures[i].Texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,8 +248,6 @@ class FTexture : public RefCountedBase
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SpritePositioningInfo *spi = nullptr;
|
|
||||||
|
|
||||||
IHardwareTexture* GetHardwareTexture(int translation, int scaleflags);
|
IHardwareTexture* GetHardwareTexture(int translation, int scaleflags);
|
||||||
static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType UseType);
|
static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType UseType);
|
||||||
virtual ~FTexture ();
|
virtual ~FTexture ();
|
||||||
|
@ -335,16 +333,6 @@ public:
|
||||||
static bool SmoothEdges(unsigned char * buffer,int w, int h);
|
static bool SmoothEdges(unsigned char * buffer,int w, int h);
|
||||||
static PalEntry averageColor(const uint32_t *data, int size, int maxout);
|
static PalEntry averageColor(const uint32_t *data, int size, int maxout);
|
||||||
|
|
||||||
|
|
||||||
ISoftwareTexture* GetSoftwareTexture()
|
|
||||||
{
|
|
||||||
return SoftwareTexture;
|
|
||||||
}
|
|
||||||
void SetSoftwareTextue(ISoftwareTexture* swtex)
|
|
||||||
{
|
|
||||||
SoftwareTexture = swtex;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
DVector2 Scale;
|
DVector2 Scale;
|
||||||
|
@ -352,11 +340,9 @@ protected:
|
||||||
int SourceLump;
|
int SourceLump;
|
||||||
FTextureID id;
|
FTextureID id;
|
||||||
|
|
||||||
FMaterial *Material[4] = { };
|
|
||||||
public:
|
public:
|
||||||
FHardwareTextureContainer SystemTextures;
|
FHardwareTextureContainer SystemTextures;
|
||||||
protected:
|
protected:
|
||||||
ISoftwareTexture *SoftwareTexture = nullptr;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -440,10 +426,6 @@ public:
|
||||||
{
|
{
|
||||||
return bTranslucent != -1 ? bTranslucent : DetermineTranslucency();
|
return bTranslucent != -1 ? bTranslucent : DetermineTranslucency();
|
||||||
}
|
}
|
||||||
FMaterial* GetMaterial(int num)
|
|
||||||
{
|
|
||||||
return Material[num];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int CheckDDPK3();
|
int CheckDDPK3();
|
||||||
|
@ -610,7 +592,7 @@ class FGameTexture
|
||||||
{
|
{
|
||||||
friend class FMaterial;
|
friend class FMaterial;
|
||||||
|
|
||||||
// Material layers
|
// Material layers. These are shared so reference counting is used.
|
||||||
RefCountedPtr<FTexture> Base;
|
RefCountedPtr<FTexture> Base;
|
||||||
RefCountedPtr<FTexture> Brightmap;
|
RefCountedPtr<FTexture> Brightmap;
|
||||||
RefCountedPtr<FTexture> Detailmap;
|
RefCountedPtr<FTexture> Detailmap;
|
||||||
|
@ -624,6 +606,10 @@ class FGameTexture
|
||||||
|
|
||||||
int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture.
|
int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture.
|
||||||
ETextureType UseType = ETextureType::Wall; // This texture's primary purpose
|
ETextureType UseType = ETextureType::Wall; // This texture's primary purpose
|
||||||
|
SpritePositioningInfo* spi = nullptr;
|
||||||
|
|
||||||
|
ISoftwareTexture* SoftwareTexture = nullptr;
|
||||||
|
FMaterial* Material[4] = { };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FGameTexture(FTexture* wrap) : Base(wrap) {}
|
FGameTexture(FTexture* wrap) : Base(wrap) {}
|
||||||
|
@ -679,9 +665,22 @@ public:
|
||||||
void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); }
|
void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); }
|
||||||
int GetSkyOffset() const { return Base->GetSkyOffset(); }
|
int GetSkyOffset() const { return Base->GetSkyOffset(); }
|
||||||
FTextureID GetID() const { return Base->GetID(); }
|
FTextureID GetID() const { return Base->GetID(); }
|
||||||
ISoftwareTexture* GetSoftwareTexture() { return Base->GetSoftwareTexture(); }
|
|
||||||
void SetSoftwareTexture(ISoftwareTexture* swtex) { Base->SetSoftwareTextue(swtex); }
|
|
||||||
void SetScale(DVector2 vec) { Base->SetScale(vec); }
|
void SetScale(DVector2 vec) { Base->SetScale(vec); }
|
||||||
|
|
||||||
|
ISoftwareTexture* GetSoftwareTexture()
|
||||||
|
{
|
||||||
|
return SoftwareTexture;
|
||||||
|
}
|
||||||
|
void SetSoftwareTexture(ISoftwareTexture* swtex)
|
||||||
|
{
|
||||||
|
SoftwareTexture = swtex;
|
||||||
|
}
|
||||||
|
|
||||||
|
FMaterial* GetMaterial(int num)
|
||||||
|
{
|
||||||
|
return Material[num];
|
||||||
|
}
|
||||||
|
|
||||||
const FString& GetName() const { return Base->GetName(); }
|
const FString& GetName() const { return Base->GetName(); }
|
||||||
void SetShaderSpeed(float speed) { Base->shaderspeed = speed; }
|
void SetShaderSpeed(float speed) { Base->shaderspeed = speed; }
|
||||||
void SetShaderIndex(int index) { Base->shaderindex = index; }
|
void SetShaderIndex(int index) { Base->shaderindex = index; }
|
||||||
|
@ -726,7 +725,7 @@ public:
|
||||||
void SetSize(int x, int y) { Base->SetSize(x, y); }
|
void SetSize(int x, int y) { Base->SetSize(x, y); }
|
||||||
void SetDisplaySize(float w, float h) { Base->SetSize((int)w, (int)h); }
|
void SetDisplaySize(float w, float h) { Base->SetSize((int)w, (int)h); }
|
||||||
|
|
||||||
const SpritePositioningInfo& GetSpritePositioning(int which) { if (Base->spi == nullptr) SetupSpriteData(); return Base->spi[which]; }
|
const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; }
|
||||||
int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); }
|
int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); }
|
||||||
PalEntry GetSkyCapColor(bool bottom) { return Base->GetSkyCapColor(bottom); }
|
PalEntry GetSkyCapColor(bool bottom) { return Base->GetSkyCapColor(bottom); }
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,8 @@ void FSoftwareRenderer::SetClearColor(int color)
|
||||||
mScene.SetClearColor(color);
|
mScene.SetClearColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FSWCanvasTexture* GetSWCamTex(FCanvasTexture* camtex);
|
||||||
|
|
||||||
void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewpoint, double fov)
|
void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewpoint, double fov)
|
||||||
{
|
{
|
||||||
auto renderTarget = mScene.MainThread()->Viewport->RenderTarget;
|
auto renderTarget = mScene.MainThread()->Viewport->RenderTarget;
|
||||||
|
@ -237,7 +239,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewp
|
||||||
cameraViewpoint = r_viewpoint;
|
cameraViewpoint = r_viewpoint;
|
||||||
cameraViewwindow = r_viewwindow;
|
cameraViewwindow = r_viewwindow;
|
||||||
|
|
||||||
auto tex = static_cast<FSWCanvasTexture*>(camtex->GetSoftwareTexture());
|
auto tex = GetSWCamTex(camtex);
|
||||||
|
|
||||||
DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();
|
DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ class FSWCanvasTexture : public FSoftwareTexture
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FSWCanvasTexture(FGameTexture *source) : FSoftwareTexture(source) {}
|
FSWCanvasTexture(FGameTexture* source);
|
||||||
~FSWCanvasTexture();
|
~FSWCanvasTexture();
|
||||||
|
|
||||||
// Returns the whole texture, stored in column-major order
|
// Returns the whole texture, stored in column-major order
|
||||||
|
|
|
@ -39,6 +39,21 @@
|
||||||
#include "m_alloc.h"
|
#include "m_alloc.h"
|
||||||
#include "imagehelpers.h"
|
#include "imagehelpers.h"
|
||||||
|
|
||||||
|
static TMap<FCanvasTexture*, FSWCanvasTexture*> canvasMap;
|
||||||
|
|
||||||
|
FSWCanvasTexture* GetSWCamTex(FCanvasTexture* camtex)
|
||||||
|
{
|
||||||
|
auto p = canvasMap.CheckKey(camtex);
|
||||||
|
return p ? *p : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSWCanvasTexture::FSWCanvasTexture(FGameTexture* source) : FSoftwareTexture(source)
|
||||||
|
{
|
||||||
|
// The SW renderer needs to link the canvas textures, but let's do that outside the texture manager.
|
||||||
|
auto camtex = static_cast<FCanvasTexture*>(source->GetTexture());
|
||||||
|
canvasMap.Insert(camtex, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FSWCanvasTexture::~FSWCanvasTexture()
|
FSWCanvasTexture::~FSWCanvasTexture()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue