UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
r_bsp.cpp File Reference

BSP model code. More...

#include "r_local.h"
#include "r_lightmap.h"
#include "r_material.h"
#include "r_light.h"
#include "r_draw.h"

Go to the source code of this file.

Data Structures

struct  bspRenderRef_s
 

Macros

#define BACKFACE_EPSILON   0.01
 
#define MAX_BSPS_TO_RENDER   1024
 

Typedefs

typedef struct bspRenderRef_s bspRenderRef_t
 
typedef void(* drawSurfaceFunc )(const mBspSurfaces_t *surfs, glElementIndex_t *indexPtr)
 

Functions

static int R_CullBox (const vec3_t mins, const vec3_t maxs)
 Returns whether if the specified bounding box is completely culled by the view frustum (PSIDE_BACK), completely not culled (PSIDE_FRONT) or split by it (PSIDE_BOTH) More...
 
bool R_CullSphere (const vec3_t centre, const float radius, const unsigned int clipflags)
 Performs a spherical frustum check. More...
 
bool R_CullBspModel (const entity_t *e)
 Returns true if the specified entity is completely culled by the view frustum, false otherwise. More...
 
void R_DrawBspNormals (int tile)
 Developer tool for viewing BSP vertex normals. Only Phong interpolated surfaces show their normals when r_shownormals > 1. More...
 
static void R_RecursiveVisibleWorldNode (const mBspNode_t *node, int tile)
 Recurse down the bsp tree and mark all surfaces as visible for being rendered. More...
 
static void R_RecursiveWorldNode (const mBspNode_t *node, int tile)
 Recurse down the bsp tree and mark surfaces that are visible (not culled) for being rendered. More...
 
static void R_RecurseWorld (const mBspNode_t *node, int tile)
 Wrapper that recurses the bsp nodes but skip the pathfinding nodes. More...
 
void R_GetLevelSurfaceLists (void)
 Fills the surface chains for the current worldlevel and hide other levels. More...
 
void R_ClearBspRRefs (void)
 
void R_AddBspRRef (const mBspModel_t *model, const vec3_t origin, const vec3_t angles, const bool forceVisibility)
 Adds bsp render references. More...
 
static void R_RenderBspRRefs (drawSurfaceFunc drawFunc, surfaceArrayType_t surfType)
 
void R_RenderOpaqueBspRRefs (void)
 Draw all simple opaque bsp surfaces with multitexture enabled and light enabled. More...
 
void R_RenderOpaqueWarpBspRRefs (void)
 Draw all warped opaque bsp surfaces via warp shader. More...
 
void R_RenderAlphaTestBspRRefs (void)
 
void R_RenderMaterialBspRRefs (void)
 
void R_RenderFlareBspRRefs (void)
 
void R_RenderBlendBspRRefs (void)
 Draw all translucent bsp surfaces with multitexture enabled and blend enabled. More...
 
void R_RenderBlendWarpBspRRefs (void)
 Draw all warped translucent bsp surfaces via warp shader and with blend enabled. More...
 

Variables

static bspRenderRef_t bspRRefs [MAX_BSPS_TO_RENDER]
 
static int numBspRRefs
 

Detailed Description

BSP model code.

Definition in file r_bsp.cpp.

Macro Definition Documentation

#define BACKFACE_EPSILON   0.01

Definition at line 38 of file r_bsp.cpp.

#define MAX_BSPS_TO_RENDER   1024

Definition at line 40 of file r_bsp.cpp.

Referenced by R_AddBspRRef().

Typedef Documentation

typedef void(* drawSurfaceFunc)(const mBspSurfaces_t *surfs, glElementIndex_t *indexPtr)

Definition at line 351 of file r_bsp.cpp.

Function Documentation

void R_AddBspRRef ( const mBspModel_t model,
const vec3_t  origin,
const vec3_t  angles,
const bool  forceVisibility 
)

Adds bsp render references.

Note
If forceVisibility is set, will mark the surfaces of the given bsp model as visible for this frame.
Parameters
[in]modelThe bsp model to add to the render chain
[in]origin
[in]angles
[in]forceVisibilityforce model to be fully visible

