Browse Source

ref: more @mittorn's changes on RefAPI

pull/2/head
Alibek Omarov 6 years ago
parent
commit
e193ac2c04
  1. 109
      common/com_image.h
  2. 34
      common/com_model.h
  3. 26
      common/ref_api.h
  4. 92
      common/xash3d_types.h
  5. 2115
      engine/client/cl_efx.c
  6. 4
      engine/client/cl_frame.c
  7. 10
      engine/client/cl_game.c
  8. 1
      engine/client/cl_scrn.c
  9. 3
      engine/client/cl_tent.c
  10. 26
      engine/client/client.h
  11. 11
      engine/client/ref_common.c
  12. 9
      engine/client/ref_common.h
  13. 532
      engine/client/vid_common.c
  14. 78
      engine/client/vid_common.h
  15. 185
      engine/common/common.h
  16. 19
      engine/common/mod_local.h
  17. 13
      engine/common/system.h
  18. 36
      engine/platform/sdl/vid_sdl.c
  19. 5
      ref_gl/gl_alias.c
  20. 23
      ref_gl/gl_backend.c
  21. 1118
      ref_gl/gl_beams.c
  22. 3
      ref_gl/gl_context.c
  23. 4
      ref_gl/gl_cull.c
  24. 10
      ref_gl/gl_dbghulls.c
  25. 6
      ref_gl/gl_decals.c
  26. 4
      ref_gl/gl_draw.c
  27. 1
      ref_gl/gl_frustum.c
  28. 2
      ref_gl/gl_image.c
  29. 83
      ref_gl/gl_local.h
  30. 518
      ref_gl/gl_opengl.c
  31. 6
      ref_gl/gl_refrag.c
  32. 8
      ref_gl/gl_rlight.c
  33. 48
      ref_gl/gl_rmain.c
  34. 2
      ref_gl/gl_rmath.c
  35. 20
      ref_gl/gl_rmisc.c
  36. 1320
      ref_gl/gl_rpart.c
  37. 96
      ref_gl/gl_rsurf.c
  38. 2
      ref_gl/gl_sprite.c
  39. 17
      ref_gl/gl_studio.c
  40. 9
      ref_gl/gl_warp.c
  41. 3
      ref_gl/wscript
  42. 2
      wscript

109
common/com_image.h

@ -0,0 +1,109 @@ @@ -0,0 +1,109 @@
#pragma once
/*
========================================================================
internal image format
typically expanded to rgba buffer
NOTE: number at end of pixelformat name it's a total bitscount e.g. PF_RGB_24 == PF_RGB_888
========================================================================
*/
#define ImageRAW( type ) (type == PF_RGBA_32 || type == PF_BGRA_32 || type == PF_RGB_24 || type == PF_BGR_24)
#define ImageDXT( type ) (type == PF_DXT1 || type == PF_DXT3 || type == PF_DXT5 || type == PF_ATI2)
typedef enum
{
PF_UNKNOWN = 0,
PF_INDEXED_24, // inflated palette (768 bytes)
PF_INDEXED_32, // deflated palette (1024 bytes)
PF_RGBA_32, // normal rgba buffer
PF_BGRA_32, // big endian RGBA (MacOS)
PF_RGB_24, // uncompressed dds or another 24-bit image
PF_BGR_24, // big-endian RGB (MacOS)
PF_DXT1, // s3tc DXT1 format
PF_DXT3, // s3tc DXT3 format
PF_DXT5, // s3tc DXT5 format
PF_ATI2, // latc ATI2N format
PF_TOTALCOUNT, // must be last
} pixformat_t;
typedef struct bpc_desc_s
{
int format; // pixelformat
char name[16]; // used for debug
uint glFormat; // RGBA format
int bpp; // channels (e.g. rgb = 3, rgba = 4)
} bpc_desc_t;
// imagelib global settings
typedef enum
{
IL_USE_LERPING = BIT(0), // lerping images during resample
IL_KEEP_8BIT = BIT(1), // don't expand paletted images
IL_ALLOW_OVERWRITE = BIT(2), // allow to overwrite stored images
IL_DONTFLIP_TGA = BIT(3), // Steam background completely ignore tga attribute 0x20 (stupid lammers!)
IL_DDS_HARDWARE = BIT(4), // DXT compression is support
IL_LOAD_DECAL = BIT(5), // special mode for load gradient decals
IL_OVERVIEW = BIT(6), // overview required some unque operations
} ilFlags_t;
// goes into rgbdata_t->encode
#define DXT_ENCODE_DEFAULT 0 // don't use custom encoders
#define DXT_ENCODE_COLOR_YCoCg 0x1A01 // make sure that value dosn't collide with anything
#define DXT_ENCODE_ALPHA_1BIT 0x1A02 // normal 1-bit alpha
#define DXT_ENCODE_ALPHA_8BIT 0x1A03 // normal 8-bit alpha
#define DXT_ENCODE_ALPHA_SDF 0x1A04 // signed distance field
#define DXT_ENCODE_NORMAL_AG_ORTHO 0x1A05 // orthographic projection
#define DXT_ENCODE_NORMAL_AG_STEREO 0x1A06 // stereographic projection
#define DXT_ENCODE_NORMAL_AG_PARABOLOID 0x1A07 // paraboloid projection
#define DXT_ENCODE_NORMAL_AG_QUARTIC 0x1A08 // newton method
#define DXT_ENCODE_NORMAL_AG_AZIMUTHAL 0x1A09 // Lambert Azimuthal Equal-Area
// rgbdata output flags
typedef enum
{
// rgbdata->flags
IMAGE_CUBEMAP = BIT(0), // it's 6-sides cubemap buffer
IMAGE_HAS_ALPHA = BIT(1), // image contain alpha-channel
IMAGE_HAS_COLOR = BIT(2), // image contain RGB-channel
IMAGE_COLORINDEX = BIT(3), // all colors in palette is gradients of last color (decals)
IMAGE_HAS_LUMA = BIT(4), // image has luma pixels (q1-style maps)
IMAGE_SKYBOX = BIT(5), // only used by FS_SaveImage - for write right suffixes
IMAGE_QUAKESKY = BIT(6), // it's a quake sky double layered clouds (so keep it as 8 bit)
IMAGE_DDS_FORMAT = BIT(7), // a hint for GL loader
IMAGE_MULTILAYER = BIT(8), // to differentiate from 3D texture
IMAGE_ONEBIT_ALPHA = BIT(9), // binary alpha
IMAGE_QUAKEPAL = BIT(10), // image has quake1 palette
// Image_Process manipulation flags
IMAGE_FLIP_X = BIT(16), // flip the image by width
IMAGE_FLIP_Y = BIT(17), // flip the image by height
IMAGE_ROT_90 = BIT(18), // flip from upper left corner to down right corner
IMAGE_ROT180 = IMAGE_FLIP_X|IMAGE_FLIP_Y,
IMAGE_ROT270 = IMAGE_FLIP_X|IMAGE_FLIP_Y|IMAGE_ROT_90,
IMAGE_EMBOSS = BIT(19), // apply emboss mapping
IMAGE_RESAMPLE = BIT(20), // resample image to specified dims
// reserved
// reserved
IMAGE_FORCE_RGBA = BIT(23), // force image to RGBA buffer
IMAGE_MAKE_LUMA = BIT(24), // create luma texture from indexed
IMAGE_QUANTIZE = BIT(25), // make indexed image from 24 or 32- bit image
IMAGE_LIGHTGAMMA = BIT(26), // apply gamma for image
IMAGE_REMAP = BIT(27), // interpret width and height as top and bottom color
} imgFlags_t;
typedef struct rgbdata_s
{
word width; // image width
word height; // image height
word depth; // image depth
uint type; // compression type
uint flags; // misc image flags
word encode; // DXT may have custom encoder, that will be decoded in GLSL-side
byte numMips; // mipmap count
byte *palette; // palette if present
byte *buffer; // image buffer
rgba_t fogParams; // some water textures in hl1 has info about fog color and alpha
size_t size; // for bounds checking
} rgbdata_t;

34
common/com_model.h

@ -495,4 +495,36 @@ typedef struct @@ -495,4 +495,36 @@ typedef struct
maliasframedesc_t frames[1]; // variable sized
} aliashdr_t;
#endif//COM_MODEL_H
// remapping info
#define SUIT_HUE_START 192
#define SUIT_HUE_END 223
#define PLATE_HUE_START 160
#define PLATE_HUE_END 191
#define SHIRT_HUE_START 16
#define SHIRT_HUE_END 32
#define PANTS_HUE_START 96
#define PANTS_HUE_END 112
// 1/32 epsilon to keep floating point happy
#define DIST_EPSILON (1.0f / 32.0f)
#define FRAC_EPSILON (1.0f / 1024.0f)
#define BACKFACE_EPSILON 0.01f
#define MAX_BOX_LEAFS 256
#define ANIM_CYCLE 2
#define MOD_FRAMES 20
#define MAX_DEMOS 32
#define MAX_MOVIES 8
#define MAX_CDTRACKS 32
#define MAX_CLIENT_SPRITES 256 // SpriteTextures
#define MAX_EFRAGS 8192 // Arcane Dimensions required
#define MAX_REQUESTS 64
#endif//COM_MODEL_H

26
common/ref_api.h

@ -15,7 +15,7 @@ GNU General Public License for more details. @@ -15,7 +15,7 @@ GNU General Public License for more details.
#pragma once
#ifndef REF_API
#define REF_API
#include "com_image.h"
#include "vgui_api.h"
#include "render_api.h"
#include "triangleapi.h"
@ -27,6 +27,21 @@ GNU General Public License for more details. @@ -27,6 +27,21 @@ GNU General Public License for more details.
#define REF_API_VERSION 1
#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP)
#define TF_FONT (TF_NOMIPMAP|TF_CLAMP)
#define TF_IMAGE (TF_NOMIPMAP|TF_CLAMP)
#define TF_DECAL (TF_CLAMP)
// screenshot types
#define VID_SCREENSHOT 0
#define VID_LEVELSHOT 1
#define VID_MINISHOT 2
#define VID_MAPSHOT 3 // special case for overview layer
#define VID_SNAPSHOT 4 // save screenshot into root dir and no gamma correction
typedef struct ref_globals_s
{
qboolean developer;
@ -108,6 +123,7 @@ typedef struct ref_interface_s @@ -108,6 +123,7 @@ typedef struct ref_interface_s
void (*GL_SetRenderMode)( int renderMode );
int (*R_AddEntity)( int entityType, cl_entity_t *ent );
void (*CL_AddCustomBeam)( cl_entity_t *pEnvBeam );
// view info
qboolean (*IsNormalPass)( void );
@ -156,10 +172,12 @@ typedef struct ref_interface_s @@ -156,10 +172,12 @@ typedef struct ref_interface_s
// studio interface
float (*R_StudioEstimateFrame)( cl_entity_t *e, mstudioseqdesc_t *pseqdesc );
void (*R_StudioLerpMovement)( cl_entity_t *e, double time, vec3_t origin, vec3_t angles );
void (*CL_InitStudioAPI)( void );
// bmodel
void (*R_InitSkyClouds)( struct mip_s *mt, struct texture_s *tx, qboolean custom_palette );
void (*GL_SubdivideSurface)( msurface_t *fa );
void (*CL_RunLightStyles)( void );
// sprites
void (*R_GetSpriteParms)( int *frameWidth, int *frameHeight, int *numFrames, int currentFrame, const model_t *pSprite );
@ -175,6 +193,12 @@ typedef struct ref_interface_s @@ -175,6 +193,12 @@ typedef struct ref_interface_s
// particle renderer
void (*CL_Particle)( const vec3_t origin, int color, float life, int zpos, int zvel ); // debug thing
// efx implementation
void (*CL_DrawParticles)( double frametime, particle_t *particles );
void (*CL_DrawTracers)( double frametime, particle_t *tracers );
void (*CL_DrawBeams)( int fTrans , BEAM *beams );
qboolean (*R_BeamCull)( const vec3_t start, const vec3_t end, qboolean pvsOnly );
// Xash3D Render Interface
render_api_t *RenderAPI; // partial RenderAPI implementation
render_interface_t *RenderIface; // compatible RenderInterface implementation: renderer should call client RenderInterface by itself

92
common/xash3d_types.h

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
// basic typedefs
#ifndef XASH_TYPES_H
#define XASH_TYPES_H
typedef unsigned char byte;
typedef int sound_t;
typedef float vec_t;
@ -30,4 +31,95 @@ typedef Uint64 integer64; @@ -30,4 +31,95 @@ typedef Uint64 integer64;
typedef unsigned long long integer64;
#endif
typedef integer64 longtime_t;
#define MAX_STRING 256 // generic string
#define MAX_INFO_STRING 256 // infostrings are transmitted across network
#define MAX_SERVERINFO_STRING 512 // server handles too many settings. expand to 1024?
#define MAX_LOCALINFO_STRING 32768 // localinfo used on server and not sended to the clients
#define MAX_SYSPATH 1024 // system filepath
#define MAX_PRINT_MSG 8192 // how many symbols can handle single call of Con_Printf or Con_DPrintf
#define MAX_TOKEN 2048 // parse token length
#define MAX_MODS 512 // environment games that engine can keep visible
#define MAX_USERMSG_LENGTH 2048 // don't modify it's relies on a client-side definitions
#define BIT( n ) ( 1 << ( n ))
#define GAMMA ( 2.2 ) // Valve Software gamma
#define INVGAMMA ( 1.0 / 2.2 ) // back to 1.0
#define TEXGAMMA ( 0.9 ) // compensate dim textures
#define SetBits( iBitVector, bits ) ((iBitVector) = (iBitVector) | (bits))
#define ClearBits( iBitVector, bits ) ((iBitVector) = (iBitVector) & ~(bits))
#define FBitSet( iBitVector, bit ) ((iBitVector) & (bit))
#ifndef __cplusplus
#ifdef NULL
#undef NULL
#endif
#define NULL ((void *)0)
#endif
// color strings
#define IsColorString( p ) ( p && *( p ) == '^' && *(( p ) + 1) && *(( p ) + 1) >= '0' && *(( p ) + 1 ) <= '9' )
#define ColorIndex( c ) ((( c ) - '0' ) & 7 )
#if defined __i386__ && defined __GNUC__
#define GAME_EXPORT __attribute__((force_align_arg_pointer))
#else
#define GAME_EXPORT
#endif
#ifdef XASH_BIG_ENDIAN
#define LittleLong(x) (((int)(((x)&255)<<24)) + ((int)((((x)>>8)&255)<<16)) + ((int)(((x)>>16)&255)<<8) + (((x) >> 24)&255))
#define LittleLongSW(x) (x = LittleLong(x) )
#define LittleShort(x) ((short)( (((short)(x) >> 8) & 255) + (((short)(x) & 255) << 8)))
#define LittleShortSW(x) (x = LittleShort(x) )
_inline float LittleFloat( float f )
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
#else
#define LittleLong(x) (x)
#define LittleLongSW(x)
#define LittleShort(x) (x)
#define LittleShortSW(x)
#define LittleFloat(x) (x)
#endif
typedef unsigned int dword;
typedef unsigned int uint;
typedef char string[MAX_STRING];
typedef struct file_s file_t; // normal file
typedef struct wfile_s wfile_t; // wad file
typedef struct stream_s stream_t; // sound stream for background music playing
typedef off_t fs_offset_t;
typedef struct dllfunc_s
{
const char *name;
void **func;
} dllfunc_t;
typedef struct dll_info_s
{
const char *name; // name of library
const dllfunc_t *fcts; // list of dll exports
qboolean crash; // crash if dll not found
void *link; // hinstance of loading library
} dll_info_t;
#endif // XASH_TYPES_H

2115
engine/client/cl_efx.c

File diff suppressed because it is too large Load Diff

4
engine/client/cl_frame.c

@ -965,7 +965,7 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) @@ -965,7 +965,7 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType )
if( entityType == ET_BEAM )
{
CL_AddCustomBeam( ent );
ref.dllFuncs.CL_AddCustomBeam( ent );
return true;
}
else if( !ref.dllFuncs.R_AddEntity( ent, entityType ))
@ -1299,7 +1299,7 @@ void CL_EmitEntities( void ) @@ -1299,7 +1299,7 @@ void CL_EmitEntities( void )
return;
// animate lightestyles
CL_RunLightStyles ();
ref.dllFuncs.CL_RunLightStyles ();
// decay dynamic lights
CL_DecayLights ();

10
engine/client/cl_game.c

@ -3614,6 +3614,7 @@ triangleapi_t gTriApi; @@ -3614,6 +3614,7 @@ triangleapi_t gTriApi;
static efx_api_t gEfxApi =
{
#if 1
R_AllocParticle,
R_BlobExplosion,
R_Blood,
@ -3688,6 +3689,7 @@ static efx_api_t gEfxApi = @@ -3688,6 +3689,7 @@ static efx_api_t gEfxApi =
R_LookupColor,
CL_DecalRemoveAll,
CL_FireCustomDecal,
#endif
};
static event_api_t gEventApi =
@ -4041,13 +4043,7 @@ qboolean CL_LoadProgs( const char *name ) @@ -4041,13 +4043,7 @@ qboolean CL_LoadProgs( const char *name )
// initialize game
clgame.dllFuncs.pfnInit();
CL_InitStudioAPI( );
// trying to grab them from client.dll
cl_righthand = Cvar_FindVar( "cl_righthand" );
if( cl_righthand == NULL )
cl_righthand = Cvar_Get( "cl_righthand", "0", FCVAR_ARCHIVE, "flip viewmodel (left to right)" );
ref.dllFuncs.CL_InitStudioAPI();
return true;
}

1
engine/client/cl_scrn.c

@ -730,7 +730,6 @@ void SCR_Init( void ) @@ -730,7 +730,6 @@ void SCR_Init( void )
scr_viewsize = Cvar_Get( "viewsize", "120", FCVAR_ARCHIVE, "screen size" );
// register our commands
Cmd_AddCommand( "timerefresh", SCR_TimeRefresh_f, "turn quickly and print rendering statistcs" );
Cmd_AddCommand( "skyname", CL_SetSky_f, "set new skybox by basename" );
Cmd_AddCommand( "loadsky", CL_SetSky_f, "set new skybox by basename" );
Cmd_AddCommand( "viewpos", SCR_Viewpos_f, "prints current player origin" );

3
engine/client/cl_tent.c

@ -2012,6 +2012,8 @@ void R_Sprite_WallPuff( TEMPENTITY *pTemp, float scale ) @@ -2012,6 +2012,8 @@ void R_Sprite_WallPuff( TEMPENTITY *pTemp, float scale )
pTemp->die = cl.time + 0.01f;
}
/*
==============
CL_ParseTempEntity
@ -3151,3 +3153,4 @@ void CL_ClearEffects( void ) @@ -3151,3 +3153,4 @@ void CL_ClearEffects( void )
CL_ClearParticles ();
CL_ClearLightStyles ();
}

26
engine/client/client.h

@ -33,20 +33,6 @@ GNU General Public License for more details. @@ -33,20 +33,6 @@ GNU General Public License for more details.
#include "world.h"
#include "ref_common.h"
#define MAX_DEMOS 32
#define MAX_MOVIES 8
#define MAX_CDTRACKS 32
#define MAX_CLIENT_SPRITES 256 // SpriteTextures
#define MAX_EFRAGS 8192 // Arcane Dimensions required
#define MAX_REQUESTS 64
// screenshot types
#define VID_SCREENSHOT 0
#define VID_LEVELSHOT 1
#define VID_MINISHOT 2
#define VID_MAPSHOT 3 // special case for overview layer
#define VID_SNAPSHOT 4 // save screenshot into root dir and no gamma correction
// client sprite types
#define SPR_CLIENT 0 // client sprite for temp-entities or user-textures
#define SPR_HUDSPRITE 1 // hud sprite
@ -167,13 +153,6 @@ typedef struct @@ -167,13 +153,6 @@ typedef struct
float weaponstarttime;
} cl_local_data_t;
typedef struct
{
char name[MAX_OSPATH];
char modelname[MAX_OSPATH];
model_t *model;
} player_model_t;
typedef struct
{
qboolean bUsed;
@ -238,7 +217,6 @@ typedef struct @@ -238,7 +217,6 @@ typedef struct
float timedelta; // floating delta between two updates
char serverinfo[MAX_SERVERINFO_STRING];
player_model_t player_models[MAX_CLIENTS]; // cache of player models
player_info_t players[MAX_CLIENTS]; // collected info about all other players include himself
double lastresourcecheck;
string downloadUrl;
@ -1007,8 +985,6 @@ int CL_FxBlend( cl_entity_t *e ); @@ -1007,8 +985,6 @@ int CL_FxBlend( cl_entity_t *e );
void CL_InitParticles( void );
void CL_ClearParticles( void );
void CL_FreeParticles( void );
void CL_DrawParticles( double frametime );
void CL_DrawTracers( double frametime );
void CL_InitTempEnts( void );
void CL_ClearTempEnts( void );
void CL_FreeTempEnts( void );
@ -1016,8 +992,6 @@ void CL_TempEntUpdate( void ); @@ -1016,8 +992,6 @@ void CL_TempEntUpdate( void );
void CL_InitViewBeams( void );
void CL_ClearViewBeams( void );
void CL_FreeViewBeams( void );
void CL_DrawBeams( int fTrans );
void CL_AddCustomBeam( cl_entity_t *pEnvBeam );
void CL_KillDeadBeams( cl_entity_t *pDeadEntity );
void CL_ParseViewBeam( sizebuf_t *msg, int beamType );
void CL_LoadClientSprites( void );

11
engine/client/ref_common.c

@ -8,10 +8,9 @@ ref_globals_t refState; @@ -8,10 +8,9 @@ ref_globals_t refState;
convar_t *gl_vsync;
convar_t *gl_showtextures;
convar_t *vid_displayfrequency;
convar_t *vid_fullscreen;
convar_t *r_decals;
convar_t *r_adjust_fov;
convar_t *gl_wgl_msaa_samples;
void R_GetTextureParms( int *w, int *h, int texnum )
{
@ -19,12 +18,6 @@ void R_GetTextureParms( int *w, int *h, int texnum ) @@ -19,12 +18,6 @@ void R_GetTextureParms( int *w, int *h, int texnum )
if( h ) *h = RENDER_GET_PARM( PARM_TEX_HEIGHT, texnum );
}
void VID_InitDefaultResolution( void )
{
refState.width = 640;
refState.height = 480;
}
/*
================
GL_FreeImage
@ -175,8 +168,6 @@ void R_Init( void ) @@ -175,8 +168,6 @@ void R_Init( void )
gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" );
gl_showtextures = Cvar_Get( "gl_showtextures", "0", FCVAR_CHEAT, "show all uploaded textures" );
vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen refresh rate" );
vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
r_adjust_fov = Cvar_Get( "r_adjust_fov", "1", FCVAR_ARCHIVE, "making FOV adjustment for wide-screens" );
r_decals = Cvar_Get( "r_decals", "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" );

9
engine/client/ref_common.h

@ -18,11 +18,6 @@ GNU General Public License for more details. @@ -18,11 +18,6 @@ GNU General Public License for more details.
#include "ref_api.h"
#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP)
#define TF_FONT (TF_NOMIPMAP|TF_CLAMP)
#define TF_IMAGE (TF_NOMIPMAP|TF_CLAMP)
#define TF_DECAL (TF_CLAMP)
#define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( cl.playernum + 1 ) && e->player )
struct ref_state_s
@ -48,7 +43,7 @@ void R_GetTextureParms( int *w, int *h, int texnum ); @@ -48,7 +43,7 @@ void R_GetTextureParms( int *w, int *h, int texnum );
extern convar_t *r_decals;
extern convar_t *r_adjust_fov;
extern convar_t *vid_fullscreen;
extern convar_t *vid_displayfrequency;
void R_Init( void );
void R_Shutdown( void );
#endif // REF_COMMON_H

532
engine/client/vid_common.c

@ -21,189 +21,18 @@ GNU General Public License for more details. @@ -21,189 +21,18 @@ GNU General Public License for more details.
#include "platform/platform.h"
#define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life
convar_t *gl_extensions;
convar_t *gl_texture_anisotropy;
convar_t *gl_texture_lodbias;
convar_t *gl_texture_nearest;
convar_t *gl_wgl_msaa_samples;
convar_t *gl_lightmap_nearest;
convar_t *gl_keeptjunctions;
convar_t *gl_emboss_scale;
convar_t *gl_detailscale;
convar_t *gl_check_errors;
convar_t *gl_polyoffset;
convar_t *gl_wireframe;
convar_t *gl_finish;
convar_t *gl_nosort;
convar_t *gl_vsync;
convar_t *gl_clear;
convar_t *gl_test;
convar_t *gl_msaa;
convar_t *gl_stencilbits;
convar_t *window_xpos;
convar_t *window_ypos;
convar_t *r_speeds;
convar_t *r_fullbright;
convar_t *r_norefresh;
convar_t *r_showtree;
convar_t *r_lighting_extended;
convar_t *r_lighting_modulate;
convar_t *r_lighting_ambient;
convar_t *r_detailtextures;
convar_t *r_drawentities;
convar_t *r_adjust_fov;
convar_t *r_decals;
convar_t *r_novis;
convar_t *r_nocull;
convar_t *r_lockpvs;
convar_t *r_lockfrustum;
convar_t *r_traceglow;
convar_t *r_dynamic;
convar_t *r_lightmap;
convar_t *gl_round_down;
convar_t *r_vbo;
convar_t *r_vbo_dlightmode;
convar_t *vid_displayfrequency;
convar_t *vid_fullscreen;
convar_t *vid_brightness;
convar_t *vid_gamma;
convar_t *vid_highdpi;
byte *r_temppool;
gl_globals_t tr;
glconfig_t glConfig;
glstate_t glState;
vidstate_t vidState;
glwstate_t glw_state;
glcontext_t glContext;
/*
=================
GL_SetExtension
=================
*/
void GL_SetExtension( int r_ext, int enable )
{
if( r_ext >= 0 && r_ext < GL_EXTCOUNT )
glConfig.extension[r_ext] = enable ? GL_TRUE : GL_FALSE;
else Con_Printf( S_ERROR "GL_SetExtension: invalid extension %d\n", r_ext );
}
/*
=================
GL_Support
=================
*/
qboolean GL_Support( int r_ext )
{
if( r_ext >= 0 && r_ext < GL_EXTCOUNT )
return glConfig.extension[r_ext] ? true : false;
Con_Printf( S_ERROR "GL_Support: invalid extension %d\n", r_ext );
return false;
}
/*
=================
GL_MaxTextureUnits
=================
*/
int GL_MaxTextureUnits( void )
{
if( GL_Support( GL_SHADER_GLSL100_EXT ))
return Q_min( Q_max( glConfig.max_texture_coords, glConfig.max_teximage_units ), MAX_TEXTURE_UNITS );
return glConfig.max_texture_units;
}
/*
=================
GL_CheckExtension
=================
*/
void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext )
{
const dllfunc_t *func;
convar_t *parm = NULL;
const char *extensions_string;
Con_Reportf( "GL_CheckExtension: %s ", name );
GL_SetExtension( r_ext, true );
if( cvarname )
{
// system config disable extensions
parm = Cvar_Get( cvarname, "1", FCVAR_GLCONFIG, va( CVAR_GLCONFIG_DESCRIPTION, name ));
}
if(( parm && !CVAR_TO_BOOL( parm )) || ( !CVAR_TO_BOOL( gl_extensions ) && r_ext != GL_OPENGL_110 ))
{
Con_Reportf( "- disabled\n" );
GL_SetExtension( r_ext, false );
return; // nothing to process at
}
extensions_string = glConfig.extensions_string;
if(( name[2] == '_' || name[3] == '_' ) && !Q_strstr( extensions_string, name ))
{
GL_SetExtension( r_ext, false ); // update render info
Con_Reportf( "- ^1failed\n" );
return;
}
// clear exports
for( func = funcs; func && func->name; func++ )
*func->func = NULL;
for( func = funcs; func && func->name != NULL; func++ )
{
// functions are cleared before all the extensions are evaluated
if((*func->func = (void *)GL_GetProcAddress( func->name )) == NULL )
GL_SetExtension( r_ext, false ); // one or more functions are invalid, extension will be disabled
}
if( GL_Support( r_ext ))
Con_Reportf( "- ^2enabled\n" );
else Con_Reportf( "- ^1failed\n" );
}
/*
===============
GL_SetDefaultTexState
===============
*/
static void GL_SetDefaultTexState( void )
{
int i;
memset( glState.currentTextures, -1, MAX_TEXTURE_UNITS * sizeof( *glState.currentTextures ));
memset( glState.texCoordArrayMode, 0, MAX_TEXTURE_UNITS * sizeof( *glState.texCoordArrayMode ));
memset( glState.genSTEnabled, 0, MAX_TEXTURE_UNITS * sizeof( *glState.genSTEnabled ));
for( i = 0; i < MAX_TEXTURE_UNITS; i++ )
{
glState.currentTextureTargets[i] = GL_NONE;
glState.texIdentityMatrix[i] = true;
}
}
/*
===============
GL_SetDefaultState
===============
*/
static void GL_SetDefaultState( void )
{
memset( &glState, 0, sizeof( glState ));
GL_SetDefaultTexState ();
// init draw stack
tr.draw_list = &tr.draw_stack[0];
tr.draw_stack_pos = 0;
}
convar_t *window_xpos;
convar_t *window_ypos;
/*
=================
VID_StartupGamma
@ -226,8 +55,8 @@ void VID_InitDefaultResolution( void ) @@ -226,8 +55,8 @@ void VID_InitDefaultResolution( void )
{
// we need to have something valid here
// until video subsystem initialized
glState.width = 640;
glState.height = 480;
vidState.width = 640;
vidState.height = 480;
}
/*
@ -237,8 +66,8 @@ R_SaveVideoMode @@ -237,8 +66,8 @@ R_SaveVideoMode
*/
void R_SaveVideoMode( int w, int h )
{
glState.width = w;
glState.height = h;
vidState.width = w;
vidState.height = h;
host.window_center_x = w / 2;
host.window_center_y = h / 2;
@ -248,8 +77,8 @@ void R_SaveVideoMode( int w, int h ) @@ -248,8 +77,8 @@ void R_SaveVideoMode( int w, int h )
// check for 4:3 or 5:4
if( w * 3 != h * 4 && w * 4 != h * 5 )
glState.wideScreen = true;
else glState.wideScreen = false;
vidState.wideScreen = true;
else vidState.wideScreen = false;
}
/*
@ -280,7 +109,7 @@ void VID_CheckChanges( void ) @@ -280,7 +109,7 @@ void VID_CheckChanges( void )
{
if( FBitSet( cl_allow_levelshots->flags, FCVAR_CHANGED ))
{
GL_FreeTexture( cls.loadingBar );
//GL_FreeTexture( cls.loadingBar );
SCR_RegisterTextures(); // reload 'lambda' image
ClearBits( cl_allow_levelshots->flags, FCVAR_CHANGED );
}
@ -299,96 +128,6 @@ void VID_CheckChanges( void ) @@ -299,96 +128,6 @@ void VID_CheckChanges( void )
}
}
/*
===============
GL_SetDefaults
===============
*/
static void GL_SetDefaults( void )
{
pglFinish();
pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f );
pglDisable( GL_DEPTH_TEST );
pglDisable( GL_CULL_FACE );
pglDisable( GL_SCISSOR_TEST );
pglDepthFunc( GL_LEQUAL );
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
if( glState.stencilEnabled )
{
pglDisable( GL_STENCIL_TEST );
pglStencilMask( ( GLuint ) ~0 );
pglStencilFunc( GL_EQUAL, 0, ~0 );
pglStencilOp( GL_KEEP, GL_INCR, GL_INCR );
}
pglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
pglPolygonOffset( -1.0f, -2.0f );
GL_CleanupAllTextureUnits();
pglDisable( GL_BLEND );
pglDisable( GL_ALPHA_TEST );
pglDisable( GL_POLYGON_OFFSET_FILL );
pglAlphaFunc( GL_GREATER, DEFAULT_ALPHATEST );
pglEnable( GL_TEXTURE_2D );
pglShadeModel( GL_SMOOTH );
pglFrontFace( GL_CCW );
pglPointSize( 1.2f );
pglLineWidth( 1.2f );
GL_Cull( GL_NONE );
}
/*
=================
R_RenderInfo_f
=================
*/
void R_RenderInfo_f( void )
{
Con_Printf( "\n" );
Con_Printf( "GL_VENDOR: %s\n", glConfig.vendor_string );
Con_Printf( "GL_RENDERER: %s\n", glConfig.renderer_string );
Con_Printf( "GL_VERSION: %s\n", glConfig.version_string );
// don't spam about extensions
if( host_developer.value >= DEV_EXTENDED )
{
Con_Printf( "GL_EXTENSIONS: %s\n", glConfig.extensions_string );
}
Con_Printf( "GL_MAX_TEXTURE_SIZE: %i\n", glConfig.max_2d_texture_size );
if( GL_Support( GL_ARB_MULTITEXTURE ))
Con_Printf( "GL_MAX_TEXTURE_UNITS_ARB: %i\n", glConfig.max_texture_units );
if( GL_Support( GL_TEXTURE_CUBEMAP_EXT ))
Con_Printf( "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB: %i\n", glConfig.max_cubemap_size );
if( GL_Support( GL_ANISOTROPY_EXT ))
Con_Printf( "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: %.1f\n", glConfig.max_texture_anisotropy );
if( GL_Support( GL_TEXTURE_2D_RECT_EXT ))
Con_Printf( "GL_MAX_RECTANGLE_TEXTURE_SIZE: %i\n", glConfig.max_2d_rectangle_size );
if( GL_Support( GL_TEXTURE_ARRAY_EXT ))
Con_Printf( "GL_MAX_ARRAY_TEXTURE_LAYERS_EXT: %i\n", glConfig.max_2d_texture_layers );
if( GL_Support( GL_SHADER_GLSL100_EXT ))
{
Con_Printf( "GL_MAX_TEXTURE_COORDS_ARB: %i\n", glConfig.max_texture_coords );
Con_Printf( "GL_MAX_TEXTURE_IMAGE_UNITS_ARB: %i\n", glConfig.max_teximage_units );
Con_Printf( "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB: %i\n", glConfig.max_vertex_uniforms );
Con_Printf( "GL_MAX_VERTEX_ATTRIBS_ARB: %i\n", glConfig.max_vertex_attribs );
}
Con_Printf( "\n" );
Con_Printf( "MODE: %ix%i\n", glState.width, glState.height );
Con_Printf( "\n" );
Con_Printf( "VERTICAL SYNC: %s\n", gl_vsync->value ? "enabled" : "disabled" );
Con_Printf( "Color %d bits, Alpha %d bits, Depth %d bits, Stencil %d bits\n", glConfig.color_bits,
glConfig.alpha_bits, glConfig.depth_bits, glConfig.stencil_bits );
}
static void VID_Mode_f( void )
{
int w, h;
@ -424,86 +163,6 @@ static void VID_Mode_f( void ) @@ -424,86 +163,6 @@ static void VID_Mode_f( void )
R_ChangeDisplaySettings( w, h, Cvar_VariableInteger( "fullscreen" ) );
}
//=======================================================================
/*
=================
GL_InitCommands
=================
*/
void GL_InitCommands( void )
{
// system screen width and height (don't suppose for change from console at all)
Cvar_Get( "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" );
Cvar_Get( "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
r_speeds = Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" );
r_fullbright = Cvar_Get( "r_fullbright", "0", FCVAR_CHEAT, "disable lightmaps, get fullbright for entities" );
r_norefresh = Cvar_Get( "r_norefresh", "0", 0, "disable 3D rendering (use with caution)" );
r_showtree = Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" );
r_lighting_extended = Cvar_Get( "r_lighting_extended", "1", FCVAR_ARCHIVE, "allow to get lighting from world and bmodels" );
r_lighting_modulate = Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" );
r_lighting_ambient = Cvar_Get( "r_lighting_ambient", "0.3", FCVAR_ARCHIVE, "map ambient lighting scale" );
r_novis = Cvar_Get( "r_novis", "0", 0, "ignore vis information (perfomance test)" );
r_nocull = Cvar_Get( "r_nocull", "0", 0, "ignore frustrum culling (perfomance test)" );
r_detailtextures = Cvar_Get( "r_detailtextures", "1", FCVAR_ARCHIVE, "enable detail textures support, use '2' for autogenerate detail.txt" );
r_lockpvs = Cvar_Get( "r_lockpvs", "0", FCVAR_CHEAT, "lockpvs area at current point (pvs test)" );
r_lockfrustum = Cvar_Get( "r_lockfrustum", "0", FCVAR_CHEAT, "lock frustrum area at current point (cull test)" );
r_dynamic = Cvar_Get( "r_dynamic", "1", FCVAR_ARCHIVE, "allow dynamic lighting (dlights, lightstyles)" );
r_traceglow = Cvar_Get( "r_traceglow", "1", FCVAR_ARCHIVE, "cull flares behind models" );
r_lightmap = Cvar_Get( "r_lightmap", "0", FCVAR_CHEAT, "lightmap debugging tool" );
r_drawentities = Cvar_Get( "r_drawentities", "1", FCVAR_CHEAT, "render entities" );
r_decals = engine.Cvar_Find( "r_decals" );
window_xpos = Cvar_Get( "_window_xpos", "130", FCVAR_RENDERINFO, "window position by horizontal" );
window_ypos = Cvar_Get( "_window_ypos", "48", FCVAR_RENDERINFO, "window position by vertical" );
gl_extensions = Cvar_Get( "gl_allow_extensions", "1", FCVAR_GLCONFIG, "allow gl_extensions" );
gl_texture_nearest = Cvar_Get( "gl_texture_nearest", "0", FCVAR_ARCHIVE, "disable texture filter" );
gl_lightmap_nearest = Cvar_Get( "gl_lightmap_nearest", "0", FCVAR_ARCHIVE, "disable lightmap filter" );
gl_check_errors = Cvar_Get( "gl_check_errors", "1", FCVAR_ARCHIVE, "ignore video engine errors" );
gl_vsync = engine.Cvar_Find( "gl_vsync" );
gl_detailscale = Cvar_Get( "gl_detailscale", "4.0", FCVAR_ARCHIVE, "default scale applies while auto-generate list of detail textures" );
gl_texture_anisotropy = Cvar_Get( "gl_anisotropy", "8", FCVAR_ARCHIVE, "textures anisotropic filter" );
gl_texture_lodbias = Cvar_Get( "gl_texture_lodbias", "0.0", FCVAR_ARCHIVE, "LOD bias for mipmapped textures (perfomance|quality)" );
gl_keeptjunctions = Cvar_Get( "gl_keeptjunctions", "1", FCVAR_ARCHIVE, "removing tjuncs causes blinking pixels" );
gl_emboss_scale = Cvar_Get( "gl_emboss_scale", "0", FCVAR_ARCHIVE|FCVAR_LATCH, "fake bumpmapping scale" );
gl_showtextures = engine.Cvar_Find( "r_showtextures" );
gl_finish = Cvar_Get( "gl_finish", "0", FCVAR_ARCHIVE, "use glFinish instead of glFlush" );
gl_nosort = Cvar_Get( "gl_nosort", "0", FCVAR_ARCHIVE, "disable sorting of translucent surfaces" );
gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" );
gl_test = Cvar_Get( "gl_test", "0", 0, "engine developer cvar for quick testing new features" );
gl_wireframe = Cvar_Get( "gl_wireframe", "0", FCVAR_ARCHIVE|FCVAR_SPONLY, "show wireframe overlay" );
gl_wgl_msaa_samples = Cvar_Get( "gl_wgl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" );
gl_msaa = Cvar_Get( "gl_msaa", "1", FCVAR_ARCHIVE, "enable or disable multisample anti-aliasing" );
gl_stencilbits = Cvar_Get( "gl_stencilbits", "8", FCVAR_GLCONFIG, "pixelformat stencil bits (0 - auto)" );
gl_round_down = Cvar_Get( "gl_round_down", "2", FCVAR_RENDERINFO, "round texture sizes to nearest POT value" );
// these cvar not used by engine but some mods requires this
gl_polyoffset = Cvar_Get( "gl_polyoffset", "2.0", FCVAR_ARCHIVE, "polygon offset for decals" );
// make sure gl_vsync is checked after vid_restart
SetBits( gl_vsync->flags, FCVAR_CHANGED );
vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
vid_fullscreen = engine.Cvar_Find( "fullscreen" );
vid_displayfrequency = engine.Cvar_Find ( "vid_displayfrequency" );
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
Cmd_AddCommand( "r_info", R_RenderInfo_f, "display renderer info" );
// a1ba: planned to be named vid_mode for compability
// but supported mode list is filled by backends, so numbers are not portable any more
Cmd_AddCommand( "vid_setmode", VID_Mode_f, "display video mode" );
// give initial OpenGL configuration
host.apply_opengl_config = true;
Cbuf_AddText( "exec opengl.cfg\n" );
Cbuf_Execute();
host.apply_opengl_config = false;
// apply actual video mode to window
Cbuf_AddText( "exec video.cfg\n" );
Cbuf_Execute();
}
/*
=================
@ -545,171 +204,8 @@ static void SetFullscreenModeFromCommandLine( ) @@ -545,171 +204,8 @@ static void SetFullscreenModeFromCommandLine( )
#endif
}
/*
===============
R_CheckVBO
register VBO cvars and get default value
===============
*/
static void R_CheckVBO( void )
{
const char *def = "1";
const char *dlightmode = "1";
int flags = FCVAR_ARCHIVE;
qboolean disable = false;
// some bad GLES1 implementations breaks dlights completely
if( glConfig.max_texture_units < 3 )
disable = true;
#ifdef XASH_MOBILE_PLATFORM
// VideoCore4 drivers have a problem with mixing VBO and client arrays
// Disable it, as there is no suitable workaround here
if( Q_stristr( glConfig.renderer_string, "VideoCore IV" ) || Q_stristr( glConfig.renderer_string, "vc4" ) )
disable = true;
// dlightmode 1 is not too much tested on android
// so better to left it off
dlightmode = "0";
#endif
if( disable )
{
// do not keep in config unless dev > 3 and enabled
flags = 0;
def = "0";
}
r_vbo = Cvar_Get( "r_vbo", def, flags, "draw world using VBO" );
r_vbo_dlightmode = Cvar_Get( "r_vbo_dlightmode", dlightmode, FCVAR_ARCHIVE, "vbo dlight rendering mode(0-1)" );
// check if enabled manually
if( CVAR_TO_BOOL(r_vbo) )
r_vbo->flags |= FCVAR_ARCHIVE;
}
/*
===============
R_Init
===============
*/
qboolean R_Init( void )
{
if( glw_state.initialized )
return true;
GL_InitCommands();
GL_InitRandomTable();
// Set screen resolution and fullscreen mode if passed in on command line.
// This is done after executing opengl.cfg, as the command line values should take priority.
SetWidthAndHeightFromCommandLine();
SetFullscreenModeFromCommandLine();
GL_SetDefaultState();
// create the window and set up the context
if( !R_Init_Video( ))
{
GL_RemoveCommands();
R_Free_Video();
Sys_Error( "Can't initialize video subsystem\nProbably driver was not installed" );
return false;
}
host.renderinfo_changed = false;
r_temppool = Mem_AllocPool( "Render Zone" );
GL_SetDefaults();
R_CheckVBO();
R_InitImages();
R_SpriteInit();
R_StudioInit();
R_AliasInit();
R_ClearDecals();
R_ClearScene();
// initialize screen
SCR_Init();
return true;
}
/*
===============
R_Shutdown
===============
*/
void R_Shutdown( void )
{
model_t *mod;
int i;
if( !glw_state.initialized )
return;
// release SpriteTextures
for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ )
{
if( !mod->name[0] ) continue;
Mod_UnloadSpriteModel( mod );
}
memset( clgame.sprites, 0, sizeof( clgame.sprites ));
GL_RemoveCommands();
R_ShutdownImages();
Mem_FreePool( &r_temppool );
// shut down OS specific OpenGL stuff like contexts, etc.
R_Free_Video();
}
/*
=================
GL_ErrorString
convert errorcode to string
=================
*/
const char *GL_ErrorString( int err )
{
switch( err )
{
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
default:
return "UNKNOWN ERROR";
}
}
/*
=================
GL_CheckForErrors
obsolete
=================
*/
void GL_CheckForErrors_( const char *filename, const int fileline )
void VID_Init()
{
int err;
if( !CVAR_TO_BOOL( gl_check_errors ))
return;
if(( err = pglGetError( )) == GL_NO_ERROR )
return;
Con_Printf( S_OPENGL_ERROR "%s (called at %s:%i)\n", GL_ErrorString( err ), filename, fileline );
vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen refresh rate" );
vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
}

