本文整理汇总了C#中DeviceContext.MapSubresource方法的典型用法代码示例。如果您正苦于以下问题:C# DeviceContext.MapSubresource方法的具体用法?C# DeviceContext.MapSubresource怎么用?C# DeviceContext.MapSubresource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeviceContext
的用法示例。
在下文中一共展示了DeviceContext.MapSubresource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapDiscard
internal static MyMapping MapDiscard(DeviceContext context, Resource buffer)
{
MyMapping mapping;
mapping.context = context;
mapping.buffer = buffer;
mapping.dataBox = context.MapSubresource(buffer, 0, MapMode.WriteDiscard, MapFlags.None, out mapping.stream);
return mapping;
}
示例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: 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);
}
示例5: 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);
}
示例6: SetShaderParameters
/// <summary>
/// Binds the shader and world matricies.
/// </summary>
/// <param name="context">The context to draw from.</param>
/// <param name="world">The world <see cref="Matrix"/> to draw from.</param>
/// <param name="view">The view <see cref="Matrix"/> to use for transforms.</param>
/// <param name="projection">The projection <see cref="Matrix"/> to use for transforms.</param>
/// <returns></returns>
private bool SetShaderParameters(DeviceContext context, Matrix world, Matrix view, Matrix projection)
{
try
{
world.Transpose();
view.Transpose();
projection.Transpose();
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);
DataStream mappedResource;
context.MapSubresource(matrixBuffer, 0, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
mappedResource.Write(world);
mappedResource.Write(view);
mappedResource.Write(projection);
context.UnmapSubresource(matrixBuffer, 0);
context.VertexShader.SetConstantBuffers(0, matrixBuffer);
context.InputAssembler.InputLayout = layout;
return true;
}
catch(Exception)
{
return false;
}
}
示例7: CompileAndBind
public void CompileAndBind(DeviceContext context)
{
foreach(var v in m_Values)
{
var property = m_Definition.GetPropertyForName(v.Key);
m_Writer.Seek(property.byteOffset, SeekOrigin.Begin);
CustomConstantBufferDefinition.ConstantType type = property.type;
Object value = v.Value;
BufferWriteType(type, value);
}
var paramProperties = m_Definition.GetParamProperties();
foreach (var paramPropertyP in paramProperties)
{
m_Writer.Seek(paramPropertyP.byteOffset, SeekOrigin.Begin);
CustomConstantBufferDefinition.ConstantType type = paramPropertyP.type;
Object value = paramPropertyP.paramValue;
BufferWriteType(type, value);
}
var scriptedProperties = m_Definition.GetScriptedProperties();
if (scriptedProperties.Count > 0)
{
foreach (var globalBuffer in s_AllGlobalInstances)
{
foreach (var val in globalBuffer.m_Values)
{
string name = val.Key;
object value = val.Value;
FillScriptLuaContext(m_LuaContext, name, value);
}
var bufferParamProperties = globalBuffer.m_Definition.GetParamProperties();
foreach (var param in bufferParamProperties)
{
string name = param.name;
object value = param.paramValue;
FillScriptLuaContext(m_LuaContext, name, value);
}
}
if (!s_AllGlobalInstances.Contains(this))
{
foreach (var val in m_Values)
{
string name = val.Key;
object value = val.Value;
FillScriptLuaContext(m_LuaContext, name, value);
}
var bufferParamProperties = m_Definition.GetParamProperties();
foreach (var param in bufferParamProperties)
{
string name = param.name;
object value = param.paramValue;
FillScriptLuaContext(m_LuaContext, name, value);
}
}
// Execute!
m_LuaContext.DoString(m_Definition.m_Script);
foreach (var scriptedProperty in scriptedProperties)
{
m_Writer.Seek(scriptedProperty.byteOffset, SeekOrigin.Begin);
CustomConstantBufferDefinition.ConstantType type = scriptedProperty.type;
float value = (float)(double)m_LuaContext[scriptedProperty.name];
BufferWriteType(type, value);
}
}
m_Writer.Flush();
ContextHelper.SetConstantBuffer(context, null, m_Definition.m_Register);
DataBox box = context.MapSubresource(m_ConstantBuffer, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);
box.Data.Write(m_DataBuffer, 0, m_Size);
context.UnmapSubresource(m_ConstantBuffer, 0);
ContextHelper.SetConstantBuffer(context, m_ConstantBuffer, m_Definition.m_Register);
}
示例8: SetConstants
public unsafe void SetConstants(DeviceContext deviceContext, RoomAliveToolkit.Kinect2Calibration kinect2Calibration, SharpDX.Matrix projection)
{
// hlsl matrices are default column order
var constants = new ConstantBuffer();
for (int i = 0, col = 0; col < 4; col++)
for (int row = 0; row < 4; row++)
{
constants.projection[i] = projection[row, col];
constants.depthToColorTransform[i] = (float)kinect2Calibration.depthToColorTransform[row, col];
i++;
}
constants.f[0] = (float)kinect2Calibration.colorCameraMatrix[0, 0];
constants.f[1] = (float)kinect2Calibration.colorCameraMatrix[1, 1];
constants.c[0] = (float)kinect2Calibration.colorCameraMatrix[0, 2];
constants.c[1] = (float)kinect2Calibration.colorCameraMatrix[1, 2];
constants.k1 = (float)kinect2Calibration.colorLensDistortion[0];
constants.k2 = (float)kinect2Calibration.colorLensDistortion[1];
DataStream dataStream;
deviceContext.MapSubresource(constantBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out dataStream);
dataStream.Write<ConstantBuffer>(constants);
deviceContext.UnmapSubresource(constantBuffer, 0);
}
示例9: MapForWrite
public DataStream MapForWrite(DeviceContext ctx)
{
return ctx.MapSubresource(this.Buffer, MapMode.WriteDiscard, MapFlags.None).Data;
}
示例10: FillBuffer
/// <summary>
/// Fills the buffer by semantics
/// </summary>
public void FillBuffer(DeviceContext Context, Matrix World)
{
DataStream cbdata = Context.MapSubresource(CBuffer, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None).Data;
FillData(cbdata, World);
Context.UnmapSubresource(CBuffer, ResourceSlot);
}
示例11: 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;
}
示例12: 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 );
}
示例13: Render
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture)
{
worldMatrix.Transpose();
viewMatrix.Transpose();
projectionMatrix.Transpose();
// Lock the constant memory buffer so it can be written to.
DataStream mappedResource;
deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
// Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
var matrixBuffer = new MatrixBuffer
{
world = worldMatrix,
view = viewMatrix,
projection = projectionMatrix
};
mappedResource.Write(matrixBuffer);
// Unlock the constant buffer.
deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);
// Set the position of the constant buffer in the vertex shader.
const int bufferNumber = 0;
// Finally set the constant buffer in the vertex shader with the updated values.
deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer);
// Set shader resource in the pixel shader.
deviceContext.PixelShader.SetShaderResource(0, texture);
// Set the vertex input layout.
deviceContext.InputAssembler.InputLayout = Layout;
// Set the vertex and pixel shaders that will be used to render this triangle.
deviceContext.VertexShader.Set(VertexShader);
deviceContext.PixelShader.Set(PixelShader);
// Set the sampler state in the pixel shader.
deviceContext.PixelShader.SetSampler(0, SamplerState);
// Render the triangle.
deviceContext.DrawIndexed(indexCount, 0, 0);
}
示例14: 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 );
}
示例15: 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 );
}