private VertexArrayObject GetOrCreateVertexArrayObjectAEN(RenderContext context) { if (vertexArrayObjectAEN == null) { var graphicsDevice = context.GraphicsDevice; var indicesAEN = IndexExtensions.GenerateIndexBufferAEN(Mesh.Draw.IndexBuffer, Mesh.Draw.VertexBuffers[0]); var indexBufferBinding = new IndexBufferBinding(Buffer.Index.New(graphicsDevice, indicesAEN), true, Mesh.Draw.IndexBuffer.Count * 12 / 3); vertexArrayObjectAEN = VertexArrayObject.New(context.GraphicsDevice, Effect.InputSignature, indexBufferBinding, Mesh.Draw.VertexBuffers); } return vertexArrayObjectAEN; }
internal void Initialize(GraphicsDevice device) { vertexArrayObject = VertexArrayObject.New(device, Effect.InputSignature, Mesh.Draw.IndexBuffer, Mesh.Draw.VertexBuffers); }
/// <summary> /// Sets a vertex array object. /// </summary> /// <param name="vertexArrayObject">The vertex array object.</param> public void SetVertexArrayObject(VertexArrayObject vertexArrayObject) { throw new NotImplementedException(); }
public SharedData(GraphicsDevice device, EffectInputSignature defaultSignature) { var vertexBuffer = Buffer.Vertex.New(device, QuadsVertices).DisposeBy(this); // Register reload vertexBuffer.Reload = (graphicsResource) => ((Buffer)graphicsResource).Recreate(QuadsVertices); VertexBuffer = VertexArrayObject.New(device, defaultSignature, new VertexBufferBinding(vertexBuffer, VertexPositionNormalTexture.Layout, QuadsVertices.Length, VertexPositionNormalTexture.Size)).DisposeBy(this); }
public override void Dispose() { if (vertexArrayObject != null) { vertexArrayObject.Dispose(); vertexArrayObject = null; } if (vertexArrayObjectAEN != null) { vertexArrayObjectAEN.Dispose(); vertexArrayObjectAEN = null; } }
/// <summary> /// Prepares a draw call. This method is called before each Draw() method to setup the correct Primitive, InputLayout and VertexBuffers. /// </summary> /// <param name="primitiveType">Type of the primitive.</param> /// <exception cref="System.InvalidOperationException">Cannot GraphicsDevice.Draw*() without an effect being previously applied with Effect.Apply() method</exception> private void PrepareDraw(PrimitiveType primitiveType) { if (CurrentEffect == null) { throw new InvalidOperationException("Cannot GraphicsDevice.Draw*() without an effect being previously applied with Effect.Apply() method"); } // Setup the primitive type PrimitiveType = primitiveType; // If the vertex array object is null, simply set the InputLayout to null if (newVertexArrayObject == null) { if (currentVertexArrayObject != null) { currentVertexArrayObject = null; currentVertexArrayLayout = null; currentEffectInputSignature = null; inputAssembler.InputLayout = currentInputLayout = null; } } else { var newVertexArrayLayout = newVertexArrayObject.Layout; var newEffectInputSignature = CurrentEffect.InputSignature; var oldInputLayout = currentInputLayout; // Apply the VertexArrayObject if (newVertexArrayObject != currentVertexArrayObject) { currentVertexArrayObject = newVertexArrayObject; newVertexArrayObject.Apply(inputAssembler); } // If the input layout of the effect or the vertex buffer has changed, get the associated new input layout if (!ReferenceEquals(newVertexArrayLayout, currentVertexArrayLayout) || !ReferenceEquals(newEffectInputSignature, currentEffectInputSignature)) { currentVertexArrayLayout = newVertexArrayLayout; currentEffectInputSignature = newEffectInputSignature; if (newVertexArrayObject.InputLayout != null && ReferenceEquals(newEffectInputSignature, newVertexArrayObject.EffectInputSignature)) { // Default configuration currentInputLayout = newVertexArrayObject.InputLayout; } else if (ReferenceEquals(newEffectInputSignature, newVertexArrayObject.LastEffectInputSignature)) { // Reuse previous configuration currentInputLayout = newVertexArrayObject.LastInputLayout; } // Slow path if the current VertexArrayObject is not optimized for the particular input (or not used right before) else { currentInputLayout = InputLayoutManager.GetInputLayout(newEffectInputSignature, currentVertexArrayLayout); // Store it in VAO since it will likely be used with same effect later newVertexArrayObject.LastInputLayout = currentInputLayout; newVertexArrayObject.LastEffectInputSignature = newEffectInputSignature; } // Setup the input layout (if it changed) if (currentInputLayout != oldInputLayout) inputAssembler.InputLayout = currentInputLayout; } } SetViewportImpl(); }
private void ReleaseDevice() { // Display D3D11 ref counting info ClearState(); NativeDevice.ImmediateContext.Flush(); NativeDevice.ImmediateContext.Dispose(); if (IsDebugMode) { var deviceDebug = new DeviceDebug(NativeDevice); deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail); } currentInputLayout = null; currentEffectInputSignature = null; currentVertexArrayObject = null; currentVertexArrayLayout = null; nativeDevice.Dispose(); }
/// <summary> /// Sets the vertex array object. /// </summary> /// <param name="vertexArrayObject">The vertex array object.</param> public void SetVertexArrayObject(VertexArrayObject vertexArrayObject) { newVertexArrayObject = vertexArrayObject; }
private void ClearStateImpl() { NativeDeviceContext.ClearState(); for (int i = 0; i < samplerStates.Length; ++i) samplerStates[i] = null; for (int i = 0; i < constantBuffers.Length; ++i) constantBuffers[i] = null; for (int i = 0; i < unorderedAccessViews.Length; ++i) unorderedAccessViews[i] = null; for (int i = 0; i < currentRenderTargetViews.Length; i++) currentRenderTargetViews[i] = null; currentEffectInputSignature = null; currentVertexArrayLayout = null; currentInputLayout = null; currentVertexArrayObject = null; CurrentEffect = null; }