0
\$\begingroup\$

I'm practicing primitives rendering in XNA and I want to create something like pipe or tunnel. I have base class called PipeSegment from which I inherit classes like RotatingSegment and NormalSegment (and whatever I imagine). To combine this segments I have created class called Pipe, which have List of PipeSegment objects.This is what I have so far :

Image

It's ok, except the fact that I'm generating way more vertices than necessary. For each segment I'm generating 36 vertices for 'front side', and 36 for 'back side'.

Illustration :

Image

Now, my question. How can I optimize this, how to generate less vertices ? Is there any way to 'share' vertices between Segments to preserve my current code structure and is my code structure suitable for this ?

Thanks

\$\endgroup\$
3

2 Answers 2

1
\$\begingroup\$

You could set up your DrawableGameComponents like links in a linked node list.

For instance, each PipeSegment would have a reference to the next PipeSegment in the line. Then when you want to draw the current PipeSegment you call some interface function that returns the vertices you need. RotatingSegment and NormalSegment implement the interface function however they want.

If all you're concerned with is not storing the data for the vertices multiple times, then you can just draw each segment separately at this point. If, however, you are trying to only make 1 draw call then you can have the segments all send there vertices to the first node through the list, then only make 1 draw call there.

\$\endgroup\$
2
  • \$\begingroup\$ I'll try your solution with linked lists, thank You \$\endgroup\$ Feb 5, 2013 at 18:06
  • \$\begingroup\$ Did it work for you? Let me know if it isn't clear enough. \$\endgroup\$ Feb 7, 2013 at 19:19
0
\$\begingroup\$

I think the real problem here is the PipeSegment having any vertices at all. Rather the PipeSegment should have two Ring objects that are a collection of points around the pipe and are shared between adjacent PipeSegments. The rings would come in two flavors to offset the points.

\$\endgroup\$
1
  • \$\begingroup\$ Thank You, I will try this too, but I worry becouse I don't know how to generate combined VertexBuffer containing vertices from ring1 and ring2... \$\endgroup\$ Feb 6, 2013 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .