- handle textures in the render state.

This should complete the transition and allow storing the render state in an array so that Polymost can be rewritten to create draw lists instead of actually doing the rendering itself.
This commit is contained in:
Christoph Oelckers 2020-01-04 23:58:26 +01:00
parent f6251cdf66
commit e61e77fb82
4 changed files with 47 additions and 45 deletions

View file

@ -75,6 +75,7 @@ struct PolymostRenderState
PalEntry ClearColor = 0; PalEntry ClearColor = 0;
short vp_x, vp_y, vp_w, vp_h; short vp_x, vp_y, vp_w, vp_h;
short sc_x, sc_y, sc_w, sc_h; short sc_x, sc_y, sc_w, sc_h;
int texIds[5], samplerIds[5];
PalEntry FogColor; PalEntry FogColor;

View file

@ -84,7 +84,6 @@ void GLInstance::Init(int ydim)
if (!mSamplers) if (!mSamplers)
{ {
mSamplers = new FSamplerManager; mSamplers = new FSamplerManager;
memset(LastBoundTextures, 0, sizeof(LastBoundTextures));
} }
//glinfo.bufferstorage = !!strstr(glinfo.extensions, "GL_ARB_buffer_storage"); //glinfo.bufferstorage = !!strstr(glinfo.extensions, "GL_ARB_buffer_storage");
@ -279,41 +278,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
matrixArray.Resize(1); matrixArray.Resize(1);
} }
void GLInstance::BindTexture(int texunit, FHardwareTexture *tex, int sampler)
{
if (!tex) return;
if (texunit == 0 && tex->isIndexed())
{
renderState.Flags |= RF_UsePalette;
}
else renderState.Flags &= ~RF_UsePalette;
if (texunit != 0) glActiveTexture(GL_TEXTURE0 + texunit);
glBindTexture(GL_TEXTURE_2D, tex->GetTextureHandle());
mSamplers->Bind(texunit, sampler == NoSampler? tex->GetSampler() : sampler, 0);
if (texunit != 0) glActiveTexture(GL_TEXTURE0);
LastBoundTextures[texunit] = tex->GetTextureHandle();
if (texunit == 0) texv = tex;
}
void GLInstance::UnbindTexture(int texunit)
{
if (LastBoundTextures[texunit] != 0)
{
if (texunit != 0) glActiveTexture(GL_TEXTURE0+texunit);
glBindTexture(GL_TEXTURE_2D, 0);
if (texunit != 0) glActiveTexture(GL_TEXTURE0);
LastBoundTextures[texunit] = 0;
}
}
void GLInstance::UnbindAllTextures()
{
for(int texunit = 0; texunit < MAX_TEXTURES; texunit++)
{
UnbindTexture(texunit);
}
}
void GLInstance::SetMatrix(int num, const VSMatrix *mat) void GLInstance::SetMatrix(int num, const VSMatrix *mat)
{ {
@ -373,8 +337,26 @@ void GLInstance::DrawImGui(ImDrawData* data)
#endif #endif
} }
void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
{ {
bool reset = false;
for (int i = 0; i < 5; i++)
{
if (texIds[i] != oldState.TexId[i] || samplerIds[i] != oldState.SamplerId[i])
{
if (i != 0)
{
glActiveTexture(GL_TEXTURE0 + i);
reset = true;
}
glBindTexture(GL_TEXTURE_2D, texIds[i]);
glBindSampler(i, samplerIds[i]);
oldState.TexId[i] = texIds[i];
oldState.SamplerId[i] = samplerIds[i];
}
if (reset) glActiveTexture(GL_TEXTURE0);
}
if (StateFlags != oldState.Flags) if (StateFlags != oldState.Flags)
{ {
if ((StateFlags ^ oldState.Flags) & STF_DEPTHTEST) if ((StateFlags ^ oldState.Flags) & STF_DEPTHTEST)

View file

@ -170,19 +170,16 @@ struct GLState
int Flags = STF_COLORMASK | STF_DEPTHMASK; int Flags = STF_COLORMASK | STF_DEPTHMASK;
FRenderStyle Style{}; FRenderStyle Style{};
int DepthFunc = -1; int DepthFunc = -1;
int TexId[5] = {}, SamplerId[5] = {};
}; };
class GLInstance class GLInstance
{ {
enum enum
{ {
MAX_TEXTURES = 15, // slot 15 is used internally and not available. MAX_TEXTURES = 5, /*15*/ // slot 15 is used internally and not available. - The renderer uses only 5, though.
THCACHESIZE = 200,
}; };
std::vector<BaseVertex> Buffer; // cheap-ass implementation. The primary purpose is to get the GL accesses out of polymost.cpp, not writing something performant right away. std::vector<BaseVertex> Buffer; // cheap-ass implementation. The primary purpose is to get the GL accesses out of polymost.cpp, not writing something performant right away.
unsigned int LastBoundTextures[MAX_TEXTURES];
unsigned TextureHandleCache[THCACHESIZE];
int currentindex = THCACHESIZE;
int maxTextureSize; int maxTextureSize;
PaletteManager palmanager; PaletteManager palmanager;
int lastPalswapIndex = -1; int lastPalswapIndex = -1;
@ -232,9 +229,6 @@ public:
void Draw(EDrawType type, size_t start, size_t count); void Draw(EDrawType type, size_t start, size_t count);
FHardwareTexture* NewTexture(); FHardwareTexture* NewTexture();
void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler);
void UnbindTexture(int texunit);
void UnbindAllTextures();
void EnableNonTransparent255(bool on) void EnableNonTransparent255(bool on)
{ {
g_nontransparent255 = on; g_nontransparent255 = on;
@ -441,6 +435,31 @@ public:
SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f));
} }
void BindTexture(int texunit, FHardwareTexture* tex, int sampler = NoSampler)
{
if (!tex) return;
if (texunit == 0)
{
if (tex->isIndexed()) renderState.Flags |= RF_UsePalette;
else renderState.Flags &= ~RF_UsePalette;
}
renderState.texIds[texunit] = tex->GetTextureHandle();
renderState.samplerIds[texunit] = sampler == NoSampler ? tex->GetSampler() : sampler;
}
void UnbindTexture(int texunit)
{
renderState.texIds[texunit] = 0;
renderState.samplerIds[texunit] = 0;
}
void UnbindAllTextures()
{
for (int texunit = 0; texunit < MAX_TEXTURES; texunit++)
{
UnbindTexture(texunit);
}
}
void UseColorOnly(bool yes) void UseColorOnly(bool yes)
{ {

View file

@ -6483,7 +6483,7 @@ DoPlayerBeginDie(PLAYERp pp)
{ {
bak = GlobInfoStringTime; bak = GlobInfoStringTime;
GlobInfoStringTime = 999; GlobInfoStringTime = 999;
PutStringInfo(pp, GStrings("TXT_PRESSSPACER")); PutStringInfo(pp, GStrings("TXT_PRESSSPACE"));
GlobInfoStringTime = bak; GlobInfoStringTime = bak;
} }