last day (14 days later) » 

5:15 PM
0
A: Drawing successive triangles in a strip with a monotonically increasing number

ReiYou can draw your triangles in a single draw call using Instanced Rendering with the functions glDrawElementsInstanced*. To access the instance index in a shader, there's the builtin variable gl_InstanceID. https://www.opengl.org/sdk/docs/man/html/glDrawElementsInstanced.xhtml https://www.openg...

 
I don't see how this solves the OP's problem.
 
user6238175
Maybe you need glasses
 
The OP wants to tag each triangle with an integer. Instanced rendering will not do that; it will only allow you to render the same mesh multiple times with an increasing index. That index will not be assigned to individual triangles.
 
user6238175
Every instance has a unique index, and you can use that index in a shader to compute the color to be rendered or get it from a data structure.
 
Yes, every instance has a unique index. But you're rendering an entire mesh. That consists of multiple triangles. And each triangle, for each instance, will get the same instance index. So again, how does this help?
 
user6238175
5:15 PM
"I would like to draw many triangles, where the 'color' of each is really in index into a [...] data structure." (where it should be a GPU-bound data structure, not a CPU one) Yes, it helps. He wants to render triangles, each with a different color. If he wants to draw cubes rendered with triangles, each with a different color, he can perform integer division between the instance id and the number of triangles in a cube and get the "instance" of the whole cube. But this is not even the case here.
 
The "each" in that statement refers to each triangle, not each "cube" or "mesh" or "instance" whatever. He wants each individual triangle in the mesh to get a different "color".
 
user6238175
Are you sure you get the meaning of the word "instance"? Using instanced rendering is pretty much equivalent to uploading the position and colors for each vertex and calling glDrawArrays for the number of triangles to render (e.g. for each instance). This is wasteful however, and on recent implementations instanced rendering avoids uploading duplicates, where instances share some attributes (vertices for example) and compute positions, color, etc. in the shader using the instance id.
 
@Rei: OK, let's say I have a mesh. It's a cube, made of 12 triangles. I already have position data for these 12 triangles, and I can render them as a cube. How does using instanced rendering allow me to give each individual triangle a different integer? Show me what the glDraw* command would look like. Show me what the vertex/fragment shader would look like.
If you render that mesh instanced, then you will render X copies of that cube, 1 per instance. Therefore, you will draw X * 12 triangles, with each set of 12 triangles getting a different instance id.
 
user6238175
Nothing to do with the question
 
user6238175
yes of course
 
5:18 PM
That's different from giving each individual triangle a different color.
And yes, that is exactly what the question asked for.
 
user6238175
he wants to draw triangles
 
user6238175
where?
 
He wants each triangle to have a different color.
 
user6238175
I see no mention of cubes, meshes, and whatelse
 
user6238175
yes, exactly
 
5:18 PM
Do you honestly believe he's drawing each individual triangle one at a time?
 
user6238175
each triangle is an instance and gets a difference instance id, used to compute the color in the fragment shader
 
user6238175
the question says so
 
user6238175
or better, there's nothing to tell
 
user6238175
It may be a simplified example, where he's actually trying to render something more complex than a triangle
 
"each triangle is an instance and gets a difference instance id" Which means that each draw command could only draw one triangle.
 
user6238175
5:20 PM
exactly
 
user6238175
he's passing three coordinates and a index, so he wants to draw triangles, not cubes
 
user6238175
there are better ways to render cubes using triangles, using index buffers
 
No, he "thought" of doing that. He thought of doing it that way, but he didn.t
Allow me to translate his question, as I see it:
 
user6238175
because is applies to his problem
 
"I'm drawing 'stuff'. When I draw that 'stuff', I want to assign each triangle some index value. How do I do that?"
 
user6238175
5:23 PM
and can work, if he loops over the instances and calls glDrawArrays
 
user6238175
so instead of uploading vertices and the index, he can upload a buffer of vertices and use instanced draw
 
user6238175
so there's no need to upload the index, the shader already keeps count of the instances
 
user6238175
yes, and there are different ways; instanced rendering is one
 
Again, "instanced drawing" only makes sense if you draw each triangle individually, with a different rendering command.
And even then, it only works with base instances.
 
user6238175
each triangle individually with instanced rendering?
 
user6238175
5:26 PM
that's pretty much the opposite
 
user6238175
but maybe you mean using triangles as primitives for a mesh, and nothing says in the question he's doing it
 
If you have an arbitrary shape, and you draw it with a single draw command, you are rendering X triangles. If you render that same arbitrary shape with an instanced drawing command, you are drawing X*Y triangles, where Y is the instance count.
 
user6238175
yes, and he wants to draw triangles, not arbitrary shapes
 
SHAPES ARE MADE OF TRIANGLES!!!
 
user6238175
of course they are
 
5:28 PM
Then you are admitting that your method ONLY WORKS if you render each triangle individually. Where each triangle is rendered with a separate drawing command.
 
