Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Enumerations | Functions | Variables
renderva.cpp File Reference
#include <SDL_opengl.h>
#include <limits.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include <unordered_set>
#include "inexor/engine/dynlight.hpp"
#include "inexor/engine/glare.hpp"
#include "inexor/engine/glemu.hpp"
#include "inexor/engine/glexts.hpp"
#include "inexor/engine/grass.hpp"
#include "inexor/engine/lightmap.hpp"
#include "inexor/engine/octaedit.hpp"
#include "inexor/engine/octarender.hpp"
#include "inexor/engine/octree.hpp"
#include "inexor/engine/pvs.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/engine/renderva.hpp"
#include "inexor/engine/shader.hpp"
#include "inexor/engine/shadowmap.hpp"
#include "inexor/engine/water.hpp"
#include "inexor/engine/world.hpp"
#include "inexor/fpsgame/entities.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/model/model.hpp"
#include "inexor/model/rendermodel.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_types.hpp"
#include "inexor/shared/cube_vector.hpp"
#include "inexor/shared/ents.hpp"
#include "inexor/shared/geom.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/texture/cubemap.hpp"
#include "inexor/texture/slot.hpp"
#include "inexor/texture/texture.hpp"
#include "inexor/util/legacy_time.hpp"

Classes

struct  queryframe
 
struct  renderstate
 
struct  geombatch
 

Macros

#define VASORTSIZE   64
 
#define MAXQUERY   2048
 
#define MAXQUERYFRAMES   2
 
#define GENFACEORIENT(orient, v0, v1, v2, v3)
 
#define GENFACEVERT(orient, vert, ox, oy, oz, rx, ry, rz)   (ox | oy | oz)
 
#define startvaquery(va, flush)
 
#define endvaquery(va, flush)
 
#define NUMCAUSTICS   16
 
#define FIRSTVA   (reflecting ? reflectedva : visibleva)
 
#define NEXTVA   (reflecting ? va->rnext : va->next)
 

Enumerations

enum  {
  RENDERPASS_LIGHTMAP = 0, RENDERPASS_Z, RENDERPASS_CAUSTICS, RENDERPASS_FOG,
  RENDERPASS_LIGHTMAP_BLEND
}
 

Functions

static void drawtris (GLsizei numindices, const GLvoid *indices, ushort minvert, ushort maxvert)
 
static void drawvatris (vtxarray *va, GLsizei numindices, const GLvoid *indices)
 
bool isfoggedsphere (float rad, const vec &cv)
 
int isvisiblesphere (float rad, const vec &cv)
 
static int ishiddencube (const ivec &o, int size)
 
static int isfoggedcube (const ivec &o, int size)
 
int isvisiblecube (const ivec &o, int size)
 
float vadist (vtxarray *va, const vec &p)
 
void addvisibleva (vtxarray *va)
 
void sortvisiblevas ()
 
void findvisiblevas (vector< vtxarray * > &vas, bool resetocclude=false)
 
void calcvfcD ()
 
void setvfcP (float z, const vec &bbmin, const vec &bbmax)
 
void savevfcP ()
 
void restorevfcP ()
 
void visiblecubes (bool cull)
 
static bool insideva (const vtxarray *va, const vec &v, int margin=2)
 
int getnumqueries ()
 
void flipqueries ()
 
occludequerynewquery (void *owner)
 
void resetqueries ()
 
void clearqueries ()
 
 VAR (oqfrags, 0, 8, 64)
 
 VAR (oqwait, 0, 1, 1)
 
bool checkquery (occludequery *query, bool nowait)
 
static void setupbb ()
 
static void cleanupbb ()
 
void startbb (bool mask)
 
void endbb (bool mask)
 
void drawbb (const ivec &bo, const ivec &br)
 
static bool insideoe (const octaentities *oe, const vec &v, int margin=1)
 
void findvisiblemms (const vector< extentity * > &ents)
 
 VAR (oqmm, 0, 4, 8)
 
void rendermapmodel (extentity &e)
 
void renderreflectedmapmodels ()
 
void rendermapmodels ()
 