78
engine/client/vid_common.h

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
#define FCONTEXT_CORE_PROFILE BIT( 0 )
#define FCONTEXT_DEBUG_ARB BIT( 1 )
#if 0
#define GL_CheckForErrors() GL_CheckForErrors_( __FILE__, __LINE__ )
void GL_CheckForErrors_( const char *filename, const int fileline );
const char *GL_ErrorString( int err );
@ -13,5 +13,81 @@ qboolean GL_Support( int r_ext ); @@ -13,5 +13,81 @@ qboolean GL_Support( int r_ext );
int GL_MaxTextureUnits( void );
void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext );
void GL_SetExtension( int r_ext, int enable );
#endif
typedef struct vidmode_s
{
const char *desc;
int width;
int height;
} vidmode_t;
typedef enum
{
SAFE_NO = 0,
SAFE_NOMSAA, // skip msaa
SAFE_NOACC, // don't set acceleration flag
SAFE_NOSTENCIL, // don't set stencil bits
SAFE_NOALPHA, // don't set alpha bits
SAFE_NODEPTH, // don't set depth bits
SAFE_NOCOLOR, // don't set color bits
SAFE_DONTCARE // ignore everything, let SDL/EGL decide
} safe_context_t;
typedef struct
{
void* context; // handle to GL rendering context
int safe;
int desktopBitsPixel;
int desktopWidth;
int desktopHeight;
qboolean initialized; // OpenGL subsystem started
qboolean extended; // extended context allows to GL_Debug
} glwstate_t;
typedef struct vidstate_s
{
int width, height;
int prev_width, prev_height;
qboolean fullScreen;
qboolean wideScreen;
} vidstate_t;
// engine will manage opengl contexts with window system (egl/sdl or wgl/glx if needed)
typedef struct glcontext_s
{
/// make renderapi defs acessible here?
// gl_context_type_t context;
// gles_wrapper_t wrapper;
int color_bits;
int alpha_bits;
int depth_bits;
int stencil_bits;
int msaasamples;
int max_multisamples;
} glcontext_t;
extern vidstate_t vidState;
extern glwstate_t glw_state;
extern glcontext_t glContext;
#define VID_MIN_HEIGHT 200
#define VID_MIN_WIDTH 320
extern convar_t *vid_fullscreen;
extern convar_t *vid_displayfrequency;
extern convar_t *vid_highdpi;
extern convar_t *gl_wgl_msaa_samples;
void R_SaveVideoMode( int w, int h );
void VID_CheckChanges( void );
const char *VID_GetModeString( int vid_mode );
void VID_StartupGamma( void );
#endif // VID_COMMON

185
engine/common/common.h

