From fbf0d87592ef9e6f6cecf8d69e3bcb52fa9c4123 Mon Sep 17 00:00:00 2001 From: gogg Date: Sat, 28 Nov 2009 17:50:30 +0000 Subject: [PATCH] D3D9 multisampling can now be enabled with 'framebuffer-multisample' and 'multisamples' settings, and it doesn't crash anymore when an unsupported sampling level is requested. --- panda/src/dxgsg9/config_dxgsg9.cxx | 4 ---- panda/src/dxgsg9/config_dxgsg9.h | 1 - panda/src/dxgsg9/wdxGraphicsWindow9.cxx | 27 ++++++++++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/panda/src/dxgsg9/config_dxgsg9.cxx b/panda/src/dxgsg9/config_dxgsg9.cxx index 3dd11f374d..7828cd6b1b 100755 --- a/panda/src/dxgsg9/config_dxgsg9.cxx +++ b/panda/src/dxgsg9/config_dxgsg9.cxx @@ -38,10 +38,6 @@ NotifyCategoryDef(wdxdisplay9, "display"); ConfigVariableBool dx_show_transforms ("dx-show-transforms", false); -// Set Level of MultiSampling to be used, if HW supports it. Valid values are 2-16. -ConfigVariableInt dx_multisample_antialiasing_level -("dx-multisample-antialiasing-level", 0); - // if true, if card only supports per-vertex fog, it will be treated as no-HW fog capability ConfigVariableBool dx_no_vertex_fog ("dx-no-vertex-fog", false); diff --git a/panda/src/dxgsg9/config_dxgsg9.h b/panda/src/dxgsg9/config_dxgsg9.h index 3096f79999..d4bb3b10ac 100755 --- a/panda/src/dxgsg9/config_dxgsg9.h +++ b/panda/src/dxgsg9/config_dxgsg9.h @@ -30,7 +30,6 @@ extern ConfigVariableBool dx_show_cursor_watermark; extern ConfigVariableBool dx_full_screen_antialiasing; extern ConfigVariableBool dx_use_rangebased_fog; extern ConfigVariableBool link_tristrips; -extern ConfigVariableInt dx_multisample_antialiasing_level; extern ConfigVariableBool dx_use_triangle_mipgen_filter; extern ConfigVariableBool dx_broken_max_index; extern ConfigVariableBool dx_broken_depth_bias; diff --git a/panda/src/dxgsg9/wdxGraphicsWindow9.cxx b/panda/src/dxgsg9/wdxGraphicsWindow9.cxx index e99e4ab237..188f32a396 100755 --- a/panda/src/dxgsg9/wdxGraphicsWindow9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsWindow9.cxx @@ -631,28 +631,35 @@ create_screen_buffers_and_device(DXScreenData &display, bool force_16bpp_zbuffer presentation_params->Windowed = !is_fullscreen(); - if (dx_multisample_antialiasing_level>1) { + int supported_multisamples = 0; + if (framebuffer_multisample.get_value()){ + supported_multisamples = multisamples.get_value(); + } + + while (supported_multisamples > 1){ // need to check both rendertarget and zbuffer fmts hr = _d3d9->CheckDeviceMultiSampleType(adapter, D3DDEVTYPE_HAL, display._display_mode.Format, - is_fullscreen(), D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level.get_value()), NULL); + is_fullscreen(), D3DMULTISAMPLE_TYPE(supported_multisamples), NULL); if (FAILED(hr)) { - wdxdisplay9_cat.fatal() << "adapter #" << adapter << " doesnt support multisample level " << dx_multisample_antialiasing_level << "surface fmt " << D3DFormatStr(display._display_mode.Format) << endl; - return false; + supported_multisamples--; + continue; } if (display._presentation_params.EnableAutoDepthStencil) { hr = _d3d9->CheckDeviceMultiSampleType(adapter, D3DDEVTYPE_HAL, display._presentation_params.AutoDepthStencilFormat, - is_fullscreen(), D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level.get_value()), NULL); + is_fullscreen(), D3DMULTISAMPLE_TYPE(supported_multisamples), NULL); if (FAILED(hr)) { - wdxdisplay9_cat.fatal() << "adapter #" << adapter << " doesnt support multisample level " << dx_multisample_antialiasing_level << "surface fmt " << D3DFormatStr(display._presentation_params.AutoDepthStencilFormat) << endl; - return false; + supported_multisamples--; + continue; } } - presentation_params->MultiSampleType = D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level.get_value()); + presentation_params->MultiSampleType = D3DMULTISAMPLE_TYPE(supported_multisamples); if (wdxdisplay9_cat.is_info()) - wdxdisplay9_cat.info() << "adapter #" << adapter << " using multisample antialiasing level " << dx_multisample_antialiasing_level << endl; + wdxdisplay9_cat.info() << "adapter #" << adapter << " using multisample antialiasing level: " << supported_multisamples << + ". Requested level was: " << multisamples.get_value() << endl; + break; } presentation_params->BackBufferCount = 1; @@ -742,7 +749,7 @@ create_screen_buffers_and_device(DXScreenData &display, bool force_16bpp_zbuffer presentation_params->PresentationInterval = 0; - if (dx_multisample_antialiasing_level<2) { + if (supported_multisamples<2) { if (do_sync) { // It turns out that COPY_VSYNC has real performance problems // on many nVidia cards--it syncs at some random interval,