/// <summary>This function is used as a delegate to determine the cloning process of static model meshes.</summary> private static void PullOutModelComponents(string currentId, Link3<string, Texture, StaticMesh> link, out string newId, out Link3<string, Texture, StaticMesh> newLink) { link.Middle.ExistingReferences++; link.Right.ExistingReferences++; newId = currentId; newLink = new Link3<string,Texture,StaticMesh>(link.Left, link.Middle, link.Right); }
private static void DrawStaticModelPart(string id, Link3<string, Texture, StaticMesh> subStaticModel) { // If there is no vertex buffer, nothing will render anyway, so we can stop it now. if (subStaticModel.Right.VertexBufferHandle == 0 || // If there is no color or texture, nothing will render anyway (subStaticModel.Right.ColorBufferHandle == 0 && subStaticModel.Right.TextureCoordinateBufferHandle == 0)) return; // Push current Array Buffer state so we can restore it later GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit); if (GL.IsEnabled(EnableCap.Lighting)) { // Normal Array Buffer if (subStaticModel.Right.NormalBufferHandle != 0) { // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.Right.NormalBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.NormalArray); } } else { // Color Array Buffer (Colors not used when lighting is enabled) if (subStaticModel.Right.ColorBufferHandle != 0) { // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.Right.ColorBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.ColorPointer(3, ColorPointerType.Float, 0, IntPtr.Zero); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.ColorArray); } } // Texture Array Buffer if (GL.IsEnabled(EnableCap.Texture2D)) { if (subStaticModel.Right.TextureCoordinateBufferHandle != 0) { // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, subStaticModel.Middle.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.Right.TextureCoordinateBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.TextureCoordArray); } else // Nothing will render if this branching is reached. return; } // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.Right.VertexBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.VertexArray); if (subStaticModel.Right.ElementBufferHandle != 0) { // Element Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ElementArrayBuffer, subStaticModel.Right.ElementBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.IndexPointer(IndexPointerType.Int, 0, IntPtr.Zero); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.IndexArray); // Draw the elements in the element array buffer // Draws up items in the Color, Vertex, TexCoordinate, and Normal Buffers using indices in the ElementArrayBuffer GL.DrawElements(BeginMode.Triangles, subStaticModel.Right.VertexCount, DrawElementsType.UnsignedInt, 0); } else { // Select the vertex buffer as the active buffer (I don't think this is necessary but I haven't tested it yet). GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.Right.VertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, subStaticModel.Right.VertexCount); } GL.PopClientAttrib(); }