static bool bbinsideva (const ivec &bo, const ivec &br, vtxarray *va)
 
static bool bboccluded (const ivec &bo, const ivec &br, cube *c, const ivec &o, int size)
 
bool bboccluded (const ivec &bo, const ivec &br)
 
 VAR (outline, 0, 0, 1)
 
 HVARP (outlinecolour, 0, 0, 0xFFFFFF)
 
 VAR (dtoutline, 0, 1, 1)
 
void renderoutline ()
 
 HVAR (blendbrushcolor, 0, 0x0000C0, 0xFFFFFF)
 
void renderblendbrush (uint tex, float x, float y, float w, float h)
 
void rendershadowmapreceivers ()
 
void renderdepthobstacles (const vec &bbmin, const vec &bbmax, float scale, float *ranges, int numranges)
 
 VAR (oqdist, 0, 256, 1024)
 
 VAR (zpass, 0, 1, 1)
 
 VAR (glowpass, 0, 1, 1)
 
 VAR (envpass, 0, 1, 1)
 
static void disablevbuf (renderstate &cur)
 
static void enablevquery (renderstate &cur)
 
static void disablevquery (renderstate &cur)
 
static void renderquery (renderstate &cur, occludequery *query, vtxarray *va, bool full=true)
 
static void mergetexs (renderstate &cur, vtxarray *va, elementset *texs=nullptr, int numtexs=0, ushort *edata=nullptr)
 
static void enablevattribs (renderstate &cur, bool all=true)
 
static void disablevattribs (renderstate &cur, bool all=true)
 
static void changevbuf (renderstate &cur, int pass, vtxarray *va)
 
void resetinvalidtextslots ()
 Resets the set of slots that an error has been reported for. More...
 
static void reportinvalidtextslot (Slot *slot)
 Reports a slot with an invalid texture definition. More...
 
static void changebatchtmus (renderstate &cur, int pass, geombatch &b)
 
static void changeslottmus (renderstate &cur, int pass, Slot &slot, VSlot &vslot)
 
static void changeshader (renderstate &cur, Shader *s, Slot &slot, VSlot &vslot, bool shadowed)
 
static void changetexgen (renderstate &cur, int dim, Slot &slot, VSlot &vslot)
 
static void renderbatch (renderstate &cur, int pass, geombatch &b)
 
static void resetbatches ()
 
static void renderbatches (renderstate &cur, int pass)
 
void renderzpass (renderstate &cur, vtxarray *va)
 
void renderfoggedvas (renderstate &cur, bool doquery=false)
 
 VAR (batchgeom, 0, 1, 1)
 
void renderva (renderstate &cur, vtxarray *va, int pass=RENDERPASS_LIGHTMAP, bool fogpass=false, bool doquery=false)
 
 SVARP (causticdir,"texture/inexor/material/water/caustic")
 
void loadcaustics (bool force)
 
void cleanupva ()
 
 VARR (causticscale, 0, 50, 10000)
 
 VARR (causticmillis, 0, 75, 1000)
 
 VARFP (caustics, 0, 1, 1, loadcaustics())
 
void setupcaustics (float blend)
 
void setupgeom (renderstate &cur)
 
void cleanupgeom (renderstate &cur)
 
static void rendergeommultipass (renderstate &cur, int pass, bool fogpass)
 
 VAR (oqgeom, 0, 1, 1)
 
void rendergeom (float causticspass, bool fogpass)
 
void renderalphageom (bool fogpass)
 
void findreflectedvas (vector< vtxarray * > &vas, int prevvfc=VFC_PART_VISIBLE)
 
void renderreflectedgeom (bool causticspass, bool fogpass)
 
void renderskyva (vtxarray *va, bool explicitonly=false)
 
static void updateskystats (vtxarray *va)
 
void renderreflectedskyvas (vector< vtxarray * > &vas, int prevvfc=VFC_PART_VISIBLE)
 
bool rendersky (bool explicitonly)
 

Variables

plane vfcP [5]
 
float vfcDfog
 
float vfcDnear [5]
 
