本文整理汇总了C#中DeviceContext.UnmapSubresource方法的典型用法代码示例。如果您正苦于以下问题:C# DeviceContext.UnmapSubresource方法的具体用法?C# DeviceContext.UnmapSubresource怎么用?C# DeviceContext.UnmapSubresource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeviceContext
的用法示例。
在下文中一共展示了DeviceContext.UnmapSubresource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload
/// <summary>
/// Uploads buffer content into gpu
/// </summary>
/// <param name="buffer">Buffer to upload</param>
/// <param name="context">Device context</param>
/// <param name="dataPointer">Pointer to image data</param>
/// <param name="size">Data size</param>
/// <remarks>Since all kinect textures have a correct stride, we do not perform a copy per row, not do that check.</remarks>
public static void Upload(this SharpDX.Direct3D11.Buffer buffer, DeviceContext context, IntPtr dataPointer, int size)
{
DeviceContext ctx = context;
DataStream ds;
DataBox db = ctx.MapSubresource(buffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out ds);
memcpy(db.DataPointer, dataPointer, size);
context.UnmapSubresource(buffer, 0);
}
示例2: SetConstants
public void SetConstants(DeviceContext deviceContext, float newSpatialSigma, float newIntensitySigma)
{
Constants constants = new Constants()
{
spatialSigma = 1f/newSpatialSigma,
intensitySigma = 1f/newIntensitySigma,
};
DataStream dataStream;
deviceContext.MapSubresource(constantBuffer, MapMode.WriteDiscard, MapFlags.None, out dataStream);
dataStream.Write<Constants>(constants);
deviceContext.UnmapSubresource(constantBuffer, 0);
}
示例3: BindBuffer
public void BindBuffer(DeviceContext context, params Matrix[] matricies)
{
Contract.Assert(matricies.Length == matrixCount);
DataStream data;
context.MapSubresource(matrixBuffer, 0, MapMode.WriteDiscard, MapFlags.None, out data);
foreach(var matrix in matricies)
{
data.Write(matrix);
}
context.UnmapSubresource(matrixBuffer, 0);
context.VertexShader.SetConstantBuffer(bufferSlot, matrixBuffer);
}
示例4: Render
public void Render(RenderTargetView renderTargetView, DeviceContext context, SurfacePass pass)
{
// TODO: generate sky envmap here, with custom params
pass.Pass(context, @"
struct PS_IN
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD;
};
float3 main(PS_IN input) : SV_Target
{
float phi = 2 * 3.14159265 * input.tex.x;
float theta = 3.14159265 * input.tex.y;
float3 p = float3(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi));
float brightness = 500;
if (p.y < 0) return lerp(float3(1, 1, 1), float3(0, 0, 0), -p.y) * brightness;
/* TEMPORARY */
float sunBrightness = (dot(p, normalize(float3(-0.5f, 0.8f, 0.9f))) > 0.9995f) ? 1 : 0;
return lerp(float3(1, 1, 1), float3(0.7f, 0.7f, 1), p.y) * brightness + sunBrightness * 50000;
}
", skyEnvMap.Dimensions, skyEnvMap.RTV, null, null);
context.OutputMerger.SetRenderTargets((RenderTargetView)null);
context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);
context.ClearRenderTargetView(renderTargetView, new Color4(0.5f, 0, 1, 1));
context.Rasterizer.State = rasterizerState;
context.OutputMerger.DepthStencilState = depthStencilState;
context.OutputMerger.SetTargets(depthStencilView, renderTargetView);
context.Rasterizer.SetViewports(new[] { new ViewportF(0, 0, RenderDimensions.Width, RenderDimensions.Height) });
context.Rasterizer.SetScissorRectangles(new[] { new SharpDX.Rectangle(0, 0, RenderDimensions.Width, RenderDimensions.Height) });
context.VertexShader.Set(vertexShader);
context.InputAssembler.InputLayout = inputLayout;
context.PixelShader.SetShaderResource(0, skyEnvMap.SRV);
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
{
DataStream cameraStream;
context.MapSubresource(cameraBuffer, MapMode.WriteDiscard, MapFlags.None, out cameraStream);
camera.WriteTo(cameraStream);
context.UnmapSubresource(cameraBuffer, 0);
cameraStream.Dispose();
}
context.VertexShader.SetConstantBuffer(0, cameraBuffer);
context.PixelShader.SetConstantBuffer(0, cameraBuffer);
foreach (Model model in models.Values)
model.Render(context, camera, materials, proxy);
}
示例5: SetVertexShaderConstants
public unsafe void SetVertexShaderConstants(DeviceContext deviceContext, SharpDX.Matrix world, SharpDX.Matrix viewProjection, SharpDX.Matrix inverseProjection)
{
// hlsl matrices are default column order
var constants = new VSConstantBuffer();
for (int i = 0, col = 0; col < 4; col++)
{
for (int row = 0; row < 4; row++)
{
constants.world[i] = world[row, col];
constants.viewProjection[i] = viewProjection[row, col];
constants.inverseProjection[i] = inverseProjection[row, col];
i++;
}
}
DataStream dataStream;
deviceContext.MapSubresource(vertexShaderConstantBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out dataStream);
dataStream.Write<VSConstantBuffer>(constants);
deviceContext.UnmapSubresource(vertexShaderConstantBuffer, 0);
}
示例6: SetConstants
public unsafe void SetConstants(DeviceContext deviceContext, SharpDX.Matrix userWorldViewProjection, SharpDX.Matrix projectorWorldViewProjection)
{
Constants constants = new Constants();
for (int i = 0, col = 0; col < 4; col++)
for (int row = 0; row < 4; row++)
{
constants.userWorldViewProjection[i] = userWorldViewProjection[row, col];
constants.projectorWorldViewProjection[i] = projectorWorldViewProjection[row, col];
i++;
}
DataStream dataStream;
deviceContext.MapSubresource(constantBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out dataStream);
dataStream.Write<Constants>(constants);
deviceContext.UnmapSubresource(constantBuffer, 0);
}
示例7: GetResults
public void GetResults(DeviceContext context, out float min, out float max)
{
context.CopySubresourceRegion(texture2DMinMax, texture2DMinMaxResourceView.Length - 1, null, textureReadback, 0, 0, 0, 0);
DataStream result;
context.MapSubresource(textureReadback, 0, MapMode.Read, MapFlags.None, out result);
min = result.ReadFloat();
max = result.ReadFloat();
context.UnmapSubresource(textureReadback, 0);
}
示例8: Render
public void Render(DeviceContext deviceContext)
{
if (_changed)
{
float left = (float)((ScreenSize.X / 2) * -1) + (float)Position.X;
float right = left + (float)Size.X;
float top = (float)(ScreenSize.Y / 2) - (float)Position.Y;
float bottom = top - (float)Size.Y;
_vertices[0] = new TranslateShader.Vertex { position = new Vector3(left, top, Depth), texture = new Vector2(0.0f, 0.0f) };
_vertices[1] = new TranslateShader.Vertex { position = new Vector3(right, bottom, Depth), texture = new Vector2(1.0f, 1.0f) };
_vertices[2] = new TranslateShader.Vertex { position = new Vector3(left, bottom, Depth), texture = new Vector2(0.0f, 1.0f) };
_vertices[3] = new TranslateShader.Vertex { position = new Vector3(right, top, Depth), texture = new Vector2(1.0f, 0.0f) };
DataStream mappedResource;
deviceContext.MapSubresource(VertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
mappedResource.WriteRange(_vertices);
deviceContext.UnmapSubresource(VertexBuffer, 0);
_changed = false;
}
// Set vertex buffer stride and offset.
int stride = Utilities.SizeOf<TranslateShader.Vertex>(); //Gets or sets the stride between vertex elements in the buffer (in bytes).
int offset = 0; //Gets or sets the offset from the start of the buffer of the first vertex to use (in bytes).
deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, stride, offset));
deviceContext.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0);
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
}
示例9: FillBuffer
/// <summary>
/// Fills the buffer by semantics
/// </summary>
public void FillBuffer(DeviceContext Context, Matrix World, params object[] CustomData)
{
DataStream cbdata = Context.MapSubresource(CBuffer, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None).Data;
FillData(cbdata, World);
foreach (object o in CustomData)
{
Type T = o.GetType();
if (T == typeof(Vector3))
{
cbdata.Write((Vector3)o);
cbdata.Position += sizeof(float);
}
else if (T == typeof(Vector2))
{
long i = cbdata.Position;
cbdata.Write((Vector2)o);
cbdata.Position += 2 * sizeof(float);
}
else if (T == typeof(Vector4))
{
cbdata.Write((Vector4)o);
}
else if (T == typeof(float))
{
cbdata.Write((float)o);
cbdata.Position += 3 * sizeof(float);
}
else if (T == typeof(int))
{
cbdata.Write((int)o);
cbdata.Position += 3 * sizeof(float);
}
else if (T == typeof(Matrix))
{
cbdata.Write((Matrix)o);
}
else if (T == typeof(Matrix[]))
{
cbdata.WriteRange((Matrix[])o);
}
else if (T == typeof(Vector2[]))
{
Vector2[] a = (Vector2[])o;
foreach (Vector2 vec in a)
{
cbdata.Write(vec);
cbdata.Position += 2 * sizeof(float);
}
}
else
{
throw new NotSupportedException();
}
}
Context.UnmapSubresource(CBuffer, ResourceSlot);
}
示例10: UpdateSentece
private bool UpdateSentece(ref Sentence sentence, string text, int positionX, int positionY, float red, float green, float blue, DeviceContext deviceContext)
{
// Store the color of the sentence.
sentence.red = red;
sentence.green = green;
sentence.blue = blue;
// Get the number of the letter in the sentence.
var numLetters = text.Length;
// Check for possible buffer overflow.
if (numLetters > sentence.MaxLength)
return false;
// Calculate the X and Y pixel position on screen to start drawing to.
var drawX = -(ScreenWidth >> 1) + positionX;
var drawY = (ScreenHeight >> 1) - positionY;
// Use the font class to build the vertex array from the sentence text and sentence draw location.
List<TextureShader.Vertex> vertices;
Font.BuildVertexArray(out vertices, text, drawX, drawY);
DataStream mappedResource;
#region Vertex Buffer
// Lock the vertex buffer so it can be written to.
deviceContext.MapSubresource(sentence.VertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
// Copy the data into the vertex buffer.
mappedResource.WriteRange<TextureShader.Vertex>(vertices.ToArray());
// Unlock the vertex buffer.
deviceContext.UnmapSubresource(sentence.VertexBuffer, 0);
#endregion
return true;
}
示例11: RenderSphereWireframeOnly
public void RenderSphereWireframeOnly( DeviceContext deviceContext, Vector3 p, float radius, Vector3 color, Camera camera )
{
var databox = deviceContext.MapSubresource( mPositionVertexBuffer,
0,
NUM_VERTICES *
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
MapMode.WriteDiscard,
SlimDX.Direct3D11.MapFlags.None );
var currentPoint = new Vector3();
var furtherSouthPoint = new Vector3();
var numVertices = 0;
// northSouthTheta traces from north pole to south pole
float northSouthTheta = (float)Math.PI / 2;
for ( int i = 0; i <= NUM_LATITUDE_LINES; i++ )
{
float currentLatitudeRadius = (float)Math.Cos( northSouthTheta ) * radius;
float nextLatitudeRadius = (float)Math.Cos( northSouthTheta + LATITUDE_STEP ) * radius;
// eastWestTheta traces around each latitude line
float eastWestTheta = 0;
for ( int j = 0; j <= NUM_LONGITUDE_LINES; j++ )
{
currentPoint.X = p.X + ( (float)Math.Cos( eastWestTheta ) * currentLatitudeRadius );
currentPoint.Y = p.Y + ( (float)Math.Sin( northSouthTheta ) * radius );
currentPoint.Z = p.Z + ( (float)Math.Sin( eastWestTheta ) * currentLatitudeRadius );
databox.Data.Write( currentPoint );
numVertices++;
furtherSouthPoint.X = p.X + ( (float)Math.Cos( eastWestTheta ) * nextLatitudeRadius );
furtherSouthPoint.Y = p.Y + ( (float)Math.Sin( northSouthTheta + LATITUDE_STEP ) * radius );
furtherSouthPoint.Z = p.Z + ( (float)Math.Sin( eastWestTheta ) * nextLatitudeRadius );
databox.Data.Write( furtherSouthPoint );
numVertices++;
eastWestTheta += LONGITUDE_STEP;
}
northSouthTheta += LATITUDE_STEP;
}
deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 );
deviceContext.InputAssembler.InputLayout = mRenderWireframeInputLayout;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT,
new VertexBufferBinding( mPositionVertexBuffer,
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
0 ) );
mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() );
mEffect.GetVariableByName( "gColor" ).AsVector().Set( color );
mRenderWireframePass.Apply( deviceContext );
deviceContext.Draw( numVertices, 0 );
}
示例12: RenderQuadSolidOnly
public void RenderQuadSolidOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 color, Camera camera )
{
DataBox databox = deviceContext.MapSubresource( mPositionVertexBuffer,
0,
QUAD_NUM_VERTICES *
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
MapMode.WriteDiscard,
SlimDX.Direct3D11.MapFlags.None );
databox.Data.Write( p1 );
databox.Data.Write( p4 );
databox.Data.Write( p2 );
databox.Data.Write( p3 );
deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 );
deviceContext.InputAssembler.InputLayout = mRenderSolidInputLayout;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT,
new VertexBufferBinding( mPositionVertexBuffer,
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
0 ) );
mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() );
mEffect.GetVariableByName( "gColor" ).AsVector().Set( color );
mRenderSolidPass.Apply( deviceContext );
deviceContext.Draw( QUAD_NUM_VERTICES, 0 );
}
示例13: RenderQuadTexture3DOnly
public void RenderQuadTexture3DOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 t4, ShaderResourceView texture, Camera camera )
{
DataBox databox;
databox = deviceContext.MapSubresource( mPositionVertexBuffer,
0,
QUAD_NUM_VERTICES *
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
MapMode.WriteDiscard,
SlimDX.Direct3D11.MapFlags.None );
databox.Data.Write( p1 );
databox.Data.Write( p4 );
databox.Data.Write( p2 );
databox.Data.Write( p3 );
deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 );
databox = deviceContext.MapSubresource( mTexCoordVertexBuffer,
0,
QUAD_NUM_VERTICES *
TEXCOORD_NUM_COMPONENTS_PER_VERTEX *
TEXCOORD_NUM_BYTES_PER_COMPONENT,
MapMode.WriteDiscard,
SlimDX.Direct3D11.MapFlags.None );
databox.Data.Write( t1 );
databox.Data.Write( t4 );
databox.Data.Write( t2 );
databox.Data.Write( t3 );
deviceContext.UnmapSubresource( mTexCoordVertexBuffer, 0 );
deviceContext.InputAssembler.InputLayout = mRenderTexture3DInputLayout;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT,
new VertexBufferBinding( mPositionVertexBuffer,
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
0 ) );
deviceContext.InputAssembler.SetVertexBuffers( TEXCOORD_SLOT,
new VertexBufferBinding( mTexCoordVertexBuffer,
TEXCOORD_NUM_COMPONENTS_PER_VERTEX *
TEXCOORD_NUM_BYTES_PER_COMPONENT,
0 ) );
mEffect.GetVariableByName( "gTexture3D" ).AsResource().SetResource( texture );
mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() );
mRenderTexture3DPass.Apply( deviceContext );
deviceContext.Draw( QUAD_NUM_VERTICES, 0 );
}
示例14: RenderPoint
public void RenderPoint( DeviceContext deviceContext, Vector3 p, Vector3 color, Camera camera )
{
var databox = deviceContext.MapSubresource( mPositionVertexBuffer,
0,
POINT_NUM_VERTICES *
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
MapMode.WriteDiscard,
SlimDX.Direct3D11.MapFlags.None );
databox.Data.Write( p );
deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 );
deviceContext.InputAssembler.InputLayout = mRenderWireframeInputLayout;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT,
new VertexBufferBinding( mPositionVertexBuffer,
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
0 ) );
mEffect.GetVariableByName( "gColor" ).AsVector().Set( color );
mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() );
mRenderWireframePass.Apply( deviceContext );
deviceContext.Draw( POINT_NUM_VERTICES, 0 );
}
示例15: Render
public void Render(DeviceContext deviceContext, int vertexCount, int vertexOffset, Matrix viewMatrix, Matrix projectionMatrix, int positionIndex, ShaderResourceView pathTexture, double translation, Vector4 mainColor, Vector4 backgroundColor)
{
DataStream mappedResource;
UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, Matrix.Identity, viewMatrix, projectionMatrix);
deviceContext.MapSubresource(ConstantPathDataBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
mappedResource.Write(new PathData
{
Translation = (float)translation,
PositionIndex = positionIndex,
MainColor = mainColor,
BackgroundColor = backgroundColor
});
deviceContext.UnmapSubresource(ConstantPathDataBuffer, 0);
deviceContext.InputAssembler.InputLayout = Layout;
deviceContext.VertexShader.Set(VertexShader);
deviceContext.PixelShader.Set(PixelShader);
deviceContext.PixelShader.SetSampler(0, SamplerState);
deviceContext.PixelShader.SetShaderResource(0, pathTexture);
deviceContext.PixelShader.SetConstantBuffer(1, ConstantPathDataBuffer);
deviceContext.GeometryShader.Set(GeometryShader);
deviceContext.GeometryShader.SetConstantBuffer(0, ConstantMatrixBuffer);
deviceContext.GeometryShader.SetConstantBuffer(1, ConstantPathDataBuffer);
deviceContext.Draw(vertexCount-vertexOffset ,vertexOffset);
deviceContext.GeometryShader.Set(null);
}