本文整理汇总了C#中GraphicsDevice.DrawInstanced方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice.DrawInstanced方法的具体用法?C# GraphicsDevice.DrawInstanced怎么用?C# GraphicsDevice.DrawInstanced使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicsDevice
的用法示例。
在下文中一共展示了GraphicsDevice.DrawInstanced方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawGhost
public void DrawGhost(Camera camera, GraphicsDevice graphicsDevice, VoxelType voxel, Int32 levelPositionCode)
{
_voxelEffect.Parameters["ViewProjection"].SetValue(camera.ViewMatrix * camera.ProjectionMatrix);
_voxelEffect.Parameters["VoxelTexture"].SetResource(_voxelTypeRenderingData[GetRenderingDataIndex(voxel)].Texture);
_voxelEffect.Parameters["Transparency"].SetValue(0.7f);
_voxelEffect.Parameters["Ambient"].SetValue(2.0f);
_voxelEffect.Parameters["ScalingFactor"].SetValue(TypeInformation.GetScalingFactor(voxel) * 0.5f);
_singleInstanceBuffer.SetDynamicData(graphicsDevice, (ptr) => System.Runtime.InteropServices.Marshal.Copy(
new Int32[] { levelPositionCode }, 0, ptr, 1));
graphicsDevice.SetRasterizerState(_noneCullingState);
graphicsDevice.SetDepthStencilState(_depthStencilStateState);
graphicsDevice.SetBlendState(_blendStateTransparent);
// Setup the vertices
graphicsDevice.SetVertexBuffer(0, _cubeVertexBuffer);
graphicsDevice.SetVertexBuffer(1, _singleInstanceBuffer);
graphicsDevice.SetVertexInputLayout(_vertexInputLayout);
_voxelEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawInstanced(PrimitiveType.TriangleList, _cubeVertexBuffer.ElementCount, 1, 0, 0);
}
示例2: Draw
/// <summary>
/// draw what else
/// </summary>
public void Draw(Camera camera, GraphicsDevice graphicsDevice)
{
_voxelEffect.Parameters["ViewProjection"].SetValue(camera.ViewMatrix * camera.ProjectionMatrix);
_voxelEffect.Parameters["Ambient"].SetValue(0.3f);
_voxelEffect.Parameters["CameraPosition"].SetValue(camera.Position);
graphicsDevice.SetRasterizerState(_backfaceCullingState);
graphicsDevice.SetDepthStencilState(_depthStencilStateState);
graphicsDevice.SetBlendState(_blendStateOpaque);
// Setup the vertices
graphicsDevice.SetVertexBuffer(_cubeVertexBuffer, 0);
graphicsDevice.SetVertexInputLayout(_vertexInputLayout);
// render all instances
for (int i = 0; i < _voxelTypeRenderingData.Length; ++i)
{
_voxelEffect.Parameters["ScalingFactor"].SetValue(TypeInformation.GetScalingFactor(_voxelTypeRenderingData[i].Voxel) * 0.5f);
_voxelEffect.Parameters["VoxelTexture"].SetResource(_voxelTypeRenderingData[i].Texture);
_voxelEffect.Parameters["SpecularModifier"].SetValue(TypeInformation.IsParasite( _voxelTypeRenderingData[i].Voxel ));
_voxelEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.SetVertexBuffer(1, _voxelTypeRenderingData[i].InstanceBuffer);
graphicsDevice.DrawInstanced(PrimitiveType.TriangleList, _cubeVertexBuffer.ElementCount, _voxelTypeRenderingData[i].InstanceDataRAM.Count, 0, 0);
}
graphicsDevice.SetVertexBuffer<int>(1, (Buffer<int>)null);
}