Removed vk_enabled()/gl_enabled().

Just use corresponding expressions directly during APIs initialization, in other places use glActive/vk.active.
This commit is contained in:
Artem Kharytoniuk 2017-05-26 12:15:51 +03:00
parent 3af17877e9
commit 0cc338ba62
6 changed files with 36 additions and 40 deletions

View File

@ -651,6 +651,9 @@ static void GLW_InitExtensions( void )
*/ */
void GLimp_EndFrame (void) void GLimp_EndFrame (void)
{ {
if (!glActive)
return;
// //
// swapinterval stuff // swapinterval stuff
// //
@ -768,6 +771,7 @@ void GLimp_Shutdown( void )
WG_RestoreGamma(); WG_RestoreGamma();
glActive = false;
memset(&glConfig, 0, sizeof(glConfig)); memset(&glConfig, 0, sizeof(glConfig));
memset(&glState, 0, sizeof(glState)); memset(&glState, 0, sizeof(glState));
@ -788,7 +792,7 @@ void vk_imp_init() {
ri.Printf(PRINT_ALL, "Initializing Vulkan subsystem\n"); ri.Printf(PRINT_ALL, "Initializing Vulkan subsystem\n");
// This will set qgl pointers to no-op placeholders. // This will set qgl pointers to no-op placeholders.
if (!gl_enabled()) { if (!glActive) {
QGL_Init(nullptr); QGL_Init(nullptr);
qglActiveTextureARB = [] (GLenum) {}; qglActiveTextureARB = [] (GLenum) {};
qglClientActiveTextureARB = [](GLenum) {}; qglClientActiveTextureARB = [](GLenum) {};

View File

@ -188,13 +188,7 @@ static void noglEnableClientState(GLenum array) {}
static void noglEnd(void) {} static void noglEnd(void) {}
static void noglFinish(void) {} static void noglFinish(void) {}
static GLenum noglGetError(void) { return GL_NO_ERROR; } static GLenum noglGetError(void) { return GL_NO_ERROR; }
static void noglGetIntegerv(GLenum pname, GLint *params) {}
static void noglGetIntegerv(GLenum pname, GLint *params) {
if (pname == GL_MAX_TEXTURE_SIZE) {
*params = 2048;
}
}
static const GLubyte* noglGetString(GLenum name) { static char* s = ""; return (GLubyte*)s;} static const GLubyte* noglGetString(GLenum name) { static char* s = ""; return (GLubyte*)s;}
static void noglLineWidth(GLfloat width) {} static void noglLineWidth(GLfloat width) {}
static void noglLoadIdentity(void) {} static void noglLoadIdentity(void) {}
@ -667,18 +661,14 @@ static void APIENTRY logViewport(GLint x, GLint y, GLsizei width, GLsizei height
*/ */
void QGL_Shutdown( void ) void QGL_Shutdown( void )
{ {
if (gl_enabled()) { if ( hinstOpenGL )
{
ri.Printf( PRINT_ALL, "...shutting down QGL\n" ); ri.Printf( PRINT_ALL, "...shutting down QGL\n" );
ri.Printf( PRINT_ALL, "...unloading OpenGL DLL\n" );
if ( hinstOpenGL ) FreeLibrary( hinstOpenGL );
{ hinstOpenGL = NULL;
ri.Printf( PRINT_ALL, "...unloading OpenGL DLL\n" );
FreeLibrary( hinstOpenGL );
}
} }
hinstOpenGL = NULL;
qglAlphaFunc = NULL; qglAlphaFunc = NULL;
qglBegin = NULL; qglBegin = NULL;
qglBindTexture = NULL; qglBindTexture = NULL;
@ -739,7 +729,7 @@ void QGL_Shutdown( void )
} }
# pragma warning (disable : 4113 4133 4047 ) # pragma warning (disable : 4113 4133 4047 )
# define GPA( a ) (gl_enabled() ? (void*)GetProcAddress(hinstOpenGL, #a) : (void*)(&no ## a)) # define GPA( a ) (dllname ? (void*)GetProcAddress(hinstOpenGL, #a) : (void*)(&no ## a))
/* /*
** QGL_Init ** QGL_Init
@ -752,7 +742,7 @@ void QGL_Shutdown( void )
*/ */
qboolean QGL_Init( const char *dllname ) qboolean QGL_Init( const char *dllname )
{ {
if (gl_enabled()) { if (dllname != nullptr) {
assert( hinstOpenGL == 0 ); assert( hinstOpenGL == 0 );
ri.Printf( PRINT_ALL, "...initializing QGL\n" ); ri.Printf( PRINT_ALL, "...initializing QGL\n" );
@ -830,7 +820,7 @@ qboolean QGL_Init( const char *dllname )
qglLockArraysEXT = 0; qglLockArraysEXT = 0;
qglUnlockArraysEXT = 0; qglUnlockArraysEXT = 0;
if (gl_enabled()) { if (dllname != nullptr) {
// check logging // check logging
QGL_EnableLogging( (qboolean) r_logFile->integer ); QGL_EnableLogging( (qboolean) r_logFile->integer );
} }

View File

@ -901,7 +901,7 @@ void RB_ShowImages( void ) {
float x, y, w, h; float x, y, w, h;
int start, end; int start, end;
if (!gl_enabled()) if (!glActive)
return; return;
if ( !backEnd.projection2D ) { if ( !backEnd.projection2D ) {
@ -1041,8 +1041,7 @@ const void *RB_SwapBuffers( const void *data ) {
GLimp_LogComment( "***************** RB_SwapBuffers *****************\n\n\n" ); GLimp_LogComment( "***************** RB_SwapBuffers *****************\n\n\n" );
if (gl_enabled()) GLimp_EndFrame();
GLimp_EndFrame();
backEnd.projection2D = qfalse; backEnd.projection2D = qfalse;

View File

@ -582,8 +582,9 @@ static void Upload32( unsigned *data,
// scale both axis down equally so we don't have to // scale both axis down equally so we don't have to
// deal with a half mip resampling // deal with a half mip resampling
// //
while ( scaled_width > glConfig.maxTextureSize int max_texture_size = glActive ? glConfig.maxTextureSize : 2048;
|| scaled_height > glConfig.maxTextureSize ) { while ( scaled_width > max_texture_size
|| scaled_height > max_texture_size ) {
scaled_width >>= 1; scaled_width >>= 1;
scaled_height >>= 1; scaled_height >>= 1;
} }

View File

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "tr_local.h" #include "tr_local.h"
bool glActive;
glconfig_t glConfig; glconfig_t glConfig;
glstate_t glState; glstate_t glState;
@ -185,19 +186,22 @@ static void InitRenderAPI( void )
// //
if ( glConfig.vidWidth == 0 ) if ( glConfig.vidWidth == 0 )
{ {
if (gl_enabled()) // OpenGL
if (r_renderAPI->integer == 0 || r_twinMode->integer) {
GLimp_Init(); GLimp_Init();
GLint temp;
qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &temp );
glConfig.maxTextureSize = temp;
glActive = true;
}
// VULKAN // VULKAN
if (vk_enabled()) { if (r_renderAPI->integer != 0 || r_twinMode->integer) {
vk_imp_init(); vk_imp_init();
vk_initialize(); vk_initialize();
} }
// OpenGL driver constants
GLint temp;
qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &temp );
glConfig.maxTextureSize = temp;
} }
// init command buffers and SMP // init command buffers and SMP
@ -760,7 +764,7 @@ void GfxInfo_f( void )
"fullscreen" "fullscreen"
}; };
if (gl_enabled()) { if (glActive) {
ri.Printf( PRINT_ALL, "\nGL_VENDOR: %s\n", glConfig.vendor_string ); ri.Printf( PRINT_ALL, "\nGL_VENDOR: %s\n", glConfig.vendor_string );
ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glConfig.renderer_string ); ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glConfig.renderer_string );
ri.Printf( PRINT_ALL, "GL_VERSION: %s\n", glConfig.version_string ); ri.Printf( PRINT_ALL, "GL_VERSION: %s\n", glConfig.version_string );
@ -786,7 +790,7 @@ void GfxInfo_f( void )
ri.Printf( PRINT_ALL, "picmip: %d\n", r_picmip->integer ); ri.Printf( PRINT_ALL, "picmip: %d\n", r_picmip->integer );
ri.Printf( PRINT_ALL, "texture bits: %d\n", r_texturebits->integer ); ri.Printf( PRINT_ALL, "texture bits: %d\n", r_texturebits->integer );
if (gl_enabled()) { if (glActive) {
ri.Printf( PRINT_ALL, "compiled vertex arrays: %s\n", enablestrings[qglLockArraysEXT != 0 ] ); ri.Printf( PRINT_ALL, "compiled vertex arrays: %s\n", enablestrings[qglLockArraysEXT != 0 ] );
ri.Printf( PRINT_ALL, "texenv add: %s\n", enablestrings[glConfig.textureEnvAddAvailable != 0] ); ri.Printf( PRINT_ALL, "texenv add: %s\n", enablestrings[glConfig.textureEnvAddAvailable != 0] );
ri.Printf( PRINT_ALL, "compressed textures: %s\n", enablestrings[glConfig.textureCompression!=TC_NONE] ); ri.Printf( PRINT_ALL, "compressed textures: %s\n", enablestrings[glConfig.textureCompression!=TC_NONE] );
@ -796,12 +800,12 @@ void GfxInfo_f( void )
{ {
ri.Printf( PRINT_ALL, "HACK: using vertex lightmap approximation\n" ); ri.Printf( PRINT_ALL, "HACK: using vertex lightmap approximation\n" );
} }
if ( gl_enabled() && glConfig.smpActive ) { if ( glActive && glConfig.smpActive ) {
ri.Printf( PRINT_ALL, "Using dual processor acceleration\n" ); ri.Printf( PRINT_ALL, "Using dual processor acceleration\n" );
} }
// VULKAN // VULKAN
if (vk_enabled()) { if (vk.active) {
VkPhysicalDeviceProperties props; VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(vk.physical_device, &props); vkGetPhysicalDeviceProperties(vk.physical_device, &props);
@ -1090,7 +1094,7 @@ void RE_Shutdown( qboolean destroyWindow ) {
R_DoneFreeType(); R_DoneFreeType();
// shut down platform specific OpenGL stuff // shut down platform specific OpenGL stuff
if ( gl_enabled() ) { if ( glActive ) {
if (destroyWindow) if (destroyWindow)
GLimp_Shutdown(); GLimp_Shutdown();
} }

View File

@ -924,6 +924,7 @@ typedef struct {
extern backEndState_t backEnd; extern backEndState_t backEnd;
extern trGlobals_t tr; extern trGlobals_t tr;
extern bool glActive; // set to true if OpenGL is used for rendering
extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared during ref re-init extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared during ref re-init
extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init
@ -1390,9 +1391,6 @@ void RB_CalcDiffuseColor( unsigned char *colors );
void myGlMultMatrix( const float *a, const float *b, float *out ); void myGlMultMatrix( const float *a, const float *b, float *out );
inline bool gl_enabled() { return r_renderAPI->integer == 0 || r_twinMode->integer; }
inline bool vk_enabled() { return r_renderAPI->integer != 0 || r_twinMode->integer; }
/* /*
============================================================= =============================================================