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


C# DataStream.Write方法代码示例

本文整理汇总了C#中DataStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# DataStream.Write方法的具体用法?C# DataStream.Write怎么用?C# DataStream.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataStream的用法示例。


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

示例1: CopyTextureToBitmap

        public static Image CopyTextureToBitmap(D3D.Texture2D texture)
        {
            int width = texture.Description.Width;
            if (width % 16 != 0)
                width = MathExtensions.Round(width, 16) + 16;
            Bitmap bmp = new Bitmap(texture.Description.Width, texture.Description.Height, PixelFormat.Format32bppArgb);
            BitmapData bData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
            using (DataStream stream = new DataStream(bData.Scan0, bData.Stride * bData.Height, false, true))
            {
                DataRectangle rect = texture.Map(0, D3D.MapMode.Read, D3D.MapFlags.None);
                using (DataStream texStream = rect.Data)
                {
                    for (int y = 0; y < texture.Description.Height; y++)
                        for (int x = 0; x < rect.Pitch; x+=4)
                        {
                            byte[] bytes = texStream.ReadRange<byte>(4);
                            if (x < bmp.Width*4)
                            {
                                stream.Write<byte>(bytes[2]);	// DXGI format is BGRA, GDI format is RGBA.
                                stream.Write<byte>(bytes[1]);
                                stream.Write<byte>(bytes[0]);
                                stream.Write<byte>(255);
                            }
                        }
                }
            }

            bmp.UnlockBits(bData);
            return bmp;
        }
开发者ID:adrianj,项目名称:Direct3D-Testing,代码行数:30,代码来源:ScreenCapture.cs

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

示例3: Write

        public void Write( DataStream stream )
        {
            stream.Write( P0 );
            stream.Write( C0 );

            stream.Write( P1 );
            stream.Write( C1 );
        }
开发者ID:jiawen,项目名称:libcgt.net,代码行数:8,代码来源:LineItem.cs

示例4: Serialize

        public void Serialize(DataStream stream)
        {
            stream.Write(SizeX);
            stream.Write(SizeY);

            stream.Write(TexelSizeX);
            stream.Write(TexelSizeY);
        }
开发者ID:fealty,项目名称:Frost,代码行数:8,代码来源:PredefinedConstants.cs

示例5: MyTriangle

 public MyTriangle()
 {
     vertices = new DataStream(12 * 3, true, true);
     vertices.Write(new Vector3(0.0f, 0.5f, 0.5f));
     vertices.Write(new Vector3(0.5f, -0.5f, 0.5f));
     vertices.Write(new Vector3(-0.5f, -0.5f, 0.5f));
     vertices.Position = 0;
 }
开发者ID:kobr4,项目名称:direct3D-projects,代码行数:8,代码来源:MyTriangle.cs

示例6: WriteVertex

 internal override void WriteVertex(DataStream stream, ref Tessellator.VS_IN vsin)
 {
     stream.Write(vsin.Vertex);
     stream.Write(vsin.Color);
     stream.Write(vsin.Normal);
     stream.Write(vsin.Uv);
     stream.Write(vsin.TextureIndex);
 }
开发者ID:samuto,项目名称:HelloWorld,代码行数:8,代码来源:FXTiles.cs

示例7: ApplyLayer

        public override void ApplyLayer(DeviceContext context, GraphicsResource output, OpticalProfile profile, SurfacePass pass, double time, double dt)
        {
            using (DataStream cbuffer = new DataStream(8, true, true))
            {
                cbuffer.Write<float>((float)profile.Size);
                cbuffer.Write<float>((float)profile.Glare);
                cbuffer.Position = 0;

                pass.Pass(context, Encoding.ASCII.GetString(Resources.Structural), output.Dimensions, output.RTV, null, cbuffer);
            }
        }
开发者ID:TomCrypto,项目名称:Insight,代码行数:11,代码来源:StructuralLayer.cs

