Skip to main content
gamedev.net
🔒 Locked

A Texture Flag System

Started by CloudNine May 28, 2003 at 12:32 AM 1 replies 350+ views
Original Post
CloudNine
CloudNine
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
S1CA
S1CA
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
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
CloudNine
CloudNine
Would turning it into a binary string, and going through the numbers one by one help?

Thanks for the advice

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.