summaryrefslogtreecommitdiff
path: root/engine/r_areaportal.h
blob: 06bf3cd3514df21259fdd75902beebef7dbdc301 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef R_AREAPORTAL_H
#define R_AREAPORTAL_H
#ifdef _WIN32
#pragma once
#endif


#include "utlvector.h"
#include "gl_model_private.h"


class Frustum_t;


// Used to clip area portals. The coordinates here are in normalized
// view space (-1,-1) - (1,1)
// BUGBUG: NOTE!!!: These are left->right, and bottom->top, so a full rect is left=-1,top=1,right=1,bottom=-1
class CPortalRect
{
public:
	float	left, top, right, bottom;
};


// ---------------------------------------------------------------------------- //
// Functions.
// ---------------------------------------------------------------------------- //

// Copies cl.pAreaBits, finds the area the viewer is in, and figures out what
// other areas are visible. The new bits are placed in g_RenderAreaBits.
void R_SetupAreaBits( int iForceViewLeaf = -1, const VisOverrideData_t* pVisData = NULL, float *pWaterReflectionHeight = NULL );

// Ask if an area is visible to the renderer.
unsigned char R_IsAreaVisible( int area );

void R_Areaportal_LevelInit();
void R_Areaportal_LevelShutdown();

// Decides if the node can be seen through the area portals (ie: if you're
// looking out a window with an areaportal in it, this will clip out the
// stuff to the sides).
enum
{
	FRUSTUM_CLIP_RIGHT = (1 << FRUSTUM_RIGHT),
	FRUSTUM_CLIP_LEFT = (1 << FRUSTUM_LEFT),
	FRUSTUM_CLIP_TOP = (1 << FRUSTUM_TOP),
	FRUSTUM_CLIP_BOTTOM = (1 << FRUSTUM_BOTTOM),

	FRUSTUM_CLIP_MASK = FRUSTUM_CLIP_RIGHT | FRUSTUM_CLIP_LEFT | FRUSTUM_CLIP_TOP | FRUSTUM_CLIP_BOTTOM,

	// This mask is used to reset the clip flags when we first enter an area
	FRUSTUM_CLIP_IN_AREA = 0x80000000,

	// Set the clipmask to this to cause it to clip against all frustum planes
	FRUSTUM_CLIP_ALL = FRUSTUM_CLIP_MASK,

	// Set the clipmask to this to suppress all future clipping
	FRUSTUM_SUPPRESS_CLIPPING = FRUSTUM_CLIP_IN_AREA,
};


bool R_CullNode( Frustum_t *pAreaFrustum, mnode_t *pNode, int &nClipMask );

const Frustum_t* GetAreaFrustum( int area );


// ---------------------------------------------------------------------------- //
// Globals.
// ---------------------------------------------------------------------------- //

extern ConVar r_DrawPortals;

// Used when r_DrawPortals is on. Draws the screen space rects for each portal.
extern CUtlVector<CPortalRect> g_PortalRects;



// ---------------------------------------------------------------------------- //
// Inlines.
// ---------------------------------------------------------------------------- //

inline unsigned char R_IsAreaVisible( int area )
{
	extern unsigned char g_RenderAreaBits[32];
	return g_RenderAreaBits[area>>3] & (1 << (area&7));
}


#endif // R_AREAPORTAL_H