public void ContentLostResources() { // https://blogs.msdn.microsoft.com/shawnhar/2007/12/12/virtualizing-the-graphicsdevice-in-xna-game-studio-2-0/ var rt = new RenderTarget2D(gdm.GraphicsDevice, 5, 5); var vb = new DynamicVertexBuffer(gd, VertexPositionColor.VertexDeclaration, 1, BufferUsage.None); var ib = new DynamicIndexBuffer(gd, IndexElementSize.SixteenBits, 1, BufferUsage.None); var rtc = new RenderTargetCube(gd, 1, false, SurfaceFormat.Color, DepthFormat.Depth16); gd.Reset(); Assert.IsTrue(rt.IsContentLost); Assert.IsFalse(rt.IsDisposed); Assert.IsTrue(vb.IsContentLost); Assert.IsFalse(vb.IsDisposed); Assert.IsTrue(ib.IsContentLost); Assert.IsFalse(ib.IsDisposed); Assert.IsTrue(rtc.IsContentLost); Assert.IsFalse(rtc.IsDisposed); rt.Dispose(); vb.Dispose(); ib.Dispose(); rtc.Dispose(); }
/// <summary> /// Resets the vertex buffer object from the verticies. /// <param Name="device">GPU to draw with.</param></summary> public virtual void ResetBuffer(GraphicsDevice device) { //if(DwarfGame.ExitGame) //{ // return; //} //lock (VertexLock) { if (VertexBuffer != null && !VertexBuffer.IsDisposed) { VertexBuffer.Dispose(); } VertexBuffer = null; if (IndexBuffer != null && !IndexBuffer.IsDisposed) { IndexBuffer.Dispose(); } IndexBuffer = null; if (IndexCount <= 0 && Indexes != null) { IndexCount = Indexes.Length; } if (VertexCount <= 0 && Vertices != null) { VertexCount = Vertices.Length; } if (Vertices != null) { try { VertexBuffer = new DynamicVertexBuffer(device, ExtendedVertex.VertexDeclaration, Vertices.Length, BufferUsage.WriteOnly); VertexBuffer.SetData(Vertices, 0, VertexCount); } catch (Exception exception) { Console.Out.WriteLine(exception.ToString()); VertexBuffer = null; } } if (Indexes != null) { try { IndexBuffer = new DynamicIndexBuffer(device, typeof(ushort), Indexes.Length, BufferUsage.None); IndexBuffer.SetData(Indexes, 0, IndexCount); } catch (Exception exception) { Console.Out.WriteLine(exception.ToString()); IndexBuffer = null; } } } }
public static void LoadContent() { _iboQuad = new DynamicIndexBuffer(Device, IndexElementSize.SixteenBits, MAX_QUADS * 6, BufferUsage.WriteOnly); _iboQuad.SetData(QuadIndices, 0, MAX_QUADS * 6); _iboFan = new DynamicIndexBuffer(Device, IndexElementSize.SixteenBits, MAX_QUADS * 3, BufferUsage.WriteOnly); _iboFan.SetData(FanIndices, 0, MAX_QUADS * 3); }
private void Allocate() { if (this._vertexBuffer == null || this._vertexBuffer.IsDisposed) { this._vertexBuffer = new DynamicVertexBuffer(this._graphicsDevice, typeof(VertexPositionColorTexture), 8192, BufferUsage.WriteOnly); this._vertexBufferPosition = 0; this._vertexBuffer.ContentLost += (EventHandler <EventArgs>)((_param1, _param2) => this._vertexBufferPosition = 0); } if (this._indexBuffer != null && !this._indexBuffer.IsDisposed) { return; } if (this._fallbackIndexData == null) { this._fallbackIndexData = new short[12288]; for (int index = 0; index < 2048; ++index) { this._fallbackIndexData[index * 6] = (short)(index * 4); this._fallbackIndexData[index * 6 + 1] = (short)(index * 4 + 1); this._fallbackIndexData[index * 6 + 2] = (short)(index * 4 + 2); this._fallbackIndexData[index * 6 + 3] = (short)(index * 4); this._fallbackIndexData[index * 6 + 4] = (short)(index * 4 + 2); this._fallbackIndexData[index * 6 + 5] = (short)(index * 4 + 3); } } this._indexBuffer = new DynamicIndexBuffer(this._graphicsDevice, typeof(short), 12288, BufferUsage.WriteOnly); this._indexBuffer.SetData <short>(this._fallbackIndexData); this._indexBuffer.ContentLost += (EventHandler <EventArgs>)((_param1, _param2) => this._indexBuffer.SetData <short>(this._fallbackIndexData)); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). } if (IndexBuffer != null) { IndexBuffer.Dispose(); } IndexBuffer = null; if (VertexBuffer != null) { VertexBuffer.Dispose(); } VertexBuffer = null; Vertices = null; Indexes = null; disposedValue = true; } }
private void Allocate() { if (vertexBuffer == null || vertexBuffer.IsDisposed) { vertexBuffer = new DynamicVertexBuffer(graphicsDevice, typeof(VertexPositionColorTexture), 8192, BufferUsage.WriteOnly); vertexBufferPosition = 0; vertexBuffer.ContentLost += delegate { vertexBufferPosition = 0; }; } if (indexBuffer != null && !indexBuffer.IsDisposed) { return; } if (fallbackIndexData == null) { fallbackIndexData = new short[12288]; for (int i = 0; i < 2048; i++) { fallbackIndexData[i * 6] = (short)(i * 4); fallbackIndexData[i * 6 + 1] = (short)(i * 4 + 1); fallbackIndexData[i * 6 + 2] = (short)(i * 4 + 2); fallbackIndexData[i * 6 + 3] = (short)(i * 4); fallbackIndexData[i * 6 + 4] = (short)(i * 4 + 2); fallbackIndexData[i * 6 + 5] = (short)(i * 4 + 3); } } indexBuffer = new DynamicIndexBuffer(graphicsDevice, typeof(short), 12288, BufferUsage.WriteOnly); indexBuffer.SetData(fallbackIndexData); indexBuffer.ContentLost += delegate { indexBuffer.SetData(fallbackIndexData); }; }
private void Allocate() { if (this._vertexBuffer == null || ((GraphicsResource)this._vertexBuffer).get_IsDisposed()) { this._vertexBuffer = new DynamicVertexBuffer(this._graphicsDevice, typeof(VertexPositionColorTexture), 8192, (BufferUsage)1); this._vertexBufferPosition = 0; this._vertexBuffer.add_ContentLost((EventHandler <EventArgs>)((sender, e) => this._vertexBufferPosition = 0)); } if (this._indexBuffer != null && !((GraphicsResource)this._indexBuffer).get_IsDisposed()) { return; } if (this._fallbackIndexData == null) { this._fallbackIndexData = new short[12288]; for (int index = 0; index < 2048; ++index) { this._fallbackIndexData[index * 6] = (short)(index * 4); this._fallbackIndexData[index * 6 + 1] = (short)(index * 4 + 1); this._fallbackIndexData[index * 6 + 2] = (short)(index * 4 + 2); this._fallbackIndexData[index * 6 + 3] = (short)(index * 4); this._fallbackIndexData[index * 6 + 4] = (short)(index * 4 + 2); this._fallbackIndexData[index * 6 + 5] = (short)(index * 4 + 3); } } this._indexBuffer = new DynamicIndexBuffer(this._graphicsDevice, typeof(short), 12288, (BufferUsage)1); ((IndexBuffer)this._indexBuffer).SetData <short>((M0[])this._fallbackIndexData); this._indexBuffer.add_ContentLost((EventHandler <EventArgs>)((sender, e) => ((IndexBuffer)this._indexBuffer).SetData <short>((M0[])this._fallbackIndexData))); }
public Primitives(GraphicsDevice device, int maxVertices, int maxIndices) { this.device = device; vertexBuffer = new DynamicVertexBuffer(device, typeof(VertexPositionColorTexture), maxVertices, BufferUsage.None); indexBuffer = new DynamicIndexBuffer(device, IndexElementSize.SixteenBits, maxIndices, BufferUsage.None); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { OrientationSensor = OrientationSensor.GetDefault(); if (OrientationSensor == null) { SimpleOrientationSensor = SimpleOrientationSensor.GetDefault(); if (SimpleOrientationSensor == null) { throw new Exception("No way of determining orientation"); } } TouchPanel.EnabledGestures = GestureType.Hold | GestureType.Flick | GestureType.HorizontalDrag | GestureType.VerticalDrag | GestureType.DragComplete; vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly); indexBuffer = new DynamicIndexBuffer(graphics.GraphicsDevice, typeof(ushort), 36, BufferUsage.WriteOnly); basicEffect = new BasicEffect(graphics.GraphicsDevice); //(device, null); basicEffect.LightingEnabled = false; basicEffect.VertexColorEnabled = true; basicEffect.TextureEnabled = false; DepthStencilState depthBufferState = new DepthStencilState(); depthBufferState.DepthBufferEnable = true; GraphicsDevice.DepthStencilState = depthBufferState; TetrisState.Initialize(graphics.GraphicsDevice); Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SuppressSystemOverlays = true; graphics.SupportedOrientations = DisplayOrientation.Portrait; base.Initialize(); }
/// <summary> /// Build the mesh used to draw all trails /// </summary> private void BuildMesh() { if (this.mesh != null) { this.DestroyMesh(); } // Indices this.indices = new ushort[this.nIndices]; DynamicIndexBuffer indexBuffer = new DynamicIndexBuffer(this.indices); this.RenderManager.GraphicsDevice.BindIndexBuffer(indexBuffer); // Vertices this.vertices = new VertexPositionColorTexture[this.nVertices]; DynamicVertexBuffer vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat); vertexBuffer.SetData(this.vertices); this.GraphicsDevice.BindVertexBuffer(vertexBuffer); this.mesh = new Mesh(0, nVertices, 0, nIndices / 3, vertexBuffer, indexBuffer, PrimitiveType.TriangleStrip) { DisableBatch = true }; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here zNear = 0.001f; zFar = 1000.0f; fov = MathHelper.Pi * 70.0f / 180.0f; eye = new Vector3(0.0f, 0.7f, 1.5f); at = new Vector3(0.0f, 0.0f, 0.0f); up = new Vector3(0.0f, 1.0f, 0.0f); cube = new VertexPositionColor[8]; cube[0] = new VertexPositionColor(new Vector3(-0.5f, -0.5f, -0.5f), new Color(0.0f, 0.0f, 0.0f)); cube[1] = new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0.5f), new Color(0.0f, 0.0f, 1.0f)); cube[2] = new VertexPositionColor(new Vector3(-0.5f, 0.5f, -0.5f), new Color(0.0f, 1.0f, 0.0f)); cube[3] = new VertexPositionColor(new Vector3(-0.5f, 0.5f, 0.5f), new Color(0.0f, 1.0f, 1.0f)); cube[4] = new VertexPositionColor(new Vector3(0.5f, -0.5f, -0.5f), new Color(1.0f, 0.0f, 0.0f)); cube[5] = new VertexPositionColor(new Vector3(0.5f, -0.5f, 0.5f), new Color(1.0f, 0.0f, 1.0f)); cube[6] = new VertexPositionColor(new Vector3(0.5f, 0.5f, -0.5f), new Color(1.0f, 1.0f, 0.0f)); cube[7] = new VertexPositionColor(new Vector3(0.5f, 0.5f, 0.5f), new Color(1.0f, 1.0f, 1.0f)); vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly); indexBuffer = new DynamicIndexBuffer(graphics.GraphicsDevice, typeof(ushort), 36, BufferUsage.WriteOnly); basicEffect = new BasicEffect(graphics.GraphicsDevice); //(device, null); basicEffect.LightingEnabled = false; basicEffect.VertexColorEnabled = true; basicEffect.TextureEnabled = false; graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; base.Initialize(); }
private void SetUpBuffers() { v_buffer = new DynamicVertexBuffer(Game.device, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); i_buffer = new DynamicIndexBuffer(Game.device, typeof(int), indices.Length, BufferUsage.WriteOnly); v_buffer.SetData(vertices); i_buffer.SetData(indices); }
public void Allocate() { Vertices = new DynamicVertexBuffer(GraphicsDevice, typeof(TVertex), VertexCount, BufferUsage.WriteOnly); Interlocked.Add(ref RenderManager.TotalVertexBytes, System.Runtime.InteropServices.Marshal.SizeOf(typeof(TVertex)) * VertexCount); Indices = new DynamicIndexBuffer(GraphicsDevice, IndexElementSize.SixteenBits, IndexCount, BufferUsage.WriteOnly); Interlocked.Add(ref RenderManager.TotalIndexBytes, 2 * IndexCount); IsAllocated = true; }
// ------------------------------------------------------------------- // Constructor // ------------------------------------------------------------------- public Square(GraphicsDevice device, Texture2D texture, int[] coordsTexture) { // Init buffers VB = new DynamicVertexBuffer(device, typeof(VertexPositionTexture), 4, BufferUsage.WriteOnly); IB = new DynamicIndexBuffer(device, IndexElementSize.ThirtyTwoBits, 6, BufferUsage.WriteOnly); // Create texture CreateTex(coordsTexture, texture); }
/// <summary> /// Constructor of the <c>OcTree</c> class. /// </summary> /// <param name="layerName">Name of the layer.</param> public OcTree(string layerName) { _name = layerName; _cubeVertexBuffer = new DynamicVertexBuffer(EngineManager.GameGraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly); _cubeIndexBuffer = new DynamicIndexBuffer(EngineManager.GameGraphicsDevice, typeof(short), 24, BufferUsage.WriteOnly); }
protected override void CreateNative() { nativeDevice = (device as XnaDevice).NativeDevice; nativeVertexBuffer = new DynamicVertexBuffer(nativeDevice, (shader as XnaShader).XnaVertexDeclaration, maxNumberOfVertices, BufferUsage.WriteOnly); nativeIndexBuffer = new DynamicIndexBuffer(nativeDevice, IndexElementSize.SixteenBits, maxNumberOfIndices, BufferUsage.WriteOnly); currentDataHint = SetDataOptions.Discard; }
/// <summary> /// Main line drawer constructor. /// </summary> /// <param name="graphicsDevice">Graphics device for rendering.</param> public LineDrawer(GraphicsDevice graphicsDevice) { _vertexBuffer = new DynamicVertexBuffer(graphicsDevice, typeof(VertexPositionColor), MAX_VERTS, BufferUsage.WriteOnly); _indexBuffer = new DynamicIndexBuffer(graphicsDevice, typeof(ushort), MAX_INDICES, BufferUsage.WriteOnly); _basicEffect = new BasicEffect(graphicsDevice); _basicEffect.LightingEnabled = false; _basicEffect.VertexColorEnabled = true; _basicEffect.TextureEnabled = false; }
public DebugDraw(GraphicsDevice device) { vertexBuffer = new DynamicVertexBuffer(device, typeof(VertexPositionColor), MAX_VERTS, BufferUsage.WriteOnly); indexBuffer = new DynamicIndexBuffer(device, typeof(ushort), MAX_INDICES, BufferUsage.WriteOnly); basicEffect = new BasicEffect(device); //(device, null); basicEffect.LightingEnabled = false; basicEffect.VertexColorEnabled = true; basicEffect.TextureEnabled = false; }
private void CreateBuffers() { var vertexDeclaration = new VertexDeclaration(Format.Stride, nativeVertexFormat.ConvertFrom(Format)); vertexBuffer = new DynamicVertexBuffer(nativeDevice, vertexDeclaration, NumberOfVertices, BufferUsage.WriteOnly); indexBuffer = new DynamicIndexBuffer(nativeDevice, IndexElementSize.SixteenBits, NumberOfIndices, BufferUsage.WriteOnly); }
static DrawAnimateWater() { indices = new short[6]; IndexBuffer = new DynamicIndexBuffer(Game1.GraphicsGlobal.GraphicsDevice, typeof(short), indices.GetLength(0), BufferUsage.WriteOnly); rasterizerState = new RasterizerState(); vertices = new VertexPositionTexture[4]; VertexBuffer = new DynamicVertexBuffer(Game1.GraphicsGlobal.GraphicsDevice, typeof(VertexPositionTexture), vertices.GetLength(0), BufferUsage.WriteOnly); rasterizerState.CullMode = CullMode.CullCounterClockwiseFace; Wave1 = 0; Wave2 = 0; Elevation = 0; }
public RibbonTrailParticle(DynamicVertexBuffer vertex, DynamicIndexBuffer index, short[] indices, VertexPositionTexture[] vertices, Texture2D tex, int primitivesCount) { _tex = tex; IndexBuffer = index; rasterizerState = new RasterizerState(); VertexBuffer = vertex; rasterizerState.CullMode = CullMode.CullCounterClockwiseFace; _alpha = 1; PrimitivesCount = primitivesCount; _indices = indices; _vertices = vertices; }
public void Dispose() { if (_IsActive != 0) { throw new InvalidOperationException("Disposed buffer while in use"); } DisposeResource(Vertices); DisposeResource(Indices); Vertices = null; Indices = null; IsAllocated = false; _IsValid = 0; }
void AllocateBuffers() { if (vertexBuffer == null || vertexBuffer.IsDisposed == true) { vertexBuffer = new DynamicVertexBuffer(graphicsDevice, typeof(GlyphVertex), vertexBufferSize, BufferUsage.WriteOnly); vertexBufferPosition = 0; } if (indexBuffer == null || indexBuffer.IsDisposed == true) { indexBuffer = new DynamicIndexBuffer(graphicsDevice, typeof(short), indexBufferSize, BufferUsage.WriteOnly); indexBuffer.SetData <short>(CreateIndexData()); } }
private void EnsureBufferSize(int vbs, int ibs) { if (_vertexBuffer == null || _vertexBuffer.VertexCount < vbs) { _vertexBuffer?.Dispose(); _vertexBuffer = new DynamicVertexBuffer(GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vbs, BufferUsage.WriteOnly); } if (_indexBuffer == null || _indexBuffer.IndexCount < ibs) { _indexBuffer?.Dispose(); _indexBuffer = new DynamicIndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, ibs, BufferUsage.WriteOnly); } }
private void CalculateBuffers() { if (fPoints.Count > 0) { fNumberOfParticles = fPoints.Count; fNumberOfVertices = fPoints.Count * 4; fNumberOfIndices = fPoints.Count * 6; VertexBillboardParticle[] vertices = new VertexBillboardParticle[fNumberOfVertices]; short[] indices = new short[fNumberOfIndices]; int verticeNumber = 0; int indiceNumber = 0; for (int i = 0; i < fNumberOfParticles; i++) { MyPoint point = fPoints[i]; int verticeNumberBase = verticeNumber; vertices[verticeNumber++] = new VertexBillboardParticle(point.Position, Vector2.Zero, point.Size, Color.White); vertices[verticeNumber++] = new VertexBillboardParticle(point.Position, new Vector2(1, 0), point.Size, Color.White); vertices[verticeNumber++] = new VertexBillboardParticle(point.Position, new Vector2(0, 1), point.Size, Color.White); vertices[verticeNumber++] = new VertexBillboardParticle(point.Position, Vector2.One, point.Size, Color.White); indices[indiceNumber++] = (short)(0 + verticeNumberBase); indices[indiceNumber++] = (short)(1 + verticeNumberBase); indices[indiceNumber++] = (short)(2 + verticeNumberBase); indices[indiceNumber++] = (short)(1 + verticeNumberBase); indices[indiceNumber++] = (short)(3 + verticeNumberBase); indices[indiceNumber++] = (short)(2 + verticeNumberBase); } // 2020-04-01 Out of memory, which hasent happened before //fIndexBuffer = new DynamicIndexBuffer(GraphicsDevice, IndexElementSize.SixteenBits, fNumberOfIndices, BufferUsage.WriteOnly); //fIndexBuffer.SetData(indices); //fVertexBuffer = new DynamicVertexBuffer(GraphicsDevice, VertexBillboardParticle.VertexDeclaration, fNumberOfVertices, BufferUsage.WriteOnly); //fVertexBuffer.SetData(vertices); if (fIndexBuffer != null) { fIndexBuffer.Dispose(); } if (fVertexBuffer != null) { fVertexBuffer.Dispose(); } fIndexBuffer = new DynamicIndexBuffer(GraphicsDevice, IndexElementSize.SixteenBits, fNumberOfIndices, BufferUsage.WriteOnly); fVertexBuffer = new DynamicVertexBuffer(GraphicsDevice, VertexBillboardParticle.VertexDeclaration, fNumberOfVertices, BufferUsage.WriteOnly); fIndexBuffer.SetData(indices); fVertexBuffer.SetData(vertices); } }
private void UpdateIndexBuffer() { indicesList.Clear(); foreach (Triangle t in triangleList) { t.AddIndices(ref indicesList); } if (dynTerrainIndexBuffer.SizeInBytes / sizeof(int) < indicesList.Count) { dynTerrainIndexBuffer.Dispose(); dynTerrainIndexBuffer = new DynamicIndexBuffer(device, typeof(int), indicesList.Count, BufferUsage.WriteOnly); } dynTerrainIndexBuffer.SetData(indicesList.ToArray(), 0, indicesList.Count, SetDataOptions.Discard); }
/// <summary> /// Ensures that the geometry buffers exist and have sufficient size. /// </summary> private void EnsureBuffers(ref ImDrawDataPtr drawDataPtr) { var dirty = false; var vtxCount = 0; var idxCount = 0; for (var i = 0; i < drawDataPtr.CmdListsCount; i++) { var cmd = drawDataPtr.CmdListsRange[i]; vtxCount = Math.Max(vtxCount, cmd.VtxBuffer.Size); idxCount = Math.Max(idxCount, cmd.IdxBuffer.Size); } if (vertexBuffer == null || vertexBuffer.VertexCount < vtxCount) { if (vertexBuffer != null) { vertexBuffer.Dispose(); } vertexBuffer = DynamicVertexBuffer.Create(ImGuiVertex.VertexDeclaration, vtxCount); dirty = true; } if (indexBuffer == null || indexBuffer.IndexCount < idxCount) { if (indexBuffer != null) { indexBuffer.Dispose(); } indexBuffer = DynamicIndexBuffer.Create(IndexBufferElementType.Int16, idxCount); dirty = true; } if (rasterizerState == null) { rasterizerState = RasterizerState.Create(); rasterizerState.ScissorTestEnable = true; } if (geometryStream == null || dirty) { this.geometryStream = GeometryStream.Create(); this.geometryStream.Attach(this.vertexBuffer); this.geometryStream.Attach(this.indexBuffer); } }
public GUIRenderer(IGUIMapper mapper, Matrix renderMatrix /*, CollisionObject colObj*/) { this.mapper = mapper; this.renderMatrix = renderMatrix; //this.colObj = colObj; guiTexture = new Texture2D(State.Device, mapper.GUIWidth, mapper.GUIHeight, false, mapper.TextureFormat); texCoords = new VertexPositionTexture[4]; // Calculate the GUI positions where it will rendered in the 3D world Matrix texPos = Matrix.Identity; width = guiTexture.Width * mapper.DrawingScaleFactor.X / 2; height = guiTexture.Height * mapper.DrawingScaleFactor.Y / 2; texCoords[0].Position = new Vector3(-width, height, 0); texCoords[0].TextureCoordinate = new Vector2(0, 1); texCoords[1].Position = new Vector3(width, -height, 0); texCoords[1].TextureCoordinate = new Vector2(1, 0); texCoords[2].Position = new Vector3(-width, -height, 0); texCoords[2].TextureCoordinate = new Vector2(0, 0); texCoords[3].Position = new Vector3(width, height, 0); texCoords[3].TextureCoordinate = new Vector2(1, 1); vb = new DynamicVertexBuffer(State.Device, VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); vb.SetData(texCoords); short[] indices = new short[6]; indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 3; indices[4] = 1; indices[5] = 0; ib = new DynamicIndexBuffer(State.Device, typeof(short), 6, BufferUsage.WriteOnly); ib.SetData(indices); textureData = mapper.GUITexture; //colObj = GoblinSetting.UICollisionWorld.Add2Dto3DGUI(new Vector2(width * 2, height * 2), // renderMatrix, mapper.GetGUIName()); }
/// <summary> /// Unload all the needed elements of the <c>DrawableModel</c>. /// </summary> public virtual void Unload() { _scale = Vector3.Zero; _rotation = Vector3.Zero; _position = Vector3.Zero; _vertexBuffer.Dispose(); _vertexBuffer = null; _indexBuffer.Dispose(); _indexBuffer = null; _modelTransforms = null; _model = null; }
public void GetBuffers(out VertexBuffer vb, out DynamicIndexBuffer ib) { if (_IsActive != 1) { throw new InvalidOperationException("Buffer not active"); } // ??????? if (_IsValid != 1) { throw new ThreadStateException("Buffer not valid"); } vb = Vertices; ib = Indices; }
/// <summary> /// Sets a dynamic index buffer as a compute resource. /// </summary> /// <param name="stage">The resource stage to set.</param> /// <param name="buffer">The buffer to set.</param> /// <param name="access">Access control flags.</param> public static void SetComputeBuffer(byte stage, DynamicIndexBuffer buffer, ComputeBufferAccess access) { NativeMethods.bgfx_set_compute_dynamic_index_buffer(stage, buffer.handle, access); }
/// <summary> /// Sets the index buffer to use for drawing primitives. /// </summary> /// <param name="indexBuffer">The index buffer to set.</param> /// <param name="firstIndex">The first index in the buffer to use.</param> /// <param name="count">The number of indices to pull from the buffer.</param> public static void SetIndexBuffer(DynamicIndexBuffer indexBuffer, int firstIndex = 0, int count = -1) { NativeMethods.bgfx_set_dynamic_index_buffer(indexBuffer.handle, firstIndex, count); }
/// <summary> /// Build the mesh used to draw all trails /// </summary> private void BuildMesh() { if (this.mesh != null) { this.DestroyMesh(); } // Indices this.indices = new ushort[this.nIndices]; DynamicIndexBuffer indexBuffer = new DynamicIndexBuffer(this.indices); this.RenderManager.GraphicsDevice.BindIndexBuffer(indexBuffer); // Vertices this.vertices = new VertexPositionColorTexture[this.nVertices]; DynamicVertexBuffer vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat); vertexBuffer.SetData(this.vertices); this.GraphicsDevice.BindVertexBuffer(vertexBuffer); this.mesh = new Mesh(0, nVertices, 0, nIndices / 3, vertexBuffer, indexBuffer, PrimitiveType.TriangleStrip) { DisableBatch = true }; }