Beispiel #1
0
        /// <summary>
        /// Generates a set of <see cref="SlimDX.Direct3D9.PresentParameters"/> for the engine
        /// </summary>
        /// <param name="config">The <see cref="Config"/> with settings to initialize the engine</param>
        /// <returns>The generated set of <see cref="SlimDX.Direct3D9.PresentParameters"/>.</returns>
        private static PresentParameters BuildPresentParams(EngineConfig config)
        {
            var presentParams = new PresentParameters
            {
                Windowed               = (!config.Fullscreen),
                SwapEffect             = SwapEffect.Discard,
                PresentationInterval   = (config.VSync ? PresentInterval.One : PresentInterval.Immediate),
                Multisample            = (MultisampleType)config.AntiAliasing,
                BackBufferWidth        = config.TargetSize.Width,
                BackBufferHeight       = config.TargetSize.Height,
                BackBufferFormat       = Format.X8R8G8B8, // Format.R5G6B5 for 16bit
                EnableAutoDepthStencil = true
            };

            // Automatically use best-possible ZBuffer
            if (EngineCapabilities.TestDepthStencil(config.Adapter, Format.D32))
            {
                presentParams.AutoDepthStencilFormat = Format.D32;
            }
            else if (EngineCapabilities.TestDepthStencil(config.Adapter, Format.D24X8))
            {
                presentParams.AutoDepthStencilFormat = Format.D24X8;
            }
            else
            {
                presentParams.AutoDepthStencilFormat = Format.D16;
            }

            return(presentParams);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the Engine and its components.
        /// </summary>
        /// <param name="target">The <see cref="System.Windows.Forms.Control"/> the engine should draw onto.</param>
        /// <param name="config">Settings for initializing the engine.</param>
        /// <exception cref="NotSupportedException">The graphics card does not meet the engine's minimum requirements.</exception>
        /// <exception cref="Direct3D9NotFoundException">Throw if required DirectX version is missing.</exception>
        /// <exception cref="Direct3DX9NotFoundException">Throw if required DirectX version is missing.</exception>
        /// <exception cref="Direct3D9Exception">internal errors occurred while intiliazing the graphics card.</exception>
        /// <exception cref="SlimDX.DirectSound.DirectSoundException">internal errors occurred while intiliazing the sound card.</exception>
        public Engine(Control target, EngineConfig config)
        {
            #region Sanity checks
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            #endregion

            Engine = this;
            RegisterChild(_views);

            _direct3D = new Direct3D();
            Target    = target;
            Config    = config;
            ShaderDir = Path.Combine(Locations.InstallBase, "Shaders");

            Capabilities = new EngineCapabilities(_direct3D, config);
            Effects      = new EngineEffects(Capabilities)
            {
                PerPixelLighting = true
            };

            try
            {
                CreateDevice();
                State = new EngineState(Device);
                SetupTextureFiltering();
                Performance = new EnginePerformance(Device, RenderPure);

                if (GeneralShader.MinShaderModel <= Capabilities.MaxShaderModel)
                {
                    RegisterChild(DefaultShader = new GeneralShader());
                }

                // Create simple default meshes ready
                SimpleSphere = Mesh.CreateSphere(Device, 1, 12, 12);
                SimpleBox    = Mesh.CreateBox(Device, 1, 1, 1);

                SetupAudio();
            }
            #region Error handling
            catch (Direct3D9Exception ex) when(ex.ResultCode == ResultCode.NotAvailable)
            {
                Dispose();
                throw new NotSupportedException(Resources.NotAvailable, ex);
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
            #endregion
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new engine effects object.
        /// </summary>
        /// <param name="capabilities">Determines which effects can be turned on.</param>
        internal EngineEffects(EngineCapabilities capabilities)
        {
            #region Sanity checks
            if (capabilities == null)
            {
                throw new ArgumentNullException(nameof(capabilities));
            }
            #endregion

            _capabilities = capabilities;
        }