本文整理汇总了C#中DrawState.GetDynamicInstanceBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# DrawState.GetDynamicInstanceBuffer方法的具体用法?C# DrawState.GetDynamicInstanceBuffer怎么用?C# DrawState.GetDynamicInstanceBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawState
的用法示例。
在下文中一共展示了DrawState.GetDynamicInstanceBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawElement
/// <summary></summary>
/// <param name="state"></param>
protected sealed override void DrawElement(DrawState state)
{
if (state.Properties.SupportsHardwareInstancing && instanceCount > HardwareInstancingMinimum)
{
using (state.WorldMatrix.PushIdentity())
{
vertices.DrawInstances(state, indices, PrimitiveType.TriangleList, state.GetDynamicInstanceBuffer(this.instances, this.instanceCount));
}
}
else
{
Graphics2D.NonInstancingSprite shader = state.GetShader<Graphics2D.NonInstancingSprite>();
for (int i = 0; i < instanceCount; i += NonInstancingRenderCount)
{
int count = Math.Min(NonInstancingRenderCount, (instanceCount - i));
shader.SetInstances(this.instances, (uint)i, 0, (uint)count);
this.verticesSI.Draw(state, this.indicesSI, PrimitiveType.TriangleList, 2 * count, 0, 0);
}
}
}
示例2: DrawChild
//the child isn't drawn right now, but for every bit of geometry that is visible, the world matrix is stored
internal void DrawChild(DrawState state)
{
if (modelData == null)
throw new InvalidOperationException("ModelData is null");
if (buffers == null)
SetupBuffers();
ContainmentType cullModel = ContainmentType.Contains;
//if there is just one geometry object, then the ICullable.CullTest() call will have been suficient.
bool skipCullTest = this.modelData != null && this.modelData.meshes.Length == 1 && this.modelData.meshes[0].geometry.Length == 1;
ICuller culler = state as ICuller;
if (!skipCullTest)
{
cullModel = culler.IntersectBox(ref modelData.staticBounds.minimum, ref modelData.staticBounds.maximum);
}
int geometryIndex = 0;
bool drawn = false;
//loop through the model data
if (cullModel != ContainmentType.Disjoint)
{
for (int m = 0; m < modelData.meshes.Length; m++)
{
MeshData mesh = modelData.meshes[m];
ContainmentType cullMesh = cullModel;
//cull testing along the way
if (cullModel == ContainmentType.Intersects && modelData.meshes.Length > 1)
cullMesh = culler.IntersectBox(ref mesh.staticBounds.minimum, ref mesh.staticBounds.maximum);
if (cullMesh != ContainmentType.Disjoint)
{
for (int g = 0; g < mesh.geometry.Length; g++)
{
GeometryData geom = mesh.geometry[g];
bool cullTest = true;
if (cullMesh == ContainmentType.Intersects && mesh.geometry.Length > 1)
cullTest = culler.TestBox(ref geom.staticBounds.minimum, ref geom.staticBounds.maximum);
//finally, is the geometry visible?
if (cullTest)
{
//add the world matrix to the geometry set
InstanceBuffer buffer = this.buffers[geometryIndex];
if (buffer == null)
{
buffer = state.GetDynamicInstanceBuffer(childCount);
this.buffers[geometryIndex] = buffer;
}
buffer.AddInstance(state);
drawn = true;
}
geometryIndex++;
}
}
else
geometryIndex += mesh.geometry.Length;
}
}
if (drawn)
drawCount++;
}