@ -84,80 +84,6 @@ XASH SPECIFIC - sort of hack that works only in Xash3D not in GoldSrc @@ -84,80 +84,6 @@ XASH SPECIFIC - sort of hack that works only in Xash3D not in GoldSrc
#define HACKS_RELATED_HLMODS // some HL-mods works differently under Xash and can't be fixed without some hacks at least at current time
#define MAX_STRING 256 // generic string
#define MAX_INFO_STRING 256 // infostrings are transmitted across network
#define MAX_SERVERINFO_STRING 512 // server handles too many settings. expand to 1024?
#define MAX_LOCALINFO_STRING 32768 // localinfo used on server and not sended to the clients
#define MAX_SYSPATH 1024 // system filepath
#define MAX_PRINT_MSG 8192 // how many symbols can handle single call of Con_Printf or Con_DPrintf
#define MAX_TOKEN 2048 // parse token length
#define MAX_MODS 512 // environment games that engine can keep visible
#define MAX_USERMSG_LENGTH 2048 // don't modify it's relies on a client-side definitions
#define BIT( n ) ( 1 << ( n ))
#define GAMMA ( 2.2 ) // Valve Software gamma
#define INVGAMMA ( 1.0 / 2.2 ) // back to 1.0
#define TEXGAMMA ( 0.9 ) // compensate dim textures
#define SetBits( iBitVector, bits ) ((iBitVector) = (iBitVector) | (bits))
#define ClearBits( iBitVector, bits ) ((iBitVector) = (iBitVector) & ~(bits))
#define FBitSet( iBitVector, bit ) ((iBitVector) & (bit))
#ifndef __cplusplus
#ifdef NULL
#undef NULL
#endif
#define NULL ((void *)0)
#endif
// color strings
#define IsColorString( p ) ( p && *( p ) == '^' && *(( p ) + 1) && *(( p ) + 1) >= '0' && *(( p ) + 1 ) <= '9' )
#define ColorIndex( c ) ((( c ) - '0' ) & 7 )
#if defined __i386__ && defined __GNUC__
#define GAME_EXPORT __attribute__((force_align_arg_pointer))
#else
#define GAME_EXPORT
#endif
#ifdef XASH_BIG_ENDIAN
#define LittleLong(x) (((int)(((x)&255)<<24)) + ((int)((((x)>>8)&255)<<16)) + ((int)(((x)>>16)&255)<<8) + (((x) >> 24)&255))
#define LittleLongSW(x) (x = LittleLong(x) )
#define LittleShort(x) ((short)( (((short)(x) >> 8) & 255) + (((short)(x) & 255) << 8)))
#define LittleShortSW(x) (x = LittleShort(x) )
_inline float LittleFloat( float f )
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
#else
#define LittleLong(x) (x)
#define LittleLongSW(x)
#define LittleShort(x) (x)
#define LittleShortSW(x)
#define LittleFloat(x) (x)
#endif
typedef unsigned int dword;
typedef unsigned int uint;
typedef char string[MAX_STRING];
typedef struct file_s file_t; // normal file
typedef struct wfile_s wfile_t; // wad file
typedef struct stream_s stream_t; // sound stream for background music playing
typedef off_t fs_offset_t;
typedef void (*setpair_t)( const char *key, const char *value, void *buffer, void *numpairs );
@ -610,117 +536,11 @@ int FS_Close( file_t *file ); @@ -610,117 +536,11 @@ int FS_Close( file_t *file );
int FS_Getc( file_t *file );
fs_offset_t FS_FileLength( file_t *f );
/*
========================================================================
internal image format
typically expanded to rgba buffer
NOTE: number at end of pixelformat name it's a total bitscount e.g. PF_RGB_24 == PF_RGB_888
========================================================================
*/
#define ImageRAW( type ) (type == PF_RGBA_32 || type == PF_BGRA_32 || type == PF_RGB_24 || type == PF_BGR_24)
#define ImageDXT( type ) (type == PF_DXT1 || type == PF_DXT3 || type == PF_DXT5 || type == PF_ATI2)
typedef enum
{
PF_UNKNOWN = 0,
PF_INDEXED_24, // inflated palette (768 bytes)
PF_INDEXED_32, // deflated palette (1024 bytes)
PF_RGBA_32, // normal rgba buffer
PF_BGRA_32, // big endian RGBA (MacOS)
PF_RGB_24, // uncompressed dds or another 24-bit image
PF_BGR_24, // big-endian RGB (MacOS)
PF_DXT1, // s3tc DXT1 format
PF_DXT3, // s3tc DXT3 format
PF_DXT5, // s3tc DXT5 format
PF_ATI2, // latc ATI2N format
PF_TOTALCOUNT, // must be last
} pixformat_t;
typedef struct bpc_desc_s
{
int format; // pixelformat
char name[16]; // used for debug
uint glFormat; // RGBA format
int bpp; // channels (e.g. rgb = 3, rgba = 4)
} bpc_desc_t;
// imagelib global settings
typedef enum
{
IL_USE_LERPING = BIT(0), // lerping images during resample
IL_KEEP_8BIT = BIT(1), // don't expand paletted images
IL_ALLOW_OVERWRITE = BIT(2), // allow to overwrite stored images
IL_DONTFLIP_TGA = BIT(3), // Steam background completely ignore tga attribute 0x20 (stupid lammers!)
IL_DDS_HARDWARE = BIT(4), // DXT compression is support
IL_LOAD_DECAL = BIT(5), // special mode for load gradient decals
IL_OVERVIEW = BIT(6), // overview required some unque operations
} ilFlags_t;
// goes into rgbdata_t->encode
#define DXT_ENCODE_DEFAULT 0 // don't use custom encoders
#define DXT_ENCODE_COLOR_YCoCg 0x1A01 // make sure that value dosn't collide with anything
#define DXT_ENCODE_ALPHA_1BIT 0x1A02 // normal 1-bit alpha
#define DXT_ENCODE_ALPHA_8BIT 0x1A03 // normal 8-bit alpha
#define DXT_ENCODE_ALPHA_SDF 0x1A04 // signed distance field
#define DXT_ENCODE_NORMAL_AG_ORTHO 0x1A05 // orthographic projection
#define DXT_ENCODE_NORMAL_AG_STEREO 0x1A06 // stereographic projection
#define DXT_ENCODE_NORMAL_AG_PARABOLOID 0x1A07 // paraboloid projection
#define DXT_ENCODE_NORMAL_AG_QUARTIC 0x1A08 // newton method
#define DXT_ENCODE_NORMAL_AG_AZIMUTHAL 0x1A09 // Lambert Azimuthal Equal-Area
// rgbdata output flags
typedef enum
{
// rgbdata->flags
IMAGE_CUBEMAP = BIT(0), // it's 6-sides cubemap buffer
IMAGE_HAS_ALPHA = BIT(1), // image contain alpha-channel
IMAGE_HAS_COLOR = BIT(2), // image contain RGB-channel
IMAGE_COLORINDEX = BIT(3), // all colors in palette is gradients of last color (decals)
IMAGE_HAS_LUMA = BIT(4), // image has luma pixels (q1-style maps)
IMAGE_SKYBOX = BIT(5), // only used by FS_SaveImage - for write right suffixes
IMAGE_QUAKESKY = BIT(6), // it's a quake sky double layered clouds (so keep it as 8 bit)
IMAGE_DDS_FORMAT = BIT(7), // a hint for GL loader
IMAGE_MULTILAYER = BIT(8), // to differentiate from 3D texture
IMAGE_ONEBIT_ALPHA = BIT(9), // binary alpha
IMAGE_QUAKEPAL = BIT(10), // image has quake1 palette
// Image_Process manipulation flags
IMAGE_FLIP_X = BIT(16), // flip the image by width
IMAGE_FLIP_Y = BIT(17), // flip the image by height
IMAGE_ROT_90 = BIT(18), // flip from upper left corner to down right corner
IMAGE_ROT180 = IMAGE_FLIP_X|IMAGE_FLIP_Y,
IMAGE_ROT270 = IMAGE_FLIP_X|IMAGE_FLIP_Y|IMAGE_ROT_90,
IMAGE_EMBOSS = BIT(19), // apply emboss mapping
IMAGE_RESAMPLE = BIT(20), // resample image to specified dims
// reserved
// reserved
IMAGE_FORCE_RGBA = BIT(23), // force image to RGBA buffer
IMAGE_MAKE_LUMA = BIT(24), // create luma texture from indexed
IMAGE_QUANTIZE = BIT(25), // make indexed image from 24 or 32- bit image
IMAGE_LIGHTGAMMA = BIT(26), // apply gamma for image
IMAGE_REMAP = BIT(27), // interpret width and height as top and bottom color
} imgFlags_t;
typedef struct rgbdata_s
{
word width; // image width
word height; // image height
word depth; // image depth
uint type; // compression type
uint flags; // misc image flags
word encode; // DXT may have custom encoder, that will be decoded in GLSL-side
byte numMips; // mipmap count
byte *palette; // palette if present
byte *buffer; // image buffer
rgba_t fogParams; // some water textures in hl1 has info about fog color and alpha
size_t size; // for bounds checking
} rgbdata_t;
//
// imagelib
//
#include "com_image.h"
void Image_Init( void );
void Image_Shutdown( void );
void Image_AddCmdFlags( uint flags );
@ -738,7 +558,6 @@ qboolean Image_CustomPalette( void ); @@ -738,7 +558,6 @@ qboolean Image_CustomPalette( void );
void Image_ClearForceFlags( void );
void Image_SetMDLPointer( byte *p );
void Image_CheckPaletteQ1( void );
/*
========================================================================

19
engine/common/mod_local.h

@ -20,25 +20,6 @@ GNU General Public License for more details. @@ -20,25 +20,6 @@ GNU General Public License for more details.
#include "edict.h"
#include "eiface.h"
// 1/32 epsilon to keep floating point happy
#define DIST_EPSILON (1.0f / 32.0f)
#define FRAC_EPSILON (1.0f / 1024.0f)
#define BACKFACE_EPSILON 0.01f
#define MAX_BOX_LEAFS 256
#define ANIM_CYCLE 2
#define MOD_FRAMES 20
// remapping info
#define SUIT_HUE_START 192
#define SUIT_HUE_END 223
#define PLATE_HUE_START 160
#define PLATE_HUE_END 191
#define SHIRT_HUE_START 16
#define SHIRT_HUE_END 32
#define PANTS_HUE_START 96
#define PANTS_HUE_END 112
#define LM_SAMPLE_SIZE 16
#define LM_SAMPLE_EXTRASIZE 8

13
engine/common/system.h

@ -63,19 +63,6 @@ NOTE: never change this structure because all dll descriptions in xash code @@ -63,19 +63,6 @@ NOTE: never change this structure because all dll descriptions in xash code
writes into struct by offsets not names
========================================================================
*/
typedef struct dllfunc_s
{
const char *name;
void **func;
} dllfunc_t;
typedef struct dll_info_s
{
const char *name; // name of library
const dllfunc_t *fcts; // list of dll exports
qboolean crash; // crash if dll not found
void *link; // hinstance of loading library
} dll_info_t;
void Sys_Sleep( int msec );
double Sys_DoubleTime( void );

36
engine/platform/sdl/vid_sdl.c

@ -245,14 +245,15 @@ qboolean GL_CreateContext( void ) @@ -245,14 +245,15 @@ qboolean GL_CreateContext( void )
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &colorBits[0] );
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &colorBits[1] );
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &colorBits[2] );
glConfig.color_bits = colorBits[0] + colorBits[1] + colorBits[2];
glContext.color_bits = colorBits[0] + colorBits[1] + colorBits[2];
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &glConfig.alpha_bits );
SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &glConfig.depth_bits );
SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &glConfig.stencil_bits );
glState.stencilEnabled = glConfig.stencil_bits ? true : false;
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &glContext.alpha_bits );
SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &glContext.depth_bits );
SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &glContext.stencil_bits );
/// move to ref
//vidState.stencilEnabled = glContext.stencil_bits ? true : false;
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &glConfig.msaasamples );
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &glContext.msaasamples );
#ifdef XASH_WES
void wes_init();
@ -491,9 +492,9 @@ void VID_DestroyWindow( void ) @@ -491,9 +492,9 @@ void VID_DestroyWindow( void )
host.hWnd = NULL;
}
if( glState.fullScreen )
if( vidState.fullScreen )
{
glState.fullScreen = false;
vidState.fullScreen = false;
}
}
@ -563,8 +564,9 @@ static void GL_SetupAttributes( void ) @@ -563,8 +564,9 @@ static void GL_SetupAttributes( void )
Msg( "bpp %d\n", glw_state.desktopBitsPixel );
if( glw_state.safe < SAFE_NOSTENCIL )
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->value );
/// ref context attribs api
// if( glw_state.safe < SAFE_NOSTENCIL )
// SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, gl_stencilbits->value );
if( glw_state.safe < SAFE_NOALPHA )
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
@ -615,14 +617,14 @@ static void GL_SetupAttributes( void ) @@ -615,14 +617,14 @@ static void GL_SetupAttributes( void )
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
glConfig.max_multisamples = samples;
glContext.max_multisamples = samples;
}
else
{
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 0 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 0 );
glConfig.max_multisamples = 0;
glContext.max_multisamples = 0;
}
}
else
@ -674,7 +676,7 @@ qboolean R_Init_Video( void ) @@ -674,7 +676,7 @@ qboolean R_Init_Video( void )
return retval;
}
GL_InitExtensions();
ref.dllFuncs.GL_InitExtensions();
return true;
}
@ -692,7 +694,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) @@ -692,7 +694,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
glw_state.desktopWidth = displayMode.w;
glw_state.desktopHeight = displayMode.h;
glState.fullScreen = fullscreen;
vidState.fullScreen = fullscreen;
if( !host.hWnd )
{
@ -764,8 +766,8 @@ qboolean VID_SetMode( void ) @@ -764,8 +766,8 @@ qboolean VID_SetMode( void )
if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, fullscreen )) == rserr_ok )
{
glConfig.prev_width = iScreenWidth;
glConfig.prev_height = iScreenHeight;
vidState.prev_width = iScreenWidth;
vidState.prev_height = iScreenHeight;
}
else
{
@ -784,7 +786,7 @@ qboolean VID_SetMode( void ) @@ -784,7 +786,7 @@ qboolean VID_SetMode( void )
}
// try setting it back to something safe
if(( err = R_ChangeDisplaySettings( glConfig.prev_width, glConfig.prev_height, false )) != rserr_ok )
if(( err = R_ChangeDisplaySettings( vidState.prev_width, vidState.prev_height, false )) != rserr_ok )
{
Con_Reportf( S_ERROR "VID_SetMode: could not revert to safe mode\n" );
Sys_Warn("could not revert to safe mode!");

5
ref_gl/gl_alias.c

@ -12,16 +12,13 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,16 +12,13 @@ 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.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mathlib.h"
#include "const.h"
#include "r_studioint.h"
#include "triangleapi.h"
#include "alias.h"
#include "pm_local.h"
#include "gl_local.h"
#include "cl_tent.h"
extern cvar_t r_shadows;

23
ref_gl/gl_backend.c

@ -13,8 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mathlib.h"
@ -85,7 +84,7 @@ void GL_BackendEndFrame( void ) @@ -85,7 +84,7 @@ void GL_BackendEndFrame( void )
return;
if( !RI.viewleaf )
curleaf = cl.worldmodel->leafs;
curleaf = WORLDMODEL->leafs;
else curleaf = RI.viewleaf;
R_Speeds_Printf( "Renderer: ^1Engine^7\n\n" );
@ -97,7 +96,7 @@ void GL_BackendEndFrame( void ) @@ -97,7 +96,7 @@ void GL_BackendEndFrame( void )
r_stats.c_world_polys, r_stats.c_alias_polys, r_stats.c_studio_polys, r_stats.c_sprite_polys );
break;
case 2:
R_Speeds_Printf( "visible leafs:\n%3i leafs\ncurrent leaf %3i\n", r_stats.c_world_leafs, curleaf - cl.worldmodel->leafs );
R_Speeds_Printf( "visible leafs:\n%3i leafs\ncurrent leaf %3i\n", r_stats.c_world_leafs, curleaf - WORLDMODEL->leafs );
R_Speeds_Printf( "ReciusiveWorldNode: %3lf secs\nDrawTextureChains %lf\n", r_stats.t_world_node, r_stats.t_world_draw );
break;
case 3:
@ -560,7 +559,7 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo @@ -560,7 +559,7 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo
string basename;
int i = 1, flags, result;
if( !RI.drawWorld || !cl.worldmodel )
if( !RI.drawWorld || !WORLDMODEL )
return false;
// make sure the specified size is valid
@ -786,7 +785,7 @@ void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes ) @@ -786,7 +785,7 @@ void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes )
if( shownodes == 1 )
{
if( cl.worldmodel->leafs == leaf )
if( WORLDMODEL->leafs == leaf )
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
else if( RI.viewleaf && RI.viewleaf == leaf )
pglColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
@ -819,7 +818,7 @@ void R_ShowTree( void ) @@ -819,7 +818,7 @@ void R_ShowTree( void )
float x = (float)((glState.width - (int)POINT_SIZE) >> 1);
float y = NODE_INTERVAL_Y(1.0);
if( !cl.worldmodel || !CVAR_TO_BOOL( r_showtree ))
if( !WORLDMODEL || !CVAR_TO_BOOL( r_showtree ))
return;
tr.recursion_level = 0;
@ -831,11 +830,11 @@ void R_ShowTree( void ) @@ -831,11 +830,11 @@ void R_ShowTree( void )
pglLineWidth( 2.0f );
pglColor3f( 1, 0.7f, 0 );
pglDisable( GL_TEXTURE_2D );
R_ShowTree_r( cl.worldmodel->nodes, x, y, tr.max_recursion * 3.5f, 2 );
R_ShowTree_r( WORLDMODEL->nodes, x, y, tr.max_recursion * 3.5f, 2 );
pglEnable( GL_TEXTURE_2D );
pglLineWidth( 1.0f );
R_ShowTree_r( cl.worldmodel->nodes, x, y, tr.max_recursion * 3.5f, 1 );
R_ShowTree_r( WORLDMODEL->nodes, x, y, tr.max_recursion * 3.5f, 1 );
Con_NPrintf( 0, "max recursion %d\n", tr.max_recursion );
}
@ -874,10 +873,10 @@ void SCR_TimeRefresh_f( void ) @@ -874,10 +873,10 @@ void SCR_TimeRefresh_f( void )
{
for( i = 0; i < 128; i++ )
{
ref.dllFuncs.R_BeginFrame( true );
R_BeginFrame( true );
refState.viewangles[1] = i / 128.0 * 360.0f;
ref.dllFuncs.R_RenderScene();
ref.dllFuncs.R_EndFrame();
R_RenderScene();
R_EndFrame();
}
}

