using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.ComponentModel;
using GraphiXNA.Materials;

namespace GraphiXNA.Graphics.Library
{
    public class Object3D : IRenderable
    {
        internal GraphicsDevice GraphicsDevice = null;
        internal VertexBuffer VertexBuffer = null;
        internal IndexBuffer IndexBuffer = null;
        internal VertexDeclaration VertexDeclaration = null;
        internal int VertexStride = 0;
        internal int NumberOfVertices = 0;
        internal int BaseVertex = 0;
        internal int PrimitiveCount = 0;
        internal int NumberOfIndices = 0;
        internal int StartIndex = 0;
        internal PrimitiveType PrimitiveType = PrimitiveType.TriangleStrip;

        public Object3D(GraphicsDevice graphicsDevice)
        {
            GraphicsDevice = graphicsDevice;
        }

        internal void Draw()
        {
            GraphicsDevice.Vertices[0].SetSource(VertexBuffer, 0, VertexStride);
            GraphicsDevice.VertexDeclaration = VertexDeclaration;

            if (IndexBuffer == null)
            {
                GraphicsDevice.DrawPrimitives(PrimitiveType, BaseVertex, PrimitiveCount);
            }
            else
            {
                GraphicsDevice.Indices = IndexBuffer;
                GraphicsDevice.DrawIndexedPrimitives(PrimitiveType, BaseVertex, 0, NumberOfVertices, StartIndex, PrimitiveCount);
            }
        }

        #region IRenderable Members

        void IRenderable.Draw()
        {
            Draw();
        }

        #endregion
    }
}
