Make a cube with a single GL_TRIANGLE_STRIP

Is it possible to create a cube with a single GL_TRIANGLE_STRIP? I have searched around but most examples use multiple strips to make the cube. I found a few people saying it’s possible with a single strip but their examples are incredibly poor with garbled ASCII art and no indication of the order the vertexes need to be in. In fact, many didn’t seem to understand how triangle strips actually work as far as winding and the edges that will be used for the next triangle.

I have tried a million different ways but I can’t seem to make it work. I even made a physical cube that I unfolded but it seems impossible. The problem is the edges that have to change direction as I render around the cube. I just can’t make it work with the alternating winding rules.

Why do you need to? It’s twelve triangles; the GPU is not going to choke on 12 triangles rendered as GL_TRIANGLES.

Because I want to output the cube from a geometry shader and it can only output triangle strips.

I mean if I can’t do it with a single strip it’s not the end of the world. I was just trying to optimize if possible. Maybe it will make no difference. I suppose two strips of 3 faces each will work just as well.

A GS can output triangle strips. It does so by using EndPrimitive() to end the primitive and start a new one. So you could output individual triangles.

But you shouldn’t be outputting a cube from a GS in any case. That’s way too much data for a GS to dump and still get anything remotely like performance.

You can use primitive restart. See the documentation.

If you choose the value of the primitive restart index:


       
GLuint pri = a_number; 
 GLfloat vertices[?]={...};
GLuint indices[i]={0,1,2,...,pri,12,13,14,...};
glPrimitiveRestartIndex(pri);
 ...
glEnable[(GL_PRIMITIVE_RESTART);//bind VAO and element array buffer
   ...
glDrawElements(GL_TRIANGLE_STRIP,0,i,nullptr);


Or you can also just enable GL_PRIMITIVE_RESTART_FIXED_INDEX then the value of pri must be equal of the following number 2^n-1. Where n is equal to 8*sizeof(GLuint or GLushort or GLubyte).

That’s interesting. Had never heard of it. But I see now it’s because it’s one of the goodies coming back to us from GL-ES that I haven’t read up on: ARB_ES3_compatibility. And supported on my desktop drivers too. Need to read up!

In my tests outputting from the geometry shader in this way is considerably faster than using primitives from a static VBO. At least 25% faster and sometimes more.

Is this possible from within a geometry shader? Something to keep in my toolbox anyway, thanks!

http://www.cs.umd.edu/gvil/papers/av_ts.pdf (first page)

In my tests outputting from the geometry shader in this way is considerably faster than using primitives from a static VBO. At least 25% faster and sometimes more.

Then your static VBO code is rendering them really wrongly.

Thanks, great reading!

Uh, how hard and wrong is “glDrawArrays”, lol.

Uh, how hard and wrong is “glDrawArrays”, lol.

I don’t know; are you calling it once per cube, with uniform changes between? And how many cubes are we talking about here? If you’re trying to make Yet Another Minecraft Ripoff, then you should know that Minecraft doesn’t render cubes.

Also, how did you measure this performance difference?

[QUOTE=Alfonse Reinheart;1249380]I don’t know; are you calling it once per cube, with uniform changes between? And how many cubes are we talking about here? If you’re trying to make Yet Another Minecraft Ripoff, then you should know that Minecraft doesn’t render cubes.

Also, how did you measure this performance difference?[/QUOTE]

I’m editing this response to try to end this derailment. We both know there are many ways to accomplish these things and no offense but you’re in no position to understand my requirements. None of this geometry shader and performance talk has anything to do with my original question.