From 6b92b95068b871d06a9bd8846278764894b677ba Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 18 Jun 2018 18:41:59 +0200 Subject: [PATCH] - moved vertex creation for skybox sector to backend independent code. --- src/gl/renderer/gl_quaddrawer.h | 4 +++ src/gl/scene/gl_flats.cpp | 36 ++------------------- src/hwrenderer/scene/hw_drawstructs.h | 1 + src/hwrenderer/scene/hw_flats.cpp | 45 ++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/gl/renderer/gl_quaddrawer.h b/src/gl/renderer/gl_quaddrawer.h index b9db606847..c4776ecae0 100644 --- a/src/gl/renderer/gl_quaddrawer.h +++ b/src/gl/renderer/gl_quaddrawer.h @@ -23,6 +23,10 @@ public: p = GLRenderer->mVBO->Alloc(4, &ndx); } } + FFlatVertex *Pointer() + { + return p; + } void Set(int ndx, float x, float y, float z, float s, float t) { p[ndx].Set(x, y, z, s, t); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 4e32ec299d..6438593f75 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -279,46 +279,14 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool //========================================================================== // -// special handling for skyboxes which need texture clamping. -// This will find the bounding rectangle of the sector and just -// draw one single polygon filling that rectangle with a clamped -// texture. +// // //========================================================================== void FDrawInfo::DrawSkyboxSector(GLFlat *flat, int pass, bool processlights) { - - float minx = FLT_MAX, miny = FLT_MAX; - float maxx = -FLT_MAX, maxy = -FLT_MAX; - - for (auto ln : flat->sector->Lines) - { - float x = ln->v1->fX(); - float y = ln->v1->fY(); - if (x < minx) minx = x; - if (y < miny) miny = y; - if (x > maxx) maxx = x; - if (y > maxy) maxy = y; - x = ln->v2->fX(); - y = ln->v2->fY(); - if (x < minx) minx = x; - if (y < miny) miny = y; - if (x > maxx) maxx = x; - if (y > maxy) maxy = y; - } - - float z = flat->plane.plane.ZatPoint(0., 0.) + flat->dz; - static float uvals[] = { 0, 0, 1, 1 }; - static float vvals[] = { 1, 0, 0, 1 }; - int rot = -xs_FloorToInt(flat->plane.Angle / 90.f); - FQuadDrawer qd; - - qd.Set(0, minx, z, miny, uvals[rot & 3], vvals[rot & 3]); - qd.Set(1, minx, z, maxy, uvals[(rot + 1) & 3], vvals[(rot + 1) & 3]); - qd.Set(2, maxx, z, maxy, uvals[(rot + 2) & 3], vvals[(rot + 2) & 3]); - qd.Set(3, maxx, z, miny, uvals[(rot + 3) & 3], vvals[(rot + 3) & 3]); + flat->CreateSkyboxVertices(qd.Pointer()); qd.Render(GL_TRIANGLE_FAN); flatvertices += 4; diff --git a/src/hwrenderer/scene/hw_drawstructs.h b/src/hwrenderer/scene/hw_drawstructs.h index 8dcc4632aa..56e744b006 100644 --- a/src/hwrenderer/scene/hw_drawstructs.h +++ b/src/hwrenderer/scene/hw_drawstructs.h @@ -314,6 +314,7 @@ public: int dynlightindex; + void CreateSkyboxVertices(FFlatVertex *buffer); bool SetupLights(int pass, FLightNode *head, FDynLightData &lightdata, int portalgroup); bool SetupSubsectorLights(int pass, subsector_t * sub, FDynLightData &lightdata); bool SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdata); diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index 25574fbd3d..adcedbd1df 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -41,6 +41,7 @@ #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/textures/hw_material.h" #include "hwrenderer/scene/hw_drawinfo.h" +#include "hwrenderer/data/flatvertices.h" #include "hw_drawstructs.h" #ifdef _DEBUG @@ -86,9 +87,51 @@ bool hw_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * glte return false; } + //========================================================================== // -// Flats +// special handling for skyboxes which need texture clamping. +// This will find the bounding rectangle of the sector and just +// draw one single polygon filling that rectangle with a clamped +// texture. +// +//========================================================================== + +void GLFlat::CreateSkyboxVertices(FFlatVertex *vert) +{ + float minx = FLT_MAX, miny = FLT_MAX; + float maxx = -FLT_MAX, maxy = -FLT_MAX; + + for (auto ln : sector->Lines) + { + float x = ln->v1->fX(); + float y = ln->v1->fY(); + if (x < minx) minx = x; + if (y < miny) miny = y; + if (x > maxx) maxx = x; + if (y > maxy) maxy = y; + x = ln->v2->fX(); + y = ln->v2->fY(); + if (x < minx) minx = x; + if (y < miny) miny = y; + if (x > maxx) maxx = x; + if (y > maxy) maxy = y; + } + + float z = plane.plane.ZatPoint(0., 0.) + dz; + static float uvals[] = { 0, 0, 1, 1 }; + static float vvals[] = { 1, 0, 0, 1 }; + int rot = -xs_FloorToInt(plane.Angle / 90.f); + + vert[0].Set(minx, z, miny, uvals[rot & 3], vvals[rot & 3]); + vert[1].Set(minx, z, maxy, uvals[(rot + 1) & 3], vvals[(rot + 1) & 3]); + vert[2].Set(maxx, z, maxy, uvals[(rot + 2) & 3], vvals[(rot + 2) & 3]); + vert[3].Set(maxx, z, miny, uvals[(rot + 3) & 3], vvals[(rot + 3) & 3]); +} + +//========================================================================== +// +// // //==========================================================================