1118
ref_gl/gl_beams.c

File diff suppressed because it is too large Load Diff

3
ref_gl/gl_context.c

@ -12,8 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,8 +12,7 @@ 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.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "gl_export.h"

4
ref_gl/gl_cull.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "entity_types.h"
@ -148,4 +146,4 @@ int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags ) @@ -148,4 +146,4 @@ int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags )
return CULL_FRUSTUM;
return CULL_VISIBLE;
}
}

10
ref_gl/gl_dbghulls.c

@ -14,11 +14,7 @@ GNU General Public License for more details. @@ -14,11 +14,7 @@ GNU General Public License for more details.
*/
#include "mod_local.h"
#include "mathlib.h"
#include "world.h"
#include "gl_local.h"
#include "client.h"
#define list_entry( ptr, type, member ) \
((type *)((char *)(ptr) - (size_t)(&((type *)0)->member)))
@ -31,7 +27,7 @@ GNU General Public License for more details. @@ -31,7 +27,7 @@ GNU General Public License for more details.
void R_DrawWorldHull( void )
{
hull_model_t *hull = &world.hull_models[0];
hull_model_t *hull = &WORLDMODEL->hull_models[0];
winding_t *poly;
int i;
@ -71,10 +67,10 @@ void R_DrawModelHull( void ) @@ -71,10 +67,10 @@ void R_DrawModelHull( void )
return;
i = atoi( RI.currentmodel->name + 1 );
if( i < 1 || i >= world.num_hull_models )
if( i < 1 || i >= WORLDMODEL->num_hull_models )
return;
hull = &world.hull_models[i];
hull = &WORLDMODEL->hull_models[i];
pglPolygonOffset( 1.0f, 2.0 );
pglEnable( GL_POLYGON_OFFSET_FILL );

6
ref_gl/gl_decals.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "cl_tent.h"
@ -774,7 +772,7 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos @@ -774,7 +772,7 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos
}
else if( modelIndex > 0 )
model = CL_ModelHandle( modelIndex );
else model = cl.worldmodel;
else model = WORLDMODEL;
if( !model ) return;
@ -1163,7 +1161,7 @@ int R_CreateDecalList( decallist_t *pList ) @@ -1163,7 +1161,7 @@ int R_CreateDecalList( decallist_t *pList )
int total = 0;
int i, depth;
if( cl.worldmodel )
if( WORLDMODEL )
{
for( i = 0; i < MAX_RENDER_DECALS; i++ )
{

4
ref_gl/gl_draw.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
/*
@ -280,4 +278,4 @@ void R_Set2DMode( qboolean enable ) @@ -280,4 +278,4 @@ void R_Set2DMode( qboolean enable )
GL_Cull( GL_FRONT );
}
}
}

1
ref_gl/gl_frustum.c

@ -13,7 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,7 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "gl_local.h"
#include "mathlib.h"

2
ref_gl/gl_image.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#define TEXTURES_HASH_SIZE (MAX_TEXTURES >> 2)

83
ref_gl/gl_local.h

@ -15,7 +15,11 @@ GNU General Public License for more details. @@ -15,7 +15,11 @@ GNU General Public License for more details.
#ifndef GL_LOCAL_H
#define GL_LOCAL_H
#include "port.h"
#include "xash3d_types.h"
#include "cvardef.h"
#include "const.h"
#include "com_model.h"
#include "gl_export.h"
#include "cl_entity.h"
#include "render_api.h"
@ -23,6 +27,62 @@ GNU General Public License for more details. @@ -23,6 +27,62 @@ GNU General Public License for more details.
#include "dlight.h"
#include "gl_frustum.h"
#include "ref_api.h"
#include "mathlib.h"
#include "ref_params.h"
#include "enginefeatures.h"
#include "com_strings.h"
#include "pm_movevars.h"
typedef cvar_t convar_t;
#include <stdio.h>
#define Con_Reportf printf
#define Con_Printf printf
#define Con_DPrintf printf
void CL_DrawEFX(double, double);
void *CL_ModelHandle(int);
void *GL_GetProcAddress(char *);
void GL_CheckForErrors();
void CL_ExtraUpdate();
void Cbuf_AddText(char*);
void Cbuf_Execute();
int COM_HashKey(char*,int);
extern convar_t cvstub;
#define Cvar_Get(...) &cvstub
#define Cvar_FindVar(...) &cvstub
#define Cvar_SetValue(...)
#define Cmd_AddCommand(...)
#define Cmd_RemoveCommand(...)
#define FS_FreeImage(...)
#define Host_Error(...)
#define ASSERT(x)
#define Q_strcpy(...)
#define Q_strncpy(...)
#define Q_strncat(...)
#define Q_strnat(...)
#define Q_snprintf(...)
#define Q_strcmp(...) 1
#define Q_stricmp(...) 1
#define Q_strncmp(...) 1
#define Q_strnicmp(...) 1
#define Q_strlen(...) 1
#define Assert(x)
#define va(...) ((const char*)NULL)
void *FS_LoadImage(char *, void *, int);
void *FS_CopyImage(void *);
void *Mem_Calloc(void*, int);
void *Mem_Malloc(void*, int);
void *Mem_Realloc(void*,void*, int);
#define CVAR_DEFINE( cv, cvname, cvstr, cvflags, cvdesc ) convar_t cv = { cvname, cvstr, cvflags, 0.0f, (void *)CVAR_SENTINEL, cvdesc }
#define CVAR_DEFINE_AUTO( cv, cvstr, cvflags, cvdesc ) convar_t cv = { #cv, cvstr, cvflags, 0.0f, (void *)CVAR_SENTINEL, cvdesc }
#define CVAR_TO_BOOL( x ) ((x) && ((x)->value != 0.0f) ? true : false )
#define WORLDMODEL ((model_t*)NULL)
#define MOVEVARS ((movevars_t*)NULL)
extern byte *r_temppool;
@ -593,10 +653,8 @@ typedef struct @@ -593,10 +653,8 @@ typedef struct
typedef struct
{
int width, height;
qboolean fullScreen;
qboolean wideScreen;
int width, height;
int activeTMU;
GLint currentTextures[MAX_TEXTURE_UNITS];
GLuint currentTextureTargets[MAX_TEXTURE_UNITS];
@ -610,18 +668,7 @@ typedef struct @@ -610,18 +668,7 @@ typedef struct
qboolean in2DMode;
} glstate_t;
typedef enum
{
SAFE_NO = 0,
SAFE_NOMSAA, // skip msaa
SAFE_NOACC, // don't set acceleration flag
SAFE_NOSTENCIL, // don't set stencil bits
SAFE_NOALPHA, // don't set alpha bits
SAFE_NODEPTH, // don't set depth bits
SAFE_NOCOLOR, // don't set color bits
SAFE_DONTCARE // ignore everything, let SDL/EGL decide
} safe_context_t;
/*
typedef struct
{
void* context; // handle to GL rendering context
@ -634,10 +681,12 @@ typedef struct @@ -634,10 +681,12 @@ typedef struct
qboolean initialized; // OpenGL subsystem started
qboolean extended; // extended context allows to GL_Debug
} glwstate_t;
*/
extern glconfig_t glConfig;
extern glstate_t glState;
extern glwstate_t glw_state;
// move to engine
//extern glwstate_t glw_state;
//
// renderer cvars

518
ref_gl/gl_opengl.c

@ -0,0 +1,518 @@ @@ -0,0 +1,518 @@
#include "gl_local.h"
convar_t *gl_extensions;
convar_t *gl_texture_anisotropy;
convar_t *gl_texture_lodbias;
convar_t *gl_texture_nearest;
convar_t *gl_lightmap_nearest;
convar_t *gl_keeptjunctions;
convar_t *gl_emboss_scale;
convar_t *gl_detailscale;
convar_t *gl_check_errors;
convar_t *gl_polyoffset;
convar_t *gl_wireframe;
convar_t *gl_finish;
convar_t *gl_nosort;
convar_t *gl_vsync;
convar_t *gl_clear;
convar_t *gl_test;
convar_t *gl_msaa;
convar_t *gl_stencilbits;
convar_t *r_speeds;
convar_t *r_fullbright;
convar_t *r_norefresh;
convar_t *r_showtree;
convar_t *r_lighting_extended;
convar_t *r_lighting_modulate;
convar_t *r_lighting_ambient;
convar_t *r_detailtextures;
convar_t *r_drawentities;
convar_t *r_adjust_fov;
convar_t *r_decals;
convar_t *r_novis;
convar_t *r_nocull;
convar_t *r_lockpvs;
convar_t *r_lockfrustum;
convar_t *r_traceglow;
convar_t *r_dynamic;
convar_t *r_lightmap;
convar_t *gl_round_down;
convar_t *r_vbo;
convar_t *r_vbo_dlightmode;
byte *r_temppool;
gl_globals_t tr;
glconfig_t glConfig;
glstate_t glState;
glwstate_t glw_state;
/*
=================
GL_SetExtension
=================
*/
void GL_SetExtension( int r_ext, int enable )
{
if( r_ext >= 0 && r_ext < GL_EXTCOUNT )
glConfig.extension[r_ext] = enable ? GL_TRUE : GL_FALSE;
else Con_Printf( S_ERROR "GL_SetExtension: invalid extension %d\n", r_ext );
}
/*
=================
GL_Support
=================
*/
qboolean GL_Support( int r_ext )
{
if( r_ext >= 0 && r_ext < GL_EXTCOUNT )
return glConfig.extension[r_ext] ? true : false;
Con_Printf( S_ERROR "GL_Support: invalid extension %d\n", r_ext );
return false;
}
/*
=================
GL_MaxTextureUnits
=================
*/
int GL_MaxTextureUnits( void )
{
if( GL_Support( GL_SHADER_GLSL100_EXT ))
return Q_min( Q_max( glConfig.max_texture_coords, glConfig.max_teximage_units ), MAX_TEXTURE_UNITS );
return glConfig.max_texture_units;
}
/*
=================
GL_CheckExtension
=================
*/
void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext )
{
const dllfunc_t *func;
convar_t *parm = NULL;
const char *extensions_string;
Con_Reportf( "GL_CheckExtension: %s ", name );
GL_SetExtension( r_ext, true );
if( cvarname )
{
// system config disable extensions
parm = Cvar_Get( cvarname, "1", FCVAR_GLCONFIG, va( CVAR_GLCONFIG_DESCRIPTION, name ));
}
if(( parm && !CVAR_TO_BOOL( parm )) || ( !CVAR_TO_BOOL( gl_extensions ) && r_ext != GL_OPENGL_110 ))
{
Con_Reportf( "- disabled\n" );
GL_SetExtension( r_ext, false );
return; // nothing to process at
}
extensions_string = glConfig.extensions_string;
if(( name[2] == '_' || name[3] == '_' ) && !Q_strstr( extensions_string, name ))
{
GL_SetExtension( r_ext, false ); // update render info
Con_Reportf( "- ^1failed\n" );
return;
}
// clear exports
for( func = funcs; func && func->name; func++ )
*func->func = NULL;
for( func = funcs; func && func->name != NULL; func++ )
{
// functions are cleared before all the extensions are evaluated
if((*func->func = (void *)GL_GetProcAddress( func->name )) == NULL )
GL_SetExtension( r_ext, false ); // one or more functions are invalid, extension will be disabled
}
if( GL_Support( r_ext ))
Con_Reportf( "- ^2enabled\n" );
else Con_Reportf( "- ^1failed\n" );
}
/*
===============
GL_SetDefaultTexState
===============
*/
static void GL_SetDefaultTexState( void )
{
int i;
memset( glState.currentTextures, -1, MAX_TEXTURE_UNITS * sizeof( *glState.currentTextures ));
memset( glState.texCoordArrayMode, 0, MAX_TEXTURE_UNITS * sizeof( *glState.texCoordArrayMode ));
memset( glState.genSTEnabled, 0, MAX_TEXTURE_UNITS * sizeof( *glState.genSTEnabled ));
for( i = 0; i < MAX_TEXTURE_UNITS; i++ )
{
glState.currentTextureTargets[i] = GL_NONE;
glState.texIdentityMatrix[i] = true;
}
}
/*
===============
GL_SetDefaultState
===============
*/
static void GL_SetDefaultState( void )
{
memset( &glState, 0, sizeof( glState ));
GL_SetDefaultTexState ();
// init draw stack
tr.draw_list = &tr.draw_stack[0];
tr.draw_stack_pos = 0;
}
/*
===============
GL_SetDefaults
===============
*/
static void GL_SetDefaults( void )
{
pglFinish();
pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f );
pglDisable( GL_DEPTH_TEST );
pglDisable( GL_CULL_FACE );
pglDisable( GL_SCISSOR_TEST );
pglDepthFunc( GL_LEQUAL );
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
if( vidState.stencilEnabled )
{
pglDisable( GL_STENCIL_TEST );
pglStencilMask( ( GLuint ) ~0 );
pglStencilFunc( GL_EQUAL, 0, ~0 );
pglStencilOp( GL_KEEP, GL_INCR, GL_INCR );
}
pglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
pglPolygonOffset( -1.0f, -2.0f );
GL_CleanupAllTextureUnits();
pglDisable( GL_BLEND );
pglDisable( GL_ALPHA_TEST );
pglDisable( GL_POLYGON_OFFSET_FILL );
pglAlphaFunc( GL_GREATER, DEFAULT_ALPHATEST );
pglEnable( GL_TEXTURE_2D );
pglShadeModel( GL_SMOOTH );
pglFrontFace( GL_CCW );
pglPointSize( 1.2f );
pglLineWidth( 1.2f );
GL_Cull( GL_NONE );
}
/*
=================
R_RenderInfo_f
=================
*/
void R_RenderInfo_f( void )
{
Con_Printf( "\n" );
Con_Printf( "GL_VENDOR: %s\n", glConfig.vendor_string );
Con_Printf( "GL_RENDERER: %s\n", glConfig.renderer_string );
Con_Printf( "GL_VERSION: %s\n", glConfig.version_string );
// don't spam about extensions
if( host_developer.value >= DEV_EXTENDED )
{
Con_Printf( "GL_EXTENSIONS: %s\n", glConfig.extensions_string );
}
Con_Printf( "GL_MAX_TEXTURE_SIZE: %i\n", glConfig.max_2d_texture_size );
if( GL_Support( GL_ARB_MULTITEXTURE ))
Con_Printf( "GL_MAX_TEXTURE_UNITS_ARB: %i\n", glConfig.max_texture_units );
if( GL_Support( GL_TEXTURE_CUBEMAP_EXT ))
Con_Printf( "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB: %i\n", glConfig.max_cubemap_size );
if( GL_Support( GL_ANISOTROPY_EXT ))
Con_Printf( "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: %.1f\n", glConfig.max_texture_anisotropy );
if( GL_Support( GL_TEXTURE_2D_RECT_EXT ))
Con_Printf( "GL_MAX_RECTANGLE_TEXTURE_SIZE: %i\n", glConfig.max_2d_rectangle_size );
if( GL_Support( GL_TEXTURE_ARRAY_EXT ))
Con_Printf( "GL_MAX_ARRAY_TEXTURE_LAYERS_EXT: %i\n", glConfig.max_2d_texture_layers );
if( GL_Support( GL_SHADER_GLSL100_EXT ))
{
Con_Printf( "GL_MAX_TEXTURE_COORDS_ARB: %i\n", glConfig.max_texture_coords );
Con_Printf( "GL_MAX_TEXTURE_IMAGE_UNITS_ARB: %i\n", glConfig.max_teximage_units );
Con_Printf( "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB: %i\n", glConfig.max_vertex_uniforms );
Con_Printf( "GL_MAX_VERTEX_ATTRIBS_ARB: %i\n", glConfig.max_vertex_attribs );
}
Con_Printf( "\n" );
Con_Printf( "MODE: %ix%i\n", vidState.width, vidState.height );
Con_Printf( "\n" );
Con_Printf( "VERTICAL SYNC: %s\n", gl_vsync->value ? "enabled" : "disabled" );
Con_Printf( "Color %d bits, Alpha %d bits, Depth %d bits, Stencil %d bits\n", glConfig.color_bits,
glConfig.alpha_bits, glConfig.depth_bits, glConfig.stencil_bits );
}
//=======================================================================
/*
=================
GL_InitCommands
=================
*/
void GL_InitCommands( void )
{
// system screen width and height (don't suppose for change from console at all)
Cvar_Get( "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" );
Cvar_Get( "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" );
r_speeds = Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" );
r_fullbright = Cvar_Get( "r_fullbright", "0", FCVAR_CHEAT, "disable lightmaps, get fullbright for entities" );
r_norefresh = Cvar_Get( "r_norefresh", "0", 0, "disable 3D rendering (use with caution)" );
r_showtree = Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" );
r_lighting_extended = Cvar_Get( "r_lighting_extended", "1", FCVAR_ARCHIVE, "allow to get lighting from world and bmodels" );
r_lighting_modulate = Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" );
r_lighting_ambient = Cvar_Get( "r_lighting_ambient", "0.3", FCVAR_ARCHIVE, "map ambient lighting scale" );
r_novis = Cvar_Get( "r_novis", "0", 0, "ignore vis information (perfomance test)" );
r_nocull = Cvar_Get( "r_nocull", "0", 0, "ignore frustrum culling (perfomance test)" );
r_detailtextures = Cvar_Get( "r_detailtextures", "1", FCVAR_ARCHIVE, "enable detail textures support, use '2' for autogenerate detail.txt" );
r_lockpvs = Cvar_Get( "r_lockpvs", "0", FCVAR_CHEAT, "lockpvs area at current point (pvs test)" );
r_lockfrustum = Cvar_Get( "r_lockfrustum", "0", FCVAR_CHEAT, "lock frustrum area at current point (cull test)" );
r_dynamic = Cvar_Get( "r_dynamic", "1", FCVAR_ARCHIVE, "allow dynamic lighting (dlights, lightstyles)" );
r_traceglow = Cvar_Get( "r_traceglow", "1", FCVAR_ARCHIVE, "cull flares behind models" );
r_lightmap = Cvar_Get( "r_lightmap", "0", FCVAR_CHEAT, "lightmap debugging tool" );
r_drawentities = Cvar_Get( "r_drawentities", "1", FCVAR_CHEAT, "render entities" );
r_decals = engine.Cvar_Find( "r_decals" );
window_xpos = Cvar_Get( "_window_xpos", "130", FCVAR_RENDERINFO, "window position by horizontal" );
window_ypos = Cvar_Get( "_window_ypos", "48", FCVAR_RENDERINFO, "window position by vertical" );
gl_extensions = Cvar_Get( "gl_allow_extensions", "1", FCVAR_GLCONFIG, "allow gl_extensions" );
gl_texture_nearest = Cvar_Get( "gl_texture_nearest", "0", FCVAR_ARCHIVE, "disable texture filter" );
gl_lightmap_nearest = Cvar_Get( "gl_lightmap_nearest", "0", FCVAR_ARCHIVE, "disable lightmap filter" );
gl_check_errors = Cvar_Get( "gl_check_errors", "1", FCVAR_ARCHIVE, "ignore video engine errors" );
gl_vsync = engine.Cvar_Find( "gl_vsync" );
gl_detailscale = Cvar_Get( "gl_detailscale", "4.0", FCVAR_ARCHIVE, "default scale applies while auto-generate list of detail textures" );
gl_texture_anisotropy = Cvar_Get( "gl_anisotropy", "8", FCVAR_ARCHIVE, "textures anisotropic filter" );
gl_texture_lodbias = Cvar_Get( "gl_texture_lodbias", "0.0", FCVAR_ARCHIVE, "LOD bias for mipmapped textures (perfomance|quality)" );
gl_keeptjunctions = Cvar_Get( "gl_keeptjunctions", "1", FCVAR_ARCHIVE, "removing tjuncs causes blinking pixels" );
gl_emboss_scale = Cvar_Get( "gl_emboss_scale", "0", FCVAR_ARCHIVE|FCVAR_LATCH, "fake bumpmapping scale" );
gl_showtextures = engine.Cvar_Find( "r_showtextures" );
gl_finish = Cvar_Get( "gl_finish", "0", FCVAR_ARCHIVE, "use glFinish instead of glFlush" );
gl_nosort = Cvar_Get( "gl_nosort", "0", FCVAR_ARCHIVE, "disable sorting of translucent surfaces" );
gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" );
gl_test = Cvar_Get( "gl_test", "0", 0, "engine developer cvar for quick testing new features" );
gl_wireframe = Cvar_Get( "gl_wireframe", "0", FCVAR_ARCHIVE|FCVAR_SPONLY, "show wireframe overlay" );
gl_wgl_msaa_samples = Cvar_Get( "gl_wgl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" );
gl_msaa = Cvar_Get( "gl_msaa", "1", FCVAR_ARCHIVE, "enable or disable multisample anti-aliasing" );
gl_stencilbits = Cvar_Get( "gl_stencilbits", "8", FCVAR_GLCONFIG, "pixelformat stencil bits (0 - auto)" );
gl_round_down = Cvar_Get( "gl_round_down", "2", FCVAR_RENDERINFO, "round texture sizes to nearest POT value" );
// these cvar not used by engine but some mods requires this
gl_polyoffset = Cvar_Get( "gl_polyoffset", "2.0", FCVAR_ARCHIVE, "polygon offset for decals" );
// make sure gl_vsync is checked after vid_restart
SetBits( gl_vsync->flags, FCVAR_CHANGED );
vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" );
vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" );
vid_fullscreen = engine.Cvar_Find( "fullscreen" );
vid_displayfrequency = engine.Cvar_Find ( "vid_displayfrequency" );
vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
Cmd_AddCommand( "r_info", R_RenderInfo_f, "display renderer info" );
Cmd_AddCommand( "timerefresh", SCR_TimeRefresh_f, "turn quickly and print rendering statistcs" );
// a1ba: planned to be named vid_mode for compability
// but supported mode list is filled by backends, so numbers are not portable any more
Cmd_AddCommand( "vid_setmode", VID_Mode_f, "display video mode" );
// give initial OpenGL configuration
host.apply_opengl_config = true;
Cbuf_AddText( "exec opengl.cfg\n" );
Cbuf_Execute();
host.apply_opengl_config = false;
// apply actual video mode to window
Cbuf_AddText( "exec video.cfg\n" );
Cbuf_Execute();
}
/*
===============
R_CheckVBO
register VBO cvars and get default value
===============
*/
static void R_CheckVBO( void )
{
const char *def = "1";
const char *dlightmode = "1";
int flags = FCVAR_ARCHIVE;
qboolean disable = false;
// some bad GLES1 implementations breaks dlights completely
if( glConfig.max_texture_units < 3 )
disable = true;
#ifdef XASH_MOBILE_PLATFORM
// VideoCore4 drivers have a problem with mixing VBO and client arrays
// Disable it, as there is no suitable workaround here
if( Q_stristr( glConfig.renderer_string, "VideoCore IV" ) || Q_stristr( glConfig.renderer_string, "vc4" ) )
disable = true;
// dlightmode 1 is not too much tested on android
// so better to left it off
dlightmode = "0";
#endif
if( disable )
{
// do not keep in config unless dev > 3 and enabled
flags = 0;
def = "0";
}
r_vbo = Cvar_Get( "r_vbo", def, flags, "draw world using VBO" );
r_vbo_dlightmode = Cvar_Get( "r_vbo_dlightmode", dlightmode, FCVAR_ARCHIVE, "vbo dlight rendering mode(0-1)" );
// check if enabled manually
if( CVAR_TO_BOOL(r_vbo) )
r_vbo->flags |= FCVAR_ARCHIVE;
}
/*
===============
R_Init
===============
*/
qboolean R_Init( void )
{
if( glw_state.initialized )
return true;
GL_InitCommands();
GL_InitRandomTable();
// Set screen resolution and fullscreen mode if passed in on command line.
// This is done after executing opengl.cfg, as the command line values should take priority.
SetWidthAndHeightFromCommandLine();
SetFullscreenModeFromCommandLine();
GL_SetDefaultState();
// create the window and set up the context
if( !R_Init_Video( ))
{
GL_RemoveCommands();
R_Free_Video();
Sys_Error( "Can't initialize video subsystem\nProbably driver was not installed" );
return false;
}
host.renderinfo_changed = false;
r_temppool = Mem_AllocPool( "Render Zone" );
GL_SetDefaults();
R_CheckVBO();
R_InitImages();
R_SpriteInit();
R_StudioInit();
R_AliasInit();
R_ClearDecals();
R_ClearScene();
// initialize screen
SCR_Init();
return true;
}
/*
===============
R_Shutdown
===============
*/
void R_Shutdown( void )
{
model_t *mod;
int i;
if( !glw_state.initialized )
return;
// release SpriteTextures
for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ )
{
if( !mod->name[0] ) continue;
Mod_UnloadSpriteModel( mod );
}
memset( clgame.sprites, 0, sizeof( clgame.sprites ));
GL_RemoveCommands();
R_ShutdownImages();
Mem_FreePool( &r_temppool );
// shut down OS specific OpenGL stuff like contexts, etc.
R_Free_Video();
}
/*
=================
GL_ErrorString
convert errorcode to string
=================
*/
const char *GL_ErrorString( int err )
{
switch( err )
{
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
default:
return "UNKNOWN ERROR";
}
}
/*
=================
GL_CheckForErrors
obsolete
=================
*/
void GL_CheckForErrors_( const char *filename, const int fileline )
{
int err;
if( !CVAR_TO_BOOL( gl_check_errors ))
return;
if(( err = pglGetError( )) == GL_NO_ERROR )
return;
Con_Printf( S_OPENGL_ERROR "%s (called at %s:%i)\n", GL_ErrorString( err ), filename, fileline );
}

6
ref_gl/gl_refrag.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mod_local.h"
#include "entity_types.h"
@ -161,7 +159,7 @@ void R_AddEfrags( cl_entity_t *ent ) @@ -161,7 +159,7 @@ void R_AddEfrags( cl_entity_t *ent )
r_emaxs[i] = ent->origin[i] + outmaxs[i];
}
R_SplitEntityOnNode( cl.worldmodel->nodes );
R_SplitEntityOnNode( WORLDMODEL->nodes );
ent->topnode = r_pefragtopnode;
}
@ -206,4 +204,4 @@ void R_StoreEfrags( efrag_t **ppefrag, int framecount ) @@ -206,4 +204,4 @@ void R_StoreEfrags( efrag_t **ppefrag, int framecount )
break;
}
}
}
}

8
ref_gl/gl_rlight.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "mathlib.h"
#include "gl_local.h"
#include "pm_local.h"
@ -41,7 +39,7 @@ void CL_RunLightStyles( void ) @@ -41,7 +39,7 @@ void CL_RunLightStyles( void )
float scale;
lightstyle_t *ls;
if( !cl.worldmodel ) return;
if( !WORLDMODEL ) return;
scale = r_lighting_modulate->value;
@ -49,7 +47,7 @@ void CL_RunLightStyles( void ) @@ -49,7 +47,7 @@ void CL_RunLightStyles( void )
// 'm' is normal light, 'a' is no light, 'z' is double bright
for( i = 0, ls = cl.lightstyles; i < MAX_LIGHTSTYLES; i++, ls++ )
{
if( !cl.worldmodel->lightdata )
if( !WORLDMODEL->lightdata )
{
tr.lightstylevalue[i] = 256 * 256;
continue;
@ -388,7 +386,7 @@ colorVec R_LightVecInternal( const vec3_t start, const vec3_t end, vec3_t lspot, @@ -388,7 +386,7 @@ colorVec R_LightVecInternal( const vec3_t start, const vec3_t end, vec3_t lspot,
if( lspot ) VectorClear( lspot );
if( lvec ) VectorClear( lvec );
if( cl.worldmodel && cl.worldmodel->lightdata )
if( WORLDMODEL && WORLDMODEL->lightdata )
{
light.r = light.g = light.b = light.a = 0;
last_fraction = 1.0f;

48
ref_gl/gl_rmain.c

@ -13,15 +13,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,15 +13,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mathlib.h"
#include "library.h"
#include "beamdef.h"
#include "particledef.h"
#include "entity_types.h"
#include "platform/platform.h"
#define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA )
@ -318,8 +315,8 @@ R_GetFarClip @@ -318,8 +315,8 @@ R_GetFarClip
*/
static float R_GetFarClip( void )
{
if( cl.worldmodel && RI.drawWorld )
return clgame.movevars.zmax * 1.73f;
if( WORLDMODEL && RI.drawWorld )
return MOVEVARS->zmax * 1.73f;
return 2048.0f;
}
@ -475,7 +472,7 @@ R_FindViewLeaf @@ -475,7 +472,7 @@ R_FindViewLeaf
void R_FindViewLeaf( void )
{
RI.oldviewleaf = RI.viewleaf;
RI.viewleaf = Mod_PointInLeaf( RI.pvsorigin, cl.worldmodel->nodes );
RI.viewleaf = Mod_PointInLeaf( RI.pvsorigin, WORLDMODEL->nodes );
}
/*
@ -661,7 +658,7 @@ static void R_CheckFog( void ) @@ -661,7 +658,7 @@ static void R_CheckFog( void )
// quake global fog
if( Host_IsQuakeCompatible( ))
{
if( !clgame.movevars.fog_settings )
if( !MOVEVARS->fog_settings )
{
if( pglIsEnabled( GL_FOG ))
pglDisable( GL_FOG );
@ -670,10 +667,10 @@ static void R_CheckFog( void ) @@ -670,10 +667,10 @@ static void R_CheckFog( void )
}
// quake-style global fog
RI.fogColor[0] = ((clgame.movevars.fog_settings & 0xFF000000) >> 24) / 255.0f;
RI.fogColor[1] = ((clgame.movevars.fog_settings & 0xFF0000) >> 16) / 255.0f;
RI.fogColor[2] = ((clgame.movevars.fog_settings & 0xFF00) >> 8) / 255.0f;
RI.fogDensity = ((clgame.movevars.fog_settings & 0xFF) / 255.0f) * 0.01f;
RI.fogColor[0] = ((MOVEVARS->fog_settings & 0xFF000000) >> 24) / 255.0f;
RI.fogColor[1] = ((MOVEVARS->fog_settings & 0xFF0000) >> 16) / 255.0f;
RI.fogColor[2] = ((MOVEVARS->fog_settings & 0xFF00) >> 8) / 255.0f;
RI.fogDensity = ((MOVEVARS->fog_settings & 0xFF) / 255.0f) * 0.01f;
RI.fogStart = RI.fogEnd = 0.0f;
RI.fogColor[3] = 1.0f;
RI.fogCustom = false;
@ -855,7 +852,7 @@ void R_DrawEntitiesOnList( void ) @@ -855,7 +852,7 @@ void R_DrawEntitiesOnList( void )
if( !RI.onlyClientDraw )
{
CL_DrawBeams( false );
CL_DrawEFX( tr.frametime, false );
}
GL_CheckForErrors();
@ -913,9 +910,7 @@ void R_DrawEntitiesOnList( void ) @@ -913,9 +910,7 @@ void R_DrawEntitiesOnList( void )
if( !RI.onlyClientDraw )
{
R_AllowFog( false );
CL_DrawBeams( true );
CL_DrawParticles( tr.frametime );
CL_DrawTracers( tr.frametime );
CL_DrawEFX( tr.frametime, true );
R_AllowFog( true );
}
@ -939,7 +934,7 @@ R_SetupRefParams must be called right before @@ -939,7 +934,7 @@ R_SetupRefParams must be called right before
*/
void R_RenderScene( void )
{
if( !cl.worldmodel && RI.drawWorld )
if( !WORLDMODEL && RI.drawWorld )
Host_Error( "R_RenderView: NULL worldmodel\n" );
// frametime is valid only for normal pass
@ -985,7 +980,7 @@ qboolean R_DoResetGamma( void ) @@ -985,7 +980,7 @@ qboolean R_DoResetGamma( void )
{
// FIXME: this looks ugly. apply the backward gamma changes to the output image
return false;
#if 0
switch( cls.scrshot_action )
{
case scrshot_normal:
@ -1005,6 +1000,7 @@ qboolean R_DoResetGamma( void ) @@ -1005,6 +1000,7 @@ qboolean R_DoResetGamma( void )
default:
return false;
}
#endif
}
/*
@ -1222,7 +1218,7 @@ static int GL_RenderGetParm( int parm, int arg ) @@ -1222,7 +1218,7 @@ static int GL_RenderGetParm( int parm, int arg )
arg = bound( 0, arg, MAX_LIGHTMAPS - 1 );
return tr.lightmapTextures[arg];
case PARM_SKY_SPHERE:
return FBitSet( world.flags, FWORLD_SKYSPHERE ) && !FBitSet( world.flags, FWORLD_CUSTOM_SKYBOX );
return FBitSet( WORLDMODEL->flags, FWORLD_SKYSPHERE ) && !FBitSet( WORLDMODEL->flags, FWORLD_CUSTOM_SKYBOX );
case PARAM_GAMEPAUSED:
return cl.paused;
case PARM_WIDESCREEN:
@ -1254,7 +1250,7 @@ static int GL_RenderGetParm( int parm, int arg ) @@ -1254,7 +1250,7 @@ static int GL_RenderGetParm( int parm, int arg )
arg = bound( 0, arg, MAX_LIGHTSTYLES - 1 );
return tr.lightstylevalue[arg];
case PARM_MAP_HAS_DELUXE:
return FBitSet( world.flags, FWORLD_HAS_DELUXEMAP );
return FBitSet( WORLDMODEL->flags, FWORLD_HAS_DELUXEMAP );
case PARM_MAX_IMAGE_UNITS:
return GL_MaxTextureUnits();
case PARM_CLIENT_ACTIVE:
@ -1264,8 +1260,8 @@ static int GL_RenderGetParm( int parm, int arg ) @@ -1264,8 +1260,8 @@ static int GL_RenderGetParm( int parm, int arg )
case PARM_DEDICATED_SERVER:
return (host.type == HOST_DEDICATED);
case PARM_SURF_SAMPLESIZE:
if( arg >= 0 && arg < cl.worldmodel->numsurfaces )
return Mod_SampleSizeForFace( &cl.worldmodel->surfaces[arg] );
if( arg >= 0 && arg < WORLDMODEL->numsurfaces )
return Mod_SampleSizeForFace( &WORLDMODEL->surfaces[arg] );
return LM_SAMPLE_SIZE;
case PARM_GL_CONTEXT_TYPE:
return glConfig.context;
@ -1274,7 +1270,7 @@ static int GL_RenderGetParm( int parm, int arg ) @@ -1274,7 +1270,7 @@ static int GL_RenderGetParm( int parm, int arg )
case PARM_STENCIL_ACTIVE:
return glState.stencilEnabled;
case PARM_WATER_ALPHA:
return FBitSet( world.flags, FWORLD_WATERALPHA );
return FBitSet( WORLDMODEL->flags, FWORLD_WATERALPHA );
}
return 0;
}
@ -1352,9 +1348,12 @@ static void R_SetCurrentModel( model_t *mod ) @@ -1352,9 +1348,12 @@ static void R_SetCurrentModel( model_t *mod )
RI.currentmodel = mod;
}
// to engine?
#if 0
static int R_FatPVS( const vec3_t org, float radius, byte *visbuffer, qboolean merge, qboolean fullvis )
{
return Mod_FatPVS( org, radius, visbuffer, world.visbytes, merge, fullvis );
return Mod_FatPVS( org, radius, visbuffer, WORLDMODEL->visbytes, merge, fullvis );
}
static lightstyle_t *CL_GetLightStyle( int number )
@ -1458,9 +1457,11 @@ const char *CL_GenericHandle( int fileindex ) @@ -1458,9 +1457,11 @@ const char *CL_GenericHandle( int fileindex )
return 0;
return cl.files_precache[fileindex];
}
#endif
static render_api_t gRenderAPI =
{
#if 0
GL_RenderGetParm,
R_GetDetailScaleForTexture,
R_GetExtraParmsForTexture,
@ -1526,6 +1527,7 @@ static render_api_t gRenderAPI = @@ -1526,6 +1527,7 @@ static render_api_t gRenderAPI =
Cvar_Set,
S_FadeMusicVolume,
COM_SetRandomSeed,
#endif
};
/*

2
ref_gl/gl_rmath.c

@ -13,10 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,10 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "gl_local.h"
#include "mathlib.h"
#include "client.h"
/*
========================================================================

20
ref_gl/gl_rmisc.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mod_local.h"
#include "shake.h"
@ -79,9 +77,9 @@ static void R_ParseDetailTextures( const char *filename ) @@ -79,9 +77,9 @@ static void R_ParseDetailTextures( const char *filename )
continue;
// search for existing texture and uploading detail texture
for( i = 0; i < cl.worldmodel->numtextures; i++ )
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
tex = cl.worldmodel->textures[i];
tex = WORLDMODEL->textures[i];
if( Q_stricmp( tex->name, texname ))
continue;
@ -116,7 +114,7 @@ void R_NewMap( void ) @@ -116,7 +114,7 @@ void R_NewMap( void )
{
string mapname, filepath;
Q_strncpy( mapname, cl.worldmodel->name, sizeof( mapname ));
Q_strncpy( mapname, WORLDMODEL->name, sizeof( mapname ));
COM_StripExtension( mapname );
Q_sprintf( filepath, "%s_detail.txt", mapname );
@ -152,20 +150,20 @@ void R_NewMap( void ) @@ -152,20 +150,20 @@ void R_NewMap( void )
}
// clear out efrags in case the level hasn't been reloaded
for( i = 0; i < cl.worldmodel->numleafs; i++ )
cl.worldmodel->leafs[i+1].efrags = NULL;
for( i = 0; i < WORLDMODEL->numleafs; i++ )
WORLDMODEL->leafs[i+1].efrags = NULL;
tr.skytexturenum = -1;
tr.max_recursion = 0;
pglDisable( GL_FOG );
// clearing texture chains
for( i = 0; i < cl.worldmodel->numtextures; i++ )
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
if( !cl.worldmodel->textures[i] )
if( !WORLDMODEL->textures[i] )
continue;
tx = cl.worldmodel->textures[i];
tx = WORLDMODEL->textures[i];
if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 ))
tr.skytexturenum = i;
@ -173,7 +171,7 @@ void R_NewMap( void ) @@ -173,7 +171,7 @@ void R_NewMap( void )
tx->texturechain = NULL;
}
R_SetupSky( clgame.movevars.skyName );
R_SetupSky( MOVEVARS->skyName );
GL_BuildLightmaps ();
R_GenerateVBO();

1320
ref_gl/gl_rpart.c

File diff suppressed because it is too large Load Diff

96
ref_gl/gl_rsurf.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mod_local.h"
#include "mathlib.h"
@ -879,7 +877,7 @@ void DrawGLPolyChain( glpoly_t *p, float soffset, float toffset ) @@ -879,7 +877,7 @@ void DrawGLPolyChain( glpoly_t *p, float soffset, float toffset )
_inline qboolean R_HasLightmap( void )
{
if( CVAR_TO_BOOL( r_fullbright ) || !cl.worldmodel->lightdata )
if( CVAR_TO_BOOL( r_fullbright ) || !WORLDMODEL->lightdata )
return false;
if( RI.currententity )
@ -1272,7 +1270,7 @@ void R_DrawTextureChains( void ) @@ -1272,7 +1270,7 @@ void R_DrawTextureChains( void )
RI.currententity = clgame.entities;
RI.currentmodel = RI.currententity->model;
if( FBitSet( world.flags, FWORLD_SKYSPHERE ) && !FBitSet( world.flags, FWORLD_CUSTOM_SKYBOX ))
if( FBitSet( WORLDMODEL->flags, FWORLD_SKYSPHERE ) && !FBitSet( WORLDMODEL->flags, FWORLD_CUSTOM_SKYBOX ))
{
pglDisable( GL_TEXTURE_2D );
pglColor3f( 1.0f, 1.0f, 1.0f );
@ -1282,7 +1280,7 @@ void R_DrawTextureChains( void ) @@ -1282,7 +1280,7 @@ void R_DrawTextureChains( void )
for( s = skychain; s != NULL; s = s->texturechain )
R_AddSkyBoxSurface( s );
if( FBitSet( world.flags, FWORLD_SKYSPHERE ) && !FBitSet( world.flags, FWORLD_CUSTOM_SKYBOX ))
if( FBitSet( WORLDMODEL->flags, FWORLD_SKYSPHERE ) && !FBitSet( WORLDMODEL->flags, FWORLD_CUSTOM_SKYBOX ))
{
pglEnable( GL_TEXTURE_2D );
if( skychain )
@ -1290,9 +1288,9 @@ void R_DrawTextureChains( void ) @@ -1290,9 +1288,9 @@ void R_DrawTextureChains( void )
skychain = NULL;
}
for( i = 0; i < cl.worldmodel->numtextures; i++ )
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
t = cl.worldmodel->textures[i];
t = WORLDMODEL->textures[i];
if( !t ) continue;
s = t->texturechain;
@ -1300,7 +1298,7 @@ void R_DrawTextureChains( void ) @@ -1300,7 +1298,7 @@ void R_DrawTextureChains( void )
if( !s || ( i == tr.skytexturenum ))
continue;
if(( s->flags & SURF_DRAWTURB ) && clgame.movevars.wateralpha < 1.0f )
if(( s->flags & SURF_DRAWTURB ) && MOVEVARS->wateralpha < 1.0f )
continue; // draw translucent water later
if( Host_IsQuakeCompatible() && FBitSet( s->flags, SURF_TRANSPARENT ))
@ -1348,9 +1346,9 @@ void R_DrawAlphaTextureChains( void ) @@ -1348,9 +1346,9 @@ void R_DrawAlphaTextureChains( void )
RI.currententity->curstate.rendermode = kRenderTransAlpha;
draw_alpha_surfaces = false;
for( i = 0; i < cl.worldmodel->numtextures; i++ )
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
t = cl.worldmodel->textures[i];
t = WORLDMODEL->textures[i];
if( !t ) continue;
s = t->texturechain;
@ -1384,7 +1382,7 @@ void R_DrawWaterSurfaces( void ) @@ -1384,7 +1382,7 @@ void R_DrawWaterSurfaces( void )
return;
// non-transparent water is already drawed
if( clgame.movevars.wateralpha >= 1.0f )
if( MOVEVARS->wateralpha >= 1.0f )
return;
// restore worldmodel
@ -1399,11 +1397,11 @@ void R_DrawWaterSurfaces( void ) @@ -1399,11 +1397,11 @@ void R_DrawWaterSurfaces( void )
pglDisable( GL_ALPHA_TEST );
pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
pglColor4f( 1.0f, 1.0f, 1.0f, clgame.movevars.wateralpha );
pglColor4f( 1.0f, 1.0f, 1.0f, MOVEVARS->wateralpha );
for( i = 0; i < cl.worldmodel->numtextures; i++ )
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
t = cl.worldmodel->textures[i];
t = WORLDMODEL->textures[i];
if( !t ) continue;
s = t->texturechain;
@ -1529,7 +1527,7 @@ void R_DrawBrushModel( cl_entity_t *e ) @@ -1529,7 +1527,7 @@ void R_DrawBrushModel( cl_entity_t *e )
clmodel = e->model;
// external models not loaded to VBO
if( clmodel->surfaces != cl.worldmodel->surfaces )
if( clmodel->surfaces != WORLDMODEL->surfaces )
allow_vbo = false;
if( !VectorIsNull( e->angles ))
@ -1610,22 +1608,22 @@ void R_DrawBrushModel( cl_entity_t *e ) @@ -1610,22 +1608,22 @@ void R_DrawBrushModel( cl_entity_t *e )
continue;
}
if( num_sorted < world.max_surfaces )
if( num_sorted < WORLDMODEL->max_surfaces )
{
world.draw_surfaces[num_sorted].surf = psurf;
world.draw_surfaces[num_sorted].cull = cull_type;
WORLDMODEL->draw_surfaces[num_sorted].surf = psurf;
WORLDMODEL->draw_surfaces[num_sorted].cull = cull_type;
num_sorted++;
}
}
// sort faces if needs
if( !FBitSet( clmodel->flags, MODEL_LIQUID ) && e->curstate.rendermode == kRenderTransTexture && !CVAR_TO_BOOL( gl_nosort ))
qsort( world.draw_surfaces, num_sorted, sizeof( sortedface_t ), R_SurfaceCompare );
qsort( WORLDMODEL->draw_surfaces, num_sorted, sizeof( sortedface_t ), R_SurfaceCompare );
// draw sorted translucent surfaces
for( i = 0; i < num_sorted; i++ )
if( !allow_vbo || !R_AddSurfToVBO( world.draw_surfaces[i].surf, true ) )
R_RenderBrushPoly( world.draw_surfaces[i].surf, world.draw_surfaces[i].cull );
if( !allow_vbo || !R_AddSurfToVBO( WORLDMODEL->draw_surfaces[i].surf, true ) )
R_RenderBrushPoly( WORLDMODEL->draw_surfaces[i].surf, WORLDMODEL->draw_surfaces[i].cull );
R_DrawVBO( R_HasLightmap(), true );
if( e->curstate.rendermode == kRenderTransColor )
@ -1775,7 +1773,7 @@ Allocate memory for arrays, fill it with vertex attribs and upload to GPU @@ -1775,7 +1773,7 @@ Allocate memory for arrays, fill it with vertex attribs and upload to GPU
*/
void R_GenerateVBO()
{
int numtextures = cl.worldmodel->numtextures;
int numtextures = WORLDMODEL->numtextures;
int numlightmaps = gl_lms.current_lightmap_texture;
int k, len = 0;
vboarray_t *vbo;
@ -1806,7 +1804,7 @@ void R_GenerateVBO() @@ -1806,7 +1804,7 @@ void R_GenerateVBO()
vbos.maxtexture = 0;
vbos.textures = Mem_Calloc( vbos.mempool, numtextures * numlightmaps * sizeof( vbotexture_t ) );
vbos.surfdata = Mem_Calloc( vbos.mempool, cl.worldmodel->numsurfaces * sizeof( vbosurfdata_t ) );
vbos.surfdata = Mem_Calloc( vbos.mempool, WORLDMODEL->numsurfaces * sizeof( vbosurfdata_t ) );
vbos.arraylist = vbo = Mem_Calloc( vbos.mempool, sizeof( vboarray_t ) );
vbos.decaldata = Mem_Calloc( vbos.mempool, sizeof( vbodecaldata_t ) );
vbos.decaldata->lm = Mem_Calloc( vbos.mempool, sizeof( msurface_t* ) * numlightmaps );
@ -1821,9 +1819,9 @@ void R_GenerateVBO() @@ -1821,9 +1819,9 @@ void R_GenerateVBO()
int i;
vbotexture_t *vbotex = &vbos.textures[k * numtextures + j];
for( i = 0; i < cl.worldmodel->numsurfaces; i++ )
for( i = 0; i < WORLDMODEL->numsurfaces; i++ )
{
msurface_t *surf = &cl.worldmodel->surfaces[i];
msurface_t *surf = &WORLDMODEL->surfaces[i];
if( surf->flags & ( SURF_DRAWSKY | SURF_DRAWTURB | SURF_CONVEYOR | SURF_DRAWTURB_QUADS ) )
continue;
@ -1831,7 +1829,7 @@ void R_GenerateVBO() @@ -1831,7 +1829,7 @@ void R_GenerateVBO()
if( surf->lightmaptexturenum != k )
continue;
if( R_TextureAnimation( surf ) != cl.worldmodel->textures[j] )
if( R_TextureAnimation( surf ) != WORLDMODEL->textures[j] )
continue;
if( vbo->array_len + surf->polys->numverts > USHRT_MAX )
@ -1888,9 +1886,9 @@ void R_GenerateVBO() @@ -1888,9 +1886,9 @@ void R_GenerateVBO()
if( maxindex < vbotex->len )
maxindex = vbotex->len;
for( i = 0; i < cl.worldmodel->numsurfaces; i++ )
for( i = 0; i < WORLDMODEL->numsurfaces; i++ )
{
msurface_t *surf = &cl.worldmodel->surfaces[i];
msurface_t *surf = &WORLDMODEL->surfaces[i];
int l;
if( surf->flags & ( SURF_DRAWSKY | SURF_DRAWTURB | SURF_CONVEYOR | SURF_DRAWTURB_QUADS ) )
@ -1899,7 +1897,7 @@ void R_GenerateVBO() @@ -1899,7 +1897,7 @@ void R_GenerateVBO()
if( surf->lightmaptexturenum != k )
continue;
if( R_TextureAnimation( surf ) != cl.worldmodel->textures[j] )
if( R_TextureAnimation( surf ) != WORLDMODEL->textures[j] )
continue;
// switch to next array
@ -1935,9 +1933,9 @@ void R_GenerateVBO() @@ -1935,9 +1933,9 @@ void R_GenerateVBO()
vbo->array[len + l].lm_tc[0] = v[5];
vbo->array[len + l].lm_tc[1] = v[6];
#ifdef NO_TEXTURE_MATRIX
if( cl.worldmodel->textures[j]->dt_texturenum )
if( WORLDMODEL->textures[j]->dt_texturenum )
{
gl_texture_t *glt = R_GetTexture( cl.worldmodel->textures[j]->gl_texturenum );
gl_texture_t *glt = R_GetTexture( WORLDMODEL->textures[j]->gl_texturenum );
vbo->array[len + l].dt_tc[0] = v[3] * glt->xscale;
vbo->array[len + l].dt_tc[1] = v[4] * glt->yscale;
}
@ -2162,7 +2160,7 @@ static texture_t *R_SetupVBOTexture( texture_t *tex, int number ) @@ -2162,7 +2160,7 @@ static texture_t *R_SetupVBOTexture( texture_t *tex, int number )
return tex;
if( !tex )
tex = R_TextureAnim( cl.worldmodel->textures[number] );
tex = R_TextureAnim( WORLDMODEL->textures[number] );
if( CVAR_TO_BOOL( r_detailtextures ) && tex->dt_texturenum && mtst.tmu_dt != -1 )
{
@ -2307,7 +2305,7 @@ static void R_DrawLightmappedVBO( vboarray_t *vbo, vbotexture_t *vbotex, texture @@ -2307,7 +2305,7 @@ static void R_DrawLightmappedVBO( vboarray_t *vbo, vbotexture_t *vbotex, texture
{
int smax, tmax;
byte *base;
uint indexbase = vbos.surfdata[((char*)surf - (char*)cl.worldmodel->surfaces) / sizeof( *surf )].startindex;
uint indexbase = vbos.surfdata[((char*)surf - (char*)WORLDMODEL->surfaces) / sizeof( *surf )].startindex;
uint index;
mextrasurf_t *info; // this stores current dlight offset
decal_t *pdecal;
@ -2623,7 +2621,7 @@ Draw generated index arrays @@ -2623,7 +2621,7 @@ Draw generated index arrays
*/
void R_DrawVBO( qboolean drawlightmap, qboolean drawtextures )
{
int numtextures = cl.worldmodel->numtextures;
int numtextures = WORLDMODEL->numtextures;
int numlightmaps = gl_lms.current_lightmap_texture;
int k;
vboarray_t *vbo = vbos.arraylist;
@ -2955,10 +2953,10 @@ static qboolean R_CheckLightMap( msurface_t *fa ) @@ -2955,10 +2953,10 @@ static qboolean R_CheckLightMap( msurface_t *fa )
qboolean R_AddSurfToVBO( msurface_t *surf, qboolean buildlightmap )
{
if( CVAR_TO_BOOL(r_vbo) && vbos.surfdata[surf - cl.worldmodel->surfaces].vbotexture )
if( CVAR_TO_BOOL(r_vbo) && vbos.surfdata[surf - WORLDMODEL->surfaces].vbotexture )
{
// find vbotexture_t assotiated with this surface
int idx = surf - cl.worldmodel->surfaces;
int idx = surf - WORLDMODEL->surfaces;
vbotexture_t *vbotex = vbos.surfdata[idx].vbotexture;
int texturenum = vbos.surfdata[idx].texturenum;
@ -2974,7 +2972,7 @@ qboolean R_AddSurfToVBO( msurface_t *surf, qboolean buildlightmap ) @@ -2974,7 +2972,7 @@ qboolean R_AddSurfToVBO( msurface_t *surf, qboolean buildlightmap )
if( vbos.mintexture > texturenum )
vbos.mintexture = texturenum;
buildlightmap &= !CVAR_TO_BOOL( r_fullbright ) && !!cl.worldmodel->lightdata;
buildlightmap &= !CVAR_TO_BOOL( r_fullbright ) && !!WORLDMODEL->lightdata;
if( buildlightmap && R_CheckLightMap( surf ) )
{
@ -3083,7 +3081,7 @@ loc0: @@ -3083,7 +3081,7 @@ loc0:
R_RecursiveWorldNode( node->children[side], clipflags );
// draw stuff
for( c = node->numsurfaces, surf = cl.worldmodel->surfaces + node->firstsurface; c; c--, surf++ )
for( c = node->numsurfaces, surf = WORLDMODEL->surfaces + node->firstsurface; c; c--, surf++ )
{
if( R_CullSurface( surf, &RI.frustum, clipflags ))
continue;
@ -3211,7 +3209,7 @@ void R_DrawWorldTopView( mnode_t *node, uint clipflags ) @@ -3211,7 +3209,7 @@ void R_DrawWorldTopView( mnode_t *node, uint clipflags )
}
// draw stuff
for( c = node->numsurfaces, surf = cl.worldmodel->surfaces + node->firstsurface; c; c--, surf++ )
for( c = node->numsurfaces, surf = WORLDMODEL->surfaces + node->firstsurface; c; c--, surf++ )
{
// don't process the same surface twice
if( surf->visframe == tr.framecount )
@ -3324,14 +3322,14 @@ void R_DrawWorld( void ) @@ -3324,14 +3322,14 @@ void R_DrawWorld( void )
start = Sys_DoubleTime();
if( RI.drawOrtho )
R_DrawWorldTopView( cl.worldmodel->nodes, RI.frustum.clipFlags );
else R_RecursiveWorldNode( cl.worldmodel->nodes, RI.frustum.clipFlags );
R_DrawWorldTopView( WORLDMODEL->nodes, RI.frustum.clipFlags );
else R_RecursiveWorldNode( WORLDMODEL->nodes, RI.frustum.clipFlags );
end = Sys_DoubleTime();
r_stats.t_world_node = end - start;
start = Sys_DoubleTime();
R_DrawVBO( !CVAR_TO_BOOL(r_fullbright) && !!cl.worldmodel->lightdata, true );
R_DrawVBO( !CVAR_TO_BOOL(r_fullbright) && !!WORLDMODEL->lightdata, true );
R_DrawTextureChains();
@ -3392,12 +3390,12 @@ void R_MarkLeaves( void ) @@ -3392,12 +3390,12 @@ void R_MarkLeaves( void )
if( RI.viewleaf->contents == CONTENTS_EMPTY )
{
VectorSet( test, RI.pvsorigin[0], RI.pvsorigin[1], RI.pvsorigin[2] - 16.0f );
leaf = Mod_PointInLeaf( test, cl.worldmodel->nodes );
leaf = Mod_PointInLeaf( test, WORLDMODEL->nodes );
}
else
{
VectorSet( test, RI.pvsorigin[0], RI.pvsorigin[1], RI.pvsorigin[2] + 16.0f );
leaf = Mod_PointInLeaf( test, cl.worldmodel->nodes );
leaf = Mod_PointInLeaf( test, WORLDMODEL->nodes );
}
if(( leaf->contents != CONTENTS_SOLID ) && ( RI.viewleaf != leaf ))
@ -3414,17 +3412,17 @@ void R_MarkLeaves( void ) @@ -3414,17 +3412,17 @@ void R_MarkLeaves( void )
RI.oldviewleaf = RI.viewleaf;
tr.visframecount++;
if( r_novis->value || RI.drawOrtho || !RI.viewleaf || !cl.worldmodel->visdata )
if( r_novis->value || RI.drawOrtho || !RI.viewleaf || !WORLDMODEL->visdata )
novis = true;
Mod_FatPVS( RI.pvsorigin, REFPVS_RADIUS, RI.visbytes, world.visbytes, FBitSet( RI.params, RP_OLDVIEWLEAF ), novis );
if( force && !novis ) Mod_FatPVS( test, REFPVS_RADIUS, RI.visbytes, world.visbytes, true, novis );
Mod_FatPVS( RI.pvsorigin, REFPVS_RADIUS, RI.visbytes, WORLDMODEL->visbytes, FBitSet( RI.params, RP_OLDVIEWLEAF ), novis );
if( force && !novis ) Mod_FatPVS( test, REFPVS_RADIUS, RI.visbytes, WORLDMODEL->visbytes, true, novis );
for( i = 0; i < cl.worldmodel->numleafs; i++ )
for( i = 0; i < WORLDMODEL->numleafs; i++ )
{
if( CHECKVISBIT( RI.visbytes, i ))
{
node = (mnode_t *)&cl.worldmodel->leafs[i+1];
node = (mnode_t *)&WORLDMODEL->leafs[i+1];
do
{
if( node->visframe == tr.visframecount )

2
ref_gl/gl_sprite.c

@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "pm_local.h"
#include "sprite.h"

17
ref_gl/gl_studio.c

@ -13,20 +13,25 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,20 +13,25 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "mathlib.h"
#include "const.h"
#include "r_studioint.h"
#include "triangleapi.h"
#include "studio.h"
#include "pm_local.h"
#include "gl_local.h"
#include "cl_tent.h"
#define EVENT_CLIENT 5000 // less than this value it's a server-side studio events
#define MAX_LOCALLIGHTS 4
typedef struct
{
char name[MAX_OSPATH];
char modelname[MAX_OSPATH];
model_t *model;
} player_model_t;
CVAR_DEFINE_AUTO( r_glowshellfreq, "2.2", 0, "glowing shell frequency update" );
CVAR_DEFINE_AUTO( r_shadows, "0", 0, "cast shadows from models" );
@ -3670,6 +3675,12 @@ void CL_InitStudioAPI( void ) @@ -3670,6 +3675,12 @@ void CL_InitStudioAPI( void )
{
pStudioDraw = &gStudioDraw;
// trying to grab them from client.dll
cl_righthand = Cvar_FindVar( "cl_righthand" );
if( cl_righthand == NULL )
cl_righthand = Cvar_Get( "cl_righthand", "0", FCVAR_ARCHIVE, "flip viewmodel (left to right)" );
// Xash will be used internal StudioModelRenderer
if( !clgame.dllFuncs.pfnGetStudioModelInterface )
return;

9
ref_gl/gl_warp.c

@ -13,8 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -13,8 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "common.h"
#include "client.h"
#include "gl_local.h"
#include "wadfile.h"
@ -311,7 +310,7 @@ void R_AddSkyBoxSurface( msurface_t *fa ) @@ -311,7 +310,7 @@ void R_AddSkyBoxSurface( msurface_t *fa )
float *v;
int i;
if( FBitSet( world.flags, FWORLD_SKYSPHERE ) && fa->polys && !FBitSet( world.flags, FWORLD_CUSTOM_SKYBOX ))
if( FBitSet( WORLDMODEL->flags, FWORLD_SKYSPHERE ) && fa->polys && !FBitSet( WORLDMODEL->flags, FWORLD_CUSTOM_SKYBOX ))
{
glpoly_t *p = fa->polys;
@ -355,7 +354,7 @@ void R_UnloadSkybox( void ) @@ -355,7 +354,7 @@ void R_UnloadSkybox( void )
tr.skyboxbasenum = 5800; // set skybox base (to let some mods load hi-res skyboxes)
memset( tr.skyboxTextures, 0, sizeof( tr.skyboxTextures ));
ClearBits( world.flags, FWORLD_CUSTOM_SKYBOX );
ClearBits( WORLDMODEL->flags, FWORLD_CUSTOM_SKYBOX );
}
/*
@ -455,7 +454,7 @@ void R_SetupSky( const char *skyboxname ) @@ -455,7 +454,7 @@ void R_SetupSky( const char *skyboxname )
if( i == 6 )
{
SetBits( world.flags, FWORLD_CUSTOM_SKYBOX );
SetBits( WORLDMODEL->flags, FWORLD_CUSTOM_SKYBOX );
Con_DPrintf( "done\n" );
return; // loaded
}

3
ref_gl/wscript

@ -33,7 +33,8 @@ def build(bld): @@ -33,7 +33,8 @@ def build(bld):
source = bld.path.ant_glob(['*.c'])
includes = ['.',
'../engine/common',
'../engine',
'../engine/common',
'../engine/server',
'../engine/client',
'../common',

2
wscript

@ -13,7 +13,7 @@ import fwgslib @@ -13,7 +13,7 @@ import fwgslib
VERSION = '0.99'
APPNAME = 'xash3d-fwgs'
SUBDIRS = [ 'engine', 'game_launch', 'mainui', 'vgui_support' ]
SUBDIRS = [ 'engine', 'game_launch', 'vgui_support', 'ref_gl' ]
top = '.'
def options(opt):

Loading…
Cancel
Save