- moved vertex creation for skybox sector to backend independent code.

This commit is contained in:
Christoph Oelckers 2018-06-18 18:41:59 +02:00
parent 34ee04f2ce
commit 6b92b95068
4 changed files with 51 additions and 35 deletions

View File

@ -23,6 +23,10 @@ public:
p = GLRenderer->mVBO->Alloc(4, &ndx); p = GLRenderer->mVBO->Alloc(4, &ndx);
} }
} }
FFlatVertex *Pointer()
{
return p;
}
void Set(int ndx, float x, float y, float z, float s, float t) void Set(int ndx, float x, float y, float z, float s, float t)
{ {
p[ndx].Set(x, y, z, s, t); p[ndx].Set(x, y, z, s, t);

View File

@ -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) 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; FQuadDrawer qd;
flat->CreateSkyboxVertices(qd.Pointer());
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]);
qd.Render(GL_TRIANGLE_FAN); qd.Render(GL_TRIANGLE_FAN);
flatvertices += 4; flatvertices += 4;

View File

@ -314,6 +314,7 @@ public:
int dynlightindex; int dynlightindex;
void CreateSkyboxVertices(FFlatVertex *buffer);
bool SetupLights(int pass, FLightNode *head, FDynLightData &lightdata, int portalgroup); bool SetupLights(int pass, FLightNode *head, FDynLightData &lightdata, int portalgroup);
bool SetupSubsectorLights(int pass, subsector_t * sub, FDynLightData &lightdata); bool SetupSubsectorLights(int pass, subsector_t * sub, FDynLightData &lightdata);
bool SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdata); bool SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdata);

View File

@ -41,6 +41,7 @@
#include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/utility/hw_lighting.h"
#include "hwrenderer/textures/hw_material.h" #include "hwrenderer/textures/hw_material.h"
#include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawinfo.h"
#include "hwrenderer/data/flatvertices.h"
#include "hw_drawstructs.h" #include "hw_drawstructs.h"
#ifdef _DEBUG #ifdef _DEBUG
@ -86,9 +87,51 @@ bool hw_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * glte
return false; 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]);
}
//==========================================================================
//
//
// //
//========================================================================== //==========================================================================