   Game object
  Hi,I want to create an object for my game that contains the entities needed to render itself, this will be for D3D10.I'm new to D3D10 so I've come up with what I think the object would need:Vertex BufferIndex BufferWorld PositionD3D10_INPUT_ELEMENT_DESC  -> has to match the vertex structure D3D10_BUFFER_DESCD3D10_SUBRESOURCE_DATA  -> hold pointer to verticesThis is just off the top of my head, there may be more and some may not be needed ( D3D10_BUFFER_DESC ?? )As the vertex buffer data can be different, I thought of a couple of structures along the lines:typedef struct VERTEX{ union {  float m_x;  float m_y;  float m_z;    }; float m_pos[3];}VERTEX;typedef struct VERTEX_AND_COLOUR{ union {  float m_x;  float m_y;  float m_z;    }; float m_pos[3]; DWORD m_dwColour;}VERTEX_AND_COLOUR;Of course, others would have texture information etc, but not all objects would be the same, thus I came up with a template class below:template <typename T>class SGObject{public: SGObject(T* pVertexBuffer) {  m_pVertexBuffer = pVertexBuffer; } T* m_pVertexBuffer;};Simple enough, can be used like: // create VERTEX object VERTEX* v = new VERTEX[2];v[0].x = 1; v[0].y = 2; v[0].z = 3; v[1].x = 10; v[1].y = 20; v[1].z = 30; SGObject<VERTEX> p(v); // create VERTEX_AND_COLOUR object VERTEX_AND_COLOUR* vac = new VERTEX_AND_COLOUR[1]; v[0].x = 1; v[0].y = 2; v[0].z = 3; SGObject<VERTEX> pvac(vac);Is this a good way to go about doing this?  A game object:template <typename T>class CGameObject // would derive from possibly other object ( state ){  D3D10_INPUT_ELEMENT_DESC  m_ElemDesc;   D3D10_BUFFER_DESC m_BufferDesc;  D3D10_SUBRESOURCE_DATA  m_InitData;  D3DXVECTOR3 m_WorldPosition;  CGameObject(T* pVertexBuffer, D3DXVECTOR3 Pos)  { m_pVertexBuffer = pVertexBuffer; m_WorldPosition = Pos;  }  T* m_pVertexBuffer;    // etc...etc...};How do you guys build your game objects, especially the vertex buffers.Any help, advice is appreciated.Regards,Steve   
