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


C# DataStream.WriteRange方法代码示例

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


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

示例1: TextureFromBitmap

        public static Texture2D TextureFromBitmap(Bitmap image)
        {
            BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                             ImageLockMode.ReadWrite, image.PixelFormat);
            int bytes = data.Stride*image.Height;
            DataStream stream = new DataStream(bytes, true, true);
            stream.WriteRange(data.Scan0, bytes);
            stream.Position = 0;
            DataRectangle dRect = new DataRectangle(data.Stride, stream);

            Texture2DDescription texDesc = new Texture2DDescription
                                               {
                                                   ArraySize = 1,
                                                   MipLevels = 1,
                                                   SampleDescription = new SampleDescription(1, 0),
                                                   Format = Format.B8G8R8A8_UNorm,
                                                   CpuAccessFlags = CpuAccessFlags.None,
                                                   BindFlags = BindFlags.ShaderResource,
                                                   Usage = ResourceUsage.Immutable,
                                                   Height = image.Height,
                                                   Width = image.Width
                                               };

            image.UnlockBits(data);
            image.Dispose();
            Texture2D texture = new Texture2D(Game.Context.Device, texDesc, dRect);
            stream.Dispose();
            return texture;
        }
开发者ID:yong-ja,项目名称:starodyssey,代码行数:29,代码来源:ImageHelper.cs

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

