Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

can you assign an enum to a memory address of a shader?

This topic is 2584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im loading my shaders in and storing them into a stl map , with there name as an index

.
is there a way to store the address in an enum ie

enum EShader
{

phong = &addressOfShader("phong");
normal

}

any way of doing this

Share this post


Link to post
Share on other sites
Advertisement
You can only assign constants to the identifiers in enumerated types so that doesn't work.

You can define the enumerated type then force the loaded shaders to that index.



enum EShader
{
phong,
normal
};

//Then when you load it

if (name == "phong")
{
assignAddress(phong);
}

Share this post


Link to post
Share on other sites

You can only assign constants to the identifiers in enumerated types so that doesn't work.

You can define the enumerated type then force the loaded shaders to that index.



enum EShader
{
phong,
normal
};

//Then when you load it

if (name == "phong")
{
assignAddress(phong);
}





not sure how that works

,
with the way i did it it has to do a search of the map stl each time,
i would like to only do that to begin with , and then it can do it via the enums, or im i going about this wring ?

Share this post


Link to post
Share on other sites
How about something like this:



enum EShader
{
phong=0,
normal,
bumpmapped,
flatshaded,
NUM_SHADERS
};

//and an array of shaders:

shader* shaders[NUM_SHADERS];

//Then you can assign each one:

shaders[ phong] = addressOfShader("phong");
shaders[ normal] = addressOfShader("normal");



Then throughout your code you can just pass around the enum. You can even write the enum to disk (since its just an int), but I would be careful because if you add/remove things from the enum list as the code matures, your values might change. It might be safer to do:


#define SHADER_PHONG 0
#define SHADER_NORMAL 1


shaders[ SHADER_PHONG] = addressOfShader("phong");
shaders[ SHADER_NORMAL] = addressOfShader("normal");



Note, my style is a bit 'C' but works for C++ too. If you really want to use a stl map, then you can use it instead of an array. But an array is the simplest way to map integers to things, IMHO.

Share this post


Link to post
Share on other sites

with the way i did it it has to do a search of the map stl each time,
i would like to only do that to begin with , and then it can do it via the enums, or im i going about this wring ?


You are going about it wrong; assuming you have some sort of data structure which allows you to hold the details of the thing being rendered at load time you lookup the shader you want to use from the map and then store the pointer to it in that structure. Then at rendering time you can just directly access that pointer to the data which holds the shader information; you only ever look up the shader the once at load time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!