#include "primitive.h"

namespace CBK
{
	namespace Shapes
	{
		Primitive::Primitive(IDirect3DDevice9* device) : Shape(device)
		{
			mesh = 0;
		}

		Primitive::~Primitive(void)
		{
			if (mesh != 0)
				d3d::Release<ID3DXMesh*>(mesh);
		}

		void Primitive::draw(const DWORD& subset)
		{
			if (mesh != 0)
			{
				applyTransform();
				if (material != 0)
					material->apply();

				if (texture != 0)
					texture->apply();
				else
					Texture::clear(device);

				mesh->DrawSubset(subset);
			}
		}
	}
}