Definition at line 324 of file r_bsp.cpp.

References bspRenderRef_s::angles, bspRenderRef_s::bsp, Com_Printf(), mBspModel_s::firstmodelsurface, mBspSurface_s::frame, rlocals_s::frame, i, MAX_BSPS_TO_RENDER, numBspRRefs, mBspModel_s::nummodelsurfaces, bspRenderRef_s::origin, r_locals, mBspModel_s::surfaces, and VectorCopy.

Referenced by R_GetEntityLists(), and R_RenderFrame().

void R_ClearBspRRefs ( void  )

Definition at line 311 of file r_bsp.cpp.

References numBspRRefs.

Referenced by R_ClearScene().

static int R_CullBox ( const vec3_t  mins,
const vec3_t  maxs 
)
static

Returns whether if the specified bounding box is completely culled by the view frustum (PSIDE_BACK), completely not culled (PSIDE_FRONT) or split by it (PSIDE_BOTH)

Parameters
[in]minsThe mins of the bounding box
[in]maxsThe maxs of the bounding box

Definition at line 57 of file r_bsp.cpp.

References rlocals_s::frustum, i, cvar_s::integer, lengthof, PSIDE_BACK, PSIDE_FRONT, r_locals, r_nocull, and TR_BoxOnPlaneSide().

Referenced by R_CullBspModel(), and R_RecursiveWorldNode().

bool R_CullBspModel ( const entity_t e)

Returns true if the specified entity is completely culled by the view frustum, false otherwise.

Parameters
[in]eThe entity to check
See also
R_CullBox

Definition at line 108 of file r_bsp.cpp.

References AABB::expand(), AABB::getMaxs(), AABB::getMins(), entity_t::origin, PSIDE_BACK, R_CullBox(), and AABB::shift().

Referenced by R_CullEntity().

bool R_CullSphere ( const vec3_t  centre,
const float  radius,
const unsigned int  clipflags 
)

Performs a spherical frustum check.

Parameters
[in]centreThe world coordinate that is the center of the sphere
[in]radiusThe radius of the sphere to check the frustum for
[in]clipflagsCan be used to skip sides of the frustum planes
Returns
true if the sphere is completely outside the frustum, false otherwise

Definition at line 83 of file r_bsp.cpp.

References cBspPlane_s::dist, DotProduct, rlocals_s::frustum, i, cvar_s::integer, lengthof, cBspPlane_s::normal, r_locals, and r_nocull.

void R_GetLevelSurfaceLists ( void  )

Fills the surface chains for the current worldlevel and hide other levels.

See also
cvar cl_worldlevel

Definition at line 281 of file r_bsp.cpp.

References model_s::bsp, mBspHeader_s::headnode, i, cvar_s::integer, LEVEL_LASTVISIBLE, mBspModel_s::nodes, mBspHeader_s::numfaces, r_drawworld, r_mapTiles, r_numMapTiles, R_RecurseWorld(), refdef, mBspModel_s::submodels, and rendererData_t::worldlevel.

Referenced by R_RenderFrame(), and R_RunThread().

static void R_RecurseWorld ( const mBspNode_t node,
int  tile 
)
static

Wrapper that recurses the bsp nodes but skip the pathfinding nodes.

See also
R_GetLevelSurfaceLists
Parameters
[in]nodeThe bsp node to check
[in]tileThe maptile (map assembly)
See also
R_ModLoadNodes about pathfinding nodes

Definition at line 265 of file r_bsp.cpp.

References mBspNode_s::children, mBspNode_s::contents, CONTENTS_PATHFINDING_NODE, and R_RecursiveWorldNode().

Referenced by R_GetLevelSurfaceLists().

static void R_RecursiveVisibleWorldNode ( const mBspNode_t node,
int  tile 
)
static

Recurse down the bsp tree and mark all surfaces as visible for being rendered.

See also
R_DrawWorld
R_RecurseWorld
R_RecursiveWorldNode
Parameters
[in]nodeThe bsp node to mark
[in]tileThe maptile (map assembly)

Definition at line 200 of file r_bsp.cpp.

