mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
- backend update from GZDoom
* GLES backend fixes. * font colorization fixes. * option menu spacing fix
This commit is contained in:
parent
49e0c461c2
commit
2348dd8848
15 changed files with 106 additions and 45 deletions
|
@ -243,7 +243,7 @@ public:
|
||||||
bool mIsFirstPass = true;
|
bool mIsFirstPass = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DShape2DBufferInfo : NoVirtualRefCountedBase
|
struct DShape2DBufferInfo : RefCountedBase
|
||||||
{
|
{
|
||||||
TArray<F2DVertexBuffer> buffers;
|
TArray<F2DVertexBuffer> buffers;
|
||||||
bool needsVertexUpload = true;
|
bool needsVertexUpload = true;
|
||||||
|
|
|
@ -570,6 +570,32 @@ void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// RecordLuminosity
|
||||||
|
//
|
||||||
|
// Records minimum and maximum luminosity of a texture.
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
static void RecordLuminosity(FImageSource* pic, int* minlum, int* maxlum)
|
||||||
|
{
|
||||||
|
auto bitmap = pic->GetCachedBitmap(nullptr, FImageSource::normal);
|
||||||
|
auto pixels = bitmap.GetPixels();
|
||||||
|
auto size = pic->GetWidth() * pic->GetHeight();
|
||||||
|
|
||||||
|
for (int x = 0; x < size; x++)
|
||||||
|
{
|
||||||
|
int xx = x * 4;
|
||||||
|
if (pixels[xx + 3] > 0)
|
||||||
|
{
|
||||||
|
int lum = Luminance(pixels[xx + 2], pixels[xx + 1], pixels[xx]);
|
||||||
|
if (lum < *minlum) *minlum = lum;
|
||||||
|
if (lum > *maxlum) *maxlum = lum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// RecordAllTextureColors
|
// RecordAllTextureColors
|
||||||
|
@ -969,27 +995,22 @@ int FFont::GetMaxAscender(const uint8_t* string) const
|
||||||
void FFont::LoadTranslations()
|
void FFont::LoadTranslations()
|
||||||
{
|
{
|
||||||
unsigned int count = min<unsigned>(Chars.Size(), LastChar - FirstChar + 1);
|
unsigned int count = min<unsigned>(Chars.Size(), LastChar - FirstChar + 1);
|
||||||
uint32_t usedcolors[256] = {};
|
|
||||||
TArray<double> Luminosity;
|
|
||||||
|
|
||||||
if (count == 0) return;
|
if (count == 0) return;
|
||||||
|
int minlum = 255, maxlum = 0;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if (Chars[i].OriginalPic)
|
if (Chars[i].OriginalPic)
|
||||||
{
|
{
|
||||||
auto pic = Chars[i].OriginalPic->GetTexture()->GetImage();
|
auto pic = Chars[i].OriginalPic->GetTexture()->GetImage();
|
||||||
if (pic) RecordTextureColors(pic, usedcolors);
|
RecordLuminosity(pic, &minlum, &maxlum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int minlum = 0, maxlum = 0;
|
|
||||||
GetLuminosity (usedcolors, Luminosity, &minlum, &maxlum);
|
|
||||||
if (MinLum >= 0 && MinLum < minlum) minlum = MinLum;
|
if (MinLum >= 0 && MinLum < minlum) minlum = MinLum;
|
||||||
if (MaxLum > maxlum) maxlum = MaxLum;
|
if (MaxLum > maxlum) maxlum = MaxLum;
|
||||||
|
|
||||||
// Here we can set everything to a luminosity translation.
|
// Here we can set everything to a luminosity translation.
|
||||||
|
|
||||||
// Create different translations for different color ranges
|
|
||||||
Translations.Resize(NumTextColors);
|
Translations.Resize(NumTextColors);
|
||||||
for (int i = 0; i < NumTextColors; i++)
|
for (int i = 0; i < NumTextColors; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -527,7 +527,7 @@ void FSingleLumpFont::FixupPalette (uint8_t *identity, const PalEntry *palette,
|
||||||
double minlum = 100000000.0;
|
double minlum = 100000000.0;
|
||||||
|
|
||||||
identity[0] = 0;
|
identity[0] = 0;
|
||||||
palette += 3; // Skip the transparent color
|
palette++; // Skip the transparent color
|
||||||
|
|
||||||
for (int i = 1; i < ActiveColors; ++i, palette ++)
|
for (int i = 1; i < ActiveColors; ++i, palette ++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,6 +94,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
|
||||||
{
|
{
|
||||||
if (!stricmp(name, "DBIGFONT")) name = "BigFont";
|
if (!stricmp(name, "DBIGFONT")) name = "BigFont";
|
||||||
else if (!stricmp(name, "CONFONT")) name = "ConsoleFont"; // several mods have used the name CONFONT directly and effectively duplicated the font.
|
else if (!stricmp(name, "CONFONT")) name = "ConsoleFont"; // several mods have used the name CONFONT directly and effectively duplicated the font.
|
||||||
|
else if (!stricmp(name, "INDEXFON")) name = "IndexFont"; // Same here - for whatever reason some people had to use its 8 character name...
|
||||||
FFont *font = FFont::FindFont (name);
|
FFont *font = FFont::FindFont (name);
|
||||||
if (font == nullptr)
|
if (font == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -873,6 +874,7 @@ void V_InitFonts()
|
||||||
NewSmallFont = CreateHexLumpFont2("NewSmallFont", lump);
|
NewSmallFont = CreateHexLumpFont2("NewSmallFont", lump);
|
||||||
CurrentConsoleFont = NewConsoleFont;
|
CurrentConsoleFont = NewConsoleFont;
|
||||||
ConFont = V_GetFont("ConsoleFont", "CONFONT");
|
ConFont = V_GetFont("ConsoleFont", "CONFONT");
|
||||||
|
V_GetFont("IndexFont", "INDEXFON"); // detect potential replacements for this one.
|
||||||
}
|
}
|
||||||
|
|
||||||
void V_LoadTranslations()
|
void V_LoadTranslations()
|
||||||
|
|
|
@ -143,7 +143,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
|
||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
lastcolor = FString((const char*)cstart, pos - start);
|
lastcolor = FString((const char*)cstart, pos - cstart);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -910,7 +910,7 @@ static void ParseOptionSettings(FScanner &sc)
|
||||||
else if (sc.Compare("Linespacing"))
|
else if (sc.Compare("Linespacing"))
|
||||||
{
|
{
|
||||||
sc.MustGetNumber();
|
sc.MustGetNumber();
|
||||||
OptionSettings.mLinespacing = sc.Number;
|
// ignored
|
||||||
}
|
}
|
||||||
else if (sc.Compare("LabelOffset"))
|
else if (sc.Compare("LabelOffset"))
|
||||||
{
|
{
|
||||||
|
@ -1402,6 +1402,7 @@ void M_ParseMenuDefs()
|
||||||
DefaultOptionMenuSettings = Create<DOptionMenuDescriptor>();
|
DefaultOptionMenuSettings = Create<DOptionMenuDescriptor>();
|
||||||
DefaultListMenuSettings->Reset();
|
DefaultListMenuSettings->Reset();
|
||||||
DefaultOptionMenuSettings->Reset();
|
DefaultOptionMenuSettings->Reset();
|
||||||
|
OptionSettings.mLinespacing = 17;
|
||||||
|
|
||||||
int IWADMenu = fileSystem.CheckNumForName("MENUDEF", ns_global, fileSystem.GetIwadNum());
|
int IWADMenu = fileSystem.CheckNumForName("MENUDEF", ns_global, fileSystem.GetIwadNum());
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,7 @@ DObject::DObject ()
|
||||||
ObjNext = GC::Root;
|
ObjNext = GC::Root;
|
||||||
GCNext = nullptr;
|
GCNext = nullptr;
|
||||||
GC::Root = this;
|
GC::Root = this;
|
||||||
|
GC::AllocCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
DObject::DObject (PClass *inClass)
|
DObject::DObject (PClass *inClass)
|
||||||
|
@ -238,6 +239,7 @@ DObject::DObject (PClass *inClass)
|
||||||
ObjNext = GC::Root;
|
ObjNext = GC::Root;
|
||||||
GCNext = nullptr;
|
GCNext = nullptr;
|
||||||
GC::Root = this;
|
GC::Root = this;
|
||||||
|
GC::AllocCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -275,6 +277,7 @@ DObject::~DObject ()
|
||||||
|
|
||||||
void DObject::Release()
|
void DObject::Release()
|
||||||
{
|
{
|
||||||
|
if (GC::AllocCount > 0) GC::AllocCount--;
|
||||||
DObject **probe;
|
DObject **probe;
|
||||||
|
|
||||||
// Unlink this object from the GC list.
|
// Unlink this object from the GC list.
|
||||||
|
|
|
@ -108,6 +108,7 @@ namespace GC
|
||||||
size_t AllocBytes;
|
size_t AllocBytes;
|
||||||
size_t Threshold;
|
size_t Threshold;
|
||||||
size_t Estimate;
|
size_t Estimate;
|
||||||
|
size_t AllocCount;
|
||||||
DObject *Gray;
|
DObject *Gray;
|
||||||
DObject *Root;
|
DObject *Root;
|
||||||
DObject *SoftRoots;
|
DObject *SoftRoots;
|
||||||
|
|
|
@ -43,6 +43,9 @@ namespace GC
|
||||||
// Number of bytes currently allocated through M_Malloc/M_Realloc.
|
// Number of bytes currently allocated through M_Malloc/M_Realloc.
|
||||||
extern size_t AllocBytes;
|
extern size_t AllocBytes;
|
||||||
|
|
||||||
|
// Number of allocated objects since last CheckGC call.
|
||||||
|
extern size_t AllocCount;
|
||||||
|
|
||||||
// Amount of memory to allocate before triggering a collection.
|
// Amount of memory to allocate before triggering a collection.
|
||||||
extern size_t Threshold;
|
extern size_t Threshold;
|
||||||
|
|
||||||
|
@ -105,10 +108,15 @@ namespace GC
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's time to collect, and do a collection step if it is.
|
// Check if it's time to collect, and do a collection step if it is.
|
||||||
static inline void CheckGC()
|
static inline bool CheckGC()
|
||||||
{
|
{
|
||||||
|
AllocCount = 0;
|
||||||
if (AllocBytes >= Threshold)
|
if (AllocBytes >= Threshold)
|
||||||
|
{
|
||||||
Step();
|
Step();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forces a collection to start now.
|
// Forces a collection to start now.
|
||||||
|
|
|
@ -81,12 +81,11 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
||||||
int texformat = GL_RGBA;// TexFormat[gl_texture_format];
|
int texformat = GL_RGBA;// TexFormat[gl_texture_format];
|
||||||
bool deletebuffer=false;
|
bool deletebuffer=false;
|
||||||
|
|
||||||
/*
|
// When running in SW mode buffer will be null, so set it to the texBuffer already created
|
||||||
if (forcenocompression)
|
// There could be other use cases I do not know about which means this is a bad idea..
|
||||||
{
|
if (buffer == nullptr)
|
||||||
texformat = GL_RGBA8;
|
buffer = texBuffer;
|
||||||
}
|
|
||||||
*/
|
|
||||||
bool firstCall = glTexID == 0;
|
bool firstCall = glTexID == 0;
|
||||||
if (firstCall)
|
if (firstCall)
|
||||||
{
|
{
|
||||||
|
@ -136,9 +135,19 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
||||||
sourcetype = GL_BGRA;
|
sourcetype = GL_BGRA;
|
||||||
texformat = GL_BGRA;
|
texformat = GL_BGRA;
|
||||||
#else
|
#else
|
||||||
|
if (glTextureBytes == 1)
|
||||||
|
{
|
||||||
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
sourcetype = GL_RED;
|
||||||
|
texformat = GL_R8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sourcetype = GL_BGRA;
|
sourcetype = GL_BGRA;
|
||||||
texformat = GL_RGBA;
|
texformat = GL_RGBA;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, sourcetype, GL_UNSIGNED_BYTE, buffer);
|
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, sourcetype, GL_UNSIGNED_BYTE, buffer);
|
||||||
|
|
||||||
if (deletebuffer && buffer) free(buffer);
|
if (deletebuffer && buffer) free(buffer);
|
||||||
|
@ -155,6 +164,26 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FHardwareTexture::AllocateBuffer(int w, int h, int texelsize)
|
||||||
|
{
|
||||||
|
int rw = GetTexDimension(w);
|
||||||
|
int rh = GetTexDimension(h);
|
||||||
|
|
||||||
|
if (texelsize < 1 || texelsize > 4) texelsize = 4;
|
||||||
|
glTextureBytes = texelsize;
|
||||||
|
bufferpitch = w;
|
||||||
|
|
||||||
|
if (texBuffer)
|
||||||
|
delete[] texBuffer;
|
||||||
|
|
||||||
|
texBuffer = new uint8_t[(w * h) * texelsize];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* FHardwareTexture::MapBuffer()
|
||||||
|
{
|
||||||
|
return texBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
|
@ -164,6 +193,9 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
||||||
FHardwareTexture::~FHardwareTexture()
|
FHardwareTexture::~FHardwareTexture()
|
||||||
{
|
{
|
||||||
if (glTexID != 0) glDeleteTextures(1, &glTexID);
|
if (glTexID != 0) glDeleteTextures(1, &glTexID);
|
||||||
|
|
||||||
|
if (texBuffer)
|
||||||
|
delete[] texBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,8 @@ private:
|
||||||
|
|
||||||
unsigned int glTexID = 0;
|
unsigned int glTexID = 0;
|
||||||
unsigned int glDepthID = 0; // only used by camera textures
|
unsigned int glDepthID = 0; // only used by camera textures
|
||||||
|
uint8_t* texBuffer;
|
||||||
|
|
||||||
int glTextureBytes;
|
int glTextureBytes;
|
||||||
bool mipmapped = false;
|
bool mipmapped = false;
|
||||||
|
|
||||||
|
@ -52,6 +54,8 @@ public:
|
||||||
{
|
{
|
||||||
forcenofilter = disablefilter;
|
forcenofilter = disablefilter;
|
||||||
glTextureBytes = numchannels;
|
glTextureBytes = numchannels;
|
||||||
|
|
||||||
|
texBuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FHardwareTexture();
|
~FHardwareTexture();
|
||||||
|
@ -64,8 +68,8 @@ public:
|
||||||
unsigned int Bind(int texunit, bool needmipmap);
|
unsigned int Bind(int texunit, bool needmipmap);
|
||||||
bool BindOrCreate(FTexture* tex, int texunit, int clampmode, int translation, int flags);
|
bool BindOrCreate(FTexture* tex, int texunit, int clampmode, int translation, int flags);
|
||||||
|
|
||||||
void AllocateBuffer(int w, int h, int texelsize) {} // Not used
|
void AllocateBuffer(int w, int h, int texelsize);
|
||||||
uint8_t* MapBuffer() { return 0; } // Not used
|
uint8_t* MapBuffer();
|
||||||
|
|
||||||
unsigned int CreateTexture(unsigned char* buffer, int w, int h, int texunit, bool mipmap, const char* name);
|
unsigned int CreateTexture(unsigned char* buffer, int w, int h, int texunit, bool mipmap, const char* name);
|
||||||
unsigned int GetTextureHandle()
|
unsigned int GetTextureHandle()
|
||||||
|
|
|
@ -32,6 +32,10 @@ static void* LoadGLES2Proc(const char* name)
|
||||||
{
|
{
|
||||||
glesLib = dlopen("libGLESv2.so", flags);
|
glesLib = dlopen("libGLESv2.so", flags);
|
||||||
}
|
}
|
||||||
|
if(!glesLib)
|
||||||
|
{
|
||||||
|
glesLib = dlopen("libGLESv2.so.2", flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void * ret = NULL;
|
void * ret = NULL;
|
||||||
|
|
|
@ -571,7 +571,7 @@ inline BufferBuilder::BufferBuilder()
|
||||||
|
|
||||||
inline void BufferBuilder::setSize(size_t size)
|
inline void BufferBuilder::setSize(size_t size)
|
||||||
{
|
{
|
||||||
bufferInfo.size = size;
|
bufferInfo.size = std::max(size, (size_t)16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void BufferBuilder::setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocFlags)
|
inline void BufferBuilder::setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocFlags)
|
||||||
|
|
|
@ -127,8 +127,5 @@ void main()
|
||||||
ClipDistanceA = vec4(ClipDistance0, ClipDistance1, ClipDistance2, ClipDistance3);
|
ClipDistanceA = vec4(ClipDistance0, ClipDistance1, ClipDistance2, ClipDistance3);
|
||||||
ClipDistanceB = vec4(ClipDistance4, 0.0, 0.0, 0.0);
|
ClipDistanceB = vec4(ClipDistance4, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
|
||||||
//gl_PointSize = 1.0;
|
|
||||||
|
|
||||||
gl_Position = ProjectionMatrix * eyeCoordPos;
|
gl_Position = ProjectionMatrix * eyeCoordPos;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,36 +14,24 @@ vec3 lightContribution(int i, vec3 normal)
|
||||||
vec3 lightdir = normalize(lightpos.xyz - pixelpos.xyz);
|
vec3 lightdir = normalize(lightpos.xyz - pixelpos.xyz);
|
||||||
float dotprod = dot(normal, lightdir);
|
float dotprod = dot(normal, lightdir);
|
||||||
|
|
||||||
//if (dotprod < -0.0001) return vec3(0.0); // light hits from the backside. This can happen with full sector light lists and must be rejected for all cases. Note that this can cause precision issues.
|
if (dotprod < -0.0001) return vec3(0.0); // light hits from the backside. This can happen with full sector light lists and must be rejected for all cases. Note that this can cause precision issues.
|
||||||
|
|
||||||
float attenuation = clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0);
|
float attenuation = clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0);
|
||||||
|
|
||||||
|
|
||||||
// NOTE, all spot light stuff gone
|
#if (DEF_HAS_SPOTLIGHT == 1) // Only perform test below if there are ANY spot lights on this surface.
|
||||||
return lightcolor.rgb * attenuation;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (lightspot1.w == 1.0)
|
if (lightspot1.w == 1.0)
|
||||||
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
|
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (lightcolor.a < 0.0) // Sign bit is the attenuated light flag
|
if (lightcolor.a < 0.0) // Sign bit is the attenuated light flag
|
||||||
{
|
{
|
||||||
attenuation *= clamp(dotprod, 0.0, 1.0);
|
attenuation *= clamp(dotprod, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (attenuation > 0.0) // Skip shadow map test if possible
|
|
||||||
{
|
|
||||||
attenuation *= shadowAttenuation(lightpos, lightcolor.a);
|
|
||||||
return lightcolor.rgb * attenuation;
|
return lightcolor.rgb * attenuation;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return vec3(0.0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vec3 ProcessMaterialLight(Material material, vec3 color)
|
vec3 ProcessMaterialLight(Material material, vec3 color)
|
||||||
|
@ -54,8 +42,8 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
|
||||||
#if (DEF_DYNAMIC_LIGHTS_MOD == 1)
|
#if (DEF_DYNAMIC_LIGHTS_MOD == 1)
|
||||||
// modulated lights
|
// modulated lights
|
||||||
|
|
||||||
// Some very old GLES2 hardward does not allow non-constants in a for-loop expression because it can not unroll it.
|
// Some very old GLES2 hardware does not allow non-constants in a for-loop expression because it can not unroll it.
|
||||||
// However they do allow 'break' and use stupid hack
|
// However they do allow 'break', so use stupid hack
|
||||||
#if (USE_GLSL_V100 == 1)
|
#if (USE_GLSL_V100 == 1)
|
||||||
|
|
||||||
for(int i = 0; i < 8; i++) // Max 8 lights
|
for(int i = 0; i < 8; i++) // Max 8 lights
|
||||||
|
|
Loading…
Reference in a new issue