Quote:Original post by stegtypedef struct VERTEX{ union {  float m_x;  float m_y;  float m_z;    }; float m_pos[3];}VERTEX;That doesn't do what you think it does. Also, I'm pretty sure you're working the C++ there. So what's up with the "typedef struct" hoohah?Quote:template <typename T>class SGObject{public: SGObject(T* pVertexBuffer) {  m_pVertexBuffer = pVertexBuffer; } T* m_pVertexBuffer;};It's unlikely that you'll have cause to mess with individual vertex attributes. Generally one just has an opaque array of floats, loaded from a file and handed to the GPU (along with the vertex format, of course). The only aspects of rendering that involve the program in a significant way are skeletal animation, visibility culling, and sometimes (rarely, these days) LOD. And particle systems, but that's a different area.   ;  Thanks for reply,Does that mean just stick with one vertex structure?Regards,Steve   ;Quote:Original post by stegDoes that mean just stick with one vertex structure?No, but it might mean just stick with zero vertex structures. It really depends on how you're loading your geometry data, and what extra, special needs your particular application has related to geometry data. To render a particular object, all I really need is a vertex buffer, a vertex format descriptor, an index buffer, a shader, and a set of uniform values to give to the shader (incl. textures). Notice that I haven't mentioned vertex colors anywhere there. That doesn't mean I don't need or use vertex colors... it just means that I don't care whether I need or use them. The only reason to see a vertex buffer as anything but a bunch of floating point numbers that are handed to the GPU is if I need to know where the seventeenth vertex's "red" value is, and I don't often have a need to do that.   ;  Many thanks, you have helped a great deal with this :-)I really appreciate it.Steve   ;  1)I made a seperate buffer class that takes any flavor of vertex data whether it be positions, texture coordinates, tangents, etc. Templates in C++ are great. I also made use of a table mapping application types to shader types and container types. ie. a color in the application is a D3DXCOLOR, when it is contained in a material it is a D3DXVECTOR4, in a shader it is a float4. Almost everything is 2,3, or 4 floats in the end. almost...The buffer class contains the actual directX buffer.Note a vertex buffer and an index buffer are both the same in d3d10, its just that the index buffer happens to contain uints.I made my system use 1 vertex buffer per input slot for simplicties sake. I haven;t run into a situation where I ran out of input slots yet and it doesn't seem to have impacted performace at all. Whether this was bad remains to be seen. It certainly made my entire system alot easier.some methods of the buffer class that you will end up needing frequently, are getstride() and getformat().I made shared pointers to buffers and pass around std::vectors of them. This is pretty much the "shape" component of renderables. It allows for copying shapes around without worrying about wasting memory.2) I made a material class (although I should rename it to effect state) which contains values to set all effect variables to. The details of it are pretty complicated. It is pretty much one class that can handle any sort of effect and any variables the effect might have. You will need to read about querying effects for varibales and types.3) I made a transform classIt's a transform with some common methods.4) I made a polygon set class that contains all of those things. You will also want to contain the (or reference to the) input layout, effect, technique, and pass(es) used to render. You will need a means of stating what kind of primitive topolgy is used. I think that is about it.5) I am about to write a mesh class that is simply a hierarchy of polygon sets, so that animations can be done down a tree of transforms. I can also have one object using multiple materials this way.I will probably be inheriting or containing a bounding box as well for the polygon set class.Hope that gives you some ideas.   ;  Hi,Thanks for that. Any chance of seeing your buffer class :-)PS - have you thought about an object that could manage state for objects in your game, stuff like health etc?Regards,Steve;Quote:Original post by stegHi,Thanks for that. Any chance of seeing your buffer class :-)PS - have you thought about an object that could manage state for objects in your game, stuff like health etc?Regards,SteveI haven't really gotten to anything game specific yet. Still working on the generic stuff.I envision when I start coding things like "health" that they would be data belonging to classes specific to the game. Those classes would contain or inherit from my mesh class. Things like player, ship, station, etc.Here is my buffer class currently:#ifndef BUFFERS_H#define BUFFERS_H// DirectX Includes#include <d3d10.h>#include <d3dx10.h>// Boost Includes#include <boost/shared_ptr.hpp>// Standard Includes#include <string>#include <map>#include <vector>//------------------------------------------------------------------------------------------/*** C++ types for representation of D3D buffered data types  HLSL type**/typedef D3DXVECTOR3  BiTangent;   // BiTangent    float3 typedef unsigned int BlendIndex;  // Blend indicesuinttypedef float   BlendWeight; // Blend weightsfloat typedef D3DXCOLOR    Color;  // Diffuse and specular color  float4 typedef D3DXVECTOR3  Normal; // Normal vectorfloat3 typedef D3DXVECTOR3  Position;    // Vertex position in object space  float3typedef D3DXVECTOR4  PositionT;   // Transformed vertex position float4typedef float   PointSize;   // Point size   floattypedef D3DXVECTOR3  Tangent;// Tangent float3 typedef float   TexCoord1D;  // Texture coordinates    floattypedef D3DXVECTOR2  TexCoord2D;  // Texture coordinates    float2typedef D3DXVECTOR3  TexCoord3D;  // Texture coordinates    float3typedef unsigned int Index;  // Indices into vertex buffers uinttypedef D3DXMATRIX   Matrix; // Transformation matrix  float4x4//------------------------------------------------------------------------------------------/*** Identifies a type of D3D buffered data** Because some D3D buffered data types map to the same C++ data types, this identifier is * necessary to tell them apart.**/enum BufferContentType{   // Correspond to built in semantics   BITANGENT  = 0,   BLENDINDEX,   BLENDWEIGHT,   COLOR,   NORMAL,   POSITION,   POSITIONT,   POINTSIZE,   TANGENT,   TEXCOORD1D,   TEXCOORD2D,   TEXCOORD3D,   INDEX,   // Correspond to custom semantics   TRANSFORM,   NUM_BUFFER_CONTENT_TYPES};//------------------------------------------------------------------------------------------/*** Gets the semantic name used for the different buffer content types**/const std::string ContentTypeToSemanticName(const BufferContentType & contentType);/*** Gets the data format for the different buffered content types **/const DXGI_FORMAT GetFormat(const BufferContentType & contentType);/*** Gets the number of bytes a piece of data, represented in the given DXGI format, takes up**/const unsigned GetFormatSize(const DXGI_FORMAT & format);/*** Gets the stride for the different buffered content types* The stride is simply the sizeof the C++ data type representing the content type**/const unsigned GetStride(const BufferContentType & contentType);//------------------------------------------------------------------------------------------/*** Wrapper for a D3D buffer**/class Buffer{public:   typedef boost::shared_ptr<Buffer> SharedPtr;   typedef boost::weak_ptr<Buffer>   WeakPtr;   /**   * Creates a buffer for the following types:   *    BlendIndex   *    Index   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<unsigned int> & data,const bool dynamic = false,const bool perInstance = false);   /**   * Creates a buffer for the following types:   *    BlendWeight   *    PointSize   *    TexCoord1D   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<float> & data,const bool dynamic   = false,const bool perInstance  = false);   /**   * Creates a buffer for the following types:   *    TexCoord2D   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXVECTOR2> & data,const bool dynamic   = false,const bool perInstance  = false);   /**   * Creates a buffer for the following types:   *    BiTangent   *    Normal   *    Position   *    Tangent   *    TexCoord3D   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXVECTOR3> & data,const bool dynamic = false,const bool perInstance = false);   /**   * Creates a buffer for the following types:   *    PositionT   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXVECTOR4> & data,const bool dynamic = false,const bool perInstance = false);   /**   * Creates a buffer for the following types:   *    Color   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXCOLOR> & data,const bool dynamic = false,const bool perInstance = false);   /**   * Creates a buffer for the following types:   *    Transform   **/   Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXMATRIX> & data,const bool dynamic = false,const bool perInstance = false);   /**   * Destructor   **/   ~Buffer();   /**   * Get the content type this buffer contains   **/   const BufferContentType GetContentType() const;   /**   * Query whether the buffer contains dynamic data or static data   **/   const bool IsDynamic() const;   /**   * Query whether the buffer contains per instance data or per vertex data   **/   const bool IsPerInstance() const;   /**   * Get the number of elements in the buffer   **/   const unsigned GetNumElements() const;   /**   * Get the D3D buffer   **/   ID3D10Buffer * GetD3DBuffer() const;private: /** No Copy allowed */   Buffer(const Buffer & rhs);   /** No assignment allowed */   Buffer & operator = (const Buffer & rhs);   ID3D10Device &m_device;   // D3D device used to create the buffer   ID3D10Buffer *m_buffer;   // D3D buffer interface   const BufferContentType m_contentType;   // Identifies the type of data the buffer contains    const bool    m_dynamic;  // Whether or not writing to the buffer after creation is permitted   const bool    m_perInstance;   // Whether or not this buffer contains per instance data or per vertex data   unsigned m_numElements;   // Number of elements the buffer contains};#endif // BUFFERS_H#include "Buffers.h"// Common Lib Includes#include "BaseException.h"using namespace common_lib_cpisz;//---------------------------------------------------------------------------const std::string ContentTypeToSemanticName(const BufferContentType & contentType){   if( contentType == BITANGENT )   { return "BITANGENT";   }   else if( contentType == BLENDINDEX )   { return "BLENDINDICES";   }   else if( contentType == BLENDWEIGHT )   { return "BLENDWEIGHT";   }   else if( contentType == COLOR )   { return "COLOR";   }   else if( contentType == NORMAL )   { return "NORMAL";   }   else if( contentType == POSITION )   { return "POSITION";   }   else if( contentType == POSITIONT )   { return "POSITIONT";   }   else if( contentType == POINTSIZE )   { return "PSIZE";   }   else if( contentType == TANGENT )   { return "TANGENT";   }   else if( contentType == TEXCOORD1D ||  contentType == TEXCOORD2D ||  contentType == TEXCOORD3D )   { return "TEXCOORD";   }   else if( contentType == TRANSFORM )   { return "TRANSFORM";   }   else   { throw BaseException("Semantic for buffered content type not found", "const std::string GetSemanticName(const BufferContentType & contentType)","Buffers.cpp");   }}//---------------------------------------------------------------------------const DXGI_FORMAT GetFormat(const BufferContentType & contentType){   // 1 unsigned int   if( contentType == BLENDINDEX ||   contentType == INDEX )   { return DXGI_FORMAT_R32_UINT;   } // 1 float   else if( contentType == BLENDWEIGHT ||  contentType == POINTSIZE   ||  contentType == TEXCOORD1D )   { return DXGI_FORMAT_R32_FLOAT;   } // 2 floats   else if( contentType == TEXCOORD2D )   { return DXGI_FORMAT_R32G32_FLOAT;   }   // 3 floats   else if( contentType == BITANGENT ||  contentType == NORMAL    ||  contentType == POSITION  ||  contentType == TANGENT   ||  contentType == TEXCOORD3D )   { return DXGI_FORMAT_R32G32B32_FLOAT;   }   // 4 floats   else if( contentType == COLOR||   contentType == POSITIONT ||  contentType == TRANSFORM )  // Transforms are read 4 floats at a time   { return DXGI_FORMAT_R32G32B32A32_FLOAT;   }   // Unknown   else   { throw BaseException("Format for buffered cotent type not found","const DXGI_FORMAT GetFormat(const BufferContentType & contentType)","Buffers.cpp");   }}//---------------------------------------------------------------------------const unsigned GetFormatSize(const DXGI_FORMAT & format){   if( format == DXGI_FORMAT_R32G32B32A32_FLOAT ||  format == DXGI_FORMAT_R32G32B32A32_UINT  ||  format == DXGI_FORMAT_R32G32B32A32_SINT )   { return 16;   }   if( format == DXGI_FORMAT_R32G32B32_FLOAT ||  format == DXGI_FORMAT_R32G32B32_UINT  ||  format == DXGI_FORMAT_R32G32B32_SINT )   { return 12;   }   if( format == DXGI_FORMAT_R32G32_FLOAT ||  format == DXGI_FORMAT_R32G32_UINT  ||  format == DXGI_FORMAT_R32G32_SINT )   {  return 8;   }   if( format == DXGI_FORMAT_R32_FLOAT ||  format == DXGI_FORMAT_R32_UINT  ||  format == DXGI_FORMAT_R32_SINT )   { return 4;   }   // Unknown   throw BaseException("Format size unknown",  "const unsigned GetFormatSize(const DXGI_FORMAT & format)",  "Buffers.cpp");}//---------------------------------------------------------------------------const unsigned GetStride(const BufferContentType & contentType){   // 1 unsigned int   if( contentType == BLENDINDEX ||   contentType == INDEX )   { return sizeof(BlendIndex);   } // 1 float   else if( contentType == BLENDWEIGHT ||  contentType == POINTSIZE   ||  contentType == TEXCOORD1D )   { return sizeof(BlendWeight);   } // 2 floats   else if( contentType == TEXCOORD2D )   { return sizeof(TexCoord2D);   }   // 3 floats   else if( contentType == BITANGENT ||  contentType == NORMAL    ||  contentType == POSITION  ||  contentType == TANGENT   ||  contentType == TEXCOORD3D )   { return sizeof(BiTangent);   }   // 4 floats   else if( contentType == COLOR ||   contentType == POSITIONT )   { return sizeof(Color);   } // 4x4 floats   else if( contentType == TRANSFORM )   { return sizeof(D3DXMATRIX);   }   // Unknown   else   { throw BaseException("Stride for buffered content type not found","const unsigned GetStride(const BufferContentType & contentType)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<unsigned int> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(unsigned int) != GetStride(contentType) ||  DXGI_FORMAT_R32_UINT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor","Buffer::Buffer(const BufferContentType contentType, const std::vector<unsigned int> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   if( contentType == INDEX && perInstance )   { throw BaseException("An index buffer cannot be 'per instance'","Buffer::Buffer(const BufferContentType contentType, const std::vector<unsigned int> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   if( contentType == INDEX )   { bufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER; }   else   { bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   }   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(unsigned int) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<unsigned int> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<float> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(float) != GetStride(contentType) ||  DXGI_FORMAT_R32_FLOAT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor","Buffer::Buffer(const BufferContentType contentType, const std::vector<float> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(float) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<float> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXVECTOR2> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(D3DXVECTOR2) != GetStride(contentType) ||  DXGI_FORMAT_R32G32_FLOAT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor", "Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXVECTOR2> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(D3DXVECTOR2) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXVECTOR2> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXVECTOR3> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(D3DXVECTOR3) != GetStride(contentType)    ||  DXGI_FORMAT_R32G32B32_FLOAT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor", "Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXVECTOR3> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(D3DXVECTOR3) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXVECTOR3> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXVECTOR4> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(D3DXVECTOR4) != GetStride(contentType)  ||  DXGI_FORMAT_R32G32B32A32_FLOAT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor", "Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXVECTOR4> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(D3DXVECTOR4) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXVECTOR4> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXCOLOR> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(D3DXCOLOR) != GetStride(contentType)    ||  DXGI_FORMAT_R32G32B32A32_FLOAT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor", "Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXCOLOR> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(D3DXCOLOR) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXCOLOR> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::Buffer(ID3D10Device & device,const BufferContentType contentType,const std::vector<D3DXMATRIX> & data,const bool dynamic,const bool perInstance)   :   m_device(device),   m_buffer(NULL),   m_contentType(contentType),   m_dynamic(dynamic),   m_perInstance(perInstance),   m_numElements(static_cast<unsigned>(data.size())){   // Check for sillyness   if( sizeof(D3DXMATRIX) != GetStride(contentType)    ||  DXGI_FORMAT_R32G32B32A32_FLOAT != GetFormat(contentType) )   { throw BaseException("Illegal content type for this constructor", "Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXMATRIX> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }   // Describe the vertex buffer   D3D10_BUFFER_DESC bufferDesc;   if( !dynamic )   { bufferDesc.Usage= D3D10_USAGE_DEFAULT; bufferDesc.CPUAccessFlags = 0;   }   else   { bufferDesc.Usage= D3D10_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;   }   bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;   bufferDesc.ByteWidth = static_cast<UINT>(sizeof(D3DXMATRIX) * data.size());   bufferDesc.MiscFlags = 0; // Provide the data for the buffer   D3D10_SUBRESOURCE_DATA initData;   initData.pSysMem = &data[0]; // Create the buffer with the provided data   if( FAILED(m_device.CreateBuffer(&bufferDesc, &initData, &m_buffer)) )   { throw BaseException("Failed to create buffer","Buffer::Buffer(const BufferContentType contentType, const std::vector<D3DXMATRIX> & data, const bool dynamic, const bool perInstance)","Buffers.cpp");   }}//---------------------------------------------------------------------------Buffer::~Buffer(){   if( m_buffer )   { m_buffer->Release();   }}//---------------------------------------------------------------------------const BufferContentType Buffer::GetContentType() const{   return m_contentType;}//---------------------------------------------------------------------------const bool Buffer::IsDynamic() const{   return m_dynamic;}//---------------------------------------------------------------------------const bool Buffer::IsPerInstance() const{   return m_perInstance;}//---------------------------------------------------------------------------const unsigned Buffer::GetNumElements() const{   return m_numElements;}//---------------------------------------------------------------------------ID3D10Buffer * Buffer::GetD3DBuffer() const{   return m_buffer;}There may be a way to consolidate all those constructors using templates like I had mentioned ;) Haven't gotten around to it.