示例8: SetCameraParameters

 public void SetCameraParameters(DeviceContext context, Camera camera)
 {
     Contract.Requires<ArgumentNullException>(context != null, "Parameter context must not be null.");
     Contract.Requires<ArgumentNullException>(camera != null, "Parameter camera must not be null.");
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(CameraCBuffer)), true, true))
     {
         data.Write(camera.Position);
         data.Write(0f);
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), cameraConstantBuffer, 0);
         context.VertexShader.SetConstantBuffer(cameraConstantBuffer, 1);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:13,代码来源:LightShader.cs

示例9: SetFogParameters

 public void SetFogParameters(DeviceContext context, float start, float end, Color3 fogColour)
 {
     Contract.Requires<ArgumentNullException>(fogColour != null, "fogColour");
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(FogCBuffer)), true, true))
     {
         data.Write(start);
         data.Write(end);
         data.Write(fogColour);
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), fogConstantBuffer, 0);
         context.VertexShader.SetConstantBuffer(fogConstantBuffer, 0);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:13,代码来源:FogShader.cs

示例10: Tetrahedron

        public DX11IndexedGeometry Tetrahedron(Vector3 size)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
            geom.VerticesCount = 4;
            geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology = PrimitiveTopology.TriangleList;

            // This is the golden ratio
            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            DataStream ds = new DataStream(4 * Pos3Norm3Tex2Vertex.VertexSize, false, true);

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            // TODO fibo 2012-03-21:
            // should be nice to have the four tetrahedra embedded in a dodecahedron
            // that's why I just commented the coordinates of the dodecahedron points
            //v.Position = new Vector3(-1, t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = new Vector3(1, t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(-1, -t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(1, -t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            //v.Position = new Vector3(0, -1, t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = new Vector3(0, 1, t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(0, -1, -t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(0, 1, -t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            //v.Position = new Vector3(t, 0, -1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = new Vector3(t, 0, 1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(-t, 0, -1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(-t, 0, 1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(12 * 4, true, true);

            int[] inds = new int[] {
                0,1,2,
                1,2,3,
                2,3,0,
                3,0,1 };

            indexstream.WriteRange(inds);

            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
            return geom;
        }
开发者ID:kopffarben,项目名称:FeralTic,代码行数:51,代码来源:DX11Primitive_Tetrahedron.cs

