r_colorMipLevels disables MSAA when centroid sampling would be used

this is because it would draw (parts of) geometric edges with different colors and that makes visual inspections annoying
also, final MSAA sample counts are always reported by GL3 and GL2 now
This commit is contained in:
myT 2020-01-22 13:49:25 +01:00
parent c72c8d5ad7
commit ca9757082f
5 changed files with 37 additions and 23 deletions

View file

@ -1017,6 +1017,11 @@ static void FindBestAvailableAA(DXGI_SAMPLE_DESC* sampleDesc)
sampleDesc->Count = (UINT)min(r_msaa->integer, D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT);
sampleDesc->Quality = 0;
if(r_colorMipLevels->integer)
{
sampleDesc->Count = 0;
}
while(sampleDesc->Count > 0)
{
UINT levelCount = 0;

View file

@ -423,22 +423,21 @@ static qbool GL2_FBO_CreateSS( FrameBuffer& fb, qbool depthStencil )
}
static qbool GL2_FBO_CreateMS( FrameBuffer& fb )
static qbool GL2_FBO_CreateMS( int* sampleCount, FrameBuffer& fb )
{
while ( glGetError() != GL_NO_ERROR ) {} // clear the error queue
GL(glGenFramebuffers( 1, &fb.fbo ));
GL(glBindFramebuffer( GL_FRAMEBUFFER, fb.fbo ));
int sampleCount = 0;
GL(glGenRenderbuffers( 1, &fb.color ));
GL(glBindRenderbuffer( GL_RENDERBUFFER, fb.color ));
GL_CreateColorRenderBufferStorageMS( &sampleCount );
GL_CreateColorRenderBufferStorageMS( sampleCount );
GL(glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fb.color ));
GL(glGenRenderbuffers( 1, &fb.depthStencil ));
GL(glBindRenderbuffer( GL_RENDERBUFFER, fb.depthStencil ));
GL(glRenderbufferStorageMultisample( GL_RENDERBUFFER, sampleCount, GL_DEPTH24_STENCIL8, glConfig.vidWidth, glConfig.vidHeight ));
GL(glRenderbufferStorageMultisample( GL_RENDERBUFFER, *sampleCount, GL_DEPTH24_STENCIL8, glConfig.vidWidth, glConfig.vidHeight ));
GL(glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb.color ));
GL(glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb.depthStencil ));
@ -454,25 +453,32 @@ static qbool GL2_FBO_CreateMS( FrameBuffer& fb )
fb.multiSampled = qtrue;
fb.hasDepthStencil = qtrue;
ri.Printf( PRINT_ALL, "MSAA: %d samples requested, %d selected\n", r_msaa->integer, sampleCount );
return qtrue;
}
static qbool GL2_FBO_Init()
{
const int msaa = r_msaa->integer;
const qbool enable = msaa >= 2;
const qbool enable = r_msaa->integer >= 2;
frameBufferMultiSampling = enable;
int finalSampleCount = 1;
qbool result = qfalse;
if ( !enable )
return GL2_FBO_CreateSS( frameBuffersPostProcess[0], qtrue ) &&
GL2_FBO_CreateSS( frameBuffersPostProcess[1], qtrue );
return GL2_FBO_CreateMS( frameBufferMain ) &&
if ( enable ) {
result =
GL2_FBO_CreateMS( &finalSampleCount, frameBufferMain ) &&
GL2_FBO_CreateSS( frameBuffersPostProcess[0], qfalse ) &&
GL2_FBO_CreateSS( frameBuffersPostProcess[1], qfalse );
} else {
result =
GL2_FBO_CreateSS( frameBuffersPostProcess[0], qtrue ) &&
GL2_FBO_CreateSS( frameBuffersPostProcess[1], qtrue );
}
if ( result )
ri.Printf( PRINT_ALL, "MSAA: %d samples requested, %d selected\n", r_msaa->integer, finalSampleCount );
return result;
}

View file

