Inside3D!
     

Official Post Your Enging Coding Tips Thread
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming
View previous topic :: View next topic  
Author Message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Tue Aug 04, 2009 10:12 pm    Post subject: Reply with quote

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.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Tue Aug 04, 2009 10:24 pm    Post subject: Reply with quote

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.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
leileilol



Joined: 15 Oct 2004
Posts: 1321

PostPosted: Wed Aug 05, 2009 5:17 am    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Mon Aug 10, 2009 11:34 am    Post subject: Reply with quote

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.
_________________
Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...
Back to top
View user's profile Send private message
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Thu Aug 13, 2009 10:09 pm    Post subject: Reply with quote

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.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Thu Aug 13, 2009 11:14 pm    Post subject: Reply with quote

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. Very Happy
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Fri Aug 14, 2009 12:41 am    Post subject: Reply with quote

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!
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Fri Aug 14, 2009 5:55 am    Post subject: Reply with quote

comments are nice Wink

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 Wink very handy.
Back to top
View user's profile Send private message
Tomaz



Joined: 05 Nov 2004
Posts: 49

PostPosted: Sat Aug 15, 2009 1:13 pm    Post subject: Reply with quote

Quote:
#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.
Back to top
View user's profile Send private message
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Sat Aug 15, 2009 11:42 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Tomaz



Joined: 05 Nov 2004
Posts: 49

PostPosted: Sun Aug 16, 2009 12:51 am    Post subject: Reply with quote

Quote:
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:

if( a >= c )
{
    return a;
}
else
{
    if( b < a )
    {
        return a;
    }
    else
    {
        if( b > c )
        {
            return c;
        }
        else
        {
            return b;
        }
    }
}
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Aug 16, 2009 12:56 am    Post subject: Reply with quote

oh yeah... he's another coding tip!

Use sane parameter/parameter names. Single letters are awkward!
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Sun Aug 16, 2009 5:45 pm    Post subject: Reply with quote

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:
      // 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
Back to top
View user's profile Send private message
Tomaz



Joined: 05 Nov 2004
Posts: 49

PostPosted: Sun Aug 16, 2009 5:50 pm    Post subject: Reply with quote

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:
      // 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:

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;
   }
}
Back to top
View user's profile Send private message
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Sun Aug 16, 2009 5:53 pm    Post subject: Reply with quote

tbh im not sure

this is the one from fitz

#define CLAMP(min, x, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) //johnfitz

looks a bit more clean ill have to try it out and see if theres any difference.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group