コード例 #1
0
ファイル: LTreeVisu.cs プロジェクト: ErtyHackward/utopia
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            _shader = new HLSLLTree(context.Device, @"Shadder\LTreeVisu.hlsl", VertexHLSLLTree.VertexDeclaration);

            _vb = new VertexBuffer <VertexHLSLLTree>(context.Device, 16, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "VB", AutoResizePerc: 10);
            _ib = new IndexBuffer <ushort>(context.Device, 32, "IB");
        }
コード例 #2
0
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            _staticBlockVB.SetData(context, _meshBluePrint.Vertices);
            _staticBlockIB.SetData(context, _meshBluePrint.Indices);

            base.LoadContent(context);
        }
コード例 #3
0
        public bool Render(SharpDX.Direct3D11.DeviceContext deviceContext, DShaderManager shaderManager, Matrix worldMatrix, Matrix viewMatrix, Matrix orthoMatrix)
        {
            // Put the mini-map bitmap vertex and index buffers on the graphics pipeline to prepare them for drawing.
            if (!MiniMapBitmap.Render(deviceContext, m_mapLocationX, m_mapLocationY))
            {
                return(false);
            }
            // Render the mini-map bitmap using the texture shader.
            if (!shaderManager.RenderTextureShader(deviceContext, MiniMapBitmap.IndexCount, worldMatrix, viewMatrix, orthoMatrix, MiniMapBitmap.Texture.TextureResource))
            {
                return(false);
            }

            // Put the point bitmap vertex and index buffers on the graphics pipeline to prepare them for drawing.
            if (!PointBitmap.Render(deviceContext, m_pointLocationX, m_pointLocationY))
            {
                return(false);
            }
            // Render the point bitmap using the texture shader.
            if (!shaderManager.RenderTextureShader(deviceContext, PointBitmap.IndexCount, worldMatrix, viewMatrix, orthoMatrix, PointBitmap.Texture.TextureResource))
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            SetGuiButtonSound(@"Sounds\Interface\button_press.adpcm.wav");
            base.LoadContent(context);

            //Add specific Channel Mapping matrix, it will overide default mapping
            float[] mapping;
            //mono sound track ==> 5.1 speaker Mapping (instead of playing the mono track to left and right speaker only)
            //              Input
            // Output       Mono
            // Front Left   1.0f
            // Front Right  1.0f
            // Front Center 0.5f
            // LowFreq      0.0f
            // Side Left    0.3f
            // Side Right   0.3f
            mapping = new float[6] {
                1.0f, 1.0f, 0.5f, 0.0f, 0.3f, 0.3f
            };
            base.SoundEngine.AddCustomChannelMapping(1, 6, mapping);

            //stereo sound track ==> 5.1 speaker Mapping (instead of playing the stereo track to left and right speaker only)
            //              Input
            // Output       Left        Right
            // Front Left   1.0f        0.0f
            // Front Right  0.0f        1.0f
            // Front Center 0.3f        0.3f
            // LowFreq      0.0f        0.0f
            // Side Left    0.8f        0.0f
            // Side Right   0.0f        0.8f
            mapping = new float[12] {
                1.0f, 0.0f, 0.0f, 1.0f, 0.3f, 0.3f, 0.0f, 0.0f, 0.8f, 0.0f, 0.0f, 0.8f
            };
            base.SoundEngine.AddCustomChannelMapping(2, 6, mapping);
        }
コード例 #5
0
        public GpuDevice(GpuAdapter adapter)
        {
            //set member to null
            mVertexShader = null;
            mPixelShader  = null;
            mInputLayout  = null;

            //set the adapter
            Adapter = adapter;

#if DEBUG
            //creation flag, we use debug flag
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#else
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.None;
#endif
            //fetuares level: 11_0, 12_0
            var fetuares = new SharpDX.Direct3D.FeatureLevel[2]
            {
                SharpDX.Direct3D.FeatureLevel.Level_11_0,
                SharpDX.Direct3D.FeatureLevel.Level_12_0
            };

            //create device with current adapter
            mDevice           = new SharpDX.Direct3D11.Device(Adapter.Adapter, creationFlags, fetuares);
            mImmediateContext = Device.ImmediateContext;

            LogEmitter.Apply(LogLevel.Information, "[Initialize Graphics Device with {0}]", adapter.Description);
            LogEmitter.Apply(LogLevel.Information, "[Graphics Device Feature Level = {0}]", Device.FeatureLevel);
        }
コード例 #6
0
        public bool Initialize(SharpDX.Direct3D11.Device device, SharpDX.Direct3D11.DeviceContext deviceContext, DSystemConfiguration condifuration, float terrainWidth, float terrainHeight)
        {
            // Set the size of the mini-map minus the borders.
            m_mapSizeX = 150.0f;
            m_mapSizeY = 150.0f;

            // Initialize the location of the mini-map on the top right corner od the screen.
            m_mapLocationX = condifuration.Width - (int)m_mapSizeX - 10;
            m_mapLocationY = 10;

            // Store the terrain size.
            m_terrainWidth  = terrainWidth;
            m_terrainHeight = terrainHeight;

            // Create the mini-map bitmap object.
            MiniMapBitmap = new DBitmap();
            // Initialize the mini-map bitmap object.
            if (!MiniMapBitmap.Initialize(device, condifuration, 154, 154, "minimap.bmp"))
            {
                return(false);
            }

            // Create the point bitmap object.
            PointBitmap = new DBitmap();
            // Initialize the point bitmap object.
            if (!PointBitmap.Initialize(device, condifuration, 3, 3, "point.bmp"))
            {
                return(false);
            }

            return(true);
        }
コード例 #7
0
        // 生成と終了


        public Effekseer(SharpDX.Direct3D11.Device1 d3dDevice1, SharpDX.Direct3D11.DeviceContext d3ddc, float width, float height)
        {
            Renderer = EffekseerRendererDX11NET.Renderer.Create(d3dDevice1.NativePointer, d3ddc.NativePointer, squareMaxCount: 8000);
            Manager  = EffekseerNET.Manager.Create(instance_max: 8000);

            Manager.SetSpriteRenderer(Renderer.CreateSpriteRenderer());
            Manager.SetRibbonRenderer(Renderer.CreateRibbonRenderer());
            Manager.SetRingRenderer(Renderer.CreateRingRenderer());
            Manager.SetTrackRenderer(Renderer.CreateTrackRenderer());
            Manager.SetModelRenderer(Renderer.CreateModelRenderer());

            Manager.SetTextureLoader(Renderer.CreateTextureLoader());
            Manager.SetModelLoader(Renderer.CreateModelLoader());
            Manager.SetMaterialLoader(Renderer.CreateMaterialLoader());

            Renderer.SetProjectionMatrix(
                new EffekseerNET.Matrix44().PerspectiveFovRH(
                    10.0f / 180.0f * MathF.PI,  // 視野角10°;2Dにあわせるため、なるべく小さくして歪みを少なくする。
                    width / height,
                    1.0f, 500.0f));

            Renderer.SetCameraMatrix(
                new EffekseerNET.Matrix44().LookAtRH(
                    eye: new EffekseerNET.Vector3D(0.0f, 0f, 50.0f),
                    at: new EffekseerNET.Vector3D(0.0f, 0.0f, 0.0f),
                    up: new EffekseerNET.Vector3D(0.0f, 1.0f, 0.0f)));

            this._前回の更新時刻 = QPCTimer.生カウント;
        }