float vfcDfar [5]
 
vtxarrayvisibleva
 
static vtxarrayvasort [VASORTSIZE]
 
plane oldvfcP [5]
 
static queryframe queryframes [MAXQUERYFRAMES]
 
static uint flipquery = 0
 
static GLuint bbvbo = 0
 
static GLuint bbebo = 0
 
SharedVar< int > octaentsize
 
static octaentitiesvisiblemms
 
static octaentities ** lastvisiblemms
 
vtxarrayreflectedva
 
static vector< geombatchgeombatches
 
static int firstbatch = -1
 
static int numbatches = 0
 
static std::unordered_set< int > reportedinvalidtextsloterrs
 The slots that an error message has been shown for. More...
 
vector< vtxarray * > foggedvas
 
static Texturecaustictex [NUMCAUSTICS] = { nullptr }
 
static vtxarrayprevskyva = nullptr
 
int renderedsky = 0
 
int renderedexplicitsky = 0
 
int renderedskyfaces = 0
 
int renderedskyclip = INT_MAX
 

Macro Definition Documentation

#define endvaquery (   va,
  flush 
)
Value:
do { \
if(va->query) \
{ \
flush; \
endquery(va->query); \
} \
} while(0)
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
#define endquery(query)
Definition: renderva.hpp:40

Referenced by renderfoggedvas(), and renderva().

#define FIRSTVA   (reflecting ? reflectedva : visibleva)
#define GENFACEORIENT (   orient,
  v0,
  v1,
  v2,
  v3 
)
Value:
do { \
int offset = orient*3*2; \
tris[offset + 0] = v0; \
tris[offset + 1] = v1; \
tris[offset + 2] = v2; \
tris[offset + 3] = v0; \
tris[offset + 4] = v2; \
tris[offset + 5] = v3; \
} while(0);
int orient
Definition: octaedit.cpp:164
GLintptr offset
Definition: glexts.hpp:354
#define GENFACEVERT (   orient,
  vert,
  ox,
  oy,
  oz,
  rx,
  ry,
  rz 
)    (ox | oy | oz)
#define MAXQUERY   2048

Referenced by queryframe::newquery().

#define MAXQUERYFRAMES   2
#define NEXTVA   (reflecting ? va->rnext : va->next)
#define NUMCAUSTICS   16
#define startvaquery (   va,
  flush 
)
Value:
do { \
if(va->query) \
{ \
flush; \
startquery(va->query); \
} \
} while(0)
#define startquery(query)
Definition: renderva.hpp:39
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2

Referenced by renderfoggedvas(), and renderva().

#define VASORTSIZE   64

Referenced by addvisibleva(), and sortvisiblevas().

Enumeration Type Documentation

anonymous enum
Enumerator
RENDERPASS_LIGHTMAP 
RENDERPASS_Z 
RENDERPASS_CAUSTICS 
RENDERPASS_FOG 
RENDERPASS_LIGHTMAP_BLEND 

Function Documentation

void addvisibleva ( vtxarray va)
static bool bbinsideva ( const ivec bo,
const ivec br,
vtxarray va 
)
inlinestatic

References vtxarray::bbmax, and vtxarray::bbmin.

Referenced by bboccluded().

static bool bboccluded ( const ivec bo,
const ivec br,
cube c,
const ivec o,
int  size 
)
inlinestatic
bool bboccluded ( const ivec bo,
const ivec br 
)
void calcvfcD ( )

References loopi(), loopk, vfcDfar, and vfcDnear.

Referenced by restorevfcP(), and setvfcP().

static void changebatchtmus ( renderstate cur,
int  pass,
geombatch b 
)
static
static void changeshader ( renderstate cur,
Shader s,
Slot slot,
VSlot vslot,
bool  shadowed 
)
static
static void changeslottmus ( renderstate cur,
int  pass,
Slot slot,
VSlot vslot 
)
static
static void changetexgen ( renderstate cur,
int  dim,
Slot slot,
VSlot vslot 
)
static
static void changevbuf ( renderstate cur,
int  pass,
vtxarray va 
)
static
bool checkquery ( occludequery query,
bool  nowait 
)
static void cleanupbb ( )
static

