UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
r_main.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 1997-2001 Id Software, Inc.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #define QGL_EXTERN
26 #include "r_gl.h"
27 #include "r_local.h"
28 #include "r_program.h"
29 #include "r_sphere.h"
30 #include "r_draw.h"
31 #include "r_font.h"
32 #include "r_light.h"
33 #include "r_lightmap.h"
34 #include "r_grass.h"
35 #include "r_weather.h"
36 #include "r_main.h"
37 #include "r_geoscape.h"
38 #include "r_misc.h"
39 #include "r_error.h"
40 #include "../../common/tracing.h"
41 #include "../ui/ui_windows.h"
42 #include "../../ports/system.h"
43 #include "../client.h"
44 
46 
50 
51 image_t* r_noTexture; /* use for bad textures */
53 image_t* r_dummyTexture; /* 1x1 pixel white texture to be used when texturing is required, but texture is not available */
54 
56 
58 
65 cvar_t* r_texture_lod; /* lod_bias */
111 
112 static void R_PrintInfo (const char* pre, const char* msg)
113 {
114  char buf[4096];
115  const size_t length = sizeof(buf);
116  const size_t maxLength = strlen(msg);
117 
118  Com_Printf("%s: ", pre);
119  for (int i = 0; i < maxLength; i += length) {
120  Q_strncpyz(buf, msg + i, sizeof(buf));
121  Com_Printf("%s", buf);
122  }
123  Com_Printf("\n");
124 }
125 
129 static void R_Strings_f (void)
130 {
131  R_PrintInfo("GL_VENDOR", r_config.vendorString);
132  R_PrintInfo("GL_RENDERER", r_config.rendererString);
133  R_PrintInfo("GL_VERSION", r_config.versionString);
134  R_PrintInfo("GL_EXTENSIONS", r_config.extensionsString);
135 }
136 
137 void R_SetupFrustum (void)
138 {
139  int i;
140 
141  /* build the transformation matrix for the given view angles */
142  AngleVectors(refdef.viewAngles, r_locals.forward, r_locals.right, r_locals.up);
143 
144 #if 0
145  /* if we are not drawing world model, we are on the UI code. It break the default UI SCISSOR
146  * Anyway we should merge that code into R_CleanupDepthBuffer (with some rework), it looks better */
147 
148  /* clear out the portion of the screen that the NOWORLDMODEL defines */
149  if (refdef.rendererFlags & RDF_NOWORLDMODEL) {
150  glEnable(GL_SCISSOR_TEST);
152  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
153  R_CheckError();
154  glDisable(GL_SCISSOR_TEST);
155  }
156 #endif
157  if (r_isometric->integer) {
158  /* 4 planes of a cube */
159  VectorScale(r_locals.right, +1, r_locals.frustum[0].normal);
160  VectorScale(r_locals.right, -1, r_locals.frustum[1].normal);
161  VectorScale(r_locals.up, +1, r_locals.frustum[2].normal);
162  VectorScale(r_locals.up, -1, r_locals.frustum[3].normal);
163 
164  for (i = 0; i < 4; i++) {
165  r_locals.frustum[i].type = PLANE_ANYZ;
166  r_locals.frustum[i].dist = DotProduct(refdef.viewOrigin, r_locals.frustum[i].normal);
167  }
168  r_locals.frustum[0].dist -= 10 * refdef.fieldOfViewX;
169  r_locals.frustum[1].dist -= 10 * refdef.fieldOfViewX;
170  r_locals.frustum[2].dist -= 10 * refdef.fieldOfViewX * ((float) viddef.viewHeight / viddef.viewWidth);
171  r_locals.frustum[3].dist -= 10 * refdef.fieldOfViewX * ((float) viddef.viewHeight / viddef.viewWidth);
172  } else {
173  /* rotate VPN right by FOV_X/2 degrees */
174  RotatePointAroundVector(r_locals.frustum[0].normal, r_locals.up, r_locals.forward, -(90 - refdef.fieldOfViewX / 2));
175  /* rotate VPN left by FOV_X/2 degrees */
176  RotatePointAroundVector(r_locals.frustum[1].normal, r_locals.up, r_locals.forward, 90 - refdef.fieldOfViewX / 2);
177  /* rotate VPN up by FOV_X/2 degrees */
178  RotatePointAroundVector(r_locals.frustum[2].normal, r_locals.right, r_locals.forward, 90 - refdef.fieldOfViewY / 2);
179  /* rotate VPN down by FOV_X/2 degrees */
180  RotatePointAroundVector(r_locals.frustum[3].normal, r_locals.right, r_locals.forward, -(90 - refdef.fieldOfViewY / 2));
181 
182  for (i = 0; i < 4; i++) {
183  r_locals.frustum[i].type = PLANE_ANYZ;
184  r_locals.frustum[i].dist = DotProduct(refdef.viewOrigin, r_locals.frustum[i].normal);
185  }
186  }
187 }
188 
192 static inline void R_Clear (void)
193 {
194  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
195  /* clear the stencil bit if shadows are enabled */
196  if (r_stencilshadows->integer)
197  glClear(GL_STENCIL_BUFFER_BIT);
198  R_CheckError();
199  glDepthFunc(GL_LEQUAL);
200  R_CheckError();
201 
202  glDepthRange(0.0f, 1.0f);
203  R_CheckError();
204 }
205 
209 static inline void R_ClearScene (void)
210 {
211  /* lights and coronas are populated as ents are added */
212  refdef.numEntities = refdef.numDynamicLights = refdef.numCoronas = 0;
213  R_ClearBspRRefs();
214 }
215 
220 void R_BeginFrame (void)
221 {
222  r_locals.frame++;
223 
224  /* avoid overflows, negatives and zero are reserved */
225  if (r_locals.frame > 0xffff)
226  r_locals.frame = 1;
227 
228  if (Com_IsRenderModified()) {
229  Com_Printf("Modified render related cvars\n");
232 
233  /* prevent reloading of some rendering cvars */
235  Com_SetRenderModified(false);
236  }
237 
238  if (r_anisotropic->modified) {
239  if (r_anisotropic->integer > r_config.maxAnisotropic) {
240  Com_Printf("...max GL_EXT_texture_filter_anisotropic value is %i\n", r_config.maxAnisotropic);
241  Cvar_SetValue("r_anisotropic", r_config.maxAnisotropic);
242  }
243  /*R_UpdateAnisotropy();*/
244  r_anisotropic->modified = false;
245  }
246 
247  /* draw buffer stuff */
248 #ifndef GL_VERSION_ES_CM_1_0
249  if (r_drawbuffer->modified) {
250  r_drawbuffer->modified = false;
251 
252  if (Q_strcasecmp(r_drawbuffer->string, "GL_FRONT") == 0)
253  glDrawBuffer(GL_FRONT);
254  else
255  glDrawBuffer(GL_BACK);
256  R_CheckError();
257  }
258 #endif
259 
260  /* texturemode stuff */
261  /* Realtime set level of anisotropy filtering and change texture lod bias */
262  if (r_texturemode->modified) {
263  R_TextureMode(r_texturemode->string);
264  r_texturemode->modified = false;
265  }
266 
267  if (r_texturealphamode->modified) {
268  R_TextureAlphaMode(r_texturealphamode->string);
269  r_texturealphamode->modified = false;
270  }
271 
272  if (r_texturesolidmode->modified) {
273  R_TextureSolidMode(r_texturesolidmode->string);
274  r_texturesolidmode->modified = false;
275  }
276 
277  /* threads */
278  if (r_threads->modified) {
279  if (r_threads->integer)
280  R_InitThreads();
281  else
283  r_threads->modified = false;
284  }
285 
286  R_EnableMultisample(true);
287 
288  R_Setup2D();
289 
290  /* clear screen if desired */
291  R_Clear();
292 }
293 
298 void R_RenderFrame (void)
299 {
300  static int lastFrame = 0;
301  int deltaMsec = cl.time - lastFrame;
302  lastFrame = cl.time;
303 
304  r_battlescapeWeather.update(deltaMsec); /* could do that in separate thread */
305 
306  R_Setup3D();
307 
308  /* activate wire mode */
309  if (r_wire->integer) {
310  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
311  }
312 
313  if (!(refdef.rendererFlags & RDF_NOWORLDMODEL)) {
314  int tile;
315  if (r_threads->integer) {
317  Sys_Sleep(0);
318 
320  } else {
321  R_SetupFrustum();
322 
323  /* draw brushes on current worldlevel */
325  }
326 
328 
329  R_CheckError();
330 
331  for (tile = 0; tile < r_numMapTiles; tile++) {
332  const model_t* mapTile = r_mapTiles[tile];
333  const mBspModel_t* bsp = &mapTile->bsp;
334 
335  R_AddBspRRef(bsp, vec3_origin, vec3_origin, false);
336  }
337 
339 
340  R_EnableFog(true);
341 
345 
347  R_DrawGrass();
348 
349  R_EnableBlend(true);
351 
352  R_EnableFog(false);
353 
357 
358  r_battlescapeWeather.render();
359 
360  R_EnableFog(true);
362  R_EnableFog(false);
363 
364  if (r_debug_lights->integer) {
365  int i;
366 
367  for (i = 0; i < refdef.numStaticLights; i++) {
368  const light_t* l = &refdef.staticLights[i];
369  R_AddCorona(l->origin, l->radius, l->color);
370  }
371  for (i = 0; i < refdef.numDynamicLights; i++) {
372  const light_t* l = &refdef.dynamicLights[i];
373  R_AddCorona(l->origin, l->radius, l->color);
374  }
375  }
376 
377  R_DrawCoronas();
378  R_EnableBlend(false);
379 
380  for (tile = 0; tile < r_numMapTiles; tile++) {
381  R_DrawBspNormals(tile);
382  }
383 
384  R_Color(nullptr);
388  } else {
389  glClear(GL_DEPTH_BUFFER_BIT);
390 
392 
397 
398  R_EnableBlend(true);
399 
401 
405 
407 
408  R_EnableBlend(false);
409 
410  R_Color(nullptr);
414  }
415 
416  R_EnableBlend(true);
417 
418  R_DrawParticles();
419 
420  R_EnableBlend(false);
421 
422  /* leave wire mode again */
423  if (r_wire->integer) {
424  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
425  }
426 
427  R_DrawBloom();
428 
430 
432 
433  /* go back into 2D mode for hud and the like */
434  R_Setup2D();
435 
436  R_CheckError();
437 }
438 
443 void R_EndFrame (void)
444 {
445  R_EnableBlend(true);
446 
447  R_DrawChars(); /* draw all chars accumulated above */
448 
449  /* restore draw color */
450  R_Color(nullptr);
451 
452  R_EnableBlend(false);
453 
454  if (vid_gamma->modified) {
455  if (!vid_ignoregamma->integer) {
456  const float g = vid_gamma->value;
457 #if SDL_VERSION_ATLEAST(2,0,0)
458  SDL_SetWindowBrightness(cls.window, g);
459 #else
460  SDL_SetGamma(g, g, g);
461 #endif
462  }
463  vid_gamma->modified = false;
464  }
465 
466  R_EnableMultisample(false);
467 
468  R_ClearScene();
469 
470 #if SDL_VERSION_ATLEAST(2,0,0)
471  SDL_GL_SwapWindow(cls.window);
472 #else
473  SDL_GL_SwapBuffers();
474 #endif
475 }
476 
477 static const cmdList_t r_commands[] = {
478  {"r_listimages", R_ImageList_f, "Show all loaded images on game console"},
479  {"r_listfontcache", R_FontListCache_f, "Show information about font cache"},
480  {"r_screenshot", R_ScreenShot_f, "Take a screenshot"},
481  {"r_listmodels", R_ModModellist_f, "Show all loaded models on game console"},
482  {"r_strings", R_Strings_f, "Print openGL vendor and other strings"},
483  {"r_restartprograms", R_RestartPrograms_f, "Reloads the shaders"},
484 
485  {nullptr, nullptr, nullptr}
486 };
487 
488 static bool R_CvarCheckMaxLightmap (cvar_t* cvar)
489 {
490  int maxSize = !r_config.maxTextureSize || LIGHTMAP_MAX_PAGE_SIZE < r_config.maxTextureSize ? LIGHTMAP_MAX_PAGE_SIZE : r_config.maxTextureSize;
491 
492  if (cvar->integer > maxSize) {
493  Com_Printf("%s exceeded max supported texture size\n", cvar->name);
494  Cvar_SetValue(cvar->name, maxSize);
495  return false;
496  }
497 
498  if (!Q_IsPowerOfTwo(cvar->integer)) {
499  Com_Printf("%s must be power of two\n", cvar->name);
501  return false;
502  }
503 
504  return Cvar_AssertValue(cvar, 128, LIGHTMAP_MAX_PAGE_SIZE, true);
505 }
506 
507 static bool R_CvarCheckDynamicLights (cvar_t* cvar)
508 {
509  float maxLights = r_config.maxLights;
510 
511  if (maxLights > MAX_ENTITY_LIGHTS)
512  maxLights = MAX_ENTITY_LIGHTS;
513 
514  return Cvar_AssertValue(cvar, 0, maxLights, true);
515 }
516 
517 static bool R_CvarPrograms (cvar_t* cvar)
518 {
519  if (qglUseProgram) {
520  return Cvar_AssertValue(cvar, 0, 3, true);
521  }
522 
523  Cvar_SetValue(cvar->name, 0);
524  return true;
525 }
526 
530 static bool R_CvarGLSLVersionCheck (cvar_t* cvar)
531 {
532  int glslVersionMajor, glslVersionMinor;
533  sscanf(cvar->string, "%d.%d", &glslVersionMajor, &glslVersionMinor);
534  if (glslVersionMajor > r_config.glslVersionMajor) {
535  Cvar_Reset(cvar);
536  return false;
537  }
538 
539  if (glslVersionMajor == r_config.glslVersionMajor && glslVersionMinor > r_config.glslVersionMinor) {
540  Cvar_Reset(cvar);
541  return false;
542  }
543 
544  return true;
545 }
546 
547 static bool R_CvarPostProcess (cvar_t* cvar)
548 {
549  if (r_config.frameBufferObject && r_config.drawBuffers)
550  return Cvar_AssertValue(cvar, 0, 1, true);
551 
552  Cvar_SetValue(cvar->name, 0);
553  return true;
554 }
555 
556 static bool R_CvarCheckMultisample (cvar_t* cvar)
557 {
558  return Cvar_AssertValue(cvar, 0, 4, true);
559 }
560 
561 static bool R_CvarCheckWeather (cvar_t* cvar)
562 {
563  return Cvar_AssertValue(cvar, (float)Weather::WEATHER_CLEAN, (float)Weather::WEATHER_MAX, true);
564 }
565 
566 static void R_UpdateWeather (const char* cvarName, const char* oldValue, const char* newValue, void* data)
567 {
568  r_battlescapeWeather.changeTo((Weather::weatherTypes)atoi(newValue));
569 }
570 
571 
572 static void R_RegisterSystemVars (void)
573 {
574  r_driver = Cvar_Get("r_driver", "", CVAR_ARCHIVE | CVAR_R_CONTEXT, "You can define the opengl driver you want to use - empty if you want to use the system default");
575  r_weather = Cvar_Get("r_weather", "0", 0, "Current battlescape weather effect");
578  r_drawentities = Cvar_Get("r_drawentities", "1", 0, "Draw the local entities");
579  r_drawworld = Cvar_Get("r_drawworld", "1", 0, "Draw the world brushes");
580  r_isometric = Cvar_Get("r_isometric", "0", CVAR_ARCHIVE, "Draw the world in isometric mode");
581  r_nocull = Cvar_Get("r_nocull", "0", 0, "Don't perform culling for brushes and entities");
582  r_anisotropic = Cvar_Get("r_anisotropic", "1", CVAR_ARCHIVE);
583  r_texture_lod = Cvar_Get("r_texture_lod", "0", CVAR_ARCHIVE);
584  r_screenshot_format = Cvar_Get("r_screenshot_format", "jpg", CVAR_ARCHIVE, "png, jpg or tga are valid screenshot formats");
585  r_screenshot_jpeg_quality = Cvar_Get("r_screenshot_jpeg_quality", "75", CVAR_ARCHIVE, "jpeg quality in percent for jpeg screenshots");
586  r_threads = Cvar_Get("r_threads", "0", CVAR_ARCHIVE, "Activate threads for the renderer");
587 
588  r_materials = Cvar_Get("r_materials", "1", CVAR_ARCHIVE, "Activate material subsystem");
589  r_overridematerial = Cvar_Get("r_overridematerial", "", 0, "Used to override the material for a map");
590  r_default_specular = Cvar_Get("r_default_specular", "0.2", CVAR_R_CONTEXT, "Default specular exponent");
591  r_default_hardness = Cvar_Get("r_default_hardness", "0.2", CVAR_R_CONTEXT, "Default specular brightness");
594  r_checkerror = Cvar_Get("r_checkerror", "0", CVAR_ARCHIVE, "Check for opengl errors");
595  r_shadows = Cvar_Get("r_shadows", "1", CVAR_ARCHIVE, "Multiplier for the alpha of the shadows");
596  r_stencilshadows = Cvar_Get("r_stencilshadows", "0", CVAR_ARCHIVE, "Activate or deactivate stencil shadows");
597  r_maxtexres = Cvar_Get("r_maxtexres", "2048", CVAR_ARCHIVE | CVAR_R_IMAGES, "The maximum texture resolution UFO should use");
598  r_texturemode = Cvar_Get("r_texturemode", "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE, "change the filtering and mipmapping for textures");
599  r_texturealphamode = Cvar_Get("r_texturealphamode", "GL_RGBA", CVAR_ARCHIVE);
600  r_texturesolidmode = Cvar_Get("r_texturesolidmode", "GL_RGB", CVAR_ARCHIVE);
601  r_wire = Cvar_Get("r_wire", "0", 0, "Draw the scene in wireframe mode");
602  r_showbox = Cvar_Get("r_showbox", "0", CVAR_ARCHIVE, "1=Shows model bounding box, 2=show also the brushes bounding boxes");
603  r_lightmap = Cvar_Get("r_lightmap", "0", CVAR_R_PROGRAMS, "Draw only the lightmap");
604  r_lightmap->modified = false;
605  r_deluxemap = Cvar_Get("r_deluxemap", "0", CVAR_R_PROGRAMS, "Draw only the deluxemap");
606  r_deluxemap->modified = false;
607  r_debug_normals = Cvar_Get("r_debug_normals", "0", CVAR_R_PROGRAMS, "Draw dot(normal, light_0 direction)");
608  r_debug_normals->modified = false;
609  r_debug_tangents = Cvar_Get("r_debug_tangents", "0", CVAR_R_PROGRAMS, "Draw tangent, bitangent, and normal dotted with light dir as RGB espectively");
610  r_debug_tangents->modified = false;
611  r_debug_lights = Cvar_Get("r_debug_lights", "0", CVAR_ARCHIVE, "Draw active light sources");
612  r_ext_texture_compression = Cvar_Get("r_ext_texture_compression", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT);
613  r_ext_nonpoweroftwo = Cvar_Get("r_ext_nonpoweroftwo", "1", CVAR_ARCHIVE, "Enable or disable the non power of two extension");
614  r_ext_s3tc_compression = Cvar_Get("r_ext_s3tc_compression", "1", CVAR_ARCHIVE, "Also see r_ext_texture_compression");
615  r_intel_hack = Cvar_Get("r_intel_hack", "1", CVAR_ARCHIVE, "Intel cards have no shaders until this is set to 0 - to it to a value > 1 to not limit the max texture resolution");
616  r_vertexbuffers = Cvar_Get("r_vertexbuffers", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Controls usage of OpenGL Vertex Buffer Objects (VBO) versus legacy vertex arrays.");
617  r_maxlightmap = Cvar_Get("r_maxlightmap", "2048", CVAR_ARCHIVE | CVAR_LATCH, "Reduce this value on older hardware");
619 
620  r_drawbuffer = Cvar_Get("r_drawbuffer", "GL_BACK");
621  r_swapinterval = Cvar_Get("r_swapinterval", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Controls swap interval synchronization (V-Sync). Values between 0 and 2");
622  r_multisample = Cvar_Get("r_multisample", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Controls multisampling (anti-aliasing). Values between 0 and 4");
624  r_warp = Cvar_Get("r_warp", "1", CVAR_ARCHIVE, "Activates or deactivates warping surface rendering");
625  r_shownormals = Cvar_Get("r_shownormals", "0", CVAR_ARCHIVE, "Show normals on bsp surfaces");
626  r_bumpmap = Cvar_Get("r_bumpmap", "1.0", CVAR_ARCHIVE | CVAR_R_PROGRAMS, "Activate bump mapping");
627  r_specular = Cvar_Get("r_specular", "1.0", CVAR_ARCHIVE, "Controls specular parameters");
628  r_hardness = Cvar_Get("r_hardness", "1.0", CVAR_ARCHIVE, "Hardness control for GLSL shaders (specular, bump, ...)");
629  r_parallax = Cvar_Get("r_parallax", "1.0", CVAR_ARCHIVE, "Controls parallax parameters");
630  r_fog = Cvar_Get("r_fog", "1", CVAR_ARCHIVE | CVAR_R_PROGRAMS, "Activate or deactivate fog");
631  r_flares = Cvar_Get("r_flares", "1", CVAR_ARCHIVE, "Activate or deactivate flares");
632  r_coronas = Cvar_Get("r_coronas", "1", CVAR_ARCHIVE, "Activate or deactivate coronas");
633  r_particles = Cvar_Get("r_particles", "1", 0, "Activate or deactivate particle rendering");
634  r_drawtags = Cvar_Get("r_drawtags", "0", 0, "Activate or deactivate tag rendering");
635 
636  Cmd_TableAddList(r_commands);
637 }
638 
642 static void R_RegisterImageVars (void)
643 {
644 }
645 
651 static void R_UpdateVidDef (const viddefContext_t* context)
652 {
653  viddef.context = *context;
654 
655  /* update cvars */
656  Cvar_SetValue("vid_width", viddef.context.width);
657  Cvar_SetValue("vid_height", viddef.context.height);
658  Cvar_SetValue("vid_mode", viddef.context.mode);
659  Cvar_SetValue("vid_fullscreen", viddef.context.fullscreen);
660  Cvar_SetValue("r_multisample", viddef.context.multisample);
661  Cvar_SetValue("r_swapinterval", viddef.context.swapinterval);
662  vid_stretch->modified = false;
663  vid_fullscreen->modified = false;
664  vid_mode->modified = false;
665  r_multisample->modified = false;
666  r_swapinterval->modified = false;
667 
668  /* update cache values */
669  if (viddef.stretch) {
672  } else {
673  float normRatio = (float) VID_NORM_WIDTH / (float) VID_NORM_HEIGHT;
674  float screenRatio = (float) viddef.context.width / (float) viddef.context.height;
675 
676  /* wide screen */
677  if (screenRatio > normRatio) {
678  viddef.virtualWidth = VID_NORM_HEIGHT * screenRatio;
680  /* 5:4 or low */
681  } else if (screenRatio < normRatio) {
683  viddef.virtualHeight = VID_NORM_WIDTH / screenRatio;
684  /* 4:3 */
685  } else {
688  }
689  }
692 }
693 
694 bool R_SetMode (void)
695 {
696  bool result;
697  viddefContext_t prevCtx;
698  viddefContext_t newCtx;
699  vidmode_t vidmode;
700 
701  Com_Printf("I: setting mode %d\n", vid_mode->integer);
702 
703  /* not values we must restitute */
704  r_ext_texture_compression->modified = false;
706 
707  /* store old values if new ones will fail */
708  prevCtx = viddef.context;
709 
710  /* new values */
711  newCtx = viddef.context;
712  newCtx.mode = vid_mode->integer;
714  newCtx.multisample = r_multisample->integer;
715  newCtx.swapinterval = r_swapinterval->integer;
716  if (!VID_GetModeInfo(newCtx.mode, &vidmode)) {
717  Com_Printf("I: invalid mode\n");
718  Cvar_Set("vid_mode", "-1");
719  Cvar_Set("vid_width", "-1");
720  Cvar_Set("vid_height", "-1");
721  return false;
722  }
723  Com_Printf("I: try to get display with %ix%i\n", vidmode.width, vidmode.height);
724  newCtx.width = vidmode.width;
725  newCtx.height = vidmode.height;
726  result = R_InitGraphics(&newCtx);
727  if (!result) {
728  /* failed, revert */
729  Com_Printf("Failed to set video mode %dx%d %s.\n",
730  newCtx.width, newCtx.height,
731  (newCtx.fullscreen ? "fullscreen" : "windowed"));
732  result = R_InitGraphics(&prevCtx);
733  if (!result)
734  return false;
735  newCtx = prevCtx;
736  }
737 
738  R_UpdateVidDef(&newCtx);
740  R_InitFBObjects();
742  Com_Printf("I: %dx%d (fullscreen: %s)\n", viddef.context.width, viddef.context.height, viddef.context.fullscreen ? "yes" : "no");
743  return true;
744 }
745 
752 static inline uintptr_t R_GetProcAddress (const char* functionName)
753 {
754  return (uintptr_t)SDL_GL_GetProcAddress(functionName);
755 }
756 
757 static uintptr_t R_GetProcAddressExt (const char* functionName)
758 {
759  const char* s = strstr(functionName, "###");
760  if (s == nullptr) {
761  return R_GetProcAddress(functionName);
762  }
763 
764  const char* replace[] = {"EXT", "OES", "ARB"};
765  char targetBuf[128];
766  const size_t length = lengthof(targetBuf);
767  const size_t replaceNo = lengthof(replace);
768  for (size_t i = 0; i < replaceNo; i++) {
769  if (Q_strreplace(functionName, "###", replace[i], targetBuf, length)) {
770  uintptr_t funcAdr = R_GetProcAddress(targetBuf);
771  if (funcAdr != 0)
772  return funcAdr;
773  }
774  }
775  Com_Printf("%s not found\n", functionName);
776  return 0;
777 }
778 
787 static inline bool R_CheckExtension (const char* extension)
788 {
789  bool found;
790 #ifdef GL_VERSION_ES_CM_1_0
791  if(strcmp(extension, "GL_ARB_texture_non_power_of_two") == 0) {
792  extension = "GL_OES_texture_npot";
793  }
794 #endif
795  const char* s = strstr(extension, "###");
796  if (s == nullptr) {
797  found = strstr(r_config.extensionsString, extension) != nullptr;
798  } else {
799  const char* replace[] = {"ARB", "EXT", "OES"};
800  char targetBuf[128];
801  const size_t length = lengthof(targetBuf);
802  const size_t replaceNo = lengthof(replace);
803  size_t i;
804  for (i = 0; i < replaceNo; i++) {
805  if (Q_strreplace(extension, "###", replace[i], targetBuf, length)) {
806  if (strstr(r_config.extensionsString, targetBuf) != nullptr) {
807  found = true;
808  break;
809  }
810  }
811  }
812  if (i == replaceNo)
813  found = false;
814  }
815 
816  if (found)
817  Com_Printf("found %s\n", extension);
818  else
819  Com_Printf("%s not found\n", extension);
820 
821 #ifdef GL_VERSION_ES_CM_1_0
822  if (strcmp(extension, "GL_ARB_multitexture") == 0 ||
823  strcmp(extension, "GL_ARB_vertex_buffer_object") == 0) {
824  found = true;
825  Com_Printf("Overriding %s - it is always present in GLES\n", extension);
826  }
827 #endif
828 
829  return found;
830 }
831 
832 #define R_CheckGLVersion(max, min) (r_config.glVersionMajor > max || (r_config.glVersionMajor == max && r_config.glVersionMinor >= min))
833 
838 static void R_InitExtensions (void)
839 {
840  GLenum err;
841  int tmpInteger;
842 
843  /* Get OpenGL version.*/
844  if(sscanf(r_config.versionString, "%d.%d", &r_config.glVersionMajor, &r_config.glVersionMinor) != 2) {
845  const char* versionNumbers = r_config.versionString; /* GLES reports version as "OpenGL ES 1.1", so we must skip non-numeric symbols first */
846  while(*versionNumbers && strchr("0123456789", *versionNumbers) == nullptr) {
847  versionNumbers ++;
848  }
849  if( *versionNumbers )
850  sscanf(versionNumbers, "%d.%d", &r_config.glVersionMajor, &r_config.glVersionMinor);
851  }
852  Com_Printf("OpenGL version detected: %d.%d\n", r_config.glVersionMajor, r_config.glVersionMinor);
853 
854  /* multitexture */
855  qglActiveTexture = nullptr;
856  qglClientActiveTexture = nullptr;
857 
858  /* vertex buffer */
859  qglGenBuffers = nullptr;
860  qglDeleteBuffers = nullptr;
861  qglBindBuffer = nullptr;
862  qglBufferData = nullptr;
863 
864  /* glsl */
865  qglCreateShader = nullptr;
866  qglDeleteShader = nullptr;
867  qglShaderSource = nullptr;
868  qglCompileShader = nullptr;
869  qglGetShaderiv = nullptr;
870  qglGetShaderInfoLog = nullptr;
871  qglCreateProgram = nullptr;
872  qglDeleteProgram = nullptr;
873  qglAttachShader = nullptr;
874  qglDetachShader = nullptr;
875  qglLinkProgram = nullptr;
876  qglUseProgram = nullptr;
877  qglGetActiveUniform = nullptr;
878  qglGetProgramiv = nullptr;
879  qglGetProgramInfoLog = nullptr;
880  qglGetUniformLocation = nullptr;
881  qglUniform1i = nullptr;
882  qglUniform1f = nullptr;
883  qglUniform1fv = nullptr;
884  qglUniform2fv = nullptr;
885  qglUniform3fv = nullptr;
886  qglUniform4fv = nullptr;
887  qglGetAttribLocation = nullptr;
888  qglUniformMatrix4fv = nullptr;
889 
890  /* vertex attribute arrays */
891  qglEnableVertexAttribArray = nullptr;
892  qglDisableVertexAttribArray = nullptr;
893  qglVertexAttribPointer = nullptr;
894 
895  /* framebuffer objects */
896  qglIsRenderbufferEXT = nullptr;
897  qglBindRenderbufferEXT = nullptr;
898  qglDeleteRenderbuffersEXT = nullptr;
899  qglGenRenderbuffersEXT = nullptr;
900  qglRenderbufferStorageEXT = nullptr;
901  qglRenderbufferStorageMultisampleEXT = nullptr;
902  qglGetRenderbufferParameterivEXT = nullptr;
903  qglIsFramebufferEXT = nullptr;
904  qglBindFramebufferEXT = nullptr;
905  qglDeleteFramebuffersEXT = nullptr;
906  qglGenFramebuffersEXT = nullptr;
907  qglCheckFramebufferStatusEXT = nullptr;
908  qglFramebufferTexture1DEXT = nullptr;
909  qglFramebufferTexture2DEXT = nullptr;
910  qglFramebufferTexture3DEXT = nullptr;
911  qglFramebufferRenderbufferEXT = nullptr;
912  qglGetFramebufferAttachmentParameterivEXT = nullptr;
913  qglGenerateMipmapEXT = nullptr;
914  qglDrawBuffers = nullptr;
915 
916  /* multitexture */
917  if (R_CheckExtension("GL_ARB_multitexture")) {
918  qglActiveTexture = (ActiveTexture_t)R_GetProcAddress("glActiveTexture");
919  qglClientActiveTexture = (ClientActiveTexture_t)R_GetProcAddress("glClientActiveTexture");
920  }
921 
922 #ifndef GL_VERSION_ES_CM_1_0
923  if (R_CheckExtension("GL_ARB_texture_compression")) {
924  if (r_ext_texture_compression->integer) {
925  Com_Printf("using GL_ARB_texture_compression\n");
926  if (r_ext_s3tc_compression->integer && strstr(r_config.extensionsString, "GL_EXT_texture_compression_s3tc")) {
927  r_config.gl_compressed_solid_format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
928  r_config.gl_compressed_alpha_format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
929  } else {
930  r_config.gl_compressed_solid_format = GL_COMPRESSED_RGB_ARB;
931  r_config.gl_compressed_alpha_format = GL_COMPRESSED_RGBA_ARB;
932  }
933  }
934  }
935 #endif
936 
937  if (R_CheckExtension("GL_ARB_texture_non_power_of_two")) {
938  if (r_ext_nonpoweroftwo->integer) {
939  Com_Printf("using GL_ARB_texture_non_power_of_two\n");
940  r_config.nonPowerOfTwo = true;
941  } else {
942  r_config.nonPowerOfTwo = false;
943  Com_Printf("ignoring GL_ARB_texture_non_power_of_two\n");
944  }
945  } else {
946  if (R_CheckGLVersion(2, 0)) {
947  r_config.nonPowerOfTwo = r_ext_nonpoweroftwo->integer == 1;
948  } else {
949  r_config.nonPowerOfTwo = false;
950  }
951  }
952 
953  /* anisotropy */
954  if (R_CheckExtension("GL_EXT_texture_filter_anisotropic")) {
955  if (r_anisotropic->integer) {
956  glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &r_config.maxAnisotropic);
957  R_CheckError();
958  if (r_anisotropic->integer > r_config.maxAnisotropic) {
959  Com_Printf("max GL_EXT_texture_filter_anisotropic value is %i\n", r_config.maxAnisotropic);
960  Cvar_SetValue("r_anisotropic", r_config.maxAnisotropic);
961  }
962 
963  if (r_config.maxAnisotropic)
964  r_config.anisotropic = true;
965  }
966  }
967 
968  if (R_CheckExtension("GL_EXT_texture_lod_bias"))
969  r_config.lod_bias = true;
970 
971  /* vertex buffer objects */
972  if (R_CheckExtension("GL_ARB_vertex_buffer_object")) {
973  qglGenBuffers = (GenBuffers_t)R_GetProcAddress("glGenBuffers");
974  qglDeleteBuffers = (DeleteBuffers_t)R_GetProcAddress("glDeleteBuffers");
975  qglBindBuffer = (BindBuffer_t)R_GetProcAddress("glBindBuffer");
976  qglBufferData = (BufferData_t)R_GetProcAddress("glBufferData");
977  r_config.maxVertexBufferSize = 256 * 256 * 256; // This is only recommended value, so we don't really care about it, and set some big number.
978 #ifndef GL_VERSION_ES_CM_1_0
979  glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &r_config.maxVertexBufferSize);
980 #endif
981  Com_Printf("using GL_ARB_vertex_buffer_object\nmax vertex buffer size: %i\n", r_config.maxVertexBufferSize);
982  }
983 
984  /* glsl vertex and fragment shaders and programs */
985  if (R_CheckExtension("GL_ARB_fragment_shader")) {
986  qglCreateShader = (CreateShader_t)R_GetProcAddress("glCreateShader");
987  qglDeleteShader = (DeleteShader_t)R_GetProcAddress("glDeleteShader");
988  qglShaderSource = (ShaderSource_t)R_GetProcAddress("glShaderSource");
989  qglCompileShader = (CompileShader_t)R_GetProcAddress("glCompileShader");
990  qglGetShaderiv = (GetShaderiv_t)R_GetProcAddress("glGetShaderiv");
991  qglGetShaderInfoLog = (GetShaderInfoLog_t)R_GetProcAddress("glGetShaderInfoLog");
992  qglCreateProgram = (CreateProgram_t)R_GetProcAddress("glCreateProgram");
993  qglDeleteProgram = (DeleteProgram_t)R_GetProcAddress("glDeleteProgram");
994  qglAttachShader = (AttachShader_t)R_GetProcAddress("glAttachShader");
995  qglDetachShader = (DetachShader_t)R_GetProcAddress("glDetachShader");
996  qglLinkProgram = (LinkProgram_t)R_GetProcAddress("glLinkProgram");
997  qglUseProgram = (UseProgram_t)R_GetProcAddress("glUseProgram");
998  qglGetActiveUniform = (GetActiveUniforms_t)R_GetProcAddress("glGetActiveUniform");
999  qglGetProgramiv = (GetProgramiv_t)R_GetProcAddress("glGetProgramiv");
1000  qglGetProgramInfoLog = (GetProgramInfoLog_t)R_GetProcAddress("glGetProgramInfoLog");
1001  qglGetUniformLocation = (GetUniformLocation_t)R_GetProcAddress("glGetUniformLocation");
1002  qglUniform1i = (Uniform1i_t)R_GetProcAddress("glUniform1i");
1003  qglUniform1f = (Uniform1f_t)R_GetProcAddress("glUniform1f");
1004  qglUniform1fv = (Uniform1fv_t)R_GetProcAddress("glUniform1fv");
1005  qglUniform2fv = (Uniform2fv_t)R_GetProcAddress("glUniform2fv");
1006  qglUniform3fv = (Uniform3fv_t)R_GetProcAddress("glUniform3fv");
1007  qglUniform4fv = (Uniform4fv_t)R_GetProcAddress("glUniform4fv");
1008  qglGetAttribLocation = (GetAttribLocation_t)R_GetProcAddress("glGetAttribLocation");
1009  qglUniformMatrix4fv = (UniformMatrix4fv_t)R_GetProcAddress("glUniformMatrix4fv");
1010 
1011  /* vertex attribute arrays */
1012  qglEnableVertexAttribArray = (EnableVertexAttribArray_t)R_GetProcAddress("glEnableVertexAttribArray");
1013  qglDisableVertexAttribArray = (DisableVertexAttribArray_t)R_GetProcAddress("glDisableVertexAttribArray");
1014  qglVertexAttribPointer = (VertexAttribPointer_t)R_GetProcAddress("glVertexAttribPointer");
1015  }
1016 
1017  if (R_CheckExtension("GL_ARB_shading_language_100") || r_config.glVersionMajor >= 2) {
1018  /* The GL_ARB_shading_language_100 extension was added to core specification since OpenGL 2.0;
1019  * it is ideally listed in the extensions for backwards compatibility. If it isn't there and OpenGL > v2.0
1020  * then enable shaders as the implementation supports the shading language!*/
1021  const char* shadingVersion = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
1022  sscanf(shadingVersion, "%d.%d", &r_config.glslVersionMajor, &r_config.glslVersionMinor);
1023  Com_Printf("GLSL version guaranteed to be supported by OpenGL implementation postfixed by vender supplied info: %i.%i\n",
1024  r_config.glslVersionMajor, r_config.glslVersionMinor);
1025  } else {
1026  /* The shading language is not supported.*/
1027  Com_Printf("GLSL shaders unsupported by OpenGL implementation.\n");
1028  }
1029 
1030  /* framebuffer objects */
1031  if (R_CheckExtension("GL_###_framebuffer_object")) {
1032  qglIsRenderbufferEXT = (IsRenderbufferEXT_t)R_GetProcAddressExt("glIsRenderbuffer###");
1033  qglBindRenderbufferEXT = (BindRenderbufferEXT_t)R_GetProcAddressExt("glBindRenderbuffer###");
1034  qglDeleteRenderbuffersEXT = (DeleteRenderbuffersEXT_t)R_GetProcAddressExt("glDeleteRenderbuffers###");
1035  qglGenRenderbuffersEXT = (GenRenderbuffersEXT_t)R_GetProcAddressExt("glGenRenderbuffers###");
1036  qglRenderbufferStorageEXT = (RenderbufferStorageEXT_t)R_GetProcAddressExt("glRenderbufferStorage###");
1037  qglRenderbufferStorageMultisampleEXT = (RenderbufferStorageMultisampleEXT_t)R_GetProcAddressExt("glRenderbufferStorageMultisample###");
1038  qglGetRenderbufferParameterivEXT = (GetRenderbufferParameterivEXT_t)R_GetProcAddressExt("glGetRenderbufferParameteriv###");
1039  qglIsFramebufferEXT = (IsFramebufferEXT_t)R_GetProcAddressExt("glIsFramebuffer###");
1040  qglBindFramebufferEXT = (BindFramebufferEXT_t)R_GetProcAddressExt("glBindFramebuffer###");
1041  qglDeleteFramebuffersEXT = (DeleteFramebuffersEXT_t)R_GetProcAddressExt("glDeleteFramebuffers###");
1042  qglGenFramebuffersEXT = (GenFramebuffersEXT_t)R_GetProcAddressExt("glGenFramebuffers###");
1043  qglCheckFramebufferStatusEXT = (CheckFramebufferStatusEXT_t)R_GetProcAddressExt("glCheckFramebufferStatus###");
1044  qglFramebufferTexture1DEXT = (FramebufferTexture1DEXT_t)R_GetProcAddressExt("glFramebufferTexture1D###");
1045  qglFramebufferTexture2DEXT = (FramebufferTexture2DEXT_t)R_GetProcAddressExt("glFramebufferTexture2D###");
1046  qglFramebufferTexture3DEXT = (FramebufferTexture3DEXT_t)R_GetProcAddressExt("glFramebufferTexture3D###");
1047  qglFramebufferRenderbufferEXT = (FramebufferRenderbufferEXT_t)R_GetProcAddressExt("glFramebufferRenderbuffer###");
1048  qglGetFramebufferAttachmentParameterivEXT = (GetFramebufferAttachmentParameterivEXT_t)R_GetProcAddressExt("glGetFramebufferAttachmentParameteriv###");
1049  qglGenerateMipmapEXT = (GenerateMipmapEXT_t)R_GetProcAddressExt("glGenerateMipmap###");
1050  qglDrawBuffers = (DrawBuffers_t)R_GetProcAddress("glDrawBuffers");
1051  qglBlitFramebuffer = (BlitFramebuffer_t)R_GetProcAddress("glBlitFramebuffer");
1052 
1053  if (qglDeleteRenderbuffersEXT && qglDeleteFramebuffersEXT && qglGenFramebuffersEXT && qglBindFramebufferEXT
1054  && qglFramebufferTexture2DEXT && qglBindRenderbufferEXT && qglRenderbufferStorageEXT && qglCheckFramebufferStatusEXT) {
1055 #ifdef GL_VERSION_ES_CM_1_0
1056  r_config.maxDrawBuffers = 1; /* GLES does not support multiple buffers or color attachments, only COLOR_ATTACHMENT0_OES is available */
1057  r_config.maxColorAttachments = 1;
1058 #else
1059  glGetIntegerv(GL_MAX_DRAW_BUFFERS, &r_config.maxDrawBuffers);
1060  glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &r_config.maxColorAttachments);
1061 #endif
1062  glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &r_config.maxRenderbufferSize);
1063 
1064  r_config.frameBufferObject = true;
1065 
1066  Com_Printf("using GL_ARB_framebuffer_object\n");
1067  Com_Printf("max draw buffers: %i\n", r_config.maxDrawBuffers);
1068  Com_Printf("max render buffer size: %i\n", r_config.maxRenderbufferSize);
1069  Com_Printf("max color attachments: %i\n", r_config.maxColorAttachments);
1070  } else {
1071  Com_Printf("skipping GL_ARB_framebuffer_object - not every needed extension is supported\n");
1072  }
1073 
1074  if (r_config.maxDrawBuffers > 1 && R_CheckExtension("GL_###_draw_buffers")) {
1075  Com_Printf("using GL_ARB_draw_buffers\n");
1076  r_config.drawBuffers = true;
1077  } else {
1078  r_config.drawBuffers = false;
1079  }
1080  } else {
1081  Com_Printf("Framebuffer objects unsupported by OpenGL implementation.\n");
1082  }
1083 
1084  r_programs = Cvar_Get("r_programs", "1", CVAR_ARCHIVE | CVAR_R_PROGRAMS, "GLSL shaders level: 0 - disabled, 1 - low, 2 - medium, 3 - high");
1085  r_programs->modified = false;
1086  Cvar_SetCheckFunction("r_programs", R_CvarPrograms);
1087 
1088  r_glsl_version = Cvar_Get("r_glsl_version", "1.10", CVAR_ARCHIVE | CVAR_R_PROGRAMS, "GLSL Version");
1089  Cvar_SetCheckFunction("r_glsl_version", R_CvarGLSLVersionCheck);
1090 
1091  r_postprocess = Cvar_Get("r_postprocess", "1", CVAR_ARCHIVE | CVAR_R_PROGRAMS, "Activate postprocessing shader effects");
1092  Cvar_SetCheckFunction("r_postprocess", R_CvarPostProcess);
1093 
1094  /* reset gl error state */
1095  R_CheckError();
1096 
1098  Com_Printf("max supported vertex texture units: %i\n", r_config.maxVertexTextureImageUnits);
1099 
1100  glGetIntegerv(GL_MAX_LIGHTS, &r_config.maxLights);
1101  Com_Printf("max supported lights: %i\n", r_config.maxLights);
1102 
1103  r_dynamic_lights = Cvar_Get("r_dynamic_lights", "1", CVAR_ARCHIVE | CVAR_R_PROGRAMS, "Sets max number of GL lightsources to use in shaders");
1104  Cvar_SetCheckFunction("r_dynamic_lights", R_CvarCheckDynamicLights);
1105 
1106  glGetIntegerv(GL_MAX_TEXTURE_UNITS, &r_config.maxTextureUnits);
1107  Com_Printf("max texture units: %i\n", r_config.maxTextureUnits);
1108  if (r_config.maxTextureUnits < 2)
1109  Com_Error(ERR_FATAL, "You need at least 2 texture units to run " GAME_TITLE);
1110 
1111  glGetIntegerv(GL_MAX_TEXTURE_COORDS, &r_config.maxTextureCoords);
1112  Com_Printf("max texture coords: %i\n", r_config.maxTextureCoords);
1113  r_config.maxTextureCoords = std::max(r_config.maxTextureUnits, r_config.maxTextureCoords);
1114 
1115  glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &r_config.maxVertexAttribs);
1116  Com_Printf("max vertex attributes: %i\n", r_config.maxVertexAttribs);
1117 
1118 #ifdef GL_VERSION_ES_CM_1_0
1119  glGetIntegerv(GL_MAX_VARYING_VECTORS, &tmpInteger);
1120  Com_Printf("max varying floats: %i\n", tmpInteger * 4);
1121  glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &tmpInteger);
1122  Com_Printf("max fragment uniform components: %i\n", tmpInteger * 4);
1123  glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &tmpInteger);
1124  Com_Printf("max vertex uniform components: %i\n", tmpInteger * 4);
1125 #else
1126  glGetIntegerv(GL_MAX_VARYING_FLOATS, &tmpInteger);
1127  Com_Printf("max varying floats: %i\n", tmpInteger);
1128  glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &tmpInteger);
1129  Com_Printf("max fragment uniform components: %i\n", tmpInteger);
1130  glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &tmpInteger);
1131  Com_Printf("max vertex uniform components: %i\n", tmpInteger);
1132 #endif
1133 
1134  /* reset gl error state */
1135  R_CheckError();
1136 
1137  /* check max texture size */
1138  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &r_config.maxTextureSize);
1139  /* stubbed or broken drivers may have reported 0 */
1140  if (r_config.maxTextureSize <= 0)
1141  r_config.maxTextureSize = 256;
1142 
1143  if ((err = glGetError()) != GL_NO_ERROR) {
1144  Com_Printf("max texture size: cannot detect - using %i! (%s)\n", r_config.maxTextureSize, R_TranslateError(err));
1145  Cvar_SetValue("r_maxtexres", r_config.maxTextureSize);
1146  } else {
1147  Com_Printf("max texture size: detected %d\n", r_config.maxTextureSize);
1148  if (r_maxtexres->integer > r_config.maxTextureSize) {
1149  Com_Printf("...downgrading from %i\n", r_maxtexres->integer);
1150  Cvar_SetValue("r_maxtexres", r_config.maxTextureSize);
1151  /* check for a minimum */
1152  } else if (r_maxtexres->integer >= 128 && r_maxtexres->integer < r_config.maxTextureSize) {
1153  Com_Printf("...but using %i as requested\n", r_maxtexres->integer);
1154  r_config.maxTextureSize = r_maxtexres->integer;
1155  }
1156  }
1157 
1158  if (r_config.maxTextureSize > 4096 && R_ImageExists("pics/geoscape/%s/map_earth_season_00", "high")) {
1159  Q_strncpyz(r_config.lodDir, "high", sizeof(r_config.lodDir));
1160  Com_Printf("Using high resolution globe textures as requested.\n");
1161  } else if (r_config.maxTextureSize > 2048 && R_ImageExists("pics/geoscape/med/map_earth_season_00")) {
1162  if (r_config.maxTextureSize > 4096) {
1163  Com_Printf("Warning: high resolution globe textures requested, but could not be found; falling back to medium resolution globe textures.\n");
1164  } else {
1165  Com_Printf("Using medium resolution globe textures as requested.\n");
1166  }
1167  Q_strncpyz(r_config.lodDir, "med", sizeof(r_config.lodDir));
1168  } else {
1169  if (r_config.maxTextureSize > 2048) {
1170  Com_Printf("Warning: medium resolution globe textures requested, but could not be found; falling back to low resolution globe textures.\n");
1171  } else {
1172  Com_Printf("Using low resolution globe textures as requested.\n");
1173  }
1174  Q_strncpyz(r_config.lodDir, "low", sizeof(r_config.lodDir));
1175  }
1176 }
1177 
1181 static inline void R_EnforceVersion (void)
1182 {
1183  int maj, min, rel;
1184 
1185  sscanf(r_config.versionString, "%d.%d.%d ", &maj, &min, &rel);
1186 
1187 #ifndef GL_VERSION_ES_CM_1_0
1188  if (maj > 1)
1189  return;
1190 
1191  if (maj < 1)
1192  Com_Error(ERR_FATAL, "OpenGL version %s is less than 1.2.1", r_config.versionString);
1193 
1194  if (min > 2)
1195  return;
1196 
1197  if (min < 2)
1198  Com_Error(ERR_FATAL, "OpenGL Version %s is less than 1.2.1", r_config.versionString);
1199 
1200  if (rel > 1)
1201  return;
1202 
1203  if (rel < 1)
1204  Com_Error(ERR_FATAL, "OpenGL version %s is less than 1.2.1", r_config.versionString);
1205 #endif
1206 }
1207 
1211 static bool R_SearchForVendor (const char* vendor)
1212 {
1213  return Q_stristr(r_config.vendorString, vendor)
1214  || Q_stristr(r_config.rendererString, vendor);
1215 }
1216 
1217 #define INTEL_TEXTURE_RESOLUTION 1024
1218 
1222 static inline void R_VerifyDriver (void)
1223 {
1224 #ifdef _WIN32
1225  if (!Q_strcasecmp((const char*)glGetString(GL_RENDERER), "gdi generic"))
1226  Com_Error(ERR_FATAL, "No hardware acceleration detected.\n"
1227  "Update your graphic card drivers.");
1228 #else
1229  if (!Q_strcasecmp((const char*)glGetString(GL_RENDERER), "Software Rasterizer"))
1230  Com_Error(ERR_FATAL, "No hardware acceleration detected.\n"
1231  "Update your graphic card drivers.");
1232 #endif
1233  if (R_SearchForVendor("Intel")) {
1234  Com_Printf("You might want to activate texture compression if you have visual artifacts.\n");
1235  if (r_intel_hack->integer) {
1236  /* HACK: */
1237  Com_Printf("Disabling shaders for Intel chips - see cvar r_intel_hack\n");
1238  Cvar_Set("r_programs", "0");
1239  if (r_intel_hack->integer == 1) {
1240  if (r_maxtexres->integer > INTEL_TEXTURE_RESOLUTION) {
1241  Com_Printf("Set max. texture resolution to %i - see cvar r_intel_hack\n", INTEL_TEXTURE_RESOLUTION);
1242  Cvar_SetValue("r_maxtexres", INTEL_TEXTURE_RESOLUTION);
1243  }
1244  }
1245  }
1246  r_config.hardwareType = GLHW_INTEL;
1247  } else if (R_SearchForVendor("NVIDIA")) {
1248  r_config.hardwareType = GLHW_NVIDIA;
1249  } else if (R_SearchForVendor("ATI") || R_SearchForVendor("Advanced Micro Devices") || R_SearchForVendor("AMD")) {
1250  r_config.hardwareType = GLHW_ATI;
1251  } else if (R_SearchForVendor("mesa") || R_SearchForVendor("gallium") || R_SearchForVendor("nouveau")) {
1252  r_config.hardwareType = GLHW_MESA;
1253  } else {
1254  r_config.hardwareType = GLHW_GENERIC;
1255  }
1256  /* disable intel hack for non intel cards */
1257  if (!R_SearchForVendor("Intel")) {
1258  Cvar_Set("r_intel_hack", "0");
1259  Cvar_Set("r_vendor_non_intel", "1");
1260  }
1261 }
1262 
1263 bool R_Init (void)
1264 {
1266 
1267  OBJZERO(r_state);
1268  OBJZERO(r_locals);
1269  OBJZERO(r_config);
1270 
1271  /* some config default values */
1272  r_config.gl_solid_format = GL_RGB;
1273  r_config.gl_alpha_format = GL_RGBA;
1274  r_config.gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
1275  r_config.gl_filter_max = GL_LINEAR;
1276  r_config.maxTextureSize = 256;
1277 
1278  /* initialize OS-specific parts of OpenGL */
1279  if (!Rimp_Init())
1280  return false;
1281 
1282  /* get our various GL strings */
1283  r_config.vendorString = (const char*)glGetString(GL_VENDOR);
1284  r_config.rendererString = (const char*)glGetString(GL_RENDERER);
1285  r_config.versionString = (const char*)glGetString(GL_VERSION);
1286  r_config.extensionsString = (const char*)glGetString(GL_EXTENSIONS);
1287  R_Strings_f();
1288 
1289  /* sanity checks and card specific hacks */
1290  R_VerifyDriver();
1291  R_EnforceVersion();
1292 
1294 
1295  /* prevent reloading of some rendering cvars */
1297 
1298  R_ModelInit();
1299  R_InitExtensions();
1301  R_InitPrograms();
1302  R_InitImages();
1304  R_DrawInitLocal();
1305  R_SphereInit();
1306  R_FontInit();
1307  R_InitFBObjects();
1308  R_UpdateDefaultMaterial("","","", nullptr);
1309  r_battlescapeWeather.setDefaults();
1310 
1311  R_CheckError();
1312 
1313  return true;
1314 }
1315 
1319 void R_Shutdown (void)
1320 {
1321  Cmd_TableRemoveList(r_commands);
1322 
1324 
1325  R_ModelShutdown();
1326  R_ShutdownImages();
1327 
1329  R_FontShutdown();
1331 
1332  /* shut down OS specific OpenGL stuff like contexts, etc. */
1333  Rimp_Shutdown();
1334 }
image_t * r_dummyTexture
Definition: r_main.cpp:53
int maxDrawBuffers
Definition: r_local.h:173
cvar_t * r_screenshot_jpeg_quality
Definition: r_main.cpp:67
int gl_solid_format
Definition: r_local.h:189
void Com_SetRenderModified(bool modified)
Definition: cvar.cpp:66
cvar_t * r_particles
Definition: r_particle.cpp:32
int gl_filter_max
Definition: r_local.h:196
static cvar_t * r_ext_s3tc_compression
Definition: r_main.cpp:74
void(APIENTRY * EnableVertexAttribArray_t)(GLuint index)
Definition: r_gl.h:155
static cvar_t * r_ext_nonpoweroftwo
Definition: r_main.cpp:75
void(APIENTRY * GetProgramiv_t)(GLuint id, GLenum field, GLuint *dest)
Definition: r_gl.h:173
void R_RestartPrograms_f(void)
Reloads the glsl shaders.
Definition: r_program.cpp:1058
int width
Definition: cl_video.h:83
bool R_SetMode(void)
Definition: r_main.cpp:694
void(APIENTRY * GetShaderInfoLog_t)(GLuint id, GLuint maxlen, GLuint *len, GLchar *dest)
Definition: r_gl.h:165
static bool R_CvarPostProcess(cvar_t *cvar)
Definition: r_main.cpp:547
cvar_t * r_overridematerial
Definition: r_main.cpp:81
void R_DrawParticles(void)
Definition: r_particle.cpp:266
static void R_RegisterImageVars(void)
Definition: r_main.cpp:642
cvarChangeListener_t * Cvar_RegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Registers a listener that is executed each time a cvar changed its value.
Definition: cvar.cpp:446
#define GL_MAX_RENDERBUFFER_SIZE_EXT
int maxVertexBufferSize
Definition: r_local.h:171
int viewHeight
Definition: cl_video.h:76
int maxVertexAttribs
Definition: r_local.h:170
int maxTextureCoords
Definition: r_local.h:169
cvar_t * r_warp
Definition: r_main.cpp:95
void R_ShutdownFBObjects(void)
Delete all registered framebuffer and render buffer objects, clear memory.
renderer_threadstate_t r_threadstate
Definition: r_thread.cpp:34
void R_DrawOpaqueMeshEntities(entity_t *ents)
Definition: r_entity.cpp:339
void R_AddBspRRef(const mBspModel_t *model, const vec3_t origin, const vec3_t angles, const bool forceVisibility)
Adds bsp render references.
Definition: r_bsp.cpp:324
#define GL_MAX_FRAGMENT_UNIFORM_VECTORS
#define CVAR_R_MASK
Definition: cvar.h:51
void R_DrawChars(void)
Definition: r_draw.cpp:155
void R_ScreenShot_f(void)
Definition: r_misc.cpp:203
cvar_t * vid_mode
Definition: cl_video.cpp:38
cvar_t * r_drawtags
Definition: r_main.cpp:110
GLint(APIENTRY * GetUniformLocation_t)(GLuint id, const GLchar *name)
Definition: r_gl.h:175
int swapinterval
Definition: cl_video.h:49
light_t staticLights[MAX_STATIC_LIGHTS]
Definition: cl_renderer.h:194
void R_DrawCoronas(void)
Definition: r_corona.cpp:41
rconfig_t r_config
Definition: r_main.cpp:47
void changeTo(weatherTypes weather)
changes to weather of given type; parameters are randomized
Definition: r_weather.cpp:91
void(APIENTRY * ShaderSource_t)(GLuint id, GLuint count, GLchar **sources, GLuint *len)
Definition: r_gl.h:162
cvar_t * r_hardness
Definition: r_main.cpp:105
cvar_t * r_multisample
Definition: r_main.cpp:90
cvar_t * r_debug_tangents
Definition: r_main.cpp:70
bool Cvar_AssertValue(cvar_t *cvar, float minVal, float maxVal, bool shouldBeIntegral)
Checks cvar values.
Definition: cvar.cpp:161
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
void(APIENTRY * Uniform1fv_t)(GLint location, int count, GLfloat *f)
Definition: r_gl.h:178
cvar_t * r_debug_normals
Definition: r_main.cpp:69
vec3_t normal
Definition: typedefs.h:21
void(APIENTRY * VertexAttribPointer_t)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer)
Definition: r_gl.h:157
model_t * r_mapTiles[MAX_MAPTILES]
The world model(s)
Definition: r_model.cpp:32
static void R_Strings_f(void)
Prints some OpenGL strings.
Definition: r_main.cpp:129
int maxColorAttachments
Definition: r_local.h:175
void R_FontListCache_f(void)
Console command binding to show the font cache.
Definition: r_font.cpp:228
void R_DrawEntityEffects(void)
Draws shadow and highlight effects for the entities (actors)
Definition: r_entity.cpp:208
void(APIENTRY * ClientActiveTexture_t)(GLenum texture)
Definition: r_gl.h:146
float fieldOfViewX
Definition: cl_renderer.h:171
void R_DrawNullEntities(const entity_t *ents)
Draw entities which models couldn't be loaded.
Definition: r_entity.cpp:503
bool drawBuffers
Definition: r_local.h:187
void(APIENTRY * Uniform2fv_t)(GLint location, int count, GLfloat *f)
Definition: r_gl.h:179
cvar_t * r_ext_texture_compression
Definition: r_main.cpp:73
const vec3_t vec3_origin
Definition: mathlib.cpp:35
static bool R_CvarCheckMultisample(cvar_t *cvar)
Definition: r_main.cpp:556
cvar_t * r_postprocess
Definition: r_main.cpp:100
void(APIENTRY * GetShaderiv_t)(GLuint id, GLenum field, GLuint *dest)
Definition: r_gl.h:164
float dist
Definition: typedefs.h:22
static void R_VerifyDriver(void)
Checks whether we have hardware acceleration.
Definition: r_main.cpp:1222
#define GL_MAX_VARYING_VECTORS
GLuint(APIENTRY * CreateShader_t)(GLenum type)
Definition: r_gl.h:160
void(APIENTRY * Uniform4fv_t)(GLint location, int count, GLfloat *f)
Definition: r_gl.h:181
void R_DrawBspNormals(int tile)
Developer tool for viewing BSP vertex normals. Only Phong interpolated surfaces show their normals wh...
Definition: r_bsp.cpp:134
void R_SetDefaultState(void)
Definition: r_state.cpp:860
void R_RenderMaterialBspRRefs(void)
Definition: r_bsp.cpp:449
void(APIENTRY * DisableVertexAttribArray_t)(GLuint index)
Definition: r_gl.h:156
float rx
Definition: cl_video.h:71
bool R_Init(void)
Definition: r_main.cpp:1263
float value
Definition: cvar.h:80
cvar_t * r_wire
Definition: r_main.cpp:91
void R_Shutdown(void)
Definition: r_main.cpp:1319
viddef_t viddef
Definition: cl_video.cpp:34
vec3_t viewAngles
Definition: cl_renderer.h:173
cvar_t * r_drawentities
Definition: r_main.cpp:60
cvar_t * r_fog
Definition: r_main.cpp:107
local graphics definitions
GL config stuff.
Definition: r_local.h:155
GLuint(APIENTRY * CreateProgram_t)(void)
Definition: r_gl.h:166
void R_RenderAlphaTestBspRRefs(void)
Definition: r_bsp.cpp:436
void RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
Rotate a point around a given vector.
Definition: mathlib.cpp:849
void R_ShutdownImages(void)
Definition: r_image.cpp:796
void R_SetupFrustum(void)
Definition: r_main.cpp:137
static const char * R_TranslateError(GLenum error)
Definition: r_error.h:33
int glVersionMinor
Definition: r_local.h:162
cvar_t * r_debug_lights
Definition: r_main.cpp:71
unsigned width
Definition: cl_video.h:44
cvar_t * r_shadows
Definition: r_main.cpp:87
int maxRenderbufferSize
Definition: r_local.h:174
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
const char * rendererString
Definition: r_local.h:156
cvar_t * r_bumpmap
Definition: r_main.cpp:103
static bool R_CvarCheckMaxLightmap(cvar_t *cvar)
Definition: r_main.cpp:488
cvar_t * r_specular
Definition: r_main.cpp:104
int virtualHeight
Definition: cl_video.h:74
void R_UpdateDefaultMaterial(const char *cvarName, const char *oldValue, const char *newValue, void *data)
Change listener callback for material value cvars.
static uintptr_t R_GetProcAddressExt(const char *functionName)
Definition: r_main.cpp:757
#define LIGHTMAP_DEFAULT_PAGE_SIZE
Definition: r_lightmap.h:30
cvar_t * r_coronas
Definition: r_main.cpp:109
image_t * r_noTexture
Definition: r_main.cpp:51
int integer
Definition: cvar.h:81
static cvar_t * r_intel_hack
Definition: r_main.cpp:76
Contains the game screen context, everything that is needed to create the graphic context...
Definition: cl_video.h:43
bool Cvar_PendingCvars(int flags)
Checks whether there are pending cvars for the given flags.
Definition: cvar.cpp:881
a light source
Definition: r_light.h:29
#define VectorScale(in, scale, out)
Definition: vector.h:79
static cvar_t * r_texturealphamode
Definition: r_main.cpp:78
void R_SphereInit(void)
Creates the spheres we need for rendering the 3d globe.
Definition: r_sphere.cpp:119
GLenum glGetError(void)
Definition: gldummy.cpp:8
void Rimp_Shutdown(void)
Definition: r_sdl.cpp:282
const GLuint *typedef GLuint *typedef GLenum
Definition: r_gl.h:190
rlocals_t r_locals
Definition: r_main.cpp:49
voidpf void * buf
Definition: ioapi.h:42
#define ERR_FATAL
Definition: common.h:210
#define CVAR_ARCHIVE
Definition: cvar.h:40
int maxVertexTextureImageUnits
Definition: r_local.h:176
void R_TextureMode(const char *string)
Definition: r_image.cpp:869
void Cmd_TableRemoveList(const cmdList_t *cmdList)
Definition: cmd.cpp:859
cvar_t * r_drawbuffer
Definition: r_main.cpp:85
int r_numMapTiles
Definition: r_model.cpp:33
void R_DrawBoundingBoxes(void)
Definition: r_draw.cpp:640
static cvar_t * r_texturesolidmode
Definition: r_main.cpp:79
bool frameBufferObject
Definition: r_local.h:186
static void R_ClearScene(void)
Definition: r_main.cpp:209
int glslVersionMajor
Definition: r_local.h:164
cvar_t * r_isometric
Definition: r_main.cpp:63
void R_Color(const vec4_t rgba)
Change the color to given value.
Definition: r_state.cpp:1011
void Com_Error(int code, const char *fmt,...)
Definition: common.cpp:417
void(APIENTRY * Uniform1i_t)(GLint location, GLint i)
Definition: r_gl.h:176
void R_ImageList_f(void)
Shows all loaded images.
Definition: r_image.cpp:85
void(APIENTRY * DeleteShader_t)(GLuint id)
Definition: r_gl.h:161
entity_t * r_blend_mesh_entities
Definition: r_entity.cpp:38
void R_InitMiscTexture(void)
Definition: r_misc.cpp:46
void R_EnableMultisample(bool enable)
Definition: r_state.cpp:243
byte type
Definition: typedefs.h:23
vec3_t viewOrigin
Definition: cl_renderer.h:172
cvar_t * r_shownormals
Definition: r_main.cpp:102
client_static_t cls
Definition: cl_main.cpp:83
lightmap definitions
void Sys_Sleep(int milliseconds)
Calls the win32 sleep function.
Definition: unix_shared.cpp:68
void R_ClearBspRRefs(void)
Definition: r_bsp.cpp:311
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition: shared.cpp:457
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Create the rotation matrix in order to rotate something.
Definition: mathlib.cpp:631
void R_ModelShutdown()
Definition: r_model.cpp:440
weatherTypes
Definition: r_weather.h:32
#define R_CheckGLVersion(max, min)
Definition: r_main.cpp:832
#define DotProduct(x, y)
Returns the distance between two 3-dimensional vectors.
Definition: vector.h:44
int maxTextureUnits
Definition: r_local.h:168
bool fullscreen
Definition: cl_video.h:47
int x
Definition: cl_video.h:76
cvar_t * r_weather
Definition: r_main.cpp:59
static bool R_SearchForVendor(const char *vendor)
Searches vendor and renderer GL strings for the given vendor id.
Definition: r_main.cpp:1211
const char * vendorString
Definition: r_local.h:157
cvar_t * r_parallax
Definition: r_main.cpp:106
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition: cvar.cpp:342
#define OBJZERO(obj)
Definition: shared.h:178
static bool R_CvarPrograms(cvar_t *cvar)
Definition: r_main.cpp:517
rendererData_t refdef
Definition: r_main.cpp:45
void R_DrawSpecialEntities(const entity_t *ents)
Definition: r_entity.cpp:473
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition: r_gl.h:110
cvar_t * r_materials
Definition: r_main.cpp:80
cvar_t * r_programs
Definition: r_main.cpp:97
float fieldOfViewY
Definition: cl_renderer.h:171
cvar_t * r_drawworld
Definition: r_main.cpp:61
int frame
Definition: r_local.h:109
const char * Q_stristr(const char *str, const char *substr)
Checks in case insensitive manner whether str contains substr.
Definition: shared.cpp:563
bool R_InitGraphics(const viddefContext_t *context)
Init the SDL window.
Definition: r_sdl.cpp:218
bool stretch
Definition: cl_video.h:69
void R_InitFBObjects(void)
void R_ModModellist_f(void)
Prints all loaded models.
Definition: r_model.cpp:53
void(APIENTRY * AttachShader_t)(GLuint prog, GLuint shader)
Definition: r_gl.h:168
void R_ResetArrayState(void)
Definition: r_array.cpp:185
static void R_EnforceVersion(void)
We need at least opengl version 1.2.1.
Definition: r_main.cpp:1181
void(APIENTRY * DetachShader_t)(GLuint prog, GLuint shader)
Definition: r_gl.h:169
void R_ShutdownPrograms(void)
Definition: r_program.cpp:265
clientBattleScape_t cl
void R_BeginFrame(void)
Definition: r_main.cpp:220
light_t dynamicLights[MAX_GL_LIGHTS]
Definition: cl_renderer.h:191
entity_t * r_null_entities
Definition: r_entity.cpp:39
cvar_t * r_anisotropic
Definition: r_main.cpp:64
hardwareType_t hardwareType
Definition: r_local.h:202
#define PLANE_ANYZ
Definition: defines.h:198
cvar_t * r_nocull
Definition: r_main.cpp:62
int gl_compressed_alpha_format
Definition: r_local.h:193
#define GL_SHADING_LANGUAGE_VERSION
#define CVAR_R_PROGRAMS
Definition: cvar.h:49
Definition: cmd.h:86
vec3_t up
Definition: r_local.h:102
void R_Setup2D(void)
Definition: r_state.cpp:825
#define GL_MAX_TEXTURE_COORDS
void R_GetLevelSurfaceLists(void)
Fills the surface chains for the current worldlevel and hide other levels.
Definition: r_bsp.cpp:281
#define GAME_TITLE
Definition: common.h:37
cvar_t * r_stencilshadows
Definition: r_main.cpp:88
static void R_UpdateVidDef(const viddefContext_t *context)
Definition: r_main.cpp:651
image_t * r_warpTexture
Definition: r_main.cpp:52
#define Q_strcasecmp(a, b)
Definition: shared.h:131
cvar_t * vid_stretch
Definition: cl_video.cpp:36
viddefContext_t context
Definition: cl_video.h:67
threadstate_t state
Definition: cl_renderer.h:227
void R_FontShutdown(void)
frees the SDL_ttf fonts
Definition: r_font.cpp:144
void R_TextureSolidMode(const char *string)
Definition: r_image.cpp:966
void R_RenderOpaqueBspRRefs(void)
Draw all simple opaque bsp surfaces with multitexture enabled and light enabled.
Definition: r_bsp.cpp:410
bool nonPowerOfTwo
Definition: r_local.h:200
#define RDF_NOWORLDMODEL
Definition: cl_renderer.h:34
void(APIENTRY * DeleteProgram_t)(GLuint id)
Definition: r_gl.h:167
int maxLights
Definition: r_local.h:172
static cvar_t * r_maxtexres
Definition: r_main.cpp:57
#define INTEL_TEXTURE_RESOLUTION
Definition: r_main.cpp:1217
static void R_PrintInfo(const char *pre, const char *msg)
Definition: r_main.cpp:112
int maxTextureSize
Definition: r_local.h:167
#define VID_NORM_WIDTH
Definition: cl_renderer.h:40
static uintptr_t R_GetProcAddress(const char *functionName)
Definition: r_main.cpp:752
cvar_t * vid_fullscreen
Definition: cl_video.cpp:37
#define GL_MAX_VERTEX_ATTRIBS
#define MAX_ENTITY_LIGHTS
Definition: r_entity.h:28
static bool R_CheckExtension(const char *extension)
Checks for an OpenGL extension that was announced via the OpenGL ext string. If the given extension s...
Definition: r_main.cpp:787
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
static void R_InitExtensions(void)
Check and load all needed and supported opengl extensions.
Definition: r_main.cpp:838
cvar_t * r_lightmap
Definition: r_main.cpp:68
char lodDir[8]
Definition: r_local.h:178
vec4_t color
Definition: r_light.h:31
#define LIGHTMAP_MAX_PAGE_SIZE
Definition: r_lightmap.h:31
Pseudoinstanced grass generation and rendering.
cvar_t * r_checkerror
Definition: r_main.cpp:84
#define CVAR_LATCH
Definition: cvar.h:44
void R_ModelInit()
Definition: r_model.cpp:436
bool anisotropic
Definition: r_local.h:185
void R_DrawBlendMeshEntities(entity_t *ents)
Definition: r_entity.cpp:411
void R_UpdateSustainedLights(void)
Updates state of sustained lights; should be called once per frame right before world rendering...
Definition: r_light.cpp:83
cvar_t * r_driver
Definition: r_main.cpp:86
Weather r_battlescapeWeather
Definition: r_main.cpp:55
#define VID_NORM_HEIGHT
Definition: cl_renderer.h:41
void(APIENTRY * UseProgram_t)(GLuint id)
Definition: r_gl.h:171
cvar_t * r_vertexbuffers
Definition: r_main.cpp:94
void(APIENTRY * LinkProgram_t)(GLuint id)
Definition: r_gl.h:170
void Cvar_Reset(cvar_t *cvar)
Sets the cvar value back to the old value.
Definition: cvar.cpp:241
int gl_filter_min
Definition: r_local.h:195
void R_DrawGrass()
Definition: r_grass.cpp:399
QGL_EXTERN GLint i
Definition: r_gl.h:113
GLint(APIENTRY * GetAttribLocation_t)(GLuint id, const GLchar *name)
Definition: r_gl.h:182
bool lod_bias
Definition: r_local.h:198
void(APIENTRY * Uniform1f_t)(GLint location, GLfloat f)
Definition: r_gl.h:177
entity_t * r_special_entities
Definition: r_entity.cpp:40
void(APIENTRY * GetActiveUniforms_t)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
Definition: r_gl.h:172
char * string
Definition: cvar.h:73
int viewWidth
Definition: cl_video.h:76
void R_EnableBlend(bool enable)
Definition: r_state.cpp:261
static bool R_CvarCheckDynamicLights(cvar_t *cvar)
Definition: r_main.cpp:507
bool Rimp_Init(void)
Definition: r_sdl.cpp:72
int gl_alpha_format
Definition: r_local.h:190
static bool R_CvarGLSLVersionCheck(cvar_t *cvar)
Callback that is called when the r_glsl_version cvar is changed,.
Definition: r_main.cpp:530
vec3_t forward
Definition: r_local.h:103
static const cmdList_t r_commands[]
Definition: r_main.cpp:477
bool Com_IsRenderModified(void)
Definition: cvar.cpp:71
vec3_t origin
Definition: r_light.h:30
cvar_t * r_default_hardness
Definition: r_main.cpp:83
void R_TextureAlphaMode(const char *string)
Definition: r_image.cpp:931
bool VID_GetModeInfo(int modeIndex, vidmode_t *modeInfo)
Definition: cl_video.cpp:88
cvar_t * r_showbox
Definition: r_main.cpp:92
entity_t * r_opaque_mesh_entities
Definition: r_entity.cpp:37
cvar_t * r_texture_lod
Definition: r_main.cpp:65
void R_InitThreads(void)
Definition: r_thread.cpp:85
void R_AddCorona(const vec3_t org, float radius, const vec3_t color)
Definition: r_corona.cpp:24
void R_GetEntityLists(void)
Primary entry point for drawing all entities.
Definition: r_entity.cpp:625
void(APIENTRY * Uniform3fv_t)(GLint location, int count, GLfloat *f)
Definition: r_gl.h:180
cBspPlane_t frustum[4]
Definition: r_local.h:107
Error checking function.
#define GL_MAX_VERTEX_UNIFORM_VECTORS
brush model
bool Q_strreplace(const char *source, const char *pattern, const char *replace, char *dest, size_t destsize)
Replaces the first occurence of the given pattern in the source string with the given replace string...
Definition: shared.cpp:596
void(APIENTRY * ActiveTexture_t)(GLenum texture)
Definition: r_gl.h:145
cvar_t * vid_gamma
Definition: cl_video.cpp:40
void update(int milliseconds)
Updates weather for the time passed; handles particle creation/removal automatically.
Definition: r_weather.cpp:164
void R_RenderBlendBspRRefs(void)
Draw all translucent bsp surfaces with multitexture enabled and blend enabled.
Definition: r_bsp.cpp:462
void R_EndFrame(void)
Definition: r_main.cpp:443
void R_Setup3D(void)
Definition: r_state.cpp:763
void R_ShutdownThreads(void)
Definition: r_thread.cpp:69
const char * versionString
Definition: r_local.h:158
cvar_t * r_swapinterval
Definition: r_main.cpp:89
void R_InitImages(void)
Definition: r_image.cpp:774
cvar_t * vid_ignoregamma
Definition: cl_video.cpp:41
#define CVAR_R_IMAGES
Definition: cvar.h:47
vec3_t right
Definition: r_local.h:104
rstate_t r_state
Definition: r_main.cpp:48
static void R_Clear(void)
Clears the screens color and depth buffer.
Definition: r_main.cpp:192
#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB
cvar_t * r_glsl_version
The GLSL version being used (not necessarily a supported version by the OpenGL implementation). Stored as a c-string and integer.
Definition: r_main.cpp:99
int y
Definition: cl_video.h:76
int32_t maxAnisotropic
Definition: r_local.h:184
void UI_InvalidateStack(void)
Invalidate all windows of the current stack.
Definition: ui_windows.cpp:593
#define lengthof(x)
Definition: shared.h:105
int virtualWidth
Definition: cl_video.h:74
#define R_CheckError()
Definition: r_error.h:30
void R_DrawBloom(void)
handle post-processing bloom
Definition: r_geoscape.cpp:760
cvar_t * r_flares
Definition: r_main.cpp:108
GLsizei const GLvoid * data
Definition: r_gl.h:152
void setDefaults(void)
Sets clean weather, but generate some parameters usable for easily changing it into the worse varieti...
Definition: r_weather.cpp:71
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition: cvar.cpp:615
void R_DrawInitLocal(void)
Loads some textures and init the 3d globe.
Definition: r_draw.cpp:83
int glVersionMajor
Definition: r_local.h:161
int glslVersionMinor
Definition: r_local.h:165
void R_RenderFrame(void)
Definition: r_main.cpp:298
bool modified
Definition: cvar.h:79
unsigned height
Definition: cl_video.h:45
void R_RenderBlendWarpBspRRefs(void)
Draw all warped translucent bsp surfaces via warp shader and with blend enabled.
Definition: r_bsp.cpp:475
float ry
Definition: cl_video.h:72
static void R_UpdateWeather(const char *cvarName, const char *oldValue, const char *newValue, void *data)
Definition: r_main.cpp:566
void(APIENTRY * CompileShader_t)(GLuint id)
Definition: r_gl.h:163
static cvar_t * r_texturemode
Definition: r_main.cpp:77
bool Q_IsPowerOfTwo(int i)
Checks whether i is power of two value.
Definition: mathlib.cpp:972
void Cvar_ClearVars(int flags)
Definition: cvar.cpp:891
Functions to generate and render spheres.
Weather effects rendering subsystem header file.
cvar_t * r_screenshot_format
Definition: r_main.cpp:66
void(APIENTRY * UniformMatrix4fv_t)(GLint location, int count, GLboolean transpose, GLfloat *v)
Definition: r_gl.h:183
cvar_t * r_default_specular
Definition: r_main.cpp:82
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition: cvar.cpp:671
const char * extensionsString
Definition: r_local.h:159
static void R_RegisterSystemVars(void)
Definition: r_main.cpp:572
void R_InitPrograms(void)
Definition: r_program.cpp:1022
void render(void)
Draws weather effects.
Definition: r_weather.cpp:257
int height
Definition: cl_video.h:83
cvar_t * r_maxlightmap
Definition: r_main.cpp:101
bool Cvar_SetCheckFunction(const char *varName, bool(*check)(cvar_t *cvar))
Set a checker function for cvar values.
Definition: cvar.cpp:139
static cvar_t * r_deluxemap
Definition: r_main.cpp:72
#define CVAR_R_CONTEXT
Definition: cvar.h:48
void R_RenderOpaqueWarpBspRRefs(void)
Draw all warped opaque bsp surfaces via warp shader.
Definition: r_bsp.cpp:426
cvar_t * r_dynamic_lights
Definition: r_main.cpp:96
void R_RenderFlareBspRRefs(void)
Definition: r_bsp.cpp:454
void(APIENTRY * GetProgramInfoLog_t)(GLuint id, GLuint maxlen, GLuint *len, GLchar *dest)
Definition: r_gl.h:174
char * name
Definition: cvar.h:72
void R_FontInit(void)
Definition: r_font.cpp:722
cvar_t * r_threads
Definition: r_main.cpp:93
void R_EnableFog(bool enable)
Definition: r_state.cpp:586
static bool R_CvarCheckWeather(cvar_t *cvar)
Definition: r_main.cpp:561
bool R_ImageExists(const char *pname,...)
Definition: r_image.cpp:681
void Cmd_TableAddList(const cmdList_t *cmdList)
Definition: cmd.cpp:853
int gl_compressed_solid_format
Definition: r_local.h:192
mBspModel_t bsp
Definition: r_model.h:60
OpenGL bindings.
float radius
Definition: r_light.h:32