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


C# Direct3D11.Buffer类代码示例

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


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

示例1: IndexBuffer

        public IndexBuffer(Device device, ushort[] indices)
        {
            if(device == null)
            {
                throw new ArgumentNullException("device");
            }

            if(indices == null)
            {
                throw new ArgumentNullException("indices");
            }

            using(var dataStream = new DataStream(sizeof(UInt16)*indices.Length, true, true))
            {
                dataStream.WriteRange(indices);
                dataStream.Position = 0;

                Buffer = new Buffer(device,
                                    dataStream,
                                    (int) dataStream.Length,
                                    ResourceUsage.Immutable,
                                    BindFlags.IndexBuffer,
                                    CpuAccessFlags.None,
                                    ResourceOptionFlags.None,
                                    0);
            }

            Count = indices.Length;
        }
开发者ID:Bloyteg,项目名称:AlphaMapper,代码行数:29,代码来源:IndexBuffer.cs

示例2: Postprocess

        public Postprocess(Game game, string shaderFile, RenderTexture rt = null, string name = null)
        {
            this.game = game;
            this.renderTexture = rt;
            if(name == null)
            {
                this.Name = System.IO.Path.GetFileNameWithoutExtension(shaderFile);
                this.debugName = "Postprocess " + this.Name;
            }
            else
            {
                this.debugName = this.Name = name;
            }
            this.shaderFile = shaderFile;

            var desc = SamplerStateDescription.Default();
            desc.Filter = Filter.MinMagMipPoint;
            defaultSamplerStateDescription = desc;

            LoadShader();
            BuildVertexBuffer();
            ppBuffer = Material.CreateBuffer<LiliumPostprocessData>();

            game.AddObject(this);
        }
开发者ID:woncomp,项目名称:LiliumLab,代码行数:25,代码来源:Postprocess.cs

示例3: Buffer

        public Buffer(BufferDescription description)
        {
            _description = description;
            _flags = GetBufferFlagsFromDescription(description);

            _nativeBuffer = new SharpDX.Direct3D11.Buffer(GraphicManager.Device, description);
        }
开发者ID:bgarate,项目名称:SynergyEngine,代码行数:7,代码来源:Buffer.cs

示例4: Rectangle

        public Rectangle(Renderer renderer, Vector2I screenSize, Vector2I position, Vector2I size, Vector4 color, float depth = 0.0f)
        {
            _shader = renderer.ColorShader;
            Position = position;
            ScreenSize = screenSize;
            Size = size;
            _color = color;
            _changed = true;
            Depth = depth;

            int vertexCount = 4;
            _indexCount = 6;

            _vertices = new VertexDefinition.PositionColor[vertexCount];
            UInt32[] indices = { 0, 1, 2, 0, 3, 1 };

            _vertexBuffer = Buffer.Create(renderer.DirectX.Device, _vertices,
                new BufferDescription
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionColor>() * vertexCount,
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                });

            _indexBuffer = Buffer.Create(renderer.DirectX.Device, BindFlags.IndexBuffer, indices);
        }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:29,代码来源:Rectangle.cs

示例5: SibenikMaterial

        public SibenikMaterial(Device device, TweakBar bar, String name)
            : base(device, bar, name)
        {
            bar.AddColor(Prefix + "diffuse", "Diffuse", name, new Color3(1, 1, 1));
            bar.AddColor(Prefix + "specular", "Specular", name, new Color3(1, 1, 1));
            bar.AddFloat(Prefix + "shininess", "Shininess", name, 1, 256, 64, 0.1, 2);
            bar.AddFloat(Prefix + "brightness", "Brightness", name, 0, 15000, 5, 50, 2);

            pixelShader = Material.CompileShader(device, "sibenik");

            constantBuffer = Material.AllocateMaterialBuffer(device, BufferSize);

            sampler = new SamplerState(device, new SamplerStateDescription()
            {
                ComparisonFunction = Comparison.Always,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                BorderColor = Color4.Black,
                MaximumAnisotropy = 16,
                MaximumLod = 15,
                MinimumLod = 0,
                MipLodBias = 0,
            });
        }
开发者ID:TomCrypto,项目名称:Insight,代码行数:26,代码来源:SibenikMaterial.cs

示例6: CreateDeviceDependentResources

        protected override void CreateDeviceDependentResources()
        {
            RemoveAndDispose(ref vertexBuffer);
            RemoveAndDispose(ref indexBuffer);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;

            // Load texture (a DDS cube map)
            textureView = ShaderResourceView.FromFile(device, "CubeMap.dds");

            // Create our sampler state
            samplerState = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinMagMipLinear,
                MaximumLod = 9, // Our cube map has 10 mip map levels (0-9)
                MinimumLod = 0,
                MipLodBias = 0.0f
            });

            Vertex[] vertices;
            int[] indices;
            GeometricPrimitives.GenerateSphere(out vertices, out indices, Color.Gray);

            vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices));
            vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf<Vertex>(), 0);

            indexBuffer = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, indices));
            totalVertexCount = indices.Length;
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:35,代码来源:SphereRenderer.cs

示例7: Geometry

        //Constructor
        internal Geometry(SharpDevice device, ModelGeometry data, bool animated)
        {
            this.Name = data.Name;
            this.Device = device;

            //Data
            List<VertexFormat> vertices = new List<VertexFormat>(data.Vertices);

            List<int> indices = new List<int>(data.Indices);

            VertexCount = vertices.Count;
            IndexCount = indices.Count;

            //Vertex Buffer
            VertexBuffer = SharpDX.Direct3D11.Buffer.Create<VertexFormat>(Device.Device, BindFlags.VertexBuffer, vertices.ToArray());

            //Index Buffer
            IndexBuffer = SharpDX.Direct3D11.Buffer.Create<int>(Device.Device, BindFlags.IndexBuffer, indices.ToArray());

            Material = new Material(data.Material);

            IsAnimated = animated;

            transformBuffer = new Buffer11(Device.Device, Utilities.SizeOf<SkinShaderInformation>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            paletteBuffer = new Buffer11(Device.Device, Utilities.SizeOf<Matrix>() * 256, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
开发者ID:chantsunman,项目名称:SharpDX_Demo,代码行数:27,代码来源:Geometry.cs

示例8: StencilShadowRenderer

        public StencilShadowRenderer(Game game)
        {
            this.game = game;

            var desc = new MaterialPassDesc();
            desc.ManualConstantBuffers = true;
            desc.ShaderFile = "StencilShadow.hlsl";
            desc.BlendStates.RenderTarget[0].IsBlendEnabled = true;
            desc.BlendStates.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
            desc.BlendStates.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
            desc.BlendStates.RenderTarget[0].BlendOperation = BlendOperation.Add;
            desc.BlendStates.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
            desc.BlendStates.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            desc.BlendStates.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
            desc.BlendStates.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            desc.DepthStencilStates.IsDepthEnabled = true;
            desc.DepthStencilStates.DepthWriteMask = DepthWriteMask.Zero;
            desc.DepthStencilStates.DepthComparison = Comparison.LessEqual;
            desc.DepthStencilStates.IsStencilEnabled = true;
            desc.DepthStencilStates.StencilReadMask = 1;
            desc.DepthStencilStates.StencilWriteMask = 1;
            desc.DepthStencilStates.FrontFace.FailOperation = StencilOperation.Keep;
            desc.DepthStencilStates.FrontFace.DepthFailOperation = StencilOperation.Keep;
            desc.DepthStencilStates.FrontFace.PassOperation = StencilOperation.Replace;
            desc.DepthStencilStates.FrontFace.Comparison = Comparison.NotEqual;
            desc.StencilRef = 1;
            pass = new MaterialPass(game.Device, desc, "StencilShadow");
            buffer = Material.CreateBuffer<ShaderData>();
        }
开发者ID:woncomp,项目名称:LiliumLab,代码行数:29,代码来源:StencilShadowRenderer.cs

示例9: CreateBufferUAV

        public static UnorderedAccessView CreateBufferUAV(SharpDX.Direct3D11.Device device, Buffer buffer, UnorderedAccessViewBufferFlags flags = UnorderedAccessViewBufferFlags.None)
        {
            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                Dimension = UnorderedAccessViewDimension.Buffer,
                Buffer = new UnorderedAccessViewDescription.BufferResource { FirstElement = 0 }
            };
            if ((buffer.Description.OptionFlags & ResourceOptionFlags.BufferAllowRawViews) == ResourceOptionFlags.BufferAllowRawViews)
            {
                // A raw buffer requires R32_Typeless
                uavDesc.Format = Format.R32_Typeless;
                uavDesc.Buffer.Flags = UnorderedAccessViewBufferFlags.Raw | flags;
                uavDesc.Buffer.ElementCount = buffer.Description.SizeInBytes / 4;
            }
            else if ((buffer.Description.OptionFlags & ResourceOptionFlags.BufferStructured) == ResourceOptionFlags.BufferStructured)
            {
                uavDesc.Format = Format.Unknown;
                uavDesc.Buffer.Flags = flags;
                uavDesc.Buffer.ElementCount = buffer.Description.SizeInBytes / buffer.Description.StructureByteStride;
            }
            else
            {
                throw new ArgumentException("Buffer must be raw or structured", "buffer");
            }

            return new UnorderedAccessView(device, buffer, uavDesc);
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:27,代码来源:ParticleRenderer.cs

示例10: PathShader

        public PathShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "VS", "vs_4_0", ShaderFlags);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "PS", "ps_4_0", ShaderFlags);
            var geometryShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "GS", "gs_4_0", ShaderFlags);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);
            GeometryShader = new GeometryShader(device, geometryShaderByteCode);
            Layout = VertexDefinition.Path.GetInputLayout(device, vertexShaderByteCode);

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

            ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
            ConstantPathDataBuffer = new Buffer(device,
                new BufferDescription
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<PathData>(),
                    BindFlags = BindFlags.ConstantBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                });
            SamplerState = new SamplerState(device, WrapSamplerStateDescription);
        }
开发者ID:ndech,项目名称:Alpha,代码行数:28,代码来源:PathShader.cs

示例11: Draw

        public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, SharpDX.Direct3D.PrimitiveTopology primitiveType, float opacity = 1.0f)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);

            }
            renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, texture != null, opacity);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
            if (texture != null)
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
            }
            else
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, null);
            }
            renderContext.devContext.Draw(count, 0);
        }
开发者ID:china-vo,项目名称:wwt-windows-client,代码行数:33,代码来源:Sprite2d.cs

示例12: Init

        internal void Init(string name, ref BufferDescription description, IntPtr? initData)
        {
            m_description = description;
            m_elementCount = description.SizeInBytes / Math.Max(1, Description.StructureByteStride);

            try
            {
                m_buffer = new Buffer(MyRender11.Device, initData ?? default(IntPtr), description)
                {
                    DebugName = name,
                };
            }
            catch (SharpDXException e)
            {
                MyRenderProxy.Log.WriteLine("Error during allocation of a directX buffer!");
                LogStuff(e);
                throw;
            }

            try
            {
                AfterBufferInit();
            }
            catch (SharpDXException e)
            {
                MyRenderProxy.Log.WriteLine("Error during creating a view or an unordered access to a directX buffer!");
                LogStuff(e);
                throw;
            }

            IsReleased = false;
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:32,代码来源:MyBuffers.cs

示例13: UpdateBuffer

        /****************************************************************************************************
         * 
         ****************************************************************************************************/
        public void UpdateBuffer(DeviceContext context, Matrix world, ICamera camera)
        {
            var view = camera.CreateViewMatrix();
            var projection = camera.CreateProjectionMatrix(Resolution);
            Matrices[0] = Matrix.Transpose(world);
            Matrices[1] = Matrix.Transpose(view);
            Matrices[2] = Matrix.Transpose(projection);
            Matrices[3] = Matrix.Transpose(world * view);
            Matrices[4] = Matrix.Transpose(world * view * projection);
            Matrices[5] = Matrix.Transpose(view * projection);
            Matrices[6] = Matrix.Invert(world);
            Matrices[7] = Matrix.Invert(world * view);
            Matrices[8] = Matrix.Transpose(Matrix.Identity * Matrix.Scaling(LightPosition));
            Matrices[9] = new Matrix(new float[] 
            {
                LerpTime, AbsoluteTime, Resolution.X, Resolution.Y,
                BeatTime, Lead,0,0,
                Nisse0, Nisse1, Nisse2, Nisse3,
                0,0,0,0,
            });
            if (Buffer == null)
            {
                Buffer = new Buffer(context.Device, Matrices.Length * Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            }

            context.UpdateSubresource(Matrices, Buffer);
        }
开发者ID:JoltSoftwareDevelopment,项目名称:Jolt.MashRoom,代码行数:30,代码来源:ShaderEnvironment.cs

示例14: CreateGameColorBuffer

        /// <summary>
        /// Create a buffer containing all GameColors
        /// </summary>
        public static SharpDX.Direct3D11.Buffer CreateGameColorBuffer(Device device)
        {
            int numcolors = GameColorRGB.NUMCOLORS;

            var arr = new int[numcolors];
            for (int i = 0; i < numcolors; ++i)
            {
                var gc = (GameColor)i;
                arr[i] = GameColorRGB.FromGameColor(gc).ToInt32();
            }

            SharpDX.Direct3D11.Buffer colorBuffer;

            using (var stream = DataStream.Create(arr, true, false))
            {
                colorBuffer = new SharpDX.Direct3D11.Buffer(device, stream, new BufferDescription()
                {
                    BindFlags = BindFlags.ShaderResource,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags = ResourceOptionFlags.None,
                    SizeInBytes = sizeof(int) * arr.Length,
                    Usage = ResourceUsage.Immutable,
                });
            }

            return colorBuffer;
        }
开发者ID:Fulborg,项目名称:dwarrowdelf,代码行数:30,代码来源:Helpers11.cs

示例15: 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


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