Skip to content

Commit

Permalink
Win32: report actual color bits and correct PFD count
Browse files Browse the repository at this point in the history
X11: request alpha bits for >=24 bit color profiles
Renderers: use glConfig.stencilBits instead of dereferencing \r_stencilbits cvar
Vulkan: increase MAX_IMAGE_CHUNKS from 48 to 56
  • Loading branch information
ec- committed Apr 14, 2024
1 parent f9ca298 commit 526944c
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 86 deletions.
2 changes: 1 addition & 1 deletion code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3822,7 +3822,7 @@ static void CL_InitGLimp_Cvars( void )
// shared with renderer:
cl_stencilbits = Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE_ND | CVAR_LATCH );
Cvar_CheckRange( cl_stencilbits, "0", "8", CV_INTEGER );
Cvar_SetDescription( cl_stencilbits, "Stencil buffer size, value decreases Z-buffer depth." );
Cvar_SetDescription( cl_stencilbits, "Stencil buffer size, required to be 8 for stencil shadows." );
cl_depthbits = Cvar_Get( "r_depthbits", "0", CVAR_ARCHIVE_ND | CVAR_LATCH );
Cvar_CheckRange( cl_depthbits, "0", "32", CV_INTEGER );
Cvar_SetDescription( cl_depthbits, "Sets precision of Z-buffer." );
Expand Down
6 changes: 4 additions & 2 deletions code/qcommon/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ void Cbuf_Execute( void )
{
char line[MAX_CMD_LINE], *text;
int i, n, quotes;
qboolean in_star_comment;
qboolean in_slash_comment;

if ( cmd_wait > 0 ) {
// delay command buffer execution
Expand All @@ -265,8 +267,8 @@ void Cbuf_Execute( void )
// This will keep // style comments all on one line by not breaking on
// a semicolon. It will keep /* ... */ style comments all on one line by not
// breaking it for semicolon or newline.
qboolean in_star_comment = qfalse;
qboolean in_slash_comment = qfalse;
in_star_comment = qfalse;
in_slash_comment = qfalse;

while ( cmd_text.cursize > 0 )
{
Expand Down
14 changes: 7 additions & 7 deletions code/renderer/tr_arb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ void FBO_Clean( frameBuffer_t *fb )
fb->depthStencil = 0;
}
#else
if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0 );
else
qglFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0 );
Expand Down Expand Up @@ -1165,7 +1165,7 @@ static GLuint FBO_CreateDepthTextureOrBuffer( GLsizei width, GLsizei height )
GLuint buffer;
qglGenRenderbuffers( 1, &buffer );
qglBindRenderbuffer( GL_RENDERBUFFER, buffer );
if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width, height );
else
qglRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height );
Expand All @@ -1176,7 +1176,7 @@ static GLuint FBO_CreateDepthTextureOrBuffer( GLsizei width, GLsizei height )
GL_BindTexture( 0, tex );
qglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
qglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL );
else
qglTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL );
Expand Down Expand Up @@ -1336,12 +1336,12 @@ static qboolean FBO_Create( frameBuffer_t *fb, GLsizei width, GLsizei height, qb
fb->depthStencil = FBO_CreateDepthTextureOrBuffer( width, height );
#endif
#ifdef DEPTH_RENDER_BUFFER
if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->depthStencil );
else
qglFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->depthStencil );
#else
if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fb->depthStencil, 0 );
else
qglFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, fb->depthStencil, 0 );
Expand Down Expand Up @@ -1413,7 +1413,7 @@ static qboolean FBO_CreateMS( frameBuffer_t *fb, int width, int height )

qglGenRenderbuffers( 1, &fb->depthStencil );
qglBindRenderbuffer( GL_RENDERBUFFER, fb->depthStencil );
if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglRenderbufferStorageMultisample( GL_RENDERBUFFER, nSamples, GL_DEPTH_COMPONENT32, width, height );
else
qglRenderbufferStorageMultisample( GL_RENDERBUFFER, nSamples, GL_DEPTH24_STENCIL8, width, height );
Expand All @@ -1424,7 +1424,7 @@ static qboolean FBO_CreateMS( frameBuffer_t *fb, int width, int height )
return qfalse;
}