References model_s::bsp, mBspNode_s::children, mBspNode_s::contents, CONTENTS_NODE, mBspNode_s::firstsurface, mBspSurface_s::frame, rlocals_s::frame, i, mBspNode_s::numsurfaces, mBspNode_s::plane, r_locals, r_mapTiles, and mBspModel_s::surfaces.

Referenced by R_RecursiveWorldNode().

static void R_RecursiveWorldNode ( const mBspNode_t node,
int  tile 
)
static

Recurse down the bsp tree and mark surfaces that are visible (not culled) for being rendered.

See also
R_DrawWorld
R_RecurseWorld
R_RecursiveVisibleWorldNode
Parameters
[in]nodeThe bsp node to check
[in]tileThe maptile (map assembly)
Todo:
avoid being too precise, it's a waste of CPU time; possibly, granularity of 256x256x256 should be enough

Definition at line 227 of file r_bsp.cpp.

References model_s::bsp, mBspNode_s::children, mBspNode_s::contents, CONTENTS_NODE, mBspNode_s::firstsurface, mBspSurface_s::frame, rlocals_s::frame, i, AABB::maxs, mBspNode_s::minmaxs, AABB::mins, mBspNode_s::numsurfaces, mBspNode_s::plane, PSIDE_BACK, PSIDE_FRONT, R_CullBox(), r_locals, r_mapTiles, R_RecursiveVisibleWorldNode(), and mBspModel_s::surfaces.

Referenced by R_RecurseWorld().

void R_RenderBlendBspRRefs ( void  )

Draw all translucent bsp surfaces with multitexture enabled and blend enabled.

Definition at line 462 of file r_bsp.cpp.

References rstate_s::blend_enabled, R_DrawSurfaces(), R_EnableTexture(), R_RenderBspRRefs(), r_state, S_BLEND, and texunit_lightmap.

Referenced by R_RenderFrame().

void R_RenderBlendWarpBspRRefs ( void  )

Draw all warped translucent bsp surfaces via warp shader and with blend enabled.

Definition at line 475 of file r_bsp.cpp.

References rstate_s::blend_enabled, R_DrawSurfaces(), R_EnableGlowMap(), R_EnableWarp(), R_RenderBspRRefs(), r_state, S_BLEND_WARP, and rstate_s::warp_program.

Referenced by R_RenderFrame().

static void R_RenderBspRRefs ( drawSurfaceFunc  drawFunc,
surfaceArrayType_t  surfType 
)
static
void R_RenderFlareBspRRefs ( void  )

Definition at line 454 of file r_bsp.cpp.

References R_DrawFlareSurfaces(), R_RenderBspRRefs(), and S_FLARE.

Referenced by R_RenderFrame().

void R_RenderMaterialBspRRefs ( void  )

Definition at line 449 of file r_bsp.cpp.

References R_DrawMaterialSurfaces(), R_RenderBspRRefs(), and S_MATERIAL.

Referenced by R_RenderFrame().

void R_RenderOpaqueBspRRefs ( void  )

Draw all simple opaque bsp surfaces with multitexture enabled and light enabled.

Definition at line 410 of file r_bsp.cpp.

References R_DrawSurfaces(), R_EnableGlowMap(), R_EnableLighting(), R_EnableTexture(), R_EnableWorldLights(), R_RenderBspRRefs(), r_state, S_OPAQUE, texunit_lightmap, and rstate_s::world_program.

Referenced by R_RenderFrame().

void R_RenderOpaqueWarpBspRRefs ( void  )

Draw all warped opaque bsp surfaces via warp shader.

Definition at line 426 of file r_bsp.cpp.

References R_DrawSurfaces(), R_EnableGlowMap(), R_EnableWarp(), R_RenderBspRRefs(), r_state, S_OPAQUE_WARP, and rstate_s::warp_program.

Referenced by R_RenderFrame().

Variable Documentation

Definition at line 48 of file r_bsp.cpp.

int numBspRRefs
static

Definition at line 49 of file r_bsp.cpp.

Referenced by R_AddBspRRef(), R_ClearBspRRefs(), and R_RenderBspRRefs().