From 74ba142eaef5d48ce02c3014314a4a471c145ae0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 20 Oct 2018 11:53:20 +0200 Subject: [PATCH] - allow vertex creation for sprites in the setup pass. Currently only used by legacy hardware. --- src/gl/scene/gl_drawinfo.cpp | 1 - src/gl/scene/gl_flats.cpp | 2 -- src/gl/scene/gl_sprite.cpp | 18 +++++++-------- src/hwrenderer/scene/hw_drawstructs.h | 2 ++ src/hwrenderer/scene/hw_sprites.cpp | 32 ++++++++++++++++++++++++++- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 1aeac50ad..96e250a19 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -40,7 +40,6 @@ #include "hwrenderer/scene/hw_clipper.h" #include "gl/scene/gl_portal.h" #include "gl/renderer/gl_renderstate.h" -#include "gl/renderer/gl_quaddrawer.h" #include "gl/dynlights/gl_lightbuffer.h" class FDrawInfoList diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 5499f1357..04771dd56 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -45,8 +45,6 @@ #include "gl/data/gl_vertexbuffer.h" #include "gl/dynlights/gl_lightbuffer.h" #include "gl/scene/gl_drawinfo.h" -#include "gl/renderer/gl_quaddrawer.h" - //========================================================================== diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 665687d6e..ebf29e3ca 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -48,7 +48,6 @@ #include "gl/renderer/gl_renderer.h" #include "gl/scene/gl_drawinfo.h" #include "gl/models/gl_models.h" -#include "gl/renderer/gl_quaddrawer.h" #include "gl/dynlights/gl_lightbuffer.h" extern uint32_t r_renderercaps; @@ -250,18 +249,17 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) FVector3 v[4]; gl_RenderState.SetNormal(0, 0, 0); - if (sprite->CalculateVertices(this, v, &vp.Pos)) + if ((gl.flags & RFL_BUFFER_STORAGE) && sprite->vertexindex == -1) + { + sprite->CreateVertices(this); + } + if (sprite->polyoffset) { glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(-1.0f, -128.0f); } - - FQuadDrawer qd; - qd.Set(0, v[0][0], v[0][1], v[0][2], sprite->ul, sprite->vt); - qd.Set(1, v[1][0], v[1][1], v[1][2], sprite->ur, sprite->vt); - qd.Set(2, v[2][0], v[2][1], v[2][2], sprite->ul, sprite->vb); - qd.Set(3, v[3][0], v[3][1], v[3][2], sprite->ur, sprite->vb); - qd.Render(GL_TRIANGLE_STRIP); + + glDrawArrays(GL_TRIANGLE_STRIP, sprite->vertexindex, 4); if (foglayer) { @@ -271,7 +269,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.Apply(); - qd.Render(GL_TRIANGLE_STRIP); + glDrawArrays(GL_TRIANGLE_STRIP, sprite->vertexindex, 4); gl_RenderState.SetTextureMode(TM_MODULATE); } } diff --git a/src/hwrenderer/scene/hw_drawstructs.h b/src/hwrenderer/scene/hw_drawstructs.h index 069a5b1cd..ff175efe1 100644 --- a/src/hwrenderer/scene/hw_drawstructs.h +++ b/src/hwrenderer/scene/hw_drawstructs.h @@ -360,6 +360,7 @@ public: int translation; int index; int depth; + int vertexindex; float topclip; float bottomclip; @@ -387,6 +388,7 @@ public: public: GLSprite() {} + void CreateVertices(HWDrawInfo *di); void PutSprite(HWDrawInfo *di, bool translucent); void Process(HWDrawInfo *di, AActor* thing,sector_t * sector, area_t in_area, int thruportal = false); void ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t *sector);//, int shade, int fakeside) diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index abdc50853..99d5d691a 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -46,6 +46,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_portal.h" +#include "hwrenderer/data/flatvertices.h" #include "hwrenderer/utility/hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" @@ -228,10 +229,39 @@ inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent) else dynlightindex = -1; - + vertexindex = -1; + if (!(screen->hwcaps & RFL_BUFFER_STORAGE)) + { + CreateVertices(di); + } di->AddSprite(this, translucent); } +//========================================================================== +// +// +// +//========================================================================== + +void GLSprite::CreateVertices(HWDrawInfo *di) +{ + if (modelframe == nullptr) + { + FVector3 v[4]; + polyoffset = CalculateVertices(di, v, &di->Viewpoint.Pos); + auto vert = di->AllocVertices(4); + auto vp = vert.first; + vertexindex = vert.second; + + vp[0].Set(v[0][0], v[0][1], v[0][2], ul, vt); + vp[1].Set(v[1][0], v[1][1], v[1][2], ur, vt); + vp[2].Set(v[2][0], v[2][1], v[2][2], ul, vb); + vp[3].Set(v[3][0], v[3][1], v[3][2], ur, vb); + } + +} + + //========================================================================== // //