Official Post Your Enging Coding Tips Thread
Moderator: InsideQC Admins
51 posts
• Page 3 of 4 • 1, 2, 3, 4
GL_EXT_texture_compression_s3tc is the equivelent of d3d's texture compression stuff. But really its only useful if you want to support dxt images. Useful if you want to save 'disk' space, but just awkward otherwise.
On the other hand, the arb texture compression extension is algorithm agnostic.
ARB texture compression is easy really.
When calling glTexImage2D, use an internal format of one of the following:
#define GL_COMPRESSED_ALPHA_ARB 0x84E9
#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
#define GL_COMPRESSED_RGB_ARB 0x84ED
#define GL_COMPRESSED_RGBA_ARB 0x84EE
Generally you want one of the bottom two.
The drivers are meant to figure out some compression routine for you, based on what they support, and then compress it before its delivered to the actual gfx hardware. Obviously you don't want to use it on any textures that are generated at run time, so don't use it on lightmaps.
The GL extension to query for that simple compression stuff is GL_ARB_texture_compression.
On the other hand, the arb texture compression extension is algorithm agnostic.
ARB texture compression is easy really.
When calling glTexImage2D, use an internal format of one of the following:
#define GL_COMPRESSED_ALPHA_ARB 0x84E9
#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
#define GL_COMPRESSED_RGB_ARB 0x84ED
#define GL_COMPRESSED_RGBA_ARB 0x84EE
Generally you want one of the bottom two.
The drivers are meant to figure out some compression routine for you, based on what they support, and then compress it before its delivered to the actual gfx hardware. Obviously you don't want to use it on any textures that are generated at run time, so don't use it on lightmaps.
The GL extension to query for that simple compression stuff is GL_ARB_texture_compression.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Good stuff, I'd forgotten about all that. There's also a glHint for compression quality if memory serves, with the usual GL_NICEST or GL_FASTEST options. Experiment with each and see if the tradeoff is worth it.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
Spike wrote:GL_EXT_texture_compression_s3tc is the equivelent of d3d's texture compression stuff. But really its only useful if you want to support dxt images. Useful if you want to save 'disk' space, but just awkward otherwise.
It still can be useful for crunching large textures onto 64mb cards, or even onboard video shared memory.
i should not be here
- leileilol
- Posts: 2783
- Joined: Fri Oct 15, 2004 3:23 am
It doesn't look like anyone mentioned the kingpin of all coding rules:
Make incremental changes and frequently compress your source and upload it somewhere. This creates the ability to backtrack the origin of any problems and by uploading to somewhere you create redundancy.
(And of course there is SVN, but you can use good coding practices without it).
The main risk that anyone can encounter is creates tons and tons of changes and then you need to reverse something or something is very wrong and you don't know what it is. Without incremental versions, this can often be maddeningly difficult to do.
Also if something happens to your computer, you can lose all your work.
The GPL makes good code maintenance almost second nature because if you do a small update, you are required to release the source and therefore more than likely you have a nice source code history.
Make incremental changes and frequently compress your source and upload it somewhere. This creates the ability to backtrack the origin of any problems and by uploading to somewhere you create redundancy.
(And of course there is SVN, but you can use good coding practices without it).
The main risk that anyone can encounter is creates tons and tons of changes and then you need to reverse something or something is very wrong and you don't know what it is. Without incremental versions, this can often be maddeningly difficult to do.
Also if something happens to your computer, you can lose all your work.
The GPL makes good code maintenance almost second nature because if you do a small update, you are required to release the source and therefore more than likely you have a nice source code history.
The night is young. How else can I annoy the world before sunsrise?
Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
-

