- draw the screen overlays using the vertex buffer.

This commit is contained in:
Christoph Oelckers 2020-01-18 13:23:01 +01:00
parent 1a916c0a76
commit 2e06ccfec6
8 changed files with 58 additions and 44 deletions

View File

@ -437,7 +437,7 @@ int32_t animvpx_render_frame(animvpx_codec_ctx *codec, double animvpx_aspect)
vt[3].SetTexCoord(1.0,1.0);
vt[3].SetVertex(x, -y, 0.0);
GLInterface.Draw(DT_TRIANGLE_FAN, data.first, 4);
GLInterface.DrawIm(DT_TRIANGLE_FAN, data.first, 4);
t = timerGetTicks()-t;
codec->sumtimes[2] += t;

View File

@ -83,5 +83,5 @@ void glsurface_blitBuffer()
vt[1].Set(-1.0f, -1.0f, 0.0f, 0.0f, 1.0f); //bottom-left
vt[2].Set(1.0f, 1.0f, 0.0f, 1.0f, 0.0f); //top-right
vt[3].Set(1.0f, -1.0f, 0.0f, 1.0f, 1.0f); //bottom-right
GLInterface.Draw(DT_TRIANGLE_STRIP, data.first, 4);
GLInterface.DrawIm(DT_TRIANGLE_STRIP, data.first, 4);
}

View File

@ -1470,7 +1470,7 @@ static void md3draw_handle_triangles(const md3surf_t *s, uint16_t *indexhandle,
vt->SetVertex(vertlist[k].x, vertlist[k].y);
}
}
GLInterface.Draw(DT_TRIANGLES, data.first, s->numtris *3);
GLInterface.DrawIm(DT_TRIANGLES, data.first, s->numtris *3);
#ifndef USE_GLEXT
UNREFERENCED_PARAMETER(texunits);

View File

@ -599,7 +599,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
r * (1.f / 1024.f));
}
GLInterface.Draw(DT_TRIANGLE_FAN, data.first, npoints);
GLInterface.DrawIm(DT_TRIANGLE_FAN, data.first, npoints);
GLInterface.SetTinting(0, 0, PalEntry(255, 255, 255));
GLInterface.UseDetailMapping(false);

View File

@ -1152,7 +1152,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
f = 1 /*clut[fi++]*/;
if (qdone > 0)
{
GLInterface.Draw(DT_TRIANGLES, qstart, qdone * 6);
GLInterface.DrawIm(DT_TRIANGLES, qstart, qdone * 6);
qstart += qdone * 6;
qdone = 0;
}
@ -1182,7 +1182,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
qdone++;
}
GLInterface.Draw(DT_TRIANGLES, qstart, qdone * 6);
GLInterface.DrawIm(DT_TRIANGLES, qstart, qdone * 6);
GLInterface.SetClamp(prevClamp);
//------------
GLInterface.SetCull(Cull_None);

View File

@ -47,6 +47,7 @@
#include "gl_interface.h"
#include "v_2ddrawer.h"
#include "v_video.h"
#include "flatvertices.h"
#include "gl_renderer.h"
float shadediv[MAXPALOOKUPS];
@ -174,6 +175,7 @@ void GLInstance::InitGLState(int fogmode, int multisample)
screen->BeginFrame();
bool useSSAO = (gl_ssao != 0);
OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(useSSAO);
ClearBufferState();
}
void GLInstance::Deinit()
@ -212,6 +214,17 @@ void GLInstance::ResetFrame()
}
void GLInstance::ClearBufferState()
{
auto buffer = (screen->mVertexData->GetBufferObjects().first);
SetVertexBuffer(buffer, 0, 0);
SetIndexBuffer(nullptr);
// Invalidate the pointers as well to make sure that if another buffer with the same address is used it actually gets bound.
LastVertexBuffer = (IVertexBuffer*)~intptr_t(0);
LastIndexBuffer = (IIndexBuffer*)~intptr_t(0);
}
std::pair<size_t, BaseVertex *> GLInstance::AllocVertices(size_t num)
{
@ -227,6 +240,36 @@ static GLint primtypes[] =
GL_LINES
};
void GLInstance::DrawIm(EDrawType type, size_t start, size_t count)
{
// Todo: Based on the current tinting flags and the texture type (indexed texture and APPLYOVERPALSWAP not set) this may have to reset the palette for the draw call / texture creation.
bool applied = false;
if (activeShader == polymostShader)
{
glVertexAttrib4fv(2, renderState.Color);
if (renderState.Color[3] != 1.f) 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, lastState);
}
glBegin(primtypes[type]);
auto p = &Buffer[start];
for (size_t i = 0; i < count; i++, p++)
{
glVertexAttrib2f(1, p->u, p->v);
glVertexAttrib3f(0, p->x, p->y, p->z);
}
glEnd();
if (MatrixChange)
{
if (MatrixChange & 1) SetIdentityMatrix(Matrix_Texture);
if (MatrixChange & 2) SetIdentityMatrix(Matrix_Detail);
MatrixChange = 0;
}
matrixArray.Resize(1);
}
void GLInstance::Draw(EDrawType type, size_t start, size_t count)
{
// Todo: Based on the current tinting flags and the texture type (indexed texture and APPLYOVERPALSWAP not set) this may have to reset the palette for the draw call / texture creation.
@ -258,18 +301,7 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
LastIndexBuffer = renderState.IndexBuffer;
}
}
if (!LastVertexBuffer)
{
glBegin(primtypes[type]);
auto p = &Buffer[start];
for (size_t i = 0; i < count; i++, p++)
{
glVertexAttrib2f(1, p->u, p->v);
glVertexAttrib3f(0, p->x, p->y, p->z);
}
glEnd();
}
else if (type != DT_LINES)
if (type != DT_LINES && renderState.IndexBuffer)
{
glDrawElements(primtypes[type], count, GL_UNSIGNED_INT, (void*)(intptr_t)(start * sizeof(uint32_t)));
}

