public void Unmap() { if (UseBufferOffsets && mappedConstantBuffer.Resource != null) { using (new DefaultCommandListLock(commandList)) { commandList.UnmapSubresource(mappedConstantBuffer); mappedConstantBuffer = new MappedResource(); } } }
public void Map(CommandList commandList) { if (UseBufferOffsets) { using (new DefaultCommandListLock(commandList)) { this.commandList = commandList; mappedConstantBuffer = commandList.MapSubresource(constantBuffer, 0, MapMode.WriteNoOverwrite); Data = mappedConstantBuffer.DataBox.DataPointer; } } }
public void Unmap() { #pragma warning disable 162 if (UseBufferOffsets && mappedConstantBuffer.Resource != null) { using (new DefaultCommandListLock(commandList)) { commandList.UnmapSubresource(mappedConstantBuffer); mappedConstantBuffer = new MappedResource(); } } #pragma warning restore 162 }
public void Map(CommandList commandList) { #pragma warning disable 162 // Unreachable code detected if (UseBufferOffsets) { using (new DefaultCommandListLock(commandList)) { this.commandList = commandList; mappedConstantBuffer = commandList.MapSubresource(constantBuffer, 0, MapMode.WriteNoOverwrite); Data = mappedConstantBuffer.DataBox.DataPointer; } } #pragma warning restore 162 }
/// <summary> /// Unmap <param name="mapped"/> resource. /// </summary> /// <param name="mapped">The mapped resource.</param> public void UnmapSubresource(MappedResource mapped) { NullHelper.ToImplement(); }
// TODO GRAPHICS REFACTOR what should we do with this? public void UnmapSubresource(MappedResource unmapped) { NativeDeviceContext.UnmapSubresource(unmapped.Resource.NativeResource, unmapped.SubResourceIndex); }
/// <summary> /// Begins text rendering (swaps and maps the vertex buffer to write to). /// </summary> /// <param name="graphicsContext">The current GraphicsContext.</param> public void End([NotNull] GraphicsContext graphicsContext) { if (graphicsContext == null) { throw new ArgumentNullException(nameof(graphicsContext)); } // Reallocate buffers if max number of characters is exceeded if (charsToRenderCount > maxCharacterCount) { maxCharacterCount = (int)(1.5f * charsToRenderCount); Initialize(graphicsContext, maxCharacterCount); } // Set the rendering parameters simpleEffect.Parameters.Set(TexturingKeys.Texture0, DebugSpriteFont); simpleEffect.Parameters.Set(SpriteEffectKeys.Color, TextColor); simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, MatrixTransform); // Swap vertex buffer activeVertexBufferIndex = ++activeVertexBufferIndex >= VertexBufferCount ? 0 : activeVertexBufferIndex; // Map the vertex buffer to write to mappedVertexBuffer = graphicsContext.CommandList.MapSubresource(vertexBuffers[activeVertexBufferIndex], 0, MapMode.WriteDiscard); mappedVertexBufferPointer = mappedVertexBuffer.DataBox.DataPointer; unsafe { // Clear buffer first (because of the buffer mapping mode used) Utilities.ClearMemory(mappedVertexBufferPointer, 0x0, VertexBufferLength * sizeof(VertexPositionNormalTexture)); charsToRenderCount = 0; //Draw the strings var constantInfos = new RectangleF(GlyphWidth, GlyphHeight, DebugSpriteWidth, DebugSpriteHeight); foreach (var textInfo in stringsToDraw) { var textLength = textInfo.Text.Length; var textLengthPointer = new IntPtr(&textLength); Native.NativeInvoke.xnGraphicsFastTextRendererGenerateVertices(constantInfos, textInfo.RenderingInfo, textInfo.Text, out textLengthPointer, out mappedVertexBufferPointer); charsToRenderCount += *(int *)textLengthPointer.ToPointer(); } } // Unmap the vertex buffer graphicsContext.CommandList.UnmapSubresource(mappedVertexBuffer); mappedVertexBufferPointer = IntPtr.Zero; // Update pipeline state pipelineState.State.SetDefaults(); pipelineState.State.RootSignature = simpleEffect.RootSignature; pipelineState.State.EffectBytecode = simpleEffect.Effect.Bytecode; pipelineState.State.DepthStencilState = DepthStencilStates.None; pipelineState.State.BlendState = BlendStates.AlphaBlend; pipelineState.State.Output.CaptureState(graphicsContext.CommandList); pipelineState.State.InputElements = inputElementDescriptions[activeVertexBufferIndex]; pipelineState.Update(); graphicsContext.CommandList.SetPipelineState(pipelineState.CurrentState); // Update effect simpleEffect.UpdateEffect(graphicsContext.CommandList.GraphicsDevice); simpleEffect.Apply(graphicsContext); // Bind and draw graphicsContext.CommandList.SetVertexBuffer(0, vertexBuffersBinding[activeVertexBufferIndex].Buffer, vertexBuffersBinding[activeVertexBufferIndex].Offset, vertexBuffersBinding[activeVertexBufferIndex].Stride); graphicsContext.CommandList.SetIndexBuffer(indexBufferBinding.Buffer, 0, indexBufferBinding.Is32Bit); graphicsContext.CommandList.DrawIndexed(charsToRenderCount * 6); }