Archived

This topic is now archived and is closed to further replies.

Zeu5

glColor*f vs glColor*ub

Recommended Posts

Hi all, I''m wondering about the internal rappresentation of colors in OpenGL. It is more efficient to use the floating-point version of glColor or the unsigned-byte one? Thanks.

Share this post


Link to post
Share on other sites
i think ub is better because ur sending less data across (1 byte as opposed to 4 bytes for float) i''m not sure how it stores it internally though.

Share this post


Link to post
Share on other sites
quote:
Original post by _walrus
i think ub is better because ur sending less data across (1 byte as opposed to 4 bytes for float) i''m not sure how it stores it internally though.


They are clamped in range [0....1]

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
Try benching :D

QuerryPerformanceCounter(x);
for(int i=0;i{
glColor4f(0,0,0);
glColor4f(255,255,255);
}
QuerryPerformanceCounter(y);
res=y-x;

and same for ''f'', but remember that difference should be 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
Just couldn''t stop :D

______________________________
Madman

Share this post


Link to post
Share on other sites
quote:
Original post by _Madman_
Try benching :D

QuerryPerformanceCounter(x);
for(int i=0;i{
glColor4f(0,0,0);
glColor4f(255,255,255);
}
QuerryPerformanceCounter(y);
res=y-x;

and same for ''f'', but remember that difference should be 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
Just couldn''t stop :D

______________________________
Madman


What''s it? The grade of your mental sanity?

Share this post


Link to post
Share on other sites
quote:
Original post by _Madman_
QuerryPerformanceCounter(x);
for(int i=0;i{
glColor4f(0,0,0);
glColor4f(255,255,255);
}
QuerryPerformanceCounter(y);
res=y-x;



I guess this is the benchmark relative to "glColor3ub", not "glColor4f", btw thanks for the idea.

Share this post


Link to post
Share on other sites
This idea is really cool.Unfortunately the loop is also taking some time...

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
quote:
Original post by _Madman_
Try benching :D

QuerryPerformanceCounter(x);
for(int i=0;i{
glColor4f(0,0,0);
glColor4f(255,255,255);
}
QuerryPerformanceCounter(y);
res=y-x;

and same for ''f'', but remember that difference should be 0.000000000000000000000000000000000000000000000000000000...0001
Just couldn''t stop :D

______________________________
Madman



There would be a difference, at least in storage of color data and loading of files (since less data to load in from files, but as far as just rendering i couldn''t tell u, but since where sending less data across it is potentially faster, unless there is an interal conversion to floats between 0 and 1).

10,000 verticies using floats (4 bytes each) to store for rgba: 4*4*10,000 = ~155k

10,000 verticies using unsigned byte (1 bytes each) to store: 1*4*10,000=~39k


Share this post


Link to post
Share on other sites
And we get back to the question.Quake2 is based on immediate mode and i don''t find it slow.Especially when i have played it on P 120 with 16 ram and 2 mb video....

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
My mental sanity is OK, trust me!
AnywayZ, for a speedy code use vbo or at least glDrawArrays. May be tuff for dynamic objects though. Secondly, GL is state machine & I doubt you are specifying those colors THAT much to get some kind of bottleneck! Finally, 123kb/34kb on !@* translates 128 MB (131072 KB), you are laughing or what?
BTW, prove me wrong, but vp/fp uses float & half as standart color variables ''usually'', I guess ther''s some point. I guess vertices are calculated in float, but colors are using, at least mostly, the same kind, if not the same pipe! That stands for 128/32/24/16/8 bit color and those old 256(ub!) color modes!
And, that loop time, if you are using identical loops, they MUST take exactly the same amount of time in f and u (arghh. ub) test!


______________________________
Madman

Share this post


Link to post
Share on other sites
" GL is state machine & I doubt you are specifying those colors THAT much to get some kind of bottleneck! Finally, 123kb/34kb on !@* translates 128 MB (131072 KB)"


I agree, but some try to optimism a much as possible; I think there was a thread a few weeks ago on this (trying to store as much geometry as possible using the least amount of room). Generally speaking it''s not neccessary because of the resources available on todays cards; it is however,still important to to note that there is a difference in terms of storage bewteen the two, so my point is valid.

Share this post


Link to post
Share on other sites
if you are using glColor* command format doesn''t matter that much becouse the function all overhead is killing your performance..

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
quote:
Original post by Mihail121
And we get back to the question.Quake2 is based on immediate mode and i don''t find it slow.Especially when i have played it on P 120 with 16 ram and 2 mb video....

The PAIN is coming...this summer!!!In cinemas everywhere.


It is NOT, read the source

Share this post


Link to post
Share on other sites
and now to answer the question.... from MSDN.

Current color values are stored in floating-point format, with unspecified mantissa and exponent sizes. Unsigned integer color components, when specified, are linearly mapped to floating-point values such that the largest representable value maps to 1.0 (full intensity), and zero maps to 0.0 (zero intensity). Signed integer color components, when specified, are linearly mapped to floating-point values such that the most positive representable value maps to 1.0, and the most negative representable value maps to –1.0. Floating-point values are mapped directly.

Neither floating-point nor signed integer values are clamped to the range [0,1] before updating the current color. However, color components are clamped to this range before they are interpolated or written into a color buffer.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites