コード例 #1
0
        private void SetupIndexBuffer()
        {
            triangleCount = subDivX * subDivY * 2;
            var indices = new ushort[triangleCount * 3];
            int offset  = 0;

            for (int i = 0; i < triangleCount / 2; i++)
            {
                indices[i * 6]     = (ushort)(i + offset + 1);
                indices[i * 6 + 1] = (ushort)(i + offset + (subDivX + 1) + 1);
                indices[i * 6 + 2] = (ushort)(i + offset + (subDivX + 1));

                indices[i * 6 + 3] = (ushort)(i + offset);
                indices[i * 6 + 4] = (ushort)(i + offset + 1);
                indices[i * 6 + 5] = (ushort)(i + offset + (subDivX + 1));

                if ((i + 1) % subDivX == 0)
                {
                    offset++;
                }
            }

            indexBuffer?.Dispose();
            indexBuffer = null;

            indexBuffer = new IndexBuffer(GameMain.Instance.GraphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None);
            indexBuffer.SetData(indices);

            Deform(new Vector2[, ]
            {
                { Vector2.Zero, Vector2.Zero },
                { Vector2.Zero, Vector2.Zero }
            });
        }
コード例 #2
0
 private void CreateIndexBuffer()
 {
     _indexBuffer?.Dispose();
     _indexBuffer = IndexBuffer.Create <ushort>(RenderContext,
                                                _indexBufferSize,
                                                BufferUsageHint.StreamDraw,
                                                true);
     _indexBuffer.Label = "SpriteBatch IndexBuffer";
 }
コード例 #3
0
ファイル: QuadBatchRenderer.cs プロジェクト: umurgdk/Tetris
        public void Clear()
        {
            _usedBlocks = 0;
            _vertices   = new VertexPositionColor[_blocksCapacity * 4];
            _indices    = new uint[_blocksCapacity * 6];

            _vertexBuffer?.Dispose();
            _indexBuffer?.Dispose();

            _vertexBuffer = null;
            _indexBuffer  = null;
        }
コード例 #4
0
 public override void Dispose()
 {
     instanceBuffer?.Dispose();
     vertexBuffer?.Dispose();
     indexBuffer?.Dispose();
     ArrayPool<InstanceData>.Shared.Return(instanceData);
 }
コード例 #5
0
 private void ShutDownBuffers()
 {
     IndexBuffer?.Dispose();
     IndexBuffer = null;
     VertexBuffer?.Dispose();
     VertexBuffer = null;
 }
コード例 #6
0
ファイル: Model.cs プロジェクト: polytronicgr/Axiverse
 public void Dispose()
 {
     VertexBuffer?.Dispose();
     VertexBuffer = null;
     IndexBuffer?.Dispose();
     IndexBuffer = null;
 }
コード例 #7
0
ファイル: Buffer.cs プロジェクト: vaulthunter/sledge
        public void Update <T>(IEnumerable <T> vertices, IEnumerable <uint> indices) where T : struct
        {
            var verts = vertices.ToArray();
            var index = indices.ToArray();

            if (verts.Length == 0 || index.Length == 0)
            {
                return;
            }

            var vsize = (uint)(verts.Length * Unsafe.SizeOf <T>());
            var isize = (uint)index.Length * sizeof(uint);

            if (VertexBuffer == null || VertexBuffer.SizeInBytes < vsize)
            {
                VertexBuffer?.Dispose();
                VertexBuffer = _device.ResourceFactory.CreateBuffer(new BufferDescription(vsize, BufferUsage.VertexBuffer | BufferUsage.Dynamic));
            }
            if (IndexBuffer == null || IndexBuffer.SizeInBytes < isize)
            {
                IndexBuffer?.Dispose();
                IndexBuffer = _device.ResourceFactory.CreateBuffer(new BufferDescription(isize, BufferUsage.IndexBuffer | BufferUsage.Dynamic));
            }

            _created = true;

            _device.UpdateBuffer(VertexBuffer, 0, verts);
            _device.UpdateBuffer(IndexBuffer, 0, index);

            VertexCount = verts.Length;
            IndexCount  = index.Length;
        }
コード例 #8
0
ファイル: DbgPrim.cs プロジェクト: metal-crow/DSAnimStudio
        protected void FinalizeBuffers(bool force = false)
        {
            if (force || NeedToRecreateVertBuffer)
            {
                VertBuffer?.Dispose();
                VertBuffer = null;
                if (Vertices.Length > 0)
                {
                    VertBuffer = new VertexBuffer(GFX.Device,
                                                  typeof(VertexPositionColorNormal), Vertices.Length, BufferUsage.WriteOnly);
                    VertBuffer.SetData(Vertices);
                }
                NeedToRecreateVertBuffer = false;
            }

            if (force || NeedToRecreateIndexBuffer)
            {
                IndexBuffer?.Dispose();
                IndexBuffer = null;
                if (Indices.Length > 0)
                {
                    IndexBuffer = new IndexBuffer(GFX.Device, IndexElementSize.ThirtyTwoBits, Indices.Length, BufferUsage.WriteOnly);
                    IndexBuffer.SetData(Indices);
                }
                NeedToRecreateIndexBuffer = false;
            }
        }
コード例 #9
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         VertexBuffer.Dispose();
         IndexBuffer?.Dispose();
     }
 }
コード例 #10
0
 public void Dispose()
 {
     _vertexBuffer?.Dispose();
     _indexBufferCage?.Dispose();
     _indexBufferCube?.Dispose();
     _decalShader?.Dispose();
     _decalBlend?.Dispose();
 }
コード例 #11
0
 public void SetOnly <VType>(VType[] vertices, int[] indices) where VType : struct
 {
     VertexBuffer?.Dispose( );
     IndexBuffer?.Dispose( );
     VertexBuffer = Buffer11.Create <VType>(Device.Device, BindFlags.VertexBuffer, vertices);
     IndexBuffer  = Buffer11.Create(Device.Device, BindFlags.IndexBuffer, indices);
     VertexSize   = SharpDX.Utilities.SizeOf <VType>();
 }
コード例 #12
0
 /// <summary>
 /// Frees resources used by this object.
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _vertexBuffer?.Dispose();
         _indexBuffer?.Dispose();
     }
 }
コード例 #13
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 public void Dispose()
 {
     ImGui.DestroyContext(Context);
     Effect?.Dispose();
     RasterizerState?.Dispose();
     VertexBuffer?.Dispose();
     IndexBuffer?.Dispose();
 }
コード例 #14
0
ファイル: DbgPrimSolid.cs プロジェクト: micvb123/DSAnimStudio
 protected override void DisposeBuffers()
 {
     if (!KeepBuffersAlive)
     {
         VertBuffer?.Dispose();
         IndexBuffer?.Dispose();
     }
 }
コード例 #15
0
 public void Dispose()
 {
     vertexBuffer?.Dispose();
     indexBuffer?.Dispose();
     texture?.Dispose();
     graphicsDevice?.Dispose();
     effect?.Dispose();
 }
コード例 #16
0
 public override void Dispose()
 {
     vertexBuffer?.Dispose();
     vertexBuffer = null;
     indexBuffer?.Dispose();
     indexBuffer = null;
     TileBufferCount--;
     disposed = true;
 }
コード例 #17
0
 public void Dispose()
 {
     _vb?.Dispose();
     _ib?.Dispose();
     _material?.Dispose();
     _texture?.Dispose();
     _textureBinding?.Dispose();
     _wireframeState?.Dispose();
 }
コード例 #18
0
 private void ReleaseBuffers()
 {
     // Release the index buffer.
     IndexBuffer?.Dispose();
     IndexBuffer = null;
     // Release the vertex buffer.
     VertexBuffer?.Dispose();
     VertexBuffer = null;
 }
コード例 #19
0
 private void ShutdownBuffers()
 {
     // Return the index buffer.
     IndexBuffer?.Dispose();
     IndexBuffer = null;
     // Release the vertex buffer.
     VertexBuffer?.Dispose();
     VertexBuffer = null;
 }
コード例 #20
0
ファイル: SpriteRecorder.cs プロジェクト: yuandev/Barotrauma
        public void Render(Camera cam)
        {
            if (!ReadyToRender)
            {
                return;
            }
            var gfxDevice = GameMain.Instance.GraphicsDevice;

            BasicEffect ??= new BasicEffect(gfxDevice);
            BasicEffect.Projection         = Matrix.CreateOrthographicOffCenter(new Rectangle(0, 0, cam.Resolution.X, cam.Resolution.Y), -1f, 1f);
            BasicEffect.View               = cam.Transform;
            BasicEffect.World              = Matrix.Identity;
            BasicEffect.TextureEnabled     = true;
            BasicEffect.VertexColorEnabled = true;
            BasicEffect.Alpha              = 1f;

            int requiredIndexCount = maxSpriteCount * 6;

            if (requiredIndexCount > 0 && (indexBuffer == null || indexBuffer.IndexCount < requiredIndexCount))
            {
                indexBuffer?.Dispose();
                indexBuffer = new IndexBuffer(gfxDevice, IndexElementSize.SixteenBits, requiredIndexCount * 2, BufferUsage.WriteOnly);
                ushort[] indices = new ushort[requiredIndexCount * 2];
                for (int i = 0; i < indices.Length; i += 6)
                {
                    indices[i + 0] = (ushort)((i / 6) * 4 + 1);
                    indices[i + 1] = (ushort)((i / 6) * 4 + 0);
                    indices[i + 2] = (ushort)((i / 6) * 4 + 2);
                    indices[i + 3] = (ushort)((i / 6) * 4 + 1);
                    indices[i + 4] = (ushort)((i / 6) * 4 + 2);
                    indices[i + 5] = (ushort)((i / 6) * 4 + 3);
                }
                indexBuffer.SetData(indices);
            }

            gfxDevice.Indices = indexBuffer;
            for (int i = 0; i < recordedBuffers.Count; i++)
            {
                gfxDevice.SetVertexBuffer(recordedBuffers[i].VertexBuffer);
                BasicEffect.Texture = recordedBuffers[i].Texture;
                BasicEffect.CurrentTechnique.Passes[0].Apply();
                gfxDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, recordedBuffers[i].PolyCount);
            }
        }
コード例 #21
0
ファイル: Mesh.cs プロジェクト: henbagle/ME3Explorer
        public void RebuildBuffer(SharpDX.Direct3D11.Device Device)
        {
            // Dispose all the old stuff
            VertexBuffer?.Dispose();
            IndexBuffer?.Dispose();
            if (Triangles.Count == 0 || Vertices.Count == 0)
            {
                return;                                              // Why build and empty buffer?
            }
            // Reset the AABB
            if (Vertices.Count == 0)
            {
                AABBMin = Vector3.Zero;
                AABBMax = Vector3.Zero;
            }
            else
            {
                AABBMin = Vertices[0].Position;
                AABBMax = Vertices[0].Position;
            }

            // Update the AABB
            float minx = AABBMin.X;
            float miny = AABBMin.Y;
            float minz = AABBMin.Z;
            float maxx = AABBMax.X;
            float maxy = AABBMax.Y;
            float maxz = AABBMax.Z;

            foreach (Vertex v in Vertices)
            {
                minx = v.Position.X < minx ? v.Position.X : minx;
                miny = v.Position.Y < miny ? v.Position.Y : miny;
                minz = v.Position.Z < minz ? v.Position.Z : minz;
                maxx = v.Position.X > maxx ? v.Position.X : maxx;
                maxy = v.Position.Y > maxy ? v.Position.Y : maxy;
                maxz = v.Position.Z > maxz ? v.Position.Z : maxz;
            }
            AABBMin = new Vector3(minx, miny, minz);
            AABBMax = new Vector3(maxx, maxy, maxz);

            // Build the list of floats for the vertex buffer
            List <float> vertexdata = new List <float>();

            foreach (Vertex v in Vertices)
            {
                foreach (float f in v.ToFloats())
                {
                    vertexdata.Add(f);
                }
            }

            // Create and populate the vertex and index buffers
            VertexBuffer = SharpDX.Direct3D11.Buffer.Create <float>(Device, BindFlags.VertexBuffer, vertexdata.ToArray());
            IndexBuffer  = SharpDX.Direct3D11.Buffer.Create <Triangle>(Device, BindFlags.IndexBuffer, Triangles.ToArray());
        }
コード例 #22
0
        public void Reset()
        {
            VertBuffer?.Dispose();
            IndBuffer?.Dispose();
            VertBuffer = null;
            IndBuffer  = null;

            Vertices.Clear();
            Indices.Clear();
        }
コード例 #23
0
 /// <summary>
 ///     Frees resources used by this object.
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     VertexBuffer?.Dispose();
     IndexBuffer?.Dispose();
     Effect?.Dispose();
 }
コード例 #24
0
ファイル: GeometricPrimitive.cs プロジェクト: dobrybajer/GK3D
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _vertexBuffer?.Dispose();

            _indexBuffer?.Dispose();
        }
コード例 #25
0
        /// <summary>
        /// Release the memory from the VRAM.
        /// </summary>
        public void ReleaseMemory()
        {
            StagingBuffer?.Dispose();
            StagingBuffer = null;

            IndexBuffer?.Dispose();
            IndexBuffer = null;

            StagingVRAM?.Free();
            VertexVRAM?.Free();
        }
