/// <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); } } }
//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++; }