Sign in to follow this  

Can you use integers as bools in HLSL just like in C++?

This topic is 1919 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

In C++ you can have:
[CODE]

int a = 5;
if(a)
{
for(int i = 0;i < a: i++)
{
DoSomething();
}
}

[/CODE]
Can you do the same in HLSL?If you could,it would be really convenient to both check if an effect is enabled to begin with and to serve as a parameter to the said effect.

Share this post


Link to post
Share on other sites
There is no such thing as "null" in HLSL. Integers used as conditionals work similarly to how they do in C/C++, where non-zero values equate to a value of "true".

Share this post


Link to post
Share on other sites
[quote name='mrheisenberg' timestamp='1350252000' post='4990161']
In C++ you can have:
[CODE]

int a = 5;
if(a)
{
for(int i = 0;i < a: i++)
{
DoSomething();
}
}

[/CODE]
Can you do the same in HLSL?If you could,it would be really convenient to both check if an effect is enabled to begin with and to serve as a parameter to the said effect.
[/quote]

it works perfectly, but i would still do the additional

if(a != 0)
// readability

Share this post


Link to post
Share on other sites

This topic is 1919 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this