UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
r_surface.cpp
Go to the documentation of this file.
1
5
6
/*
7
Copyright (C) 1997-2001 Id Software, Inc.
8
9
This program is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License
11
as published by the Free Software Foundation; either version 2
12
of the License, or (at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18
See the GNU General Public License for more details.
19
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24
*/
25
26
#include "
r_local.h
"
27
#include "
r_lightmap.h
"
28
#include "
r_light.h
"
29
#include "
r_error.h
"
30
#include "
r_draw.h
"
31
32
void
R_SetSurfaceBumpMappingParameters
(
const
mBspSurface_t
* surf,
const
image_t
* normalMap,
const
image_t
* specularMap)
33
{
34
if
(!
r_state
.lighting_enabled)
35
return
;
36
37
if
(!
r_bumpmap
->value)
38
return
;
39
40
assert(surf);
41
42
if
(normalMap && (surf->
flags
&
MSURF_LIGHTMAP
)) {
43
const
image_t
* image = surf->
texinfo
->
image
;
44
R_BindDeluxemapTexture
(surf->
deluxemap_texnum
);
45
R_EnableBumpmap
(normalMap);
46
R_EnableSpecularMap
(specularMap,
true
);
47
R_UseMaterial
(&image->
material
);
48
}
else
{
49
R_EnableBumpmap
(
nullptr
);
50
R_EnableSpecularMap
(
nullptr
,
false
);
51
R_UseMaterial
(
nullptr
);
52
}
53
}
54
59
static
void
R_SetSurfaceState
(
const
mBspSurface_t
* surf)
60
{
61
image_t
* image;
62
63
if
(
r_state
.blend_enabled) {
/* alpha blend */
64
vec4_t
color = {1.0, 1.0, 1.0, 1.0};
65
switch
(surf->
texinfo
->
flags
& (
SURF_BLEND33
|
SURF_BLEND66
)) {
66
case
SURF_BLEND33
:
67
color[3] = 0.33;
68
break
;
69
case
SURF_BLEND66
:
70
color[3] = 0.66;
71
break
;
72
}
73
74
R_Color
(color);
75
}
76
77
image = surf->
texinfo
->
image
;
78
R_BindTexture
(image->
texnum
);
/* texture */
79
80
if
(
texunit_lightmap
.enabled) {
/* lightmap */
81
if
(surf->
flags
&
MSURF_LIGHTMAP
)
82
R_BindLightmapTexture
(surf->
lightmap_texnum
);
83
}
84
85
R_SetSurfaceBumpMappingParameters
(surf, image->
normalmap
, image->
specularmap
);
86
87
R_EnableGlowMap
(image->
glowmap
);
88
89
R_CheckError
();
90
}
91
98
void
R_DrawSurfaces
(
const
mBspSurfaces_t
* surfs,
glElementIndex_t
* indexPtr)
99
{
100
int
numSurfaces = surfs->
count
;
101
mBspSurface_t
** surfPtrList = surfs->
surfaces
;
102
const
int
frame =
r_locals
.frame;
103
104
int
lastLightMap = 0, lastDeluxeMap = 0;
105
image_t
* lastTexture =
nullptr
;
106
uint32_t lastFlags = ~0;
107
108
int
batchStart = 0, batchSize = 0;
/* in triangles */
109
110
while
(numSurfaces--) {
111
const
mBspSurface_t
* surf = *surfPtrList++;
112
const
int
numTriangles = surf->
numTriangles
;
113
mBspTexInfo_t
* texInfo;
114
int
texFlags;
115
bool
newBatch =
false
;
116
117
if
(surf->
frame
!= frame)
118
continue
;
119
if
(numTriangles <= 0)
120
continue
;
121
122
refdef
.brushCount += numTriangles;
123
124
if
(batchStart + batchSize != surf->
firstTriangle
) {
125
/* Cannot continue assembling the batch, draw it and start a new one*/
126
if
(batchSize > 0) {
127
glDrawElements(GL_TRIANGLES, batchSize * 3,
GL_ELEMENT_INDEX_TYPE
, indexPtr + batchStart * 3);
128
refdef
.batchCount++;
129
}
130
batchStart = surf->
firstTriangle
;
131
batchSize = 0;
132
newBatch =
true
;
133
}
134
136
texInfo = surf->
texinfo
;
137
texFlags = texInfo->
flags
& (
SURF_BLEND33
|
SURF_BLEND66
);
/* should match flags that affect R_SetSurfaceState behavior */
138
if
(texInfo->
image
!= lastTexture || surf->
lightmap_texnum
!= lastLightMap || surf->
deluxemap_texnum
!= lastDeluxeMap || texFlags != lastFlags) {
139
if
(!newBatch) {
140
/* changes in texturing require new batch */
141
glDrawElements(GL_TRIANGLES, batchSize * 3,
GL_ELEMENT_INDEX_TYPE
, indexPtr + batchStart * 3);
142
refdef
.batchCount++;
143
batchStart = surf->
firstTriangle
;
144
batchSize = 0;
145
}
146
lastTexture = texInfo->
image
;
147
lastLightMap = surf->
lightmap_texnum
;
148
lastDeluxeMap = surf->
deluxemap_texnum
;
149
lastFlags = texFlags;
150
R_SetSurfaceState
(surf);
151
}
152
153
batchSize += numTriangles;
154
}
155
156
/* finish uncomplete batch, if any */
157
if
(batchSize > 0) {
158
glDrawElements(GL_TRIANGLES, batchSize * 3,
GL_ELEMENT_INDEX_TYPE
, indexPtr + batchStart * 3);
159
refdef
.batchCount++;
160
}
161
162
/* reset state */
163
if
(
r_state
.active_normalmap)
164
R_EnableBumpmap
(
nullptr
);
165
166
R_EnableGlowMap
(
nullptr
);
167
168
R_Color
(
nullptr
);
169
}
refdef
rendererData_t refdef
Definition
r_main.cpp:45
R_Color
void R_Color(const vec4_t rgba)
Change the color to given value.
Definition
r_state.cpp:1011
SURF_BLEND66
#define SURF_BLEND66
Definition
defines.h:258
SURF_BLEND33
#define SURF_BLEND33
Definition
defines.h:257
r_draw.h
r_error.h
Error checking function.
R_CheckError
#define R_CheckError()
Definition
r_error.h:30
GL_ELEMENT_INDEX_TYPE
#define GL_ELEMENT_INDEX_TYPE
Definition
r_gl.h:58
glElementIndex_t
GLuint glElementIndex_t
Definition
r_gl.h:57
r_light.h
r_lightmap.h
lightmap definitions
r_local.h
local graphics definitions
r_bumpmap
cvar_t * r_bumpmap
Definition
r_main.cpp:103
r_locals
rlocals_t r_locals
Definition
r_main.cpp:49
r_state
rstate_t r_state
Definition
r_main.cpp:48
MSURF_LIGHTMAP
#define MSURF_LIGHTMAP
Definition
r_model_brush.h:51
R_EnableGlowMap
void R_EnableGlowMap(const image_t *image)
Definition
r_state.cpp:664
R_BindLightmapTexture
void R_BindLightmapTexture(GLuint texnum)
Definition
r_state.cpp:90
R_BindDeluxemapTexture
void R_BindDeluxemapTexture(GLuint texnum)
Definition
r_state.cpp:95
R_UseMaterial
void R_UseMaterial(const material_t *material)
Definition
r_state.cpp:105
R_EnableBumpmap
void R_EnableBumpmap(const image_t *normalmap)
Enables bumpmapping and binds the given normalmap.
Definition
r_state.cpp:465
R_EnableSpecularMap
void R_EnableSpecularMap(const image_t *image, bool enable)
Definition
r_state.cpp:707
texunit_lightmap
#define texunit_lightmap
Definition
r_state.h:69
R_BindTexture
#define R_BindTexture(tn)
Definition
r_state.h:184
R_DrawSurfaces
void R_DrawSurfaces(const mBspSurfaces_t *surfs, glElementIndex_t *indexPtr)
General surface drawing function, that draw the surface chains.
Definition
r_surface.cpp:98
R_SetSurfaceBumpMappingParameters
void R_SetSurfaceBumpMappingParameters(const mBspSurface_t *surf, const image_t *normalMap, const image_t *specularMap)
Definition
r_surface.cpp:32
R_SetSurfaceState
static void R_SetSurfaceState(const mBspSurface_t *surf)
Set the surface state according to surface flags and bind the texture.
Definition
r_surface.cpp:59
image_t
Definition
r_image.h:61
image_t::specularmap
struct image_s * specularmap
Definition
r_image.h:71
image_t::texnum
GLuint texnum
Definition
r_image.h:66
image_t::normalmap
struct image_s * normalmap
Definition
r_image.h:69
image_t::glowmap
struct image_s * glowmap
Definition
r_image.h:70
image_t::material
material_t material
Definition
r_image.h:68
mBspSurface_t
Definition
r_model_brush.h:83
mBspSurface_t::frame
int frame
Definition
r_model_brush.h:88
mBspSurface_t::deluxemap_texnum
int deluxemap_texnum
Definition
r_model_brush.h:120
mBspSurface_t::texinfo
mBspTexInfo_t * texinfo
Definition
r_model_brush.h:115
mBspSurface_t::flags
int flags
Definition
r_model_brush.h:85
mBspSurface_t::numTriangles
unsigned int numTriangles
Definition
r_model_brush.h:111
mBspSurface_t::lightmap_texnum
int lightmap_texnum
Definition
r_model_brush.h:119
mBspSurface_t::firstTriangle
int firstTriangle
Definition
r_model_brush.h:110
mBspSurfaces_t
surfaces are assigned to arrays based on their primary rendering type and then sorted by world textur...
Definition
r_model_brush.h:138
mBspSurfaces_t::count
int count
Definition
r_model_brush.h:140
mBspSurfaces_t::surfaces
mBspSurface_t ** surfaces
Definition
r_model_brush.h:139
mBspTexInfo_t
Definition
r_model_brush.h:65
mBspTexInfo_t::image
image_t * image
Definition
r_model_brush.h:71
mBspTexInfo_t::flags
uint32_t flags
Definition
r_model_brush.h:70
vec4_t
vec_t vec4_t[4]
Definition
ufotypes.h:40
src
client
renderer
r_surface.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0