user6238175
do you really think he's going to render a large mesh where he has precomputed the color or each single triangle?
 
user6238175
*of
 
"do you really think he's going to render a large mesh where he has precomputed the color or each single triangle?" Yes. That's what he says he's doing.
 
user6238175
yes of course, that's the question
 
Do you have some other interpretation for the phase "I would like to draw many triangles"?
 
user6238175
5:30 PM
you can't really know what he's really trying to do
 
user6238175
yes, that he really likes to draw triangles and wants t draw a bunch of them
 
If that's the case, if he's really drawing individual triangles, he wouldn't have bothered to ask the question. Why? Because he would just change a uniform between triangles.
 
user6238175
looks like every triangle is a separate entity, since he wants to use an array for their colors
 
user6238175
usually for a mesh you use a texture
 
user6238175
you don't color each triangle directly
 
user6238175
5:32 PM
you leave that to the fragment shader and texture samplers
 
He stated in his question that the "colors" are not really colors. They're just an arbitrary value that he wants associated with each triangle.
 
user6238175
"Because he would just change a uniform between triangles." which is exactly what he thought
 
user6238175
I think anyway this is a waste of time
 
user6238175
if anyone on internet wants to render 1028923 triangles in fast way, there's instanced rendering
 
user6238175
if OP wants to do something weird and specific, well, it's not helpful to anyone
 
5:34 PM
"if anyone on internet wants to render 1028923 triangles in fast way, there's instanced rendering" WTF?
 
user6238175
maybe he's just learning and it's very common for beginners to render simple meshes that way
 
That doesn't even begin to make sense.
 
user6238175
do you realize mine was a joke
 
How could I realize it's a joke? You've said so many things that don't make sense in total seriousness; I can't tell the difference.
 
user6238175
if may be helpful to someone else, if my answer does not exactly apply to OP
 
user6238175
5:36 PM
if you say so
 
Rei: are you a politician? :)
(that was a joke!)
 
user6238175
maybe I am
 
Nicol's right, your answer doesn't make much sense, nobody in practice would ever use it, and beginners should not learn to do things that way.
 
user6238175
oh right so instanced rendering is not used
 
oh no, instancing rendering is used all the time. But not to render a single triangle at a time.
 
user6238175
5:38 PM
I assume that was a simplified example
 
user6238175
not really rendering a bunch of triangles, makes no sense to precompute the color of 10,000 triangles
 
user6238175
and render them in a mesh
 
user6238175
so yes I assume the triangles are actually complex meshes each with a different color
 
user6238175
we can't know unless op is more explicit
 
he did say specifically: "I would like to draw many triangles, where the 'color' of each is really in index into an internal CPU-side data structure."
it's the first sentence of his question.
 
user6238175
5:40 PM
read my message again
 
user6238175
does it make sense to you to store 10,000 colors for simple triangles? for meshes you use textures
 
textures are essentially color data...
except, with textures, you would either need to compute texture coordinates, or, store UVs as mesh data, so, in many ways storing single color values could be more optimal.
can you explain to me why your answer is better than mine?
 
user6238175
never said that
 
so... why add an answer you know is not as good as an existing one?
 
user6238175
I call this mafia
 
user6238175
5:47 PM
this is not a war
 
user6238175
not a race
 
user6238175
if my answer applies to someone, then fine
 
well, but the point of the site is to answer the question as it is asked, not some other question that you want to answer.
 
user6238175
you interpreted the question in a different way than me
 
okay, that's fine, but you see now how your answer does not actually answer the question?
 
user6238175
5:50 PM
are you op?
 
user6238175
then you don't really know what op is trying to do
 
yes, I read their question. If your answer in fact answers their question, they didn't ask it properly.
Although, your answer is not very good advice in general, it probably would not answer any reasonable question.
 
user6238175
right, instanced rendering should be removed from opengl
 
user6238175
right?
 
user6238175
5:54 PM
it's useless, never used
 
user6238175
I'm the only one on the planet using it to do things similar to what OP is trying to do
 
user6238175
not triangles, but complex meshes
 
yes, but that's not what he asked... I can see you're just here to argue pointlessly.
 
user6238175
I'm not here, Nicol asked me to chat
 
leave your answer, those that know will downvote it, because it's a bad answer.
 
user6238175
5:56 PM
I don't care at all
 
user6238175
that;s fine
 
user6238175
if he's trying to render triangles as primitives, you answer applies
 
user6238175
if he's trying to render many instances of a mesh with different colors, mine does
 
did he say anything about meshes? ...
 
user6238175
I want to hear from OP, not from a poster that dislikes when others answer
 
6:00 PM
I don't care if others answer. Let's wait for the OP to decide.
 
user6238175
I saw your answer and was not sure it applied to OP, if he actually meant to render them as separate instances, so I posted mine.
 
user6238175
with a downvote my answer is very likely to be ignored anyway, so I'm deleting it to avoid further discussions.
 
user6238175
bye
 

last day (14 days later) »