Browse Source

ref: context creating prototype, not working yet

pull/2/head
Alibek Omarov 6 years ago
parent
commit
e5000742f1
  1. 2
      engine/client/cl_game.c
  2. 14
      engine/client/ref_common.c
  3. 19
      engine/client/vgui/vgui_draw.c
  4. 1
      engine/client/vid_common.c
  5. 35
      engine/client/vid_common.h
  6. 2
      engine/platform/platform.h
  7. 168
      engine/platform/sdl/vid_sdl.c
  8. 82
      engine/ref_api.h
  9. 6
      ref_gl/gl_context.c
  10. 3
      ref_gl/gl_local.h
  11. 181
      ref_gl/gl_opengl.c

2
engine/client/cl_game.c

@ -1236,7 +1236,7 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite, @@ -1236,7 +1236,7 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite,
if( type == SPR_MAPSPRITE )
ref.dllFuncs.Mod_LoadMapSprite( m_pSprite, buf, size, &loaded );
else ref.dllFuncs.Mod_LoadModel( mod_sprite, m_pSprite, buf, &loaded, texFlags );
else Mod_LoadSpriteModel( m_pSprite, buf, &loaded, texFlags );
Mem_Free( buf );

14
engine/client/ref_common.c

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
#include "client.h"
#include "library.h"
#include "cl_tent.h"
#include "platform/platform.h"
struct ref_state_s ref;
ref_globals_t refState;
@ -321,6 +322,7 @@ static ref_api_t gEngfuncs = @@ -321,6 +322,7 @@ static ref_api_t gEngfuncs =
pfnCL_GetPaletteColor,
pfnCL_GetScreenInfo,
pfnSetLocalLightLevel,
Sys_CheckParm,
pfnPlayerInfo,
R_StudioGetPlayerState,
@ -344,11 +346,12 @@ static ref_api_t gEngfuncs = @@ -344,11 +346,12 @@ static ref_api_t gEngfuncs =
FS_FileExists,
FS_AllowDirectPaths,
NULL,
NULL,
NULL,
NULL,
NULL,
R_Init_Video,
R_Free_Video,
GL_SetAttribute,
GL_GetAttribute,
GL_GetProcAddress,
BuildGammaTable,
LightToTexGamma,
@ -531,6 +534,7 @@ qboolean R_Init( void ) @@ -531,6 +534,7 @@ qboolean R_Init( void )
gl_showtextures = Cvar_Get( "gl_showtextures", "0", FCVAR_CHEAT, "show all uploaded textures" );
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" );
gl_wgl_msaa_samples = Cvar_Get( "gl_wgl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" );
if( !R_LoadProgs( refdll ))
{

19
engine/client/vgui/vgui_draw.c

@ -194,6 +194,23 @@ qboolean VGui_IsActive( void ) @@ -194,6 +194,23 @@ qboolean VGui_IsActive( void )
return vgui.initialized;
}
void VGui_FillAPIFromRef( vguiapi_t *to, const ref_interface_t *from )
{
to->DrawInit = from->VGUI_DrawInit;
to->DrawShutdown = from->VGUI_DrawShutdown;
to->SetupDrawingText = from->VGUI_SetupDrawingText;
to->SetupDrawingRect = from->VGUI_SetupDrawingRect;
to->SetupDrawingImage = from->VGUI_SetupDrawingImage;
to->BindTexture = from->VGUI_BindTexture;
to->EnableTexture = from->VGUI_EnableTexture;
to->CreateTexture = from->VGUI_CreateTexture;
to->UploadTexture = from->VGUI_UploadTexture;
to->UploadTextureBlock = from->VGUI_UploadTextureBlock;
to->DrawQuad = from->VGUI_DrawQuad;
to->GetTextureSizes = from->VGUI_GetTextureSizes;
to->GenerateTexture = from->VGUI_GenerateTexture;
}
/*
================
VGui_Startup
@ -218,6 +235,8 @@ void VGui_Startup( int width, int height ) @@ -218,6 +235,8 @@ void VGui_Startup( int width, int height )
{
vgui_utf8 = Cvar_Get( "vgui_utf8", "0", FCVAR_ARCHIVE, "enable utf-8 support for vgui text" );
VGui_FillAPIFromRef( &vgui, &ref.dllFuncs );
#ifdef XASH_INTERNAL_GAMELIBS
s_pVGuiSupport = COM_LoadLibrary( "client", false, false );

1
engine/client/vid_common.c

@ -29,7 +29,6 @@ convar_t *vid_highdpi; @@ -29,7 +29,6 @@ convar_t *vid_highdpi;
vidstate_t vidState;
glwstate_t glw_state;
glcontext_t glContext;
convar_t *window_xpos;
convar_t *window_ypos;

35
engine/client/vid_common.h

@ -13,19 +13,6 @@ typedef struct vidmode_s @@ -13,19 +13,6 @@ typedef struct vidmode_s
} 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
@ -37,9 +24,10 @@ typedef struct @@ -37,9 +24,10 @@ typedef struct
qboolean initialized; // OpenGL subsystem started
qboolean extended; // extended context allows to GL_Debug
} glwstate_t;
} glwstate_t;
typedef struct vidstate_s
{
int width, height;
@ -48,25 +36,8 @@ typedef struct vidstate_s @@ -48,25 +36,8 @@ typedef struct vidstate_s
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;
extern glwstate_t glw_state;
#define VID_MIN_HEIGHT 200
#define VID_MIN_WIDTH 320

2
engine/platform/platform.h

@ -90,6 +90,8 @@ int R_MaxVideoModes(); @@ -90,6 +90,8 @@ int R_MaxVideoModes();
vidmode_t*R_GetVideoMode( int num );
void* GL_GetProcAddress( const char *name ); // RenderAPI requirement
void GL_UpdateSwapInterval( void );
int GL_SetAttribute( int attr, int val );
int GL_GetAttribute( int attr, int *val );
/*
==============================================================================

168
engine/platform/sdl/vid_sdl.c

@ -23,7 +23,6 @@ GNU General Public License for more details. @@ -23,7 +23,6 @@ GNU General Public License for more details.
static vidmode_t *vidmodes = NULL;
static int num_vidmodes = 0;
static int context_flags = 0;
static void GL_SetupAttributes( void );
int R_MaxVideoModes( void )
@ -231,34 +230,13 @@ GL_CreateContext @@ -231,34 +230,13 @@ GL_CreateContext
*/
qboolean GL_CreateContext( void )
{
int colorBits[3];
#ifdef XASH_NANOGL
nanoGL_Init();
#endif
if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL)
{
Con_Reportf( S_ERROR "GL_CreateContext: %s\n", SDL_GetError());
return GL_DeleteContext();
}
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] );
glContext.color_bits = colorBits[0] + colorBits[1] + colorBits[2];
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, &glContext.msaasamples );
#ifdef XASH_WES
void wes_init();
wes_init();
#endif
ref.dllFuncs.GL_OnContextCreated();
return true;
}
@ -388,7 +366,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) @@ -388,7 +366,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
if( !gl_wgl_msaa_samples->value && glw_state.safe + 1 == SAFE_NOMSAA )
glw_state.safe += 2; // no need to skip msaa, if we already disabled it
else glw_state.safe++;
GL_SetupAttributes(); // re-choose attributes
GL_SetupAttributes( ); // re-choose attributes
// try again
return VID_CreateWindow( width, height, fullscreen );
@ -505,132 +483,19 @@ GL_SetupAttributes @@ -505,132 +483,19 @@ GL_SetupAttributes
*/
static void GL_SetupAttributes( void )
{
int samples;
#if !defined(_WIN32)
SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" );
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
#endif
SDL_GL_ResetAttributes();
#ifdef XASH_GLES
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_EGL, 1 );
#ifdef XASH_NANOGL
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
#elif defined( XASH_WES ) || defined( XASH_REGAL )
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 0 );
#endif
#else // GL1.x
#ifndef XASH_GL_STATIC
if( Sys_CheckParm( "-gldebug" ) )
{
Con_Reportf( "Creating an extended GL context for debug...\n" );
SetBits( context_flags, FCONTEXT_DEBUG_ARB );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
glw_state.extended = true;
}
#endif // XASH_GL_STATIC
if( Sys_CheckParm( "-glcore" ))
{
SetBits( context_flags, FCONTEXT_CORE_PROFILE );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
}
else
{
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY );
}
#endif // XASH_GLES
if( glw_state.safe > SAFE_DONTCARE )
{
glw_state.safe = -1; // can't retry anymore, can only shutdown engine
return;
}
Msg( "Trying safe opengl mode %d\n", glw_state.safe );
if( glw_state.safe == SAFE_DONTCARE )
return;
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if( glw_state.safe < SAFE_NOACC )
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
Msg( "bpp %d\n", glw_state.desktopBitsPixel );
/// 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 );
if( glw_state.safe < SAFE_NODEPTH )
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
else
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8 );
if( glw_state.safe < SAFE_NOCOLOR )
{
if( glw_state.desktopBitsPixel >= 24 )
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
}
else if( glw_state.desktopBitsPixel >= 16 )
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
}
else
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 3 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 3 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 2 );
}
}
if( glw_state.safe < SAFE_NOMSAA )
{
switch( (int)gl_wgl_msaa_samples->value )
{
case 2:
case 4:
case 8:
case 16:
samples = gl_wgl_msaa_samples->value;
break;
default:
samples = 0; // don't use, because invalid parameter is passed
}
if( samples )
{
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );
ref.dllFuncs.GL_SetupAttributes( glw_state.safe );
}
glContext.max_multisamples = samples;
}
else
{
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 0 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 0 );
int GL_SetAttribute( int attr, int val )
{
return SDL_GL_SetAttribute( (SDL_GLattr)attr, val );
}
glContext.max_multisamples = 0;
}
}
else
{
Cvar_Set( "gl_wgl_msaa_samples", "0" );
}
int GL_GetAttribute( int attr, int *val )
{
return SDL_GL_GetAttribute( (SDL_GLattr)attr, val );
}
#ifndef EGL_LIB
@ -656,7 +521,13 @@ qboolean R_Init_Video( void ) @@ -656,7 +521,13 @@ qboolean R_Init_Video( void )
if( !glw_state.safe && Sys_GetParmFromCmdLine( "-safegl", safe ) )
glw_state.safe = bound( SAFE_NO, Q_atoi( safe ), SAFE_DONTCARE );
GL_SetupAttributes();
#if !defined(_WIN32)
SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" );
SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" );
#endif
// refdll can request some attributes
GL_SetupAttributes( );
if( SDL_GL_LoadLibrary( EGL_LIB ) )
{
@ -676,8 +547,11 @@ qboolean R_Init_Video( void ) @@ -676,8 +547,11 @@ qboolean R_Init_Video( void )
return retval;
}
// refdll also can check extensions
ref.dllFuncs.GL_InitExtensions();
host.renderinfo_changed = false;
return true;
}