References bbebo, bbvbo, and glDeleteBuffers_.

Referenced by cleanupva().

void cleanupgeom ( renderstate cur)
void cleanupva ( )
void clearqueries ( )

References queryframe::cleanup(), loopi(), and MAXQUERYFRAMES.

Referenced by cleanupva().

static void disablevattribs ( renderstate cur,
bool  all = true 
)
inlinestatic
static void disablevbuf ( renderstate cur)
inlinestatic
static void disablevquery ( renderstate cur)
inlinestatic

References endbb(), and renderstate::vquery.

Referenced by renderbatches(), rendergeom(), and renderzpass().

void drawbb ( const ivec bo,
const ivec br 
)
static void drawtris ( GLsizei  numindices,
const GLvoid *  indices,
ushort  minvert,
ushort  maxvert 
)
inlinestatic

References glde, and glDrawRangeElements_.

Referenced by drawvatris(), and renderbatch().

static void drawvatris ( vtxarray va,
GLsizei  numindices,
const GLvoid *  indices 
)
inlinestatic
static void enablevattribs ( renderstate cur,
bool  all = true 
)
inlinestatic
static void enablevquery ( renderstate cur)
inlinestatic
void endbb ( bool  mask)
void findreflectedvas ( vector< vtxarray * > &  vas,
int  prevvfc = VFC_PART_VISIBLE 
)
void findvisiblemms ( const vector< extentity * > &  ents)
void findvisiblevas ( vector< vtxarray * > &  vas,
bool  resetocclude = false 
)
void flipqueries ( )

References queryframe::flip(), flipquery, and MAXQUERYFRAMES.

Referenced by rendergeom().

int getnumqueries ( )

References queryframe::cur, and flipquery.

Referenced by gl_drawhud().

HVAR ( blendbrushcolor  ,
,
0x0000C0  ,
0xFFFFFF   
)
HVARP ( outlinecolour  ,
,
,
0xFFFFFF   
)
static bool insideoe ( const octaentities oe,
const vec v,
int  margin = 1 
)
inlinestatic
static bool insideva ( const vtxarray va,
const vec v,
int  margin = 2 
)
inlinestatic

References vtxarray::o, and vtxarray::size.

Referenced by rendergeom().

static int isfoggedcube ( const ivec o,
int  size 
)
inlinestatic
bool isfoggedsphere ( float  rad,
const vec cv 
)
static int ishiddencube ( const ivec o,
int  size 
)
inlinestatic
int isvisiblecube ( const ivec o,
int  size 
)
int isvisiblesphere ( float  rad,
const vec cv 
)
void loadcaustics ( bool  force)
static void mergetexs ( renderstate cur,
vtxarray va,
elementset texs = nullptr,
int  numtexs = 0,
ushort edata = nullptr 
)
static
occludequery* newquery ( void owner)
void renderalphageom ( bool  fogpass)
static void renderbatch ( renderstate cur,
int  pass,
geombatch b 
)
static
static void renderbatches ( renderstate cur,
int  pass 
)
static
void renderblendbrush ( uint  tex,
float  x,
float  y,
float  w,
float  h 
)
void renderdepthobstacles ( const vec bbmin,
const vec bbmax,
float  scale,
float *  ranges,
int  numranges 
)
void renderfoggedvas ( renderstate cur,
bool  doquery = false 
)
void rendergeom ( float  causticspass,
bool  fogpass 
)
static void rendergeommultipass ( renderstate cur,
int  pass,
bool  fogpass 
)
static
void rendermapmodel ( extentity e)
void rendermapmodels ( )
void renderoutline ( )
static void renderquery ( renderstate cur,
occludequery query,
vtxarray va,
bool  full = true 
)
static
void renderreflectedgeom ( bool  causticspass,
bool  fogpass 
)
void renderreflectedmapmodels ( )
void renderreflectedskyvas ( vector< vtxarray * > &  vas,
int  prevvfc = VFC_PART_VISIBLE 
)
void rendershadowmapreceivers ( )
bool rendersky ( bool  explicitonly)
void renderskyva ( vtxarray va,
bool  explicitonly = false 
)
void renderva ( renderstate cur,
vtxarray va,
int  pass = RENDERPASS_LIGHTMAP,
bool  fogpass = false,
bool  doquery = false 
)
void renderzpass ( renderstate cur,
vtxarray va 
)
static void reportinvalidtextslot ( Slot slot)
static

