2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl_renderstruct.h
|
|
|
|
** Generalized portal maintenance classes to make rendering special effects easier
|
|
|
|
** and help add future extensions
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2002-2005 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GL_PORTAL_H
|
|
|
|
#define __GL_PORTAL_H
|
|
|
|
|
|
|
|
#include "tarray.h"
|
|
|
|
//#include "gl/gl_intern.h"
|
|
|
|
#include "gl/renderer/gl_renderer.h"
|
|
|
|
#include "gl/scene/gl_drawinfo.h"
|
|
|
|
#include "gl/utility/gl_templates.h"
|
2016-03-04 13:10:13 +00:00
|
|
|
#include "gl/data/gl_data.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
class ASkyViewpoint;
|
|
|
|
|
2016-03-04 13:10:13 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
struct GLHorizonInfo
|
|
|
|
{
|
|
|
|
GLSectorPlane plane;
|
|
|
|
int lightlevel;
|
|
|
|
FColormap colormap;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GLSkyInfo
|
|
|
|
{
|
|
|
|
float x_offset[2];
|
|
|
|
float y_offset; // doubleskies don't have a y-offset
|
|
|
|
FMaterial * texture[2];
|
|
|
|
FTextureID skytexno1;
|
|
|
|
bool mirrored;
|
|
|
|
bool doublesky;
|
|
|
|
bool sky2;
|
|
|
|
PalEntry fadecolor; // if this isn't made part of the dome things will become more complicated when sky fog is used.
|
|
|
|
|
|
|
|
bool operator==(const GLSkyInfo & inf)
|
|
|
|
{
|
|
|
|
return !memcmp(this, &inf, sizeof(*this));
|
|
|
|
}
|
|
|
|
bool operator!=(const GLSkyInfo & inf)
|
|
|
|
{
|
|
|
|
return !!memcmp(this, &inf, sizeof(*this));
|
|
|
|
}
|
2016-01-11 14:07:58 +00:00
|
|
|
void init(int sky1, PalEntry fadecolor);
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern UniqueList<GLSkyInfo> UniqueSkies;
|
|
|
|
extern UniqueList<GLHorizonInfo> UniqueHorizons;
|
|
|
|
extern UniqueList<secplane_t> UniquePlaneMirrors;
|
2016-03-04 13:10:13 +00:00
|
|
|
extern UniqueList<FGLLinePortal> UniqueLineToLines;
|
2016-01-11 14:07:58 +00:00
|
|
|
struct GLEEHorizonPortal;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
class GLPortal
|
|
|
|
{
|
|
|
|
static TArray<GLPortal *> portals;
|
|
|
|
static int recursion;
|
|
|
|
static unsigned int QueryObject;
|
|
|
|
protected:
|
2014-07-13 10:14:12 +00:00
|
|
|
static TArray<float> planestack;
|
2013-06-23 07:49:34 +00:00
|
|
|
static int MirrorFlag;
|
|
|
|
static int PlaneMirrorFlag;
|
|
|
|
static int renderdepth;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static int PlaneMirrorMode;
|
|
|
|
static int inupperstack;
|
|
|
|
static int instack[2];
|
|
|
|
static bool inskybox;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DrawPortalStencil();
|
|
|
|
|
2016-04-02 21:17:16 +00:00
|
|
|
DVector3 savedViewPos;
|
|
|
|
DAngle savedAngle;
|
2013-06-23 07:49:34 +00:00
|
|
|
AActor * savedviewactor;
|
|
|
|
area_t savedviewarea;
|
2016-06-18 10:14:20 +00:00
|
|
|
ActorRenderFlags savedvisibility;
|
2016-04-07 19:13:37 +00:00
|
|
|
DVector3 savedviewpath[2];
|
2016-04-28 23:48:06 +00:00
|
|
|
GLPortal *PrevPortal;
|
|
|
|
GLPortal *PrevClipPortal;
|
2013-06-23 07:49:34 +00:00
|
|
|
TArray<BYTE> savedmapsection;
|
2014-05-31 07:32:17 +00:00
|
|
|
TArray<unsigned int> mPrimIndices;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
TArray<GLWall> lines;
|
|
|
|
int level;
|
|
|
|
|
2016-01-11 14:07:58 +00:00
|
|
|
GLPortal(bool local = false) { if (!local) portals.Push(this); }
|
2013-06-23 07:49:34 +00:00
|
|
|
virtual ~GLPortal() { }
|
|
|
|
|
|
|
|
bool Start(bool usestencil, bool doquery);
|
|
|
|
void End(bool usestencil);
|
|
|
|
virtual void DrawContents()=0;
|
|
|
|
virtual void * GetSource() const =0; // GetSource MUST be implemented!
|
|
|
|
void ClearClipper();
|
|
|
|
virtual bool IsSky() { return false; }
|
|
|
|
virtual bool NeedCap() { return true; }
|
|
|
|
virtual bool NeedDepthBuffer() { return true; }
|
|
|
|
void ClearScreen();
|
|
|
|
virtual const char *GetName() = 0;
|
|
|
|
void SaveMapSection();
|
|
|
|
void RestoreMapSection();
|
2016-04-28 23:48:06 +00:00
|
|
|
virtual void PushState() {}
|
|
|
|
virtual void PopState() {}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PClip_InFront,
|
|
|
|
PClip_Inside,
|
2016-04-17 13:46:04 +00:00
|
|
|
PClip_Behind,
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void RenderPortal(bool usestencil, bool doquery)
|
|
|
|
{
|
|
|
|
// Start may perform an occlusion query. If that returns 0 there
|
|
|
|
// is no need to draw the stencil's contents and there's also no
|
|
|
|
// need to restore the affected area becasue there is none!
|
|
|
|
if (Start(usestencil, doquery))
|
|
|
|
{
|
|
|
|
DrawContents();
|
|
|
|
End(usestencil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddLine(GLWall * l)
|
|
|
|
{
|
|
|
|
lines.Push(*l);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int GetRecursion()
|
|
|
|
{
|
|
|
|
return recursion;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int ClipSeg(seg_t *seg) { return PClip_Inside; }
|
2016-01-27 11:02:43 +00:00
|
|
|
virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; }
|
2016-04-02 21:17:16 +00:00
|
|
|
virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; }
|
2016-04-17 13:46:04 +00:00
|
|
|
virtual line_t *ClipLine() { return NULL; }
|
2016-04-30 14:57:53 +00:00
|
|
|
virtual void RenderAttached() {}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
static void BeginScene();
|
|
|
|
static void StartFrame();
|
|
|
|
static bool RenderFirstSkyPortal(int recursion);
|
|
|
|
static void EndFrame();
|
|
|
|
static GLPortal * FindPortal(const void * src);
|
|
|
|
};
|
|
|
|
|
2016-03-04 13:10:13 +00:00
|
|
|
struct GLLinePortal : public GLPortal
|
|
|
|
{
|
|
|
|
// this must be the same as at the start of line_t, so that we can pass in this structure directly to P_ClipLineToPortal.
|
|
|
|
vertex_t *v1, *v2; // vertices, from v1 to v2
|
2016-04-07 15:41:06 +00:00
|
|
|
DVector2 delta; // precalculated v2 - v1 for side checking
|
2016-03-04 13:10:13 +00:00
|
|
|
|
|
|
|
angle_t angv1, angv2; // for quick comparisons with a line or subsector
|
|
|
|
|
|
|
|
GLLinePortal(line_t *line)
|
|
|
|
{
|
|
|
|
v1 = line->v1;
|
|
|
|
v2 = line->v2;
|
2016-04-02 21:17:16 +00:00
|
|
|
CalcDelta();
|
2016-03-04 13:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLLinePortal(FGLLinePortal *line)
|
|
|
|
{
|
2016-07-16 10:45:49 +00:00
|
|
|
if (line->lines[0]->mType != PORTT_LINKED || line->v1 == nullptr)
|
2016-03-04 13:41:24 +00:00
|
|
|
{
|
|
|
|
// For non-linked portals we must check the actual linedef.
|
2016-04-30 14:57:53 +00:00
|
|
|
line_t *lline = line->lines[0]->mDestination;
|
2016-03-04 13:41:24 +00:00
|
|
|
v1 = lline->v1;
|
|
|
|
v2 = lline->v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For linked portals we can check the merged span.
|
|
|
|
v1 = line->v1;
|
|
|
|
v2 = line->v2;
|
|
|
|
}
|
2016-04-02 21:17:16 +00:00
|
|
|
CalcDelta();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CalcDelta()
|
|
|
|
{
|
2016-04-07 15:41:06 +00:00
|
|
|
delta = v2->fPos() - v1->fPos();
|
2016-03-04 13:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line_t *line()
|
|
|
|
{
|
|
|
|
vertex_t **pv = &v1;
|
|
|
|
return reinterpret_cast<line_t*>(pv);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int ClipSeg(seg_t *seg);
|
|
|
|
virtual int ClipSubsector(subsector_t *sub);
|
2016-04-02 21:17:16 +00:00
|
|
|
virtual int ClipPoint(const DVector2 &pos);
|
2016-03-04 13:10:13 +00:00
|
|
|
virtual bool NeedCap() { return false; }
|
2016-04-29 10:26:57 +00:00
|
|
|
virtual void PushState();
|
|
|
|
virtual void PopState();
|
2016-03-04 13:10:13 +00:00
|
|
|
};
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-03-04 13:10:13 +00:00
|
|
|
struct GLMirrorPortal : public GLLinePortal
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// mirror portals always consist of single linedefs!
|
|
|
|
line_t * linedef;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
|
|
|
virtual void * GetSource() const { return linedef; }
|
|
|
|
virtual const char *GetName();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
GLMirrorPortal(line_t * line)
|
2016-03-04 13:10:13 +00:00
|
|
|
: GLLinePortal(line)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
linedef=line;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-03-04 13:10:13 +00:00
|
|
|
struct GLLineToLinePortal : public GLLinePortal
|
2016-02-06 04:17:47 +00:00
|
|
|
{
|
2016-03-04 13:10:13 +00:00
|
|
|
FGLLinePortal *glport;
|
2016-02-06 04:17:47 +00:00
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
2016-03-04 13:10:13 +00:00
|
|
|
virtual void * GetSource() const { return glport; }
|
2016-02-06 04:17:47 +00:00
|
|
|
virtual const char *GetName();
|
2016-04-17 13:46:04 +00:00
|
|
|
virtual line_t *ClipLine() { return line(); }
|
2016-04-30 14:57:53 +00:00
|
|
|
virtual void RenderAttached();
|
2016-02-06 04:17:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-03-04 13:10:13 +00:00
|
|
|
GLLineToLinePortal(FGLLinePortal *ll)
|
|
|
|
: GLLinePortal(ll)
|
2016-02-06 04:17:47 +00:00
|
|
|
{
|
2016-03-04 13:10:13 +00:00
|
|
|
glport = ll;
|
2016-02-06 04:17:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
struct GLSkyboxPortal : public GLPortal
|
|
|
|
{
|
2016-04-20 18:08:53 +00:00
|
|
|
FSectorPortal * portal;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
2016-04-20 18:08:53 +00:00
|
|
|
virtual void * GetSource() const { return portal; }
|
2016-03-04 13:10:13 +00:00
|
|
|
virtual bool IsSky() { return true; }
|
2013-06-23 07:49:34 +00:00
|
|
|
virtual const char *GetName();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2016-04-20 18:08:53 +00:00
|
|
|
GLSkyboxPortal(FSectorPortal * pt)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-20 18:08:53 +00:00
|
|
|
portal=pt;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct GLSkyPortal : public GLPortal
|
|
|
|
{
|
|
|
|
GLSkyInfo * origin;
|
2016-01-11 14:07:58 +00:00
|
|
|
friend struct GLEEHorizonPortal;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
|
|
|
virtual void * GetSource() const { return origin; }
|
|
|
|
virtual bool IsSky() { return true; }
|
|
|
|
virtual bool NeedDepthBuffer() { return false; }
|
|
|
|
virtual const char *GetName();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2016-01-11 14:07:58 +00:00
|
|
|
GLSkyPortal(GLSkyInfo * pt, bool local = false)
|
|
|
|
: GLPortal(local)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
origin=pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct GLSectorStackPortal : public GLPortal
|
|
|
|
{
|
|
|
|
TArray<subsector_t *> subsectors;
|
|
|
|
protected:
|
|
|
|
virtual ~GLSectorStackPortal();
|
|
|
|
virtual void DrawContents();
|
|
|
|
virtual void * GetSource() const { return origin; }
|
|
|
|
virtual bool IsSky() { return true; } // although this isn't a real sky it can be handled as one.
|
|
|
|
virtual const char *GetName();
|
|
|
|
FPortal *origin;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
GLSectorStackPortal(FPortal *pt)
|
|
|
|
{
|
|
|
|
origin=pt;
|
|
|
|
}
|
|
|
|
void SetupCoverage();
|
|
|
|
void AddSubsector(subsector_t *sub)
|
|
|
|
{
|
|
|
|
subsectors.Push(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GLPlaneMirrorPortal : public GLPortal
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
|
|
|
virtual void * GetSource() const { return origin; }
|
|
|
|
virtual const char *GetName();
|
2016-04-28 23:48:06 +00:00
|
|
|
virtual void PushState();
|
|
|
|
virtual void PopState();
|
2013-06-23 07:49:34 +00:00
|
|
|
secplane_t * origin;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
GLPlaneMirrorPortal(secplane_t * pt)
|
|
|
|
{
|
|
|
|
origin=pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct GLHorizonPortal : public GLPortal
|
|
|
|
{
|
|
|
|
GLHorizonInfo * origin;
|
2016-01-11 14:07:58 +00:00
|
|
|
friend struct GLEEHorizonPortal;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
|
|
|
virtual void * GetSource() const { return origin; }
|
|
|
|
virtual bool NeedDepthBuffer() { return false; }
|
|
|
|
virtual bool NeedCap() { return false; }
|
|
|
|
virtual const char *GetName();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-01-11 14:07:58 +00:00
|
|
|
GLHorizonPortal(GLHorizonInfo * pt, bool local = false)
|
|
|
|
: GLPortal(local)
|
|
|
|
{
|
|
|
|
origin=pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GLEEHorizonPortal : public GLPortal
|
|
|
|
{
|
2016-04-20 18:08:53 +00:00
|
|
|
FSectorPortal * portal;
|
2016-01-11 14:07:58 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void DrawContents();
|
2016-04-20 18:08:53 +00:00
|
|
|
virtual void * GetSource() const { return portal; }
|
2016-01-11 14:07:58 +00:00
|
|
|
virtual bool NeedDepthBuffer() { return false; }
|
|
|
|
virtual bool NeedCap() { return false; }
|
|
|
|
virtual const char *GetName();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-04-20 18:08:53 +00:00
|
|
|
GLEEHorizonPortal(FSectorPortal *pt)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-20 18:08:53 +00:00
|
|
|
portal=pt;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|