82
engine/ref_api.h

@ -144,6 +144,72 @@ enum ref_defaultsprite_e @@ -144,6 +144,72 @@ enum ref_defaultsprite_e
REF_CHROME_SPRITE // cl_sprite_shell
};
enum ref_graphic_apis_e
{
REF_SOFTWARE, // hypothetical: just make a surface to draw on, in software
REF_GL, // create GL context
};
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
} ref_safegl_context_t;
// binary compatible with SDL2
enum // OpenGL configuration attributes
{
REF_GL_RED_SIZE,
REF_GL_GREEN_SIZE,
REF_GL_BLUE_SIZE,
REF_GL_ALPHA_SIZE,
REF_GL_BUFFER_SIZE,
REF_GL_DOUBLEBUFFER,
REF_GL_DEPTH_SIZE,
REF_GL_STENCIL_SIZE,
REF_GL_ACCUM_RED_SIZE,
REF_GL_ACCUM_GREEN_SIZE,
REF_GL_ACCUM_BLUE_SIZE,
REF_GL_ACCUM_ALPHA_SIZE,
REF_GL_STEREO,
REF_GL_MULTISAMPLEBUFFERS,
REF_GL_MULTISAMPLESAMPLES,
REF_GL_ACCELERATED_VISUAL,
REF_GL_RETAINED_BACKING,
REF_GL_CONTEXT_MAJOR_VERSION,
REF_GL_CONTEXT_MINOR_VERSION,
REF_GL_CONTEXT_EGL,
REF_GL_CONTEXT_FLAGS,
REF_GL_CONTEXT_PROFILE_MASK,
REF_GL_SHARE_WITH_CURRENT_CONTEXT,
REF_GL_FRAMEBUFFER_SRGB_CAPABLE,
REF_GL_CONTEXT_RELEASE_BEHAVIOR,
REF_GL_CONTEXT_RESET_NOTIFICATION,
REF_GL_CONTEXT_NO_ERROR
};
enum
{
REF_GL_CONTEXT_PROFILE_CORE = 0x0001,
REF_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002,
REF_GL_CONTEXT_PROFILE_ES = 0x0004 /**< GLX_CONTEXT_ES2_PROFILE_BIT_EXT */
};
enum
{
REF_GL_CONTEXT_DEBUG_FLAG = 0x0001,
REF_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002,
REF_GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004,
REF_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008
};
struct con_nprint_s;
struct remap_info_s;
@ -260,6 +326,7 @@ typedef struct ref_api_s @@ -260,6 +326,7 @@ typedef struct ref_api_s
byte *(*CL_GetPaletteColor)(int color); // clgame.palette[color]
void (*CL_GetScreenInfo)( int *width, int *height ); // clgame.scrInfo, ptrs may be NULL
void (*SetLocalLightLevel)( int level ); // cl.local.light_level
int (*Sys_CheckParm)( const char *flag );
// studio interface
player_info_t *(*pfnPlayerInfo)( int index );
@ -289,11 +356,15 @@ typedef struct ref_api_s @@ -289,11 +356,15 @@ typedef struct ref_api_s
int (*FS_FileExists)( const char *filename, int gamedironly );
void (*FS_AllowDirectPaths)( qboolean enable );
// video init
// try to create window
// will call GL_SetupAttributes in case of REF_GL
int (*R_Init_Video)( int type );
void (*R_Free_Video)( void );
// GL
int (*GL_SetAttribute)( int attr, int value );
int (*GL_GetAttribute)( int attr );
int (*GL_CreateContext)( void ); // TODO
void (*GL_DestroyContext)( );
int (*GL_GetAttribute)( int attr, int *value );
void *(*GL_GetProcAddress)( const char *name );
// gamma
@ -347,6 +418,8 @@ typedef struct ref_interface_s @@ -347,6 +418,8 @@ typedef struct ref_interface_s
void (*R_Shutdown)( void );
//
void (*GL_SetupAttributes)( int safegl );
void (*GL_OnContextCreated)( void );
void (*GL_InitExtensions)( void );
void (*GL_ClearExtensions)( void );
@ -528,6 +601,9 @@ typedef struct ref_interface_s @@ -528,6 +601,9 @@ typedef struct ref_interface_s
void (*VGUI_UploadTexture)( int id, const char *buffer, int width, int height );
void (*VGUI_UploadTextureBlock)( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight );
void (*VGUI_DrawQuad)( const vpoint_t *ul, const vpoint_t *lr );
void (*VGUI_GetTextureSizes)( int *width, int *height );
int (*VGUI_GenerateTexture)( void );
} ref_interface_t;
typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals );

6
ref_gl/gl_context.c

@ -325,6 +325,8 @@ ref_interface_t gReffuncs = @@ -325,6 +325,8 @@ ref_interface_t gReffuncs =
R_Init,
R_Shutdown,
GL_SetupAttributes,
GL_OnContextCreated,
GL_InitExtensions,
GL_ClearExtensions,
@ -471,7 +473,9 @@ ref_interface_t gReffuncs = @@ -471,7 +473,9 @@ ref_interface_t gReffuncs =
VGUI_CreateTexture,
VGUI_UploadTexture,
VGUI_UploadTextureBlock,
VGUI_DrawQuad
VGUI_DrawQuad,
VGUI_GetTextureSizes,
VGUI_GenerateTexture,
};
int GAME_EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, ref_globals_t *globals )

3
ref_gl/gl_local.h

@ -516,6 +516,8 @@ int VGUI_GenerateTexture( void ); @@ -516,6 +516,8 @@ int VGUI_GenerateTexture( void );
//
qboolean R_Init( void );
void R_Shutdown( void );
void GL_SetupAttributes( int safegl );
void GL_OnContextCreated( void );
void GL_InitExtensions( void );
void GL_ClearExtensions( void );
void VID_CheckChanges( void );
@ -719,7 +721,6 @@ extern convar_t *gl_extensions; @@ -719,7 +721,6 @@ extern convar_t *gl_extensions;
extern convar_t *gl_check_errors;
extern convar_t *gl_texture_lodbias;
extern convar_t *gl_texture_nearest;
extern convar_t *gl_wgl_msaa_samples;
extern convar_t *gl_lightmap_nearest;
extern convar_t *gl_keeptjunctions;
extern convar_t *gl_emboss_scale;

