A Texture Flag System

Started by
1 comment, last by CloudNine 20 years, 10 months ago
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
Advertisement
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; // defaultUINT levels = 1; // default, no mipmappingif (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

Would turning it into a binary string, and going through the numbers one by one help?

Thanks for the advice

This topic is closed to new replies.

Advertisement