Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Enumerations | Functions | Variables
octarender.cpp File Reference
#include "inexor/engine/octarender.hpp"
#include <SDL_opengl.h>
#include <boost/algorithm/clamp.hpp>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include "inexor/engine/blob.hpp"
#include "inexor/engine/glemu.hpp"
#include "inexor/engine/glexts.hpp"
#include "inexor/engine/lightmap.hpp"
#include "inexor/engine/material.hpp"
#include "inexor/engine/octa.hpp"
#include "inexor/engine/octree.hpp"
#include "inexor/engine/renderbackground.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/engine/renderparticles.hpp"
#include "inexor/engine/rendersky.hpp"
#include "inexor/engine/renderva.hpp"
#include "inexor/engine/shader.hpp"
#include "inexor/engine/shadowmap.hpp"
#include "inexor/engine/world.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/network/legacy/buffer_types.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_hash.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_tools.hpp"
#include "inexor/shared/cube_types.hpp"
#include "inexor/shared/cube_vector.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"

Classes

struct  vboinfo
 
struct  verthash
 
struct  sortkey
 
struct  sortval
 
struct  vacollect
 
struct  edgegroup
 
struct  cubeedge
 
struct  mergedface
 

Macros

#define GENVERTS(type, ptr, body)
 
#define progress(s)   if((recalcprogress++&0xFFF)==0) renderprogress(recalcprogress/(float)allocnodes, s);
 
#define MAXMERGELEVEL   12
 

Enumerations

enum  { VBO_VBUF = 0, VBO_EBUF, VBO_SKYBUF, NUMVBO }
 
enum  { NO_ALPHA = 0, ALPHA_BACK, ALPHA_FRONT }
 
enum  { CE_START = 1<<0, CE_END = 1<<1, CE_FLIP = 1<<2, CE_DUP = 1<<3 }
 

Functions

 VAR (debugvbo, 0, 0, 1)
 
 VARFN (vbosize, maxvbosize, 0, 16384, 65536, allchanged())
 
void destroyvbo (GLuint vbo)
 
void genvbo (int type, void *buf, int len, vtxarray **vas, int numva)
 
bool readva (vtxarray *va, ushort *&edata, vertex *&vdata)
 
void flushvbo (int type=-1)
 
ucharaddvbo (vtxarray *va, int type, int numelems, int elemsize)
 
static bool htcmp (const sortkey &x, const sortkey &y)
 
static uint hthash (const sortkey &k)
 
int calcshadowmask (vec *pos, int numpos)
 
 VARFP (filltjoints, 0, 1, 1, allchanged())
 
void reduceslope (ivec &n)
 
void addtris (const sortkey &key, int orient, vertex *verts, int *index, int numverts, int convex, int shadowmask, int tj)
 
void addgrasstri (int face, vertex *verts, int numv, ushort texture, ushort lmid)
 
static void calctexgen (VSlot &vslot, int dim, vec4 &sgen, vec4 &tgen)
 
ushort encodenormal (const vec &n)
 
vec decodenormal (ushort norm)
 
void guessnormals (const vec *pos, int numverts, vec *normals)
 
void addcubeverts (VSlot &vslot, int orient, int size, vec *pos, int convex, ushort texture, ushort lmid, vertinfo *vinfo, int numverts, int tj=-1, ushort envmap=EMID_NONE, int grassy=0, bool alpha=false, int layer=LAYER_TOP)
 
static uint hthash (const edgegroup &g)
 
static bool htcmp (const edgegroup &x, const edgegroup &y)
 
void gencubeedges (cube &c, const ivec &co, int size)
 
void gencubeedges (cube *c=worldroot, const ivec &co=ivec(0, 0, 0), int size=worldsize >>1)
 
void gencubeverts (cube &c, const ivec &co, int size, int csi)
 
static bool skyoccluded (cube &c, int orient)
 
static int hasskyfaces (cube &c, const ivec &co, int size, int faces[6]=dummyskyfaces)
 