Baker - Posts: 3666
- Joined: Tue Mar 14, 2006 5:15 am
Use comments!
Comments make your code readable and easy to modify and change!
Here is another one!
Just because it compiles does *not* mean it will work.
Comments make your code readable and easy to modify and change!
Here is another one!
Just because it compiles does *not* mean it will work.
- Team Xlink
- Posts: 368
- Joined: Thu Jun 25, 2009 4:45 am
- Location: Michigan
Team Xlink wrote:Use comments!
Comments make your code readable and easy to modify and change!
I'd add: comments on why the code is the way it is are much more useful than comments on what it does. What I mean here is that a comment over a printf saying "output results to screen" is useless, but a comment along the lines of "I can't just store the value directly because Quake does blah blah blah so I need to send it through COM_StoreValue instead" is really good to see.
Team Xlink wrote:Here is another one!
Just because it compiles does *not* mean it will work.
I like that one; it's amazing how often some people forget it.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
mh wrote:Team Xlink wrote:Here is another one!
Just because it compiles does *not* mean it will work.
I like that one; it's amazing how often some people forget it. :D
It compiles! Ship it!
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
comments are nice
however if you use say mingw as a compiler it might bitch at stuff like // comment. if it does change it to /* comment. */
another hint if you use min/max a lot define it globally in say quakedef.h since all quakes *.c files includes that.
newer msvc actually has min/max defined i found in this case define it as such.
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
in this case it gets skipped if min or max is allready defined.
#define bound(a, b, c) ((a) >= (c) ? (a) : (b) < (a) ? (a) : (b) > (c) ? (c) : (b))
clamps the stuff to its min/max values
very handy.
however if you use say mingw as a compiler it might bitch at stuff like // comment. if it does change it to /* comment. */
another hint if you use min/max a lot define it globally in say quakedef.h since all quakes *.c files includes that.
newer msvc actually has min/max defined i found in this case define it as such.
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
in this case it gets skipped if min or max is allready defined.
#define bound(a, b, c) ((a) >= (c) ? (a) : (b) < (a) ? (a) : (b) > (c) ? (c) : (b))
clamps the stuff to its min/max values
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
#define bound(a, b, c) ((a) >= (c) ? (a) : (b) < (a) ? (a) : (b) > (c) ? (c) : (b))
clamps the stuff to its min/max values Wink very handy.
Would be alot more handy if you specified which of a b and c is min, max, and the value to clamp. I tried to decypher it but failed.
- Tomaz
- Posts: 67
- Joined: Fri Nov 05, 2004 8:21 pm
thought it was pretty straight forward hmm :/
if the value a is less than the value b then a is used as min else b is min
say if 1"a" is less than 2"b" then min is 1"a" else min"a" is 2"b"
can use it instead of doing if ( a < 0 ) { a = 0; }
like min (a, 0); a will newer get below 0 but it can go above.
i newer was good at algebra
bound is just something óf a mixup
say if b = 0 and c =10 then the value a cant go above 10 and cant go below 0
clamping the values to a min/max.
if the value a is less than the value b then a is used as min else b is min
say if 1"a" is less than 2"b" then min is 1"a" else min"a" is 2"b"
can use it instead of doing if ( a < 0 ) { a = 0; }
like min (a, 0); a will newer get below 0 but it can go above.
i newer was good at algebra
bound is just something óf a mixup
say if b = 0 and c =10 then the value a cant go above 10 and cant go below 0
clamping the values to a min/max.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
thought it was pretty straight forward hmm :/
if the value a is less than the value b then a is used as min else b is min
say if 1"a" is less than 2"b" then min is 1"a" else min"a" is 2"b"
can use it instead of doing if ( a < 0 ) { a = 0; }
like min (a, 0); a will newer get below 0 but it can go above.
i newer was good at algebra Laughing
bound is just something óf a mixup
say if b = 0 and c =10 then the value a cant go above 10 and cant go below 0
clamping the values to a min/max.
That still doesnt answer what a b and c is, is it..
a = value to clamp
b = min
c = max
???
Trying to decypher this again
- Code: Select all
if( a >= c )
{
return a;
}
else
{
if( b < a )
{
return a;
}
else
{
if( b > c )
{
return c;
}
else
{
return b;
}
}
}
- Tomaz
- Posts: 67
- Joined: Fri Nov 05, 2004 8:21 pm
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
well the function aint from me its part of fuhquake source later joequake.
actually looking at one of the values it seems b is the value to clamp while a = min and c = max ?
code snippet below
btw i believe fitzquake has a similar function named CLAMP
actually looking at one of the values it seems b is the value to clamp while a = min and c = max ?
code snippet below
- Code: Select all
// clamp center of light to corner and check brightness
l = DotProduct(impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
s = l + 0.5;
s = bound(0, s, surf->extents[0]);
s = l - s;
l = DotProduct(impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
t = l + 0.5;
t = bound(0, t, surf->extents[1]);
t = l - t;
btw i believe fitzquake has a similar function named CLAMP
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
reckless wrote:well the function aint from me its part of fuhquake source later joequake.
actually looking at one of the values it seems b is the value to clamp while a = min and c = max ?
code snippet below
- Code: Select all
// clamp center of light to corner and check brightness
l = DotProduct(impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
s = l + 0.5;
s = bound(0, s, surf->extents[0]);
s = l - s;
l = DotProduct(impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
t = l + 0.5;
t = bound(0, t, surf->extents[1]);
t = l - t;
What i dont get it she a >= c then return a
Why would min be bigger than max, and why would that automatically yield in a return of a?
This is what ive always done for bound:
- Code: Select all
inline float tgMathClamp( const float Min, const float Num, const float Max )
{
if( Min < Max )
{
if ( Num < Min ) return Min;
else if( Num > Max ) return Max;
else return Num;
}
else
{
if ( Num < Max ) return Max;
else if( Num > Min ) return Min;
else return Num;
}
}
- Tomaz
- Posts: 67
- Joined: Fri Nov 05, 2004 8:21 pm
51 posts
• Page 3 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 1 guest