コード例 #8
0
        /// <summary>
        ///     Initializes the specified device.
        /// </summary>
        /// <param name="graphicsProfiles">The graphics profiles.</param>
        /// <param name="deviceCreationFlags">The device creation flags.</param>
        /// <param name="windowHandle">The window handle.</param>
        private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle)
        {
            if (nativeDevice != null)
            {
                // Destroy previous device
                ReleaseDevice();
            }

            // Profiling is supported through pix markers
            IsProfilingSupported = true;

            // Map GraphicsProfile to D3D11 FeatureLevel
            SharpDX.Direct3D.FeatureLevel[] levels = graphicsProfiles.ToFeatureLevel();
            creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags;

            // Create Device D3D11 with feature Level based on profile
            nativeDevice        = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, levels);
            nativeDeviceContext = nativeDevice.ImmediateContext;
            if (IsDebugMode)
            {
                GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext");
            }

            InitializeStages();

            // Create the input layout manager
            if (InputLayoutManager == null)
            {
                InputLayoutManager = new InputLayoutManager(this).DisposeBy(this);
            }
        }
コード例 #9
0
 public void Render(SharpDX.Direct3D11.DeviceContext context)
 {
     if (Show)
     {
         DoRender(context);
     }
 }
コード例 #10
0
ファイル: Game.cs プロジェクト: Winbringer/SharpDXTest
        private void InitializeDeviceResources()
        {
            SharpDX.DXGI.ModeDescription      backBufferDesc = new SharpDX.DXGI.ModeDescription(Width, Height, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm);
            SharpDX.DXGI.SwapChainDescription swapChainDesc  = new SharpDX.DXGI.SwapChainDescription()
            {
                ModeDescription   = backBufferDesc,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = SharpDX.DXGI.Usage.RenderTargetOutput,
                BufferCount       = 1,
                OutputHandle      = renderForm.Handle,
                IsWindowed        = true
            };
            SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, swapChainDesc, out d3dDevice, out swapChain);
            var factory = swapChain.GetParent <SharpDX.DXGI.Factory>();

            factory.MakeWindowAssociation(renderForm.Handle, SharpDX.DXGI.WindowAssociationFlags.IgnoreAll);
            d3dDeviceContext = d3dDevice.ImmediateContext;
            using (SharpDX.Direct3D11.Texture2D backBuffer = swapChain.GetBackBuffer <SharpDX.Direct3D11.Texture2D>(0))
            {
                renderTargetView = new SharpDX.Direct3D11.RenderTargetView(d3dDevice, backBuffer);
            }

            d3dDeviceContext.OutputMerger.SetRenderTargets(renderTargetView);
            // Set viewport
            viewport = new SharpDX.Viewport(0, 0, Width, Height);
            d3dDeviceContext.Rasterizer.SetViewport(viewport);
        }
コード例 #11
0
ファイル: CommandList.Direct3D.cs プロジェクト: cg123/xenko
        public CommandList(GraphicsDevice device) : base(device)
        {
            nativeDeviceContext = device.NativeDeviceContext;
            nativeDeviceProfiler = device.IsDebugMode ? SharpDX.ComObject.QueryInterfaceOrNull<SharpDX.Direct3D11.UserDefinedAnnotation>(nativeDeviceContext.NativePointer) : null;
            InitializeStages();

            ClearState();
        }
コード例 #12
0
ファイル: CommandList.Direct3D.cs プロジェクト: rohitshe/Code
        public CommandList(GraphicsDevice device) : base(device)
        {
            nativeDeviceContext  = device.NativeDeviceContext;
            nativeDeviceProfiler = device.IsDebugMode ? SharpDX.ComObject.QueryInterfaceOrNull <SharpDX.Direct3D11.UserDefinedAnnotation>(nativeDeviceContext.NativePointer) : null;
            InitializeStages();

            ClearState();
        }
コード例 #13
0
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            _voxelEffect = ToDispose(new HLSLVoxelModel(context.Device, ClientSettings.EffectPack + @"Entities\VoxelModel.hlsl", VertexVoxel.VertexDeclaration));

            SelectionWindow.VoxelEffect              = _voxelEffect;
            SelectionWindow.SelectionButton.Pressed += SelectionButtonOnPressed;

            base.LoadContent(context);
        }
コード例 #14
0
ファイル: SettingsState.cs プロジェクト: ErtyHackward/utopia
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var gui      = _iocContainer.Get <GuiManager>();
            var settings = _iocContainer.Get <SettingsComponent>();

            AddComponent(settings);
            AddComponent(gui);

            settings.BackPressed += settings_BackPressed;

            base.Initialize(context);
        }
コード例 #15
0
ファイル: Label.cs プロジェクト: xx70235/wwt-windows-client
        // Set up render context state required for drawing ground overlays when shaders
        // are enabled.
        public void SetupGroundOverlays(RenderContext11 renderContext)
        {
            // A shader should be set up already
            if (renderContext.Shader == null)
            {
                renderContext.SetupBasicEffect(BasicEffect.TextureOnly, 1.0f, Color.White);
            }

            // Count the number of overlays so that we can choose the appropriate shader
            int overlayCount = 0;

            foreach (KmlGroundOverlay overlay in GroundOverlays)
            {
                if (overlay.Icon.Texture != null)
                {
                    ++overlayCount;
                }
            }

            overlayCount = Math.Min(PlanetShader11.MaxOverlayTextures, overlayCount);
            if (overlayCount == 0)
            {
                // No work to do
                return;
            }

            // Get a shader identical to the one currently in use, but which supports
            // the required number of overlays.
            PlanetShaderKey key = renderContext.Shader.Key;

            key.overlayTextureCount = overlayCount;
            PlanetShader11 overlayShader = PlanetShader11.GetPlanetShader(renderContext.Device, key);

            renderContext.Shader = overlayShader;
            renderContext.Shader.DiffuseColor = new SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            SharpDX.Direct3D11.DeviceContext devContext = renderContext.Device.ImmediateContext;
            int overlayIndex = 0;

            foreach (KmlGroundOverlay overlay in GroundOverlays)
            {
                Texture11 texture = overlay.Icon.Texture;
                if (texture != null)
                {
                    if (overlayIndex < PlanetShader11.MaxOverlayTextures)
                    {
                        renderContext.Shader.SetOverlayTextureMatrix(overlayIndex, overlay.GetMatrix().Matrix11);
                        renderContext.Shader.SetOverlayTextureColor(overlayIndex, overlay.color);
                        renderContext.Shader.SetOverlayTexture(overlayIndex, texture.ResourceView);
                    }
                    ++overlayIndex;
                }
            }
        }
コード例 #16
0
        private void Render(DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spreadMax == 0)
            {
                return;
            }

            if (this.FInEnabled[0])
            {
                float w = (float)settings.RenderWidth;
                float h = (float)settings.RenderHeight;
                SharpDX.Direct3D11.DeviceContext shaprdxContext = new SharpDX.Direct3D11.DeviceContext(context.CurrentDeviceContext.ComPointer);

                FontWrapper fw = this.FTextRenderer.IsConnected ? this.FTextRenderer[0][context].FontWrapper : FontWrapperFactory.GetWrapper(context, this.dwFactory);

                var sView = settings.View;
                var sProj = settings.Projection;

                SharpDX.Matrix view       = *(SharpDX.Matrix *) & sView;
                SharpDX.Matrix projection = *(SharpDX.Matrix *) & sProj;


                var objectsettings = this.objectSettings[context];
                objectsettings.IterationCount = 1;
                objectsettings.Geometry       = null;

                for (int i = 0; i < this.textCache.objects.Length; i++)
                {
                    SharpDX.Matrix mat = SharpDX.Matrix.Scaling(1.0f, -1.0f, 1.0f);
                    mat = SharpDX.Matrix.Multiply(mat, view);
                    mat = SharpDX.Matrix.Multiply(mat, projection);

                    objectsettings.DrawCallIndex  = i;
                    objectsettings.WorldTransform = *(SlimDX.Matrix *) & mat;

                    if (settings.ValidateObject(objectsettings))
                    {
                        SlimDX.Color4 color = this.textCache.objects[i].Color;
                        color.Alpha *= SharpDX.MathUtil.Clamp(settings.LayerOpacity, 0.0f, 1.0f);
                        SharpDX.Color4 sdxColor = *(SharpDX.Color4 *) & color;

                        fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(this.textCache.objects[i].TextLayout.ComPointer), SharpDX.Vector2.Zero,
                                          mat, sdxColor, TextFlags.None);
                    }
                }

                //Apply old states back
                context.RenderStateStack.Apply();
                context.CleanShaderStages();
            }
        }
コード例 #17
0
ファイル: CreditsState.cs プロジェクト: ErtyHackward/utopia
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var bg      = _iocContainer.Get <BlackBgComponent>();
            var gui     = _iocContainer.Get <GuiManager>();
            var credits = _iocContainer.Get <CreditsComponent>();

            credits.BackPressed += CreditsBackPressed;

            AddComponent(bg);
            AddComponent(gui);
            AddComponent(credits);

            base.Initialize(context);
        }
コード例 #18
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var bg   = _ioc.Get <BlackBgComponent>();
            var gui  = _ioc.Get <GuiManager>();
            var menu = _ioc.Get <MainMenuComponent>();

            _vars = _ioc.Get <RealmRuntimeVariables>();

            AddComponent(bg);
            AddComponent(gui);
            AddComponent(menu);

            base.Initialize(context);
        }
コード例 #19
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var gui          = _iocContainer.Get <GuiManager>();
            var singlePlayer = _iocContainer.Get <SinglePlayerComponent>();

            _vars = _iocContainer.Get <RealmRuntimeVariables>();

            AddComponent(singlePlayer);
            AddComponent(gui);

            singlePlayer.BackPressed           += settings_BackPressed;
            singlePlayer.StartingGameRequested += singlePlayer_StartingGameRequested;

            base.Initialize(context);
        }
コード例 #20
0
        private void InitializeDirectXResources()
        {
            var clientSize     = ClientSize;
            var backBufferDesc = new SharpDX.DXGI.ModeDescription(clientSize.Width, clientSize.Height,
                                                                  new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm);

            var swapChainDesc = new SharpDX.DXGI.SwapChainDescription()
            {
                ModeDescription   = backBufferDesc,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = SharpDX.DXGI.Usage.RenderTargetOutput,
                BufferCount       = 1,
                OutputHandle      = Handle,
                SwapEffect        = SharpDX.DXGI.SwapEffect.Discard,
                IsWindowed        = false
            };

            SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport,
                                                          new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, swapChainDesc,
                                                          out _d3DDevice, out var swapChain);
            _d3DDeviceContext = _d3DDevice.ImmediateContext;

            _swapChain = new SharpDX.DXGI.SwapChain1(swapChain.NativePointer);

            _d2DFactory = new SharpDX.Direct2D1.Factory();

            using (var backBuffer = _swapChain.GetBackBuffer <SharpDX.Direct3D11.Texture2D>(0))
            {
                _renderTargetView = new SharpDX.Direct3D11.RenderTargetView(_d3DDevice, backBuffer);
                _renderTarget     = new SharpDX.Direct2D1.RenderTarget(_d2DFactory, backBuffer.QueryInterface <SharpDX.DXGI.Surface>(),
                                                                       new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)))
                {
                    TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Cleartype
                };
            }

            _solidColorBrush = new SharpDX.Direct2D1.SolidColorBrush(_renderTarget, Color.White);

            _dwFactory  = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared);
            _textFormat = new SharpDX.DirectWrite.TextFormat(_dwFactory, "Arial", SharpDX.DirectWrite.FontWeight.Bold,
                                                             SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, 84 * (float)GraphicsUtils.Scale)
            {
                TextAlignment      = SharpDX.DirectWrite.TextAlignment.Center,
                ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center
            };
            //                var rectangleGeometry = new D2D1.RoundedRectangleGeometry(_d2DFactory,
            //                    new D2D1.RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, Width - 128 * 2, Height - 128 * 2) });
        }
コード例 #21
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var gui       = _iocContainer.Get <GuiManager>();
            var selection = _iocContainer.Get <ServerSelectionComponent>();
            var webApi    = _iocContainer.Get <ClientWebApi>();

            GameComponents.Add(gui);
            GameComponents.Add(selection);

            selection.BackPressed    += SelectionBackPressed;
            selection.ConnectPressed += SelectionConnectPressed;

            webApi.ServerListReceived += WebApiServerListReceived;

            base.Initialize(context);
        }
コード例 #22
0
        //State Initialization =>
        //Add Loading screen animation, and ServerComponent
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            if (PreviousGameState != this)
            {
                GameComponents.Clear();
            }

            var loading = _ioc.Get <LoadingComponent>();

            _vars = _ioc.Get <RealmRuntimeVariables>();

            AddComponent(loading); //Will "Mask" the Components being loaded.
            AddComponent(_ioc.Get <ServerComponent>());
            AddComponent(_ioc.Get <GuiManager>());

            base.Initialize(context);
        }
コード例 #23
0
        public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index)
        {
            if (Display && Transform.HasValue && _toolVoxelModel != null)
            {
                RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadEnabled);

                _voxelModelEffect.Begin(context);
                _voxelModelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D);
                _voxelModelEffect.CBPerFrame.IsDirty = true;

                _toolVoxelInstance.World      = Matrix.Scaling(1f / 16) * Transform.Value;
                _toolVoxelInstance.LightColor = new Color3(0.0f, 0.0f, 1f);
                _toolVoxelInstance.Alpha      = _alpha;

                _toolVoxelModel.Draw(context, _voxelModelEffect, _toolVoxelInstance);
            }
        }
コード例 #24
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var gui  = _ioc.Get <GuiManager>();
            var menu = _ioc.Get <InGameMenuComponent>();
            var fade = _ioc.Get <FadeComponent>();

            fade.Color = new SharpDX.Color4(0, 0, 0, 0.85f);

            AddComponent(fade);
            AddComponent(gui);
            AddComponent(menu);

            menu.ContinuePressed       += MenuContinuePressed;
            menu.ExitPressed           += MenuExitPressed;
            menu.SettingsButtonPressed += MenuSettingsButtonPressed;

            base.Initialize(context);
        }
コード例 #25
0
ファイル: LTreeVisu.cs プロジェクト: ErtyHackward/utopia
        public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index)
        {
            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled);

            if (_bufferDirty)
            {
                _vb.SetData(context, _letreeVertexCollection.ToArray());
                _ib.SetData(context, _letreeIndexCollection.ToArray());

                _bufferDirty = false;
            }

            _shader.Begin(context);
            _shader.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D);
            _shader.CBPerFrame.IsDirty = true;

            _shader.CBPerDraw.Values.World = Matrix.Transpose(Matrix.RotationQuaternion(rotationQ.ValueInterp));
            _shader.CBPerDraw.IsDirty      = true;
            _shader.Apply(context);

            _vb.SetToDevice(context, 0);
            _ib.SetToDevice(context, 0);

            context.DrawIndexed(_ib.IndicesCount, 0, 0);

            //Draw text
            _spriteRenderer.Begin(false, context);

            Vector2   positionText = new Vector2(0, 0);
            ByteColor color        = Color.White;

            string info = "[R] Toggle rotation; [T] New generation";

            info += Environment.NewLine + "Blocks quantity : " + _letreeIndexCollection.Count / 36;
            info += Environment.NewLine + "Tree size : " + (MaxtreeSize.X - MintreeSize.X + 1).ToString("X : 00 ") + (MaxtreeSize.Y - MintreeSize.Y + 1).ToString("Y : 00 ") + (MaxtreeSize.Z - MintreeSize.Z + 1).ToString("Z : 00 ");
            if (_newTemplate != null)
            {
                info += Environment.NewLine + "Axiome : " + _newTemplate.Axiom;
            }

            _spriteRenderer.DrawText(_font, info, ref positionText, ref color, -1, -1, SpriteRenderer.TextFontPosition.RelativeToFontUp);

            _spriteRenderer.End(context);
        }
コード例 #26
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var startUpComponent = _iocContainer.Get <StartUpComponent>();
            var inputsManager    = _iocContainer.Get <InputsManager>();

            _webApi = _iocContainer.Get <ClientWebApi>();

            inputsManager.KeyboardManager.IsRunning = true;

            //Get the list of Slides
            List <FileInfo> slides = new List <FileInfo>();

            foreach (var slide in Directory.GetFiles(@"Images\StartUpSlides\", "StartUpSlide*.*"))
            {
                slides.Add(new FileInfo(slide));
            }

            startUpComponent.SetSlideShows(slides.ToArray(), 3000);

            startUpComponent.SlideShowFinished += StartUpComponentSlideShowFinished;

            //Prepare Async SystemComponentState
            GameState systemComponentState = StatesManager.GetByName("SystemComponents");

            systemComponentState.StateInitialized += SystemComponentStateStateInitialized;

            StatesManager.PrepareStateAsync(systemComponentState);

            _webApi.TokenVerified += WebApiTokenVerified;
            if (!string.IsNullOrEmpty(ClientSettings.Current.Settings.Token))
            {
                _webApi.OauthVerifyTokenAsync(ClientSettings.Current.Settings.Token);
            }
            else
            {
                _nextState = "Login";
            }

            AddComponent(startUpComponent);
            AddComponent(inputsManager);
            base.Initialize(context);
        }
コード例 #27
0
        /// <summary>
        /// <p> Creates a device that uses Direct3D 11 functionality in Direct3D 12, specifying a pre-existing D3D12 device to use for D3D11 interop. </p>
        /// </summary>
        /// <param name = "deviceRef"><dd>  <p> Specifies a pre-existing D3D12 device to use for D3D11 interop. May not be <c>null</c>. </p> </dd></param>
        /// <param name = "flags"><dd>  <p> One or more bitwise OR'ed flags from <strong><see cref = "SharpDX.Direct3D11.DeviceCreationFlags"/></strong>. These are the same flags as those used by <strong>D3D11CreateDeviceAndSwapChain</strong>. Specifies which runtime layers to enable. <em>Flags</em> must be compatible with device flags, and its <em>NodeMask</em> must be a subset of the <em>NodeMask</em> provided to the present API. </p> </dd></param>
        /// <param name = "featureLevelsRef"><dd>  <p> An array of any of the following: </p> <ul> <li>D3D_FEATURE_LEVEL_12_1</li> <li>D3D_FEATURE_LEVEL_12_0</li> <li>D3D_FEATURE_LEVEL_11_1</li> <li>D3D_FEATURE_LEVEL_11_0</li> <li>D3D_FEATURE_LEVEL_10_1</li> <li>D3D_FEATURE_LEVEL_10_0</li> <li>D3D_FEATURE_LEVEL_9_3</li> <li>D3D_FEATURE_LEVEL_9_2</li> <li>D3D_FEATURE_LEVEL_9_1</li> </ul> <p> The first feature level which is less than or equal to the D3D12 device's feature level will be used to perform D3D11 validation. Creation will fail if no acceptable feature levels are provided. Providing <c>null</c> will default to the D3D12 device's feature level. </p> </dd></param>
        /// <param name = "featureLevels"><dd>  <p> The size of the feature levels array, in bytes. </p> </dd></param>
        /// <param name = "commandQueuesOut"><dd>  <p> An array of unique queues for D3D11On12 to use. Valid queue types: 3D command queue. </p> </dd></param>
        /// <param name = "numQueues"><dd>  <p> The size of the command queue array, in bytes. </p> </dd></param>
        /// <param name = "nodeMask"><dd>  <p> Which node of the D3D12 device to use. Only 1 bit may be set. </p> </dd></param>
        /// <param name = "deviceOut"><dd>  <p> Pointer to the returned <strong><see cref = "SharpDX.Direct3D11.Device"/></strong>. May be <c>null</c>. </p> </dd></param>
        /// <param name = "immediateContextOut"><dd>  <p> A reference to the returned <strong><see cref = "SharpDX.Direct3D11.DeviceContext"/></strong>. May be <c>null</c>. </p> </dd></param>
        /// <param name = "chosenFeatureLevelRef"><dd>  <p> A reference to the returned feature level. May be <c>null</c>. </p> </dd></param>
        /// <returns><p> This method returns one of the Direct3D 12 Return Codes that are documented for <strong>D3D11CreateDevice</strong>. See Direct3D 12 Return Codes. </p><p> This method returns <strong><see cref = "SdkComponentMissing"/></strong> if you specify <strong>D3D11_CREATE_DEVICE_DEBUG</strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns>
        /// <remarks>
        /// <p> The function signature PFN_D3D11ON12_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p>
        /// </remarks>
        /// <doc-id>dn933209</doc-id>
        /// <unmanaged>HRESULT D3D11On12CreateDevice([In] IUnknown* pDevice,[In] unsigned int Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In, Buffer, Optional] const IUnknown** ppCommandQueues,[In] unsigned int NumQueues,[In] unsigned int NodeMask,[Out] ID3D11Device** ppDevice,[Out, Optional] ID3D11DeviceContext** ppImmediateContext,[Out, Optional] D3D_FEATURE_LEVEL* pChosenFeatureLevel)</unmanaged>
        /// <unmanaged-short>D3D11On12CreateDevice</unmanaged-short>
        public static unsafe void On12CreateDevice(SharpDX.IUnknown deviceRef, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, System.Int32 featureLevels, SharpDX.IUnknown[] commandQueuesOut, System.Int32 numQueues, System.Int32 nodeMask, out SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D11.DeviceContext immediateContextOut, out SharpDX.Direct3D.FeatureLevel chosenFeatureLevelRef)
        {
            System.IntPtr  deviceRef_ = System.IntPtr.Zero;
            System.IntPtr *commandQueuesOut_;
            commandQueuesOut_ = (System.IntPtr *) 0;
            if (commandQueuesOut != null)
            {
                System.IntPtr *_commandQueuesOut = stackalloc System.IntPtr[commandQueuesOut.Length];
                commandQueuesOut_ = _commandQueuesOut;
            }

            System.IntPtr  deviceOut_           = System.IntPtr.Zero;
            System.IntPtr  immediateContextOut_ = System.IntPtr.Zero;
            SharpDX.Result __result__;
            deviceRef_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.IUnknown>(deviceRef);
            if (commandQueuesOut != null)
            {
                for (int i = 0; i < commandQueuesOut.Length; ++i)
                {
                    (commandQueuesOut_)[i] = SharpDX.CppObject.ToCallbackPtr <SharpDX.IUnknown>(commandQueuesOut[i]);
                }
                fixed(void *chosenFeatureLevelRef_ = &chosenFeatureLevelRef)
                fixed(void *featureLevelsRef_ = featureLevelsRef)
                __result__ = D3D11On12CreateDevice_((void *)deviceRef_, unchecked ((System.Int32)flags), featureLevelsRef_, featureLevels, (void *)commandQueuesOut_, numQueues, nodeMask, &deviceOut_, &immediateContextOut_, chosenFeatureLevelRef_);

                if (deviceOut_ != System.IntPtr.Zero)
                {
                    deviceOut = new SharpDX.Direct3D11.Device(deviceOut_);
                }
                else
                {
                    deviceOut = null;
                }
                if (immediateContextOut_ != System.IntPtr.Zero)
                    immediateContextOut = new SharpDX.Direct3D11.DeviceContext(immediateContextOut_); }
                else
                {
                    immediateContextOut = null;
                }
                __result__.CheckError();
        }
コード例 #28
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var guiManager          = _iocContainer.Get <GuiManager>();
            var inputManager        = _iocContainer.Get <InputsManager>();
            var generalSoundManager = _iocContainer.Get <GeneralSoundManager>();
            var watermark           = _iocContainer.Get <VersionWatermark>();

            DebugComponent debugComponent = null;

            if (Program.ShowDebug)
            {
                debugComponent = _iocContainer.Get <DebugComponent>(new ConstructorArgument("withDisplayInfoActivated", true));
            }

            //Init Common GUI Menu resources
            var commonResources = _iocContainer.Get <SandboxCommonResources>();

            commonResources.LoadFontAndMenuImages(_iocContainer.Get <D3DEngine>());

            //Init MSAA list
            InitMSAASystemList();

            //Init RuntimeVariables
            var vars = _iocContainer.Get <RealmRuntimeVariables>();

            vars.ApplicationDataPath = XmlSettingsManager.GetFilePath("", SettingsStorage.ApplicationData);

            //"Late Binding" of IVoxelModelStorage, must be done after vars is initialized
            _iocContainer.Bind <IVoxelModelStorage>().To <ModelSQLiteStorage>().InSingletonScope().WithConstructorArgument("fileName", Path.Combine(vars.ApplicationDataPath, "Common", "models.db"));

            var storage = (ModelSQLiteStorage)_iocContainer.Get <IVoxelModelStorage>();

            storage.ImportFromPath("Models");

            AddComponent(watermark);
            AddComponent(debugComponent);
            AddComponent(guiManager);
            AddComponent(inputManager);
            AddComponent(generalSoundManager);
            base.Initialize(context);
        }
