/// <summary> /// /// </summary> public void Draw() { int instanceCount = this.InstanceCount; uint mode = (uint)this.CurrentMode; IndexBuffer indexBuffer = this.indexBuffer; int vertexCount = indexBuffer.Length; IndexBufferElementType elementType = indexBuffer.ElementType; IntPtr offset = GetOffset(elementType, this.FirstVertex); uint rs = this.PrimitiveRestartIndex; if (rs != 0) { GL.Instance.Enable(GL.GL_PRIMITIVE_RESTART); glPrimitiveRestartIndex(rs); } GLBuffer.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.BufferId); glDrawElementsInstanced(mode, this.VertexCount, (uint)elementType, offset, instanceCount); GLBuffer.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); if (rs != 0) { GL.Instance.Disable(GL.GL_PRIMITIVE_RESTART); } }
/// <summary> /// /// </summary> /// <param name="controlMode">index buffer is accessable randomly or only by frame.</param> public void Draw(ControlMode controlMode) { int instanceCount = this.InstanceCount; if (instanceCount < 1) { throw new Exception("error: instanceCount is less than 1."); } int frameCount = this.FrameCount; if (frameCount < 1) { throw new Exception("error: frameCount is less than 1."); } uint mode = (uint)this.Mode; IndexBuffer indexBuffer = this.indexBuffer; int vertexCount = indexBuffer.Length; IndexBufferElementType elementType = indexBuffer.ElementType; IntPtr offset = GetOffset(elementType, this.FirstVertex); GLBuffer.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.BufferId); switch (controlMode) { case ControlMode.ByFrame: if (instanceCount == 1) { if (frameCount == 1) { GL.Instance.DrawElements(mode, vertexCount, (uint)elementType, offset); } else { glDrawElementsBaseVertex(mode, vertexCount, (uint)elementType, offset, this.CurrentFrame * vertexCount); } } else { if (frameCount == 1) { glDrawElementsInstanced(mode, vertexCount, (uint)elementType, offset, instanceCount); } else { glDrawElementsInstancedBaseVertex(mode, vertexCount, (uint)elementType, offset, instanceCount, this.CurrentFrame * vertexCount); } } break; case ControlMode.Random: if (instanceCount == 1) { if (frameCount == 1) { GL.Instance.DrawElements(mode, this.RenderingVertexCount, (uint)elementType, offset); } else { glDrawElementsBaseVertex(mode, this.RenderingVertexCount, (uint)elementType, offset, this.CurrentFrame * vertexCount); } } else { if (frameCount == 1) { glDrawElementsInstanced(mode, this.RenderingVertexCount, (uint)elementType, offset, instanceCount); } else { glDrawElementsInstancedBaseVertex(mode, this.RenderingVertexCount, (uint)elementType, offset, instanceCount, this.CurrentFrame * vertexCount); } } break; default: throw new NotDealWithNewEnumItemException(typeof(ControlMode)); } GLBuffer.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); }