raze/source/core/rendering/scene/hw_clipper.h

152 lines
2.8 KiB
C
Raw Normal View History

2021-03-15 18:05:08 +00:00
#ifndef __GL_CLIPPER
#define __GL_CLIPPER
#include "xs_Float.h"
#include "memarena.h"
#include "basics.h"
#include "vectors.h"
#include "binaryangle.h"
#include "intvec.h"
2021-03-15 18:05:08 +00:00
class ClipNode
{
friend class Clipper;
ClipNode *prev, *next;
angle_t start, end;
bool operator== (const ClipNode &other)
{
return other.start == start && other.end == end;
}
};
class Clipper
{
static unsigned starttime;
FMemArena nodearena;
ClipNode * freelist = nullptr;
ClipNode * clipnodes = nullptr;
ClipNode * cliphead = nullptr;
ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called
vec2_t viewpoint;
2021-03-15 18:05:08 +00:00
bool blocked = false;
bool IsRangeVisible(binangle startangle, binangle endangle);
2021-03-15 18:05:08 +00:00
void RemoveRange(ClipNode * cn);
void AddClipRange(binangle startangle, binangle endangle);
void RemoveClipRange(binangle startangle, binangle endangle);
2021-03-15 18:05:08 +00:00
public:
Clipper();
void Clear();
static binangle AngleToPseudo(binangle ang);
2021-03-15 18:05:08 +00:00
void Free(ClipNode *node)
{
node->next = freelist;
freelist = node;
}
private:
2021-03-15 18:05:08 +00:00
ClipNode * GetNew()
{
if (freelist)
{
ClipNode * p = freelist;
freelist = p->next;
return p;
}
else return (ClipNode*)nodearena.Alloc(sizeof(ClipNode));
}
ClipNode * NewRange(angle_t start, angle_t end)
{
ClipNode * c = GetNew();
c->start = start;
c->end = end;
c->next = c->prev = NULL;
return c;
}
void DoRemoveClipRange(angle_t start, angle_t end);
public:
2021-03-15 18:05:08 +00:00
void SetViewpoint(const vec2_t &vp)
2021-03-15 18:05:08 +00:00
{
viewpoint = vp;
}
void SetSilhouette();
bool SafeCheckRange(binangle startAngle, binangle endAngle)
2021-03-15 18:05:08 +00:00
{
if(startAngle.asbam() > endAngle.asbam())
2021-03-15 18:05:08 +00:00
{
return (IsRangeVisible(startAngle, bamang(ANGLE_MAX)) || IsRangeVisible(bamang(0), endAngle));
2021-03-15 18:05:08 +00:00
}
return IsRangeVisible(startAngle, endAngle);
}
void SafeAddClipRange(binangle startangle, binangle endangle)
2021-03-15 18:05:08 +00:00
{
if(startangle.asbam() > endangle.asbam())
2021-03-15 18:05:08 +00:00
{
// The range has to added in two parts.
AddClipRange(startangle, bamang(ANGLE_MAX));
AddClipRange(bamang(0), endangle);
2021-03-15 18:05:08 +00:00
}
else
{
// Add the range as usual.
AddClipRange(startangle, endangle);
}
}
void SafeAddClipRange(const vec2_t& v1, const vec2_t& v2)
2021-03-15 18:05:08 +00:00
{
binangle a2 = PointToAngle(v1);
binangle a1 = PointToAngle(v2);
2021-03-15 18:05:08 +00:00
SafeAddClipRange(a1,a2);
}
void SafeRemoveClipRange(binangle startangle, binangle endangle)
2021-03-15 18:05:08 +00:00
{
if(startangle.asbam() > endangle.asbam())
2021-03-15 18:05:08 +00:00
{
// The range has to added in two parts.
RemoveClipRange(startangle, bamang(ANGLE_MAX));
RemoveClipRange(bamang(0), endangle);
2021-03-15 18:05:08 +00:00
}
else
{
// Add the range as usual.
RemoveClipRange(startangle, endangle);
}
}
void SetBlocked(bool on)
{
blocked = on;
}
bool IsBlocked() const
{
return blocked;
}
2021-03-23 20:23:49 +00:00
void DumpClipper();
2021-03-15 18:05:08 +00:00
binangle PointToAngle(const vec2_t& point);
2021-03-15 18:05:08 +00:00
};
#endif