⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxmut.cs

📁 运用directX完成的坦克游戏雏形
💻 CS
📖 第 1 页 / 共 5 页
字号:
        /// best device settings combo found.
        /// </summary>
        private DeviceSettings BuildValidDeviceSettings(EnumDeviceSettingsCombo deviceCombo, DeviceSettings settings, MatchOptions match)
        {
            DeviceSettings validSettings = new DeviceSettings();
            DisplayMode adapterDesktopDisplayMode = Manager.Adapters[(int)deviceCombo.AdapterOrdinal].CurrentDisplayMode;

            // For each setting pick the best, taking into account the match options and 
            // what's supported by the device

            //---------------------
            // Adapter Ordinal
            //---------------------
            // Just using deviceCombo.AdapterOrdinal

            //---------------------
            // Device Type
            //---------------------
            // Just using deviceCombo.DeviceType

            //---------------------
            // Windowed 
            //---------------------
            // Just using deviceCombo.Windowed

            //---------------------
            // Adapter Format
            //---------------------
            // Just using deviceCombo.AdapterFormat

            //---------------------
            // Vertex processing
            //---------------------
            CreateFlags bestBehaviorFlags = 0;
            if (match.VertexProcessing == MatchType.PreserveInput )   
            {
                bestBehaviorFlags = settings.BehaviorFlags;
            }
            else if (match.VertexProcessing == MatchType.IgnoreInput )    
            {
                // The framework defaults to HWVP if available otherwise use SWVP
                if (deviceCombo.deviceInformation.Caps.DeviceCaps.SupportsHardwareTransformAndLight)
                    bestBehaviorFlags |= CreateFlags.HardwareVertexProcessing;
                else
                    bestBehaviorFlags |= CreateFlags.SoftwareVertexProcessing;
            }
            else 
            {
                // Default to input, and fallback to SWVP if HWVP not available 
                bestBehaviorFlags = settings.BehaviorFlags;
                if ((!deviceCombo.deviceInformation.Caps.DeviceCaps.SupportsHardwareTransformAndLight) && 
                    ( (bestBehaviorFlags & CreateFlags.HardwareVertexProcessing ) != 0 || 
                    (bestBehaviorFlags & CreateFlags.MixedVertexProcessing) != 0) )
                {
                    bestBehaviorFlags &= ~CreateFlags.HardwareVertexProcessing ;
                    bestBehaviorFlags &= ~CreateFlags.MixedVertexProcessing;
                    bestBehaviorFlags |= CreateFlags.SoftwareVertexProcessing;
                }

                // One of these must be selected
                if ((bestBehaviorFlags & CreateFlags.HardwareVertexProcessing ) == 0 &&
                    (bestBehaviorFlags & CreateFlags.MixedVertexProcessing) == 0 &&
                    (bestBehaviorFlags & CreateFlags.SoftwareVertexProcessing) == 0 )
                {
                    if (deviceCombo.deviceInformation.Caps.DeviceCaps.SupportsHardwareTransformAndLight)
                        bestBehaviorFlags |= CreateFlags.HardwareVertexProcessing ;
                    else
                        bestBehaviorFlags |= CreateFlags.SoftwareVertexProcessing;
                }
            }

            //---------------------
            // Resolution
            //---------------------
            DisplayMode bestDisplayMode = new DisplayMode();  
            if (match.Resolution == MatchType.PreserveInput )   
            {
                bestDisplayMode.Width = settings.presentParams.BackBufferWidth;
                bestDisplayMode.Height = settings.presentParams.BackBufferHeight;
            }
            else 
            {
                DisplayMode displayModeIn = new DisplayMode();  
                if (match.Resolution == MatchType.ClosestToInput &&
                    (settings.presentParams.BackBufferWidth != 0 && settings.presentParams.BackBufferWidth != 0) )   
                {
                    displayModeIn.Width = settings.presentParams.BackBufferWidth;
                    displayModeIn.Height = settings.presentParams.BackBufferHeight;
                }
                else // if (match.Resolution == MatchType.IgnoreInput )   
                {
                    if (deviceCombo.IsWindowed )
                    {
                        // The framework defaults to 640x480 for windowed
                        displayModeIn.Width = DefaultSizeWidth;
                        displayModeIn.Height = DefaultSizeHeight;
                    }
                    else
                    {
                        // The framework defaults to desktop resolution for fullscreen to try to avoid slow mode change
                        displayModeIn.Width = adapterDesktopDisplayMode.Width;
                        displayModeIn.Height = adapterDesktopDisplayMode.Height;
                    }
                }

                // Call a helper function to find the closest valid display mode to the optimal 
                bestDisplayMode = FindValidResolution(deviceCombo, displayModeIn);
            }

            //---------------------
            // Back Buffer Format
            //---------------------
            // Just using deviceCombo.BackBufferFormat

            //---------------------
            // Back buffer count
            //---------------------
            uint bestBackBufferCount;
            if (match.BackBufferCount == MatchType.PreserveInput )   
            {
                bestBackBufferCount = (uint)settings.presentParams.BackBufferCount;
            }
            else if (match.BackBufferCount == MatchType.IgnoreInput )   
            {
                // The framework defaults to triple buffering 
                bestBackBufferCount = 2;
            }
            else // if (match.BackBufferCount == MatchType.ClosestToInput )   
            {
                bestBackBufferCount = (uint)settings.presentParams.BackBufferCount;
                if (bestBackBufferCount > 3 )
                    bestBackBufferCount = 3;
                if (bestBackBufferCount < 1 )
                    bestBackBufferCount = 1;
            }
    
            //---------------------
            // Multisample
            //---------------------
            MultiSampleType bestMultiSampleType;
            uint bestMultiSampleQuality;
            if (settings.presentParams.SwapEffect != SwapEffect.Discard)
            {
                // Swap effect is not set to discard so multisampling has to off
                bestMultiSampleType = MultiSampleType.None;
                bestMultiSampleQuality = 0;
            }
            else
            {
                if (match.BackBufferCount == MatchType.PreserveInput )   
                {
                    bestMultiSampleType    = settings.presentParams.MultiSample;
                    bestMultiSampleQuality = (uint)settings.presentParams.MultiSampleQuality;
                }
                else if (match.BackBufferCount == MatchType.IgnoreInput )   
                {
                    // Default to no multisampling (always supported)
                    bestMultiSampleType = MultiSampleType.None;
                    bestMultiSampleQuality = 0;
                }
                else if (match.BackBufferCount == MatchType.ClosestToInput )   
                {
                    // Default to no multisampling (always supported)
                    bestMultiSampleType = MultiSampleType.None;
                    bestMultiSampleQuality = 0;

                    for (int i = 0; i < deviceCombo.multiSampleTypeList.Count; i++)
                    {
                        MultiSampleType tempType = (MultiSampleType)deviceCombo.multiSampleTypeList[i];
                        uint tempQuality = (uint)(int)deviceCombo.multiSampleQualityList[i];

                        // Check whether supported type is closer to the input than our current best
                        if (Math.Abs((int)tempType -  (int)settings.presentParams.MultiSample) < Math.Abs((int)bestMultiSampleType - (int)settings.presentParams.MultiSample) )
                        {
                            bestMultiSampleType = tempType;
                            bestMultiSampleQuality = (uint)Math.Min(tempQuality-1, settings.presentParams.MultiSampleQuality);
                        }
                    }
                }
                else // Error case
                {
                    // Default to no multisampling (always supported) 
                    bestMultiSampleType = MultiSampleType.None;
                    bestMultiSampleQuality = 0;
                }
            }

            //---------------------
            // Swap effect
            //---------------------
            SwapEffect bestSwapEffect;
            if (match.SwapEffect == MatchType.PreserveInput )   
            {
                bestSwapEffect = settings.presentParams.SwapEffect;
            }
            else if (match.SwapEffect == MatchType.IgnoreInput )   
            {
                bestSwapEffect = SwapEffect.Discard;
            }
            else // if (match.SwapEffect == MatchType.ClosestToInput )   
            {
                bestSwapEffect = settings.presentParams.SwapEffect;

                // Swap effect has to be one of these 3
                if (bestSwapEffect != SwapEffect.Discard &&
                    bestSwapEffect != SwapEffect.Flip &&
                    bestSwapEffect != SwapEffect.Copy )
                {
                    bestSwapEffect = SwapEffect.Discard;
                }
            }

            //---------------------
            // Depth stencil 
            //---------------------
            DepthFormat bestDepthStencilFormat;
            bool bestEnableAutoDepthStencil;

            int[] depthStencilRanking = new int[deviceCombo.depthStencilFormatList.Count];

            uint backBufferBitDepth = ManagedUtility.GetColorChannelBits( deviceCombo.BackBufferFormat );       
            uint inputDepthBitDepth = ManagedUtility.GetDepthBits( settings.presentParams.AutoDepthStencilFormat );

            for( int i=0; i<deviceCombo.depthStencilFormatList.Count; i++ )
            {
                DepthFormat curDepthStencilFmt = (DepthFormat)deviceCombo.depthStencilFormatList[i];
                uint curDepthBitDepth = ManagedUtility.GetDepthBits( curDepthStencilFmt );
                int ranking;

                if (match.DepthFormat == MatchType.PreserveInput )
                {                       
                    // Need to match bit depth of input
                    if(curDepthBitDepth == inputDepthBitDepth)
                        ranking = 0;
                    else
                        ranking = 10000;
                }
                else if (match.DepthFormat == MatchType.IgnoreInput )
                {
                    // Prefer match of backbuffer bit depth
                    ranking = Math.Abs((int)curDepthBitDepth - (int)(backBufferBitDepth*4));
                }
                else // if (match.DepthFormat == MatchType.ClosestToInput )
                {
                    // Prefer match of input depth format bit depth
                    ranking = Math.Abs((int)curDepthBitDepth - (int)inputDepthBitDepth);
                }

                depthStencilRanking[i] = ranking;
            }

            uint inputStencilBitDepth = ManagedUtility.GetStencilBits( settings.presentParams.AutoDepthStencilFormat );

            for( int i=0; i<deviceCombo.depthStencilFormatList.Count; i++ )
            {
                DepthFormat curDepthStencilFmt = (DepthFormat)deviceCombo.depthStencilFormatList[i];
                int ranking = depthStencilRanking[i];
                uint curStencilBitDepth = ManagedUtility.GetStencilBits( curDepthStencilFmt );

                if (match.StencilFormat == MatchType.PreserveInput )
                {                       
                    // Need to match bit depth of input
                    if(curStencilBitDepth == inputStencilBitDepth)
                        ranking += 0;
                    else
                        ranking += 10000;
                }
                else if (match.StencilFormat == MatchType.IgnoreInput )
                {
                    // Prefer 0 stencil bit depth
                    ranking += (int)curStencilBitDepth;
                }
                else // if (match.StencilFormat == MatchType.ClosestToInput )
                {
                    // Prefer match of input stencil format bit depth
                    ranking += Math.Abs((int)curStencilBitDepth -

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -