当前位置: 首页>>代码示例>>C#>>正文


C# Direct3D11.Device类代码示例

本文整理汇总了C#中SharpDX.Direct3D11.Device的典型用法代码示例。如果您正苦于以下问题:C# Device类的具体用法?C# Device怎么用?C# Device使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Device类属于SharpDX.Direct3D11命名空间,在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Terrain

 public Terrain(Device device, String texture, int pitch, Renderer renderer)
 {
     HeightMap = new System.Drawing.Bitmap(@"Data/Textures/"+texture);
     WaterShader = new WaterShader(device);
     TerrainShader = new TerrainShader(device);
     _width = HeightMap.Width-1;
     _height = HeightMap.Height-1;
     _pitch = pitch;
     _terrainTextures = new ShaderResourceView[4];
     _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource;
     _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource;
     _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource;
     _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource;
     _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
     _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f);
     _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000);
     _reflectionTexture = new RenderTexture(device, renderer.ScreenSize);
     _refractionTexture = new RenderTexture(device, renderer.ScreenSize);
     _renderer = renderer;
     _bitmap = new Bitmap(device,_refractionTexture.ShaderResourceView,renderer.ScreenSize, new Vector2I(100, 100), 0);
     _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0);
     _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0);
     _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120);
     _bumpMap = _renderer.TextureManager.Create("OceanWater.png");
     _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png"));
     BuildBuffers(device);
     WaveTranslation = new Vector2(0,0);
 }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:28,代码来源:Terrain.cs

示例2: GraphicsResource

        /// <summary>
        /// Creates a new graphics resource.
        /// </summary>
        /// <param name="device">The graphics device to use.</param>
        /// <param name="dimensions">The resource dimensions.</param>
        /// <param name="format">The resource's DXGI format.</param>
        /// <param name="renderTargetView">Whether to bind as RTV.</param>
        /// <param name="shaderResourceView">Whether to bind as SRV.</param>
        /// <param name="hasMipMaps">Whether to enable mip-maps for this texture.</param>
        public GraphicsResource(Device device, Size dimensions, Format format, Boolean renderTargetView = true, Boolean shaderResourceView = true, Boolean hasMipMaps = false)
        {
            if ((!renderTargetView) && (!shaderResourceView))
                throw new ArgumentException("The requested resource cannot be bound at all to the pipeline.");

            if ((hasMipMaps) && ((!renderTargetView) || (!shaderResourceView)))
                throw new ArgumentException("A resource with mipmaps must be bound as both input and output.");

            BindFlags bindFlags = (renderTargetView ? BindFlags.RenderTarget : 0) | (shaderResourceView ? BindFlags.ShaderResource : 0);
            ResourceOptionFlags optionFlags = (hasMipMaps ? ResourceOptionFlags.GenerateMipMaps : 0);
            int mipLevels = (hasMipMaps ? MipLevels(dimensions) : 1);

            Resource = new Texture2D(device, new Texture2DDescription()
            {
                Format = format,
                BindFlags = bindFlags,
                Width = dimensions.Width,
                Height = dimensions.Height,

                ArraySize = 1,
                MipLevels = mipLevels,
                OptionFlags = optionFlags,
                Usage = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
                SampleDescription = new SampleDescription(1, 0),
            });

            RTV = (  renderTargetView ?   new RenderTargetView(device, Resource) : null);
            SRV = (shaderResourceView ? new ShaderResourceView(device, Resource) : null);
        }
开发者ID:TomCrypto,项目名称:Insight,代码行数:39,代码来源:GraphicsResource.cs

示例3: IsDx11Supported

        public static bool IsDx11Supported()
        {
            var factory = GetFactory();
            FeatureLevel[] featureLevels = {FeatureLevel.Level_11_0};

            for (int i = 0; i < factory.Adapters.Length; i++)
            {
                var adapter = factory.Adapters[i];
                Device adapterTestDevice = null;
                try
                {
                    adapterTestDevice = new Device(adapter, DeviceCreationFlags.None, featureLevels);
                }
                catch (Exception)
                {
                    continue;
                }

                UInt64 vram;
                UInt64 svram;
                GetRamSizes(out vram, adapter, out svram);

                // microsoft software renderer allocates 256MB shared memory, cpu integrated graphic on notebooks has 0 preallocated, all shared
                return (vram > 500000000 || svram > 500000000);
            }
            return false;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:27,代码来源:MyDirectXHelper.cs

示例4: Initialize

        public void Initialize()
        {
            DestroyResources();

            var flags = DeviceCreationFlags.BgraSupport;
            #if DEBUG
            flags |= DeviceCreationFlags.Debug;
            #endif

            var featureLevels = new[]
            {
                FeatureLevel.Level_11_1,
                FeatureLevel.Level_11_0
            };

            using(var device = new Device(DriverType.Hardware, flags, featureLevels))
            {
                Device = device.QueryInterface<Device1>();
                Context = device.ImmediateContext.QueryInterface<DeviceContext1>();
            }

            IsInitialized = true;

            // todo: Reinitialize all dependent resources by having them hook this event
            var handler = Initialized;
            if(handler != null)
                handler();
        }
开发者ID:gitter-badger,项目名称:Grasshopper,代码行数:28,代码来源:DeviceManager.cs

示例5: CompositionEngine

// ReSharper restore InconsistentNaming

        static CompositionEngine()
        {
            _wicFactory = new SharpDX.WIC.ImagingFactory();
            _dWriteFactory = new SharpDX.DirectWrite.Factory();

            var d3DDevice = new SharpDX.Direct3D11.Device(
                DriverType.Hardware,
                DeviceCreationFlags.BgraSupport
#if DEBUG
                | DeviceCreationFlags.Debug
#endif
,
                FeatureLevel.Level_11_1,
                FeatureLevel.Level_11_0,
                FeatureLevel.Level_10_1,
                FeatureLevel.Level_10_0,
                FeatureLevel.Level_9_3,
                FeatureLevel.Level_9_2,
                FeatureLevel.Level_9_1
                );

            var dxgiDevice = ComObject.As<SharpDX.DXGI.Device>(d3DDevice.NativePointer);
                //new SharpDX.DXGI.Device2(d3DDevice.NativePointer);
            var d2DDevice = new SharpDX.Direct2D1.Device(dxgiDevice);
            _d2DFactory = d2DDevice.Factory;
            _d2DDeviceContext = new SharpDX.Direct2D1.DeviceContext(d2DDevice, D2D.DeviceContextOptions.None);
            _d2DDeviceContext.DotsPerInch = new Size2F(LogicalDpi, LogicalDpi);
        }
开发者ID:cstehreem,项目名称:WinRTXamlToolkit,代码行数:30,代码来源:CompositionEngine.cs

示例6: FbxMesh

 public FbxMesh(AssimpSharp.Mesh mesh, AssimpSharp.Material mat, Device device, string path)
 {
     this.device = device;
     this.path = path;
     LoadMesh(mesh);
     LoadMaterial(mat);
 }
开发者ID:oguna,项目名称:AssimpSharp,代码行数:7,代码来源:FbxMesh.cs

示例7: MeshFactory

        public MeshFactory(SharpDX11Graphics graphics)
        {
            this.device = graphics.Device;
            this.inputAssembler = device.ImmediateContext.InputAssembler;
            this.demo = graphics.Demo;

            instanceDataDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
            };

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
                new InputElement("WORLD", 0, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 1, Format.R32G32B32A32_Float, 16, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 2, Format.R32G32B32A32_Float, 32, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 3, Format.R32G32B32A32_Float, 48, 1, InputClassification.PerInstanceData, 1),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 64, 1, InputClassification.PerInstanceData, 1)
            };
            inputLayout = new InputLayout(device, graphics.GetEffectPass().Description.Signature, elements);

            groundColor = ColorToUint(Color.Green);
            activeColor = ColorToUint(Color.Orange);
            passiveColor = ColorToUint(Color.OrangeRed);
            softBodyColor = ColorToUint(Color.LightBlue);
        }
开发者ID:RainsSoft,项目名称:BulletSharpPInvoke,代码行数:31,代码来源:MeshFactory.cs

示例8: Form1

 public Form1(Factory factory, SharpDX.Direct3D11.Device device, Object renderLock)
 {
     InitializeComponent();
     this.factory = factory;
     this.device = device;
     this.renderLock = renderLock;
 }
开发者ID:virrkharia,项目名称:RoomAliveToolkit,代码行数:7,代码来源:Form1.cs

示例9: DepthBuffer

        public DepthBuffer(Device device, int width, int height)
        {
            try
            {
                _device = device;
                _depthBuffer = new Texture2D(_device, new Texture2DDescription
                {
                    Format = Format.D32_Float_S8X24_UInt,
                    ArraySize = 1,
                    MipLevels = 1,
                    Width = width,
                    Height = height,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage = ResourceUsage.Default,
                    BindFlags = BindFlags.DepthStencil,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags = ResourceOptionFlags.None
                });

                _depthView = new DepthStencilView(device, _depthBuffer);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
开发者ID:akimoto-akira,项目名称:Pulse,代码行数:27,代码来源:DepthBuffer.cs

示例10: RenderTarget

 public RenderTarget(Device device, int width, int height, int sampleCount, int sampleQuality, Format format)
     : this()
 {
     Texture = _disposer.Add(new Texture2D(device, new Texture2DDescription
     {
         Format              = format,
         Width               = width,
         Height              = height,
         ArraySize           = 1,
         MipLevels           = 1,
         BindFlags           = BindFlags.RenderTarget | BindFlags.ShaderResource,
         CpuAccessFlags      = CpuAccessFlags.None,
         OptionFlags         = ResourceOptionFlags.None,
         Usage               = ResourceUsage.Default,
         SampleDescription   = new SampleDescription(sampleCount, sampleQuality),
     }));
     RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture, new RenderTargetViewDescription
     {
         Format = format,
         Dimension = RenderTargetViewDimension.Texture2DMultisampled,
         //MipSlice = 0,
     }));
     
     ShaderResourceView = _disposer.Add(new ShaderResourceView(device, Texture));
     Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f);
 }
开发者ID:JoltSoftwareDevelopment,项目名称:Jolt.MashRoom,代码行数:26,代码来源:RenderTarget.cs

示例11: ProjectorFormLoader

        public ProjectorFormLoader(String path)
        {
            Forms = new List<ProjectorForm>();

            // load ensemble.xml
            string directory = Path.GetDirectoryName(path);
            var ensemble = ProjectorCameraEnsemble.FromFile(path);

            // create d3d device
            var factory = new Factory1();
            var adapter = factory.Adapters[0];

            // When using DeviceCreationFlags.Debug on Windows 10, ensure that "Graphics Tools" are installed via Settings/System/Apps & features/Manage optional features.
            // Also, when debugging in VS, "Enable native code debugging" must be selected on the project.
            var device = new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.None);

            Object renderLock = new Object();

            // create a form for each projector
            foreach (var projector in ensemble.projectors) {
                var form = new ProjectorForm(factory, device, renderLock, projector);
                form.FullScreen = FULLSCREEN_ENABLED; // TODO: fix this so can be called after Show
                form.Show();
                Forms.Add(form);
            }
        }
开发者ID:louisch,项目名称:RoomAliveToolkit,代码行数:26,代码来源:ProjectorFormLoader.cs

示例12: Initialize

        public bool Initialize(Device device, string heightMapFileName, string textureFileName)
        {
            // Set the number of vertices per quad (2 triangles)
            NumberOfVerticesPerQuad = 6;

            // Set the value of the topology
            CurrentTopology = PrimitiveTopology.TriangleList;

            // How many times the terrain texture will be repeated both over the width and length of the terrain.
            TextureRepeat = 8;

            // Load the height map for the terrain
            if (!LoadHeightMapFilename(heightMapFileName))
                return false;

            // Normalize the height of the height map
            NormalizeHeightMap();

            // Calculate the normals for the terrain data.
            if (!CalculateNormals())
                return false;

            // Calculate the texture coordinates.
            CalculateTextureCoordinates();

            // Load the texture for this model.
            if (!LoadTexture(device, textureFileName))
                return false;

            // Initialize the vertex and index buffer.
            if (!InitializeBuffers(device))
                return false;

            return true;
        }
开发者ID:nyx1220,项目名称:sharpdx-examples,代码行数:35,代码来源:HeightMapTerrain.cs

示例13: PhysicsDebugDraw

        public PhysicsDebugDraw(DeviceManager manager)
        {
            device = manager.Direct3DDevice;
            inputAssembler = device.ImmediateContext.InputAssembler;
            lineArray = new PositionColored[0];

            using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "VSMain", "vs_5_0"))
            {
                vertexShader = new VertexShader(device, bc);

                InputElement[] elements = new InputElement[]
                {
                    new InputElement("SV_POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                    new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
                };
                inputLayout = new InputLayout(device, bc, elements);
            }

            vertexBufferDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write
            };

            vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);

            using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "PSMain", "ps_5_0"))
                pixelShader = new PixelShader(device, bc);
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:30,代码来源:PhysicsDebugDraw.cs

示例14: TextureShader

        public TextureShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TextureVertexShader", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TexturePixelShader", "ps_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            Layout = VertexDefinition.PositionTexture.GetInputLayout(device, vertexShaderByteCode);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);

            // Create a texture sampler state description.
            var samplerDesc = new SamplerStateDescription
            {
                Filter = Filter.Anisotropic,
                AddressU = TextureAddressMode.Mirror,
                AddressV = TextureAddressMode.Mirror,
                AddressW = TextureAddressMode.Mirror,
                MipLodBias = 0,
                MaximumAnisotropy = 16,
                ComparisonFunction = Comparison.Always,
                BorderColor = new Color4(1, 1, 1, 1),
                MinimumLod = 0,
                MaximumLod = 0
            };

            // Create the texture sampler state.
            SamplerState = new SamplerState(device, samplerDesc);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:33,代码来源:TextureShader.cs

示例15: Copy

        /// <summary>
        /// Copies the content of the specified texture.
        /// </summary>
        /// <param name="device">The Direct3D 11 device.</param>
        /// <param name="source">The source texture.</param>
        /// <param name="target">The target texture.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="device"/>, <paramref name="source"/> or <paramref name="target"/> is
        /// <see langword="null"/>.
        /// </exception>
        public static void Copy(Device device, Texture2D source, Texture2D target)
        {
            if (device == null)
            throw new ArgumentNullException("device");
              if (source == null)
            throw new ArgumentNullException("source");
              if (target == null)
            throw new ArgumentNullException("target");

              int sourceWidth = source.Description.Width;
              int sourceHeight = source.Description.Height;
              int targetWidth = target.Description.Width;
              int targetHeight = target.Description.Height;

              if (sourceWidth == targetWidth && sourceHeight == targetHeight)
              {
            device.ImmediateContext.CopyResource(source, target);
              }
              else
              {
            int width = Math.Min(sourceWidth, targetWidth);
            int height = Math.Min(sourceHeight, targetHeight);
            var region = new ResourceRegion(0, 0, 0, width, height, 1);
            device.ImmediateContext.CopySubresourceRegion(source, 0, region, target, 0);
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:36,代码来源:D3D11Helper.cs


注:本文中的SharpDX.Direct3D11.Device类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。