void minskyface (cube &cu, int orient, const ivec &co, int size, facebounds &orig)
 
void genskyfaces (cube &c, const ivec &o, int size)
 
void addskyverts (const ivec &o, int size)
 
vtxarraynewva (const ivec &co, int size)
 
void destroyva (vtxarray *va, bool reparent)
 
void clearvas (cube *c)
 
void updatevabb (vtxarray *va, bool force)
 
void updatevabbs (bool force)
 
int genmergedfaces (cube &c, const ivec &co, int size, int minlevel=-1)
 
int findmergedfaces (cube &c, const ivec &co, int size, int csi, int minlevel)
 
void addmergedverts (int level, const ivec &o)
 
void rendercube (cube &c, const ivec &co, int size, int csi, int &maxlevel)
 
void calcgeombb (const ivec &co, int size, ivec &bbmin, ivec &bbmax)
 
void calcmatbb (const ivec &co, int size, ivec &bbmin, ivec &bbmax)
 
void setva (cube &c, const ivec &co, int size, int csi)
 
static int setcubevisibility (cube &c, const ivec &co, int size)
 
 VARF (vafacemax, 64, 384, 256 *256, allchanged())
 
 VARF (vafacemin, 0, 96, 256 *256, allchanged())
 
 VARF (vacubesize, 32, 128, 0x1000, allchanged())
 
int updateva (cube *c, const ivec &co, int size, int csi)
 
void addtjoint (const edgegroup &g, const cubeedge &e, int offset)
 
void findtjoints (int cur, const edgegroup &g)
 
void findtjoints ()
 
void octarender ()
 
void precachetextures ()
 
void allchanged (bool load)
 
void recalc ()
 
 COMMAND (recalc,"")
 

Variables

hashtable< GLuint, vboinfovbos
 
static vector< ucharvbodata [NUMVBO]
 
static vector< vtxarray * > vbovas [NUMVBO]
 
static int vbosize [NUMVBO]
 
vacollect vc
 
int recalcprogress = 0
 
vector< tjointtjoints
 
vec shadowmapmin
 
vec shadowmapmax
 
vec orientation_tangent [6][3]
 
vec orientation_bitangent [6][3]
 
vector< cubeedgecubeedges
 
hashtable< edgegroup, int > edgegroups (1<< 13)
 
static int dummyskyfaces [6]
 
int allocva = 0
 
int wtris = 0
 
int wverts = 0
 
int vtris = 0
 
int vverts = 0
 
int glde = 0
 
int gbatches = 0
 
vector< vtxarray * > valist
 
vector< vtxarray * > varoot
 
static int vahasmerges = 0
 
static int vamergemax = 0
 
static vector< mergedfacevamerges [MAXMERGELEVEL+1]
 

Class Documentation

struct vboinfo
Class Members
int uses
struct edgegroup
Class Members
int axis
ivec origin
ivec slope
struct cubeedge
Class Members
cube * c
uchar flags
uchar index
int next
int offset
ushort size
struct mergedface
Class Members
ushort envmap
uchar lmid
ushort mat
uchar numverts
uchar orient
ushort tex
int tjoints
vertinfo * verts

Macro Definition Documentation

#define GENVERTS (   type,
  ptr,
  body 
)
Value:
do \
{ \
type *f = (type *)ptr; \
{ \
const vertex &v = verts[i]; \
body; \
f++; \
} \
} while(0)
ICOMMAND * f(float *a, float *b), floatret(*a **b)
struct sphere::vert * verts
Definition: world.hpp:82
#define loopv(v)
Definition: cube_loops.hpp:21

Referenced by vacollect::genverts().

#define MAXMERGELEVEL   12

Referenced by rendercube(), setva(), and updateva().

#define progress (   s)    if((recalcprogress++&0xFFF)==0) renderprogress(recalcprogress/(float)allocnodes, s);

Referenced by gencubeedges(), and updateva().

Enumeration Type Documentation

