mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-30 07:41:22 +00:00
- removed the intermediate FGLTexture class.
This wasn't serving any real purpose anymore, and all its remaining functionality could be moved to FHardwareTexture
This commit is contained in:
parent
8d62ebd2f4
commit
c37ff22a05
11 changed files with 172 additions and 300 deletions
|
@ -65,7 +65,6 @@ public:
|
|||
class FSWSceneTexture : public FTexture
|
||||
{
|
||||
public:
|
||||
FHardwareTexture *hwtex;
|
||||
|
||||
FSWSceneTexture(int w, int h, int bits)
|
||||
{
|
||||
|
@ -73,9 +72,8 @@ public:
|
|||
Height = h;
|
||||
WidthBits = bits;
|
||||
UseType = ETextureType::SWCanvas;
|
||||
|
||||
hwtex = new FHardwareTexture(true);
|
||||
new FGLTexture(this, hwtex);
|
||||
bNoCompress = true;
|
||||
gl_info.SystemTexture[0] = screen->CreateHardwareTexture(this);
|
||||
}
|
||||
|
||||
// This is just a wrapper around the hardware texture and should never call the bitmap getters - if it does, something is wrong.
|
||||
|
@ -101,20 +99,23 @@ SWSceneDrawer::~SWSceneDrawer()
|
|||
void SWSceneDrawer::RenderView(player_t *player)
|
||||
{
|
||||
DCanvas buffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor());
|
||||
if (FBTexture == nullptr || FBTexture->hwtex == nullptr || FBTexture->GetWidth() != screen->GetWidth() || FBTexture->GetHeight() != screen->GetHeight() || (V_IsTrueColor() ? 1:0) != FBTexture->WidthBits)
|
||||
if (FBTexture == nullptr || FBTexture->gl_info.SystemTexture[0] == nullptr ||
|
||||
FBTexture->GetWidth() != screen->GetWidth() ||
|
||||
FBTexture->GetHeight() != screen->GetHeight() ||
|
||||
(V_IsTrueColor() ? 1:0) != FBTexture->WidthBits)
|
||||
{
|
||||
// This manually constructs its own material here.
|
||||
if (FBTexture != nullptr) delete FBTexture;
|
||||
FBTexture = new FSWSceneTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor());
|
||||
FBTexture->hwtex->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
FBTexture->gl_info.SystemTexture[0]->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
auto mat = FMaterial::ValidateTexture(FBTexture, false);
|
||||
mat->AddTextureLayer(PaletteTexture);
|
||||
}
|
||||
auto buf = FBTexture->hwtex->MapBuffer();
|
||||
auto buf = FBTexture->gl_info.SystemTexture[0]->MapBuffer();
|
||||
if (!buf) I_FatalError("Unable to map buffer for software rendering");
|
||||
buffer.SetBuffer(screen->GetWidth(), screen->GetHeight(), screen->GetWidth(), buf);
|
||||
SWRenderer->RenderView(player, &buffer);
|
||||
FBTexture->hwtex->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
|
||||
FBTexture->gl_info.SystemTexture[0]->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
|
||||
|
||||
auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
|
||||
screen->Begin2D(false);
|
||||
|
|
|
@ -388,6 +388,12 @@ void OpenGLFrameBuffer::SetTextureFilterMode()
|
|||
if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode();
|
||||
}
|
||||
|
||||
FHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(FTexture *tex)
|
||||
{
|
||||
return new FHardwareTexture(tex->bNoCompress);
|
||||
}
|
||||
|
||||
|
||||
void OpenGLFrameBuffer::UpdatePalette()
|
||||
{
|
||||
if (GLRenderer)
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
void WriteSavePic(player_t *player, FileWriter *file, int width, int height) override;
|
||||
void RenderView(player_t *player) override;
|
||||
void SetTextureFilterMode() override;
|
||||
FHardwareTexture *CreateHardwareTexture(FTexture *tex) override;
|
||||
|
||||
// Retrieves a buffer containing image data for a screenshot.
|
||||
// Hint: Pitch can be negative for upside-down images, in which case buffer
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "gl/system/gl_debug.h"
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
#include "gl/textures/gl_samplers.h"
|
||||
|
||||
|
||||
extern TexFilter_s TexFilter[];
|
||||
|
@ -491,3 +492,64 @@ void FHardwareTexture::BindToFrameBuffer(int width, int height)
|
|||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer(width, height));
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Binds a texture to the renderer
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags)
|
||||
{
|
||||
int usebright = false;
|
||||
|
||||
if (translation <= 0)
|
||||
{
|
||||
translation = -translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto remap = TranslationToTable(translation);
|
||||
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
|
||||
}
|
||||
|
||||
bool needmipmap = (clampmode <= CLAMP_XY);
|
||||
|
||||
// Texture has become invalid
|
||||
if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified(DefaultRenderStyle()))
|
||||
{
|
||||
Clean(true);
|
||||
}
|
||||
|
||||
// Bind it to the system.
|
||||
if (!Bind(texunit, translation, needmipmap))
|
||||
{
|
||||
|
||||
int w = 0, h = 0;
|
||||
|
||||
// Create this texture
|
||||
unsigned char * buffer = nullptr;
|
||||
|
||||
if (!tex->bHasCanvas)
|
||||
{
|
||||
if (gl.legacyMode) flags |= CTF_MaybeWarped;
|
||||
buffer = tex->CreateTexBuffer(translation, w, h, flags | CTF_ProcessData);
|
||||
}
|
||||
else
|
||||
{
|
||||
w = tex->GetWidth();
|
||||
h = tex->GetHeight();
|
||||
}
|
||||
if (!CreateTexture(buffer, w, h, texunit, needmipmap, translation, "FHardwareTexture.BindOrCreate"))
|
||||
{
|
||||
// could not create texture
|
||||
delete[] buffer;
|
||||
return false;
|
||||
}
|
||||
delete[] buffer;
|
||||
}
|
||||
if (tex->bHasCanvas) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
|
||||
GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@ public:
|
|||
void BindToFrameBuffer(int w, int h);
|
||||
|
||||
unsigned int Bind(int texunit, int translation, bool needmipmap);
|
||||
bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);
|
||||
|
||||
void AllocateBuffer(int w, int h, int texelsize);
|
||||
uint8_t *MapBuffer();
|
||||
|
||||
|
|
|
@ -26,13 +26,11 @@
|
|||
#include "sbar.h"
|
||||
#include "stats.h"
|
||||
#include "r_utility.h"
|
||||
#include "textures/warpbuffer.h"
|
||||
|
||||
#include "gl/system/gl_interface.h"
|
||||
#include "gl/system/gl_framebuffer.h"
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
#include "gl/textures/gl_samplers.h"
|
||||
#include "gl/shaders/gl_shader.h"
|
||||
|
||||
EXTERN_CVAR(Bool, gl_render_precise)
|
||||
|
@ -40,185 +38,6 @@ EXTERN_CVAR(Int, gl_lightmode)
|
|||
EXTERN_CVAR(Bool, gl_precache)
|
||||
EXTERN_CVAR(Bool, gl_texture_usehires)
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// The GL texture maintenance class
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
//===========================================================================
|
||||
FGLTexture::FGLTexture(FTexture * tx, bool expandpatches)
|
||||
{
|
||||
assert(tx->gl_info.SystemTexture[expandpatches] == NULL);
|
||||
tex = tx;
|
||||
|
||||
mHwTexture = NULL;
|
||||
lastSampler = 254;
|
||||
lastTranslation = -1;
|
||||
tex->gl_info.SystemTexture[expandpatches] = this;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Constructor 2 for the SW framebuffer which provides its own hardware texture.
|
||||
//
|
||||
//===========================================================================
|
||||
FGLTexture::FGLTexture(FTexture * tx, FHardwareTexture *hwtex)
|
||||
{
|
||||
assert(tx->gl_info.SystemTexture[0] == NULL);
|
||||
tex = tx;
|
||||
|
||||
mHwTexture = hwtex;
|
||||
lastSampler = 254;
|
||||
lastTranslation = -1;
|
||||
tex->gl_info.SystemTexture[0] = this;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Destructor
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FGLTexture::~FGLTexture()
|
||||
{
|
||||
Clean(true);
|
||||
for (auto & i : tex->gl_info.SystemTexture) if (i == this) i = nullptr;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Deletes all allocated resources
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FGLTexture::Clean(bool all)
|
||||
{
|
||||
if (mHwTexture != nullptr)
|
||||
{
|
||||
if (!all) mHwTexture->Clean(false);
|
||||
else
|
||||
{
|
||||
delete mHwTexture;
|
||||
mHwTexture = nullptr;
|
||||
}
|
||||
|
||||
lastSampler = 253;
|
||||
lastTranslation = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FGLTexture::CleanUnused(SpriteHits &usedtranslations)
|
||||
{
|
||||
if (mHwTexture != nullptr)
|
||||
{
|
||||
mHwTexture->CleanUnused(usedtranslations);
|
||||
lastSampler = 253;
|
||||
lastTranslation = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Create hardware texture for world use
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FHardwareTexture *FGLTexture::CreateHwTexture()
|
||||
{
|
||||
if (tex->UseType==ETextureType::Null) return NULL; // Cannot register a NULL texture
|
||||
if (mHwTexture == NULL)
|
||||
{
|
||||
mHwTexture = new FHardwareTexture(tex->bNoCompress);
|
||||
}
|
||||
return mHwTexture;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Binds a texture to the renderer
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FGLTexture::Bind(int texunit, int clampmode, int translation, int flags)
|
||||
{
|
||||
int usebright = false;
|
||||
|
||||
if (translation <= 0)
|
||||
{
|
||||
translation = -translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto remap = TranslationToTable(translation);
|
||||
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
|
||||
}
|
||||
|
||||
bool needmipmap = (clampmode <= CLAMP_XY);
|
||||
|
||||
FHardwareTexture *hwtex = CreateHwTexture();
|
||||
|
||||
if (hwtex)
|
||||
{
|
||||
// Texture has become invalid
|
||||
if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified(DefaultRenderStyle()))
|
||||
{
|
||||
Clean(true);
|
||||
hwtex = CreateHwTexture();
|
||||
}
|
||||
|
||||
// Bind it to the system.
|
||||
if (!hwtex->Bind(texunit, translation, needmipmap))
|
||||
{
|
||||
|
||||
int w=0, h=0;
|
||||
|
||||
// Create this texture
|
||||
unsigned char * buffer = nullptr;
|
||||
|
||||
if (!tex->bHasCanvas)
|
||||
{
|
||||
buffer = tex->CreateTexBuffer(translation, w, h, flags | CTF_ProcessData);
|
||||
if (tex->bWarped && gl.legacyMode && w*h <= 256*256) // do not software-warp larger textures, especially on the old systems that still need this fallback.
|
||||
{
|
||||
// need to do software warping
|
||||
FWarpTexture *wt = static_cast<FWarpTexture*>(tex);
|
||||
unsigned char *warpbuffer = new unsigned char[w*h*4];
|
||||
WarpBuffer((uint32_t*)warpbuffer, (const uint32_t*)buffer, w, h, wt->WidthOffsetMultiplier, wt->HeightOffsetMultiplier, screen->FrameTime, wt->Speed, tex->bWarped);
|
||||
delete[] buffer;
|
||||
buffer = warpbuffer;
|
||||
wt->GenTime[0] = screen->FrameTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
w = tex->GetWidth();
|
||||
h = tex->GetHeight();
|
||||
}
|
||||
if (!hwtex->CreateTexture(buffer, w, h, texunit, needmipmap, translation, "FGLTexture.Bind"))
|
||||
{
|
||||
// could not create texture
|
||||
delete[] buffer;
|
||||
return false;
|
||||
}
|
||||
delete[] buffer;
|
||||
}
|
||||
if (tex->bHasCanvas) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
|
||||
if (translation != lastTranslation) lastSampler = 254;
|
||||
if (lastSampler != clampmode)
|
||||
lastSampler = GLRenderer->mSamplerManager->Bind(texunit, clampmode, lastSampler);
|
||||
lastTranslation = translation;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
|
@ -288,18 +107,18 @@ float FTexCoordInfo::TextureAdjustWidth() const
|
|||
//
|
||||
//
|
||||
//===========================================================================
|
||||
FGLTexture * FMaterial::ValidateSysTexture(FTexture * tex, bool expand)
|
||||
FHardwareTexture * FMaterial::ValidateSysTexture(FTexture * tex, bool expand)
|
||||
{
|
||||
if (tex && tex->UseType!=ETextureType::Null)
|
||||
{
|
||||
FGLTexture *gltex = tex->gl_info.SystemTexture[expand];
|
||||
if (gltex == NULL)
|
||||
FHardwareTexture *gltex = tex->gl_info.SystemTexture[expand];
|
||||
if (gltex == nullptr)
|
||||
{
|
||||
gltex = new FGLTexture(tex, expand);
|
||||
gltex = tex->gl_info.SystemTexture[expand] = screen->CreateHardwareTexture(tex);
|
||||
}
|
||||
return gltex;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -625,7 +444,7 @@ void FMaterial::Bind(int clampmode, int translation)
|
|||
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
|
||||
int flags = mExpanded? CTF_Expand : (gl_texture_usehires && tex->Scale.X == 1 && tex->Scale.Y == 1 && clampmode <= CLAMP_XY)? CTF_CheckHires : 0;
|
||||
|
||||
if (mBaseLayer->Bind(0, clampmode, translation, flags))
|
||||
if (mBaseLayer->BindOrCreate(tex, 0, clampmode, translation, flags))
|
||||
{
|
||||
for(unsigned i=0;i<mTextureLayers.Size();i++)
|
||||
{
|
||||
|
@ -634,13 +453,13 @@ void FMaterial::Bind(int clampmode, int translation)
|
|||
{
|
||||
FTextureID id = mTextureLayers[i].texture->id;
|
||||
layer = TexMan(id);
|
||||
ValidateSysTexture(layer, mExpanded);
|
||||
}
|
||||
else
|
||||
{
|
||||
layer = mTextureLayers[i].texture;
|
||||
}
|
||||
layer->gl_info.SystemTexture[mExpanded]->Bind(i+1, clampmode, 0, 0);
|
||||
auto systex = ValidateSysTexture(layer, mExpanded);
|
||||
systex->BindOrCreate(layer, i+1, clampmode, 0, 0);
|
||||
maxbound = i+1;
|
||||
}
|
||||
}
|
||||
|
@ -730,7 +549,6 @@ int FMaterial::GetAreas(FloatRect **pAreas) const
|
|||
{
|
||||
if (mShaderIndex == SHADER_Default) // texture splitting can only be done if there's no attached effects
|
||||
{
|
||||
FTexture *tex = mBaseLayer->tex;
|
||||
*pAreas = tex->areas;
|
||||
return tex->areacount;
|
||||
}
|
||||
|
@ -748,14 +566,14 @@ int FMaterial::GetAreas(FloatRect **pAreas) const
|
|||
|
||||
void FMaterial::BindToFrameBuffer()
|
||||
{
|
||||
if (mBaseLayer->mHwTexture == NULL)
|
||||
if (mBaseLayer == nullptr)
|
||||
{
|
||||
// must create the hardware texture first
|
||||
mBaseLayer->Bind(0, 0, 0, 0);
|
||||
mBaseLayer->BindOrCreate(tex, 0, 0, 0, 0);
|
||||
FHardwareTexture::Unbind(0);
|
||||
ClearLastTexture();
|
||||
}
|
||||
mBaseLayer->mHwTexture->BindToFrameBuffer(mWidth, mHeight);
|
||||
mBaseLayer->BindToFrameBuffer(mWidth, mHeight);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -823,8 +641,8 @@ void FMaterial::FlushAll()
|
|||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
FGLTexture *gltex = TexMan.ByIndex(i)->gl_info.SystemTexture[j];
|
||||
if (gltex != NULL) gltex->Clean(true);
|
||||
auto gltex = TexMan.ByIndex(i)->gl_info.SystemTexture[j];
|
||||
if (gltex != nullptr) gltex->Clean(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,39 +43,6 @@ struct FTexCoordInfo
|
|||
float TextureAdjustWidth() const;
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// device independent wrapper around the hardware texture and its sampler state
|
||||
//
|
||||
//===========================================================================
|
||||
class FMaterial;
|
||||
|
||||
class FGLTexture
|
||||
{
|
||||
friend class FMaterial;
|
||||
public:
|
||||
FTexture * tex;
|
||||
|
||||
private:
|
||||
FHardwareTexture *mHwTexture;
|
||||
|
||||
uint8_t lastSampler;
|
||||
int lastTranslation;
|
||||
|
||||
FHardwareTexture *CreateHwTexture();
|
||||
|
||||
bool Bind(int texunit, int clamp, int translation, int flags);
|
||||
|
||||
public:
|
||||
FGLTexture(FTexture * tx, bool expandpatches);
|
||||
FGLTexture(FTexture * tx, FHardwareTexture *hwtex); // for the SW framebuffer
|
||||
~FGLTexture();
|
||||
|
||||
void Clean(bool all);
|
||||
void CleanUnused(SpriteHits &usedtranslations);
|
||||
bool isInitialized() const { return mHwTexture != nullptr; }
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// this is the material class for OpenGL.
|
||||
|
@ -98,7 +65,7 @@ class FMaterial
|
|||
static TArray<FMaterial *> mMaterials;
|
||||
static int mMaxBound;
|
||||
|
||||
FGLTexture *mBaseLayer;
|
||||
FHardwareTexture *mBaseLayer;
|
||||
TArray<FTextureLayer> mTextureLayers;
|
||||
int mShaderIndex;
|
||||
|
||||
|
@ -115,7 +82,7 @@ class FMaterial
|
|||
float mSpriteU[2], mSpriteV[2];
|
||||
FloatRect mSpriteRect;
|
||||
|
||||
FGLTexture * ValidateSysTexture(FTexture * tex, bool expand);
|
||||
FHardwareTexture * ValidateSysTexture(FTexture * tex, bool expand);
|
||||
bool TrimBorders(uint16_t *rect);
|
||||
|
||||
public:
|
||||
|
@ -134,7 +101,7 @@ public:
|
|||
}
|
||||
bool isMasked() const
|
||||
{
|
||||
return !!mBaseLayer->tex->bMasked;
|
||||
return !!tex->bMasked;
|
||||
}
|
||||
|
||||
int GetLayers() const
|
||||
|
|
|
@ -173,9 +173,8 @@ area_t hw_CheckViewArea(area_t in_area, vertex_t *v1, vertex_t *v2, sector_t *fr
|
|||
// allow some tolerance in case slopes are involved
|
||||
if (cz1 <= fz1 + 1. / 100 && cz2 <= fz2 + 1. / 100)
|
||||
return area_below;
|
||||
else
|
||||
return area_normal;
|
||||
}
|
||||
return area_normal;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "c_dispatch.h"
|
||||
#include "v_video.h"
|
||||
#include "m_fixed.h"
|
||||
#include "textures/warpbuffer.h"
|
||||
|
||||
FTexture *CreateBrightmapTexture(FTexture*);
|
||||
|
||||
|
@ -1352,7 +1353,7 @@ bool FTexture::ProcessData(unsigned char * buffer, int w, int h, bool ispatch)
|
|||
|
||||
unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int flags)
|
||||
{
|
||||
unsigned char * buffer;
|
||||
unsigned char * buffer = nullptr;
|
||||
int W, H;
|
||||
int isTransparent = -1;
|
||||
|
||||
|
@ -1360,71 +1361,82 @@ unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int
|
|||
if ((flags & CTF_CheckHires) && translation != STRange_AlphaTexture)
|
||||
{
|
||||
buffer = LoadHiresTexture(&w, &h);
|
||||
if (buffer)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
int exx = !!(flags & CTF_Expand);
|
||||
|
||||
W = w = GetWidth() + 2 * exx;
|
||||
H = h = GetHeight() + 2 * exx;
|
||||
|
||||
|
||||
buffer = new unsigned char[W*(H + 1) * 4];
|
||||
memset(buffer, 0, W * (H + 1) * 4);
|
||||
|
||||
FBitmap bmp(buffer, W * 4, W, H);
|
||||
|
||||
if (translation <= 0 || translation >= STRange_Min)
|
||||
if (buffer == nullptr)
|
||||
{
|
||||
// Allow creation of desaturated or special-colormapped textures for the legacy renderer.
|
||||
FCopyInfo inf = { OP_COPY, BLEND_NONE,{ 0 }, 0, 0 };
|
||||
if (translation >= STRange_Desaturate && translation < STRange_Desaturate + 31) // there are 31 ranges of desaturations available
|
||||
{
|
||||
inf.blend = (EBlend)(BLEND_DESATURATE1 + translation - STRange_Desaturate);
|
||||
}
|
||||
else if (translation >= STRange_Specialcolormap && translation < STRange_Specialcolormap + (int)SpecialColormaps.Size())
|
||||
{
|
||||
inf.blend = (EBlend)(BLEND_SPECIALCOLORMAP1 + translation - STRange_Specialcolormap);
|
||||
}
|
||||
|
||||
int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, translation >= STRange_Min ? &inf : nullptr);
|
||||
CheckTrans(buffer, W*H, trans);
|
||||
isTransparent = bTranslucent;
|
||||
// alpha texture for legacy mode
|
||||
if (translation == STRange_AlphaTexture)
|
||||
int exx = !!(flags & CTF_Expand);
|
||||
|
||||
W = w = GetWidth() + 2 * exx;
|
||||
H = h = GetHeight() + 2 * exx;
|
||||
|
||||
|
||||
buffer = new unsigned char[W*(H + 1) * 4];
|
||||
memset(buffer, 0, W * (H + 1) * 4);
|
||||
|
||||
FBitmap bmp(buffer, W * 4, W, H);
|
||||
|
||||
if (translation <= 0 || translation >= STRange_Min)
|
||||
{
|
||||
for (int i = 0; i < W*H; i++)
|
||||
// Allow creation of desaturated or special-colormapped textures for the legacy renderer.
|
||||
FCopyInfo inf = { OP_COPY, BLEND_NONE,{ 0 }, 0, 0 };
|
||||
if (translation >= STRange_Desaturate && translation < STRange_Desaturate + 31) // there are 31 ranges of desaturations available
|
||||
{
|
||||
int b = buffer[4 * i];
|
||||
int g = buffer[4 * i + 1];
|
||||
int r = buffer[4 * i + 2];
|
||||
int gray = Luminance(r, g, b);
|
||||
buffer[4 * i] = 255;
|
||||
buffer[4 * i + 1] = 255;
|
||||
buffer[4 * i + 2] = 255;
|
||||
buffer[4 * i + 3] = (buffer[4 * i + 3] * gray) >> 8;
|
||||
inf.blend = (EBlend)(BLEND_DESATURATE1 + translation - STRange_Desaturate);
|
||||
}
|
||||
else if (translation >= STRange_Specialcolormap && translation < STRange_Specialcolormap + (int)SpecialColormaps.Size())
|
||||
{
|
||||
inf.blend = (EBlend)(BLEND_SPECIALCOLORMAP1 + translation - STRange_Specialcolormap);
|
||||
}
|
||||
|
||||
int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, translation >= STRange_Min ? &inf : nullptr);
|
||||
CheckTrans(buffer, W*H, trans);
|
||||
isTransparent = bTranslucent;
|
||||
// alpha texture for legacy mode
|
||||
if (translation == STRange_AlphaTexture)
|
||||
{
|
||||
for (int i = 0; i < W*H; i++)
|
||||
{
|
||||
int b = buffer[4 * i];
|
||||
int g = buffer[4 * i + 1];
|
||||
int r = buffer[4 * i + 2];
|
||||
int gray = Luminance(r, g, b);
|
||||
buffer[4 * i] = 255;
|
||||
buffer[4 * i + 1] = 255;
|
||||
buffer[4 * i + 2] = 255;
|
||||
buffer[4 * i + 3] = (buffer[4 * i + 3] * gray) >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// When using translations everything must be mapped to the base palette.
|
||||
// so use CopyTrueColorTranslated
|
||||
CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation));
|
||||
isTransparent = 0;
|
||||
// This is not conclusive for setting the texture's transparency info.
|
||||
}
|
||||
|
||||
// [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it.
|
||||
// [BB] Potentially upsample the buffer.
|
||||
if (flags & CTF_ProcessData)
|
||||
{
|
||||
buffer = CreateUpsampledTextureBuffer(buffer, W, H, w, h, !!isTransparent);
|
||||
ProcessData(buffer, w, h, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
if ((flags & CTF_MaybeWarped) && bWarped && w*h <= 256 * 256) // do not software-warp larger textures, especially on the old systems that still need this fallback.
|
||||
{
|
||||
// When using translations everything must be mapped to the base palette.
|
||||
// so use CopyTrueColorTranslated
|
||||
CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation));
|
||||
isTransparent = 0;
|
||||
// This is not conclusive for setting the texture's transparency info.
|
||||
// need to do software warping
|
||||
FWarpTexture *wt = static_cast<FWarpTexture*>(this);
|
||||
unsigned char *warpbuffer = new unsigned char[w*h * 4];
|
||||
WarpBuffer((uint32_t*)warpbuffer, (const uint32_t*)buffer, w, h, wt->WidthOffsetMultiplier, wt->HeightOffsetMultiplier, screen->FrameTime, wt->Speed, bWarped);
|
||||
delete[] buffer;
|
||||
buffer = warpbuffer;
|
||||
wt->GenTime[0] = screen->FrameTime;
|
||||
}
|
||||
|
||||
// [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it.
|
||||
// [BB] Potentially upsample the buffer.
|
||||
if (flags & CTF_ProcessData)
|
||||
{
|
||||
buffer = CreateUpsampledTextureBuffer(buffer, W, H, w, h, !!isTransparent);
|
||||
ProcessData(buffer, w, h, false);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,9 +99,10 @@ enum ESpecialTranslations : int32_t
|
|||
|
||||
enum ECreateTexBufferFlags
|
||||
{
|
||||
CTF_CheckHires = 1, // use external hires replacement if found
|
||||
CTF_Expand = 2, // create buffer with a one-pixel wide border
|
||||
CTF_ProcessData = 4 // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
|
||||
CTF_CheckHires = 1, // use external hires replacement if found
|
||||
CTF_Expand = 2, // create buffer with a one-pixel wide border
|
||||
CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
|
||||
CTF_MaybeWarped = 8 // may be warped if needed
|
||||
};
|
||||
|
||||
|
||||
|
@ -114,7 +115,7 @@ class FScanner;
|
|||
// Texture IDs
|
||||
class FTextureManager;
|
||||
class FTerrainTypeArray;
|
||||
class FGLTexture;
|
||||
class FHardwareTexture;
|
||||
class FMaterial;
|
||||
extern int r_spriteadjustSW, r_spriteadjustHW;
|
||||
|
||||
|
@ -481,7 +482,7 @@ public:
|
|||
struct GLTexInfo
|
||||
{
|
||||
FMaterial *Material[2] = { nullptr, nullptr };
|
||||
FGLTexture *SystemTexture[2] = { nullptr, nullptr };
|
||||
FHardwareTexture *SystemTexture[2] = { nullptr, nullptr };
|
||||
bool bNoExpand = false;
|
||||
|
||||
~GLTexInfo();
|
||||
|
|
|
@ -280,6 +280,8 @@ public:
|
|||
|
||||
|
||||
class FUniquePalette;
|
||||
class FHardwareTexture;
|
||||
class FTexture;
|
||||
|
||||
// A canvas that represents the actual display. The video code is responsible
|
||||
// for actually implementing this. Built on top of SimpleCanvas, because it
|
||||
|
@ -351,6 +353,7 @@ public:
|
|||
// Delete any resources that need to be deleted after restarting with a different IWAD
|
||||
virtual void CleanForRestart() {}
|
||||
virtual void SetTextureFilterMode() {}
|
||||
virtual FHardwareTexture *CreateHardwareTexture(FTexture *tex) { return nullptr; }
|
||||
|
||||
// Begin 2D drawing operations.
|
||||
// Returns true if hardware-accelerated 2D has been entered, false if not.
|
||||
|
|
Loading…
Reference in a new issue