UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
r_array.cpp
Go to the documentation of this file.
1
6
7
/*
8
Copyright(c) 1997-2001 Id Software, Inc.
9
Copyright(c) 2002 The Quakeforge Project.
10
Copyright(c) 2006 Quake2World.
11
12
This program is free software; you can redistribute it and/or
13
modify it under the terms of the GNU General Public License
14
as published by the Free Software Foundation; either version 2
15
of the License, or(at your option) any later version.
16
17
This program is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21
See the GNU General Public License for more details.
22
23
You should have received a copy of the GNU General Public License
24
along with this program; if not, write to the Free Software
25
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
*/
27
28
#include "
r_local.h
"
29
30
#define R_ARRAY_VERTEX 0x1
31
#define R_ARRAY_COLOR 0x2
32
#define R_ARRAY_NORMAL 0x4
33
#define R_ARRAY_TANGENT 0x8
34
#define R_ARRAY_TEX_DIFFUSE 0x10
35
#define R_ARRAY_TEX_LIGHTMAP 0x20
36
#define R_ARRAY_ELEMENT 0x1000
37
38
typedef
struct
r_array_state_s {
39
const
mBspModel_t
*
bspmodel
;
40
int
arrays
;
41
}
r_array_state_t
;
42
43
static
r_array_state_t
r_array_state
;
44
45
52
static
int
R_ArraysMask
(
void
)
53
{
54
int
mask;
55
56
mask =
R_ARRAY_VERTEX
|
R_ARRAY_ELEMENT
;
57
58
if
(
r_state
.color_array_enabled)
59
mask |=
R_ARRAY_COLOR
;
60
61
if
(
r_state
.lighting_enabled) {
62
mask |=
R_ARRAY_NORMAL
;
63
64
if
(
r_bumpmap
->value > 0.0)
65
mask |=
R_ARRAY_TANGENT
;
66
}
67
68
if
(
texunit_diffuse
.enabled)
69
mask |=
R_ARRAY_TEX_DIFFUSE
;
70
71
if
(
texunit_lightmap
.enabled)
72
mask |=
R_ARRAY_TEX_LIGHTMAP
;
73
74
return
mask;
75
}
76
82
static
inline
void
R_SetVertexArrayState
(
const
mBspModel_t
* bsp,
int
mask)
83
{
84
/* vertex array */
85
if
(mask &
R_ARRAY_VERTEX
)
86
R_BindArray
(GL_VERTEX_ARRAY, GL_FLOAT, bsp->
verts
);
87
88
/* normals and tangents for lighting */
89
if
(
r_state
.lighting_enabled) {
90
if
(mask &
R_ARRAY_NORMAL
)
91
R_BindArray
(GL_NORMAL_ARRAY, GL_FLOAT, bsp->
normals
);
92
93
if
(mask &
R_ARRAY_TANGENT
)
94
R_BindArray
(
GL_TANGENT_ARRAY
, GL_FLOAT, bsp->
tangents
);
95
}
96
97
/* diffuse texcoords */
98
if
(
texunit_diffuse
.enabled) {
99
if
(mask &
R_ARRAY_TEX_DIFFUSE
)
100
R_BindArray
(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, bsp->
texcoords
);
101
}
102
103
if
(
texunit_lightmap
.enabled) {
/* lightmap texcoords */
104
if
(mask &
R_ARRAY_TEX_LIGHTMAP
) {
105
R_SelectTexture
(&
texunit_lightmap
);
106
R_BindArray
(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, bsp->
lmtexcoords
);
107
R_SelectTexture
(&
texunit_diffuse
);
108
}
109
}
110
}
111
118
static
inline
void
R_SetVertexBufferState
(
const
mBspModel_t
* bsp,
int
mask)
119
{
120
/* vertex array */
121
if
(mask &
R_ARRAY_VERTEX
)
122
R_BindBuffer
(GL_VERTEX_ARRAY, GL_FLOAT, bsp->
vertex_buffer
);
123
124
/* index array */
125
if
(mask &
R_ARRAY_ELEMENT
)
126
R_BindBuffer
(GL_ELEMENT_ARRAY_BUFFER, 0, bsp->
index_buffer
);
127
/* R_BindBuffer ignores the type parameter for GL_ELEMENT_ARRAY_BUFFER, and GL_INT is not defined in GLES */
128
129
if
(
r_state
.lighting_enabled) {
/* normals and tangents for lighting */
130
if
(mask &
R_ARRAY_NORMAL
)
131
R_BindBuffer
(GL_NORMAL_ARRAY, GL_FLOAT, bsp->
normal_buffer
);
132
133
if
(mask &
R_ARRAY_TANGENT
)
134
R_BindBuffer
(
GL_TANGENT_ARRAY
, GL_FLOAT, bsp->
tangent_buffer
);
135
}
136
137
/* diffuse texcoords */
138
if
(
texunit_diffuse
.enabled) {
139
if
(mask &
R_ARRAY_TEX_DIFFUSE
)
140
R_BindBuffer
(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, bsp->
texcoord_buffer
);
141
}
142
143
/* lightmap texcoords */
144
if
(
texunit_lightmap
.enabled) {
145
if
(mask &
R_ARRAY_TEX_LIGHTMAP
) {
146
R_SelectTexture
(&
texunit_lightmap
);
147
R_BindBuffer
(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, bsp->
lmtexcoord_buffer
);
148
R_SelectTexture
(&
texunit_diffuse
);
149
}
150
}
151
}
152
153
void
R_SetArrayState
(
const
mBspModel_t
* bsp)
154
{
155
int
arrays, mask;
156
157
if
(
r_vertexbuffers
->modified) {
/* force a full re-bind */
158
r_array_state
.bspmodel =
nullptr
;
159
r_array_state
.arrays = 0xFFFF;
160
r_vertexbuffers
->modified =
false
;
161
}
162
163
/* resolve the desired arrays mask */
164
mask = 0xFFFF, arrays =
R_ArraysMask
();
165
166
/* try to save some binds */
167
if
(
r_array_state
.bspmodel == bsp) {
168
const
int
xorR =
r_array_state
.arrays ^ arrays;
169
if
(!xorR)
/* no changes, we're done */
170
return
;
171
172
/* resolve what's left to turn on */
173
mask = arrays & xorR;
174
}
175
176
if
(
r_vertexbuffers
->integer && qglGenBuffers)
/* use vbo */
177
R_SetVertexBufferState
(bsp, mask);
178
else
/* or arrays */
179
R_SetVertexArrayState
(bsp, mask);
180
181
r_array_state
.bspmodel = bsp;
182
r_array_state
.arrays = arrays;
183
}
184
185
void
R_ResetArrayState
(
void
)
186
{
187
r_array_state
.bspmodel =
nullptr
;
188
r_array_state
.arrays = 0;
189
190
/* vbo */
191
R_BindBuffer
(0, 0, 0);
192
if
(qglBindBuffer &&
r_vertexbuffers
->integer)
193
qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
194
195
/* vertex array */
196
R_BindDefaultArray
(GL_VERTEX_ARRAY);
197
198
/* color array */
199
if
(
r_state
.color_array_enabled)
200
R_BindDefaultArray
(GL_COLOR_ARRAY);
201
202
/* normals and tangents */
203
if
(
r_state
.lighting_enabled) {
204
R_BindDefaultArray
(GL_NORMAL_ARRAY);
205
206
R_BindDefaultArray
(
GL_TANGENT_ARRAY
);
207
}
208
209
/* diffuse texcoords */
210
if
(
texunit_diffuse
.enabled)
211
R_BindDefaultArray
(GL_TEXTURE_COORD_ARRAY);
212
213
/* lightmap texcoords */
214
if
(
texunit_lightmap
.enabled) {
215
R_SelectTexture
(&
texunit_lightmap
);
216
R_BindDefaultArray
(GL_TEXTURE_COORD_ARRAY);
217
R_SelectTexture
(&
texunit_diffuse
);
218
}
219
}
R_ArraysMask
static int R_ArraysMask(void)
This function is consulted to determine whether or not array bindings are up to date.
Definition
r_array.cpp:52
R_ARRAY_TEX_DIFFUSE
#define R_ARRAY_TEX_DIFFUSE
Definition
r_array.cpp:34
R_ARRAY_VERTEX
#define R_ARRAY_VERTEX
Definition
r_array.cpp:30
R_ARRAY_ELEMENT
#define R_ARRAY_ELEMENT
Definition
r_array.cpp:36
R_SetArrayState
void R_SetArrayState(const mBspModel_t *bsp)
Definition
r_array.cpp:153
R_SetVertexArrayState
static void R_SetVertexArrayState(const mBspModel_t *bsp, int mask)
Definition
r_array.cpp:82
R_ARRAY_TANGENT
#define R_ARRAY_TANGENT
Definition
r_array.cpp:33
R_ResetArrayState
void R_ResetArrayState(void)
Definition
r_array.cpp:185
r_array_state
static r_array_state_t r_array_state
Definition
r_array.cpp:43
R_SetVertexBufferState
static void R_SetVertexBufferState(const mBspModel_t *bsp, int mask)
Definition
r_array.cpp:118
R_ARRAY_COLOR
#define R_ARRAY_COLOR
Definition
r_array.cpp:31
R_ARRAY_TEX_LIGHTMAP
#define R_ARRAY_TEX_LIGHTMAP
Definition
r_array.cpp:35
R_ARRAY_NORMAL
#define R_ARRAY_NORMAL
Definition
r_array.cpp:32
GL_TANGENT_ARRAY
#define GL_TANGENT_ARRAY
Definition
r_gl.h:76
r_local.h
local graphics definitions
r_bumpmap
cvar_t * r_bumpmap
Definition
r_main.cpp:103
r_vertexbuffers
cvar_t * r_vertexbuffers
Definition
r_main.cpp:94
r_state
rstate_t r_state
Definition
r_main.cpp:48
R_BindBuffer
void R_BindBuffer(GLenum target, GLenum type, GLuint id)
Definition
r_state.cpp:213
R_BindDefaultArray
void R_BindDefaultArray(GLenum target)
Binds the appropriate shared vertex array to the specified target.
Definition
r_state.cpp:182
R_SelectTexture
bool R_SelectTexture(gltexunit_t *texunit)
Returns false if the texunit is not supported.
Definition
r_state.cpp:40
R_BindArray
void R_BindArray(GLenum target, GLenum type, const void *array)
Definition
r_state.cpp:148
texunit_diffuse
#define texunit_diffuse
Definition
r_state.h:68
texunit_lightmap
#define texunit_lightmap
Definition
r_state.h:69
mBspModel_t
brush model
Definition
r_model_brush.h:199
mBspModel_t::tangent_buffer
unsigned int tangent_buffer
Definition
r_model_brush.h:245
mBspModel_t::normal_buffer
unsigned int normal_buffer
Definition
r_model_brush.h:246
mBspModel_t::normals
float * normals
Definition
r_model_brush.h:237
mBspModel_t::index_buffer
unsigned int index_buffer
Definition
r_model_brush.h:247
mBspModel_t::vertex_buffer
unsigned int vertex_buffer
Definition
r_model_brush.h:242
mBspModel_t::texcoord_buffer
unsigned int texcoord_buffer
Definition
r_model_brush.h:243
mBspModel_t::lmtexcoord_buffer
unsigned int lmtexcoord_buffer
Definition
r_model_brush.h:244
mBspModel_t::lmtexcoords
float * lmtexcoords
Definition
r_model_brush.h:235
mBspModel_t::texcoords
float * texcoords
Definition
r_model_brush.h:234
mBspModel_t::tangents
float * tangents
Definition
r_model_brush.h:236
mBspModel_t::verts
float * verts
Definition
r_model_brush.h:233
r_array_state_t
Definition
r_array.cpp:38
r_array_state_t::arrays
int arrays
Definition
r_array.cpp:40
r_array_state_t::bspmodel
const mBspModel_t * bspmodel
Definition
r_array.cpp:39
src
client
renderer
r_array.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0