2016-11-24 04:51:37 +00:00
|
|
|
/*
|
|
|
|
** Polygon Doom software renderer
|
|
|
|
** Copyright (c) 2016 Magnus Norddahl
|
|
|
|
**
|
|
|
|
** This software is provided 'as-is', without any express or implied
|
|
|
|
** warranty. In no event will the authors be held liable for any damages
|
|
|
|
** arising from the use of this software.
|
|
|
|
**
|
|
|
|
** Permission is granted to anyone to use this software for any purpose,
|
|
|
|
** including commercial applications, and to alter it and redistribute it
|
|
|
|
** freely, subject to the following restrictions:
|
|
|
|
**
|
|
|
|
** 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
** claim that you wrote the original software. If you use this software
|
|
|
|
** in a product, an acknowledgment in the product documentation would be
|
|
|
|
** appreciated but is not required.
|
|
|
|
** 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
** misrepresented as being the original software.
|
|
|
|
** 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
#include "doomdata.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "r_main.h"
|
|
|
|
#include "r_poly_triangle.h"
|
|
|
|
#include "r_poly_intersection.h"
|
|
|
|
#include "r_poly_wall.h"
|
|
|
|
#include "r_poly_sprite.h"
|
|
|
|
#include "r_poly_wallsprite.h"
|
|
|
|
#include "r_poly_playersprite.h"
|
|
|
|
#include "r_poly_particle.h"
|
|
|
|
#include "r_poly_plane.h"
|
|
|
|
#include "r_poly_cull.h"
|
|
|
|
|
|
|
|
// Used for sorting things by distance to the camera
|
|
|
|
class PolySortedSprite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PolySortedSprite(AActor *thing, double distanceSquared) : Thing(thing), DistanceSquared(distanceSquared) { }
|
|
|
|
bool operator<(const PolySortedSprite &other) const { return DistanceSquared < other.DistanceSquared; }
|
|
|
|
|
|
|
|
AActor *Thing;
|
|
|
|
double DistanceSquared;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PolyTranslucentObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PolyTranslucentObject(particle_t *particle, subsector_t *sub, uint32_t subsectorDepth) : particle(particle), sub(sub), subsectorDepth(subsectorDepth) { }
|
|
|
|
PolyTranslucentObject(AActor *thing, subsector_t *sub, uint32_t subsectorDepth) : thing(thing), sub(sub), subsectorDepth(subsectorDepth) { }
|
|
|
|
PolyTranslucentObject(RenderPolyWall wall) : wall(wall) { }
|
|
|
|
|
|
|
|
particle_t *particle = nullptr;
|
|
|
|
AActor *thing = nullptr;
|
|
|
|
subsector_t *sub = nullptr;
|
|
|
|
uint32_t subsectorDepth = 0;
|
|
|
|
|
|
|
|
RenderPolyWall wall;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SpriteRange
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SpriteRange() = default;
|
|
|
|
SpriteRange(int start, int count) : Start(start), Count(count) { }
|
|
|
|
int Start = -1;
|
|
|
|
int Count = 0;
|
|
|
|
};
|
|
|
|
|
2016-11-24 22:08:36 +00:00
|
|
|
class PolyDrawSectorPortal;
|
|
|
|
class PolyDrawLinePortal;
|
|
|
|
|
2016-11-24 04:51:37 +00:00
|
|
|
// Renders everything from a specific viewpoint
|
|
|
|
class RenderPolyPortal
|
|
|
|
{
|
|
|
|
public:
|
2016-11-24 22:08:36 +00:00
|
|
|
RenderPolyPortal();
|
|
|
|
~RenderPolyPortal();
|
2016-11-24 04:51:37 +00:00
|
|
|
void SetViewpoint(const TriMatrix &worldToClip, uint32_t stencilValue);
|
2016-11-25 17:15:48 +00:00
|
|
|
void Render(int portalDepth);
|
|
|
|
void RenderTranslucent(int portalDepth);
|
2016-11-24 04:51:37 +00:00
|
|
|
|
|
|
|
static const uint32_t SkySubsectorDepth = 0x7fffffff;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ClearBuffers();
|
|
|
|
void RenderSectors();
|
|
|
|
void RenderSubsector(subsector_t *sub);
|
|
|
|
void RenderLine(subsector_t *sub, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth);
|
|
|
|
|
|
|
|
SpriteRange GetSpritesForSector(sector_t *sector);
|
|
|
|
|
|
|
|
TriMatrix WorldToClip;
|
|
|
|
uint32_t StencilValue = 0;
|
|
|
|
PolyCull Cull;
|
|
|
|
uint32_t NextSubsectorDepth = 0;
|
|
|
|
std::vector<SpriteRange> SectorSpriteRanges;
|
|
|
|
std::vector<PolySortedSprite> SortedSprites;
|
|
|
|
std::vector<PolyTranslucentObject> TranslucentObjects;
|
|
|
|
std::vector<PolyTranslucentObject> SubsectorTranslucentWalls;
|
|
|
|
|
2016-11-24 22:08:36 +00:00
|
|
|
std::vector<std::unique_ptr<PolyDrawSectorPortal>> SectorPortals;
|
|
|
|
std::vector<std::unique_ptr<PolyDrawLinePortal>> LinePortals;
|
|
|
|
};
|
|
|
|
|
2016-11-25 00:08:25 +00:00
|
|
|
struct PolyPortalVertexRange
|
|
|
|
{
|
2016-11-25 06:44:51 +00:00
|
|
|
PolyPortalVertexRange(const TriVertex *vertices, int count, bool ccw, uint32_t subsectorDepth) : Vertices(vertices), Count(count), Ccw(ccw), SubsectorDepth(subsectorDepth) { }
|
2016-11-25 00:08:25 +00:00
|
|
|
const TriVertex *Vertices;
|
|
|
|
int Count;
|
|
|
|
bool Ccw;
|
2016-11-25 06:44:51 +00:00
|
|
|
uint32_t SubsectorDepth;
|
2016-11-25 00:08:25 +00:00
|
|
|
};
|
|
|
|
|
2016-11-24 22:08:36 +00:00
|
|
|
class PolyDrawSectorPortal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PolyDrawSectorPortal(FSectorPortal *portal, bool ceiling);
|
|
|
|
|
2016-11-25 17:15:48 +00:00
|
|
|
void Render(int portalDepth);
|
|
|
|
void RenderTranslucent(int portalDepth);
|
2016-11-25 00:08:25 +00:00
|
|
|
|
|
|
|
FSectorPortal *Portal;
|
2016-11-25 16:14:26 +00:00
|
|
|
uint32_t StencilValue = 0;
|
2016-11-25 00:08:25 +00:00
|
|
|
std::vector<PolyPortalVertexRange> Shape;
|
2016-11-24 22:08:36 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-25 00:08:25 +00:00
|
|
|
void SaveGlobals();
|
|
|
|
void RestoreGlobals();
|
|
|
|
|
2016-11-24 22:08:36 +00:00
|
|
|
bool Ceiling;
|
|
|
|
RenderPolyPortal RenderPortal;
|
2016-11-25 00:08:25 +00:00
|
|
|
|
|
|
|
int savedextralight;
|
|
|
|
DVector3 savedpos;
|
|
|
|
DAngle savedangle;
|
|
|
|
double savedvisibility;
|
|
|
|
AActor *savedcamera;
|
|
|
|
sector_t *savedsector;
|
2016-11-24 22:08:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PolyDrawLinePortal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PolyDrawLinePortal(line_t *src, line_t *dest, bool mirror);
|
|
|
|
|
2016-11-25 17:15:48 +00:00
|
|
|
void Render(int portalDepth);
|
|
|
|
void RenderTranslucent(int portalDepth);
|
2016-11-24 22:08:36 +00:00
|
|
|
|
2016-11-25 16:14:26 +00:00
|
|
|
uint32_t StencilValue = 0;
|
2016-11-25 00:08:25 +00:00
|
|
|
std::vector<PolyPortalVertexRange> Shape;
|
|
|
|
|
2016-11-24 22:08:36 +00:00
|
|
|
private:
|
|
|
|
line_t *Src;
|
|
|
|
line_t *Dest;
|
|
|
|
RenderPolyPortal RenderPortal;
|
2016-11-24 04:51:37 +00:00
|
|
|
};
|