if ( r_stencilbits->integer == 0 )
if ( glConfig.stencilBits == 0 )
qglFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->depthStencil );
else
qglFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->depthStencil );
Expand Down
2 changes: 1 addition & 1 deletion code/renderer/tr_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern int gl_version;
//
// cvars
//
extern cvar_t *r_stencilbits; // number of desired stencil bits
//extern cvar_t *r_stencilbits; // number of desired stencil bits
extern cvar_t *r_texturebits; // number of desired texture bits
// 0 = use framebuffer depth
// 16 = use 16-bit textures
Expand Down
30 changes: 15 additions & 15 deletions code/renderer/tr_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ return a hash value for the filename
*/
void R_GammaCorrect( byte *buffer, int bufSize ) {
int i;
#ifdef USE_FBO
#ifdef USE_FBO
if ( fboEnabled ) {
return;
}
#endif
#endif
if ( !gls.deviceSupportsGamma ) {
return;
}
Expand Down Expand Up @@ -304,11 +304,11 @@ static void R_LightScaleTexture( byte *in, int inwidth, int inheight, qboolean o

if ( only_gamma )
{
#ifdef USE_FBO
#ifdef USE_FBO
if ( !glConfig.deviceSupportsGamma && !fboEnabled )
#else
if ( !glConfig.deviceSupportsGamma )
#endif
#else
if ( !glConfig.deviceSupportsGamma )
#endif
{
int i, c;
byte *p;
Expand All @@ -333,10 +333,10 @@ static void R_LightScaleTexture( byte *in, int inwidth, int inheight, qboolean o

c = inwidth*inheight;

#ifdef USE_FBO
if ( glConfig.deviceSupportsGamma || fboEnabled )
#else
if ( glConfig.deviceSupportsGamma )
#ifdef USE_FBO
if ( glConfig.deviceSupportsGamma || fboEnabled )
#else
if ( glConfig.deviceSupportsGamma )
#endif
{
for (i=0 ; i<c ; i++, p+=4)
Expand Down Expand Up @@ -1376,11 +1376,11 @@ void R_SetColorMappings( void ) {
tr.overbrightBits = abs( r_overBrightBits->integer );

// never overbright in windowed mode
#ifdef USE_FBO
#ifdef USE_FBO
if ( !glConfig.isFullscreen && r_overBrightBits->integer >= 0 && !fboEnabled ) {
#else
#else
if ( !glConfig.isFullscreen && r_overBrightBits->integer >= 0 ) {
#endif
#endif
tr.overbrightBits = 0;
applyGamma = qfalse;
} else {
Expand Down Expand Up @@ -1442,11 +1442,11 @@ void R_SetColorMappings( void ) {
}

if ( gls.deviceSupportsGamma ) {
#ifdef USE_FBO
#ifdef USE_FBO
if ( fboEnabled )
ri.GLimp_SetGamma( s_gammatable_linear, s_gammatable_linear, s_gammatable_linear );
else
#endif
#endif
{
if ( applyGamma ) {
ri.GLimp_SetGamma( s_gammatable, s_gammatable, s_gammatable );
Expand Down
5 changes: 2 additions & 3 deletions code/renderer/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ cvar_t *r_ext_max_anisotropy;

cvar_t *r_ignoreGLErrors;

cvar_t *r_stencilbits;
//cvar_t *r_stencilbits;
cvar_t *r_texturebits;

#ifdef USE_FBO
Expand Down Expand Up @@ -1759,8 +1759,7 @@ static void R_Register( void )
ri.Cvar_CheckRange( r_ext_max_anisotropy, "1", NULL, CV_INTEGER );
ri.Cvar_SetDescription( r_ext_max_anisotropy, "Sets maximum anisotropic level for your graphics driver. Requires \\r_ext_texture_filter_anisotropic." );

r_stencilbits = ri.Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE_ND | CVAR_LATCH );
ri.Cvar_SetDescription( r_stencilbits, "Stencil buffer size, value decreases Z-buffer depth." );
//r_stencilbits = ri.Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE_ND | CVAR_LATCH );
r_ignorehwgamma = ri.Cvar_Get( "r_ignorehwgamma", "0", CVAR_ARCHIVE_ND | CVAR_LATCH );
ri.Cvar_CheckRange( r_ignorehwgamma, "0", "1", CV_INTEGER );
ri.Cvar_SetDescription( r_ignorehwgamma, "Overrides hardware gamma capabilities." );
Expand Down
5 changes: 2 additions & 3 deletions code/renderer2/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ cvar_t *r_ignoreDstAlpha;
cvar_t *r_ignoreGLErrors;
cvar_t *r_logFile;

cvar_t *r_stencilbits;
//cvar_t *r_stencilbits;
cvar_t *r_texturebits;
cvar_t *r_ext_multisample;

Expand Down Expand Up @@ -1140,8 +1140,7 @@ static void R_Register( void )
ri.Cvar_SetDescription( r_detailTextures, "Enables usage of shader stages flagged as detail." );
r_texturebits = ri.Cvar_Get( "r_texturebits", "0", CVAR_ARCHIVE | CVAR_LATCH );
ri.Cvar_SetDescription( r_texturebits, "Number of texture bits per texture." );
r_stencilbits = ri.Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE | CVAR_LATCH );
ri.Cvar_SetDescription( r_stencilbits, "Stencil buffer size, value decreases Z-buffer depth." );
// r_stencilbits = ri.Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE | CVAR_LATCH );
r_ext_multisample = ri.Cvar_Get( "r_ext_multisample", "0", CVAR_ARCHIVE | CVAR_LATCH );
ri.Cvar_CheckRange( r_ext_multisample, "0", "8", CV_INTEGER );
ri.Cvar_SetDescription( r_ext_multisample, "For anti-aliasing geometry edges." );
Expand Down
2 changes: 1 addition & 1 deletion code/renderervk/tr_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern int maxAnisotropy;
//
// cvars
//
extern cvar_t *r_stencilbits; // number of desired stencil bits
//extern cvar_t *r_stencilbits; // number of desired stencil bits
extern cvar_t *r_texturebits; // number of desired texture bits
// 0 = use framebuffer depth
// 16 = use 16-bit textures
Expand Down
7 changes: 2 additions & 5 deletions code/renderervk/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ cvar_t *r_ext_max_anisotropy;

cvar_t *r_ignoreGLErrors;

cvar_t *r_stencilbits;
//cvar_t *r_stencilbits;
cvar_t *r_texturebits;
cvar_t *r_ext_multisample;
cvar_t *r_ext_alpha_to_coverage;
Expand Down Expand Up @@ -1762,10 +1762,7 @@ static void R_Register( void )
ri.Cvar_CheckRange( r_ext_max_anisotropy, "1", NULL, CV_INTEGER );
ri.Cvar_SetDescription( r_ext_max_anisotropy, "Sets maximum anisotropic level for your graphics driver. Requires \\r_ext_texture_filter_anisotropic." );

r_stencilbits = ri.Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE_ND | CVAR_LATCH );
ri.Cvar_CheckRange( r_stencilbits, "0", "8", CV_INTEGER );
ri.Cvar_SetDescription( r_stencilbits, "Stencil buffer size, value decreases Z-buffer depth." );

//r_stencilbits = ri.Cvar_Get( "r_stencilbits", "8", CVAR_ARCHIVE_ND | CVAR_LATCH );
r_ignorehwgamma = ri.Cvar_Get( "r_ignorehwgamma", "0", CVAR_ARCHIVE_ND | CVAR_LATCH );
ri.Cvar_CheckRange( r_ignorehwgamma, "0", "1", CV_INTEGER );
ri.Cvar_SetDescription( r_ignorehwgamma, "Overrides hardware gamma capabilities." );
Expand Down
13 changes: 6 additions & 7 deletions code/renderervk/vk.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ static void vk_create_render_passes( void )
attachments[1].format = depth_format;
attachments[1].samples = vkSamples;
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Need empty depth buffer before use
attachments[1].stencilLoadOp = r_stencilbits->integer ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachments[1].stencilLoadOp = glConfig.stencilBits ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
if ( r_bloom->integer ) {
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; // keep it for post-bloom pass
attachments[1].stencilStoreOp = r_stencilbits->integer ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachments[1].stencilStoreOp = glConfig.stencilBits ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
} else {
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
Expand Down Expand Up @@ -1247,15 +1247,14 @@ static VkFormat get_depth_format( VkPhysicalDevice physical_device ) {
VkFormat formats[2];
int i;

if (r_stencilbits->integer > 0) {
if ( glConfig.stencilBits > 0 ) {
formats[0] = glConfig.depthBits == 16 ? VK_FORMAT_D16_UNORM_S8_UINT : VK_FORMAT_D24_UNORM_S8_UINT;
formats[1] = VK_FORMAT_D32_SFLOAT_S8_UINT;
glConfig.stencilBits = 8;
} else {
formats[0] = glConfig.depthBits == 16 ? VK_FORMAT_D16_UNORM : VK_FORMAT_X8_D24_UNORM_PACK32;
formats[1] = VK_FORMAT_D32_SFLOAT;
glConfig.stencilBits = 0;
}

for ( i = 0; i < ARRAY_LEN( formats ); i++ ) {
qvkGetPhysicalDeviceFormatProperties( physical_device, formats[i], &props );
if ( ( props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT ) != 0 ) {
Expand Down Expand Up @@ -3228,7 +3227,7 @@ static void create_depth_attachment( uint32_t width, uint32_t height, VkSampleCo
create_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;

image_aspect_flags = VK_IMAGE_ASPECT_DEPTH_BIT;
if ( r_stencilbits->integer )
if ( glConfig.stencilBits > 0 )
image_aspect_flags |= VK_IMAGE_ASPECT_STENCIL_BIT;

VK_CHECK( qvkCreateImage( vk.device, &create_desc, NULL, image ) );
Expand Down Expand Up @@ -6383,7 +6382,7 @@ void vk_clear_depth( qboolean clear_stencil ) {
attachment.clearValue.depthStencil.depth = 1.0f;
#endif
attachment.clearValue.depthStencil.stencil = 0;
if ( clear_stencil && r_stencilbits->integer ) {
if ( clear_stencil && glConfig.stencilBits > 0 ) {
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
} else {
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Expand Down
2 changes: 1 addition & 1 deletion code/renderervk/vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define VERTEX_BUFFER_SIZE (4 * 1024 * 1024)
#define IMAGE_CHUNK_SIZE (32 * 1024 * 1024)
#define MAX_IMAGE_CHUNKS 48
#define MAX_IMAGE_CHUNKS 56

#define NUM_COMMAND_BUFFERS 2 // number of command buffers / render semaphores / framebuffer sets

Expand Down
8 changes: 1 addition & 7 deletions code/sdl/sdl_glimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,11 @@ static int GLW_SetMode( int mode, const char *modeFS, qboolean fullscreen, qbool
{ // reduce depthBits
if (testDepthBits == 24)
testDepthBits = 16;
else if (testDepthBits == 16)
testDepthBits = 8;
}

if ((i % 4) == 1)
{ // reduce stencilBits
if (testStencilBits == 24)
testStencilBits = 16;
else if (testStencilBits == 16)
testStencilBits = 8;
else
if (testStencilBits == 8)
testStencilBits = 0;
}

Expand Down
Loading

0 comments on commit 526944c

Please sign in to comment.