2013-06-23 07:49:34 +00:00
# ifndef __GL_WALL_H
# define __GL_WALL_H
//==========================================================================
//
// One wall segment in the draw list
//
//==========================================================================
# include "r_defs.h"
# include "textures/textures.h"
# include "gl/renderer/gl_colormap.h"
struct GLHorizonInfo ;
struct F3DFloor ;
struct model_t ;
struct FSpriteModelFrame ;
struct particle_t ;
class ADynamicLight ;
class FMaterial ;
struct GLDrawList ;
struct GLSkyInfo ;
struct FTexCoordInfo ;
struct FPortal ;
2014-05-10 23:23:27 +00:00
struct FFlatVertex ;
2016-03-04 13:10:13 +00:00
struct FGLLinePortal ;
2013-06-23 07:49:34 +00:00
2016-04-14 11:22:15 +00:00
enum
{
GLSector_NoSkyDraw = 89 ,
GLSector_Skybox = 90 ,
} ;
2013-06-23 07:49:34 +00:00
enum WallTypes
{
RENDERWALL_NONE ,
RENDERWALL_TOP ,
RENDERWALL_M1S ,
RENDERWALL_M2S ,
RENDERWALL_BOTTOM ,
RENDERWALL_FOGBOUNDARY ,
RENDERWALL_MIRRORSURFACE ,
RENDERWALL_M2SNF ,
RENDERWALL_COLOR ,
RENDERWALL_FFBLOCK ,
// Insert new types at the end!
} ;
2016-02-01 00:49:49 +00:00
enum PortalTypes
{
PORTALTYPE_SKY ,
PORTALTYPE_HORIZON ,
PORTALTYPE_SKYBOX ,
PORTALTYPE_SECTORSTACK ,
PORTALTYPE_PLANEMIRROR ,
PORTALTYPE_MIRROR ,
2016-02-06 04:17:47 +00:00
PORTALTYPE_LINETOLINE ,
2016-02-01 00:49:49 +00:00
} ;
2013-06-23 07:49:34 +00:00
struct GLSeg
{
float x1 , x2 ;
float y1 , y2 ;
float fracleft , fracright ; // fractional offset of the 2 vertices on the linedef
} ;
struct texcoord
{
float u , v ;
} ;
//==========================================================================
//
// One sector plane, still in fixed point
//
//==========================================================================
struct GLSectorPlane
{
FTextureID texture ;
secplane_t plane ;
2016-03-31 07:50:59 +00:00
float Texheight ;
float Angle ;
FVector2 Offs ;
FVector2 Scale ;
2013-06-23 07:49:34 +00:00
void GetFromSector ( sector_t * sec , int ceiling )
{
2016-04-23 11:48:25 +00:00
Offs . X = ( float ) sec - > GetXOffset ( ceiling ) ;
Offs . Y = ( float ) sec - > GetYOffset ( ceiling ) ;
Scale . X = ( float ) sec - > GetXScale ( ceiling ) ;
Scale . Y = ( float ) sec - > GetYScale ( ceiling ) ;
Angle = ( float ) sec - > GetAngle ( ceiling ) . Degrees ;
2013-06-23 07:49:34 +00:00
texture = sec - > GetTexture ( ceiling ) ;
plane = sec - > GetSecPlane ( ceiling ) ;
2016-03-31 07:50:59 +00:00
Texheight = ( float ) ( ( ceiling = = sector_t : : ceiling ) ? plane . fD ( ) : - plane . fD ( ) ) ;
2013-06-23 07:49:34 +00:00
}
} ;
class GLWall
{
public :
enum
{
//GLWF_CLAMPX=1, use GLT_* for these!
//GLWF_CLAMPY=2,
GLWF_SKYHACK = 4 ,
2014-07-15 19:16:59 +00:00
GLWF_GLOW = 8 , // illuminated by glowing flats
GLWF_NOSPLITUPPER = 16 ,
GLWF_NOSPLITLOWER = 32 ,
2014-08-04 21:00:40 +00:00
GLWF_NOSPLIT = 64 ,
2013-06-23 07:49:34 +00:00
} ;
2014-06-15 08:15:44 +00:00
enum
{
RWF_BLANK = 0 ,
RWF_TEXTURED = 1 , // actually not being used anymore because with buffers it's even less efficient not writing the texture coordinates - but leave it here
RWF_NOSPLIT = 4 ,
RWF_NORENDER = 8 ,
} ;
2013-06-23 07:49:34 +00:00
friend struct GLDrawList ;
friend class GLPortal ;
GLSeg glseg ;
vertex_t * vertexes [ 2 ] ; // required for polygon splitting
float ztop [ 2 ] , zbottom [ 2 ] ;
texcoord uplft , uprgt , lolft , lorgt ;
float alpha ;
FMaterial * gltexture ;
FColormap Colormap ;
ERenderStyle RenderStyle ;
2016-04-02 21:17:16 +00:00
float ViewDistance ;
2013-06-23 07:49:34 +00:00
2016-02-01 00:03:34 +00:00
TArray < lightlist_t > * lightlist ;
2013-06-23 08:17:58 +00:00
int lightlevel ;
2013-06-23 07:49:34 +00:00
BYTE type ;
BYTE flags ;
short rellight ;
float topglowcolor [ 4 ] ;
float bottomglowcolor [ 4 ] ;
2014-08-01 18:59:39 +00:00
int dynlightindex ;
2013-06-23 07:49:34 +00:00
union
{
// it's either one of them but never more!
2016-04-20 18:08:53 +00:00
FSectorPortal * secportal ; // sector portal (formerly skybox)
2013-06-23 07:49:34 +00:00
GLSkyInfo * sky ; // for normal sky
GLHorizonInfo * horizon ; // for horizon information
FPortal * portal ; // stacked sector portals
secplane_t * planemirror ; // for plane mirrors
2016-03-04 13:10:13 +00:00
FGLLinePortal * lineportal ; // line-to-line portals
2013-06-23 07:49:34 +00:00
} ;
FTextureID topflat , bottomflat ;
2014-05-10 15:09:43 +00:00
secplane_t topplane , bottomplane ; // we need to save these to pass them to the shader for calculating glows.
2013-06-23 07:49:34 +00:00
// these are not the same as ytop and ybottom!!!
float zceil [ 2 ] ;
float zfloor [ 2 ] ;
public :
seg_t * seg ; // this gives the easiest access to all other structs involved
subsector_t * sub ; // For polyobjects
private :
void CheckGlowing ( ) ;
2016-02-05 00:48:53 +00:00
void PutWall ( bool translucent ) ;
2016-02-01 00:49:49 +00:00
void PutPortal ( int ptype ) ;
2013-06-23 07:49:34 +00:00
void CheckTexturePosition ( ) ;
2016-02-04 14:34:12 +00:00
void Put3DWall ( lightlist_t * lightlist , bool translucent ) ;
2016-04-26 19:42:15 +00:00
void SplitWallComplex ( sector_t * frontsector , bool translucent , float maplightbottomleft , float maplightbottomright ) ;
2016-02-04 14:34:12 +00:00
void SplitWall ( sector_t * frontsector , bool translucent ) ;
2013-06-23 07:49:34 +00:00
void SetupLights ( ) ;
bool PrepareLight ( texcoord * tcs , ADynamicLight * light ) ;
2014-07-15 18:49:21 +00:00
void RenderWall ( int textured , unsigned int * store = NULL ) ;
2016-01-31 20:10:59 +00:00
void RenderTextured ( int rflags ) ;
2013-06-23 07:49:34 +00:00
void FloodPlane ( int pass ) ;
void SkyPlane ( sector_t * sector , int plane , bool allowmirror ) ;
2016-02-06 04:17:47 +00:00
void SkyLine ( sector_t * sec , line_t * line ) ;
2013-06-23 07:49:34 +00:00
void SkyNormal ( sector_t * fs , vertex_t * v1 , vertex_t * v2 ) ;
void SkyTop ( seg_t * seg , sector_t * fs , sector_t * bs , vertex_t * v1 , vertex_t * v2 ) ;
void SkyBottom ( seg_t * seg , sector_t * fs , sector_t * bs , vertex_t * v1 , vertex_t * v2 ) ;
void LightPass ( ) ;
void SetHorizon ( vertex_t * ul , vertex_t * ur , vertex_t * ll , vertex_t * lr ) ;
bool DoHorizon ( seg_t * seg , sector_t * fs , vertex_t * v1 , vertex_t * v2 ) ;
bool SetWallCoordinates ( seg_t * seg , FTexCoordInfo * tci , float ceilingrefheight ,
2016-04-07 22:19:51 +00:00
float topleft , float topright , float bottomleft , float bottomright , float t_ofs ) ;
2013-06-23 07:49:34 +00:00
void DoTexture ( int type , seg_t * seg , int peg ,
2016-04-07 22:19:51 +00:00
float ceilingrefheight , float floorrefheight ,
2016-04-07 15:00:13 +00:00
float CeilingHeightstart , float CeilingHeightend ,
float FloorHeightstart , float FloorHeightend ,
2016-04-07 22:19:51 +00:00
float v_offset ) ;
2013-06-23 07:49:34 +00:00
void DoMidTexture ( seg_t * seg , bool drawfogboundary ,
sector_t * front , sector_t * back ,
sector_t * realfront , sector_t * realback ,
2016-04-07 21:19:37 +00:00
float fch1 , float fch2 , float ffh1 , float ffh2 ,
float bch1 , float bch2 , float bfh1 , float bfh2 ) ;
2013-06-23 07:49:34 +00:00
2016-04-07 21:19:37 +00:00
void GetPlanePos ( F3DFloor : : planeref * planeref , float & left , float & right ) ;
2013-06-23 07:49:34 +00:00
void BuildFFBlock ( seg_t * seg , F3DFloor * rover ,
2016-04-07 21:19:37 +00:00
float ff_topleft , float ff_topright ,
float ff_bottomleft , float ff_bottomright ) ;
2013-06-23 07:49:34 +00:00
void InverseFloors ( seg_t * seg , sector_t * frontsector ,
2016-04-07 21:19:37 +00:00
float topleft , float topright ,
float bottomleft , float bottomright ) ;
2013-06-23 07:49:34 +00:00
void ClipFFloors ( seg_t * seg , F3DFloor * ffloor , sector_t * frontsector ,
2016-04-07 21:19:37 +00:00
float topleft , float topright ,
float bottomleft , float bottomright ) ;
2013-06-23 07:49:34 +00:00
void DoFFloorBlocks ( seg_t * seg , sector_t * frontsector , sector_t * backsector ,
2016-04-07 21:19:37 +00:00
float fch1 , float fch2 , float ffh1 , float ffh2 ,
float bch1 , float bch2 , float bfh1 , float bfh2 ) ;
2013-06-23 07:49:34 +00:00
void DrawDecal ( DBaseDecal * actor ) ;
void DoDrawDecals ( ) ;
void RenderFogBoundary ( ) ;
void RenderMirrorSurface ( ) ;
void RenderTranslucentWall ( ) ;
2014-05-10 23:23:27 +00:00
void SplitLeftEdge ( texcoord * tcs , FFlatVertex * & ptr ) ;
void SplitRightEdge ( texcoord * tcs , FFlatVertex * & ptr ) ;
void SplitUpperEdge ( texcoord * tcs , FFlatVertex * & ptr ) ;
void SplitLowerEdge ( texcoord * tcs , FFlatVertex * & ptr ) ;
2013-06-23 07:49:34 +00:00
public :
void Process ( seg_t * seg , sector_t * frontsector , sector_t * backsector ) ;
void ProcessLowerMiniseg ( seg_t * seg , sector_t * frontsector , sector_t * backsector ) ;
void Draw ( int pass ) ;
float PointOnSide ( float x , float y )
{
return - ( ( y - glseg . y1 ) * ( glseg . x2 - glseg . x1 ) - ( x - glseg . x1 ) * ( glseg . y2 - glseg . y1 ) ) ;
}
// Lines start-end and fdiv must intersect.
double CalcIntersectionVertex ( GLWall * w2 )
{
float ax = glseg . x1 , ay = glseg . y1 ;
float bx = glseg . x2 , by = glseg . y2 ;
float cx = w2 - > glseg . x1 , cy = w2 - > glseg . y1 ;
float dx = w2 - > glseg . x2 , dy = w2 - > glseg . y2 ;
return ( ( ay - cy ) * ( dx - cx ) - ( ax - cx ) * ( dy - cy ) ) / ( ( bx - ax ) * ( dy - cy ) - ( by - ay ) * ( dx - cx ) ) ;
}
} ;
//==========================================================================
//
// One flat plane in the draw list
//
//==========================================================================
class GLFlat
{
public :
friend struct GLDrawList ;
sector_t * sector ;
subsector_t * sub ; // only used for translucent planes
float dz ; // z offset for rendering hacks
float z ; // the z position of the flat (only valid for non-sloped planes)
FMaterial * gltexture ;
FColormap Colormap ; // light and fog
ERenderStyle renderstyle ;
float alpha ;
GLSectorPlane plane ;
int lightlevel ;
bool stack ;
bool foggy ;
bool ceiling ;
BYTE renderflags ;
int vboindex ;
2016-04-24 11:35:43 +00:00
//int vboheight;
2013-06-23 07:49:34 +00:00
int dynlightindex ;
2014-08-19 12:18:21 +00:00
void SetupSubsectorLights ( int pass , subsector_t * sub , int * dli = NULL ) ;
2013-06-23 07:49:34 +00:00
void DrawSubsector ( subsector_t * sub ) ;
void DrawSubsectorLights ( subsector_t * sub , int pass ) ;
2016-04-14 11:22:15 +00:00
void DrawSkyboxSector ( int pass , bool processlights ) ;
2014-08-19 12:18:21 +00:00
void DrawSubsectors ( int pass , bool processlights , bool istrans ) ;
void ProcessLights ( bool istrans ) ;
2013-06-23 07:49:34 +00:00
void PutFlat ( bool fog = false ) ;
void Process ( sector_t * model , int whichplane , bool notexture ) ;
void SetFrom3DFloor ( F3DFloor * rover , bool top , bool underside ) ;
void ProcessSector ( sector_t * frontsector ) ;
2014-08-19 12:18:21 +00:00
void Draw ( int pass , bool trans ) ;
2013-06-23 07:49:34 +00:00
} ;
//==========================================================================
//
// One sprite in the draw list
//
//==========================================================================
class GLSprite
{
public :
friend struct GLDrawList ;
friend void Mod_RenderModel ( GLSprite * spr , model_t * mdl , int framenumber ) ;
2016-04-06 12:03:21 +00:00
int lightlevel ;
2013-06-23 07:49:34 +00:00
BYTE foglevel ;
BYTE hw_styleflags ;
bool fullbright ;
PalEntry ThingColor ; // thing's own color
FColormap Colormap ;
FSpriteModelFrame * modelframe ;
FRenderStyle RenderStyle ;
int OverrideShader ;
int translation ;
int index ;
int depth ;
2016-04-18 14:27:04 +00:00
float topclip ;
float bottomclip ;
2013-06-23 07:49:34 +00:00
float x , y , z ; // needed for sorting!
float ul , ur ;
float vt , vb ;
float x1 , y1 , z1 ;
float x2 , y2 , z2 ;
FMaterial * gltexture ;
float trans ;
AActor * actor ;
particle_t * particle ;
2016-02-01 17:14:00 +00:00
TArray < lightlist_t > * lightlist ;
2013-06-23 07:49:34 +00:00
2016-04-26 19:31:24 +00:00
void SplitSprite ( sector_t * frontsector , bool translucent ) ;
2013-06-23 07:49:34 +00:00
void SetLowerParam ( ) ;
2016-04-03 11:00:09 +00:00
void PerformSpriteClipAdjustment ( AActor * thing , const DVector2 & thingpos , float spriteheight ) ;
2013-06-23 07:49:34 +00:00
public :
void Draw ( int pass ) ;
void PutSprite ( bool translucent ) ;
2016-04-18 14:27:04 +00:00
void Process ( AActor * thing , sector_t * sector , bool thruportal = false ) ;
2013-06-23 07:49:34 +00:00
void ProcessParticle ( particle_t * particle , sector_t * sector ) ; //, int shade, int fakeside)
void SetThingColor ( PalEntry ) ;
// Lines start-end and fdiv must intersect.
double CalcIntersectionVertex ( GLWall * w2 ) ;
} ;
inline float Dist2 ( float x1 , float y1 , float x2 , float y2 )
{
return sqrtf ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;
}
// Light + color
2016-03-22 22:19:21 +00:00
void gl_SetDynSpriteLight ( AActor * self , float x , float y , float z , subsector_t * subsec ) ;
2014-05-11 15:56:38 +00:00
void gl_SetDynSpriteLight ( AActor * actor , particle_t * particle ) ;
2013-06-23 07:49:34 +00:00
# endif