コード例 #26
0
ファイル: FSOF.cs プロジェクト: terrynoya/FreeSO
 public void Dispose()
 {
     FloorTexture?.Dispose();
     WallTexture?.Dispose();
     NightFloorTexture?.Dispose();
     NightWallTexture?.Dispose();
     FloorVGPU?.Dispose();
     FloorIGPU?.Dispose();
     WallVGPU?.Dispose();
     WallIGPU?.Dispose();
 }
コード例 #27
0
ファイル: DGRP3DGeometry.cs プロジェクト: jmonroe5/FreeSO
        public void SComplete(GraphicsDevice gd)
        {
            Rendered = true;
            Verts?.Dispose();
            Indices?.Dispose();

            PrimCount = SIndices.Count / 3;
            if (PrimCount > 0)
            {
                Verts = new VertexBuffer(gd, typeof(DGRP3DVert), SVerts.Count, BufferUsage.None);
                Verts.SetData(SVerts.ToArray());
                Indices = new IndexBuffer(gd, IndexElementSize.ThirtyTwoBits, SIndices.Count, BufferUsage.None);
                Indices.SetData(SIndices.ToArray());
            }

            if (!IffFile.RETAIN_CHUNK_DATA)
            {
                SVerts   = null;
                SIndices = null;
            }
        }
コード例 #28
0
 void IDisposable.Dispose()
 {
     effectInstance?.Dispose(); effectInstance = null;
     if (linesBuffer != indexLinesBuffer && linesBuffer != indexPointsBuffer)
     {
         linesBuffer?.Dispose();
     }
     linesBuffer = null; linesCount = 0;
     triangleBuffer?.Dispose(); triangleBuffer = null; triangleCount = 0;
     vertexFormat?.Dispose();   vertexFormat   = null;
     vertexBuffer?.Dispose();   vertexBuffer   = null; vertexCount = 0;
 }
コード例 #29
0
 /// <inheritdoc/>
 protected override void OnDispose()
 {
     try
     {
         _vb?.Dispose();
         _ib?.Dispose();
     }
     finally
     {
         base.OnDispose();
     }
 }
コード例 #30
0
ファイル: ImGuiRenderer.cs プロジェクト: alanmbennett/Diez
		unsafe void UpdateBuffers(ImDrawDataPtr drawData)
		{
			if (drawData.TotalVtxCount == 0)
			{
				return;
			}

			// Expand buffers if we need more room
			if (drawData.TotalVtxCount > _vertexBufferSize)
			{
				_vertexBuffer?.Dispose();

				_vertexBufferSize = (int) (drawData.TotalVtxCount * 1.5f);
				_vertexBuffer = new VertexBuffer(Core.GraphicsDevice, _vertexDeclaration, _vertexBufferSize,
					BufferUsage.None);
				_vertexData = new byte[_vertexBufferSize * _vertexDeclarationSize];
			}

			if (drawData.TotalIdxCount > _indexBufferSize)
			{
				_indexBuffer?.Dispose();

				_indexBufferSize = (int) (drawData.TotalIdxCount * 1.5f);
				_indexBuffer = new IndexBuffer(Core.GraphicsDevice, IndexElementSize.SixteenBits, _indexBufferSize,
					BufferUsage.None);
				_indexData = new byte[_indexBufferSize * sizeof(ushort)];
			}

			// Copy ImGui's vertices and indices to a set of managed byte arrays
			int vtxOffset = 0;
			int idxOffset = 0;

			for (var n = 0; n < drawData.CmdListsCount; n++)
			{
				var cmdList = drawData.CmdListsRange[n];

				fixed (void* vtxDstPtr = &_vertexData[vtxOffset * _vertexDeclarationSize])
				fixed (void* idxDstPtr = &_indexData[idxOffset * sizeof(ushort)])
				{
					Buffer.MemoryCopy((void*) cmdList.VtxBuffer.Data, vtxDstPtr, _vertexData.Length,
						cmdList.VtxBuffer.Size * _vertexDeclarationSize);
					Buffer.MemoryCopy((void*) cmdList.IdxBuffer.Data, idxDstPtr, _indexData.Length,
						cmdList.IdxBuffer.Size * sizeof(ushort));
				}

				vtxOffset += cmdList.VtxBuffer.Size;
				idxOffset += cmdList.IdxBuffer.Size;
			}

			// Copy the managed byte arrays to the gpu vertex- and index buffers
			_vertexBuffer.SetData(_vertexData, 0, drawData.TotalVtxCount * _vertexDeclarationSize);
			_indexBuffer.SetData(_indexData, 0, drawData.TotalIdxCount * sizeof(ushort));
		}
