📄 tr_init.c
字号:
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// tr_init.c -- functions that are not called every frame
#include "tr_local.h"
glconfig_t glConfig;
glstate_t glState;
static void GfxInfo_f( void );
cvar_t *r_flareSize;
cvar_t *r_flareFade;
cvar_t *r_railWidth;
cvar_t *r_railCoreWidth;
cvar_t *r_railSegmentLength;
cvar_t *r_ignoreFastPath;
cvar_t *r_verbose;
cvar_t *r_ignore;
cvar_t *r_displayRefresh;
cvar_t *r_detailTextures;
cvar_t *r_znear;
cvar_t *r_smp;
cvar_t *r_showSmp;
cvar_t *r_skipBackEnd;
cvar_t *r_ignorehwgamma;
cvar_t *r_measureOverdraw;
cvar_t *r_inGameVideo;
cvar_t *r_fastsky;
cvar_t *r_drawSun;
cvar_t *r_dynamiclight;
cvar_t *r_dlightBacks;
cvar_t *r_lodbias;
cvar_t *r_lodscale;
cvar_t *r_norefresh;
cvar_t *r_drawentities;
cvar_t *r_drawworld;
cvar_t *r_speeds;
cvar_t *r_fullbright;
cvar_t *r_novis;
cvar_t *r_nocull;
cvar_t *r_facePlaneCull;
cvar_t *r_showcluster;
cvar_t *r_nocurves;
cvar_t *r_allowExtensions;
cvar_t *r_ext_compressed_textures;
cvar_t *r_ext_gamma_control;
cvar_t *r_ext_multitexture;
cvar_t *r_ext_compiled_vertex_array;
cvar_t *r_ext_texture_env_add;
cvar_t *r_ignoreGLErrors;
cvar_t *r_logFile;
cvar_t *r_stencilbits;
cvar_t *r_depthbits;
cvar_t *r_colorbits;
cvar_t *r_stereo;
cvar_t *r_primitives;
cvar_t *r_texturebits;
cvar_t *r_drawBuffer;
cvar_t *r_glDriver;
cvar_t *r_lightmap;
cvar_t *r_vertexLight;
cvar_t *r_uiFullScreen;
cvar_t *r_shadows;
cvar_t *r_flares;
cvar_t *r_mode;
cvar_t *r_nobind;
cvar_t *r_singleShader;
cvar_t *r_roundImagesDown;
cvar_t *r_colorMipLevels;
cvar_t *r_picmip;
cvar_t *r_showtris;
cvar_t *r_showsky;
cvar_t *r_shownormals;
cvar_t *r_finish;
cvar_t *r_clear;
cvar_t *r_swapInterval;
cvar_t *r_textureMode;
cvar_t *r_offsetFactor;
cvar_t *r_offsetUnits;
cvar_t *r_gamma;
cvar_t *r_intensity;
cvar_t *r_lockpvs;
cvar_t *r_noportals;
cvar_t *r_portalOnly;
cvar_t *r_subdivisions;
cvar_t *r_lodCurveError;
cvar_t *r_fullscreen;
cvar_t *r_customwidth;
cvar_t *r_customheight;
cvar_t *r_customaspect;
cvar_t *r_overBrightBits;
cvar_t *r_mapOverBrightBits;
cvar_t *r_debugSurface;
cvar_t *r_simpleMipMaps;
cvar_t *r_showImages;
cvar_t *r_ambientScale;
cvar_t *r_directedScale;
cvar_t *r_debugLight;
cvar_t *r_debugSort;
cvar_t *r_printShaders;
cvar_t *r_saveFontData;
cvar_t *r_maxpolys;
int max_polys;
cvar_t *r_maxpolyverts;
int max_polyverts;
void ( APIENTRY * qglMultiTexCoord2fARB )( GLenum texture, GLfloat s, GLfloat t );
void ( APIENTRY * qglActiveTextureARB )( GLenum texture );
void ( APIENTRY * qglClientActiveTextureARB )( GLenum texture );
void ( APIENTRY * qglLockArraysEXT)( GLint, GLint);
void ( APIENTRY * qglUnlockArraysEXT) ( void );
static void AssertCvarRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral )
{
if ( shouldBeIntegral )
{
if ( ( int ) cv->value != cv->integer )
{
ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' must be integral (%f)\n", cv->name, cv->value );
ri.Cvar_Set( cv->name, va( "%d", cv->integer ) );
}
}
if ( cv->value < minVal )
{
ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f < %f)\n", cv->name, cv->value, minVal );
ri.Cvar_Set( cv->name, va( "%f", minVal ) );
}
else if ( cv->value > maxVal )
{
ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f > %f)\n", cv->name, cv->value, maxVal );
ri.Cvar_Set( cv->name, va( "%f", maxVal ) );
}
}
/*
** InitOpenGL
**
** This function is responsible for initializing a valid OpenGL subsystem. This
** is done by calling GLimp_Init (which gives us a working OGL subsystem) then
** setting variables, checking GL constants, and reporting the gfx system config
** to the user.
*/
static void InitOpenGL( void )
{
char renderer_buffer[1024];
//
// initialize OS specific portions of the renderer
//
// GLimp_Init directly or indirectly references the following cvars:
// - r_fullscreen
// - r_glDriver
// - r_mode
// - r_(color|depth|stencil)bits
// - r_ignorehwgamma
// - r_gamma
//
if ( glConfig.vidWidth == 0 )
{
GLint temp;
GLimp_Init();
strcpy( renderer_buffer, glConfig.renderer_string );
Q_strlwr( renderer_buffer );
// OpenGL driver constants
qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &temp );
glConfig.maxTextureSize = temp;
// stubbed or broken drivers may have reported 0...
if ( glConfig.maxTextureSize <= 0 )
{
glConfig.maxTextureSize = 0;
}
}
// init command buffers and SMP
R_InitCommandBuffers();
// print info
GfxInfo_f();
// set default state
GL_SetDefaultState();
}
/*
==================
GL_CheckErrors
==================
*/
void GL_CheckErrors( void ) {
int err;
char s[64];
err = qglGetError();
if ( err == GL_NO_ERROR ) {
return;
}
if ( r_ignoreGLErrors->integer ) {
return;
}
switch( err ) {
case GL_INVALID_ENUM:
strcpy( s, "GL_INVALID_ENUM" );
break;
case GL_INVALID_VALUE:
strcpy( s, "GL_INVALID_VALUE" );
break;
case GL_INVALID_OPERATION:
strcpy( s, "GL_INVALID_OPERATION" );
break;
case GL_STACK_OVERFLOW:
strcpy( s, "GL_STACK_OVERFLOW" );
break;
case GL_STACK_UNDERFLOW:
strcpy( s, "GL_STACK_UNDERFLOW" );
break;
case GL_OUT_OF_MEMORY:
strcpy( s, "GL_OUT_OF_MEMORY" );
break;
default:
Com_sprintf( s, sizeof(s), "%i", err);
break;
}
ri.Error( ERR_FATAL, "GL_CheckErrors: %s", s );
}
/*
** R_GetModeInfo
*/
typedef struct vidmode_s
{
const char *description;
int width, height;
float pixelAspect; // pixel width / height
} vidmode_t;
vidmode_t r_vidModes[] =
{
{ "Mode 0: 320x240", 320, 240, 1 },
{ "Mode 1: 400x300", 400, 300, 1 },
{ "Mode 2: 512x384", 512, 384, 1 },
{ "Mode 3: 640x480", 640, 480, 1 },
{ "Mode 4: 800x600", 800, 600, 1 },
{ "Mode 5: 960x720", 960, 720, 1 },
{ "Mode 6: 1024x768", 1024, 768, 1 },
{ "Mode 7: 1152x864", 1152, 864, 1 },
{ "Mode 8: 1280x1024", 1280, 1024, 1 },
{ "Mode 9: 1600x1200", 1600, 1200, 1 },
{ "Mode 10: 2048x1536", 2048, 1536, 1 },
{ "Mode 11: 856x480 (wide)",856, 480, 1 }
};
static int s_numVidModes = ( sizeof( r_vidModes ) / sizeof( r_vidModes[0] ) );
qboolean R_GetModeInfo( int *width, int *height, float *windowAspect, int mode ) {
vidmode_t *vm;
if ( mode < -1 ) {
return qfalse;
}
if ( mode >= s_numVidModes ) {
return qfalse;
}
if ( mode == -1 ) {
*width = r_customwidth->integer;
*height = r_customheight->integer;
*windowAspect = r_customaspect->value;
return qtrue;
}
vm = &r_vidModes[mode];
*width = vm->width;
*height = vm->height;
*windowAspect = (float)vm->width / ( vm->height * vm->pixelAspect );
return qtrue;
}
/*
** R_ModeList_f
*/
static void R_ModeList_f( void )
{
int i;
ri.Printf( PRINT_ALL, "\n" );
for ( i = 0; i < s_numVidModes; i++ )
{
ri.Printf( PRINT_ALL, "%s\n", r_vidModes[i].description );
}
ri.Printf( PRINT_ALL, "\n" );
}
/*
==============================================================================
SCREEN SHOTS
NOTE TTimo
some thoughts about the screenshots system:
screenshots get written in fs_homepath + fs_gamedir
vanilla q3 .. baseq3/screenshots/ *.tga
team arena .. missionpack/screenshots/ *.tga
two commands: "screenshot" and "screenshotJPEG"
we use statics to store a count and start writing the first screenshot/screenshot????.tga (.jpg) available
(with FS_FileExists / FS_FOpenFileWrite calls)
FIXME: the statics don't get a reinit between fs_game changes
==============================================================================
*/
/*
==================
RB_TakeScreenshot
==================
*/
void RB_TakeScreenshot( int x, int y, int width, int height, char *fileName ) {
byte *buffer;
int i, c, temp;
buffer = ri.Hunk_AllocateTempMemory(glConfig.vidWidth*glConfig.vidHeight*3+18);
Com_Memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = width & 255;
buffer[13] = width >> 8;
buffer[14] = height & 255;
buffer[15] = height >> 8;
buffer[16] = 24; // pixel size
qglReadPixels( x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 );
// swap rgb to bgr
c = 18 + width * height * 3;
for (i=18 ; i<c ; i+=3) {
temp = buffer[i];
buffer[i] = buffer[i+2];
buffer[i+2] = temp;
}
// gamma correct
if ( ( tr.overbrightBits > 0 ) && glConfig.deviceSupportsGamma ) {
R_GammaCorrect( buffer + 18, glConfig.vidWidth * glConfig.vidHeight * 3 );
}
ri.FS_WriteFile( fileName, buffer, c );
ri.Hunk_FreeTempMemory( buffer );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -