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


C# Direct3D11.Buffer类代码示例

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


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

示例1: Quad

        public Quad(int startX,int endX, int startZ, int endZ, Base.Content.Terrain.Terrain terrain, RenderManager renderer)
        {
            _bounds = new QuadBounds
            {
                MinX = startX / terrain.PointsPerMeter,
                MaxX = endX / terrain.PointsPerMeter,
                MinZ = startZ / terrain.PointsPerMeter,
                MaxZ = endZ / terrain.PointsPerMeter,
                MinY = terrain.Height[0],
                MaxY = terrain.Height[0]
            };
            HorizontalCenter = new Vector2(Bounds.MinX + (Bounds.MaxX - Bounds.MinX) / 2, Bounds.MinZ + (Bounds.MaxZ - Bounds.MinZ) / 2);

            int verticesX = endX - startX + 1;
            int verticesZ = endZ - startZ + 1;

            var dataStream = new DataStream(32 * verticesX * verticesZ, true, true);

            for (int i = 0; i < verticesX; i++)
            {
                for (int j = 0; j < verticesZ; j++)
                {
                    //Position
                    int xindex = Math.Min(i + startX, terrain.PointsX - 1);//Clamp to arraybounds if neccessary
                    int zindex = Math.Min(j + startZ, terrain.PointsZ - 1);//(Quadsize needs to be consistent for sharing IndexBuffers)
                    float x = xindex / terrain.PointsPerMeter;
                    float z = zindex / terrain.PointsPerMeter;
                    float y = terrain.Height[xindex * terrain.PointsZ + zindex];
                    dataStream.Write(new Vector3(x, y, z));

                    //Normal
                    float deltax = (terrain.Height[(xindex < terrain.PointsX - 1 ? xindex + 1 : xindex) * terrain.PointsZ + zindex]
                        - terrain.Height[(xindex != 0 ? xindex - 1 : xindex) * terrain.PointsZ + zindex]);

                    float deltaz = (terrain.Height[xindex * terrain.PointsZ + (zindex < terrain.PointsZ - 1 ? zindex + 1 : zindex)]
                        - terrain.Height[xindex * terrain.PointsZ + (zindex != 0 ? zindex - 1 : zindex)]);
                    if (xindex == 0 || xindex == terrain.PointsX - 1)
                        deltax *= 2;
                    if (zindex == 0 || zindex == terrain.PointsZ - 1)
                        deltaz *= 2;
                    var normal = new Vector3(-deltax, 2 / terrain.PointsPerMeter, deltaz);
                    normal.Normalize();
                    dataStream.Write(normal);

                    //TextureCoordinates
                    dataStream.Write(new Vector2(x / terrain.PointsX, z / terrain.PointsZ));

                    //Boundingbox-Params
                    if (y < _bounds.MinY)
                        _bounds.MinY = y;
                    if (y > _bounds.MaxY)
                        _bounds.MaxY = y;
                }
            }

            dataStream.Position = 0;
            VBuffer = new Buffer(renderer.D3DDevice, dataStream, 32 * verticesX * verticesZ, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            VertexBuffer = new VertexBufferBinding(VBuffer, 32, 0);
            dataStream.Dispose();
        }
开发者ID:hexd0t,项目名称:Garm_Net,代码行数:60,代码来源:TerrainQuad.cs

示例2: TransparencyShader

 protected TransparencyShader(Device device, string vertexShaderPath, string pixelShaderPath, IInputLayoutProvider inputLayoutMaker)
     : base(device, vertexShaderPath, pixelShaderPath, inputLayoutMaker)
 {
     Contract.Ensures(transparencyConstantBuffer != null, "lightConstantBuffer must be instantiated by this function.");
     BufferDescription transparencyBufferDesc = new BufferDescription(System.Runtime.InteropServices.Marshal.SizeOf(typeof(TransparencyCBuffer)), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
     transparencyConstantBuffer = new SlimDX.Direct3D11.Buffer(device, transparencyBufferDesc);
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:7,代码来源:TransparencyShader.cs

示例3: LoadResources

		public void LoadResources()
		{
			if (m_Disposed == true)
			{
				if (m_Filename != null)
				{
					m_ImposterTexture = Texture2D.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_Filename));
					TextureView = new ShaderResourceView(GameEnvironment.Device, m_ImposterTexture);
				}

				m_Vertices = new SlimDX.Direct3D11.Buffer(GameEnvironment.Device, new BufferDescription()
				{
					BindFlags = BindFlags.VertexBuffer,
					CpuAccessFlags = CpuAccessFlags.Write,
					OptionFlags = ResourceOptionFlags.None,
					SizeInBytes = 4 * Marshal.SizeOf(typeof(Vertex2D)),
					Usage = ResourceUsage.Dynamic
				});

				m_VerticesBindings = new VertexBufferBinding(m_Vertices, Marshal.SizeOf(typeof(Vertex2D)), 0);

				WriteRectangle(); 		

				m_Disposed = false;
			}
		}
开发者ID:RugCode,项目名称:drg-pt,代码行数:26,代码来源:ImageBox.cs

示例4: ObjRenderer

        public ObjRenderer(Form1 F)
            : base(F.Device)
        {
            P = F;
            PortalRoomManager.Equals(null, null);
            S = new Sorter();
            string s0 = Environment.CurrentDirectory + "/resources/shaders/ambient_fast.fx";
            SB_V = ShaderBytecode.CompileFromFile(s0, "VS_STATIC", "vs_4_0", ManagedSettings.ShaderCompileFlags, EffectFlags.None);
            SB_P = ShaderBytecode.CompileFromFile(s0, "PS", "ps_4_0", ManagedSettings.ShaderCompileFlags, EffectFlags.None);
            VS = new VertexShader(F.Device.HadrwareDevice(), SB_V);
            PS = new PixelShader(F.Device.HadrwareDevice(), SB_P);
            IL = new InputLayout(Device.HadrwareDevice(), SB_V, StaticVertex.ies);
            BufferDescription desc = new BufferDescription
            {
                Usage = ResourceUsage.Default,
                SizeInBytes = 2 * 64,
                BindFlags = BindFlags.ConstantBuffer
            };
            cBuf = new SlimDX.Direct3D11.Buffer(Device.HadrwareDevice(), desc);
            dS = new DataStream(2 * 64, true, true);

            BufferDescription desc2 = new BufferDescription
            {
                Usage = ResourceUsage.Default,
                SizeInBytes = 64,
                BindFlags = BindFlags.ConstantBuffer
            };
            cBuf2 = new SlimDX.Direct3D11.Buffer(Device.HadrwareDevice(), desc2);
            dS2 = new DataStream(64, true, true);
        }
开发者ID:hhergeth,项目名称:RisenEditor,代码行数:30,代码来源:ObjRenderer.cs

示例5: GenerateNoiseTexture

        public ShaderResourceView GenerateNoiseTexture(Buffer constantBuffer, DirectComputeConstantBuffer container)
        {
            Texture3D noiseTexture = new Texture3D(graphicsDevice, new Texture3DDescription()
            {
                BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R32_Float,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                Width = container.Width,
                Height = container.Height,
                Depth = container.Depth
            });

            UnorderedAccessView noiseTextureUAV = new UnorderedAccessView(graphicsDevice, noiseTexture);

            DataBox data = graphicsDevice.ImmediateContext.MapSubresource(constantBuffer, MapMode.WriteDiscard, MapFlags.None);
            data.Data.Write<DirectComputeConstantBuffer>(container);
            graphicsDevice.ImmediateContext.UnmapSubresource(constantBuffer, 0);

            graphicsDevice.ImmediateContext.ComputeShader.Set(computeFillNoiseTexture);
            graphicsDevice.ImmediateContext.ComputeShader.SetConstantBuffer(constantBuffer, 0);
            graphicsDevice.ImmediateContext.ComputeShader.SetUnorderedAccessView(noiseTextureUAV, 0);

            Vector3 gridDim = new Vector3((float)Math.Ceiling(container.Width / 8.0f), (float)Math.Ceiling(container.Height / 8.0f), (float)Math.Ceiling(container.Depth / 8.0f));

            graphicsDevice.ImmediateContext.Dispatch((int)gridDim.X, (int)gridDim.Y, (int)gridDim.Z);

            noiseTextureUAV.Dispose();

            return new ShaderResourceView(graphicsDevice, noiseTexture);
        }
开发者ID:barograf,项目名称:VoxelTerrain,代码行数:33,代码来源:DirectComputeNoiseCube.cs

示例6: Minimap

        public Minimap(Device device, DeviceContext dc, int minimapWidth, int minimapHeight, Terrain terrain, CameraBase viewCam)
        {
            _dc = dc;

            _minimapViewport = new Viewport(0, 0, minimapWidth, minimapHeight);

            CreateMinimapTextureViews(device, minimapWidth, minimapHeight);

            _terrain = terrain;

            SetupOrthoCamera();
            _viewCam = viewCam;

            // frustum vb will contain four corners of view frustum, with first vertex repeated as the last
            var vbd = new BufferDescription(
                VertexPC.Stride * 5,
                ResourceUsage.Dynamic,
                BindFlags.VertexBuffer,
                CpuAccessFlags.Write,
                ResourceOptionFlags.None,
                0
            );
            _frustumVB = new Buffer(device, vbd);

            _edgePlanes = new[] {
            new Plane(1, 0, 0, -_terrain.Width / 2),
            new Plane(-1, 0, 0, _terrain.Width / 2),
            new Plane(0, 1, 0, -_terrain.Depth / 2),
            new Plane(0, -1, 0, _terrain.Depth / 2)
            };

            ScreenPosition = new Vector2(0.25f, 0.75f);
            Size = new Vector2(0.25f, 0.25f);
        }
开发者ID:jackinf,项目名称:dx11,代码行数:34,代码来源:Minimap.cs

示例7: DX11DynamicStructuredBuffer

 public DX11DynamicStructuredBuffer(Device dev, Buffer buffer, int cnt) //Dynamic default buffer
 {
     this.Size = cnt;
     this.Buffer = buffer;
     this.Stride = buffer.Description.StructureByteStride;
     this.SRV = new ShaderResourceView(dev, this.Buffer);
 }
开发者ID:arturoc,项目名称:FeralTic,代码行数:7,代码来源:NonGenericStructuredBuffer.cs

示例8: WVPTransformShader

 /// <summary>
 /// Initializes a new instance of the <see cref="WVPTransformShader" /> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="vertexShaderPath">The vertex shader path.</param>
 /// <param name="pixelShaderPath">The pixel shader path.</param>
 public WVPTransformShader(Device device, string vertexShaderPath, string pixelShaderPath, IInputLayoutProvider inputLayoutMaker)
     : base(device, vertexShaderPath, pixelShaderPath, inputLayoutMaker)
 {
     Contract.Ensures(matrixConstantBuffer != null, "matrixConstantBuffer must not be null after this method executes.");
     BufferDescription matrixBufferDesc = new BufferDescription(System.Runtime.InteropServices.Marshal.SizeOf(typeof(MatrixCBuffer)), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
     matrixConstantBuffer = new SlimDX.Direct3D11.Buffer(device, matrixBufferDesc);
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:13,代码来源:WVPTransformShader.cs

示例9: GetRenderablePrimitive

        public override RenderableLightPrimitive GetRenderablePrimitive()
        {
            LightShader shader = new LightShader(Renderer);

            using (ShaderBytecode bytecode = new ShaderBytecode(new DataStream(File.ReadAllBytes("Shaders\\DeferredPointLight.vs"), true, false)))
            {
                shader.VertexShader = new VertexShader(Renderer.Device, bytecode);
                shader.InputLayout = new InputLayout(Renderer.Device, bytecode, new[]
                {
                    new InputElement("Position", 0, Format.R32G32B32_Float, sizeof(float) * 0, 0),
                });
            }
            using (ShaderBytecode bytecode = new ShaderBytecode(new DataStream(File.ReadAllBytes("Shaders\\DeferredPointLightShadowless.ps"), true, false)))
            {
                shader.PixelShader = new PixelShader(Renderer.Device, bytecode);
            }
            using (ShaderBytecode bytecode = new ShaderBytecode(new DataStream(File.ReadAllBytes("Shaders\\DeferredPointLightShadowless.ps"), true, false)))
            {
                shader.PixelShaderShadowless = new PixelShader(Renderer.Device, bytecode);
            }
            shader.Topology = PrimitiveTopology.TriangleList;

            ConstantBufferWrapper MatricesCBuffer = new ConstantBufferWrapper(Renderer, sizeof(float) * 32, ShaderType.VertexShader, 0);
            ConstantBufferWrapper LightCBuffer = new ConstantBufferWrapper(Renderer, sizeof(float) * 64, ShaderType.PixelShader, 0);
            ConstantBufferWrapper ShadowCBuffer = new ConstantBufferWrapper(Renderer, sizeof(float) * 16 * 4, ShaderType.PixelShader, 1);
            MatricesCBuffer.Semantics.Add(Semantic.WorldViewProj);
            MatricesCBuffer.Semantics.Add(Semantic.World);
            LightCBuffer.Semantics.Add(Semantic.View);
            LightCBuffer.Semantics.Add(Semantic.ViewInverse);
            LightCBuffer.Semantics.Add(Semantic.ViewProjInverse);
            LightCBuffer.Semantics.Add(Semantic.CameraPosition);
            shader.ConstantBuffers.Add(MatricesCBuffer);
            shader.ConstantBuffers.Add(LightCBuffer);
            shader.ConstantBuffers.Add(ShadowCBuffer);

            GeometricPrimitive prim = new SpherePrimitive(Renderer, 1, 16);

            DataStream str = new DataStream(prim.GeometryData.Positions, true, false);
            Buffer vertexBuffer = new Buffer(Renderer.Device, str, new BufferDescription()
            {
                SizeInBytes = (int)str.Length,
                BindFlags = BindFlags.VertexBuffer,
                StructureByteStride = 3 * sizeof(float),
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
            });
            int vertexCount = prim.GeometryData.VertexCount;

            DataStream IndicesStream = new DataStream(prim.GeometryData.Indices.ToArray(), true, true);

            int indexCount = prim.GeometryData.IndexCount;
            Buffer indexBuffer = new Buffer(Renderer.Device, IndicesStream, sizeof(ushort) * indexCount,
                ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, sizeof(ushort));

            prim.Dispose();

            return new RenderableLightPrimitive(shader, vertexBuffer, vertexCount, indexBuffer, indexCount);
        }
开发者ID:RomanHodulak,项目名称:DeferredLightingD3D11,代码行数:59,代码来源:PointLightPrimitive.cs

示例10: GPUBufferObject

 // Functions
 public GPUBufferObject()
 {
     m_Size = -1;
     m_BufferObject = null;
     m_ShaderResourceView = null;
     m_UnorderedAccessView = null;
     m_StagingBufferObject = null;
     m_StagingCountBufferObject = null;
 }
开发者ID:shoff,项目名称:CSharpRenderer,代码行数:10,代码来源:GPUBufferObject.cs

示例11: Dispose

 protected override void Dispose(bool disposable)
 {
     Contract.Ensures(transparencyConstantBuffer == null, "This function must dispose of the lightConstantBuffer variable.");
     if (transparencyConstantBuffer != null)
     {
         transparencyConstantBuffer.Dispose();
         transparencyConstantBuffer = null;
     }
     base.Dispose(disposable);
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:10,代码来源:TransparencyShader.cs

示例12: LineStrip3d

        public DX11VertexGeometry LineStrip3d(List<Vector3> points, bool loop)
        {
            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            int vcount = loop ? points.Count + 1 : points.Count;

            Pos3Tex2Vertex[] verts = new Pos3Tex2Vertex[vcount];

            float inc = loop ? 1.0f / (float)vcount : 1.0f / ((float)vcount + 1.0f);

            float curr = 0.0f;
            
                
            for (int i = 0; i < points.Count; i++)
            {
                verts[i].Position = points[i];
                verts[i].TexCoords.X = curr;
                curr += inc;
            }

            if (loop)
            {
                verts[points.Count].Position = points[0];
                verts[points.Count].TexCoords.X = 1.0f;
            }


            DataStream ds = new DataStream(vcount * Pos3Tex2Vertex.VertexSize, true, true);
            ds.Position = 0;
            ds.WriteRange(verts);
            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = (int)ds.Length,
                Usage = ResourceUsage.Default
            });

            ds.Dispose();

            geom.VertexBuffer = vbuffer;
            geom.InputLayout = Pos3Tex2Vertex.Layout;
            geom.Topology = PrimitiveTopology.LineStrip;
            geom.VerticesCount = vcount;
            geom.VertexSize = Pos3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = false;

            return geom;
        }
开发者ID:arturoc,项目名称:FeralTic,代码行数:53,代码来源:DX11Primitive_Line.cs

示例13: Dispose

 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposable"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposable)
 {
     Contract.Ensures(matrixConstantBuffer == null, "matrixConstantBuffer must be null after this method executes.");
     if (disposable)
     {
         if (matrixConstantBuffer != null)
         {
             matrixConstantBuffer.Dispose();
             matrixConstantBuffer = null;
         }
     }
     base.Dispose(disposable);
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:17,代码来源:WVPTransformShader.cs

示例14: Draw

        internal override void Draw(SlimDX.Direct3D11.DeviceContext context)
        {
            Effect effect;
            using (ShaderBytecode byteCode = ShaderBytecode.CompileFromFile("Graphics/Effects/default.fx", "bidon", "fx_5_0", ShaderFlags.OptimizationLevel3, EffectFlags.None))
            {
                effect = new Effect(context.Device, byteCode);
            }
            var technique = effect.GetTechniqueByIndex(1);
            var pass = technique.GetPassByIndex(0);
            InputLayout inputLayout = new InputLayout(context.Device, pass.Description.Signature, new[] {
                new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
                new InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, InputElement.AppendAligned, 0)
            });

            DataStream vertices = new DataStream((Vector3.SizeInBytes + 4) * 6, true, true);
            vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(-1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
            vertices.Write(new ColoredVertex(new Vector3(1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));

            vertices.Position = 0;
            BufferDescription bd = new BufferDescription()
            {
                Usage = ResourceUsage.Default,
                SizeInBytes = 16 * 6,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None
            };

            var vertexBuffer = new SlimDX.Direct3D11.Buffer(context.Device, vertices, bd);

            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
            //context.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);

            /* scale * rotation * translation */
            Matrix worldMatrix = Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.Translation(Position);

            Matrix viewMatrix = Camera.ViewMatrix;

            Matrix projectionMatrix = Camera.ProjectionMatrix;

            effect.GetVariableByName("finalMatrix").AsMatrix().SetMatrix(worldMatrix * viewMatrix * projectionMatrix);

            context.InputAssembler.InputLayout = inputLayout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;

            pass.Apply(context);
            context.Draw(6, 0);
        }
开发者ID:eldernos,项目名称:SlimDXEngine,代码行数:51,代码来源:Rectangle.cs

示例15: Dispose

 protected override void Dispose(bool managed)
 {
     Contract.Ensures(fogConstantBuffer == null, "fogConstantBuffer must be null after this method executes.");
     if (managed)
     {
         //Check if fogConstantBuffer still exists and if so, dispose it and set it to null.
         if (fogConstantBuffer != null)
         {
             fogConstantBuffer.Dispose();
             fogConstantBuffer = null;
         }
     }
     base.Dispose(managed);
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:14,代码来源:FogShader.cs


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