コード例 #31
0
ファイル: Mesh.cs プロジェクト: nohbdy/ffxivmodelviewer
        public IndexBuffer ExtractSubset(Device device, short[] triList)
        {
            int numTris = triList.Length;
            IndexBuffer result = null;
            try
            {
                result = new IndexBuffer(device, numTris * 6, Usage.WriteOnly, Pool.Managed, true);
                try
                {
                    var str = result.Lock(0, 0, LockFlags.None);
                    for (var i = 0; i < numTris; i++)
                    {
                        int triNum = triList[i];
                        int offset = triNum * 3;

                        str.Write(this.indices[offset]);
                        str.Write(this.indices[offset+1]);
                        str.Write(this.indices[offset+2]);

                        if (!used[triNum])
                        {
                            used[triNum] = true;
                            UsedCount += 3; // 3 indices used
                        }
                    }
                }
                finally
                {
                    result.Unlock();
                }
                return result;
            }
            catch
            {
                if (result != null) { result.Dispose(); }
                throw;
            }
        }
コード例 #32
0
        private void Rebuild(string fIn, string fOut)
        {
            // Check Args
            FileInfo fiIn = new FileInfo(fIn);
            if(!fiIn.Exists) {
                Console.WriteLine("File Does Not Exist");
                return;
            }
            FileInfo fiOut = new FileInfo(fOut);
            if(!fiOut.Directory.Exists) {
                Console.WriteLine("Output Directory Does Not Exist");
                return;
            }

            // Read Model
            Stream s = File.OpenRead(fiIn.FullName);
            VertexPositionNormalTexture[] verts;
            int[] inds;
            if(!ObjParser.TryParse(s, out verts, out inds, ParsingFlags.ConversionOpenGL)) {
                s.Dispose();
                Console.WriteLine("Could Not Read Model");
                return;
            }
            s.Dispose();

            // Compute The AABB Of The Terrain
            BoundingBox aabb = ComputeAABB(verts);
            Vector3 mid = aabb.Max + aabb.Min;
            Vector3 dif = aabb.Max - aabb.Min;
            Vector3 top = new Vector3(mid.X, aabb.Max.Y, mid.Z);
            mid *= 0.5f;
            fx.FogStart = 1f;
            fx.FogEnd = aabb.Max.Y - aabb.Min.Y + 1f;
            fx.World = Matrix.Identity;
            fx.View = Matrix.CreateLookAt(top + Vector3.UnitY, mid, -Vector3.UnitZ);
            fx.Projection = Matrix.CreateOrthographic(dif.X, dif.Z, 0, dif.Y + 2f);

            // Append A Plane At The Bottom
            int vc = verts.Length, ic = inds.Length;
            Array.Resize(ref verts, verts.Length + 4);
            Array.Resize(ref inds, inds.Length + 6);
            inds[ic++] = vc + 0;
            inds[ic++] = vc + 1;
            inds[ic++] = vc + 2;
            inds[ic++] = vc + 2;
            inds[ic++] = vc + 1;
            inds[ic++] = vc + 3;
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Min.X, aabb.Min.Y, aabb.Min.Z),
                Vector3.UnitY, Vector2.Zero
                );
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Max.X, aabb.Min.Y, aabb.Min.Z),
                Vector3.UnitY, Vector2.UnitX
                );
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Min.X, aabb.Min.Y, aabb.Max.Z),
                Vector3.UnitY, Vector2.UnitY
                );
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Max.X, aabb.Min.Y, aabb.Max.Z),
                Vector3.UnitY, Vector2.One
                );

            // Create Model
            VertexBuffer vb = new VertexBuffer(G, VertexPositionNormalTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            IndexBuffer ib = new IndexBuffer(G, IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);

            // Render The Height
            if(rtHeight != null)
                rtHeight.Dispose();
            rtHeight = new RenderTarget2D(G, 4096, 4096, false, SurfaceFormat.Color, DepthFormat.Depth24);
            G.SetRenderTarget(rtHeight);
            G.SetVertexBuffer(vb);
            G.Indices = ib;
            fx.CurrentTechnique.Passes[0].Apply();
            G.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vb.VertexCount, 0, ib.IndexCount / 3);

            // Dispose Of Buffers
            G.SetRenderTarget(null);
            G.Clear(Color.Black);
            G.SetVertexBuffer(null);
            G.Indices = null;
            vb.Dispose();
            ib.Dispose();

            // Save The Image
            using(Stream os = File.Create(fiOut.FullName)) {
                rtHeight.SaveAsPng(os, rtHeight.Width, rtHeight.Height);
            }

            ShouldRebuild = false;
        }
コード例 #33
0
ファイル: ToothChartDirectX.cs プロジェクト: mnisl/OD
		private void DrawFurcationTriangle(float tipx,float tipy,bool pointUp,Matrix lineMat,int furcationValue) {
			const float triSideLenMM=2f;
			float sign=pointUp?1:-1;
			Color color=GetFurcationColor(furcationValue);
			List<Vector3> triPoints=new List<Vector3>();
			//We form an equilateral triangle.
			triPoints.Add(new Vector3(tipx+triSideLenMM/2f,tipy+sign*((float)(triSideLenMM*Math.Sqrt(3)/2f)),0));
			triPoints.Add(new Vector3(tipx,tipy,0));
			triPoints.Add(new Vector3(tipx-triSideLenMM/2f,tipy+sign*((float)(triSideLenMM*Math.Sqrt(3)/2f)),0));
			if(furcationValue==1) {
				DrawExtended3dLine(new Vector3[] { triPoints[0],triPoints[1],triPoints[2] },0.1f,false,color,2f,lineMat);
			} else if(furcationValue==2) {
				DrawExtended3dLine(new Vector3[] { triPoints[0],triPoints[1],triPoints[2],triPoints[0] },0.1f,true,color,2f,lineMat);
			} else if(furcationValue==3) {
				DrawExtended3dLine(new Vector3[] { triPoints[0],triPoints[1],triPoints[2],triPoints[0] },0.1f,true,color,2f,lineMat);
				VertexBuffer triVb=null;
				IndexBuffer triIb=null;
				try{
					CustomVertex.PositionColored[] solidTriVerts=new CustomVertex.PositionColored[] {
									new CustomVertex.PositionColored(triPoints[0],color.ToArgb()),
									new CustomVertex.PositionColored(triPoints[1],color.ToArgb()),
									new CustomVertex.PositionColored(triPoints[2],color.ToArgb()),
								};
					triVb=new VertexBuffer(typeof(CustomVertex.PositionColored),
						CustomVertex.PositionColored.StrideSize*solidTriVerts.Length,
						device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
					triVb.SetData(solidTriVerts,0,LockFlags.None);
					int[] triIndicies=new int[] { 0,1,2 };
					triIb=new IndexBuffer(typeof(int),triIndicies.Length,device,Usage.None,Pool.Managed);
					triIb.SetData(triIndicies,0,LockFlags.None);
					device.VertexFormat=CustomVertex.PositionColored.Format;
					device.SetStreamSource(0,triVb,0);
					device.Indices=triIb;
					device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,solidTriVerts.Length,0,triIndicies.Length/3);
				}finally{
					if(triVb!=null){
						triVb.Dispose();
						triVb=null;
					}
					if(triIb!=null){
						triIb.Dispose();
					}
				}
			} else {
				//invalid value. assume no furcation.
			}
		}
コード例 #34
0
ファイル: DisposeHelper.cs プロジェクト: kiichi7/XnaTetris
 /// <summary>
 /// Dispose
 /// </summary>
 /// <param name="someObject">Some object</param>
 public static void Dispose(ref IndexBuffer someObject)
 {
     if (someObject != null)
         someObject.Dispose();
     someObject = null;
 }
コード例 #35
0
ファイル: QuadTree.cs プロジェクト: jwvdiermen/LD28
        private void CollectGeometry(bool enabled, ref VertexBuffer vertexBuffer, ref IndexBuffer indexBuffer)
        {
            // Clear the buffers first.
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                vertexBuffer = null;
            }
            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                indexBuffer = null;
            }

            // Collect the vertices and indices.
            var vertices = new List<Vector2>();
            var indices = new List<ushort>();

            Root.CollectGeometry(vertices, indices, enabled);

            // Create the hardware resources.
            if (vertices.Count > 0 && indices.Count > 0)
            {
                vertexBuffer = new VertexBuffer(_graphics, VertexPositionColorTexture.VertexDeclaration, vertices.Count, BufferUsage.None);
                vertexBuffer.SetData(vertices.Select(e => new VertexPositionColorTexture
                {
                    Position = new Vector3(e, 0.0f),
                    Color = Color.White,
                    TextureCoordinate = e / _size

                }).ToArray());

                indexBuffer = new IndexBuffer(_graphics, IndexElementSize.SixteenBits, indices.Count, BufferUsage.None);
                indexBuffer.SetData(indices.ToArray());
            }
        }
コード例 #36
0
ファイル: ToothChartDirectX.cs プロジェクト: mnisl/OD
		public static void DrawColoredRectangle(Device dev,RectangleF rect,Color color){
			VertexBuffer vb=null;
			IndexBuffer ib=null;
			try{
				int colorArgb=color.ToArgb();
				CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
						new CustomVertex.PositionColored(rect.Left,rect.Bottom,0,colorArgb),
						new CustomVertex.PositionColored(rect.Left,rect.Top,0,colorArgb),
						new CustomVertex.PositionColored(rect.Right,rect.Top,0,colorArgb),
						new CustomVertex.PositionColored(rect.Right,rect.Bottom,0,colorArgb),
					};
				vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
					CustomVertex.PositionColored.StrideSize*quadVerts.Length,
					dev,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
				vb.SetData(quadVerts,0,LockFlags.None);
				int[] indicies=new int[] { 0,1,2,0,2,3 };
				ib=new IndexBuffer(typeof(int),indicies.Length,dev,Usage.None,Pool.Managed);
				ib.SetData(indicies,0,LockFlags.None);
				dev.VertexFormat=CustomVertex.PositionColored.Format;
				dev.SetStreamSource(0,vb,0);
				dev.Indices=ib;
				dev.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
			}finally{
				if(vb!=null){
					vb.Dispose();
					vb=null;
				}
				if(ib!=null){
					ib.Dispose();
					ib=null;
				}
			}
		}
コード例 #37
0
ファイル: ToothChartDirectX.cs プロジェクト: mnisl/OD
		private void DrawDroplet(float x,float y,Color dropletColor){
			int dropletColorArgb=dropletColor.ToArgb();
			List<PointF> dropletVertsP=TcData.GetDropletVertices();
			List<CustomVertex.PositionColored> dropletVertsV=new List<CustomVertex.PositionColored>();
			for(int p=0;p<dropletVertsP.Count;p++) {
				dropletVertsV.Add(new CustomVertex.PositionColored(
					x+dropletVertsP[p].X,y+dropletVertsP[p].Y,0,dropletColorArgb));
			}
			//This point is implied and is the last point.
			dropletVertsV.Add(new CustomVertex.PositionColored(x,y,0,dropletColorArgb));
			VertexBuffer vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
				CustomVertex.PositionColored.StrideSize*dropletVertsV.Count,
				device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
			vb.SetData(dropletVertsV.ToArray(),0,LockFlags.None);
			List<int> indiciesL=new List<int>();
			for(int v=0;v<dropletVertsV.Count-2;v++) {
				indiciesL.Add(0);
				indiciesL.Add(v+1);
				indiciesL.Add(v+2);
			}
			int[] indicies=indiciesL.ToArray();
			IndexBuffer ib=new IndexBuffer(typeof(int),indicies.Length,device,Usage.None,Pool.Managed);
			ib.SetData(indicies,0,LockFlags.None);
			device.VertexFormat=CustomVertex.PositionColored.Format;
			device.SetStreamSource(0,vb,0);
			device.Indices=ib;
			device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,dropletVertsV.Count,0,indicies.Length/3);
			ib.Dispose();
			vb.Dispose();
		}
コード例 #38
0
ファイル: Mesh.cs プロジェクト: nohbdy/ffxivmodelviewer
        public IndexBuffer BuildRemainder(Device device)
        {
            if (UsedCount == indices.Length) { return null; }

            int numIndices = indices.Length - UsedCount;
            IndexBuffer result = null;
            try
            {
                result = new IndexBuffer(device, numIndices * 2, Usage.WriteOnly, Pool.Managed, true);

                try
                {
                    var str = result.Lock(0, 0, LockFlags.None);
                    int numTris = used.Length;
                    for (var i = 0; i < numTris; i++)
                    {
                        if (used[i]) { continue; }

                        int offset = i * 3;

                        str.Write(this.indices[offset]);
                        str.Write(this.indices[offset + 1]);
                        str.Write(this.indices[offset + 2]);
                    }
                }
                finally
                {
                    result.Unlock();
                }
                return result;
            }
            catch
            {
                if (result != null) { result.Dispose(); }
                throw;
            }
        }
コード例 #39
0
ファイル: ToothChartDirectX.cs プロジェクト: mnisl/OD
		///<summary>Draws the number and the small rectangle behind it.  Draws in the appropriate color.  isFullRedraw means that all of the toothnumbers are being redrawn.  This helps with a few optimizations and with not painting blank rectangles when not needed.</summary>
		private void DrawNumber(string tooth_id,bool isSelected,float offsetY) {
			if(!Tooth.IsValidDB(tooth_id)) {
				return;
			}
			if(TcData.ListToothGraphics[tooth_id].HideNumber) {//if this is a "hidden" number
				return;//skip
			}
			//primary, but not set to show primary letters
			if(Tooth.IsPrimary(tooth_id) && !TcData.ListToothGraphics[Tooth.PriToPerm(tooth_id)].ShowPrimaryLetter){
				return;
			}
			device.RenderState.Lighting=false;
			device.RenderState.ZBufferEnable=false;
			device.Transform.World=Matrix.Identity;
			string displayNum=Tooth.GetToothLabelGraphic(tooth_id,TcData.ToothNumberingNomenclature);
			SizeF labelSize=MeasureStringMm(displayNum);
			RectangleF recMm=TcData.GetNumberRecMm(tooth_id,labelSize);
			recMm.Y+=offsetY;
			Color foreColor=TcData.ColorText;
			if(isSelected) {
				foreColor=TcData.ColorTextHighlight;
				//Draw the background rectangle only if the text is selected.
				int backColorARGB=TcData.ColorBackHighlight.ToArgb();
				CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
			    new CustomVertex.PositionColored(recMm.X,recMm.Y,0,backColorARGB),//LL
			    new CustomVertex.PositionColored(recMm.X,recMm.Y+recMm.Height,0,backColorARGB),//UL
			    new CustomVertex.PositionColored(recMm.X+recMm.Width,recMm.Y+recMm.Height,0,backColorARGB),//UR
			    new CustomVertex.PositionColored(recMm.X+recMm.Width,recMm.Y,0,backColorARGB),//LR
			  };
				VertexBuffer vb=new VertexBuffer(typeof(CustomVertex.PositionColored),CustomVertex.PositionColored.StrideSize*quadVerts.Length,
					device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
				vb.SetData(quadVerts,0,LockFlags.None);
				int[] indicies=new int[] { 0,1,2,0,2,3 };
				IndexBuffer ib=new IndexBuffer(typeof(int),indicies.Length,device,Usage.None,Pool.Managed);
				ib.SetData(indicies,0,LockFlags.None);
				device.VertexFormat=CustomVertex.PositionColored.Format;
				device.SetStreamSource(0,vb,0);
				device.Indices=ib;
				device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
				ib.Dispose();
				vb.Dispose();
			}
			//Offsets the text by 10% of the rectangle width to ensure that there is at least on pixel of space on
			//the left for the background rectangle.
			PrintString(displayNum,recMm.X+recMm.Width*0.1f,recMm.Y+recMm.Height,0,foreColor,xfont);
		}
コード例 #40
0
ファイル: ToothChartDirectX.cs プロジェクト: mnisl/OD
		private void DrawProbingBar(int intTooth,PerioSurf perioSurf){
			const float barWidthMM=0.6f;
			Color colorBar;
			LineSimple barPoints=TcData.GetProbingLine(intTooth,perioSurf,out colorBar);
			if(barPoints==null){
				return;
			}
			CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X-barWidthMM/2f,barPoints.Vertices[0].Y,0,colorBar.ToArgb()),
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X-barWidthMM/2f,barPoints.Vertices[1].Y,0,colorBar.ToArgb()),
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X+barWidthMM/2f,barPoints.Vertices[1].Y,0,colorBar.ToArgb()),
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X+barWidthMM/2f,barPoints.Vertices[0].Y,0,colorBar.ToArgb()),
			  };
			VertexBuffer vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
				CustomVertex.PositionColored.StrideSize*quadVerts.Length,
			  device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
			vb.SetData(quadVerts,0,LockFlags.None);
			int[] indicies=new int[] { 0,1,2,0,2,3 };
			IndexBuffer ib=new IndexBuffer(typeof(int),indicies.Length,device,Usage.None,Pool.Managed);
			ib.SetData(indicies,0,LockFlags.None);
			device.VertexFormat=CustomVertex.PositionColored.Format;
			device.SetStreamSource(0,vb,0);
			device.Indices=ib;
			device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
			ib.Dispose();
			vb.Dispose();
		}