6 #include "cl_collision.h"
10 // we have to include snd_main.h here only to get access to snd_renderbuffer->format.speed when writing the AVI headers
13 cvar_t scr_viewsize = {CVAR_SAVE, "viewsize","100", "how large the view should be, 110 disables inventory bar, 120 disables status bar"};
14 cvar_t scr_fov = {CVAR_SAVE, "fov","90", "field of vision, 1-170 degrees, default 90, some players use 110-130"};
15 cvar_t scr_conalpha = {CVAR_SAVE, "scr_conalpha", "1", "opacity of console background"};
16 cvar_t scr_conbrightness = {CVAR_SAVE, "scr_conbrightness", "1", "brightness of console background (0 = black, 1 = image)"};
17 cvar_t scr_conforcewhiledisconnected = {0, "scr_conforcewhiledisconnected", "1", "forces fullscreen console while disconnected"};
18 cvar_t scr_menuforcewhiledisconnected = {0, "scr_menuforcewhiledisconnected", "0", "forces menu while disconnected"};
19 cvar_t scr_centertime = {0, "scr_centertime","2", "how long centerprint messages show"};
20 cvar_t scr_showram = {CVAR_SAVE, "showram","1", "show ram icon if low on surface cache memory (not used)"};
21 cvar_t scr_showturtle = {CVAR_SAVE, "showturtle","0", "show turtle icon when framerate is too low"};
22 cvar_t scr_showpause = {CVAR_SAVE, "showpause","1", "show pause icon when game is paused"};
23 cvar_t scr_showbrand = {0, "showbrand","0", "shows gfx/brand.tga in a corner of the screen (different values select different positions, including centered)"};
24 cvar_t scr_printspeed = {0, "scr_printspeed","0", "speed of intermission printing (episode end texts), a value of 0 disables the slow printing"};
25 cvar_t vid_conwidth = {CVAR_SAVE, "vid_conwidth", "640", "virtual width of 2D graphics system"};
26 cvar_t vid_conheight = {CVAR_SAVE, "vid_conheight", "480", "virtual height of 2D graphics system"};
27 cvar_t vid_pixelheight = {CVAR_SAVE, "vid_pixelheight", "1", "adjusts vertical field of vision to account for non-square pixels (1280x1024 on a CRT monitor for example)"};
28 cvar_t scr_screenshot_jpeg = {CVAR_SAVE, "scr_screenshot_jpeg","1", "save jpeg instead of targa"};
29 cvar_t scr_screenshot_jpeg_quality = {CVAR_SAVE, "scr_screenshot_jpeg_quality","0.9", "image quality of saved jpeg"};
30 cvar_t scr_screenshot_gammaboost = {CVAR_SAVE, "scr_screenshot_gammaboost","1", "gamma correction on saved screenshots and videos, 1.0 saves unmodified images"};
31 // scr_screenshot_name is defined in fs.c
32 cvar_t cl_capturevideo = {0, "cl_capturevideo", "0", "enables saving of video to a .avi file using uncompressed I420 colorspace and PCM audio, note that scr_screenshot_gammaboost affects the brightness of the output)"};
33 cvar_t cl_capturevideo_width = {0, "cl_capturevideo_width", "0", "scales all frames to this resolution before saving the video"};
34 cvar_t cl_capturevideo_height = {0, "cl_capturevideo_height", "0", "scales all frames to this resolution before saving the video"};
35 cvar_t cl_capturevideo_realtime = {0, "cl_capturevideo_realtime", "0", "causes video saving to operate in realtime (mostly useful while playing, not while capturing demos), this can produce a much lower quality video due to poor sound/video sync and will abort saving if your machine stalls for over a minute"};
36 cvar_t cl_capturevideo_fps = {0, "cl_capturevideo_fps", "30", "how many frames per second to save (29.97 for NTSC, 30 for typical PC video, 15 can be useful)"};
37 cvar_t cl_capturevideo_number = {CVAR_SAVE, "cl_capturevideo_number", "1", "number to append to video filename, incremented each time a capture begins"};
38 cvar_t r_letterbox = {0, "r_letterbox", "0", "reduces vertical height of view to simulate a letterboxed movie effect (can be used by mods for cutscenes)"};
39 cvar_t r_stereo_separation = {0, "r_stereo_separation", "4", "separation distance of eyes in the world (negative values are only useful for cross-eyed viewing)"};
40 cvar_t r_stereo_sidebyside = {0, "r_stereo_sidebyside", "0", "side by side views for those who can't afford glasses but can afford eye strain (note: use a negative r_stereo_separation if you want cross-eyed viewing)"};
41 cvar_t r_stereo_redblue = {0, "r_stereo_redblue", "0", "red/blue anaglyph stereo glasses (note: most of these glasses are actually red/cyan, try that one too)"};
42 cvar_t r_stereo_redcyan = {0, "r_stereo_redcyan", "0", "red/cyan anaglyph stereo glasses, the kind given away at drive-in movies like Creature From The Black Lagoon In 3D"};
43 cvar_t r_stereo_redgreen = {0, "r_stereo_redgreen", "0", "red/green anaglyph stereo glasses (for those who don't mind yellow)"};
44 cvar_t r_stereo_angle = {0, "r_stereo_angle", "0", "separation angle of eyes (makes the views look different directions, as an example, 90 gives a 90 degree separation where the views are 45 degrees left and 45 degrees right)"};
45 cvar_t scr_zoomwindow = {CVAR_SAVE, "scr_zoomwindow", "0", "displays a zoomed in overlay window"};
46 cvar_t scr_zoomwindow_viewsizex = {CVAR_SAVE, "scr_zoomwindow_viewsizex", "20", "horizontal viewsize of zoom window"};
47 cvar_t scr_zoomwindow_viewsizey = {CVAR_SAVE, "scr_zoomwindow_viewsizey", "20", "vertical viewsize of zoom window"};
48 cvar_t scr_zoomwindow_fov = {CVAR_SAVE, "scr_zoomwindow_fov", "20", "fov of zoom window"};
49 cvar_t scr_stipple = {0, "scr_stipple", "0", "interlacing-like stippling of the display"};
50 cvar_t scr_refresh = {0, "scr_refresh", "1", "allows you to completely shut off rendering for benchmarking purposes"};
51 cvar_t shownetgraph = {CVAR_SAVE, "shownetgraph", "0", "shows a graph of packet sizes and other information, 0 = off, 1 = show client netgraph, 2 = show client and server netgraphs (when hosting a server)"};
52 cvar_t cl_demo_mousegrab = {0, "cl_demo_mousegrab", "0", "Allows reading the mouse input while playing demos. Useful for camera mods developed in csqc. (0: never, 1: always)"};
54 #define AVI_MASTER_INDEX_SIZE 640 // GB ought to be enough for anyone
56 int jpeg_supported = false;
58 qboolean scr_initialized; // ready to draw
60 float scr_con_current;
61 int scr_con_margin_bottom;
63 extern int con_vislines;
65 static void SCR_ScreenShot_f (void);
66 static void R_Envmap_f (void);
69 void R_ClearScreen(qboolean fogcolor);
72 ===============================================================================
76 ===============================================================================
79 char scr_centerstring[MAX_INPUTLINE];
80 float scr_centertime_start; // for slow victory printing
81 float scr_centertime_off;
85 char scr_infobarstring[MAX_INPUTLINE];
86 float scr_infobartime_off;
92 Called for important messages that should stay in the center of the screen
96 void SCR_CenterPrint(const char *str)
98 strlcpy (scr_centerstring, str, sizeof (scr_centerstring));
99 scr_centertime_off = scr_centertime.value;
100 scr_centertime_start = cl.time;
102 // count the number of lines for centering
103 scr_center_lines = 1;
113 void SCR_DrawCenterString (void)
120 if(cl.intermission == 2) // in finale,
121 if(sb_showscores) // make TAB hide the finale message (sb_showscores overrides finale in sbar.c)
124 if(scr_centertime.value <= 0 && !cl.intermission)
127 // the finale prints the characters one at a time, except if printspeed is an absurdly high value
128 if (cl.intermission && scr_printspeed.value > 0 && scr_printspeed.value < 1000000)
129 remaining = (int)(scr_printspeed.value * (cl.time - scr_centertime_start));
133 scr_erase_center = 0;
134 start = scr_centerstring;
139 if (scr_center_lines <= 4)
140 y = (int)(vid_conheight.integer*0.35);
147 // scan the number of characters on the line, not counting color codes
148 char *newline = strchr(start, '\n');
149 int l = newline ? (newline - start) : (int)strlen(start);
150 float width = DrawQ_TextWidth_Font(start, l, false, FONT_CENTERPRINT) * 8;
152 x = (int) (vid_conwidth.integer - width)/2;
157 DrawQ_String_Font(x, y, start, l, 8, 8, 1, 1, 1, 1, 0, &color, false, FONT_CENTERPRINT);
166 start = newline + 1; // skip the \n
170 void SCR_CheckDrawCenterString (void)
172 if (scr_center_lines > scr_erase_lines)
173 scr_erase_lines = scr_center_lines;
175 if (cl.time > cl.oldtime)
176 scr_centertime_off -= cl.time - cl.oldtime;
178 // don't draw if this is a normal stats-screen intermission,
179 // only if it is not an intermission, or a finale intermission
180 if (cl.intermission == 1)
182 if (scr_centertime_off <= 0 && !cl.intermission)
184 if (key_dest != key_game)
187 SCR_DrawCenterString ();
190 void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *label, float textsize, int packetcounter, int numparameters, const int **parameters, const float parametercolors[][4])
192 int j, k, x, y, index, offset, height;
193 // draw the bar graph itself
194 // advance the packet counter because it is the latest packet column being
195 // built up and should come last
196 packetcounter = (packetcounter + 1) % NETGRAPH_PACKETS;
197 for (j = 0;j < NETGRAPH_PACKETS;j++)
199 x = graphx + j * barwidth;
200 y = graphy + barheight;
201 index = (packetcounter + j) % NETGRAPH_PACKETS;
202 if (parameters[0][index] == NETGRAPH_LOSTPACKET)
203 DrawQ_Fill(x, y - barheight, barwidth, barheight, 1, 0, 0, 1, 0);
204 else if (parameters[0][index] == NETGRAPH_CHOKEDPACKET)
205 DrawQ_Fill(x, y - min(2, barheight), barwidth, min(2, barheight), 1, 1, 0, 1, 0);
209 for (k = 0;k < numparameters;k++)
211 height = (parameters[k][index] + bardivide - 1) / bardivide;
212 height = min(height, barheight - offset);
215 DrawQ_Fill(x, y - offset, barwidth, height, parametercolors[k][0], parametercolors[k][1], parametercolors[k][2], parametercolors[k][3], 0);
221 const float netgraphcolors[3][4] =
228 void SCR_DrawNetGraph_DrawConnection_Client (netconn_t *conn, int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *labelincoming, int separator, const char *labeloutgoing, float textsize)
231 const int *parameters[3];
233 DrawQ_Fill(graphx , graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
234 DrawQ_Fill(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
235 // draw the bar graphs
237 parameters[0] = conn->incoming_unreliablesize;
238 parameters[1] = conn->incoming_reliablesize;
239 parameters[2] = conn->incoming_acksize;
240 SCR_DrawNetGraph_DrawGraph(graphx, graphy, barwidth, barheight, bardivide, labelincoming, textsize, conn->incoming_packetcounter, numparameters, parameters, netgraphcolors);
241 parameters[0] = conn->outgoing_unreliablesize;
242 parameters[1] = conn->outgoing_reliablesize;
243 parameters[2] = conn->outgoing_acksize;
244 SCR_DrawNetGraph_DrawGraph(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth, barheight, bardivide, labeloutgoing, textsize, conn->outgoing_packetcounter, numparameters, parameters, netgraphcolors);
246 DrawQ_String(graphx , graphy + barheight, labelincoming, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
247 DrawQ_String(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy + barheight, labeloutgoing, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
250 void SCR_DrawNetGraph_DrawConnection_Server (netconn_t *conn, int graphx, int graphy, int barwidth, int barheight, int bardivide, const char *labeloutgoing, int separator, const char *labelincoming, float textsize)
253 const int *parameters[3];
255 DrawQ_Fill(graphx , graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
256 DrawQ_Fill(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth * NETGRAPH_PACKETS, barheight + textsize, 0, 0, 0, 0.5, 0);
257 // draw the bar graphs
259 parameters[0] = conn->outgoing_unreliablesize;
260 parameters[1] = conn->outgoing_reliablesize;
261 parameters[2] = conn->outgoing_acksize;
262 SCR_DrawNetGraph_DrawGraph(graphx , graphy, barwidth, barheight, bardivide, labeloutgoing, textsize, conn->outgoing_packetcounter, numparameters, parameters, netgraphcolors);
263 parameters[0] = conn->incoming_unreliablesize;
264 parameters[1] = conn->incoming_reliablesize;
265 parameters[2] = conn->incoming_acksize;
266 SCR_DrawNetGraph_DrawGraph(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy, barwidth, barheight, bardivide, labelincoming, textsize, conn->incoming_packetcounter, numparameters, parameters, netgraphcolors);
268 DrawQ_String(graphx , graphy + barheight, labeloutgoing, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
269 DrawQ_String(graphx + barwidth * NETGRAPH_PACKETS + separator, graphy + barheight, labelincoming, 0, textsize, textsize, 1, 1, 1, 1, 0, NULL, false);
277 void SCR_DrawNetGraph (void)
279 int i, separator1, separator2, barwidth, barheight, bardivide, netgraph_x, netgraph_y, textsize, index, netgraphsperrow;
281 if (cls.state != ca_connected)
285 if (!shownetgraph.integer)
295 netgraphsperrow = (vid_conwidth.integer + separator2) / (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
296 netgraphsperrow = max(netgraphsperrow, 1);
299 netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
300 netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
301 SCR_DrawNetGraph_DrawConnection_Client(cls.netcon, netgraph_x, netgraph_y, barwidth, barheight, bardivide, "incoming", separator1, "outgoing", textsize);
304 if (sv.active && shownetgraph.integer >= 2)
306 for (i = 0;i < svs.maxclients;i++)
308 if (!svs.clients[i].netconnection)
310 netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
311 netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
312 SCR_DrawNetGraph_DrawConnection_Server(svs.clients[i].netconnection, netgraph_x, netgraph_y, barwidth, barheight, bardivide, va("%s", svs.clients[i].name), separator1, "", textsize);
323 void SCR_DrawTurtle (void)
327 if (cls.state != ca_connected)
330 if (!scr_showturtle.integer)
333 if (cl.realframetime < 0.1)
343 DrawQ_Pic (0, 0, Draw_CachePic ("gfx/turtle"), 0, 0, 1, 1, 1, 1, 0);
351 void SCR_DrawNet (void)
353 if (cls.state != ca_connected)
355 if (realtime - cl.last_received_message < 0.3)
357 if (cls.demoplayback)
360 DrawQ_Pic (64, 0, Draw_CachePic ("gfx/net"), 0, 0, 1, 1, 1, 1, 0);
368 void SCR_DrawPause (void)
372 if (cls.state != ca_connected)
375 if (!scr_showpause.integer) // turn off for screenshots
381 pic = Draw_CachePic ("gfx/pause");
382 DrawQ_Pic ((vid_conwidth.integer - pic->width)/2, (vid_conheight.integer - pic->height)/2, pic, 0, 0, 1, 1, 1, 1, 0);
390 void SCR_DrawBrand (void)
395 if (!scr_showbrand.value)
398 pic = Draw_CachePic ("gfx/brand");
400 switch ((int)scr_showbrand.value)
402 case 1: // bottom left
404 y = vid_conheight.integer - pic->height;
406 case 2: // bottom centre
407 x = (vid_conwidth.integer - pic->width) / 2;
408 y = vid_conheight.integer - pic->height;
410 case 3: // bottom right
411 x = vid_conwidth.integer - pic->width;
412 y = vid_conheight.integer - pic->height;
414 case 4: // centre right
415 x = vid_conwidth.integer - pic->width;
416 y = (vid_conheight.integer - pic->height) / 2;
419 x = vid_conwidth.integer - pic->width;
422 case 6: // top centre
423 x = (vid_conwidth.integer - pic->width) / 2;
430 case 8: // centre left
432 y = (vid_conheight.integer - pic->height) / 2;
438 DrawQ_Pic (x, y, pic, 0, 0, 1, 1, 1, 1, 0);
446 static int SCR_DrawQWDownload(int offset)
448 // sync with SCR_InfobarHeight
454 if (!cls.qw_downloadname[0])
456 cls.qw_downloadspeedrate = 0;
457 cls.qw_downloadspeedtime = realtime;
458 cls.qw_downloadspeedcount = 0;
461 if (realtime >= cls.qw_downloadspeedtime + 1)
463 cls.qw_downloadspeedrate = cls.qw_downloadspeedcount;
464 cls.qw_downloadspeedtime = realtime;
465 cls.qw_downloadspeedcount = 0;
467 if (cls.protocol == PROTOCOL_QUAKEWORLD)
468 dpsnprintf(temp, sizeof(temp), "Downloading %s %3i%% (%i) at %i bytes/s\n", cls.qw_downloadname, cls.qw_downloadpercent, cls.qw_downloadmemorycursize, cls.qw_downloadspeedrate);
470 dpsnprintf(temp, sizeof(temp), "Downloading %s %3i%% (%i/%i) at %i bytes/s\n", cls.qw_downloadname, cls.qw_downloadpercent, cls.qw_downloadmemorycursize, cls.qw_downloadmemorymaxsize, cls.qw_downloadspeedrate);
471 len = (int)strlen(temp);
472 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(temp, len, true, FONT_INFOBAR) * size) / 2;
473 y = vid_conheight.integer - size - offset;
474 DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
475 DrawQ_String_Font(x, y, temp, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
480 SCR_DrawInfobarString
483 static int SCR_DrawInfobarString(int offset)
489 len = (int)strlen(scr_infobarstring);
490 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(scr_infobarstring, len, false, FONT_INFOBAR) * size) / 2;
491 y = vid_conheight.integer - size - offset;
492 DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
493 DrawQ_String_Font(x, y, scr_infobarstring, len, size, size, 1, 1, 1, 1, 0, NULL, false, FONT_INFOBAR);
502 static int SCR_DrawCurlDownload(int offset)
504 // sync with SCR_InfobarHeight
510 Curl_downloadinfo_t *downinfo;
514 downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo);
518 y = vid_conheight.integer - size * nDownloads - offset;
522 len = (int)strlen(addinfo);
523 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(addinfo, len, true, FONT_INFOBAR) * size) / 2;
524 DrawQ_Fill(0, y - size, vid_conwidth.integer, size, 1, 1, 1, cls.signon == SIGNONS ? 0.8 : 1, 0);
525 DrawQ_String_Font(x, y - size, addinfo, len, size, size, 0, 0, 0, 1, 0, NULL, true, FONT_INFOBAR);
528 for(i = 0; i != nDownloads; ++i)
530 if(downinfo[i].queued)
531 dpsnprintf(temp, sizeof(temp), "Still in queue: %s\n", downinfo[i].filename);
532 else if(downinfo[i].progress <= 0)
533 dpsnprintf(temp, sizeof(temp), "Downloading %s ... ???.?%% @ %.1f KiB/s\n", downinfo[i].filename, downinfo[i].speed / 1024.0);
535 dpsnprintf(temp, sizeof(temp), "Downloading %s ... %5.1f%% @ %.1f KiB/s\n", downinfo[i].filename, 100.0 * downinfo[i].progress, downinfo[i].speed / 1024.0);
536 len = (int)strlen(temp);
537 x = (vid_conwidth.integer - DrawQ_TextWidth_Font(temp, len, true, FONT_INFOBAR) * size) / 2;
538 DrawQ_Fill(0, y + i * size, vid_conwidth.integer, size, 0, 0, 0, cls.signon == SIGNONS ? 0.5 : 1, 0);
539 DrawQ_String_Font(x, y + i * size, temp, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
544 return 8 * (nDownloads + (addinfo ? 1 : 0));
552 static void SCR_DrawInfobar()
555 if(scr_infobartime_off > 0)
556 offset += SCR_DrawInfobarString(offset);
557 offset += SCR_DrawQWDownload(offset);
558 offset += SCR_DrawCurlDownload(offset);
559 if(offset != scr_con_margin_bottom)
560 Con_DPrintf("broken console margin calculation: %d != %d\n", offset, scr_con_margin_bottom);
563 static int SCR_InfobarHeight()
566 Curl_downloadinfo_t *downinfo;
570 if (cl.time > cl.oldtime)
571 scr_infobartime_off -= cl.time - cl.oldtime;
572 if(scr_infobartime_off > 0)
575 if(cls.qw_downloadname[0])
578 downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo);
581 offset += 8 * (nDownloads + (addinfo ? 1 : 0));
593 void SCR_InfoBar_f(void)
597 scr_infobartime_off = atof(Cmd_Argv(1));
598 strlcpy(scr_infobarstring, Cmd_Argv(2), sizeof(scr_infobarstring));
602 Con_Printf("usage:\ninfobar expiretime \"string\"\n");
605 //=============================================================================
609 SCR_SetUpToDrawConsole
612 void SCR_SetUpToDrawConsole (void)
614 // lines of console to display
616 static int framecounter = 0;
620 if (scr_menuforcewhiledisconnected.integer && key_dest == key_game && cls.state == ca_disconnected)
622 if (framecounter >= 2)
630 if (scr_conforcewhiledisconnected.integer && key_dest == key_game && cls.signon != SIGNONS)
631 key_consoleactive |= KEY_CONSOLEACTIVE_FORCED;
633 key_consoleactive &= ~KEY_CONSOLEACTIVE_FORCED;
635 // decide on the height of the console
636 if (key_consoleactive & KEY_CONSOLEACTIVE_USER)
637 conlines = vid_conheight.integer/2; // half screen
639 conlines = 0; // none visible
641 scr_con_current = conlines;
649 void SCR_DrawConsole (void)
651 scr_con_margin_bottom = SCR_InfobarHeight();
652 if (key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
655 Con_DrawConsole (vid_conheight.integer - scr_con_margin_bottom);
657 else if (scr_con_current)
658 Con_DrawConsole (min((int)scr_con_current, vid_conheight.integer - scr_con_margin_bottom));
665 SCR_BeginLoadingPlaque
669 void SCR_BeginLoadingPlaque (void)
671 // save console log up to this point to log_file if it was set by configs
675 SCR_UpdateLoadingScreen(false);
678 //=============================================================================
680 char r_speeds_timestring[4096];
681 int speedstringcount, r_timereport_active;
682 double r_timereport_temp = 0, r_timereport_current = 0, r_timereport_start = 0;
683 int r_speeds_longestitem = 0;
685 void R_TimeReport(char *desc)
691 if (r_speeds.integer < 2 || !r_timereport_active)
695 if (r_speeds.integer == 2)
698 r_timereport_temp = r_timereport_current;
699 r_timereport_current = Sys_DoubleTime();
700 t = (int) ((r_timereport_current - r_timereport_temp) * 1000000.0 + 0.5);
702 length = dpsnprintf(tempbuf, sizeof(tempbuf), "%8i %s", t, desc);
703 length = min(length, (int)sizeof(tempbuf) - 1);
704 if (r_speeds_longestitem < length)
705 r_speeds_longestitem = length;
706 for (;length < r_speeds_longestitem;length++)
707 tempbuf[length] = ' ';
710 if (speedstringcount + length > (vid_conwidth.integer / 8))
712 strlcat(r_speeds_timestring, "\n", sizeof(r_speeds_timestring));
713 speedstringcount = 0;
715 strlcat(r_speeds_timestring, tempbuf, sizeof(r_speeds_timestring));
716 speedstringcount += length;
719 void R_TimeReport_BeginFrame(void)
721 speedstringcount = 0;
722 r_speeds_timestring[0] = 0;
723 r_timereport_active = false;
724 memset(&r_refdef.stats, 0, sizeof(r_refdef.stats));
726 if (r_speeds.integer >= 2 && cls.signon == SIGNONS && cls.state == ca_connected)
728 r_timereport_active = true;
729 r_timereport_start = r_timereport_current = Sys_DoubleTime();
733 void R_TimeReport_EndFrame(void)
737 char string[1024+4096];
740 if (r_speeds.integer && cls.signon == SIGNONS && cls.state == ca_connected)
742 // put the location name in the r_speeds display as it greatly helps
743 // when creating loc files
744 loc = CL_Locs_FindNearest(cl.movement_origin);
745 dpsnprintf(string, sizeof(string),
747 "%3i renders org:'%+8.2f %+8.2f %+8.2f' dir:'%+2.3f %+2.3f %+2.3f'\n"
748 "%7i surfaces%7i triangles %5i entities (%7i surfaces%7i triangles)\n"
749 "%5i leafs%5i portals%6i/%6i particles%6i/%6i decals %3i%% quality\n"
750 "%7i lightmap updates (%7i pixels)\n"
751 "%4i lights%4i clears%4i scissored%7i light%7i shadow%7i dynamic\n"
752 "rendered%6i meshes%8i triangles bloompixels%8i copied%8i drawn\n"
754 , loc ? "Location: " : "", loc ? loc->name : ""
755 , r_refdef.stats.renders, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], r_refdef.view.forward[0], r_refdef.view.forward[1], r_refdef.view.forward[2]
756 , r_refdef.stats.world_surfaces, r_refdef.stats.world_triangles, r_refdef.stats.entities, r_refdef.stats.entities_surfaces, r_refdef.stats.entities_triangles
757 , r_refdef.stats.world_leafs, r_refdef.stats.world_portals, r_refdef.stats.particles, cl.num_particles, r_refdef.stats.decals, cl.num_decals, (int)(100 * r_refdef.view.quality)
758 , r_refdef.stats.lightmapupdates, r_refdef.stats.lightmapupdatepixels
759 , r_refdef.stats.lights, r_refdef.stats.lights_clears, r_refdef.stats.lights_scissored, r_refdef.stats.lights_lighttriangles, r_refdef.stats.lights_shadowtriangles, r_refdef.stats.lights_dynamicshadowtriangles
760 , r_refdef.stats.meshes, r_refdef.stats.meshes_elements / 3, r_refdef.stats.bloom_copypixels, r_refdef.stats.bloom_drawpixels
761 , r_speeds_timestring);
763 memset(&r_refdef.stats, 0, sizeof(r_refdef.stats));
765 speedstringcount = 0;
766 r_speeds_timestring[0] = 0;
767 r_timereport_active = false;
769 if (r_speeds.integer >= 2)
771 r_timereport_active = true;
772 r_timereport_start = r_timereport_current = Sys_DoubleTime();
778 if (string[strlen(string)-1] == '\n')
779 string[strlen(string)-1] = 0;
781 for (i = 0;string[i];i++)
782 if (string[i] == '\n')
784 y = vid_conheight.integer - sb_lines - lines * 8;
786 DrawQ_Fill(0, y, vid_conwidth.integer, lines * 8, 0, 0, 0, 0.5, 0);
790 while (string[i] && string[i] != '\n')
793 DrawQ_String(0, y, string + j, i - j, 8, 8, 1, 1, 1, 1, 0, NULL, true);
794 if (string[i] == '\n')
808 void SCR_SizeUp_f (void)
810 Cvar_SetValue ("viewsize",scr_viewsize.value+10);
821 void SCR_SizeDown_f (void)
823 Cvar_SetValue ("viewsize",scr_viewsize.value-10);
826 void SCR_CaptureVideo_EndVideo(void);
827 void CL_Screen_Shutdown(void)
829 SCR_CaptureVideo_EndVideo();
832 void CL_Screen_Init(void)
834 Cvar_RegisterVariable (&scr_fov);
835 Cvar_RegisterVariable (&scr_viewsize);
836 Cvar_RegisterVariable (&scr_conalpha);
837 Cvar_RegisterVariable (&scr_conbrightness);
838 Cvar_RegisterVariable (&scr_conforcewhiledisconnected);
839 Cvar_RegisterVariable (&scr_menuforcewhiledisconnected);
840 Cvar_RegisterVariable (&scr_showram);
841 Cvar_RegisterVariable (&scr_showturtle);
842 Cvar_RegisterVariable (&scr_showpause);
843 Cvar_RegisterVariable (&scr_showbrand);
844 Cvar_RegisterVariable (&scr_centertime);
845 Cvar_RegisterVariable (&scr_printspeed);
846 Cvar_RegisterVariable (&vid_conwidth);
847 Cvar_RegisterVariable (&vid_conheight);
848 Cvar_RegisterVariable (&vid_pixelheight);
849 Cvar_RegisterVariable (&scr_screenshot_jpeg);
850 Cvar_RegisterVariable (&scr_screenshot_jpeg_quality);
851 Cvar_RegisterVariable (&scr_screenshot_gammaboost);
852 Cvar_RegisterVariable (&cl_capturevideo);
853 Cvar_RegisterVariable (&cl_capturevideo_width);
854 Cvar_RegisterVariable (&cl_capturevideo_height);
855 Cvar_RegisterVariable (&cl_capturevideo_realtime);
856 Cvar_RegisterVariable (&cl_capturevideo_fps);
857 Cvar_RegisterVariable (&cl_capturevideo_number);
858 Cvar_RegisterVariable (&r_letterbox);
859 Cvar_RegisterVariable(&r_stereo_separation);
860 Cvar_RegisterVariable(&r_stereo_sidebyside);
861 Cvar_RegisterVariable(&r_stereo_redblue);
862 Cvar_RegisterVariable(&r_stereo_redcyan);
863 Cvar_RegisterVariable(&r_stereo_redgreen);
864 Cvar_RegisterVariable(&r_stereo_angle);
865 Cvar_RegisterVariable(&scr_zoomwindow);
866 Cvar_RegisterVariable(&scr_zoomwindow_viewsizex);
867 Cvar_RegisterVariable(&scr_zoomwindow_viewsizey);
868 Cvar_RegisterVariable(&scr_zoomwindow_fov);
869 Cvar_RegisterVariable(&scr_stipple);
870 Cvar_RegisterVariable(&scr_refresh);
871 Cvar_RegisterVariable(&shownetgraph);
872 Cvar_RegisterVariable(&cl_demo_mousegrab);
874 Cmd_AddCommand ("sizeup",SCR_SizeUp_f, "increase view size (increases viewsize cvar)");
875 Cmd_AddCommand ("sizedown",SCR_SizeDown_f, "decrease view size (decreases viewsize cvar)");
876 Cmd_AddCommand ("screenshot",SCR_ScreenShot_f, "takes a screenshot of the next rendered frame");
877 Cmd_AddCommand ("envmap", R_Envmap_f, "render a cubemap (skybox) of the current scene");
878 Cmd_AddCommand ("infobar", SCR_InfoBar_f, "display a text in the infobar (usage: infobar expiretime string)");
880 scr_initialized = true;
888 void SCR_ScreenShot_f (void)
890 static int shotnumber;
891 static char oldname[MAX_QPATH];
892 char base[MAX_QPATH];
893 char filename[MAX_QPATH];
894 unsigned char *buffer1;
895 unsigned char *buffer2;
896 unsigned char *buffer3;
897 qboolean jpeg = (scr_screenshot_jpeg.integer != 0);
899 dpsnprintf (base, sizeof(base), "screenshots/%s", scr_screenshot_name.string);
901 if (strcmp (oldname, scr_screenshot_name.string))
903 dpsnprintf(oldname, sizeof(oldname), "%s", scr_screenshot_name.string);
907 // find a file name to save it to
908 for (;shotnumber < 1000000;shotnumber++)
909 if (!FS_SysFileExists(va("%s/%s%06d.tga", fs_gamedir, base, shotnumber)) && !FS_SysFileExists(va("%s/%s%06d.jpg", fs_gamedir, base, shotnumber)))
911 if (shotnumber >= 1000000)
913 Con_Print("SCR_ScreenShot_f: Couldn't create the image file\n");
917 dpsnprintf(filename, sizeof(filename), "%s%06d.%s", base, shotnumber, jpeg ? "jpg" : "tga");
919 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3);
920 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3);
921 buffer3 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3 + 18);
923 if (SCR_ScreenShot (filename, buffer1, buffer2, buffer3, 0, 0, vid.width, vid.height, false, false, false, jpeg, true))
924 Con_Printf("Wrote %s\n", filename);
926 Con_Printf("unable to write %s\n", filename);
935 static void SCR_CaptureVideo_RIFF_Start(void)
937 memset(&cls.capturevideo.riffbuffer, 0, sizeof(sizebuf_t));
938 cls.capturevideo.riffbuffer.maxsize = sizeof(cls.capturevideo.riffbufferdata);
939 cls.capturevideo.riffbuffer.data = cls.capturevideo.riffbufferdata;
940 cls.capturevideo.position = 0;
943 static void SCR_CaptureVideo_RIFF_Flush(void)
945 if (cls.capturevideo.riffbuffer.cursize > 0)
947 if (!FS_Write(cls.capturevideo.videofile, cls.capturevideo.riffbuffer.data, cls.capturevideo.riffbuffer.cursize))
948 cls.capturevideo.error = true;
949 cls.capturevideo.position += cls.capturevideo.riffbuffer.cursize;
950 cls.capturevideo.riffbuffer.cursize = 0;
951 cls.capturevideo.riffbuffer.overflowed = false;
955 static void SCR_CaptureVideo_RIFF_WriteBytes(const unsigned char *data, size_t size)
957 SCR_CaptureVideo_RIFF_Flush();
958 if (!FS_Write(cls.capturevideo.videofile, data, size))
959 cls.capturevideo.error = true;
960 cls.capturevideo.position += size;
963 static void SCR_CaptureVideo_RIFF_Write32(int n)
965 if (cls.capturevideo.riffbuffer.cursize + 4 > cls.capturevideo.riffbuffer.maxsize)
966 SCR_CaptureVideo_RIFF_Flush();
967 MSG_WriteLong(&cls.capturevideo.riffbuffer, n);
970 static void SCR_CaptureVideo_RIFF_Write16(int n)
972 if (cls.capturevideo.riffbuffer.cursize + 2 > cls.capturevideo.riffbuffer.maxsize)
973 SCR_CaptureVideo_RIFF_Flush();
974 MSG_WriteShort(&cls.capturevideo.riffbuffer, n);
977 static void SCR_CaptureVideo_RIFF_WriteFourCC(const char *chunkfourcc)
979 if (cls.capturevideo.riffbuffer.cursize + (int)strlen(chunkfourcc) > cls.capturevideo.riffbuffer.maxsize)
980 SCR_CaptureVideo_RIFF_Flush();
981 MSG_WriteUnterminatedString(&cls.capturevideo.riffbuffer, chunkfourcc);
984 static void SCR_CaptureVideo_RIFF_WriteTerminatedString(const char *string)
986 if (cls.capturevideo.riffbuffer.cursize + (int)strlen(string) > cls.capturevideo.riffbuffer.maxsize)
987 SCR_CaptureVideo_RIFF_Flush();
988 MSG_WriteString(&cls.capturevideo.riffbuffer, string);
991 static fs_offset_t SCR_CaptureVideo_RIFF_GetPosition(void)
993 SCR_CaptureVideo_RIFF_Flush();
994 //return FS_Tell(cls.capturevideo.videofile);
995 return cls.capturevideo.position;
998 static void SCR_CaptureVideo_RIFF_Push(const char *chunkfourcc, const char *listtypefourcc, fs_offset_t sizeHint)
1000 Con_Printf("RIFF push: %s\n", chunkfourcc);
1001 if (listtypefourcc && sizeHint >= 0)
1002 sizeHint += 4; // size hint is for INNER size
1003 SCR_CaptureVideo_RIFF_WriteFourCC(chunkfourcc);
1004 SCR_CaptureVideo_RIFF_Write32(sizeHint);
1005 SCR_CaptureVideo_RIFF_Flush();
1006 cls.capturevideo.riffstacksizehint[cls.capturevideo.riffstacklevel] = sizeHint;
1007 cls.capturevideo.riffstackstartoffset[cls.capturevideo.riffstacklevel] = SCR_CaptureVideo_RIFF_GetPosition();
1008 cls.capturevideo.riffstackfourcc[cls.capturevideo.riffstacklevel] = chunkfourcc;
1009 ++cls.capturevideo.riffstacklevel;
1011 SCR_CaptureVideo_RIFF_WriteFourCC(listtypefourcc);
1014 static void SCR_CaptureVideo_RIFF_Pop(void)
1016 fs_offset_t offset, sizehint;
1018 unsigned char sizebytes[4];
1019 // write out the chunk size and then return to the current file position
1020 cls.capturevideo.riffstacklevel--;
1021 offset = SCR_CaptureVideo_RIFF_GetPosition();
1023 sizehint = cls.capturevideo.riffstacksizehint[cls.capturevideo.riffstacklevel];
1024 x = (int)(offset - (cls.capturevideo.riffstackstartoffset[cls.capturevideo.riffstacklevel]));
1026 Con_Printf("RIFF pop: %s\n", cls.capturevideo.riffstackfourcc[cls.capturevideo.riffstacklevel]);
1033 Con_Printf("WARNING: invalid size hint %d when writing video data (actual size: %d)\n", (int) sizehint, x);
1034 for(i = 0; i <= cls.capturevideo.riffstacklevel; ++i)
1036 Con_Printf(" RIFF level %d = %s\n", i, cls.capturevideo.riffstackfourcc[i]);
1039 sizebytes[0] = (x) & 0xff;sizebytes[1] = (x >> 8) & 0xff;sizebytes[2] = (x >> 16) & 0xff;sizebytes[3] = (x >> 24) & 0xff;
1040 if(FS_Seek(cls.capturevideo.videofile, -(x + 4), SEEK_END) >= 0)
1042 FS_Write(cls.capturevideo.videofile, sizebytes, 4);
1044 FS_Seek(cls.capturevideo.videofile, 0, SEEK_END);
1049 SCR_CaptureVideo_RIFF_WriteBytes((unsigned char *) "\0", 1);
1053 static void GrowBuf(sizebuf_t *buf, int extralen)
1055 if(buf->cursize + extralen > buf->maxsize)
1057 int oldsize = buf->maxsize;
1058 unsigned char *olddata;
1059 olddata = buf->data;
1060 buf->maxsize = max(buf->maxsize * 2, 4096);
1061 buf->data = (unsigned char *) Mem_Alloc(tempmempool, buf->maxsize);
1064 memcpy(buf->data, olddata, oldsize);
1070 static void SCR_CaptureVideo_RIFF_IndexEntry(const char *chunkfourcc, int chunksize, int flags)
1072 if(!cls.capturevideo.canseek)
1073 Host_Error("SCR_CaptureVideo_RIFF_IndexEntry called on non-seekable AVI");
1075 if (cls.capturevideo.riffstacklevel != 2)
1076 Sys_Error("SCR_Capturevideo_RIFF_IndexEntry: RIFF stack level is %i (should be 2)\n", cls.capturevideo.riffstacklevel);
1077 GrowBuf(&cls.capturevideo.riffindexbuffer, 16);
1078 SCR_CaptureVideo_RIFF_Flush();
1079 MSG_WriteUnterminatedString(&cls.capturevideo.riffindexbuffer, chunkfourcc);
1080 MSG_WriteLong(&cls.capturevideo.riffindexbuffer, flags);
1081 MSG_WriteLong(&cls.capturevideo.riffindexbuffer, (int)FS_Tell(cls.capturevideo.videofile) - cls.capturevideo.riffstackstartoffset[1]);
1082 MSG_WriteLong(&cls.capturevideo.riffindexbuffer, chunksize);
1085 static void SCR_CaptureVideo_RIFF_MakeIxChunk(const char *fcc, const char *dwChunkId, fs_offset_t masteridx_counter, int *masteridx_count, fs_offset_t masteridx_start)
1089 fs_offset_t ix = SCR_CaptureVideo_RIFF_GetPosition();
1090 fs_offset_t pos, sz;
1092 if(!cls.capturevideo.canseek)
1093 Host_Error("SCR_CaptureVideo_RIFF_MakeIxChunk called on non-seekable AVI");
1095 if(*masteridx_count >= AVI_MASTER_INDEX_SIZE)
1098 nMatching = 0; // go through index and enumerate them
1099 for(i = 0; i < cls.capturevideo.riffindexbuffer.cursize; i += 16)
1100 if(!memcmp(cls.capturevideo.riffindexbuffer.data + i, dwChunkId, 4))
1104 for(i = 0; i < cls.capturevideo.riffindexbuffer.cursize; i += 16)
1105 if(!memcmp(cls.capturevideo.riffindexbuffer.data + i, dwChunkId, 4))
1108 SCR_CaptureVideo_RIFF_Push(fcc, NULL, sz);
1109 SCR_CaptureVideo_RIFF_Write16(2); // wLongsPerEntry
1110 SCR_CaptureVideo_RIFF_Write16(0x0100); // bIndexType=1, bIndexSubType=0
1111 SCR_CaptureVideo_RIFF_Write32(nMatching); // nEntriesInUse
1112 SCR_CaptureVideo_RIFF_WriteFourCC(dwChunkId); // dwChunkId
1113 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.videofile_ix_movistart & (fs_offset_t) 0xFFFFFFFFu);
1114 SCR_CaptureVideo_RIFF_Write32(((fs_offset_t) cls.capturevideo.videofile_ix_movistart) >> 32);
1115 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved
1117 for(i = 0; i < cls.capturevideo.riffindexbuffer.cursize; i += 16)
1118 if(!memcmp(cls.capturevideo.riffindexbuffer.data + i, dwChunkId, 4))
1120 unsigned int *p = (unsigned int *) (cls.capturevideo.riffindexbuffer.data + i);
1121 unsigned int flags = p[1];
1122 unsigned int rpos = p[2];
1123 unsigned int size = p[3];
1124 size &= ~0x80000000;
1125 if(!(flags & 0x10)) // no keyframe?
1127 SCR_CaptureVideo_RIFF_Write32(rpos + 8);
1128 SCR_CaptureVideo_RIFF_Write32(size);
1131 SCR_CaptureVideo_RIFF_Flush();
1132 SCR_CaptureVideo_RIFF_Pop();
1133 pos = SCR_CaptureVideo_RIFF_GetPosition();
1135 if(FS_Seek(cls.capturevideo.videofile, masteridx_start + 16 * *masteridx_count, SEEK_SET) >= 0)
1137 SCR_CaptureVideo_RIFF_Write32(ix & (fs_offset_t) 0xFFFFFFFFu);
1138 SCR_CaptureVideo_RIFF_Write32(((fs_offset_t) ix) >> 32);
1139 SCR_CaptureVideo_RIFF_Write32(pos - ix);
1140 SCR_CaptureVideo_RIFF_Write32(nMatching);
1141 SCR_CaptureVideo_RIFF_Flush();
1144 if(FS_Seek(cls.capturevideo.videofile, masteridx_counter, SEEK_SET) >= 0)
1146 SCR_CaptureVideo_RIFF_Write32(++*masteridx_count);
1147 SCR_CaptureVideo_RIFF_Flush();
1150 FS_Seek(cls.capturevideo.videofile, 0, SEEK_END); // return value doesn't matter here
1153 static void SCR_CaptureVideo_RIFF_Finish(qboolean final)
1155 // close the "movi" list
1156 SCR_CaptureVideo_RIFF_Pop();
1157 if(cls.capturevideo.videofile_ix_master_video_inuse_offset)
1158 SCR_CaptureVideo_RIFF_MakeIxChunk("ix00", "00dc", cls.capturevideo.videofile_ix_master_video_inuse_offset, &cls.capturevideo.videofile_ix_master_video_inuse, cls.capturevideo.videofile_ix_master_video_start_offset);
1159 if(cls.capturevideo.videofile_ix_master_audio_inuse_offset)
1160 SCR_CaptureVideo_RIFF_MakeIxChunk("ix01", "01wb", cls.capturevideo.videofile_ix_master_audio_inuse_offset, &cls.capturevideo.videofile_ix_master_audio_inuse, cls.capturevideo.videofile_ix_master_audio_start_offset);
1161 // write the idx1 chunk that we've been building while saving the frames (for old style players)
1162 if(final && cls.capturevideo.videofile_firstchunkframes_offset)
1163 // TODO replace index creating by OpenDML ix##/##ix/indx chunk so it works for more than one AVI part too
1165 SCR_CaptureVideo_RIFF_Push("idx1", NULL, cls.capturevideo.riffindexbuffer.cursize);
1166 SCR_CaptureVideo_RIFF_WriteBytes(cls.capturevideo.riffindexbuffer.data, cls.capturevideo.riffindexbuffer.cursize);
1167 SCR_CaptureVideo_RIFF_Pop();
1169 cls.capturevideo.riffindexbuffer.cursize = 0;
1170 // pop the RIFF chunk itself
1171 while (cls.capturevideo.riffstacklevel > 0)
1172 SCR_CaptureVideo_RIFF_Pop();
1173 SCR_CaptureVideo_RIFF_Flush();
1174 if(cls.capturevideo.videofile_firstchunkframes_offset)
1176 Con_DPrintf("Finishing first chunk (%d frames)\n", cls.capturevideo.frame);
1177 if(FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_firstchunkframes_offset, SEEK_SET) >= 0)
1179 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.frame);
1180 SCR_CaptureVideo_RIFF_Flush();
1182 FS_Seek(cls.capturevideo.videofile, 0, SEEK_END);
1183 cls.capturevideo.videofile_firstchunkframes_offset = 0;
1186 Con_DPrintf("Finishing another chunk (%d frames)\n", cls.capturevideo.frame);
1189 static void SCR_CaptureVideo_RIFF_OverflowCheck(int framesize)
1191 fs_offset_t cursize, curfilesize;
1192 if (cls.capturevideo.riffstacklevel != 2)
1193 Sys_Error("SCR_CaptureVideo_RIFF_OverflowCheck: chunk stack leakage!\n");
1195 if(!cls.capturevideo.canseek)
1198 // check where we are in the file
1199 SCR_CaptureVideo_RIFF_Flush();
1200 cursize = SCR_CaptureVideo_RIFF_GetPosition() - cls.capturevideo.riffstackstartoffset[0];
1201 curfilesize = SCR_CaptureVideo_RIFF_GetPosition();
1203 // if this would overflow the windows limit of 1GB per RIFF chunk, we need
1204 // to close the current RIFF chunk and open another for future frames
1205 if (8 + cursize + framesize + cls.capturevideo.riffindexbuffer.cursize + 8 + cls.capturevideo.riffindexbuffer.cursize + 64 > 1<<30) // note that the Ix buffer takes less space... I just don't dare to / 2 here now... sorry, maybe later
1207 SCR_CaptureVideo_RIFF_Finish(false);
1208 // begin a new 1GB extended section of the AVI
1209 SCR_CaptureVideo_RIFF_Push("RIFF", "AVIX", -1);
1210 SCR_CaptureVideo_RIFF_Push("LIST", "movi", -1);
1211 cls.capturevideo.videofile_ix_movistart = cls.capturevideo.riffstackstartoffset[1];
1215 static void FindFraction(double val, int *num, int *denom, int denomMax)
1220 bestdiff = fabs(val);
1224 for(i = 1; i <= denomMax; ++i)
1226 int inum = (int) floor(0.5 + val * i);
1227 double diff = fabs(val - inum / (double)i);
1237 void SCR_CaptureVideo_BeginVideo(void)
1239 double gamma, g, aspect;
1240 int width = cl_capturevideo_width.integer, height = cl_capturevideo_height.integer;
1243 if (cls.capturevideo.active)
1245 memset(&cls.capturevideo, 0, sizeof(cls.capturevideo));
1246 // soundrate is figured out on the first SoundFrame
1248 if(width == 0 && height != 0)
1249 width = (int) (height * (double)vid.width / ((double)vid.height * vid_pixelheight.value)); // keep aspect
1250 if(width != 0 && height == 0)
1251 height = (int) (width * ((double)vid.height * vid_pixelheight.value) / (double)vid.width); // keep aspect
1253 if(width < 2 || width > vid.width) // can't scale up
1255 if(height < 2 || height > vid.height) // can't scale up
1256 height = vid.height;
1258 aspect = vid.width / (vid.height * vid_pixelheight.value);
1260 // ensure it's all even; if not, scale down a little
1266 cls.capturevideo.width = width;
1267 cls.capturevideo.height = height;
1268 cls.capturevideo.active = true;
1269 cls.capturevideo.starttime = realtime;
1270 cls.capturevideo.framerate = bound(1, cl_capturevideo_fps.value, 1000);
1271 cls.capturevideo.soundrate = S_GetSoundRate();
1272 cls.capturevideo.frame = 0;
1273 cls.capturevideo.soundsampleframe = 0;
1274 cls.capturevideo.realtime = cl_capturevideo_realtime.integer != 0;
1275 cls.capturevideo.screenbuffer = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
1276 cls.capturevideo.outbuffer = (unsigned char *)Mem_Alloc(tempmempool, width * height * (4+4) + 18);
1277 gamma = 1.0/scr_screenshot_gammaboost.value;
1278 dpsnprintf(cls.capturevideo.basename, sizeof(cls.capturevideo.basename), "video/dpvideo%03i", cl_capturevideo_number.integer);
1279 Cvar_SetValueQuick(&cl_capturevideo_number, cl_capturevideo_number.integer + 1);
1282 for (i = 0;i < 256;i++)
1284 unsigned char j = (unsigned char)bound(0, 255*pow(i/255.0, gamma), 255);
1285 cls.capturevideo.rgbgammatable[0][i] = j;
1286 cls.capturevideo.rgbgammatable[1][i] = j;
1287 cls.capturevideo.rgbgammatable[2][i] = j;
1291 R = Y + 1.4075 * (Cr - 128);
1292 G = Y + -0.3455 * (Cb - 128) + -0.7169 * (Cr - 128);
1293 B = Y + 1.7790 * (Cb - 128);
1294 Y = R * .299 + G * .587 + B * .114;
1295 Cb = R * -.169 + G * -.332 + B * .500 + 128.;
1296 Cr = R * .500 + G * -.419 + B * -.0813 + 128.;
1298 for (i = 0;i < 256;i++)
1300 g = 255*pow(i/255.0, gamma);
1301 // Y weights from RGB
1302 cls.capturevideo.rgbtoyuvscaletable[0][0][i] = (short)(g * 0.299);
1303 cls.capturevideo.rgbtoyuvscaletable[0][1][i] = (short)(g * 0.587);
1304 cls.capturevideo.rgbtoyuvscaletable[0][2][i] = (short)(g * 0.114);
1305 // Cb weights from RGB
1306 cls.capturevideo.rgbtoyuvscaletable[1][0][i] = (short)(g * -0.169);
1307 cls.capturevideo.rgbtoyuvscaletable[1][1][i] = (short)(g * -0.332);
1308 cls.capturevideo.rgbtoyuvscaletable[1][2][i] = (short)(g * 0.500);
1309 // Cr weights from RGB
1310 cls.capturevideo.rgbtoyuvscaletable[2][0][i] = (short)(g * 0.500);
1311 cls.capturevideo.rgbtoyuvscaletable[2][1][i] = (short)(g * -0.419);
1312 cls.capturevideo.rgbtoyuvscaletable[2][2][i] = (short)(g * -0.0813);
1313 // range reduction of YCbCr to valid signal range
1314 cls.capturevideo.yuvnormalizetable[0][i] = 16 + i * (236-16) / 256;
1315 cls.capturevideo.yuvnormalizetable[1][i] = 16 + i * (240-16) / 256;
1316 cls.capturevideo.yuvnormalizetable[2][i] = 16 + i * (240-16) / 256;
1319 //if (cl_capturevideo_)
1324 cls.capturevideo.format = CAPTUREVIDEOFORMAT_AVI_I420;
1325 cls.capturevideo.videofile = FS_OpenRealFile(va("%s.avi", cls.capturevideo.basename), "wb", false);
1326 cls.capturevideo.canseek = (FS_Seek(cls.capturevideo.videofile, 0, SEEK_SET) == 0);
1327 SCR_CaptureVideo_RIFF_Start();
1328 // enclosing RIFF chunk (there can be multiple of these in >1GB files, the later ones are "AVIX" instead of "AVI " and have no header/stream info)
1329 SCR_CaptureVideo_RIFF_Push("RIFF", "AVI ", -1);
1331 SCR_CaptureVideo_RIFF_Push("LIST", "hdrl", cls.capturevideo.canseek ? -1 : 8+56+12+(12+52+8+40+8+68)+(cls.capturevideo.soundrate?(12+12+52+8+18):0)+12+(8+4));
1332 SCR_CaptureVideo_RIFF_Push("avih", NULL, 56);
1333 SCR_CaptureVideo_RIFF_Write32((int)(1000000.0 / cls.capturevideo.framerate)); // microseconds per frame
1334 SCR_CaptureVideo_RIFF_Write32(0); // max bytes per second
1335 SCR_CaptureVideo_RIFF_Write32(0); // padding granularity
1336 SCR_CaptureVideo_RIFF_Write32(0x910); // flags (AVIF_HASINDEX | AVIF_ISINTERLEAVED | AVIF_TRUSTCKTYPE)
1337 cls.capturevideo.videofile_firstchunkframes_offset = SCR_CaptureVideo_RIFF_GetPosition();
1338 SCR_CaptureVideo_RIFF_Write32(0); // total frames
1339 SCR_CaptureVideo_RIFF_Write32(0); // initial frames
1340 if (cls.capturevideo.soundrate)
1341 SCR_CaptureVideo_RIFF_Write32(2); // number of streams
1343 SCR_CaptureVideo_RIFF_Write32(1); // number of streams
1344 SCR_CaptureVideo_RIFF_Write32(0); // suggested buffer size
1345 SCR_CaptureVideo_RIFF_Write32(width); // width
1346 SCR_CaptureVideo_RIFF_Write32(height); // height
1347 SCR_CaptureVideo_RIFF_Write32(0); // reserved[0]
1348 SCR_CaptureVideo_RIFF_Write32(0); // reserved[1]
1349 SCR_CaptureVideo_RIFF_Write32(0); // reserved[2]
1350 SCR_CaptureVideo_RIFF_Write32(0); // reserved[3]
1351 SCR_CaptureVideo_RIFF_Pop();
1352 // video stream info
1353 SCR_CaptureVideo_RIFF_Push("LIST", "strl", cls.capturevideo.canseek ? -1 : 12+52+8+40+8+68);
1354 SCR_CaptureVideo_RIFF_Push("strh", "vids", 52);
1355 SCR_CaptureVideo_RIFF_WriteFourCC("I420"); // stream fourcc (I420 colorspace, uncompressed)
1356 SCR_CaptureVideo_RIFF_Write32(0); // flags
1357 SCR_CaptureVideo_RIFF_Write16(0); // priority
1358 SCR_CaptureVideo_RIFF_Write16(0); // language
1359 SCR_CaptureVideo_RIFF_Write32(0); // initial frames
1360 // find an ideal divisor for the framerate
1361 FindFraction(cls.capturevideo.framerate, &n, &d, 1000);
1362 SCR_CaptureVideo_RIFF_Write32(d); // samples/second divisor
1363 SCR_CaptureVideo_RIFF_Write32(n); // samples/second multiplied by divisor
1364 SCR_CaptureVideo_RIFF_Write32(0); // start
1365 cls.capturevideo.videofile_totalframes_offset1 = SCR_CaptureVideo_RIFF_GetPosition();
1366 SCR_CaptureVideo_RIFF_Write32(0); // length
1367 SCR_CaptureVideo_RIFF_Write32(width*height+(width/2)*(height/2)*2); // suggested buffer size
1368 SCR_CaptureVideo_RIFF_Write32(0); // quality
1369 SCR_CaptureVideo_RIFF_Write32(0); // sample size
1370 SCR_CaptureVideo_RIFF_Write16(0); // frame left
1371 SCR_CaptureVideo_RIFF_Write16(0); // frame top
1372 SCR_CaptureVideo_RIFF_Write16(width); // frame right
1373 SCR_CaptureVideo_RIFF_Write16(height); // frame bottom
1374 SCR_CaptureVideo_RIFF_Pop();
1375 // video stream format
1376 SCR_CaptureVideo_RIFF_Push("strf", NULL, 40);
1377 SCR_CaptureVideo_RIFF_Write32(40); // BITMAPINFO struct size
1378 SCR_CaptureVideo_RIFF_Write32(width); // width
1379 SCR_CaptureVideo_RIFF_Write32(height); // height
1380 SCR_CaptureVideo_RIFF_Write16(3); // planes
1381 SCR_CaptureVideo_RIFF_Write16(12); // bitcount
1382 SCR_CaptureVideo_RIFF_WriteFourCC("I420"); // compression
1383 SCR_CaptureVideo_RIFF_Write32(width*height+(width/2)*(height/2)*2); // size of image
1384 SCR_CaptureVideo_RIFF_Write32(0); // x pixels per meter
1385 SCR_CaptureVideo_RIFF_Write32(0); // y pixels per meter
1386 SCR_CaptureVideo_RIFF_Write32(0); // color used
1387 SCR_CaptureVideo_RIFF_Write32(0); // color important
1388 SCR_CaptureVideo_RIFF_Pop();
1390 if(cls.capturevideo.canseek)
1392 SCR_CaptureVideo_RIFF_Push("indx", NULL, -1);
1393 SCR_CaptureVideo_RIFF_Write16(4); // wLongsPerEntry
1394 SCR_CaptureVideo_RIFF_Write16(0); // bIndexSubType=0, bIndexType=0
1395 cls.capturevideo.videofile_ix_master_video_inuse_offset = SCR_CaptureVideo_RIFF_GetPosition();
1396 SCR_CaptureVideo_RIFF_Write32(0); // nEntriesInUse
1397 SCR_CaptureVideo_RIFF_WriteFourCC("00dc"); // dwChunkId
1398 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved1
1399 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved2
1400 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved3
1401 cls.capturevideo.videofile_ix_master_video_start_offset = SCR_CaptureVideo_RIFF_GetPosition();
1402 for(i = 0; i < AVI_MASTER_INDEX_SIZE * 4; ++i)
1403 SCR_CaptureVideo_RIFF_Write32(0); // fill up later
1404 SCR_CaptureVideo_RIFF_Pop();
1406 // extended format (aspect!)
1407 SCR_CaptureVideo_RIFF_Push("vprp", NULL, 68);
1408 SCR_CaptureVideo_RIFF_Write32(0); // VideoFormatToken
1409 SCR_CaptureVideo_RIFF_Write32(0); // VideoStandard
1410 SCR_CaptureVideo_RIFF_Write32((int)cls.capturevideo.framerate); // dwVerticalRefreshRate (bogus)
1411 SCR_CaptureVideo_RIFF_Write32(width); // dwHTotalInT
1412 SCR_CaptureVideo_RIFF_Write32(height); // dwVTotalInLines
1413 FindFraction(aspect, &n, &d, 1000);
1414 SCR_CaptureVideo_RIFF_Write32((n << 16) | d); // dwFrameAspectRatio // TODO a word
1415 SCR_CaptureVideo_RIFF_Write32(width); // dwFrameWidthInPixels
1416 SCR_CaptureVideo_RIFF_Write32(height); // dwFrameHeightInLines
1417 SCR_CaptureVideo_RIFF_Write32(1); // nFieldPerFrame
1418 SCR_CaptureVideo_RIFF_Write32(width); // CompressedBMWidth
1419 SCR_CaptureVideo_RIFF_Write32(height); // CompressedBMHeight
1420 SCR_CaptureVideo_RIFF_Write32(width); // ValidBMHeight
1421 SCR_CaptureVideo_RIFF_Write32(height); // ValidBMWidth
1422 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMXOffset
1423 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMYOffset
1424 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMXOffsetInT
1425 SCR_CaptureVideo_RIFF_Write32(0); // ValidBMYValidStartLine
1426 SCR_CaptureVideo_RIFF_Pop();
1427 SCR_CaptureVideo_RIFF_Pop();
1428 if (cls.capturevideo.soundrate)
1430 // audio stream info
1431 SCR_CaptureVideo_RIFF_Push("LIST", "strl", cls.capturevideo.canseek ? -1 : 12+52+8+18);
1432 SCR_CaptureVideo_RIFF_Push("strh", "auds", 52);
1433 SCR_CaptureVideo_RIFF_Write32(1); // stream fourcc (PCM audio, uncompressed)
1434 SCR_CaptureVideo_RIFF_Write32(0); // flags
1435 SCR_CaptureVideo_RIFF_Write16(0); // priority
1436 SCR_CaptureVideo_RIFF_Write16(0); // language
1437 SCR_CaptureVideo_RIFF_Write32(0); // initial frames
1438 SCR_CaptureVideo_RIFF_Write32(1); // samples/second divisor
1439 SCR_CaptureVideo_RIFF_Write32((int)(cls.capturevideo.soundrate)); // samples/second multiplied by divisor
1440 SCR_CaptureVideo_RIFF_Write32(0); // start
1441 cls.capturevideo.videofile_totalsampleframes_offset = SCR_CaptureVideo_RIFF_GetPosition();
1442 SCR_CaptureVideo_RIFF_Write32(0); // length
1443 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundrate * 2); // suggested buffer size (this is a half second)
1444 SCR_CaptureVideo_RIFF_Write32(0); // quality
1445 SCR_CaptureVideo_RIFF_Write32(4); // sample size
1446 SCR_CaptureVideo_RIFF_Write16(0); // frame left
1447 SCR_CaptureVideo_RIFF_Write16(0); // frame top
1448 SCR_CaptureVideo_RIFF_Write16(0); // frame right
1449 SCR_CaptureVideo_RIFF_Write16(0); // frame bottom
1450 SCR_CaptureVideo_RIFF_Pop();
1451 // audio stream format
1452 SCR_CaptureVideo_RIFF_Push("strf", NULL, 18);
1453 SCR_CaptureVideo_RIFF_Write16(1); // format (uncompressed PCM?)
1454 SCR_CaptureVideo_RIFF_Write16(2); // channels (stereo)
1455 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundrate); // sampleframes per second
1456 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundrate * 4); // average bytes per second
1457 SCR_CaptureVideo_RIFF_Write16(4); // block align
1458 SCR_CaptureVideo_RIFF_Write16(16); // bits per sample
1459 SCR_CaptureVideo_RIFF_Write16(0); // size
1460 SCR_CaptureVideo_RIFF_Pop();
1462 if(cls.capturevideo.canseek)
1464 SCR_CaptureVideo_RIFF_Push("indx", NULL, -1);
1465 SCR_CaptureVideo_RIFF_Write16(4); // wLongsPerEntry
1466 SCR_CaptureVideo_RIFF_Write16(0); // bIndexSubType=0, bIndexType=0
1467 cls.capturevideo.videofile_ix_master_audio_inuse_offset = SCR_CaptureVideo_RIFF_GetPosition();
1468 SCR_CaptureVideo_RIFF_Write32(0); // nEntriesInUse
1469 SCR_CaptureVideo_RIFF_WriteFourCC("01wb"); // dwChunkId
1470 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved1
1471 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved2
1472 SCR_CaptureVideo_RIFF_Write32(0); // dwReserved3
1473 cls.capturevideo.videofile_ix_master_audio_start_offset = SCR_CaptureVideo_RIFF_GetPosition();
1474 for(i = 0; i < AVI_MASTER_INDEX_SIZE * 4; ++i)
1475 SCR_CaptureVideo_RIFF_Write32(0); // fill up later
1476 SCR_CaptureVideo_RIFF_Pop();
1478 SCR_CaptureVideo_RIFF_Pop();
1481 cls.capturevideo.videofile_ix_master_audio_inuse = cls.capturevideo.videofile_ix_master_video_inuse = 0;
1483 // extended header (for total #frames)
1484 SCR_CaptureVideo_RIFF_Push("LIST", "odml", 8+4);
1485 SCR_CaptureVideo_RIFF_Push("dmlh", NULL, 4);
1486 cls.capturevideo.videofile_totalframes_offset2 = SCR_CaptureVideo_RIFF_GetPosition();
1487 SCR_CaptureVideo_RIFF_Write32(0);
1488 SCR_CaptureVideo_RIFF_Pop();
1489 SCR_CaptureVideo_RIFF_Pop();
1491 // close the AVI header list
1492 SCR_CaptureVideo_RIFF_Pop();
1493 // software that produced this AVI video file
1494 SCR_CaptureVideo_RIFF_Push("LIST", "INFO", 8+((strlen(engineversion) | 1) + 1));
1495 SCR_CaptureVideo_RIFF_Push("ISFT", NULL, strlen(engineversion) + 1);
1496 SCR_CaptureVideo_RIFF_WriteTerminatedString(engineversion);
1497 SCR_CaptureVideo_RIFF_Pop();
1498 // enable this junk filler if you like the LIST movi to always begin at 4KB in the file (why?)
1500 SCR_CaptureVideo_RIFF_Push("JUNK", NULL);
1501 x = 4096 - SCR_CaptureVideo_RIFF_GetPosition();
1504 const char *junkfiller = "[ DarkPlaces junk data ]";
1505 int i = min(x, (int)strlen(junkfiller));
1506 SCR_CaptureVideo_RIFF_WriteBytes((const unsigned char *)junkfiller, i);
1509 SCR_CaptureVideo_RIFF_Pop();
1511 SCR_CaptureVideo_RIFF_Pop();
1512 // begin the actual video section now
1513 SCR_CaptureVideo_RIFF_Push("LIST", "movi", -1);
1514 cls.capturevideo.videofile_ix_movistart = cls.capturevideo.riffstackstartoffset[1];
1515 // we're done with the headers now...
1516 SCR_CaptureVideo_RIFF_Flush();
1517 if (cls.capturevideo.riffstacklevel != 2)
1518 Sys_Error("SCR_CaptureVideo_BeginVideo: broken AVI writing code (stack level is %i (should be 2) at end of headers)\n", cls.capturevideo.riffstacklevel);
1521 switch(cls.capturevideo.format)
1523 case CAPTUREVIDEOFORMAT_AVI_I420:
1530 void SCR_CaptureVideo_EndVideo(void)
1532 if (!cls.capturevideo.active)
1534 cls.capturevideo.active = false;
1535 if (cls.capturevideo.videofile)
1537 switch(cls.capturevideo.format)
1539 case CAPTUREVIDEOFORMAT_AVI_I420:
1540 // close any open chunks
1541 SCR_CaptureVideo_RIFF_Finish(true);
1542 // go back and fix the video frames and audio samples fields
1543 Con_DPrintf("Finishing capture (%d frames, %d audio frames)\n", cls.capturevideo.frame, cls.capturevideo.soundsampleframe);
1544 if(cls.capturevideo.videofile_totalframes_offset1)
1545 if(FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_totalframes_offset1, SEEK_SET) >= 0)
1547 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.frame);
1548 SCR_CaptureVideo_RIFF_Flush();
1550 if(cls.capturevideo.videofile_totalframes_offset2)
1551 if(FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_totalframes_offset2, SEEK_SET) >= 0)
1553 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.frame);
1554 SCR_CaptureVideo_RIFF_Flush();
1556 if (cls.capturevideo.soundrate)
1558 if(cls.capturevideo.videofile_totalsampleframes_offset)
1559 if(FS_Seek(cls.capturevideo.videofile, cls.capturevideo.videofile_totalsampleframes_offset, SEEK_SET) >= 0)
1561 SCR_CaptureVideo_RIFF_Write32(cls.capturevideo.soundsampleframe);
1562 SCR_CaptureVideo_RIFF_Flush();
1569 FS_Close(cls.capturevideo.videofile);
1570 cls.capturevideo.videofile = NULL;
1573 if (cls.capturevideo.screenbuffer)
1575 Mem_Free (cls.capturevideo.screenbuffer);
1576 cls.capturevideo.screenbuffer = NULL;
1579 if (cls.capturevideo.outbuffer)
1581 Mem_Free (cls.capturevideo.outbuffer);
1582 cls.capturevideo.outbuffer = NULL;
1585 if (cls.capturevideo.riffindexbuffer.data)
1587 Mem_Free(cls.capturevideo.riffindexbuffer.data);
1588 cls.capturevideo.riffindexbuffer.data = NULL;
1591 memset(&cls.capturevideo, 0, sizeof(cls.capturevideo));
1594 // converts from BGRA32 to I420 colorspace (identical to YV12 except chroma plane order is reversed), this colorspace is handled by the Intel(r) 4:2:0 codec on Windows
1595 void SCR_CaptureVideo_ConvertFrame_BGRA_to_I420_flip(int width, int height, unsigned char *instart, unsigned char *outstart)
1598 int blockr, blockg, blockb;
1599 int outoffset = (width/2)*(height/2);
1600 unsigned char *b, *out;
1601 // process one line at a time, and CbCr every other line at 2 pixel intervals
1602 for (y = 0;y < height;y++)
1605 for (b = instart + (height-1-y)*width*4, out = outstart + y*width, x = 0;x < width;x++, b += 4, out++)
1610 *out = cls.capturevideo.yuvnormalizetable[0][cls.capturevideo.rgbtoyuvscaletable[0][0][blockr] + cls.capturevideo.rgbtoyuvscaletable[0][1][blockg] + cls.capturevideo.rgbtoyuvscaletable[0][2][blockb]];
1614 // 2x2 Cr and Cb planes
1615 int inpitch = width*4;
1616 for (b = instart + (height-2-y)*width*4, out = outstart + width*height + (y/2)*(width/2), x = 0;x < width/2;x++, b += 8, out++)
1618 blockr = (b[2] + b[6] + b[inpitch+2] + b[inpitch+6]) >> 2;
1619 blockg = (b[1] + b[5] + b[inpitch+1] + b[inpitch+5]) >> 2;
1620 blockb = (b[0] + b[4] + b[inpitch+0] + b[inpitch+4]) >> 2;
1622 out[0 ] = cls.capturevideo.yuvnormalizetable[1][cls.capturevideo.rgbtoyuvscaletable[1][0][blockr] + cls.capturevideo.rgbtoyuvscaletable[1][1][blockg] + cls.capturevideo.rgbtoyuvscaletable[1][2][blockb] + 128];
1624 out[outoffset] = cls.capturevideo.yuvnormalizetable[2][cls.capturevideo.rgbtoyuvscaletable[2][0][blockr] + cls.capturevideo.rgbtoyuvscaletable[2][1][blockg] + cls.capturevideo.rgbtoyuvscaletable[2][2][blockb] + 128];
1630 static void SCR_ScaleDownBGRA(unsigned char *in, int inw, int inh, unsigned char *out, int outw, int outh)
1632 // TODO optimize this function
1637 // memcpy is faster than me
1638 if(inw == outw && inh == outh)
1640 memcpy(out, in, 4 * inw * inh);
1644 // otherwise: a box filter
1645 area = (float)outw * (float)outh / (float)inw / (float)inh;
1646 for(y = 0; y < outh; ++y)
1648 float iny0 = y / (float)outh * inh; int iny0_i = (int) floor(iny0);
1649 float iny1 = (y+1) / (float)outh * inh; int iny1_i = (int) ceil(iny1);
1650 for(x = 0; x < outw; ++x)
1652 float inx0 = x / (float)outw * inw; int inx0_i = (int) floor(inx0);
1653 float inx1 = (x+1) / (float)outw * inw; int inx1_i = (int) ceil(inx1);
1654 float r = 0, g = 0, b = 0, alpha = 0;
1657 for(yy = iny0_i; yy < iny1_i; ++yy)
1659 float ya = min(yy+1, iny1) - max(iny0, yy);
1660 for(xx = inx0_i; xx < inx1_i; ++xx)
1662 float a = ya * (min(xx+1, inx1) - max(inx0, xx));
1663 r += a * in[4*(xx + inw * yy)+0];
1664 g += a * in[4*(xx + inw * yy)+1];
1665 b += a * in[4*(xx + inw * yy)+2];
1666 alpha += a * in[4*(xx + inw * yy)+3];
1670 out[4*(x + outw * y)+0] = (unsigned char) (r * area);
1671 out[4*(x + outw * y)+1] = (unsigned char) (g * area);
1672 out[4*(x + outw * y)+2] = (unsigned char) (b * area);
1673 out[4*(x + outw * y)+3] = (unsigned char) (alpha * area);
1678 qboolean SCR_CaptureVideo_VideoFrame(int newframenum)
1680 int x = 0, y = 0, width = cls.capturevideo.width, height = cls.capturevideo.height;
1681 unsigned char *in, *out;
1683 //return SCR_ScreenShot(filename, cls.capturevideo.buffer, cls.capturevideo.buffer + vid.width * vid.height * 3, cls.capturevideo.buffer + vid.width * vid.height * 6, 0, 0, vid.width, vid.height, false, false, false, jpeg, true);
1684 // speed is critical here, so do saving as directly as possible
1685 switch (cls.capturevideo.format)
1687 case CAPTUREVIDEOFORMAT_AVI_I420:
1688 // if there's no videofile we have to just give up, and abort saving
1689 if (!cls.capturevideo.videofile)
1691 // FIXME: width/height must be multiple of 2, enforce this?
1692 qglReadPixels (x, y, vid.width, vid.height, GL_BGRA, GL_UNSIGNED_BYTE, cls.capturevideo.screenbuffer);CHECKGLERROR
1693 SCR_ScaleDownBGRA (cls.capturevideo.screenbuffer, vid.width, vid.height, cls.capturevideo.outbuffer, width, height);
1694 in = cls.capturevideo.outbuffer;
1695 out = cls.capturevideo.outbuffer + width*height*4;
1696 SCR_CaptureVideo_ConvertFrame_BGRA_to_I420_flip(width, height, in, out);
1697 x = width*height+(width/2)*(height/2)*2;
1698 SCR_CaptureVideo_RIFF_OverflowCheck(8 + x);
1699 for (;cls.capturevideo.frame < newframenum;cls.capturevideo.frame++)
1701 if(cls.capturevideo.canseek)
1702 SCR_CaptureVideo_RIFF_IndexEntry("00dc", x, 0x10); // AVIIF_KEYFRAME
1703 SCR_CaptureVideo_RIFF_Push("00dc", NULL, x);
1704 SCR_CaptureVideo_RIFF_WriteBytes(out, x);
1705 SCR_CaptureVideo_RIFF_Pop();
1713 void SCR_CaptureVideo_SoundFrame(unsigned char *bufstereo16le, size_t length, int rate)
1716 cls.capturevideo.soundrate = rate;
1717 cls.capturevideo.soundsampleframe += length;
1718 switch (cls.capturevideo.format)
1720 case CAPTUREVIDEOFORMAT_AVI_I420:
1722 SCR_CaptureVideo_RIFF_OverflowCheck(8 + x);
1723 if(cls.capturevideo.canseek)
1724 SCR_CaptureVideo_RIFF_IndexEntry("01wb", x, 0x10); // AVIIF_KEYFRAME
1725 SCR_CaptureVideo_RIFF_Push("01wb", NULL, x);
1726 SCR_CaptureVideo_RIFF_WriteBytes(bufstereo16le, x);
1727 SCR_CaptureVideo_RIFF_Pop();
1734 void SCR_CaptureVideo(void)
1737 if (cl_capturevideo.integer && r_render.integer)
1739 if (!cls.capturevideo.active)
1740 SCR_CaptureVideo_BeginVideo();
1741 if (cls.capturevideo.framerate != cl_capturevideo_fps.value)
1743 Con_Printf("You can not change the video framerate while recording a video.\n");
1744 Cvar_SetValueQuick(&cl_capturevideo_fps, cls.capturevideo.framerate);
1746 // for AVI saving we have to make sure that sound is saved before video
1747 if (cls.capturevideo.soundrate && !cls.capturevideo.soundsampleframe)
1749 if (cls.capturevideo.realtime)
1751 // preserve sound sync by duplicating frames when running slow
1752 newframenum = (int)((realtime - cls.capturevideo.starttime) * cls.capturevideo.framerate);
1755 newframenum = cls.capturevideo.frame + 1;
1756 // if falling behind more than one second, stop
1757 if (newframenum - cls.capturevideo.frame > 60 * (int)ceil(cls.capturevideo.framerate))
1759 Cvar_SetValueQuick(&cl_capturevideo, 0);
1760 Con_Printf("video saving failed on frame %i, your machine is too slow for this capture speed.\n", cls.capturevideo.frame);
1761 SCR_CaptureVideo_EndVideo();
1765 SCR_CaptureVideo_VideoFrame(newframenum);
1766 if (cls.capturevideo.error)
1768 Cvar_SetValueQuick(&cl_capturevideo, 0);
1769 Con_Printf("video saving failed on frame %i, out of disk space? stopping video capture.\n", cls.capturevideo.frame);
1770 SCR_CaptureVideo_EndVideo();
1773 else if (cls.capturevideo.active)
1774 SCR_CaptureVideo_EndVideo();
1781 Grab six views for environment mapping tests
1788 qboolean flipx, flipy, flipdiagonaly;
1792 {{ 0, 0, 0}, "rt", false, false, false},
1793 {{ 0, 270, 0}, "ft", false, false, false},
1794 {{ 0, 180, 0}, "lf", false, false, false},
1795 {{ 0, 90, 0}, "bk", false, false, false},
1796 {{-90, 180, 0}, "up", true, true, false},
1797 {{ 90, 180, 0}, "dn", true, true, false},
1799 {{ 0, 0, 0}, "px", true, true, true},
1800 {{ 0, 90, 0}, "py", false, true, false},
1801 {{ 0, 180, 0}, "nx", false, false, true},
1802 {{ 0, 270, 0}, "ny", true, false, false},
1803 {{-90, 180, 0}, "pz", false, false, true},
1804 {{ 90, 180, 0}, "nz", false, false, true}
1807 static void R_Envmap_f (void)
1810 char filename[MAX_QPATH], basename[MAX_QPATH];
1811 unsigned char *buffer1;
1812 unsigned char *buffer2;
1813 unsigned char *buffer3;
1815 if (Cmd_Argc() != 3)
1817 Con_Print("envmap <basename> <size>: save out 6 cubic environment map images, usable with loadsky, note that size must one of 128, 256, 512, or 1024 and can't be bigger than your current resolution\n");
1821 strlcpy (basename, Cmd_Argv(1), sizeof (basename));
1822 size = atoi(Cmd_Argv(2));
1823 if (size != 128 && size != 256 && size != 512 && size != 1024)
1825 Con_Print("envmap: size must be one of 128, 256, 512, or 1024\n");
1828 if (size > vid.width || size > vid.height)
1830 Con_Print("envmap: your resolution is not big enough to render that size\n");
1834 r_refdef.envmap = true;
1836 R_UpdateVariables();
1838 r_refdef.view.x = 0;
1839 r_refdef.view.y = 0;
1840 r_refdef.view.z = 0;
1841 r_refdef.view.width = size;
1842 r_refdef.view.height = size;
1843 r_refdef.view.depth = 1;
1844 r_refdef.view.useperspective = true;
1845 r_refdef.view.isoverlay = false;
1847 r_refdef.view.frustum_x = tan(90 * M_PI / 360.0);
1848 r_refdef.view.frustum_y = tan(90 * M_PI / 360.0);
1850 buffer1 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3);
1851 buffer2 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3);
1852 buffer3 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3 + 18);
1854 for (j = 0;j < 12;j++)
1856 dpsnprintf(filename, sizeof(filename), "env/%s%s.tga", basename, envmapinfo[j].name);
1857 Matrix4x4_CreateFromQuakeEntity(&r_refdef.view.matrix, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], envmapinfo[j].angles[0], envmapinfo[j].angles[1], envmapinfo[j].angles[2], 1);
1858 r_refdef.view.quality = 1;
1859 r_refdef.view.clear = true;
1863 SCR_ScreenShot(filename, buffer1, buffer2, buffer3, 0, vid.height - (r_refdef.view.y + r_refdef.view.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false, false);
1870 r_refdef.envmap = false;
1873 //=============================================================================
1875 void SHOWLMP_decodehide(void)
1879 lmplabel = MSG_ReadString();
1880 for (i = 0;i < cl.num_showlmps;i++)
1881 if (cl.showlmps[i].isactive && strcmp(cl.showlmps[i].label, lmplabel) == 0)
1883 cl.showlmps[i].isactive = false;
1888 void SHOWLMP_decodeshow(void)
1891 char lmplabel[256], picname[256];
1893 strlcpy (lmplabel,MSG_ReadString(), sizeof (lmplabel));
1894 strlcpy (picname, MSG_ReadString(), sizeof (picname));
1895 if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
1902 x = MSG_ReadShort();
1903 y = MSG_ReadShort();
1905 if (!cl.showlmps || cl.num_showlmps >= cl.max_showlmps)
1907 showlmp_t *oldshowlmps = cl.showlmps;
1908 cl.max_showlmps += 16;
1909 cl.showlmps = (showlmp_t *) Mem_Alloc(cls.levelmempool, cl.max_showlmps * sizeof(showlmp_t));
1910 if (cl.num_showlmps)
1911 memcpy(cl.showlmps, oldshowlmps, cl.num_showlmps * sizeof(showlmp_t));
1913 Mem_Free(oldshowlmps);
1915 for (k = 0;k < cl.max_showlmps;k++)
1916 if (cl.showlmps[k].isactive && !strcmp(cl.showlmps[k].label, lmplabel))
1918 if (k == cl.max_showlmps)
1919 for (k = 0;k < cl.max_showlmps;k++)
1920 if (!cl.showlmps[k].isactive)
1922 cl.showlmps[k].isactive = true;
1923 strlcpy (cl.showlmps[k].label, lmplabel, sizeof (cl.showlmps[k].label));
1924 strlcpy (cl.showlmps[k].pic, picname, sizeof (cl.showlmps[k].pic));
1925 cl.showlmps[k].x = x;
1926 cl.showlmps[k].y = y;
1927 cl.num_showlmps = max(cl.num_showlmps, k + 1);
1930 void SHOWLMP_drawall(void)
1933 for (i = 0;i < cl.num_showlmps;i++)
1934 if (cl.showlmps[i].isactive)
1935 DrawQ_Pic(cl.showlmps[i].x, cl.showlmps[i].y, Draw_CachePic (cl.showlmps[i].pic), 0, 0, 1, 1, 1, 1, 0);
1939 ==============================================================================
1943 ==============================================================================
1946 qboolean SCR_ScreenShot(char *filename, unsigned char *buffer1, unsigned char *buffer2, unsigned char *buffer3, int x, int y, int width, int height, qboolean flipx, qboolean flipy, qboolean flipdiagonal, qboolean jpeg, qboolean gammacorrect)
1948 int indices[3] = {0,1,2};
1951 if (!r_render.integer)
1955 qglReadPixels (x, y, width, height, jpeg ? GL_RGB : GL_BGR, GL_UNSIGNED_BYTE, buffer1);CHECKGLERROR
1957 if (scr_screenshot_gammaboost.value != 1 && gammacorrect)
1960 double igamma = 1.0 / scr_screenshot_gammaboost.value;
1961 unsigned char ramp[256];
1962 for (i = 0;i < 256;i++)
1963 ramp[i] = (unsigned char) (pow(i * (1.0 / 255.0), igamma) * 255.0);
1964 for (i = 0;i < width*height*3;i++)
1965 buffer1[i] = ramp[buffer1[i]];
1968 Image_CopyMux (buffer2, buffer1, width, height, flipx, flipy, flipdiagonal, 3, 3, indices);
1971 ret = JPEG_SaveImage_preflipped (filename, width, height, buffer2);
1973 ret = Image_WriteTGABGR_preflipped (filename, width, height, buffer2, buffer3);
1978 //=============================================================================
1980 extern void R_UpdateFogColor(void);
1981 void R_ClearScreen(qboolean fogcolor)
1988 qglClearColor(r_refdef.fogcolor[0],r_refdef.fogcolor[1],r_refdef.fogcolor[2],0);CHECKGLERROR
1992 qglClearColor(0,0,0,0);CHECKGLERROR
1994 qglClearDepth(1);CHECKGLERROR
1997 // LordHavoc: we use a stencil centered around 128 instead of 0,
1998 // to avoid clamping interfering with strange shadow volume
2000 qglClearStencil(128);CHECKGLERROR
2003 if (r_render.integer)
2004 GL_Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | (gl_stencil ? GL_STENCIL_BUFFER_BIT : 0));
2005 // set dithering mode
2006 if (gl_dither.integer)
2008 qglEnable(GL_DITHER);CHECKGLERROR
2012 qglDisable(GL_DITHER);CHECKGLERROR
2016 qboolean CL_VM_UpdateView (void);
2017 void SCR_DrawConsole (void);
2018 void R_Shadow_EditLights_DrawSelectedLightProperties(void);
2022 void SCR_DrawScreen (void)
2026 R_TimeReport_BeginFrame();
2028 R_UpdateVariables();
2030 // Quake uses clockwise winding, so these are swapped
2031 r_refdef.view.cullface_front = GL_BACK;
2032 r_refdef.view.cullface_back = GL_FRONT;
2034 if (cls.signon == SIGNONS)
2038 size = scr_viewsize.value * (1.0 / 100.0);
2039 size = min(size, 1);
2041 if (r_stereo_sidebyside.integer)
2043 r_refdef.view.width = (int)(vid.width * size / 2.5);
2044 r_refdef.view.height = (int)(vid.height * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100));
2045 r_refdef.view.depth = 1;
2046 r_refdef.view.x = (int)((vid.width - r_refdef.view.width * 2.5) * 0.5);
2047 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
2048 r_refdef.view.z = 0;
2050 r_refdef.view.x += (int)(r_refdef.view.width * 1.5);
2054 r_refdef.view.width = (int)(vid.width * size);
2055 r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
2056 r_refdef.view.depth = 1;
2057 r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
2058 r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
2059 r_refdef.view.z = 0;
2062 // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
2063 // LordHavoc: this is designed to produce widescreen fov values
2064 // when the screen is wider than 4/3 width/height aspect, to do
2065 // this it simply assumes the requested fov is the vertical fov
2066 // for a 4x3 display, if the ratio is not 4x3 this makes the fov
2067 // higher/lower according to the ratio
2068 r_refdef.view.useperspective = true;
2069 r_refdef.view.frustum_y = tan(scr_fov.value * M_PI / 360.0) * (3.0/4.0) * cl.viewzoom;
2070 r_refdef.view.frustum_x = r_refdef.view.frustum_y * (float)r_refdef.view.width / (float)r_refdef.view.height / vid_pixelheight.value;
2072 r_refdef.view.frustum_x *= r_refdef.frustumscale_x;
2073 r_refdef.view.frustum_y *= r_refdef.frustumscale_y;
2075 if(!CL_VM_UpdateView())
2078 if (scr_zoomwindow.integer)
2080 float sizex = bound(10, scr_zoomwindow_viewsizex.value, 100) / 100.0;
2081 float sizey = bound(10, scr_zoomwindow_viewsizey.value, 100) / 100.0;
2082 r_refdef.view.width = (int)(vid.width * sizex);
2083 r_refdef.view.height = (int)(vid.height * sizey);
2084 r_refdef.view.depth = 1;
2085 r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
2086 r_refdef.view.y = 0;
2087 r_refdef.view.z = 0;
2089 r_refdef.view.useperspective = true;
2090 r_refdef.view.frustum_y = tan(scr_zoomwindow_fov.value * M_PI / 360.0) * (3.0/4.0) * cl.viewzoom;
2091 r_refdef.view.frustum_x = r_refdef.view.frustum_y * vid_pixelheight.value * (float)r_refdef.view.width / (float)r_refdef.view.height;
2093 r_refdef.view.frustum_x *= r_refdef.frustumscale_x;
2094 r_refdef.view.frustum_y *= r_refdef.frustumscale_y;
2096 if(!CL_VM_UpdateView())
2101 if (!r_stereo_sidebyside.integer)
2103 r_refdef.view.width = vid.width;
2104 r_refdef.view.height = vid.height;
2105 r_refdef.view.depth = 1;
2106 r_refdef.view.x = 0;
2107 r_refdef.view.y = 0;
2108 r_refdef.view.z = 0;
2109 r_refdef.view.useperspective = false;
2113 if(!scr_con_current && !(key_consoleactive & KEY_CONSOLEACTIVE_FORCED))
2114 if ((key_dest == key_game || key_dest == key_message) && !r_letterbox.value)
2115 Con_DrawNotify (); // only draw notify in game
2117 if (cls.signon == SIGNONS)
2122 if (!r_letterbox.value)
2125 SCR_CheckDrawCenterString();
2127 SCR_DrawNetGraph ();
2130 R_Shadow_EditLights_DrawSelectedLightProperties();
2138 if (r_timereport_active)
2141 if (cls.signon == SIGNONS)
2142 R_TimeReport_EndFrame();
2151 void SCR_UpdateLoadingScreen (qboolean clear)
2156 float texcoord2f[8];
2157 // don't do anything if not initialized yet
2158 if (vid_hidden || !scr_refresh.integer)
2160 // release mouse grab while loading
2161 if (!vid.fullscreen)
2162 VID_SetMouse(false, false, false);
2164 qglViewport(0, 0, vid.width, vid.height);CHECKGLERROR
2165 //qglDisable(GL_SCISSOR_TEST);CHECKGLERROR
2166 //qglDepthMask(1);CHECKGLERROR
2167 qglColorMask(1,1,1,1);CHECKGLERROR
2168 qglClearColor(0,0,0,0);CHECKGLERROR
2169 // when starting up a new video mode, make sure the screen is cleared to black
2172 qglClear(GL_COLOR_BUFFER_BIT);CHECKGLERROR
2174 //qglDisable(GL_CULL_FACE);CHECKGLERROR
2177 GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
2179 R_Mesh_Matrix(&identitymatrix);
2180 // draw the loading plaque
2181 pic = Draw_CachePic ("gfx/loading");
2182 x = (vid_conwidth.integer - pic->width)/2;
2183 y = (vid_conheight.integer - pic->height)/2;
2185 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2186 GL_DepthRange(0, 1);
2187 GL_PolygonOffset(0, 0);
2188 GL_DepthTest(false);
2189 R_Mesh_VertexPointer(vertex3f, 0, 0);
2190 R_Mesh_ColorPointer(NULL, 0, 0);
2191 R_Mesh_ResetTextureState();
2192 R_Mesh_TexBind(0, R_GetTexture(pic->tex));
2193 R_Mesh_TexCoordPointer(0, 2, texcoord2f, 0, 0);
2194 R_SetupGenericShader(true);
2195 vertex3f[2] = vertex3f[5] = vertex3f[8] = vertex3f[11] = 0;
2196 vertex3f[0] = vertex3f[9] = x;
2197 vertex3f[1] = vertex3f[4] = y;
2198 vertex3f[3] = vertex3f[6] = x + pic->width;
2199 vertex3f[7] = vertex3f[10] = y + pic->height;
2200 texcoord2f[0] = 0;texcoord2f[1] = 0;
2201 texcoord2f[2] = 1;texcoord2f[3] = 0;
2202 texcoord2f[4] = 1;texcoord2f[5] = 1;
2203 texcoord2f[6] = 0;texcoord2f[7] = 1;
2204 if (vid.stereobuffer)
2206 qglDrawBuffer(GL_FRONT_LEFT);
2207 R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
2208 qglDrawBuffer(GL_FRONT_RIGHT);
2209 R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
2213 qglDrawBuffer(GL_FRONT);
2214 R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
2218 // not necessary when rendering to GL_FRONT buffers
2220 // however this IS necessary on Windows Vista
2224 extern cvar_t cl_minfps;
2225 extern cvar_t cl_minfps_fade;
2226 extern cvar_t cl_minfps_qualitymax;
2227 extern cvar_t cl_minfps_qualitymin;
2228 extern cvar_t cl_minfps_qualitypower;
2229 extern cvar_t cl_minfps_qualityscale;
2230 static double cl_updatescreen_rendertime = 0;
2231 static double cl_updatescreen_quality = 1;
2232 void CL_UpdateScreen(void)
2235 float conwidth, conheight;
2237 if (!scr_initialized || !con_initialized)
2238 return; // not initialized yet
2240 if(gamemode == GAME_NEXUIZ)
2242 // play a bit with the palette (experimental)
2243 palette_rgb_pantscolormap[15][0] = (unsigned char) (128 + 127 * sin(cl.time / exp(1) + 0*M_PI/3));
2244 palette_rgb_pantscolormap[15][1] = (unsigned char) (128 + 127 * sin(cl.time / exp(1) + 2*M_PI/3));
2245 palette_rgb_pantscolormap[15][2] = (unsigned char) (128 + 127 * sin(cl.time / exp(1) + 4*M_PI/3));
2246 palette_rgb_shirtcolormap[15][0] = (unsigned char) (128 + 127 * sin(cl.time / M_PI + 5*M_PI/3));
2247 palette_rgb_shirtcolormap[15][1] = (unsigned char) (128 + 127 * sin(cl.time / M_PI + 3*M_PI/3));
2248 palette_rgb_shirtcolormap[15][2] = (unsigned char) (128 + 127 * sin(cl.time / M_PI + 1*M_PI/3));
2249 memcpy(palette_rgb_pantsscoreboard[15], palette_rgb_pantscolormap[15], sizeof(*palette_rgb_pantscolormap));
2250 memcpy(palette_rgb_shirtscoreboard[15], palette_rgb_shirtcolormap[15], sizeof(*palette_rgb_shirtcolormap));
2253 if (vid_hidden || !scr_refresh.integer)
2256 rendertime1 = Sys_DoubleTime();
2258 conwidth = bound(320, vid_conwidth.value, 2048);
2259 conheight = bound(200, vid_conheight.value, 1536);
2260 if (vid_conwidth.value != conwidth)
2261 Cvar_SetValue("vid_conwidth", conwidth);
2262 if (vid_conheight.value != conheight)
2263 Cvar_SetValue("vid_conheight", conheight);
2266 if (scr_viewsize.value < 30)
2267 Cvar_Set ("viewsize","30");
2268 if (scr_viewsize.value > 120)
2269 Cvar_Set ("viewsize","120");
2271 // bound field of view
2272 if (scr_fov.value < 1)
2273 Cvar_Set ("fov","1");
2274 if (scr_fov.value > 170)
2275 Cvar_Set ("fov","170");
2277 // validate r_textureunits cvar
2278 if (r_textureunits.integer > gl_textureunits)
2279 Cvar_SetValueQuick(&r_textureunits, gl_textureunits);
2280 if (r_textureunits.integer < 1)
2281 Cvar_SetValueQuick(&r_textureunits, 1);
2283 // validate gl_combine cvar
2284 if (gl_combine.integer && !gl_combine_extension)
2285 Cvar_SetValueQuick(&gl_combine, 0);
2287 // intermission is always full screen
2288 if (cl.intermission)
2292 if (scr_viewsize.value >= 120)
2293 sb_lines = 0; // no status bar at all
2294 else if (scr_viewsize.value >= 110)
2295 sb_lines = 24; // no inventory
2300 r_refdef.view.colormask[0] = 1;
2301 r_refdef.view.colormask[1] = 1;
2302 r_refdef.view.colormask[2] = 1;
2304 SCR_SetUpToDrawConsole();
2307 qglDrawBuffer(GL_BACK);CHECKGLERROR
2308 qglViewport(0, 0, vid.width, vid.height);CHECKGLERROR
2309 qglDisable(GL_SCISSOR_TEST);CHECKGLERROR
2310 qglDepthMask(1);CHECKGLERROR
2311 qglColorMask(1,1,1,1);CHECKGLERROR
2312 qglClearColor(0,0,0,0);CHECKGLERROR
2313 R_ClearScreen(false);
2314 r_refdef.view.clear = false;
2315 r_refdef.view.isoverlay = false;
2316 r_refdef.view.quality = bound(cl_minfps_qualitymin.value, pow(cl_updatescreen_quality, cl_minfps_qualitypower.value) * cl_minfps_qualityscale.value, cl_minfps_qualitymax.value);
2318 if(scr_stipple.integer)
2320 GLubyte stipple[128];
2321 int i, s, width, parts;
2322 static int frame = 0;
2325 s = scr_stipple.integer;
2327 width = (s & 070) >> 3;
2329 qglEnable(GL_POLYGON_STIPPLE); // 0x0B42
2330 for(i = 0; i < 128; ++i)
2333 stipple[i] = (((line >> width) + frame) & ((1 << parts) - 1)) ? 0x00 : 0xFF;
2335 qglPolygonStipple(stipple);
2338 qglDisable(GL_POLYGON_STIPPLE);
2340 if (vid.stereobuffer || r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer || r_stereo_sidebyside.integer)
2342 matrix4x4_t originalmatrix = r_refdef.view.matrix;
2343 matrix4x4_t offsetmatrix;
2344 Matrix4x4_CreateFromQuakeEntity(&offsetmatrix, 0, r_stereo_separation.value * 0.5f, 0, 0, r_stereo_angle.value * 0.5f, 0, 1);
2345 Matrix4x4_Concat(&r_refdef.view.matrix, &originalmatrix, &offsetmatrix);
2347 if (r_stereo_sidebyside.integer)
2350 if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer)
2352 r_refdef.view.colormask[0] = 1;
2353 r_refdef.view.colormask[1] = 0;
2354 r_refdef.view.colormask[2] = 0;
2357 if (vid.stereobuffer)
2358 qglDrawBuffer(GL_BACK_RIGHT);
2362 Matrix4x4_CreateFromQuakeEntity(&offsetmatrix, 0, r_stereo_separation.value * -0.5f, 0, 0, r_stereo_angle.value * -0.5f, 0, 1);
2363 Matrix4x4_Concat(&r_refdef.view.matrix, &originalmatrix, &offsetmatrix);
2365 if (r_stereo_sidebyside.integer)
2368 if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer)
2370 r_refdef.view.colormask[0] = 0;
2371 r_refdef.view.colormask[1] = r_stereo_redcyan.integer || r_stereo_redgreen.integer;
2372 r_refdef.view.colormask[2] = r_stereo_redcyan.integer || r_stereo_redblue.integer;
2375 if (vid.stereobuffer)
2376 qglDrawBuffer(GL_BACK_LEFT);
2380 r_refdef.view.matrix = originalmatrix;
2387 // quality adjustment according to render time
2389 cl_updatescreen_rendertime += ((Sys_DoubleTime() - rendertime1) - cl_updatescreen_rendertime) * bound(0, cl_minfps_fade.value, 1);
2390 if (cl_minfps.value > 0 && cl_updatescreen_rendertime > 0 && !cls.timedemo && (!cls.capturevideo.active || !cls.capturevideo.realtime))
2391 cl_updatescreen_quality = 1 / (cl_updatescreen_rendertime * cl_minfps.value);
2393 cl_updatescreen_quality = 1;
2395 if (!vid_activewindow)
2396 VID_SetMouse(false, false, false);
2397 else if (key_consoleactive)
2398 VID_SetMouse(vid.fullscreen, false, false);
2399 else if (key_dest == key_menu_grabbed)
2400 VID_SetMouse(true, vid_mouse.integer && !in_client_mouse, true);
2401 else if (key_dest == key_menu)
2402 VID_SetMouse(vid.fullscreen, vid_mouse.integer && !in_client_mouse, true);
2404 VID_SetMouse(vid.fullscreen, vid_mouse.integer && !cl.csqc_wantsmousemove && (!cls.demoplayback || cl_demo_mousegrab.integer), true);
2409 void CL_Screen_NewMap(void)