Could someone please explain the following in Newbie-speak?

Member
Posts: 48
Joined: 2009.05
Post: #1
From the Apple OGL ES doc.

===============================

Avoid Storing Constants in Arrays

If your geometry uses data that remains constant across an object, you should not duplicate that data inside your vertex format. Instead, you should disable that array entirely and use a per-vertex attribute state call such as glColor4ub or glTexCoord2F instead. OpenGL ES 2.0 applications can either set a constant vertex attribute or use a uniform shader value to hold information that is constant across an object and changes infrequently.

===============================


o.O

Huh?!

Plain English and maybe an pseudo code example?

Thanks muchly.
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
This means that if you have the same value for every single vertex, try to pull it out of the array and set it as an attribute.

For example, say this is your vertex array for a triangle, where it holds 2 pieces of information for each vertex: the position and the color.
Code:
Vertex vertices[] =
{
   Vertex(Position0, White),
   Vertex(Position1, White),
   Vertex(Position2, White)
};
Draw(vertices);

Each of the positions are different, but the color is the same for every single vertex. They are saying you should pull that value out like this:
Code:
Color(White);
Vertex vertices[] =
{
   Vertex(Position0),
   Vertex(Position1),
   Vertex(Position2)
};
Draw(vertices);
Notice how the color is set as an attribute, so the same value is used for every vertex until that attribute is changed again. This way you can save the amount of memory used for each vertex array, as well as reduce the amount of data that must be sent to the video card.

There are 2 main ways to set a common value as an attribute for all subsequent vertices in OpenGL. If you're using fixed function, then you can use one of the functions like glColor() to set that attribute. If you're using shaders, you can set a shader variable.
Member
Posts: 446
Joined: 2002.09
Post: #3
Elphaba Wrote:...such as glColor4ub or glTexCoord2F
glTexCoord2F? Blink
Member
Posts: 269
Joined: 2005.04
Post: #4
Frank C. Wrote:glTexCoord2F? Blink

Weird. The docs do say glTexCoord2f. That typo aside, if you have any data that's constant across an array (texture coordinate, normal, color, etc), it's faster to set that once instead of duplicate the data for every vertex. For ES 2.x you set a uniform ( glUniform4f, etc). For ES 1.x you can use glColor/glMaterial for colors, glMultiTexCoord4f for texture coordinates, or glNormal3f for normals.
Member
Posts: 48
Joined: 2009.05
Post: #5
Ah, so say I have my particle system and all of the textured quads use the SAME TEXTURE ID, but DIFFERENT COLOURS, then it would be better to do it this way?

particleArray =
{ vertex, color (as short)
....

}

glBindTexture( my common texture id)
glDrawArray( particleArray)



Right?

Thanks again.. this is really helping make sense of a quite a confusing document... (at least in terms of translating uber graphics god -> ordinary English games programmer ) Wink
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
You never specify textures per vertex, and you can only change bound textures between draw calls, so this document doesn't pertain to that. However, if your color was the same for each vertex, for example, then you would call glColor4ub(color) (or whatever glColor* call you need) before your draw call, just like your texture bind, and not store the color in your vertex. Since you colors are changing, it's correct to stick in the vertex array like you're doing, along with the position and texture coordinates.
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
So Elphaba, did akb825's answer make any more sense than Apple's documentation? If so, why?

Seriously, I'm curious to know which word/phrase/concept in the documentation is hard to understand. Programming is a technical subject, but it's the job of a technical writer to describe these things as clearly as possible.

I suspect the answer is that you don't understand how vertex attributes work. If so, the best reply to the OP is probably "you're reading the documentation in the wrong order."
Apprentice
Posts: 15
Joined: 2002.04
Post: #8
Elphaa:
I don't read arekkusu's post the same way you do. What he's asking is what exactly it is that you did not understand in Apple's documentation and how Akb825's answer made more sense for you. He's interest is in how to improve technical documentation. So getting feedback on actual examples helps him write better technical documentation.