181
ref_gl/gl_opengl.c

@ -42,7 +42,6 @@ convar_t *gl_round_down; @@ -42,7 +42,6 @@ convar_t *gl_round_down;
convar_t *r_vbo;
convar_t *r_vbo_dlightmode;
convar_t *gl_showtextures;
convar_t *gl_wgl_msaa_samples;
convar_t *cl_lightstyle_lerping;
convar_t *vid_brightness;
@ -788,7 +787,6 @@ void GL_InitCommands( void ) @@ -788,7 +787,6 @@ void GL_InitCommands( void )
gl_clear = gEngfuncs.Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" );
gl_test = gEngfuncs.Cvar_Get( "gl_test", "0", 0, "engine developer cvar for quick testing new features" );
gl_wireframe = gEngfuncs.Cvar_Get( "gl_wireframe", "0", FCVAR_ARCHIVE|FCVAR_SPONLY, "show wireframe overlay" );
gl_wgl_msaa_samples = gEngfuncs.Cvar_Get( "gl_wgl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" );
gl_msaa = gEngfuncs.Cvar_Get( "gl_msaa", "1", FCVAR_ARCHIVE, "enable or disable multisample anti-aliasing" );
gl_stencilbits = gEngfuncs.Cvar_Get( "gl_stencilbits", "8", FCVAR_GLCONFIG, "pixelformat stencil bits (0 - auto)" );
gl_round_down = gEngfuncs.Cvar_Get( "gl_round_down", "2", FCVAR_RENDERINFO, "round texture sizes to nearest POT value" );
@ -866,6 +864,16 @@ static void R_CheckVBO( void ) @@ -866,6 +864,16 @@ static void R_CheckVBO( void )
r_vbo->flags |= FCVAR_ARCHIVE;
}
/*
=================
GL_RemoveCommands
=================
*/
void GL_RemoveCommands( void )
{
gEngfuncs.Cmd_RemoveCommand( "r_info" );
}
/*
===============
R_Init
@ -882,18 +890,15 @@ qboolean R_Init( void ) @@ -882,18 +890,15 @@ qboolean R_Init( void )
GL_SetDefaultState();
// create the window and set up the context
#if 0 // REFTODO: just make it compile
if( !R_Init_Video( ))
if( !gEngfuncs.R_Init_Video( REF_GL )) // request GL context
{
GL_RemoveCommands();
R_Free_Video();
gEngfuncs.R_Free_Video();
gEngfuncs.Host_Error( "Can't initialize video subsystem\nProbably driver was not installed" );
return false;
}
host.renderinfo_changed = false;
#endif
r_temppool = Mem_AllocPool( "Render Zone" );
GL_SetDefaults();
@ -908,16 +913,6 @@ qboolean R_Init( void ) @@ -908,16 +913,6 @@ qboolean R_Init( void )
return true;
}
/*
=================
GL_RemoveCommands
=================
*/
void GL_RemoveCommands( void )
{
gEngfuncs.Cmd_RemoveCommand( "r_info" );
}
/*
===============
R_Shutdown
@ -933,10 +928,8 @@ void R_Shutdown( void ) @@ -933,10 +928,8 @@ void R_Shutdown( void )
Mem_FreePool( &r_temppool );
#if 0 // REFTODO: just make it compile
// shut down OS specific OpenGL stuff like contexts, etc.
R_Free_Video();
#endif // 0
gEngfuncs.R_Free_Video();
}
/*
@ -985,3 +978,151 @@ void GL_CheckForErrors_( const char *filename, const int fileline ) @@ -985,3 +978,151 @@ void GL_CheckForErrors_( const char *filename, const int fileline )
gEngfuncs.Con_Printf( S_OPENGL_ERROR "%s (called at %s:%i)\n", GL_ErrorString( err ), filename, fileline );
}
void GL_SetupAttributes( int safegl )
{
int context_flags = 0; // REFTODO!!!!!
int samples = 0;
#ifdef XASH_GLES
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_PROFILE_MASK, REF_GL_CONTEXT_PROFILE_ES );
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_EGL, 1 );
#ifdef XASH_NANOGL
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_MAJOR_VERSION, 1 );
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_MINOR_VERSION, 1 );
#elif defined( XASH_WES ) || defined( XASH_REGAL )
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_MAJOR_VERSION, 2 );
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_MINOR_VERSION, 0 );
#endif
#else // GL1.x
#ifndef XASH_GL_STATIC
if( gEngfuncs.Sys_CheckParm( "-gldebug" ) )
{
gEngfuncs.Con_Reportf( "Creating an extended GL context for debug...\n" );
SetBits( context_flags, FCONTEXT_DEBUG_ARB );
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_FLAGS, REF_GL_CONTEXT_DEBUG_FLAG );
glw_state.extended = true;
}
#endif // XASH_GL_STATIC
if( gEngfuncs.Sys_CheckParm( "-glcore" ))
{
SetBits( context_flags, FCONTEXT_CORE_PROFILE );
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_PROFILE_MASK, REF_GL_CONTEXT_PROFILE_CORE );
}
else
{
gEngfuncs.GL_SetAttribute( REF_GL_CONTEXT_PROFILE_MASK, REF_GL_CONTEXT_PROFILE_COMPATIBILITY );
}
#endif // XASH_GLES
if( safegl > SAFE_DONTCARE )
{
safegl = -1; // can't retry anymore, can only shutdown engine
return;
}
gEngfuncs.Con_Printf( "Trying safe opengl mode %d\n", safegl );
if( safegl == SAFE_DONTCARE )
return;
gEngfuncs.GL_SetAttribute( REF_GL_DOUBLEBUFFER, 1 );
if( safegl < SAFE_NOACC )
gEngfuncs.GL_SetAttribute( REF_GL_ACCELERATED_VISUAL, 1 );
gEngfuncs.Con_Printf( "bpp %d\n", glw_state.desktopBitsPixel );
if( safegl < SAFE_NOSTENCIL )
gEngfuncs.GL_SetAttribute( REF_GL_STENCIL_SIZE, gl_stencilbits->value );
if( safegl < SAFE_NOALPHA )
gEngfuncs.GL_SetAttribute( REF_GL_ALPHA_SIZE, 8 );
if( safegl < SAFE_NODEPTH )
gEngfuncs.GL_SetAttribute( REF_GL_DEPTH_SIZE, 24 );
else
gEngfuncs.GL_SetAttribute( REF_GL_DEPTH_SIZE, 8 );
if( safegl < SAFE_NOCOLOR )
{
if( glw_state.desktopBitsPixel >= 24 )
{
gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 8 );
gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 8 );
gEngfuncs.GL_SetAttribute( REF_GL_BLUE_SIZE, 8 );
}
else if( glw_state.desktopBitsPixel >= 16 )
{
gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 5 );
gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 6 );
gEngfuncs.GL_SetAttribute( REF_GL_BLUE_SIZE, 5 );
}
else
{
gEngfuncs.GL_SetAttribute( REF_GL_RED_SIZE, 3 );
gEngfuncs.GL_SetAttribute( REF_GL_GREEN_SIZE, 3 );
gEngfuncs.GL_SetAttribute( REF_GL_BLUE_SIZE, 2 );
}
}
if( safegl < SAFE_NOMSAA )
{
switch( (int)gEngfuncs.pfnGetCvarFloat( "gl_wgl_msaa_samples" ))
{
case 2:
case 4:
case 8:
case 16:
samples = gEngfuncs.pfnGetCvarFloat( "gl_wgl_msaa_samples" );
break;
default:
samples = 0; // don't use, because invalid parameter is passed
}
if( samples )
{
gEngfuncs.GL_SetAttribute( REF_GL_MULTISAMPLEBUFFERS, 1 );
gEngfuncs.GL_SetAttribute( REF_GL_MULTISAMPLESAMPLES, samples );
glConfig.max_multisamples = samples;
}
else
{
gEngfuncs.GL_SetAttribute( REF_GL_MULTISAMPLEBUFFERS, 0 );
gEngfuncs.GL_SetAttribute( REF_GL_MULTISAMPLESAMPLES, 0 );
glConfig.max_multisamples = 0;
}
}
else
{
gEngfuncs.Cvar_Set( "gl_wgl_msaa_samples", "0" );
}
}
void GL_OnContextCreated( void )
{
int colorBits[3];
#ifdef XASH_NANOGL
nanoGL_Init();
#endif
gEngfuncs.GL_GetAttribute( REF_GL_RED_SIZE, &colorBits[0] );
gEngfuncs.GL_GetAttribute( REF_GL_GREEN_SIZE, &colorBits[1] );
gEngfuncs.GL_GetAttribute( REF_GL_BLUE_SIZE, &colorBits[2] );
glConfig.color_bits = colorBits[0] + colorBits[1] + colorBits[2];
gEngfuncs.GL_GetAttribute( REF_GL_ALPHA_SIZE, &glConfig.alpha_bits );
gEngfuncs.GL_GetAttribute( REF_GL_DEPTH_SIZE, &glConfig.depth_bits );
gEngfuncs.GL_GetAttribute( REF_GL_STENCIL_SIZE, &glConfig.stencil_bits );
glState.stencilEnabled = glConfig.stencil_bits ? true : false;
gEngfuncs.GL_GetAttribute( REF_GL_MULTISAMPLESAMPLES, &glConfig.msaasamples );
#ifdef XASH_WES
void wes_init();
wes_init();
#endif
}

Loading…
Cancel
Save