mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-28 23:11:58 +00:00
- took the sky cap color getter out of the texture system.
# Conflicts: # src/common/textures/textures.h
This commit is contained in:
parent
d1da26895b
commit
c563f4993f
10 changed files with 92 additions and 83 deletions
|
@ -158,69 +158,6 @@ void FTexture::SetDisplaySize(int fitwidth, int fitheight)
|
||||||
if (int(Scale.Y * fitheight) != Height) Scale.Y += (1 / 65536.);
|
if (int(Scale.Y * fitheight) != Height) Scale.Y += (1 / 65536.);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
//
|
|
||||||
// Gets the average color of a texture for use as a sky cap color
|
|
||||||
//
|
|
||||||
//===========================================================================
|
|
||||||
|
|
||||||
PalEntry FTexture::averageColor(const uint32_t *data, int size, int maxout)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
unsigned int r, g, b;
|
|
||||||
|
|
||||||
// First clear them.
|
|
||||||
r = g = b = 0;
|
|
||||||
if (size == 0)
|
|
||||||
{
|
|
||||||
return PalEntry(255, 255, 255);
|
|
||||||
}
|
|
||||||
for (i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
b += BPART(data[i]);
|
|
||||||
g += GPART(data[i]);
|
|
||||||
r += RPART(data[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = r / size;
|
|
||||||
g = g / size;
|
|
||||||
b = b / size;
|
|
||||||
|
|
||||||
int maxv = MAX(MAX(r, g), b);
|
|
||||||
|
|
||||||
if (maxv && maxout)
|
|
||||||
{
|
|
||||||
r = ::Scale(r, maxout, maxv);
|
|
||||||
g = ::Scale(g, maxout, maxv);
|
|
||||||
b = ::Scale(b, maxout, maxv);
|
|
||||||
}
|
|
||||||
return PalEntry(255, r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
PalEntry FTexture::GetSkyCapColor(bool bottom)
|
|
||||||
{
|
|
||||||
if (!bSWSkyColorDone)
|
|
||||||
{
|
|
||||||
bSWSkyColorDone = true;
|
|
||||||
|
|
||||||
FBitmap bitmap = GetBgraBitmap(nullptr);
|
|
||||||
int w = bitmap.GetWidth();
|
|
||||||
int h = bitmap.GetHeight();
|
|
||||||
|
|
||||||
const uint32_t *buffer = (const uint32_t *)bitmap.GetPixels();
|
|
||||||
if (buffer)
|
|
||||||
{
|
|
||||||
CeilingSkyColor = averageColor((uint32_t *)buffer, w * MIN(30, h), 0);
|
|
||||||
if (h>30)
|
|
||||||
{
|
|
||||||
FloorSkyColor = averageColor(((uint32_t *)buffer) + (h - 30)*w, w * 30, 0);
|
|
||||||
}
|
|
||||||
else FloorSkyColor = CeilingSkyColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bottom ? FloorSkyColor : CeilingSkyColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
//
|
//
|
||||||
// CheckRealHeight
|
// CheckRealHeight
|
||||||
|
|
|
@ -288,7 +288,6 @@ public:
|
||||||
bool isMasked() const { return bMasked; }
|
bool isMasked() const { return bMasked; }
|
||||||
void SetSkyOffset(int offs) { SkyOffset = offs; }
|
void SetSkyOffset(int offs) { SkyOffset = offs; }
|
||||||
int GetSkyOffset() const { return SkyOffset; }
|
int GetSkyOffset() const { return SkyOffset; }
|
||||||
PalEntry GetSkyCapColor(bool bottom);
|
|
||||||
virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method.
|
virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method.
|
||||||
void GetGlowColor(float *data);
|
void GetGlowColor(float *data);
|
||||||
bool isGlowing() const { return bGlowing; }
|
bool isGlowing() const { return bGlowing; }
|
||||||
|
@ -329,7 +328,6 @@ public:
|
||||||
virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans = nullptr);
|
virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans = nullptr);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -424,14 +422,6 @@ public:
|
||||||
return bTranslucent != -1 ? bTranslucent : DetermineTranslucency();
|
return bTranslucent != -1 ? bTranslucent : DetermineTranslucency();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
int CheckDDPK3();
|
|
||||||
int CheckExternalFile(bool & hascolorkey);
|
|
||||||
|
|
||||||
bool bSWSkyColorDone = false;
|
|
||||||
PalEntry FloorSkyColor;
|
|
||||||
PalEntry CeilingSkyColor;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void CheckTrans(unsigned char * buffer, int size, int trans);
|
void CheckTrans(unsigned char * buffer, int size, int trans);
|
||||||
|
@ -731,7 +721,6 @@ public:
|
||||||
|
|
||||||
const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return 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); }
|
|
||||||
|
|
||||||
bool GetTranslucency()
|
bool GetTranslucency()
|
||||||
{
|
{
|
||||||
|
|
|
@ -471,6 +471,47 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
|
||||||
// 256 entries are different. :-)
|
// 256 entries are different. :-)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Gets the average color of a texture for use as a sky cap color
|
||||||
|
//
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
PalEntry averageColor(const uint32_t* data, int size, int maxout)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned int r, g, b;
|
||||||
|
|
||||||
|
// First clear them.
|
||||||
|
r = g = b = 0;
|
||||||
|
if (size == 0)
|
||||||
|
{
|
||||||
|
return PalEntry(255, 255, 255);
|
||||||
|
}
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
b += BPART(data[i]);
|
||||||
|
g += GPART(data[i]);
|
||||||
|
r += RPART(data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = r / size;
|
||||||
|
g = g / size;
|
||||||
|
b = b / size;
|
||||||
|
|
||||||
|
int maxv = MAX(MAX(r, g), b);
|
||||||
|
|
||||||
|
if (maxv && maxout)
|
||||||
|
{
|
||||||
|
r = ::Scale(r, maxout, maxv);
|
||||||
|
g = ::Scale(g, maxout, maxv);
|
||||||
|
b = ::Scale(b, maxout, maxv);
|
||||||
|
}
|
||||||
|
return PalEntry(255, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// V_GetColorFromString
|
// V_GetColorFromString
|
||||||
|
|
|
@ -30,6 +30,7 @@ FString V_GetColorStringByName(const char* name, FScriptPosition* sc = nullptr);
|
||||||
// Tries to get color by name, then by string
|
// Tries to get color by name, then by string
|
||||||
int V_GetColor(const uint32_t* palette, const char* str, FScriptPosition* sc = nullptr);
|
int V_GetColor(const uint32_t* palette, const char* str, FScriptPosition* sc = nullptr);
|
||||||
int V_GetColor(const uint32_t* palette, FScanner& sc);
|
int V_GetColor(const uint32_t* palette, FScanner& sc);
|
||||||
|
PalEntry averageColor(const uint32_t* data, int size, int maxout);
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,13 +66,12 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture *
|
||||||
// The caps only get drawn for the main layer but not for the overlay.
|
// The caps only get drawn for the main layer but not for the overlay.
|
||||||
if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL)
|
if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL)
|
||||||
{
|
{
|
||||||
PalEntry pe = tex->GetSkyCapColor(false);
|
auto &col = R_GetSkyCapColor(tex);
|
||||||
state.SetObjectColor(pe);
|
state.SetObjectColor(col.first);
|
||||||
state.EnableTexture(false);
|
state.EnableTexture(false);
|
||||||
RenderRow(di, state, DT_TriangleFan, 0);
|
RenderRow(di, state, DT_TriangleFan, 0);
|
||||||
|
|
||||||
pe = tex->GetSkyCapColor(true);
|
state.SetObjectColor(col.second);
|
||||||
state.SetObjectColor(pe);
|
|
||||||
RenderRow(di, state, DT_TriangleFan, rc);
|
RenderRow(di, state, DT_TriangleFan, rc);
|
||||||
state.EnableTexture(true);
|
state.EnableTexture(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,6 @@ void PolyHardwareTexture::Reset()
|
||||||
|
|
||||||
DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state)
|
DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state)
|
||||||
{
|
{
|
||||||
FGameTexture *tex = state.mMaterial->Source();
|
|
||||||
|
|
||||||
if (!mCanvas)
|
if (!mCanvas)
|
||||||
{
|
{
|
||||||
int flags = state.mMaterial->GetScaleFlags();
|
int flags = state.mMaterial->GetScaleFlags();
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include "v_text.h"
|
#include "v_text.h"
|
||||||
#include "g_levellocals.h"
|
#include "g_levellocals.h"
|
||||||
#include "texturemanager.h"
|
#include "texturemanager.h"
|
||||||
|
#include "palentry.h"
|
||||||
|
#include "bitmap.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// sky mapping
|
// sky mapping
|
||||||
|
@ -54,6 +56,46 @@ CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE|CVAR_NOINITCALL)
|
||||||
|
|
||||||
CVAR(Float, skyoffset, 0, 0) // for testing
|
CVAR(Float, skyoffset, 0, 0) // for testing
|
||||||
|
|
||||||
|
|
||||||
|
struct SkyColor
|
||||||
|
{
|
||||||
|
FTextureID Texture;
|
||||||
|
std::pair<PalEntry, PalEntry> Colors;
|
||||||
|
};
|
||||||
|
|
||||||
|
static TArray<SkyColor> SkyColors;
|
||||||
|
|
||||||
|
std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex)
|
||||||
|
{
|
||||||
|
for (auto& sky : SkyColors)
|
||||||
|
{
|
||||||
|
if (sky.Texture == tex->GetID()) return sky.Colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto itex = tex->GetTexture();
|
||||||
|
SkyColor sky;
|
||||||
|
|
||||||
|
FBitmap bitmap = itex->GetBgraBitmap(nullptr);
|
||||||
|
int w = bitmap.GetWidth();
|
||||||
|
int h = bitmap.GetHeight();
|
||||||
|
|
||||||
|
const uint32_t* buffer = (const uint32_t*)bitmap.GetPixels();
|
||||||
|
if (buffer)
|
||||||
|
{
|
||||||
|
sky.Colors.first = averageColor((uint32_t*)buffer, w * MIN(30, h), 0);
|
||||||
|
if (h > 30)
|
||||||
|
{
|
||||||
|
sky.Colors.second = averageColor(((uint32_t*)buffer) + (h - 30) * w, w * 30, 0);
|
||||||
|
}
|
||||||
|
else sky.Colors.second = sky.Colors.first;
|
||||||
|
}
|
||||||
|
sky.Texture = tex->GetID();
|
||||||
|
SkyColors.Push(sky);
|
||||||
|
|
||||||
|
return SkyColors.Last().Colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// R_InitSkyMap
|
// R_InitSkyMap
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#ifndef __R_SKY_H__
|
#ifndef __R_SKY_H__
|
||||||
#define __R_SKY_H__
|
#define __R_SKY_H__
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include "textures.h"
|
#include "textures.h"
|
||||||
|
|
||||||
struct FLevelLocals;
|
struct FLevelLocals;
|
||||||
|
@ -41,6 +42,7 @@ extern int freelookviewheight;
|
||||||
void InitSkyMap(FLevelLocals *Level);
|
void InitSkyMap(FLevelLocals *Level);
|
||||||
void R_InitSkyMap();
|
void R_InitSkyMap();
|
||||||
void R_UpdateSky (uint64_t mstime);
|
void R_UpdateSky (uint64_t mstime);
|
||||||
|
std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex);
|
||||||
|
|
||||||
// 57 world units roughly represent one sky texel for the glTranslate call.
|
// 57 world units roughly represent one sky texel for the glTranslate call.
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -258,8 +258,9 @@ namespace swrenderer
|
||||||
drawerargs.SetDest(viewport, start_x, y1);
|
drawerargs.SetDest(viewport, start_x, y1);
|
||||||
drawerargs.SetCount(y2 - y1);
|
drawerargs.SetCount(y2 - y1);
|
||||||
drawerargs.SetFadeSky(r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY));
|
drawerargs.SetFadeSky(r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY));
|
||||||
drawerargs.SetSolidTop(frontskytex->GetSkyCapColor(false));
|
auto& col = R_GetSkyCapColor(frontskytex->GetTexture());
|
||||||
drawerargs.SetSolidBottom(frontskytex->GetSkyCapColor(true));
|
drawerargs.SetSolidTop(col.first);
|
||||||
|
drawerargs.SetSolidBottom(col.second);
|
||||||
|
|
||||||
if (!backskytex)
|
if (!backskytex)
|
||||||
drawerargs.DrawSingleSkyColumn(Thread);
|
drawerargs.DrawSingleSkyColumn(Thread);
|
||||||
|
|
|
@ -62,7 +62,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetSkyOffset() const { return mTexture->GetSkyOffset(); }
|
int GetSkyOffset() const { return mTexture->GetSkyOffset(); }
|
||||||
PalEntry GetSkyCapColor(bool bottom) const { return mSource->GetSkyCapColor(bottom); }
|
|
||||||
|
|
||||||
int GetWidth () { return mTexture->GetTexelWidth(); }
|
int GetWidth () { return mTexture->GetTexelWidth(); }
|
||||||
int GetHeight () { return mTexture->GetTexelHeight(); }
|
int GetHeight () { return mTexture->GetTexelHeight(); }
|
||||||
|
|
Loading…
Reference in a new issue