]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - gl_rmain.c
surfvertex_t is gone, in it's place are non-interleaved arrays, which keeps things...
[xonotic/darkplaces.git] / gl_rmain.c
1 /*
2 Copyright (C) 1996-1997 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 // r_main.c
21
22 #include "quakedef.h"
23
24 // used for dlight push checking and other things
25 int r_framecount;
26
27 mplane_t frustum[4];
28
29 int c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c_bmodels, c_sprites, c_particles, c_dlights;
30
31 // true during envmap command capture
32 qboolean envmap;
33
34 float r_farclip;
35
36 // view origin
37 vec3_t r_origin;
38 vec3_t vpn;
39 vec3_t vright;
40 vec3_t vup;
41
42 //
43 // screen size info
44 //
45 refdef_t r_refdef;
46
47 // 8.8 fraction of base light value
48 unsigned short d_lightstylevalue[256];
49
50 cvar_t r_drawentities = {0, "r_drawentities","1"};
51 cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
52 cvar_t r_speeds = {0, "r_speeds","0"};
53 cvar_t r_fullbright = {0, "r_fullbright","0"};
54 cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
55 cvar_t r_dynamic = {CVAR_SAVE, "r_dynamic","1"};
56 cvar_t r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1"};
57
58 cvar_t gl_fogenable = {0, "gl_fogenable", "0"};
59 cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25"};
60 cvar_t gl_fogred = {0, "gl_fogred","0.3"};
61 cvar_t gl_foggreen = {0, "gl_foggreen","0.3"};
62 cvar_t gl_fogblue = {0, "gl_fogblue","0.3"};
63 cvar_t gl_fogstart = {0, "gl_fogstart", "0"};
64 cvar_t gl_fogend = {0, "gl_fogend","0"};
65
66 cvar_t r_textureunits = {0, "r_textureunits", "32"};
67
68 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
69 {
70         int i;
71         for (i = 0;i < verts;i++)
72         {
73                 out[0] = in[0] * r;
74                 out[1] = in[1] * g;
75                 out[2] = in[2] * b;
76                 out[3] = in[3];
77                 in += 4;
78                 out += 4;
79         }
80 }
81
82 void R_FillColors(float *out, int verts, float r, float g, float b, float a)
83 {
84         int i;
85         for (i = 0;i < verts;i++)
86         {
87                 out[0] = r;
88                 out[1] = g;
89                 out[2] = b;
90                 out[3] = a;
91                 out += 4;
92         }
93 }
94
95 /*
96 ====================
97 R_TimeRefresh_f
98
99 For program optimization
100 ====================
101 */
102 qboolean intimerefresh = 0;
103 static void R_TimeRefresh_f (void)
104 {
105         int i;
106         float start, stop, time;
107
108         intimerefresh = 1;
109         start = Sys_DoubleTime ();
110         for (i = 0;i < 128;i++)
111         {
112                 r_refdef.viewangles[0] = 0;
113                 r_refdef.viewangles[1] = i/128.0*360.0;
114                 r_refdef.viewangles[2] = 0;
115                 CL_UpdateScreen();
116         }
117
118         stop = Sys_DoubleTime ();
119         intimerefresh = 0;
120         time = stop-start;
121         Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
122 }
123
124 vec3_t fogcolor;
125 vec_t fogdensity;
126 float fog_density, fog_red, fog_green, fog_blue;
127 qboolean fogenabled;
128 qboolean oldgl_fogenable;
129 void R_SetupFog(void)
130 {
131         if (gamemode == GAME_NEHAHRA)
132         {
133                 if (gl_fogenable.integer)
134                 {
135                         oldgl_fogenable = true;
136                         fog_density = gl_fogdensity.value;
137                         fog_red = gl_fogred.value;
138                         fog_green = gl_foggreen.value;
139                         fog_blue = gl_fogblue.value;
140                 }
141                 else if (oldgl_fogenable)
142                 {
143                         oldgl_fogenable = false;
144                         fog_density = 0;
145                         fog_red = 0;
146                         fog_green = 0;
147                         fog_blue = 0;
148                 }
149         }
150         if (fog_density)
151         {
152                 fogcolor[0] = fog_red   = bound(0.0f, fog_red  , 1.0f);
153                 fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
154                 fogcolor[2] = fog_blue  = bound(0.0f, fog_blue , 1.0f);
155         }
156         if (fog_density)
157         {
158                 fogenabled = true;
159                 fogdensity = -4000.0f / (fog_density * fog_density);
160                 // fog color was already set
161         }
162         else
163                 fogenabled = false;
164 }
165
166 // FIXME: move this to client?
167 void FOG_clear(void)
168 {
169         if (gamemode == GAME_NEHAHRA)
170         {
171                 Cvar_Set("gl_fogenable", "0");
172                 Cvar_Set("gl_fogdensity", "0.2");
173                 Cvar_Set("gl_fogred", "0.3");
174                 Cvar_Set("gl_foggreen", "0.3");
175                 Cvar_Set("gl_fogblue", "0.3");
176         }
177         fog_density = fog_red = fog_green = fog_blue = 0.0f;
178 }
179
180 // FIXME: move this to client?
181 void FOG_registercvars(void)
182 {
183         if (gamemode == GAME_NEHAHRA)
184         {
185                 Cvar_RegisterVariable (&gl_fogenable);
186                 Cvar_RegisterVariable (&gl_fogdensity);
187                 Cvar_RegisterVariable (&gl_fogred);
188                 Cvar_RegisterVariable (&gl_foggreen);
189                 Cvar_RegisterVariable (&gl_fogblue);
190                 Cvar_RegisterVariable (&gl_fogstart);
191                 Cvar_RegisterVariable (&gl_fogend);
192         }
193 }
194
195 void gl_main_start(void)
196 {
197 }
198
199 void gl_main_shutdown(void)
200 {
201 }
202
203 extern void CL_ParseEntityLump(char *entitystring);
204 void gl_main_newmap(void)
205 {
206         if (cl.worldmodel && cl.worldmodel->entities)
207                 CL_ParseEntityLump(cl.worldmodel->entities);
208         r_framecount = 1;
209 }
210
211 void GL_Main_Init(void)
212 {
213 // FIXME: move this to client?
214         FOG_registercvars();
215         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
216         Cvar_RegisterVariable (&r_drawentities);
217         Cvar_RegisterVariable (&r_drawviewmodel);
218         Cvar_RegisterVariable (&r_speeds);
219         Cvar_RegisterVariable (&r_fullbrights);
220         Cvar_RegisterVariable (&r_wateralpha);
221         Cvar_RegisterVariable (&r_dynamic);
222         Cvar_RegisterVariable (&r_fullbright);
223         Cvar_RegisterVariable (&r_textureunits);
224         if (gamemode == GAME_NEHAHRA)
225                 Cvar_SetValue("r_fullbrights", 0);
226         R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
227 }
228
229 vec3_t r_farclip_origin;
230 vec3_t r_farclip_direction;
231 vec_t r_farclip_directiondist;
232 vec_t r_farclip_meshfarclip;
233 int r_farclip_directionbit0;
234 int r_farclip_directionbit1;
235 int r_farclip_directionbit2;
236
237 // start a farclip measuring session
238 void R_FarClip_Start(vec3_t origin, vec3_t direction, vec_t startfarclip)
239 {
240         VectorCopy(origin, r_farclip_origin);
241         VectorCopy(direction, r_farclip_direction);
242         r_farclip_directiondist = DotProduct(r_farclip_origin, r_farclip_direction);
243         r_farclip_directionbit0 = r_farclip_direction[0] < 0;
244         r_farclip_directionbit1 = r_farclip_direction[1] < 0;
245         r_farclip_directionbit2 = r_farclip_direction[2] < 0;
246         r_farclip_meshfarclip = r_farclip_directiondist + startfarclip;
247 }
248
249 // enlarge farclip to accomodate box
250 void R_FarClip_Box(vec3_t mins, vec3_t maxs)
251 {
252         float d;
253         d = (r_farclip_directionbit0 ? mins[0] : maxs[0]) * r_farclip_direction[0]
254           + (r_farclip_directionbit1 ? mins[1] : maxs[1]) * r_farclip_direction[1]
255           + (r_farclip_directionbit2 ? mins[2] : maxs[2]) * r_farclip_direction[2];
256         if (r_farclip_meshfarclip < d)
257                 r_farclip_meshfarclip = d;
258 }
259
260 // return farclip value
261 float R_FarClip_Finish(void)
262 {
263         return r_farclip_meshfarclip - r_farclip_directiondist;
264 }
265
266 /*
267 ===============
268 R_NewMap
269 ===============
270 */
271 void R_NewMap (void)
272 {
273         R_Modules_NewMap();
274 }
275
276 extern void R_Textures_Init(void);
277 extern void Mod_RenderInit(void);
278 extern void GL_Draw_Init(void);
279 extern void GL_Main_Init(void);
280 extern void GL_Models_Init(void);
281 extern void R_Sky_Init(void);
282 extern void GL_Surf_Init(void);
283 extern void R_Crosshairs_Init(void);
284 extern void R_Light_Init(void);
285 extern void R_Particles_Init(void);
286 extern void R_Explosion_Init(void);
287 extern void ui_init(void);
288 extern void gl_backend_init(void);
289
290 void Render_Init(void)
291 {
292         R_Modules_Shutdown();
293         R_Textures_Init();
294         Mod_RenderInit();
295         gl_backend_init();
296         R_MeshQueue_Init();
297         GL_Draw_Init();
298         GL_Main_Init();
299         GL_Models_Init();
300         R_Sky_Init();
301         GL_Surf_Init();
302         R_Crosshairs_Init();
303         R_Light_Init();
304         R_Particles_Init();
305         R_Explosion_Init();
306         ui_init();
307         R_Modules_Start();
308 }
309
310 /*
311 ===============
312 GL_Init
313 ===============
314 */
315 extern char *ENGINE_EXTENSIONS;
316 void GL_Init (void)
317 {
318         VID_CheckExtensions();
319
320         // LordHavoc: report supported extensions
321         Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
322
323         qglCullFace(GL_FRONT);
324         qglEnable(GL_TEXTURE_2D);
325 }
326
327
328 //==================================================================================
329
330 static void R_MarkEntities (void)
331 {
332         int i;
333         vec3_t v;
334         entity_render_t *ent;
335
336         ent = &cl_entities[0].render;
337         Matrix4x4_CreateIdentity(&ent->matrix);
338         Matrix4x4_CreateIdentity(&ent->inversematrix);
339
340         if (cl.worldmodel)
341                 R_FarClip_Box(cl.worldmodel->normalmins, cl.worldmodel->normalmaxs);
342
343         if (!r_drawentities.integer)
344                 return;
345
346         for (i = 0;i < r_refdef.numentities;i++)
347         {
348                 ent = r_refdef.entities[i];
349                 Mod_CheckLoaded(ent->model);
350
351                 // move view-relative models to where they should be
352                 if (ent->flags & RENDER_VIEWMODEL)
353                 {
354                         // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
355                         ent->flags -= RENDER_VIEWMODEL;
356                         // transform origin
357                         VectorCopy(ent->origin, v);
358                         ent->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
359                         ent->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
360                         ent->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
361                         // adjust angles
362                         VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
363                 }
364
365                 if (R_CullBox(ent->mins, ent->maxs))
366                         continue;
367
368                 ent->visframe = r_framecount;
369                 VectorCopy(ent->angles, v);
370                 if (!ent->model || ent->model->type != mod_brush)
371                         v[0] = -v[0];
372                 Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], v[0], v[1], v[2], ent->scale);
373                 Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
374                 R_LerpAnimation(ent);
375                 R_UpdateEntLights(ent);
376                 R_FarClip_Box(ent->mins, ent->maxs);
377         }
378 }
379
380 // only used if skyrendermasked, and normally returns false
381 int R_DrawBrushModelsSky (void)
382 {
383         int i, sky;
384         entity_render_t *ent;
385
386         if (!r_drawentities.integer)
387                 return false;
388
389         sky = false;
390         for (i = 0;i < r_refdef.numentities;i++)
391         {
392                 ent = r_refdef.entities[i];
393                 if (ent->visframe == r_framecount && ent->model && ent->model->DrawSky)
394                 {
395                         ent->model->DrawSky(ent);
396                         sky = true;
397                 }
398         }
399         return sky;
400 }
401
402 /*
403 =============
404 R_DrawViewModel
405 =============
406 */
407 void R_DrawViewModel (void)
408 {
409         entity_render_t *ent;
410
411         // FIXME: move these checks to client
412         if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
413                 return;
414
415         ent = &cl.viewent.render;
416         Mod_CheckLoaded(ent->model);
417         R_LerpAnimation(ent);
418         Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], -ent->angles[0], ent->angles[1], ent->angles[2], ent->scale);
419         Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
420         R_UpdateEntLights(ent);
421         ent->model->Draw(ent);
422 }
423
424 void R_DrawNoModel(entity_render_t *ent);
425 void R_DrawModels (void)
426 {
427         int i;
428         entity_render_t *ent;
429
430         if (!r_drawentities.integer)
431                 return;
432
433         R_DrawViewModel();
434         for (i = 0;i < r_refdef.numentities;i++)
435         {
436                 ent = r_refdef.entities[i];
437                 if (ent->visframe == r_framecount)
438                 {
439                         if (ent->model)
440                         {
441                                 if (ent->model->Draw)
442                                         ent->model->Draw(ent);
443                         }
444                         else
445                                 R_DrawNoModel(ent);
446                 }
447         }
448 }
449
450 static void R_SetFrustum (void)
451 {
452         int i;
453
454         // LordHavoc: note to all quake engine coders, the special case for 90
455         // degrees assumed a square view (wrong), so I removed it, Quake2 has it
456         // disabled as well.
457         // rotate VPN right by FOV_X/2 degrees
458         RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
459         // rotate VPN left by FOV_X/2 degrees
460         RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
461         // rotate VPN up by FOV_X/2 degrees
462         RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
463         // rotate VPN down by FOV_X/2 degrees
464         RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
465
466         for (i = 0;i < 4;i++)
467         {
468                 frustum[i].type = PLANE_ANYZ;
469                 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
470                 PlaneClassify(&frustum[i]);
471         }
472 }
473
474 /*
475 ===============
476 R_SetupFrame
477 ===============
478 */
479 static void R_SetupFrame (void)
480 {
481 // don't allow cheats in multiplayer
482         if (cl.maxclients > 1)
483         {
484                 if (r_fullbright.integer != 0)
485                         Cvar_Set ("r_fullbright", "0");
486                 if (r_ambient.value != 0)
487                         Cvar_Set ("r_ambient", "0");
488         }
489
490         r_framecount++;
491
492 // build the transformation matrix for the given view angles
493         VectorCopy (r_refdef.vieworg, r_origin);
494
495         AngleVectors (r_refdef.viewangles, vpn, vright, vup);
496
497         R_AnimateLight ();
498 }
499
500
501 static void R_BlendView(void)
502 {
503         rmeshbufferinfo_t m;
504         float r;
505
506         if (r_refdef.viewblend[3] < 0.01f)
507                 return;
508
509         memset(&m, 0, sizeof(m));
510         m.blendfunc1 = GL_SRC_ALPHA;
511         m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
512         m.depthdisable = true; // magic
513         m.numtriangles = 1;
514         m.numverts = 3;
515         Matrix4x4_CreateIdentity(&m.matrix);
516         if (R_Mesh_Draw_GetBuffer(&m, false))
517         {
518                 m.index[0] = 0;
519                 m.index[1] = 1;
520                 m.index[2] = 2;
521                 m.color[0] = m.color[4] = m.color[8] = r_refdef.viewblend[0];
522                 m.color[1] = m.color[5] = m.color[9] = r_refdef.viewblend[1];
523                 m.color[2] = m.color[6] = m.color[10] = r_refdef.viewblend[2];
524                 m.color[3] = m.color[7] = m.color[11] = r_refdef.viewblend[3];
525                 r = 64000;
526                 m.vertex[0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r;
527                 m.vertex[1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r;
528                 m.vertex[2] = r_origin[2] + vpn[2] * 1.5 - vright[2] * r - vup[2] * r;
529                 r *= 3;
530                 m.vertex[4] = m.vertex[0] + vup[0] * r;
531                 m.vertex[5] = m.vertex[1] + vup[1] * r;
532                 m.vertex[6] = m.vertex[2] + vup[2] * r;
533                 m.vertex[8] = m.vertex[0] + vright[0] * r;
534                 m.vertex[9] = m.vertex[1] + vright[1] * r;
535                 m.vertex[10] = m.vertex[2] + vright[2] * r;
536                 R_Mesh_Render();
537         }
538 }
539
540 /*
541 ================
542 R_RenderView
543
544 r_refdef must be set before the first call
545 ================
546 */
547 void R_RenderView (void)
548 {
549         entity_render_t *world;
550         if (!r_refdef.entities/* || !cl.worldmodel*/)
551                 return; //Host_Error ("R_RenderView: NULL worldmodel");
552
553         world = &cl_entities[0].render;
554
555         // FIXME: move to client
556         R_MoveExplosions();
557         R_TimeReport("mexplosion");
558
559         R_Textures_Frame();
560         R_SetupFrame();
561         R_SetFrustum();
562         R_SetupFog();
563         R_SkyStartFrame();
564         R_BuildLightList();
565         R_TimeReport("setup");
566
567         R_FarClip_Start(r_origin, vpn, 768.0f);
568         R_MarkEntities();
569         r_farclip = R_FarClip_Finish() + 256.0f;
570         R_TimeReport("markentity");
571
572         R_Mesh_Start(r_farclip);
573         R_MeshQueue_BeginScene();
574
575         if (R_DrawBrushModelsSky())
576                 R_TimeReport("bmodelsky");
577
578         R_DrawModels();
579         R_TimeReport("models");
580
581         R_DrawParticles();
582         R_TimeReport("particles");
583
584         R_DrawExplosions();
585         R_TimeReport("explosions");
586
587         // don't let sound skip if going slow
588         if (!intimerefresh && !r_speeds.integer)
589                 S_ExtraUpdate ();
590
591         R_DrawWorld(world);
592         R_TimeReport("world");
593
594         R_MeshQueue_RenderTransparent();
595         R_TimeReport("drawtrans");
596
597         R_DrawCoronas();
598         R_TimeReport("coronas");
599
600         R_DrawCrosshair();
601         R_TimeReport("crosshair");
602
603         R_BlendView();
604         R_TimeReport("blendview");
605
606         R_MeshQueue_Render();
607         R_MeshQueue_EndScene();
608         R_Mesh_Finish();
609         R_TimeReport("meshfinish");
610 }
611
612 void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, float ca)
613 {
614         int i;
615         float *v, *c, f1, f2, diff[3];
616         rmeshbufferinfo_t m;
617         m.numtriangles = 12;
618         m.numverts = 8;
619         m.blendfunc1 = GL_SRC_ALPHA;
620         m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
621         Matrix4x4_CreateIdentity(&m.matrix);
622         if (R_Mesh_Draw_GetBuffer(&m, false))
623         {
624                 m.vertex[ 0] = mins[0];m.vertex[ 1] = mins[1];m.vertex[ 2] = mins[2];
625                 m.vertex[ 4] = maxs[0];m.vertex[ 5] = mins[1];m.vertex[ 6] = mins[2];
626                 m.vertex[ 8] = mins[0];m.vertex[ 9] = maxs[1];m.vertex[10] = mins[2];
627                 m.vertex[12] = maxs[0];m.vertex[13] = maxs[1];m.vertex[14] = mins[2];
628                 m.vertex[16] = mins[0];m.vertex[17] = mins[1];m.vertex[18] = maxs[2];
629                 m.vertex[20] = maxs[0];m.vertex[21] = mins[1];m.vertex[22] = maxs[2];
630                 m.vertex[24] = mins[0];m.vertex[25] = maxs[1];m.vertex[26] = maxs[2];
631                 m.vertex[28] = maxs[0];m.vertex[29] = maxs[1];m.vertex[30] = maxs[2];
632                 m.color[ 0] = m.color[ 4] = m.color[ 8] = m.color[12] = m.color[16] = m.color[20] = m.color[24] = m.color[28] = cr * m.colorscale;
633                 m.color[ 1] = m.color[ 5] = m.color[ 9] = m.color[13] = m.color[17] = m.color[21] = m.color[25] = m.color[29] = cg * m.colorscale;
634                 m.color[ 2] = m.color[ 6] = m.color[10] = m.color[14] = m.color[18] = m.color[22] = m.color[26] = m.color[30] = cb * m.colorscale;
635                 m.color[ 3] = m.color[ 7] = m.color[11] = m.color[15] = m.color[19] = m.color[23] = m.color[27] = m.color[31] = ca;
636                 if (fogenabled)
637                 {
638                         for (i = 0, v = m.vertex, c = m.color;i < m.numverts;i++, v += 4, c += 4)
639                         {
640                                 VectorSubtract(v, r_origin, diff);
641                                 f2 = exp(fogdensity/DotProduct(diff, diff));
642                                 f1 = 1 - f2;
643                                 f2 *= m.colorscale;
644                                 c[0] = c[0] * f1 + fogcolor[0] * f2;
645                                 c[1] = c[1] * f1 + fogcolor[1] * f2;
646                                 c[2] = c[2] * f1 + fogcolor[2] * f2;
647                         }
648                 }
649                 R_Mesh_Render();
650         }
651 }
652
653 void R_DrawNoModelCallback(const void *calldata1, int calldata2)
654 {
655         const entity_render_t *ent = calldata1;
656         int i;
657         float f1, f2, *c, diff[3];
658         rmeshbufferinfo_t m;
659         memset(&m, 0, sizeof(m));
660         if (ent->flags & EF_ADDITIVE)
661         {
662                 m.blendfunc1 = GL_SRC_ALPHA;
663                 m.blendfunc2 = GL_ONE;
664         }
665         else if (ent->alpha < 1)
666         {
667                 m.blendfunc1 = GL_SRC_ALPHA;
668                 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
669         }
670         else
671         {
672                 m.blendfunc1 = GL_ONE;
673                 m.blendfunc2 = GL_ZERO;
674         }
675         m.numtriangles = 8;
676         m.numverts = 6;
677         m.matrix = ent->matrix;
678         if (R_Mesh_Draw_GetBuffer(&m, false))
679         {
680                 m.index[ 0] = 5;m.index[ 1] = 2;m.index[ 2] = 0;
681                 m.index[ 3] = 5;m.index[ 4] = 1;m.index[ 5] = 2;
682                 m.index[ 6] = 5;m.index[ 7] = 0;m.index[ 8] = 3;
683                 m.index[ 9] = 5;m.index[10] = 3;m.index[11] = 1;
684                 m.index[12] = 0;m.index[13] = 2;m.index[14] = 4;
685                 m.index[15] = 2;m.index[16] = 1;m.index[17] = 4;
686                 m.index[18] = 3;m.index[19] = 0;m.index[20] = 4;
687                 m.index[21] = 1;m.index[22] = 3;m.index[23] = 4;
688                 m.vertex[ 0] = -16;m.vertex[ 1] =   0;m.vertex[ 2] =   0;
689                 m.vertex[ 4] =  16;m.vertex[ 5] =   0;m.vertex[ 6] =   0;
690                 m.vertex[ 8] =   0;m.vertex[ 9] = -16;m.vertex[10] =   0;
691                 m.vertex[12] =   0;m.vertex[13] =  16;m.vertex[14] =   0;
692                 m.vertex[16] =   0;m.vertex[17] =   0;m.vertex[18] = -16;
693                 m.vertex[20] =   0;m.vertex[21] =   0;m.vertex[22] =  16;
694                 m.color[ 0] = 0.00f;m.color[ 1] = 0.00f;m.color[ 2] = 0.50f;m.color[ 3] = ent->alpha;
695                 m.color[ 4] = 0.00f;m.color[ 5] = 0.00f;m.color[ 6] = 0.50f;m.color[ 7] = ent->alpha;
696                 m.color[ 8] = 0.00f;m.color[ 9] = 0.50f;m.color[10] = 0.00f;m.color[11] = ent->alpha;
697                 m.color[12] = 0.00f;m.color[13] = 0.50f;m.color[14] = 0.00f;m.color[15] = ent->alpha;
698                 m.color[16] = 0.50f;m.color[17] = 0.00f;m.color[18] = 0.00f;m.color[19] = ent->alpha;
699                 m.color[20] = 0.50f;m.color[21] = 0.00f;m.color[22] = 0.00f;m.color[23] = ent->alpha;
700                 if (fogenabled)
701                 {
702                         VectorSubtract(ent->origin, r_origin, diff);
703                         f2 = exp(fogdensity/DotProduct(diff, diff));
704                         f1 = 1 - f2;
705                         for (i = 0, c = m.color;i < m.numverts;i++, c += 4)
706                         {
707                                 c[0] = (c[0] * f1 + fogcolor[0] * f2) * m.colorscale;
708                                 c[1] = (c[1] * f1 + fogcolor[1] * f2) * m.colorscale;
709                                 c[2] = (c[2] * f1 + fogcolor[2] * f2) * m.colorscale;
710                         }
711                 }
712                 else
713                 {
714                         for (i = 0, c = m.color;i < m.numverts;i++, c += 4)
715                         {
716                                 c[0] *= m.colorscale;
717                                 c[1] *= m.colorscale;
718                                 c[2] *= m.colorscale;
719                         }
720                 }
721                 R_Mesh_Render();
722         }
723 }
724
725 void R_DrawNoModel(entity_render_t *ent)
726 {
727         //if ((ent->effects & EF_ADDITIVE) || (ent->alpha < 1))
728                 R_MeshQueue_AddTransparent(ent->origin, R_DrawNoModelCallback, ent, 0);
729         //else
730         //      R_DrawNoModelCallback(ent, 0);
731 }
732