anonymous enum
Enumerator
VBO_VBUF 
VBO_EBUF 
VBO_SKYBUF 
NUMVBO 
anonymous enum
Enumerator
NO_ALPHA 
ALPHA_BACK 
ALPHA_FRONT 
anonymous enum
Enumerator
CE_START 
CE_END 
CE_FLIP 
CE_DUP 

Function Documentation

void addcubeverts ( VSlot vslot,
int  orient,
int  size,
vec pos,
int  convex,
ushort  texture,
ushort  lmid,
vertinfo vinfo,
int  numverts,
int  tj = -1,
ushort  envmap = EMID_NONE,
int  grassy = 0,
bool  alpha = false,
int  layer = LAYER_TOP 
)
void addgrasstri ( int  face,
vertex verts,
int  numv,
ushort  texture,
ushort  lmid 
)
void addmergedverts ( int  level,
const ivec o 
)
void addskyverts ( const ivec o,
int  size 
)
void addtjoint ( const edgegroup g,
const cubeedge e,
int  offset 
)
void addtris ( const sortkey key,
int  orient,
vertex verts,
int *  index,
int  numverts,
int  convex,
int  shadowmask,
int  tj 
)
uchar* addvbo ( vtxarray va,
int  type,
int  numelems,
int  elemsize 
)
void allchanged ( bool  load)
void calcgeombb ( const ivec co,
int  size,
ivec bbmin,
ivec bbmax 
)
void calcmatbb ( const ivec co,
int  size,
ivec bbmin,
ivec bbmax 
)
int calcshadowmask ( vec pos,
int  numpos 
)

References loopk, vec::max(), vec::min(), shadowdir, and vec::sub().

Referenced by addcubeverts().

static void calctexgen ( VSlot vslot,
int  dim,
vec4 sgen,
vec4 tgen 
)
inlinestatic
void clearvas ( cube c)
COMMAND ( recalc  ,
""   
)
vec decodenormal ( ushort  norm)

References sincos360.

Referenced by addcubeverts().

void destroyva ( vtxarray va,
bool  reparent 
)
void destroyvbo ( GLuint  vbo)
ushort encodenormal ( const vec n)

References vec::iszero(), and RAD.

Referenced by convertoldsurfaces(), and setupsurfaces().

int findmergedfaces ( cube c,
const ivec co,
int  size,
int  csi,
int  minlevel 
)
void findtjoints ( int  cur,
const edgegroup g 
)
void findtjoints ( )
void flushvbo ( int  type = -1)
void gencubeedges ( cube c,
const ivec co,
int  size 
)
void gencubeedges ( cube c = worldroot,
const ivec co = ivec(0, 0, 0),
int  size = worldsize>>1 
)
void gencubeverts ( cube c,
const ivec co,
int  size,
int  csi 
)
int genmergedfaces ( cube c,
const ivec co,
int  size,
int  minlevel = -1 
)
void genskyfaces ( cube c,
const ivec o,
int  size 
)
void genvbo ( int  type,
void buf,
int  len,
vtxarray **  vas,
int  numva 
)
void guessnormals ( const vec pos,
int  numverts,
vec normals 
)
static int hasskyfaces ( cube c,
const ivec co,
int  size,
int  faces[6] = dummyskyfaces 
)
inlinestatic
static bool htcmp ( const sortkey x,
const sortkey y 
)
inlinestatic
static bool htcmp ( const edgegroup x,
const edgegroup y 
)
static
static uint hthash ( const sortkey k)
inlinestatic

References sortkey::lmid, and sortkey::tex.

Referenced by verthash::addvert().

static uint hthash ( const edgegroup g)
static
void minskyface ( cube cu,
int  orient,
const ivec co,
int  size,
facebounds orig 
)
vtxarray* newva ( const ivec co,
int  size 
)
void octarender ( )
void precachetextures ( )
bool readva ( vtxarray va,
ushort *&  edata,
vertex *&  vdata 
)
void recalc ( )

References allchanged().

void reduceslope ( ivec n)

