- preparation for moving GL state into the renderstate struct.

This commit is contained in:
Christoph Oelckers 2020-01-02 23:15:16 +01:00
parent 85593e3e93
commit 6156e7382a
4 changed files with 26 additions and 18 deletions

View file

@ -63,7 +63,7 @@ unsigned int FHardwareTexture::CreateTexture(int w, int h, int type, bool mipmap
{ {
static int gltypes[] = { GL_R8, GL_RGBA8, GL_RGB5_A1, GL_RGBA2 }; static int gltypes[] = { GL_R8, GL_RGBA8, GL_RGB5_A1, GL_RGBA2 };
static uint8_t bytes[] = { 1, 4, 2, 1 }; static uint8_t bytes[] = { 1, 4, 2, 1 };
glTexID = GLInterface.GetTextureID(); glGenTextures(1, &glTexID);
glActiveTexture(GL_TEXTURE15); glActiveTexture(GL_TEXTURE15);
glBindTexture(GL_TEXTURE_2D, glTexID); glBindTexture(GL_TEXTURE_2D, glTexID);
int size = std::max(w, h); int size = std::max(w, h);

View file

@ -22,6 +22,19 @@ enum PRSFlags
RF_HICTINT_BLEND_Overlay = 0x100000, RF_HICTINT_BLEND_Overlay = 0x100000,
RF_HICTINT_BLEND_Hardlight = 0x200000, RF_HICTINT_BLEND_Hardlight = 0x200000,
RF_HICTINT_BLENDMASK = RF_HICTINT_BLEND_Screen | RF_HICTINT_BLEND_Overlay | RF_HICTINT_BLEND_Hardlight, RF_HICTINT_BLENDMASK = RF_HICTINT_BLEND_Screen | RF_HICTINT_BLEND_Overlay | RF_HICTINT_BLEND_Hardlight,
STF_BLEND = 1,
STF_COLORMASK = 2,
STF_DEPTHMASK = 4,
STF_DEPTHTEST = 8,
STF_MULTISAMPLE = 16,
STF_STENCILWRITE = 32,
STF_STENCILTEST = 64,
STF_CULLCW = 128,
STF_CULLCCW = 256,
STF_WIREFRAME = 512,
}; };
struct PolymostRenderState struct PolymostRenderState
@ -37,11 +50,13 @@ struct PolymostRenderState
float AlphaThreshold = 0.5f; float AlphaThreshold = 0.5f;
bool AlphaTest = true; bool AlphaTest = true;
int StateFlags = STF_COLORMASK|STF_DEPTHMASK;
PalEntry FogColor; PalEntry FogColor;
IVertexBuffer* VertexBuffer = nullptr; IVertexBuffer* VertexBuffer = nullptr;
int VB_Offset[2] = {}; int VB_Offset[2] = {};
IIndexBuffer* IndexBuffer = nullptr; IIndexBuffer* IndexBuffer = nullptr;
void Apply(PolymostShader *shader); void Apply(PolymostShader *shader, int &oldstate);
}; };

View file

@ -194,6 +194,12 @@ void GLInstance::Deinit()
lastPalswapIndex = -1; lastPalswapIndex = -1;
} }
FHardwareTexture* GLInstance::NewTexture()
{
return new FHardwareTexture;
}
std::pair<size_t, BaseVertex *> GLInstance::AllocVertices(size_t num) std::pair<size_t, BaseVertex *> GLInstance::AllocVertices(size_t num)
{ {
Buffer.resize(num); Buffer.resize(num);
@ -227,7 +233,7 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
if (activeShader == polymostShader) if (activeShader == polymostShader)
{ {
if (istrans) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all. if (istrans) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all.
renderState.Apply(polymostShader); renderState.Apply(polymostShader, lastState);
if (renderState.VertexBuffer != LastVertexBuffer || LastVB_Offset[0] != renderState.VB_Offset[0] || LastVB_Offset[1] != renderState.VB_Offset[1]) if (renderState.VertexBuffer != LastVertexBuffer || LastVB_Offset[0] != renderState.VB_Offset[0] || LastVB_Offset[1] != renderState.VB_Offset[1])
{ {
if (renderState.VertexBuffer) if (renderState.VertexBuffer)
@ -271,19 +277,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
if (MatrixChange) RestoreTextureProps(); if (MatrixChange) RestoreTextureProps();
} }
int GLInstance::GetTextureID()
{
uint32_t id = 0;
glGenTextures(1, &id);
return id;
}
FHardwareTexture* GLInstance::NewTexture()
{
return new FHardwareTexture;
}
void GLInstance::BindTexture(int texunit, FHardwareTexture *tex, int sampler) void GLInstance::BindTexture(int texunit, FHardwareTexture *tex, int sampler)
{ {
if (!tex) return; if (!tex) return;
@ -540,7 +533,7 @@ void GLInstance::ClearScreen(PalEntry color)
} }
void PolymostRenderState::Apply(PolymostShader* shader) void PolymostRenderState::Apply(PolymostShader* shader, int &oldstate)
{ {
// Disable brightmaps if non-black fog is used. // Disable brightmaps if non-black fog is used.
if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping; if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping;

View file

@ -196,6 +196,7 @@ class GLInstance
int MatrixChange = 0; int MatrixChange = 0;
bool istrans = false; bool istrans = false;
bool g_nontransparent255 = false; // Ugh... This is for movie playback and needs to be maintained as global state. bool g_nontransparent255 = false; // Ugh... This is for movie playback and needs to be maintained as global state.
int lastState = STF_COLORMASK | STF_DEPTHMASK;
IVertexBuffer* LastVertexBuffer = nullptr; IVertexBuffer* LastVertexBuffer = nullptr;
int LastVB_Offset[2] = {}; int LastVB_Offset[2] = {};
@ -234,7 +235,6 @@ public:
std::pair<size_t, BaseVertex *> AllocVertices(size_t num); std::pair<size_t, BaseVertex *> AllocVertices(size_t num);
void Draw(EDrawType type, size_t start, size_t count); void Draw(EDrawType type, size_t start, size_t count);
int GetTextureID();
FHardwareTexture* NewTexture(); FHardwareTexture* NewTexture();
void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler); void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler);
void UnbindTexture(int texunit); void UnbindTexture(int texunit);