Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7022935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:38:47+00:00 2026-05-27T23:38:47+00:00

According to http://msdn.microsoft.com/en-us/library/windows/desktop/bb509610(v=vs.85).aspx HLSL supports conditional operator (since version 2.0? I am using 4_0)

  • 0

According to

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509610(v=vs.85).aspx

HLSL supports conditional operator (since version 2.0? I am using 4_0)

I need to set blending state before each Draw call. In FX file I’m doing this:

BlendState BlendNone
{
    AlphaToCoverageEnable = FALSE;
    BlendEnable[0] = FALSE;
};
BlendState BlendSrcAlphaOne
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = INV_SRC_ALPHA;
    BlendOp = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};
BlendState BlendSrcAlphaOneMinusSrcAlpha
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = ONE;
    BlendOp = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};
int g_Blend;

technique10 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( CompileShader( gs_4_0, GS() ) );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );

        SetRasterizerState(rsCullNone);
        SetDepthStencilState( EnableDepth, 0 );

        if (g_Blend == 0)
        {
            SetBlendState( BlendNone, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
        else if (g_Blend == 1)
        {
            SetBlendState( BlendSrcAlphaOne, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
        else if (g_Blend == 2)
        {
            SetBlendState( BlendSrcAlphaOneMinusSrcAlpha, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
    }
}

This does not compile with error:
error X3000: syntax error: unexpected token ‘if’

If I move the whole block into a separate function like:

void setBlend()
{
        if (g_Blend == 0)
        {
            SetBlendState( BlendNone, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
        else if (g_Blend == 1)
        {
            SetBlendState( BlendSrcAlphaOne, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
        else if (g_Blend == 2)
        {
            SetBlendState( BlendSrcAlphaOneMinusSrcAlpha, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
}

technique10 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( CompileShader( gs_4_0, GS() ) );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );

        SetRasterizerState(rsCullNone);
        SetDepthStencilState( EnableDepth, 0 );

        setBlend();
    }
}

it doesn’t compile with error:
error X3000: this FX API is not available in this part your program (SetBlendState)

So, is if supported in HLSL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:38:47+00:00Added an answer on May 27, 2026 at 11:38 pm

    Ok, after lots of attempts and reading
    http://msdn.microsoft.com/en-us/library/windows/desktop/bb205052(v=vs.85).aspx#Blend

    This compiles:

    BlendState blendStates[3]
    {
        {
            AlphaToCoverageEnable = FALSE;
            BlendEnable[0] = FALSE;
        },
        {
            BlendEnable[0] = TRUE;
            SrcBlend = SRC_ALPHA;
            DestBlend = INV_SRC_ALPHA;
            BlendOp = ADD;
            RenderTargetWriteMask[0] = 0x0F;
        },
        {
            BlendEnable[0] = TRUE;
            SrcBlend = SRC_ALPHA;
            DestBlend = ONE;
            BlendOp = ADD;
            RenderTargetWriteMask[0] = 0x0F;
        }
    };
    int g_Blend;
    
    technique10 Render
    {
        pass P0
        {
            SetVertexShader( CompileShader( vs_4_0, VS() ) );
            SetGeometryShader( CompileShader( gs_4_0, GS() ) );
            SetPixelShader( CompileShader( ps_4_0, PS() ) );
    
            SetRasterizerState(rsCullNone);
            SetDepthStencilState( EnableDepth, 0 );
    
            SetBlendState( blendStates[g_Blend], float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
    }
    

    SetBlendState is not strictly a function call and conditional operators are not allowed inside the pass {}. However it’s allowed to pass array of state objects with index instead of just state objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to http://msdn.microsoft.com/en-us/library/aa916070.aspx (DnsQuery_W), DNS query libraries are available on Windows Mobile / CE
According to : http://msdn.microsoft.com/en-us/library/ms175061.aspx It says that the NOT LIKE relational operator : Specifies
According to http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.aspx , the LinkLabel class has both a Click event inherited from
First off, according to http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx , the List.Find method is only listed as throwing
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
According to the UserNamePasswordValidator sample on http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.usernamepasswordvalidator.aspx one should throw a SecurityTokenException if the
I'm using ICommandText::GetCommandText method. According to the MSDN documentation ( http://msdn.microsoft.com/en-us/library/ms709825(v=VS.85).aspx ) I need
According to the MSDN documentation ( http://msdn.microsoft.com/en-us/library/ms172987.aspx ), the My.Application.Log property is used to
Registered my program according to http://msdn.microsoft.com/en-us/library/aa767914.aspx . The association seems to be working, because
According to http://msdn.microsoft.com/en-us/library/ms687032%28v=vs.85%29.aspx , WaitForSingleObject() has undefined behavior if a handle gets closed while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.