I don't know if you just had a bad day and arekkusu's post just sort of tipped you over but the only offensive thing I see here is your last post, filled with hostility and completely unnecessary insults.

Did it ever occur to you that he might actually work at Apple, writing documentation? I'm not saying that he does, since I actually don't know, but from the reply he gave it would definitely make sense. So the next time something appears to be hostile towards you, take a deep breath and reread it again with an open mind. People around here are usually very helpful and not at all hostile.
Member
Posts: 48
Joined: 2009.05
Post: #9
Hi Sacha.

Yes that thought (about Apple employee) occurred but I totally discounted from the tone and they actual words used.

Plus as a paid up member of ADC, I get into the 3.1 beta forums and REGULARLY talk to Apple people and none are a condescending and patronising as that post was.

Yes I read and re-read it.

In fact I SLEPT on it.

Yes, I will admit to being against the gun here - I'm 6 days before final deadline and still stuck... HOWEVER that doesn't forgive the tone or words used.

It's been insinuated that I insulted another member of these boards on another un-related post... and I've looked, read - got 2nd 3rd and 4th opinions, and all agree with me

Maybe it's my level of education or the fact that I am an native English speaker from the country the language originated, but I KNOW English, and I know when words are 'right' or 'wrong'. And I can read tone.

I am also very aware that forums are inherently difficult to use... conveying meaning, emphasising, clarity and intent are very difficult to get across with words alone ( unless words are your 'thing') but more importantly are even more difficult to get across when you have a problem and you're bashing the key's quickly to get a question out there to hopefully meet someone who can help you.

I understand this, and IF I have mis-read the situation and Arekkusu want's to clarify and choose his words more carefully and more 'considered', then I will happily retract my comments and we can clear this up.


However, the point still stands that SHOULD he have posted "you're reading the documentation in the wrong order." as he seemed to indicate that he would have done had he been first poster, then what use is that to man or beast?

It's like asking someone "Do you like Red or Blue?" and getting "Yes." in return.

No frakking use whatsoever and only aggravates and complicates the situation.

I've said my peace in response to him.

If I could have send a PM I would have done, but again - this site is not as useful as virtually every other forum.

Whilst there is a huge amount of skill and knowledge on here and some wonderful, helpful and genuine people... I feel that the one's that aren't ruin it... completely.
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #10
I declare the name calling to be officially over. If you like getting angry over nothing, please go do it somewhere else, on one of those "virtually every other forum" thingies.
Moderator
Posts: 682
Joined: 2002.11
Post: #11
I would just like to point out that the terminology used was not "invented to keep people out," but to precisely describe complex concepts that must be understood exactly in order to make them work together.

My web site - Games, music, Python stuff
Moderator
Posts: 437
Joined: 2002.09
Post: #12
Elphaba,

I hope you'll at least agree arrekusu said nothing wrong in the first two paragraphs. He was asking you for feedback, and even implied that if you were confused the documentation might be to blame.

I think what you had a problem with was the final paragraph. I don't read it as a dig myself, but to be fair I've seen many posts by arrekusu over the years, and you haven't. So I have more information to go on.

Given that arrekusu started off perfectly politely, asking for your feedback where he didn't need to, I think you should give him the benefit of the doubt on the last paragraph. You can also search for past posts by him- if they haven't been purged I'm pretty sure they will bear out that he is a polite, helpful, non-condescending person.

My other advice is that if you have a problem with someone's reply it is to your benefit to take the high road. The less polite you think someone is being, the more polite you need to be. This will infuriate the people who ARE trying to get a rise out of you, and gains you the respect of the people who aren't. If you had laid out your grievance politely the misunderstanding could have been cleared up. Instead, you blew up and posted some junk that would have gotten you permanently banned from other forums.

Measure twice, cut once, curse three or four times.
Thread Closed