View File

@ -228,6 +228,7 @@ public:
GLInstance();
std::pair<size_t, BaseVertex *> AllocVertices(size_t num);
void DrawIm(EDrawType type, size_t start, size_t count);
void Draw(EDrawType type, size_t start, size_t count);
FHardwareTexture* NewTexture();
@ -246,14 +247,7 @@ public:
{
renderState.IndexBuffer = vb;
}
void ClearBufferState()
{
SetVertexBuffer(nullptr, 0, 0);
SetIndexBuffer(nullptr);
// Invalidate the pointers as well to make sure that if another buffer with the same address is used it actually gets bound.
LastVertexBuffer = (IVertexBuffer*)~intptr_t(0);
LastIndexBuffer = (IIndexBuffer*)~intptr_t(0);
}
void ClearBufferState();
float GetProjectionM5() { return mProjectionM5; }
void SetMatrix(int num, const VSMatrix *mat );

View File

@ -40,6 +40,7 @@
#include "glbackend.h"
#include "v_draw.h"
#include "palette.h"
#include "flatvertices.h"
extern int16_t numshades;
//===========================================================================
@ -244,12 +245,7 @@ void fullscreen_tint_gl(PalEntry pe)
GLInterface.UseColorOnly(true);
auto data = GLInterface.AllocVertices(3);
auto vt = data.second;
vt[0].Set(-2.5f, 1.f);
vt[1].Set(2.5f, 1.f);
vt[2].Set(.0f, -2.5f);
GLInterface.Draw(DT_TRIANGLES, data.first, 3);
GLInterface.Draw(DT_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4);
GLInterface.UseColorOnly(false);
}
@ -268,20 +264,12 @@ void fullscreen_tint_gl_blood(int tint_blood_r, int tint_blood_g, int tint_blood
GLInterface.UseColorOnly(true);
GLInterface.SetColorub(max(tint_blood_r, 0), max(tint_blood_g, 0), max(tint_blood_b, 0), 255);
auto data = GLInterface.AllocVertices(3);
auto vt = data.second;
vt[0].Set(-2.5f, 1.f);
vt[1].Set(2.5f, 1.f);
vt[2].Set(.0f, -2.5f);
GLInterface.Draw(DT_TRIANGLES, data.first, 3);
GLInterface.Draw(DT_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4);
GLInterface.SetRenderStyle(LegacyRenderStyles[STYLE_Subtract]);
GLInterface.SetColorub(max(-tint_blood_r, 0), max(-tint_blood_g, 0), max(-tint_blood_b, 0), 255);
data = GLInterface.AllocVertices(3);
vt = data.second;
vt[0].Set(-2.5f, 1.f);
vt[1].Set(2.5f, 1.f);
vt[2].Set(.0f, -2.5f);
GLInterface.Draw(DT_TRIANGLES, data.first, 3);
GLInterface.Draw(DT_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4);
GLInterface.SetColorub(255, 255, 255, 255);
GLInterface.SetRenderStyle(LegacyRenderStyles[STYLE_Translucent]);
GLInterface.UseColorOnly(false);