1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 
20 //
21 // rb_public.h
22 // Refresh backend header
23 //
24 
25 /*
26 =============================================================================
27 
28 	BACKEND
29 
30 =============================================================================
31 */
32 
33 #define RB_MAX_VERTS			4096
34 #define RB_MAX_INDEXES			RB_MAX_VERTS*6
35 #define RB_MAX_TRIANGLES		RB_MAX_INDEXES/3
36 #define RB_MAX_NEIGHBORS		RB_MAX_TRIANGLES*3
37 
38 // FIXME: this could be made local to the backend
39 typedef struct rbData_batch_s {
40 	bvec4_t					colors[RB_MAX_VERTS];
41 	vec2_t					coords[RB_MAX_VERTS];
42 	index_t					indices[RB_MAX_INDEXES];
43 	vec2_t					lmCoords[RB_MAX_VERTS];
44 	vec3_t					normals[RB_MAX_VERTS];
45 	vec3_t					sVectors[RB_MAX_VERTS];
46 	vec3_t					tVectors[RB_MAX_VERTS];
47 	vec3_t					vertices[RB_MAX_VERTS];
48 
49 #ifdef SHADOW_VOLUMES
50 	int						neighbors[RB_MAX_NEIGHBORS];
51 	vec3_t					trNormals[RB_MAX_TRIANGLES];
52 #endif
53 } rbData_batch_t;
54 
55 typedef struct rbData_s {
56 	// Batch buffers are used for SHADER_ENTITY_MERGABLE shaders and for
57 	// storage to pass to the backend on non-SHADER_ENTITY_MERGABLE shaders.
58 	rbData_batch_t			batch;
59 
60 	// Input data pointers for rendering a mesh buffer
61 	bvec4_t					*inColors;
62 	vec2_t					*inCoords;
63 	index_t					*inIndices;
64 	vec2_t					*inLMCoords;
65 	vec3_t					*inNormals;
66 	vec3_t					*inSVectors;
67 	vec3_t					*inTVectors;
68 	vec3_t					*inVertices;
69 
70 #ifdef SHADOW_VOLUMES
71 	int						*inNeighbors;
72 	vec3_t					*inTrNormals;
73 	int						*curTrNeighbor;
74 	float					*curTrNormal;
75 #endif
76 
77 	refEntity_t				*curEntity;
78 	uint32					curDLightBits;
79 	int						curLMTexNum;
80 	meshFeatures_t			curMeshFeatures;
81 	meshType_t				curMeshType;
82 	struct refModel_s		*curModel;
83 	uint32					curPatchWidth;
84 	uint32					curPatchHeight;
85 	shader_t				*curShader;
86 
87 	struct mQ3BspFog_s		*curColorFog;
88 	struct mQ3BspFog_s		*curTexFog;
89 
90 	int						numIndexes;
91 	int						numVerts;
92 } rbData_t;
93 
94 extern rbData_t	rb;
95 
96 /*
97 =============================================================================
98 
99 	STATE COMPRESSION
100 
101 =============================================================================
102 */
103 
104 enum {
105 	SB1_BLENDSRC_ZERO					= 0x1,
106 	SB1_BLENDSRC_ONE					= 0x2,
107 	SB1_BLENDSRC_DST_COLOR				= 0x3,
108 	SB1_BLENDSRC_ONE_MINUS_DST_COLOR	= 0x4,
109 	SB1_BLENDSRC_SRC_ALPHA				= 0x5,
110 	SB1_BLENDSRC_ONE_MINUS_SRC_ALPHA	= 0x6,
111 	SB1_BLENDSRC_DST_ALPHA				= 0x7,
112 	SB1_BLENDSRC_ONE_MINUS_DST_ALPHA	= 0x8,
113 	SB1_BLENDSRC_SRC_ALPHA_SATURATE		= 0x9,
114 	SB1_BLENDSRC_BITS					= 0xf,
115 
116 	SB1_BLENDDST_ZERO					= 0x10,
117 	SB1_BLENDDST_ONE					= 0x20,
118 	SB1_BLENDDST_SRC_COLOR				= 0x30,
119 	SB1_BLENDDST_ONE_MINUS_SRC_COLOR	= 0x40,
120 	SB1_BLENDDST_SRC_ALPHA				= 0x50,
121 	SB1_BLENDDST_ONE_MINUS_SRC_ALPHA	= 0x60,
122 	SB1_BLENDDST_DST_ALPHA				= 0x70,
123 	SB1_BLENDDST_ONE_MINUS_DST_ALPHA	= 0x80,
124 	SB1_BLENDDST_BITS					= 0xf0,
125 
126 	SB1_BLEND_ON						= 0x100,
127 	SB1_DEPTHMASK_ON					= 0x1000,
128 	SB1_DEPTHTEST_ON					= 0x10000,
129 	SB1_POLYOFFSET_ON					= 0x100000,
130 
131 	SB1_CULL_FRONT						= 0x1000000,
132 	SB1_CULL_BACK						= 0x2000000,
133 	SB1_CULL_BITS						= 0xf000000,
134 
135 	SB1_ATEST_GT0						= 0x10000000,
136 	SB1_ATEST_LT128						= 0x20000000,
137 	SB1_ATEST_GE128						= 0x40000000,
138 	SB1_ATEST_BITS						= 0xf0000000,
139 };
140 
141 #define SB1_DEFAULT		(SB1_BLENDSRC_SRC_ALPHA|SB1_BLENDDST_ONE_MINUS_SRC_ALPHA|SB1_DEPTHTEST_ON)
142 
143 /*
144 =============================================================================
145 
146 	ENTITY HANDLING
147 
148 =============================================================================
149 */
150 
151 void		RB_LoadModelIdentity (void);
152 void		RB_RotateForEntity (refEntity_t *ent);
153 void		RB_RotateForAliasShadow (refEntity_t *ent);
154 void		RB_TranslateForEntity (refEntity_t *ent);
155 
156 void		RB_AddNullModelToList (refEntity_t *ent);
157 void		RB_DrawNullModelList (void);
158