Archived

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

CloudNine

A Texture Flag System

Recommended Posts

Hi, I''ve been working on my DirectX wrapper again, and I want to make a texture flag system much like the Blitz3D engine, which went like this:
Color - 1
Alpha - 2
Masked - 4
Mipmapped - 8
 
and so on. The flags could be added together to produce more effects. My question is, how should I go about creating the different texture flags after recieving the number? CloudNine

Share this post


Link to post
Share on other sites
First, work out which parameter of CreateTexture() and which render state each of your texture flags is aligned with. Make a list of these.

Then you''ll probably need a long line of "if" statements checking each flag and setting up the relevent CreateTexture() parameters, and other states:


D3DFORMAT texture_format = D3DFMT_A8R8G8B8; // default
UINT levels = 1; // default, no mipmapping

if (myflags & Color)
{
format = D3DFMT_A8R8G8B8;
}

if ((myflags & Alpha) || (myflags & Masked))
{
format = D3DFMT_X8R8G8B8;
}

if ((myflags & MipMapping)
{
levels = 0; // 0 so that D3D creates mip levels
}

etc
.
..
...
....
.....
....
...
..
.
Then at render time (you''d probably do the "if" part of this at load time):

if (myflags & Masked)
{
SetRS( D3DRS_ALPHATESTENABLE, TRUE );
}
else
{
SetRS( D3DRS_ALPHATESTENABLE, FALSE );
}

etc etc



For flags, just combine D3D flags based on the input flag combinations.

For many things you could also make translation lookup tables. So you just feed in your combination of flags (assuming a small number of combinations such as 255) as an index, and you get the combined and already ORred (etc) D3D flags out.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites