S3DVertex base class

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Bazzilic
Posts: 21
Joined: Mon Jun 20, 2005 6:44 pm
Location: Moscow, Russia

S3DVertex base class

Post by Bazzilic »

It would be great if in the next release of IrrLicht classes S3DVertex, S3DVertex2TCoords & S3DVertexTangent would have one base class (e.g. I3DVertex ? ), containing at least Pos, 'cause it's really boring to clon my funcs to serve different types of Vertex...
Sincerely yours, Bazzilic
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

Actually I'd be even happier, if irrlicht got a completely free vertex format. 8)
Bazzilic
Posts: 21
Joined: Mon Jun 20, 2005 6:44 pm
Location: Moscow, Russia

Post by Bazzilic »

What d'u actually mean by "completely free vertex format" ? O_o
Sincerely yours, Bazzilic
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

Any semantic in any order.
For instance, what do you do, if you want tangents and two texture coords now?
Bazzilic
Posts: 21
Joined: Mon Jun 20, 2005 6:44 pm
Location: Moscow, Russia

Post by Bazzilic »

Heh... dunno! :) But i have much more common problem - i'm simulating physics and i have to bulid collision trees, so i have to have access to vertices and i'm being made to write three functions (identical in fact) for three different vertex types!
Sincerely yours, Bazzilic
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Baal Cadar is right about a vertex-free format. It's much more flexible to simply store a vertex buffer containing user-specified vertex elements. For example, http://lf.mmdevel.de/lf/documentation/a ... uffer.html and http://lf.mmdevel.de/lf/documentation/a ... uffer.html
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm just getting started with Irrlicht, but it seems that it would be a bad idea to have to make a virtual function call to get access each vertex.

There are a few simple solutions that I can think of for this without adding a virtual call into the middle of things. Templates may be able to solve some of the issues.

Code: Select all

template< class V >
struct transformPos
{
public:
   transformPos(const core::matrix4& m)
      : M(m)
   {
   }

   void operator()(V& v)
   {
      M.transformVect(v.Pos);
   }

private:
   const core::matrix4 M;
};

template< class Iter, class Fun >
void apply(Iter begin, Iter end, Fun fn)
{
   for (; begin < end; ++begin)
      fn(*begin);
}

  // your code
  apply( verts, verts + n, transformPos<S3DVertexTangents>(mat));
Since the layout of the first few elements of the S3DVertex are the common (Pos, Normal, Color, TCoords), another solution would be to pass a pointer and a stride to access each element...

Code: Select all

void accessVerts(void* verts, irr::u32 stride, irr::u32 count)
{
   S3DVertex* v = (S3DVertex*)verts;
   for (irr::u32 i = 0; i < count; ++i)
   {
      v->Color = 0xbaadf00d;
      v = (S3DVertex*)((irr::u8*)v + stride);
   }
}

  // your code
  accessVerts(verts, sizeof(S3DVertexTangents), nverts);
This solution is better if you have several layers of functions that you don't want to make into templates. You lose type safety, but you gain some performance. This solution would also break if the layout of the beginning of a vertex type was different from S3DVertex. I would hope that isn't likely to happen, but anything is possible.

Travis
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

I dislike the fact that hte base vertex class in LF is pure interface and I may change it some time (all the renaming stuff is a hassle though). It's not really that bad tho b/c you don't by any means generally need ot call getPosition on ever vertex every frame. THe whole buffer is rendered as a vbo or vertex array, so the number of vertex calls is few. I do agree with you though that the number could be minimized further
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Post Reply