Reports a slot with an invalid texture definition.

Keeps track of what slots already have been reported in order to show an error only once.

References Slot::index, Log, loopv, Slot::Tex::name, inexor::util::log_manager::std, Slot::sts, anonymous_namespace{utilTest.cpp}::t(), TEX_DIFFUSE, and Slot::Tex::type.

Referenced by changebatchtmus().

static void resetbatches ( )
static
void resetinvalidtextslots ( )

Resets the set of slots that an error has been reported for.

Referenced by clearslots().

void resetqueries ( )

References loopi(), MAXQUERYFRAMES, and queryframe::reset().

Referenced by allchanged().

void restorevfcP ( )

References calcvfcD().

Referenced by drawreflections().

void savevfcP ( )

Referenced by drawreflections().

static void setupbb ( )
static
void setupcaustics ( float  blend)
void setupgeom ( renderstate cur)
void setvfcP ( float  z,
const vec bbmin,
const vec bbmax 
)
void sortvisiblevas ( )

References loopi(), vtxarray::next, VASORTSIZE, and visibleva.

Referenced by visiblecubes().

void startbb ( bool  mask)
SVARP ( causticdir  ,
"texture/inexor/material/water/caustic"   
)
static void updateskystats ( vtxarray va)
inlinestatic
float vadist ( vtxarray va,
const vec p 
)
VAR ( oqfrags  ,
,
,
64   
)
VAR ( oqwait  ,
,
,
 
)
VAR ( oqmm  ,
,
,
 
)
VAR ( outline  ,
,
,
 
)
VAR ( dtoutline  ,
,
,
 
)
VAR ( oqdist  ,
,
256  ,
1024   
)
VAR ( zpass  ,
,
,
 
)
VAR ( glowpass  ,
,
,
 
)
VAR ( envpass  ,
,
,
 
)
VAR ( batchgeom  ,
,
,
 
)
VAR ( oqgeom  ,
,
,
 
)
VARFP ( caustics  ,
,
,
,
loadcaustics()   
)
VARR ( causticscale  ,
,
50  ,
10000   
)
VARR ( causticmillis  ,
,
75  ,
1000   
)
void visiblecubes ( bool  cull)

Variable Documentation

GLuint bbebo = 0
static

Referenced by cleanupbb(), setupbb(), and startbb().

GLuint bbvbo = 0
static

Referenced by cleanupbb(), setupbb(), and startbb().

Texture* caustictex[NUMCAUSTICS] = { nullptr }
static
int firstbatch = -1
static
uint flipquery = 0
static
vector<vtxarray *> foggedvas
vector<geombatch> geombatches
static
octaentities ** lastvisiblemms
static
int numbatches = 0
static

Referenced by mergetexs(), and resetbatches().

SharedVar<int> octaentsize

Referenced by findents(), and modifyoctaent().

plane oldvfcP[5]
vtxarray* prevskyva = nullptr
static
queryframe queryframes[MAXQUERYFRAMES]
static
vtxarray* reflectedva

Referenced by findreflectedvas(), and sortmaterials().

int renderedexplicitsky = 0

Referenced by rendersky(), and updateskystats().

int renderedsky = 0
int renderedskyclip = INT_MAX
int renderedskyfaces = 0
std::unordered_set<int> reportedinvalidtextsloterrs
static

The slots that an error message has been shown for.

This is used to prevent repeating the same error over and over.

vtxarray* vasort[VASORTSIZE]
static
float vfcDfar[5]
float vfcDfog
float vfcDnear[5]
plane vfcP[5]
octaentities* visiblemms
static
vtxarray* visibleva