mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 06:41:59 +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;
|
||||
};
|
||||
|
||||
struct DShape2DBufferInfo : NoVirtualRefCountedBase
|
||||
struct DShape2DBufferInfo : RefCountedBase
|
||||
{
|
||||
TArray<F2DVertexBuffer> buffers;
|
||||
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
|
||||
|
@ -969,27 +995,22 @@ int FFont::GetMaxAscender(const uint8_t* string) const
|
|||
void FFont::LoadTranslations()
|
||||
{
|
||||
unsigned int count = min<unsigned>(Chars.Size(), LastChar - FirstChar + 1);
|
||||
uint32_t usedcolors[256] = {};
|
||||
TArray<double> Luminosity;
|
||||
|
||||
if (count == 0) return;
|
||||
int minlum = 255, maxlum = 0;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
if (Chars[i].OriginalPic)
|
||||
{
|
||||
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 (MaxLum > maxlum) maxlum = MaxLum;
|
||||
|
||||
// Here we can set everything to a luminosity translation.
|
||||
|
||||
// Create different translations for different color ranges
|
||||
Translations.Resize(NumTextColors);
|
||||
for (int i = 0; i < NumTextColors; i++)
|
||||
{
|
||||
|
|
|
@ -527,7 +527,7 @@ void FSingleLumpFont::FixupPalette (uint8_t *identity, const PalEntry *palette,
|
|||
double minlum = 100000000.0;
|
||||
|
||||
identity[0] = 0;
|
||||
palette += 3; // Skip the transparent color
|
||||
palette++; // Skip the transparent color
|
||||
|
||||
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";
|
||||
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);
|
||||
if (font == nullptr)
|
||||
{
|
||||
|
@ -873,6 +874,7 @@ void V_InitFonts()
|
|||
NewSmallFont = CreateHexLumpFont2("NewSmallFont", lump);
|
||||
CurrentConsoleFont = NewConsoleFont;
|
||||
ConFont = V_GetFont("ConsoleFont", "CONFONT");
|
||||
V_GetFont("IndexFont", "INDEXFON"); // detect potential replacements for this one.
|
||||
}
|
||||
|
||||
void V_LoadTranslations()
|
||||
|
|
|
@ -143,7 +143,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
|
|||
{
|
||||
pos++;
|
||||
}
|
||||
lastcolor = FString((const char*)cstart, pos - start);
|
||||
lastcolor = FString((const char*)cstart, pos - cstart);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -910,7 +910,7 @@ static void ParseOptionSettings(FScanner &sc)
|
|||
else if (sc.Compare("Linespacing"))
|
||||
{
|
||||
sc.MustGetNumber();
|
||||
OptionSettings.mLinespacing = sc.Number;
|
||||
// ignored
|
||||
}
|
||||
else if (sc.Compare("LabelOffset"))
|
||||
{
|
||||
|
@ -1402,6 +1402,7 @@ void M_ParseMenuDefs()
|
|||
DefaultOptionMenuSettings = Create<DOptionMenuDescriptor>();
|
||||
DefaultListMenuSettings->Reset();
|
||||
DefaultOptionMenuSettings->Reset();
|
||||
OptionSettings.mLinespacing = 17;
|
||||
|
||||
int IWADMenu = fileSystem.CheckNumForName("MENUDEF", ns_global, fileSystem.GetIwadNum());
|
||||
|
||||
|
|
|
@ -229,6 +229,7 @@ DObject::DObject ()
|
|||
ObjNext = GC::Root;
|
||||
GCNext = nullptr;
|
||||
GC::Root = this;
|
||||
GC::AllocCount++;
|
||||
}
|
||||
|
||||
DObject::DObject (PClass *inClass)
|
||||
|
@ -238,6 +239,7 @@ DObject::DObject (PClass *inClass)
|
|||
ObjNext = GC::Root;
|
||||
GCNext = nullptr;
|
||||
GC::Root = this;
|
||||
GC::AllocCount++;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -275,6 +277,7 @@ DObject::~DObject ()
|
|||
|
||||
void DObject::Release()
|
||||
{
|
||||
if (GC::AllocCount > 0) GC::AllocCount--;
|
||||
DObject **probe;
|
||||
|
||||
// Unlink this object from the GC list.
|
||||
|
|
|
@ -108,6 +108,7 @@ namespace GC
|
|||
size_t AllocBytes;
|
||||
size_t Threshold;
|
||||
size_t Estimate;
|
||||
size_t AllocCount;
|
||||
DObject *Gray;
|
||||
DObject *Root;
|
||||
DObject *SoftRoots;
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace GC
|
|||
// Number of bytes currently allocated through M_Malloc/M_Realloc.
|
||||
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.
|
||||
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.
|
||||
static inline void CheckGC()
|
||||
static inline bool CheckGC()
|
||||
{
|
||||
AllocCount = 0;
|
||||
if (AllocBytes >= Threshold)
|
||||
{
|
||||
Step();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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];
|
||||
bool deletebuffer=false;
|
||||
|
||||
/*
|
||||
if (forcenocompression)
|
||||
{
|
||||
texformat = GL_RGBA8;
|
||||
}
|
||||
*/
|
||||
// When running in SW mode buffer will be null, so set it to the texBuffer already created
|
||||
// There could be other use cases I do not know about which means this is a bad idea..
|
||||
if (buffer == nullptr)
|
||||
buffer = texBuffer;
|
||||
|
||||
bool firstCall = glTexID == 0;
|
||||
if (firstCall)
|
||||
{
|
||||
|
@ -136,9 +135,19 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
sourcetype = GL_BGRA;
|
||||
texformat = GL_BGRA;
|
||||
#else
|
||||
sourcetype = GL_BGRA;
|
||||
texformat = GL_RGBA;
|
||||
if (glTextureBytes == 1)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
sourcetype = GL_RED;
|
||||
texformat = GL_R8;
|
||||
}
|
||||
else
|
||||
{
|
||||
sourcetype = GL_BGRA;
|
||||
texformat = GL_RGBA;
|
||||
}
|
||||
#endif
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, sourcetype, GL_UNSIGNED_BYTE, 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()
|
||||
{
|
||||
if (glTexID != 0) glDeleteTextures(1, &glTexID);
|
||||
|
||||
if (texBuffer)
|
||||
delete[] texBuffer;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ private:
|
|||
|
||||
unsigned int glTexID = 0;
|
||||
unsigned int glDepthID = 0; // only used by camera textures
|
||||
uint8_t* texBuffer;
|
||||
|
||||
int glTextureBytes;
|
||||
bool mipmapped = false;
|
||||
|
||||
|
@ -52,6 +54,8 @@ public:
|
|||
{
|
||||
forcenofilter = disablefilter;
|
||||
glTextureBytes = numchannels;
|
||||
|
||||
texBuffer = nullptr;
|
||||
}
|
||||
|
||||
~FHardwareTexture();
|
||||
|
@ -64,8 +68,8 @@ public:
|
|||
unsigned int Bind(int texunit, bool needmipmap);
|
||||
bool BindOrCreate(FTexture* tex, int texunit, int clampmode, int translation, int flags);
|
||||
|
||||
void AllocateBuffer(int w, int h, int texelsize) {} // Not used
|
||||
uint8_t* MapBuffer() { return 0; } // Not used
|
||||
void AllocateBuffer(int w, int h, int texelsize);
|
||||
uint8_t* MapBuffer();
|
||||
|
||||
unsigned int CreateTexture(unsigned char* buffer, int w, int h, int texunit, bool mipmap, const char* name);
|
||||
unsigned int GetTextureHandle()
|
||||
|
|
|
@ -32,6 +32,10 @@ static void* LoadGLES2Proc(const char* name)
|
|||
{
|
||||
glesLib = dlopen("libGLESv2.so", flags);
|
||||
}
|
||||
if(!glesLib)
|
||||
{
|
||||
glesLib = dlopen("libGLESv2.so.2", flags);
|
||||
}
|
||||
}
|
||||
|
||||
void * ret = NULL;
|
||||
|
|
|
@ -571,7 +571,7 @@ inline BufferBuilder::BufferBuilder()
|
|||
|
||||
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)
|
||||
|
|
|
@ -127,8 +127,5 @@ void main()
|
|||
ClipDistanceA = vec4(ClipDistance0, ClipDistance1, ClipDistance2, ClipDistance3);
|
||||
ClipDistanceB = vec4(ClipDistance4, 0.0, 0.0, 0.0);
|
||||
|
||||
|
||||
//gl_PointSize = 1.0;
|
||||
|
||||
gl_Position = ProjectionMatrix * eyeCoordPos;
|
||||
}
|
||||
|
|
|
@ -14,35 +14,23 @@ vec3 lightContribution(int i, vec3 normal)
|
|||
vec3 lightdir = normalize(lightpos.xyz - pixelpos.xyz);
|
||||
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);
|
||||
|
||||
|
||||
// NOTE, all spot light stuff gone
|
||||
return lightcolor.rgb * attenuation;
|
||||
#if (DEF_HAS_SPOTLIGHT == 1) // Only perform test below if there are ANY spot lights on this surface.
|
||||
|
||||
/*
|
||||
if (lightspot1.w == 1.0)
|
||||
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
|
||||
|
||||
#endif
|
||||
|
||||
if (lightcolor.a < 0.0) // Sign bit is the attenuated light flag
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
return vec3(0.0);
|
||||
}
|
||||
*/
|
||||
return lightcolor.rgb * attenuation;
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,8 +42,8 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
|
|||
#if (DEF_DYNAMIC_LIGHTS_MOD == 1)
|
||||
// modulated lights
|
||||
|
||||
// Some very old GLES2 hardward 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
|
||||
// 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', so use stupid hack
|
||||
#if (USE_GLSL_V100 == 1)
|
||||
|
||||
for(int i = 0; i < 8; i++) // Max 8 lights
|
||||
|
|
Loading…
Reference in a new issue