コード例 #29
0
        public override void Initialize(SharpDX.Direct3D11.DeviceContext context)
        {
            var bg           = _ioc.Get <BlackBgComponent>();
            var gui          = _ioc.Get <GuiManager>();
            var modelManager = _ioc.Get <VoxelModelManager>();

            _modelEditor = _ioc.Get <ModelEditorComponent>();
            var iconFactory = _ioc.Get <IconFactory>();

            _modelEditor.BackPressed += EditorBackPressed;

            AddComponent(bg);
            AddComponent(modelManager);
            AddComponent(_modelEditor);
            AddComponent(gui);
            AddComponent(iconFactory);

            var vars = _ioc.Get <RealmRuntimeVariables>();

            _modelEditor.Author = vars.DisplayName;

            base.Initialize(context);
        }
コード例 #30
0
        /// <summary>
        /// <p>Creates a device that represents the display adapter.</p>
        /// </summary>
        /// <param name = "adapterRef"><dd>  <p> A reference to the video adapter to use when creating a device. Pass <strong><c>null</c></strong> to use the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong>. </p> <strong>Note</strong>?? Do not mix the use of DXGI 1.0 (<strong><see cref = "SharpDX.DXGI.Factory"/></strong>) and DXGI 1.1 (<strong><see cref = "SharpDX.DXGI.Factory1"/></strong>) in an application. Use <strong><see cref = "SharpDX.DXGI.Factory"/></strong> or <strong><see cref = "SharpDX.DXGI.Factory1"/></strong>, but not both in an application.  ? </dd></param>
        /// <param name = "driverType"><dd>  <p> The <strong><see cref = "SharpDX.Direct3D.DriverType"/></strong>, which represents the driver type to create. </p> </dd></param>
        /// <param name = "software"><dd>  <p> A handle to a DLL that implements a software rasterizer. If <em>DriverType</em> is <em>D3D_DRIVER_TYPE_SOFTWARE</em>, <em>Software</em> must not be <strong><c>null</c></strong>. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle. </p> </dd></param>
        /// <param name = "flags"><dd>  <p> The runtime layers to enable (see <strong><see cref = "SharpDX.Direct3D11.DeviceCreationFlags"/></strong>); values can be bitwise OR'd together. </p> </dd></param>
        /// <param name = "featureLevelsRef"><dd>  <p> A reference to an array of <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong>s, which determine the order of feature levels to attempt to create. If <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function uses the following array of feature levels: </p>  <pre>{ D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1,};</pre>  <strong>Note</strong>?? If the Direct3D 11.1 runtime is present on the computer and <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function won't create a <strong>D3D_FEATURE_LEVEL_11_1</strong> device. To create a <strong>D3D_FEATURE_LEVEL_11_1</strong> device, you must explicitly provide a <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> array that includes <strong>D3D_FEATURE_LEVEL_11_1</strong>. If you provide a <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> array that contains <strong>D3D_FEATURE_LEVEL_11_1</strong> on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG.  ? </dd></param>
        /// <param name = "featureLevels"><dd>  <p> The number of elements in <em>pFeatureLevels</em>. </p> </dd></param>
        /// <param name = "sDKVersion"><dd>  <p> The SDK version; use <em><see cref = "SdkVersion"/></em>. </p> </dd></param>
        /// <param name = "deviceOut"><dd>  <p> Returns the address of a reference to an <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object that represents the device created. If this parameter is <strong><c>null</c></strong>, no <see cref = "SharpDX.Direct3D11.Device"/> will be returned. </p> </dd></param>
        /// <param name = "featureLevelRef"><dd>  <p> If successful, returns the first <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> from the <em>pFeatureLevels</em> array which succeeded. Supply <strong><c>null</c></strong> as an input if you don't need to determine which feature level is supported. </p> </dd></param>
        /// <param name = "immediateContextOut"><dd>  <p> Returns the address of a reference to an <strong><see cref = "SharpDX.Direct3D11.DeviceContext"/></strong> object that represents the device context. If this parameter is <strong><c>null</c></strong>, no <see cref = "SharpDX.Direct3D11.DeviceContext"/> will be returned. </p> </dd></param>
        /// <returns><p> This method can return one of the Direct3D 11 Return Codes. </p><p> This method returns E_INVALIDARG if you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_HARDWARE value. </p><p> This method returns <strong><see cref = "SdkComponentMissing"/></strong> if you specify <strong>D3D11_CREATE_DEVICE_DEBUG</strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns>
        /// <remarks>
        /// <p> This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista (KB971644). </p><p> To create a Direct3D 11.1 device (<strong><see cref = "SharpDX.Direct3D11.Device1"/></strong>), which is available on Windows?8, Windows Server?2012, and Windows?7 and Windows Server?2008?R2 with the Platform Update for Windows 7 installed, you first create a <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref = "SharpDX.Direct3D11.Device1"/></strong> interface. </p><p> To create a Direct3D 11.2 device (<strong><see cref = "SharpDX.Direct3D11.Device2"/></strong>), which is available on Windows?8.1 and Windows Server?2012?R2, you first create a <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref = "SharpDX.Direct3D11.Device2"/></strong> interface. </p><p> Set <em>ppDevice</em> and <em>ppImmediateContext</em> to <strong><c>null</c></strong> to determine which feature level is supported by looking at <em>pFeatureLevel</em> without creating a device. </p><p> For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time, use <strong>D3D11CreateDeviceAndSwapChain</strong>. </p><p> If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value, you must also set the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_HARDWARE value, <strong>D3D11CreateDevice</strong> returns an <strong><see cref = "SharpDX.Result"/></strong> of E_INVALIDARG. </p><table> <tr><td> <p>Differences between Direct3D 10 and Direct3D 11:</p> <p> In Direct3D 10, the presence of <em>pAdapter</em> dictated which adapter to use and the <em>DriverType</em> could mismatch what the adapter was. </p> <p> In Direct3D 11, if you are trying to create a hardware or a software device, set <em>pAdapter</em> != <strong><c>null</c></strong> which constrains the other inputs to be: </p> <ul> <li><em>DriverType</em> must be D3D_DRIVER_TYPE_UNKNOWN </li> <li><em>Software</em> must be <strong><c>null</c></strong>. </li> </ul> <p> On the other hand, if <em>pAdapter</em> == <strong><c>null</c></strong>, the <em>DriverType</em> cannot be set to D3D_DRIVER_TYPE_UNKNOWN; it can be set to either: </p> <ul> <li> If <em>DriverType</em> == D3D_DRIVER_TYPE_SOFTWARE,  <em>Software</em> cannot be <strong><c>null</c></strong>. </li> <li> If <em>DriverType</em> == D3D_DRIVER_TYPE_HARDWARE, the adapter used will be the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong> </li> </ul> </td></tr> </table><p>?</p><p> The function signature PFN_D3D11_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p><p><strong>Windows?Phone?8: </strong> This API is supported. </p><p><strong>Windows Phone 8.1: </strong> This API is supported. </p>
        /// </remarks>
        /// <doc-id>ff476082</doc-id>
        /// <unmanaged>HRESULT D3D11CreateDevice([In, Optional] IDXGIAdapter* pAdapter,[In] D3D_DRIVER_TYPE DriverType,[In] HINSTANCE Software,[In] unsigned int Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In] unsigned int SDKVersion,[Out, Fast] ID3D11Device** ppDevice,[Out, Optional] D3D_FEATURE_LEVEL* pFeatureLevel,[Out, Optional] ID3D11DeviceContext** ppImmediateContext)</unmanaged>
        /// <unmanaged-short>D3D11CreateDevice</unmanaged-short>
        public static unsafe SharpDX.Result CreateDevice(SharpDX.DXGI.Adapter adapterRef, SharpDX.Direct3D.DriverType driverType, System.IntPtr software, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, System.Int32 featureLevels, System.Int32 sDKVersion, SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D.FeatureLevel featureLevelRef, out SharpDX.Direct3D11.DeviceContext immediateContextOut)
        {
            System.IntPtr  adapterRef_          = System.IntPtr.Zero;
            System.IntPtr  deviceOut_           = System.IntPtr.Zero;
            System.IntPtr  immediateContextOut_ = System.IntPtr.Zero;
            SharpDX.Result __result__;
            adapterRef_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.DXGI.Adapter>(adapterRef);

            fixed(void *featureLevelRef_ = &featureLevelRef)
            fixed(void *featureLevelsRef_ = featureLevelsRef)
            __result__ = D3D11CreateDevice_((void *)adapterRef_, unchecked ((System.Int32)driverType), (void *)software, unchecked ((System.Int32)flags), featureLevelsRef_, featureLevels, sDKVersion, &deviceOut_, featureLevelRef_, &immediateContextOut_);

            (deviceOut).NativePointer = deviceOut_;
            if (immediateContextOut_ != System.IntPtr.Zero)
            {
                immediateContextOut = new SharpDX.Direct3D11.DeviceContext(immediateContextOut_);
            }
            else
            {
                immediateContextOut = null;
            }
            return(__result__);
        }
コード例 #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class using the default GraphicsAdapter
        /// and the Level10 <see cref="GraphicsProfile" />.
        /// </summary>
        /// <param name="device">The device.</param>
        private GraphicsDevice(GraphicsDevice device)
        {
            RootDevice           = device;
            Adapter              = device.Adapter;
            creationFlags        = device.creationFlags;
            Features             = device.Features;
            sharedDataPerDevice  = device.sharedDataPerDevice;
            InputLayoutManager   = device.InputLayoutManager;
            nativeDevice         = device.NativeDevice;
            nativeDeviceContext  = new SharpDX.Direct3D11.DeviceContext(NativeDevice).DisposeBy(this);
            nativeDeviceProfiler = SharpDX.ComObject.QueryInterfaceOrNull <SharpDX.Direct3D11.UserDefinedAnnotation>(nativeDeviceContext.NativePointer);
            isDeferred           = true;
            IsDebugMode          = device.IsDebugMode;
            if (IsDebugMode)
            {
                GraphicsResourceBase.SetDebugName(device, nativeDeviceContext, "DeferredContext");
            }
            NeedWorkAroundForUpdateSubResource = !Features.HasDriverCommandLists;

            primitiveQuad = new PrimitiveQuad(this).DisposeBy(this);

            InitializeStages();
        }
コード例 #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class using the default GraphicsAdapter
        /// and the Level10 <see cref="GraphicsProfile" />.
        /// </summary>
        /// <param name="device">The device.</param>
        private GraphicsDevice(GraphicsDevice device)
        {
            RootDevice = device;
            Adapter = device.Adapter;
            creationFlags = device.creationFlags;
            Features = device.Features;
            sharedDataPerDevice = device.sharedDataPerDevice;
            InputLayoutManager = device.InputLayoutManager;
            nativeDevice = device.NativeDevice;
            nativeDeviceContext = new SharpDX.Direct3D11.DeviceContext(NativeDevice).DisposeBy(this);
            nativeDeviceProfiler = SharpDX.ComObject.QueryInterfaceOrNull<SharpDX.Direct3D11.UserDefinedAnnotation>(nativeDeviceContext.NativePointer);
            isDeferred = true;
            IsDebugMode = device.IsDebugMode;
            if (IsDebugMode)
            {
                GraphicsResourceBase.SetDebugName(device, nativeDeviceContext, "DeferredContext");
            }
            NeedWorkAroundForUpdateSubResource = !Features.HasDriverCommandLists;

            primitiveQuad = new PrimitiveQuad(this).DisposeBy(this);

            InitializeStages();
        }
コード例 #33
0
ファイル: GraphicsContext.cs プロジェクト: Daramkun/Misty
 internal GraphicsContext( IGraphicsDevice graphicsDevice, bool isImmediate )
 {
     GraphicsDevice = graphicsDevice;
     d3dContext = isImmediate ? ( graphicsDevice.Handle as SharpDX.Direct3D11.Device ).ImmediateContext :
         new SharpDX.Direct3D11.DeviceContext ( graphicsDevice.Handle as SharpDX.Direct3D11.Device );
 }
