   Geometry structures
  I have been working on my software renderer recently and I'm not happy with the current way I deal with objects/geometries. Currently this is the structure im using:struct Triangle{Vector3 v[3]; //Original VertsVector3 vt[3];//Translated VertsVector3 n;//NormalColor c[3];Texcoort[3];//Material propertiesColor specularcolor;    Color diffusecolor;    Color ambientcolor;};At the moment I create an object then call my pipeline class method draw(Triangle &t). This method then does all the pipeline operations -> transform -> clip -> lighting etc..I was wondering how you guys deal with this sort of thing?   
  I would emulate ogl's vertex arrays. Where to enable a particular vertex attribute you have to set its pointer and stride. If the software renderer gets a null ptr then that attribute doesnt exist. struct UserVert{  Vector Pos, Normal;};UserVert verts[500];yourApiSetVertexPtr(&verts.Pos, sizeof(UserVert));yourApiSetNormalPtr(&verts.Normal, sizeof(UserVert));yourApiSetTexturePtr(NULL, 0);yourApiDrawVerts(500);   ;  Do you mean something like this:Vertex Buffer Class I understand that is D3D.If I am storing say 3 independant triangles in a vertex array how would i then go about translating just one of them? would I have to apply a transform to the whole list? Or are you suggesting a list per object(group of triangles) only?;  bzroom - im a little confused about your code, could you explain a little further on what you mean.If anyone else has an input I would like to hear how you deal with things.   ;struct Vertex{ Vertex(Vector p) : Pos(p) { } Vector Pos;};//triangle geometryVertex verts[3] = { Vertex(Vector(-1,0))   , Vertex(Vector(0,1))   , Vertex(Vector(1,0)) }; device.SetVertexPtr(&verts[0].Pos, sizeof(Vertex));device.SetNormalPtr(NULL, 0);device.SetTexturePtr(NULL, 0);device.SetModelTransform(tri1Transform);device.DrawTriangles(1);device.SetModelTransform(tri2Transform);device.DrawTriangles(1);device.SetModelTransform(tri3Transform);device.DrawTriangles(1);DrawTriangle(uint n) will draw n triangles using n * 3 verts from the address set using SetVertexPtr(ptr, vsize). Where each vertex is at an offset of vsize from the previous.It's the same as d3d, you bind vertex objects, which sets all your vertex pointers (using the vertex description) and then you call some kind of draw primitives function.Sorry, 3 triangles in the array? we can play with that://triangle geometryVertex verts[9] = { Vertex(Vector(-1,0))   , Vertex(Vector(0,1))   , Vertex(Vector(1,0))   , Vertex(Vector(2,0))   , Vertex(Vector(0,1))   , Vertex(Vector(4,0))   , Vertex(Vector(-1,3))   , Vertex(Vector(0,4))   , Vertex(Vector(1,3)) }; if (vertsAreTransformedInArray){  device.SetVertexPtr(&verts[0].Pos, sizeof(Vertex));  device.SetModelTransform(identity);  device.DrawTriangles(3);}else if (vertsAreTransformedWithMatrix){  device.SetVertexPtr(&verts[0].Pos, sizeof(Vertex));  device.SetModelTransform(tri1Trans);  device.DrawTriangles(1);  device.SetVertexPtr(&verts[3].Pos, sizeof(Vertex));  device.SetModelTransform(tri2Trans);  device.DrawTriangles(1);  device.SetVertexPtr(&verts[6].Pos, sizeof(Vertex));  device.SetModelTransform(tri3Trans);  device.DrawTriangles(1);}Or you could be totally crazy//triangle geometryVertex verts[3] = { Vertex(Vector(-1,0))   , Vertex(Vector(0,1))   , Vertex(Vector(1,0)) }; uint vertIndices[3] = { 0,1,2 };uint instanceIndices[3] = { 0,0,0 };Matrix instanceTransforms[3] = { tri1Transform, tri2Transform, tri3Transform } ;device.SetVertexPtr(&verts[0].Pos, sizeof(Vertex));device.SetIndexPtr(vertIndices, sizeof(uint));device.SetInstancePtr(instanceIndices, sizeof(uint));device.SetTransformPtr(instanceTransforms, sizeof(Matrix));//hey i can make this do what ever the f i want :)device.DrawInstancedObjects(3);;  Ok I thought I understood where this idea was going but I'm finding it difficult to see how this works. Unfortunately I have a very pictographic mind so reading text often goes straight over my head :-( I generally find books good for this as they often include very good graphics but unfortunately I cant find any books that explain this type of datastructure in great detail (or at least outside of opengl or d3d context).If I implement a Class/Struct:class swVertex{public:Vector3 position;Vector3 normal;Color color;float u, v;//Texture CoordinateswVertex();swVertex(Vector3 vtx, Vector3 norm, Color3 col, float u, float v);~swVertex(void);};In my main/file loader etc. I create an array of :swVertex verts[500]My rasterizing class is called swPipeline. Do I place the setPtr methodsthere? What exactly would the mechanics of these methods do? Would they simply save a pointer in my swPipeline to the array i created in the main/file loader? Then when I come to my draw function do I just go through all the verts in the array?[Edited by - RenderMe on April 27, 2009 3:41:26 PM]