@ -940,21 +940,20 @@ static void FBO_CreateSS(FrameBuffer* fb, qbool color, qbool depthStencil, const
fb->hasColor = color;
}
static void FBO_CreateMS(FrameBuffer* fb, const char* name)
static void FBO_CreateMS(int* sampleCount, FrameBuffer* fb, const char* name)
{
glGenFramebuffers(1, &fb->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fb->fbo);
int sampleCount = 0;
glGenRenderbuffers(1, &fb->color);
glBindRenderbuffer(GL_RENDERBUFFER, fb->color);
GL_CreateColorRenderBufferStorageMS(&sampleCount);
GL_CreateColorRenderBufferStorageMS(sampleCount);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fb->color);
SetDebugName(GL_RENDERBUFFER, fb->color, va("%s color attachment 0", name));
glGenRenderbuffers(1, &fb->depthStencil);
glBindRenderbuffer(GL_RENDERBUFFER, fb->depthStencil);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_DEPTH24_STENCIL8, glConfig.vidWidth, glConfig.vidHeight);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, *sampleCount, GL_DEPTH24_STENCIL8, glConfig.vidWidth, glConfig.vidHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->depthStencil);
SetDebugName(GL_RENDERBUFFER, fb->depthStencil, va("%s depth/stencil attachment", name));
@ -970,18 +969,16 @@ static void FBO_CreateMS(FrameBuffer* fb, const char* name)
fb->multiSampled = qtrue;
fb->hasDepthStencil = qtrue;
fb->hasColor = qtrue;
ri.Printf(PRINT_ALL, "MSAA: %d samples requested, %d selected\n", r_msaa->integer, sampleCount);
}
static void FBO_Init()
{
const int msaa = r_msaa->integer;
gl.fbMSEnabled = msaa >= 2;
gl.fbMSEnabled = r_msaa->integer >= 2 && r_colorMipLevels->integer == 0;
int finalSampleCount = 1;
if(gl.fbMSEnabled)
{
FBO_CreateMS(&gl.fbMS, "main");
FBO_CreateMS(&finalSampleCount, &gl.fbMS, "main");
FBO_CreateSS(&gl.fbSSDepth, qfalse, qtrue, "depth resolve");
FBO_CreateSS(&gl.fbSS[0], qtrue, qfalse, "post-process #1");
FBO_CreateSS(&gl.fbSS[1], qtrue, qfalse, "post-process #2");
@ -991,6 +988,8 @@ static void FBO_Init()
FBO_CreateSS(&gl.fbSS[0], qtrue, qtrue, "post-process #1");
FBO_CreateSS(&gl.fbSS[1], qtrue, qtrue, "post-process #2");
}
ri.Printf(PRINT_ALL, "MSAA: %d samples requested, %d selected\n", r_msaa->integer, finalSampleCount);
}
static void FBO_Bind(const FrameBuffer* fb)

View file

@ -162,3 +162,7 @@ S_COLOR_VAL " T2 " S_COLOR_HELP "= Tent 2 (1/3 2/3, same as the CPU version)
S_COLOR_VAL " 0 " S_COLOR_HELP "= R8G8B8A8\n" \
S_COLOR_VAL " 1 " S_COLOR_HELP "= R10G10B10A2\n" \
S_COLOR_VAL " 2 " S_COLOR_HELP "= R16G16B16A16"
#define help_r_colorMipLevels \
"colorizes textures based on their mip level\n" \
"This disables MSAA on back-ends that use centroid sampling."

View file

@ -372,7 +372,7 @@ static const cvarTableItem_t r_cvars[] =
{ &r_msaa, "r_msaa", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_INTEGER, "0", "32", "anti-aliasing sample count, " S_COLOR_VAL "0" S_COLOR_HELP "=off" },
{ &r_picmip, "r_picmip", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_INTEGER, "0", "16", help_r_picmip },
{ &r_roundImagesDown, "r_roundImagesDown", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_roundImagesDown },
{ &r_colorMipLevels, "r_colorMipLevels", "0", CVAR_LATCH, CVART_BOOL, NULL, NULL, "colorizes textures based on their mip level" },
{ &r_colorMipLevels, "r_colorMipLevels", "0", CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_colorMipLevels },
{ &r_detailTextures, "r_detailtextures", "1", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, "enables detail textures shader stages" },
{ &r_mode, "r_mode", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_INTEGER, "0", XSTRING(VIDEOMODE_MAX), help_r_mode },
{ &r_blitMode, "r_blitMode", "0", CVAR_ARCHIVE, CVART_INTEGER, "0", XSTRING(BLITMODE_MAX), help_r_blitMode },