コード例 #34
0
        /// <summary>
        ///     Initializes the specified device.
        /// </summary>
        /// <param name="graphicsProfiles">The graphics profiles.</param>
        /// <param name="deviceCreationFlags">The device creation flags.</param>
        /// <param name="windowHandle">The window handle.</param>
        private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle)
        {
            if (nativeDevice != null)
            {
                // Destroy previous device
                ReleaseDevice();
            }

            rendererName = Adapter.NativeAdapter.Description.Description;

            // Profiling is supported through pix markers
            IsProfilingSupported = true;

            // Map GraphicsProfile to D3D11 FeatureLevel
            creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags;

            // Default fallback
            if (graphicsProfiles.Length == 0)
                graphicsProfiles = new[] { GraphicsProfile.Level_11_0, GraphicsProfile.Level_10_1, GraphicsProfile.Level_10_0, GraphicsProfile.Level_9_3, GraphicsProfile.Level_9_2, GraphicsProfile.Level_9_1 };

            // Create Device D3D11 with feature Level based on profile
            for (int index = 0; index < graphicsProfiles.Length; index++)
            {
                var graphicsProfile = graphicsProfiles[index];
                try
                {
                    // D3D12 supports only feature level 11+
                    var level = graphicsProfile.ToFeatureLevel();

                    // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10.
                    if (Adapter.VendorId == 0x8086)
                    {
                        if (level < SharpDX.Direct3D.FeatureLevel.Level_10_0)
                            level = SharpDX.Direct3D.FeatureLevel.Level_10_0;
                    }

                    nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, level);

                    // INTEL workaround: force ShaderProfile to be 10+ as well
                    if (Adapter.VendorId == 0x8086)
                    {
                        if (graphicsProfile < GraphicsProfile.Level_10_0 && (!ShaderProfile.HasValue || ShaderProfile.Value < GraphicsProfile.Level_10_0))
                            ShaderProfile = GraphicsProfile.Level_10_0;
                    }

                    RequestedProfile = graphicsProfile;
                    break;
                }
                catch (Exception)
                {
                    if (index == graphicsProfiles.Length - 1)
                        throw;
                }
            }

            nativeDeviceContext = nativeDevice.ImmediateContext;
            if (IsDebugMode)
            {
                GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext");
            }
        }
コード例 #35
0
        private void LoadPipeline(RenderForm form)
        {
            int width = form.ClientSize.Width;
            int height = form.ClientSize.Height;

            viewport.Width = width;
            viewport.Height = height;
            viewport.MaxDepth = 1.0f;

            scissorRect.Right = width;
            scissorRect.Bottom = height;

            #if DEBUG
            // Enable the D3D12 debug layer.
            {
                DebugInterface.Get().EnableDebugLayer();
            }
            #endif
            device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_12_0);
            using (var factory = new Factory4())
            {

                // Describe and create the command queue.
                CommandQueueDescription queueDesc = new CommandQueueDescription(CommandListType.Direct);
                commandQueue = device.CreateCommandQueue(queueDesc);

                // Describe and create the swap chain.
                SwapChainDescription swapChainDesc = new SwapChainDescription()
                {
                    BufferCount = FrameCount,
                    ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                    Usage = Usage.RenderTargetOutput,
                    SwapEffect = SwapEffect.FlipDiscard,
                    OutputHandle = form.Handle,
                    //Flags = SwapChainFlags.None,
                    SampleDescription = new SampleDescription(1, 0),
                    IsWindowed = true
                };

                SwapChain tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc);
                swapChain = tempSwapChain.QueryInterface<SwapChain3>();
                tempSwapChain.Dispose();
                frameIndex = swapChain.CurrentBackBufferIndex;
            }

            // Create descriptor heaps.
            // Describe and create a render target view (RTV) descriptor heap.
            DescriptorHeapDescription rtvHeapDesc = new DescriptorHeapDescription()
            {
                DescriptorCount = FrameCount,
                Flags = DescriptorHeapFlags.None,
                Type = DescriptorHeapType.RenderTargetView
            };

            renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc);

            rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);

            //Init Direct3D11 device from Direct3D12 device
            device11 = SharpDX.Direct3D11.Device.CreateFromDirect3D12(device, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, null, null, commandQueue);
            deviceContext11 = device11.ImmediateContext;
            device11on12 = device11.QueryInterface<SharpDX.Direct3D11.ID3D11On12Device>();
            var d2dFactory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.MultiThreaded);

            // Create frame resources.
            CpuDescriptorHandle rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart;
            for (int n = 0; n < FrameCount; n++)
            {
                renderTargets[n] = swapChain.GetBackBuffer<Resource>(n);
                device.CreateRenderTargetView(renderTargets[n], null, rtvHandle);
                rtvHandle += rtvDescriptorSize;

                //init Direct2D surfaces
                SharpDX.Direct3D11.D3D11ResourceFlags format = new SharpDX.Direct3D11.D3D11ResourceFlags()
                {
                    BindFlags = (int)SharpDX.Direct3D11.BindFlags.RenderTarget,
                    CPUAccessFlags = (int)SharpDX.Direct3D11.CpuAccessFlags.None
                };

                device11on12.CreateWrappedResource(
                    renderTargets[n], format,
                    (int)ResourceStates.Present,
                    (int)ResourceStates.RenderTarget,
                    typeof(SharpDX.Direct3D11.Resource).GUID,
                    out wrappedBackBuffers[n]);

                //Init direct2D surface
                var d2dSurface = wrappedBackBuffers[n].QueryInterface<Surface>();
                direct2DRenderTarget[n] = new SharpDX.Direct2D1.RenderTarget(d2dFactory, d2dSurface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)));
                d2dSurface.Dispose();
            }

            commandAllocator = device.CreateCommandAllocator(CommandListType.Direct);

            d2dFactory.Dispose();

            //Init font
            var directWriteFactory = new SharpDX.DirectWrite.Factory();
            textFormat = new SharpDX.DirectWrite.TextFormat(directWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Bold, SharpDX.DirectWrite.FontStyle.Normal, 48) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near };
            textBrush = new SharpDX.Direct2D1.SolidColorBrush(direct2DRenderTarget[0], Color.White);
            directWriteFactory.Dispose();
        }
コード例 #36
0
        /// <summary>
        ///     Initializes the specified device.
        /// </summary>
        /// <param name="graphicsProfiles">The graphics profiles.</param>
        /// <param name="deviceCreationFlags">The device creation flags.</param>
        /// <param name="windowHandle">The window handle.</param>
        private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle)
        {
            if (nativeDevice != null)
            {
                // Destroy previous device
                ReleaseDevice();
            }

            // Profiling is supported through pix markers
            IsProfilingSupported = true;

            // Map GraphicsProfile to D3D11 FeatureLevel
            SharpDX.Direct3D.FeatureLevel[] levels = graphicsProfiles.ToFeatureLevel();
            creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags;

            // Create Device D3D11 with feature Level based on profile
            nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, levels);
            nativeDeviceContext = nativeDevice.ImmediateContext;
            if (IsDebugMode)
            {
                GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext");
            }

            InitializeStages();

            // Create the input layout manager
            if (InputLayoutManager == null)
                InputLayoutManager = new InputLayoutManager(this).DisposeBy(this);
        }