References C, ivec::div(), loopi(), R, and ivec::shr().

Referenced by addnormals(), addtris(), gencubeedges(), and genpoly().

void rendercube ( cube c,
const ivec co,
int  size,
int  csi,
int &  maxlevel 
)
static int setcubevisibility ( cube c,
const ivec co,
int  size 
)
inlinestatic
void setva ( cube c,
const ivec co,
int  size,
int  csi 
)
static bool skyoccluded ( cube c,
int  orient 
)
inlinestatic

References F_SOLID, faceedges(), and touchingface().

Referenced by hasskyfaces().

int updateva ( cube c,
const ivec co,
int  size,
int  csi 
)
void updatevabb ( vtxarray va,
bool  force 
)
void updatevabbs ( bool  force)

References loopv, and updatevabb().

Referenced by allchanged(), and commitchanges().

VAR ( debugvbo  ,
,
,
 
)
VARF ( vafacemax  ,
64  ,
384  ,
256 *  256,
allchanged()   
)
VARF ( vafacemin  ,
,
96  ,
256 *  256,
allchanged()   
)
VARF ( vacubesize  ,
32  ,
128  ,
0x1000  ,
allchanged()   
)
VARFN ( vbosize  ,
maxvbosize  ,
,
16384  ,
65536  ,
allchanged()   
)
VARFP ( filltjoints  ,
,
,
,
allchanged()   
)

Variable Documentation

int allocva = 0

Referenced by gl_drawhud().

vector<cubeedge> cubeedges
int dummyskyfaces[6]
static
hashtable<edgegroup, int> edgegroups(1<< 13)

Referenced by findtjoints(), and gencubeedges().

int gbatches = 0
int glde = 0
vec orientation_bitangent[6][3]
Initial value:
=
{
{ vec(0, 0, -1), vec( 0, 0, -1), vec( 0, 1, 0) },
{ vec(0, -1, 0), vec(-1, 0, 0), vec(-1, 0, 0) },
{ vec(0, 0, 1), vec( 0, 0, 1), vec( 0, -1, 0) },
{ vec(0, 1, 0), vec( 1, 0, 0), vec( 1, 0, 0) },
{ vec(0, 0, -1), vec( 0, 0, -1), vec( 0, 1, 0) },
{ vec(0, 0, 1), vec( 0, 0, 1), vec( 0, -1, 0) },
}
vector with 3 floats and some useful methods.
Definition: geom.hpp:110

Referenced by generatelumel().

vec orientation_tangent[6][3]
Initial value:
=
{
{ vec(0, 1, 0), vec( 1, 0, 0), vec( 1, 0, 0) },
{ vec(0, 0, -1), vec( 0, 0, -1), vec( 0, 1, 0) },
{ vec(0, -1, 0), vec(-1, 0, 0), vec(-1, 0, 0) },
{ vec(0, 0, 1), vec( 0, 0, 1), vec( 0, -1, 0) },
{ vec(0, -1, 0), vec(-1, 0, 0), vec(-1, 0, 0) },
{ vec(0, 1, 0), vec( 1, 0, 0), vec( 1, 0, 0) },
}
vector with 3 floats and some useful methods.
Definition: geom.hpp:110

Referenced by generatelumel().

int recalcprogress = 0
vec shadowmapmax
vec shadowmapmin
vector<tjoint> tjoints

Referenced by addnormals().

int vahasmerges = 0
static

Referenced by setva(), and updateva().

vector<vtxarray *> valist
int vamergemax = 0
static

Referenced by genmergedfaces(), setva(), and updateva().

vector<mergedface> vamerges[MAXMERGELEVEL+1]
static
vector<vtxarray *> varoot
vector<uchar> vbodata[NUMVBO]
static
int vbosize[NUMVBO]
static
vector<vtxarray *> vbovas[NUMVBO]
static
int vtris = 0
int vverts = 0
int wtris = 0

Referenced by gl_drawhud().

int wverts = 0

Referenced by destroyva(), gl_drawhud(), and newva().