示例3: MeshContainer

        public MeshContainer(Engine.Serialize.Mesh M)
        {
            if (M != null)
            {
                LocalAABBMax = M.AABBMax;
                LocalAABBMin = M.AABBMin;

                VertexsCount = M.VertexCount;
                FaceCount = M.FaceCount;
                BytesPerVertex = M.VertexData.Length / VertexsCount;

                using (var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true))
                {
                    vertices.WriteRange<byte>(M.VertexData, 0, M.VertexData.Length);
                    vertices.Position = 0;
                    Vertexs = new Buffer(ModelViewer.Program.device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                    binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
                }

                using (var indices = new DataStream(4 * FaceCount * 3, true, true))
                {
                    indices.WriteRange<byte>(M.IndexData, 0, M.IndexData.Length);
                    indices.Position = 0;
                    Indices = new Buffer(ModelViewer.Program.device, indices, 4 * FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                }
            }
        }
开发者ID:MagistrAVSH,项目名称:my-spacegame-engine,代码行数:27,代码来源:MeshContainer.cs

示例4: TerrainObject

        public TerrainObject(TerrainRenderer renderer, Device renderingDevice)
        {
            this.renderingDevice = renderingDevice;
            this.renderer = renderer;

            // Default position
            Position = new Vector3(0, 20, 0);

            // Load textures
            noiseTexture = ShaderResourceView.FromFile(renderingDevice, renderer.Directory + "\\Resources\\Noise.dds");
            grassTexture = ShaderResourceView.FromFile(renderingDevice, renderer.Directory + "\\Resources\\Grass.dds");
            sandTexture = ShaderResourceView.FromFile(renderingDevice, renderer.Directory + "\\Resources\\Sand.dds");
            snowTexture = ShaderResourceView.FromFile(renderingDevice, renderer.Directory + "\\Resources\\Snow.dds");
            snowRockTexture = ShaderResourceView.FromFile(renderingDevice, renderer.Directory + "\\Resources\\SnowRock.dds");

            // Create shader
            SetSourceCode(" float4 getColor(float4 position, float4 normal, float4 camera) { return float4(0, 0, 0, 0); } ");

            // Read data from file
            Vector3[] vertices; int[] indices;

            new XLoader().LoadFile(renderer.Directory + "\\Resources\\Terrain.X", out vertices, out indices);

            //
            DataStream vertexStream = new DataStream(vertices.Length * 12, true, true);
            vertexStream.WriteRange(vertices);
            vertexStream.Position = 0;

            DataStream indexStream = new DataStream(indices.Length * 4, true, true);
            indexStream.WriteRange(indices);
            indexStream.Position = 0;

            //
            BufferDescription vbufferDescription = new BufferDescription();
            vbufferDescription.BindFlags = BindFlags.VertexBuffer;
            vbufferDescription.CpuAccessFlags = CpuAccessFlags.None;
            vbufferDescription.OptionFlags = ResourceOptionFlags.None;
            vbufferDescription.SizeInBytes = (int)vertexStream.Length;
            vbufferDescription.Usage = ResourceUsage.Immutable;

            vertexBuffer = new Buffer(renderingDevice, vertexStream, vbufferDescription);

            //
            BufferDescription ibufferDescription = new BufferDescription();
            ibufferDescription.BindFlags = BindFlags.IndexBuffer;
            ibufferDescription.CpuAccessFlags = CpuAccessFlags.None;
            ibufferDescription.OptionFlags = ResourceOptionFlags.None;
            ibufferDescription.SizeInBytes = (int)indexStream.Length;
            ibufferDescription.Usage = ResourceUsage.Immutable;

            indexBuffer = new Buffer(renderingDevice, indexStream, ibufferDescription);
            indexCount = (int)indexStream.Length / 4;
        }
开发者ID:DelvarWorld,项目名称:shadercomposer,代码行数:53,代码来源:TerrainObject.cs

示例5: MultiMeshContainer

        public MultiMeshContainer(Engine.Serialize.MeshesContainer MC)
        {
            if (MC != null)
            {
                //Transform = Matrix.Scaling(1);

                Hardpoints = MC.HardPoints;
                if (MC.Materials != null && MC.Geometry != null && MC.Geometry.Meshes != null)
                {
                    BSP = MC.Geometry.BSP;
                    LocalAABBMax = MC.Geometry.AABBMax;
                    LocalAABBMin = MC.Geometry.AABBMin;

                    Meshes = new Serialize.MeshLink[MC.Materials.Length];
                    Materials = new MaterialContainer[MC.Materials.Length];
                    for (int i = 0; i < MC.Materials.Length; i++)
                    {
                        Meshes[i] = MC.Geometry.Meshes[i];
                        Materials[i] = new MaterialContainer(MC.Materials[i]);
                    }

                    VertexsCount = MC.Geometry.VertexCount;
                    BytesPerVertex = MC.Geometry.VertexData.Length / VertexsCount;
                    FaceCount = MC.Geometry.IndexData.Length / 12;

                    using (var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true))
                    {
                        vertices.WriteRange<byte>(MC.Geometry.VertexData, 0, MC.Geometry.VertexData.Length);
                        vertices.Position = 0;
                        Vertexs = new Buffer(ModelViewer.Program.device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                        binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
                    }

                    using (var indices = new DataStream(4 * FaceCount * 3, true, true))
                    {
                        indices.WriteRange<byte>(MC.Geometry.IndexData, 0, MC.Geometry.IndexData.Length);
                        indices.Position = 0;
                        Indices = new Buffer(ModelViewer.Program.device, indices, 4 * FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
                    }

                    BufferDescription bd = new BufferDescription();
                    bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
                    bd.Usage = ResourceUsage.Dynamic;
                    bd.BindFlags = BindFlags.ConstantBuffer;
                    bd.CpuAccessFlags = CpuAccessFlags.Write;
                    bd.OptionFlags = ResourceOptionFlags.None;
                    bd.StructureByteStride = 0;

                    constantsBuffer = new Buffer(ModelViewer.Program.device, bd);
                    constants = new ShaderConstants();
                }
            }
        }
开发者ID:MagistrAVSH,项目名称:my-spacegame-engine,代码行数:53,代码来源:MultiMeshContainer.cs

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

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

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

示例9: DXTreeSkeleton

        public DXTreeSkeleton(CS_Tree tree, CS_Params csParams)
        {
            InitShaders();

            DXTreeSkeleton_TreeTraversal traversal = new DXTreeSkeleton_TreeTraversal(csParams);
            tree.traverseTree(traversal);
            BBox = traversal.BBox;

            for (int i = 0; i < 5; i++)
            {
                if (traversal.Vertices2[i].Count != 0)
                {

                    var stream = new DataStream(traversal.Vertices2[i].Count * Marshal.SizeOf(typeof(DXSKV)), true, true);

                    stream.WriteRange(traversal.Vertices2[i].ToArray());
                    stream.Position = 0;
                    _vertexBuffer2[i] = new Buffer(DXDevice, stream, new BufferDescription()
                    {
                        BindFlags = BindFlags.VertexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags = ResourceOptionFlags.None,
                        SizeInBytes = traversal.Vertices2[i].Count * Marshal.SizeOf(typeof(DXSKV)),
                        Usage = ResourceUsage.Default
                    });
                    stream.Dispose();

                    List<UInt32> indices = new List<UInt32>();
                    for (int k = 0; k < traversal.Vertices2[i].Count; k++) { indices.Add((UInt32)k); }

                    stream = new DataStream(indices.Count * sizeof(UInt32), true, true);
                    stream.WriteRange(indices.ToArray());

                    stream.Position = 0;

                    _indexBuffer2[i] = new Buffer(DXDevice, stream, new BufferDescription()
                    {
                        BindFlags = BindFlags.IndexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags = ResourceOptionFlags.None,
                        SizeInBytes = indices.Count * sizeof(UInt32),
                        Usage = ResourceUsage.Default
                    });
                    stream.Dispose();

                    IndexCount2[i] = indices.Count;
                }
            }
        }
开发者ID:khazanJM,项目名称:arbaro-csharp,代码行数:49,代码来源:DXTreeSkeleton.cs

示例10: Octahedron

        public DX11IndexedGeometry Octahedron(Octahedron settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
            geom.PrimitiveType = settings.PrimitiveType;
            geom.Tag = settings;
            geom.VerticesCount = 6;
            geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology = PrimitiveTopology.TriangleList;

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

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            Vector3 size = settings.Size;

            v.Position = Vector3.Normalize(new Vector3(1.0f,0,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(-1.0f,0,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0,1.0f,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0,-1.0f,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            v.Position = Vector3.Normalize(new Vector3(0,0,-1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0,0, 1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            

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

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

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

            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:arturoc,项目名称:FeralTic,代码行数:48,代码来源:DX11Primitive_Octahedron.cs

示例11: TeapotObject

        public TeapotObject(TeapotRenderer renderer, Device renderingDevice)
        {
            this.renderingDevice = renderingDevice;
            this.renderer = renderer;

            // Default position
            Position = new Vector3(0, 20, 0);

            // Create shader
            SetSourceCode(" float4 getColor(float4 position, float4 normal, float4 camera) { return float4(0, 0, 0, 0); } ");

            // Read data from file
            Vector3[] vertices; short[] indices;

            new XLoader().LoadFile(renderer.Directory + "\\Resources\\Teapot.X" , out vertices, out indices);

            //
            DataStream vertexStream = new DataStream(vertices.Length * 12, true, true);
            vertexStream.WriteRange(vertices);
            vertexStream.Position = 0;

            DataStream indexStream = new DataStream(indices.Length * 2, true, true);
            indexStream.WriteRange(indices);
            indexStream.Position = 0;
            
            //
            BufferDescription vbufferDescription = new BufferDescription();
            vbufferDescription.BindFlags = BindFlags.VertexBuffer;
            vbufferDescription.CpuAccessFlags = CpuAccessFlags.None;
            vbufferDescription.OptionFlags = ResourceOptionFlags.None;
            vbufferDescription.SizeInBytes = (int)vertexStream.Length;
            vbufferDescription.Usage = ResourceUsage.Immutable;

            vertexBuffer = new Buffer(renderingDevice, vertexStream, vbufferDescription);

            //
            BufferDescription ibufferDescription = new BufferDescription();
            ibufferDescription.BindFlags = BindFlags.IndexBuffer;
            ibufferDescription.CpuAccessFlags = CpuAccessFlags.None;
            ibufferDescription.OptionFlags = ResourceOptionFlags.None;
            ibufferDescription.SizeInBytes = (int)indexStream.Length;
            ibufferDescription.Usage = ResourceUsage.Immutable;
            
            indexBuffer = new Buffer(renderingDevice, indexStream, ibufferDescription);
            indexCount = (int)indexStream.Length / 2;
        }
开发者ID:DelvarWorld,项目名称:shadercomposer,代码行数:46,代码来源:TeapotObject.cs

示例12: UpdateMap

        public void UpdateMap(string mapName)
        {
            mWdlFile = new IO.Files.Terrain.WdlFile();
            try
            {
                mWdlFile.Load(mapName);
                if(mWdlFile.HasEntries == false)
                {
                    UpdateMapNoWdl(mapName);
                    return;
                }
            }
            catch(Exception)
            {
                UpdateMapNoWdl(mapName);
                return;
            }

            if (mImage != null)
                mImage.Dispose();

            var textureData = new uint[Width * Height];
            for(var i = 0; i < 64; ++i)
            {
                for(var j = 0; j < 64; ++j)
                {
                    if (mWdlFile.HasEntry(j, i) == false)
                        continue;

                    var entry = mWdlFile.GetEntry(j, i);
                    LoadEntry(entry, textureData, ref i, ref j);
                }
            }

            var bmpProps =
                new BitmapProperties(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Ignore));

            using (var dataStream = new DataStream(Width * Height * 4, true, true))
            {
                dataStream.WriteRange(textureData);
                dataStream.Position = 0;

                mImage = new Bitmap(InterfaceManager.Instance.Surface.RenderTarget, new Size2(Width, Height),
                    new DataPointer(dataStream.DataPointer, Width * Height * 4), Width * 4, bmpProps);
            }
        }
开发者ID:Linrasis,项目名称:WoWEditor,代码行数:46,代码来源:WdlControl.cs

示例13: ConvertToByteArray

        private static byte[] ConvertToByteArray(uint[] array)
        {
            
            byte[] result = new byte[array.Length * 4];
            using (DataStream ds = new DataStream(result, true, true))
            {
                ds.WriteRange(array);
            }
            /*
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = (byte)(array[i] >> (8 * 3));
                result[i + 1] = (byte)(array[i] >> (8 * 2));
                result[i + 2] = (byte)(array[i] >> 8);
                result[i + 3] = (byte)(array[i]);

            }*/
            return result;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:19,代码来源:DDS.cs

示例14: TestTriangle

        public TestTriangle(SlimDX.Direct3D11.Device Device)
        {
            using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(@"R:\Users\Rox Cox\Documents\Visual Studio 2013\Projects\LightingEngine_v2\LightingEngine_v2\test.fx", "fx_5_0"))
            {
                try
                {
                    SampleEffect = new Effect(Device, bytecode);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(@"R:\Users\Rox Cox\Documents\Visual Studio 2013\Projects\LightingEngine_v2\LightingEngine_v2\test.fx", "VSTri", "vs_5_0", ShaderFlags.None, EffectFlags.None))
            {
                VS = new VertexShader(Device, bytecode);
            }
            EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0);
            EffectPass pass = technique.GetPassByIndex(0);
            SampleLayout = new InputLayout(Device, pass.Description.Signature, new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });

            SampleStream = new DataStream(4 * 32, true, true);
            SampleStream.WriteRange(new[] {
                new Vector4(1.0f, 1.0f, 0.5f, 1.0f), new Vector4(0.0f, 0.8f, 1.0f, 1.0f),
                new Vector4(1.0f, -1.0f, 0.5f, 1.0f), new Vector4(0.3f, 1.0f, 0.3f, 1.0f),
                new Vector4(-1.0f, -1.0f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, 0.5f, 1.0f), new Vector4(0.0f, 0.8f, 1.0f, 1.0f),
            });
            SampleStream.Position = 0;

            SampleVertices = new SlimDX.Direct3D11.Buffer(Device, SampleStream, new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = 3 * 32,
                Usage = ResourceUsage.Default
            });
        }
开发者ID:RomanHodulak,项目名称:DeferredLightingD3D11,代码行数:42,代码来源:TestTriangle.cs

示例15: Update

        public void Update(TimeSpan timeSpan)
        {
            if (!isRunning) return;

            TimeSpan ts = (DateTime.Now - Last);
            Time.Dt = (float)ts.TotalSeconds;
            //Time.Dt = 1.0f / 60.0f;

            Last = DateTime.Now;
            double fps = 1 / ts.TotalSeconds;
            sumFps += (float)fps;

            Profiles.Current.State.Score = Math.Max((int)(PlayerShip.Instance.Position.Y / 10), Profiles.Current.State.Score);

            if (counter++ % 60 == 0)
            {
                {
                    float fa = 0.18618986725025f;
                    float fb = 210125.0f / 156.0f;
                    float fc = 31.0f / 6.0f;

                    maxEntities = (int)(fa * Math.Sqrt(fb + Profiles.Current.State.Score) + fc);
                }
                {
                    float fa = 38.0f / 9.0f;
                    float fb = 70.0f / 9.0f;
                    float fc = 200f;

                    float x = (float)Profiles.Current.State.Score / 1000.0f;
                    linesSpeed = (int)(fa * x * x + fb * x + fc);
                }
            }

            for (int i = EntityManager.Count; i < maxEntities; i++)
                EntityManager.Add(Rock.Create());

            EntityManager.Update();
            ParticleManager.Update();
            Profiles.Current.State.LinesPosition += linesSpeed * Time.Dt;

            if (Profiles.Current.State.LinesPosition > PlayerShip.Instance.Position.Y)
                GameOver();

            Device device = Host.Device;

            if (ParticleManager.particleList.Count > 0)
            {
                DataStream particles = new DataStream(ParticleManager.particleList.Count * 32, true, true);

                for (int i = 0; i < ParticleManager.particleList.Count; i++)
                {
                    var particle = ParticleManager.particleList[i];

                    Vector2 a = new Vector2(particle.Position.X, particle.Position.Y);
                    Vector2 b = new Vector2(particle.Scale.X, -particle.Orientation);

                    particles.WriteRange(new[] { a, b });
                    particles.Write(particle.Color);
                }
                particles.Position = 0;

                Disposer.RemoveAndDispose(ref this.Particles);

                this.Particles = new Buffer(device, particles, new BufferDescription()
                {
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags = ResourceOptionFlags.None,
                    SizeInBytes = ParticleManager.particleList.Count * 32,
                    Usage = ResourceUsage.Default
                });

                Disposer.RemoveAndDispose(ref particles);
            }
        }
开发者ID:Wronq,项目名称:RocknSpace,代码行数:75,代码来源:GameRoot.cs


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