示例11: QuadNormals

        public DX11IndexedGeometry QuadNormals(Quad settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
            geom.Tag = settings;
            geom.PrimitiveType = settings.PrimitiveType;

            Vector2 size = settings.Size;

            DataStream ds = new DataStream(4 * Pos4Norm3Tex2Vertex.VertexSize, true, true);
            ds.Position = 0;

            float sx = 0.5f * size.X;
            float sy = 0.5f * size.Y;

            Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex();
            v.Position = new Vector4(-sx, sy, 0.0f, 1.0f);
            v.Normals = new Vector3(0, 0, 1);
            v.TexCoords = new Vector2(0, 0);
            ds.Write<Pos4Norm3Tex2Vertex>(v);

            v.Position = new Vector4(sx, sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(1, 0);
            ds.Write<Pos4Norm3Tex2Vertex>(v);

            v.Position = new Vector4(-sx, -sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(0, 1);
            ds.Write<Pos4Norm3Tex2Vertex>(v);

            v.Position = new Vector4(sx, -sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(1, 1);
            ds.Write<Pos4Norm3Tex2Vertex>(v);

            var vertices = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(24, true, true);
            indexstream.WriteRange(new int[] { 0, 1, 3, 3, 2, 0 });


            geom.VertexBuffer = vertices;
            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);
            geom.InputLayout = Pos4Norm3Tex2Vertex.Layout;
            geom.Topology = PrimitiveTopology.TriangleList;
            geom.VerticesCount = 4;
            geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f));

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

示例12: ResourceFontLoader

        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceFontLoader"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        public ResourceFontLoader(Factory factory)
        {
            _factory = factory;
            foreach (var name in typeof(ResourceFontLoader).Assembly.GetManifestResourceNames())
            {
                if (name.EndsWith(".ttf"))
                {
                    var fontBytes = Utilities.ReadStream(typeof (ResourceFontLoader).Assembly.GetManifestResourceStream(name));
                    var stream = new DataStream(fontBytes.Length, true, true);
                    stream.Write(fontBytes, 0, fontBytes.Length);
                    stream.Position = 0;
                    _fontStreams.Add(new ResourceFontFileStream(stream));
                }
            }

            // Build a Key storage that stores the index of the font
            _keyStream = new DataStream(sizeof(int) * _fontStreams.Count, true, true);
            for (int i = 0; i < _fontStreams.Count; i++ )
                _keyStream.Write((int)i);
            _keyStream.Position = 0;

            // Register the 
            _factory.RegisterFontFileLoader(this);
            _factory.RegisterFontCollectionLoader(this);
        }
开发者ID:numo16,项目名称:SharpDX,代码行数:29,代码来源:ResourceFontLoader.cs

示例13: SDXBitmapFromSysBitmap

        private SharpDX.Direct2D1.Bitmap SDXBitmapFromSysBitmap(WindowRenderTarget device, System.Drawing.Bitmap bitmap)
        {
            var sourceArea = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var bitmapProperties = new BitmapProperties(new PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied));
            var size = new Size2(bitmap.Width, bitmap.Height);

            // Transform pixels from BGRA to RGBA
            int stride = bitmap.Width * sizeof(int);
            using (var tempStream = new DataStream(bitmap.Height * stride, true, true))
            {
                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Convert all pixels 
                for (int y = 0; y < bitmap.Height; y++)
                {
                    int offset = bitmapData.Stride * y;
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        // Not optimized 
                        byte B = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte G = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte R = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte A = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int rgba = R | (G << 8) | (B << 16) | (A << 24);
                        tempStream.Write(rgba);
                    }

                }
                bitmap.UnlockBits(bitmapData);
                tempStream.Position = 0;

                return new SharpDX.Direct2D1.Bitmap(device, size, tempStream, stride, bitmapProperties);
            }
        }
开发者ID:nkarpey,项目名称:Zat-s-External-CSGO-Multihack,代码行数:35,代码来源:ESP.cs

示例14: SetWVPMatrices

 /// <summary>
 /// Sets the shader parameters.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="world">The world.</param>
 /// <param name="view">The view.</param>
 /// <param name="projection">The projection.</param>
 public virtual void SetWVPMatrices(DeviceContext context, Matrix world, Matrix view, Matrix projection)
 {
     Contract.Requires<ArgumentNullException>(context != null, "context");
     Contract.Requires<ArgumentNullException>(world != null, "world");
     Contract.Requires<ArgumentNullException>(view != null, "view");
     Contract.Requires<ArgumentNullException>(projection != null, "projection");
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(MatrixCBuffer)), true, true))
     {
         data.Write(Matrix.Transpose(world));
         data.Write(Matrix.Transpose(view));
         data.Write(Matrix.Transpose(projection));
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), matrixConstantBuffer, 0);
         context.VertexShader.SetConstantBuffer(matrixConstantBuffer, 0);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:23,代码来源:WVPTransformShader.cs

示例15: ToTexture3D

        public ShaderResourceView ToTexture3D(Device graphicsDevice, Format format)
        {
            int sizeInBytes = sizeof(float) * width * height * depth;

            DataStream stream = new DataStream(sizeInBytes, true, true);
            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                    for (int z = 0; z < depth; z++)
                        stream.Write(values[x, y, z]);
            stream.Position = 0;

            DataBox dataBox = new DataBox(sizeof(float) * width, sizeof(float) * width * height, stream);
            Texture3DDescription description = new Texture3DDescription()
            {
                BindFlags = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Depth = depth,
                Format = format,
                Height = height,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                Width = width
            };
            Texture3D texture = new Texture3D(graphicsDevice, description, dataBox);

            stream.Dispose();

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


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