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 | #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)(__builtin_expect(!(surf), 0) ? __assert_rtn(__func__, "src/client/renderer/r_surface.cpp" , 40, "surf") : (void)0); |
41 | |
42 | if (normalMap && (surf->flags & MSURF_LIGHTMAP2)) { |
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(NULL__null); |
50 | R_EnableSpecularMap(NULL__null, false); |
51 | R_UseMaterial(NULL__null); |
52 | } |
53 | } |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | static void R_SetSurfaceState (const mBspSurface_t *surf) |
60 | { |
61 | image_t *image; |
62 | |
63 | if (r_state.blend_enabled) { |
| |
64 | vec4_t color = {1.0, 1.0, 1.0, 1.0}; |
65 | switch (surf->texinfo->flags & (SURF_BLEND330x00000010 | SURF_BLEND660x00000020)) { |
66 | case SURF_BLEND330x00000010: |
67 | color[3] = 0.33; |
68 | break; |
69 | case SURF_BLEND660x00000020: |
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)R_BindTextureDebug(image->texnum, "src/client/renderer/r_surface.cpp" , 78, __PRETTY_FUNCTION__); |
| 15 | Within the expansion of the macro 'R_BindTexture':
|
a | Access to field 'texnum' results in a dereference of a null pointer (loaded from variable 'image') |
|
79 | |
80 | if (texunit_lightmapr_state.texunits[1].enabled) { |
81 | if (surf->flags & MSURF_LIGHTMAP2) |
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()R_CheckErrorDebug("src/client/renderer/r_surface.cpp", 89, __PRETTY_FUNCTION__ ); |
90 | } |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | static inline void R_DrawSurface (const mBspSurface_t *surf) |
97 | { |
98 | glDrawArrays(GL_TRIANGLE_FAN0x0006, surf->index, surf->numedges); |
99 | |
100 | refdef.batchCount++; |
101 | |
102 | if (r_showbox->integer == 2) |
103 | R_DrawBoundingBox(surf->mins, surf->maxs); |
104 | |
105 | refdef.brushCount++; |
106 | } |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | void R_DrawSurfaces (const mBspSurfaces_t *surfs) |
115 | { |
116 | int numSurfaces = surfs->count; |
117 | mBspSurface_t **surfPtrList = surfs->surfaces; |
118 | const int frame = r_locals.frame; |
119 | |
120 | int lastLightMap = 0, lastDeluxeMap = 0; |
121 | image_t *lastTexture = NULL__null; |
122 | uint32_t lastFlags = ~0; |
123 | |
124 | while (numSurfaces--) { |
| 1 | Loop condition is true. Entering loop body |
|
| 4 | Loop condition is true. Entering loop body |
|
| 7 | Loop condition is true. Entering loop body |
|
| 10 | Loop condition is true. Entering loop body |
|
125 | const mBspSurface_t *surf = *surfPtrList++; |
126 | mBspTexInfo_t *texInfo; |
127 | int texFlags; |
128 | if (surf->frame != frame) |
| |
| |
| |
| |
129 | continue; |
130 | |
131 | |
132 | texInfo = surf->texinfo; |
133 | texFlags = texInfo->flags & (SURF_BLEND330x00000010 | SURF_BLEND660x00000020 | MSURF_LIGHTMAP2); |
134 | if (texInfo->image != lastTexture || surf->lightmap_texnum != lastLightMap || surf->deluxemap_texnum != lastDeluxeMap || texFlags != lastFlags) { |
| |
| |
| |
| |
135 | lastTexture = texInfo->image; |
136 | lastLightMap = surf->lightmap_texnum; |
137 | lastDeluxeMap = surf->deluxemap_texnum; |
138 | lastFlags = texFlags; |
139 | R_SetSurfaceState(surf); |
| 13 | Calling 'R_SetSurfaceState' |
|
140 | } |
141 | |
142 | R_DrawSurface(surf); |
143 | } |
144 | |
145 | |
146 | if (r_state.active_normalmap) |
147 | R_EnableBumpmap(NULL__null); |
148 | |
149 | R_EnableGlowMap(NULL__null); |
150 | |
151 | R_Color(NULL__null); |
152 | } |