mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-29 07:22:07 +00:00
- use vertex buffer for all the common 2D rendering functions.
This commit is contained in:
parent
09ba62fbef
commit
f5ea31b518
3 changed files with 172 additions and 65 deletions
|
@ -49,8 +49,6 @@
|
|||
#include "gl/data/gl_vertexbuffer.h"
|
||||
|
||||
|
||||
const int BUFFER_SIZE = 2000000;
|
||||
|
||||
CUSTOM_CVAR(Int, gl_usevbo, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
if (self < -1 || self > 1 || !(gl.flags & RFL_BUFFER_STORAGE))
|
||||
|
@ -105,6 +103,7 @@ FFlatVertexBuffer::FFlatVertexBuffer()
|
|||
{
|
||||
map = NULL;
|
||||
}
|
||||
mIndex = mCurIndex = 0;
|
||||
}
|
||||
|
||||
FFlatVertexBuffer::~FFlatVertexBuffer()
|
||||
|
@ -296,7 +295,7 @@ void FFlatVertexBuffer::CreateVBO()
|
|||
{
|
||||
CreateFlatVBO();
|
||||
memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex));
|
||||
mIndex = vbo_shadowdata.Size();
|
||||
mCurIndex = mIndex = vbo_shadowdata.Size();
|
||||
}
|
||||
else if (sectors)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,8 @@ class FFlatVertexBuffer : public FVertexBuffer
|
|||
|
||||
void CheckPlanes(sector_t *sector);
|
||||
|
||||
const unsigned int BUFFER_SIZE = 2000000;
|
||||
|
||||
public:
|
||||
int vbo_arg;
|
||||
TArray<FFlatVertex> vbo_shadowdata; // this is kept around for updating the actual (non-readable) buffer
|
||||
|
@ -68,6 +70,7 @@ public:
|
|||
unsigned int diff = newofs - mCurIndex;
|
||||
*poffset = mCurIndex;
|
||||
mCurIndex = newofs;
|
||||
if (mCurIndex >= BUFFER_SIZE) mCurIndex = mIndex;
|
||||
return diff;
|
||||
}
|
||||
#ifdef __GL_PCH_H // we need the system includes for this but we cannot include them ourselves without creating #define clashes. The affected files wouldn't try to draw anyway.
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "gl/system/gl_interface.h"
|
||||
#include "gl/system/gl_framebuffer.h"
|
||||
#include "gl/system/gl_threads.h"
|
||||
#include "gl/system/gl_cvars.h"
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/renderer/gl_lightdata.h"
|
||||
#include "gl/renderer/gl_renderstate.h"
|
||||
|
@ -106,6 +107,7 @@ void FGLRenderer::Initialize()
|
|||
gllight = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/gllight.png"), FTexture::TEX_MiscPatch);
|
||||
|
||||
mVBO = new FFlatVertexBuffer;
|
||||
gl_RenderState.SetVertexBuffer(mVBO);
|
||||
mFBID = 0;
|
||||
SetupLevel();
|
||||
mShaderManager = new FShaderManager;
|
||||
|
@ -278,20 +280,36 @@ void FGLRenderer::ClearBorders()
|
|||
gl_RenderState.EnableTexture(false);
|
||||
gl_RenderState.Apply();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
// upper quad
|
||||
glVertex2i(0, borderHeight);
|
||||
glVertex2i(0, 0);
|
||||
glVertex2i(width, 0);
|
||||
glVertex2i(width, borderHeight);
|
||||
|
||||
// lower quad
|
||||
glVertex2i(0, trueHeight);
|
||||
glVertex2i(0, trueHeight - borderHeight);
|
||||
glVertex2i(width, trueHeight - borderHeight);
|
||||
glVertex2i(width, trueHeight);
|
||||
glEnd();
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
// upper quad
|
||||
glVertex2i(0, borderHeight);
|
||||
glVertex2i(0, 0);
|
||||
glVertex2i(width, 0);
|
||||
glVertex2i(width, borderHeight);
|
||||
|
||||
// lower quad
|
||||
glVertex2i(0, trueHeight);
|
||||
glVertex2i(0, trueHeight - borderHeight);
|
||||
glVertex2i(width, trueHeight - borderHeight);
|
||||
glVertex2i(width, trueHeight);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(0, borderHeight, 0, 0, 0); ptr++;
|
||||
ptr->Set(0, 0, 0, 0, 0); ptr++;
|
||||
ptr->Set(width, 0, 0, 0, 0); ptr++;
|
||||
ptr->Set(width, borderHeight, 0, 0, 0); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
||||
ptr->Set(0, trueHeight, 0, 0, 0); ptr++;
|
||||
ptr->Set(0, trueHeight - borderHeight, 0, 0, 0); ptr++;
|
||||
ptr->Set(width, trueHeight - borderHeight, 0, 0, 0); ptr++;
|
||||
ptr->Set(width, trueHeight, 0, 0, 0); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
||||
}
|
||||
gl_RenderState.EnableTexture(true);
|
||||
|
||||
glViewport(0, (trueHeight - height) / 2, width, height);
|
||||
|
@ -391,25 +409,8 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms)
|
|||
gl_RenderState.SetColor(color);
|
||||
gl_RenderState.EnableAlphaTest(false);
|
||||
gl_RenderState.Apply();
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(u1, v1);
|
||||
glVertex2d(x, y);
|
||||
glTexCoord2f(u1, v2);
|
||||
glVertex2d(x, y + h);
|
||||
glTexCoord2f(u2, v1);
|
||||
glVertex2d(x + w, y);
|
||||
glTexCoord2f(u2, v2);
|
||||
glVertex2d(x + w, y + h);
|
||||
glEnd();
|
||||
|
||||
if (parms.colorOverlay)
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
gl_RenderState.SetTextureMode(TM_MASK);
|
||||
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl_RenderState.BlendEquation(GL_FUNC_ADD);
|
||||
gl_RenderState.SetColor(PalEntry(parms.colorOverlay));
|
||||
gl_RenderState.Apply();
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(u1, v1);
|
||||
glVertex2d(x, y);
|
||||
|
@ -421,6 +422,47 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms)
|
|||
glVertex2d(x + w, y + h);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(x, y, 0, u1, v1); ptr++;
|
||||
ptr->Set(x, y + h, 0, u1, v2); ptr++;
|
||||
ptr->Set(x + w, y, 0, u2, v1); ptr++;
|
||||
ptr->Set(x + w, y + h, 0, u2, v2); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
||||
}
|
||||
|
||||
if (parms.colorOverlay)
|
||||
{
|
||||
gl_RenderState.SetTextureMode(TM_MASK);
|
||||
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl_RenderState.BlendEquation(GL_FUNC_ADD);
|
||||
gl_RenderState.SetColor(PalEntry(parms.colorOverlay));
|
||||
gl_RenderState.Apply();
|
||||
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(u1, v1);
|
||||
glVertex2d(x, y);
|
||||
glTexCoord2f(u1, v2);
|
||||
glVertex2d(x, y + h);
|
||||
glTexCoord2f(u2, v1);
|
||||
glVertex2d(x + w, y);
|
||||
glTexCoord2f(u2, v2);
|
||||
glVertex2d(x + w, y + h);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(x, y, 0, u1, v1); ptr++;
|
||||
ptr->Set(x, y + h, 0, u1, v2); ptr++;
|
||||
ptr->Set(x + w, y, 0, u2, v1); ptr++;
|
||||
ptr->Set(x + w, y + h, 0, u2, v2); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
||||
}
|
||||
}
|
||||
|
||||
gl_RenderState.EnableAlphaTest(true);
|
||||
|
||||
|
@ -442,10 +484,20 @@ void FGLRenderer::DrawLine(int x1, int y1, int x2, int y2, int palcolor, uint32
|
|||
gl_RenderState.EnableTexture(false);
|
||||
gl_RenderState.SetColorAlpha(p, 1.f);
|
||||
gl_RenderState.Apply();
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(x1, y1);
|
||||
glVertex2i(x2, y2);
|
||||
glEnd();
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(x1, y1);
|
||||
glVertex2i(x2, y2);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(x1, y1, 0, 0, 0); ptr++;
|
||||
ptr->Set(x2, y2, 0, 0, 0); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_LINES);
|
||||
}
|
||||
gl_RenderState.EnableTexture(true);
|
||||
}
|
||||
|
||||
|
@ -460,9 +512,18 @@ void FGLRenderer::DrawPixel(int x1, int y1, int palcolor, uint32 color)
|
|||
gl_RenderState.EnableTexture(false);
|
||||
gl_RenderState.SetColorAlpha(p, 1.f);
|
||||
gl_RenderState.Apply();
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2i(x1, y1);
|
||||
glEnd();
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2i(x1, y1);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(x1, y1, 0, 0, 0); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_POINTS);
|
||||
}
|
||||
gl_RenderState.EnableTexture(true);
|
||||
}
|
||||
|
||||
|
@ -480,13 +541,24 @@ void FGLRenderer::Dim(PalEntry color, float damount, int x1, int y1, int w, int
|
|||
gl_RenderState.SetColorAlpha(color, damount);
|
||||
gl_RenderState.Apply();
|
||||
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex2i(x1, y1);
|
||||
glVertex2i(x1, y1 + h);
|
||||
glVertex2i(x1 + w, y1 + h);
|
||||
glVertex2i(x1 + w, y1);
|
||||
glEnd();
|
||||
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex2i(x1, y1);
|
||||
glVertex2i(x1, y1 + h);
|
||||
glVertex2i(x1 + w, y1 + h);
|
||||
glVertex2i(x1 + w, y1);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(x1, y1, 0, 0, 0); ptr++;
|
||||
ptr->Set(x1, y1+h, 0, 0, 0); ptr++;
|
||||
ptr->Set(x1+w, y1+h, 0, 0, 0); ptr++;
|
||||
ptr->Set(x1+w, y1, 0, 0, 0); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN);
|
||||
}
|
||||
gl_RenderState.EnableTexture(true);
|
||||
}
|
||||
|
||||
|
@ -522,12 +594,24 @@ void FGLRenderer::FlatFill (int left, int top, int right, int bottom, FTexture *
|
|||
}
|
||||
gl_RenderState.ResetColor();
|
||||
gl_RenderState.Apply();
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(fU1, fV1); glVertex2f(left, top);
|
||||
glTexCoord2f(fU1, fV2); glVertex2f(left, bottom);
|
||||
glTexCoord2f(fU2, fV1); glVertex2f(right, top);
|
||||
glTexCoord2f(fU2, fV2); glVertex2f(right, bottom);
|
||||
glEnd();
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(fU1, fV1); glVertex2f(left, top);
|
||||
glTexCoord2f(fU1, fV2); glVertex2f(left, bottom);
|
||||
glTexCoord2f(fU2, fV1); glVertex2f(right, top);
|
||||
glTexCoord2f(fU2, fV2); glVertex2f(right, bottom);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
ptr->Set(left, top, 0, fU1, fV1); ptr++;
|
||||
ptr->Set(left, bottom, 0, fU1, fV2); ptr++;
|
||||
ptr->Set(right, top, 0, fU2, fV1); ptr++;
|
||||
ptr->Set(right, bottom, 0, fU2, fV2); ptr++;
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -615,20 +699,41 @@ void FGLRenderer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoint
|
|||
float oy = float(originy);
|
||||
|
||||
gl_RenderState.Apply();
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
for (i = 0; i < npoints; ++i)
|
||||
if (!gl_usevbo)
|
||||
{
|
||||
float u = points[i].X - 0.5f - ox;
|
||||
float v = points[i].Y - 0.5f - oy;
|
||||
if (dorotate)
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
for (i = 0; i < npoints; ++i)
|
||||
{
|
||||
float t = u;
|
||||
u = t * cosrot - v * sinrot;
|
||||
v = v * cosrot + t * sinrot;
|
||||
float u = points[i].X - 0.5f - ox;
|
||||
float v = points[i].Y - 0.5f - oy;
|
||||
if (dorotate)
|
||||
{
|
||||
float t = u;
|
||||
u = t * cosrot - v * sinrot;
|
||||
v = v * cosrot + t * sinrot;
|
||||
}
|
||||
glTexCoord2f(u * uscale, v * vscale);
|
||||
glVertex3f(points[i].X, points[i].Y /* + yoffs */, 0);
|
||||
}
|
||||
glTexCoord2f(u * uscale, v * vscale);
|
||||
glVertex3f(points[i].X, points[i].Y /* + yoffs */, 0);
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer();
|
||||
for (i = 0; i < npoints; ++i)
|
||||
{
|
||||
float u = points[i].X - 0.5f - ox;
|
||||
float v = points[i].Y - 0.5f - oy;
|
||||
if (dorotate)
|
||||
{
|
||||
float t = u;
|
||||
u = t * cosrot - v * sinrot;
|
||||
v = v * cosrot + t * sinrot;
|
||||
}
|
||||
ptr->Set(points[i].X, points[i].Y, 0, u*uscale, v*vscale);
|
||||
ptr++;
|
||||
}
|
||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue