Problem about use struct as parameter or return value of function in fragment shader

This topic contains 2 replies, has 2 voices, and was last updated by  Arron 3 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #31585

    xie_dev
    Member

    hi all.
    I am new to OpenGLES2.0. I use PowerVR in my project on win7 platform. Recently I wirte a fragment shader, it has a compile error but I do not know why.

    This is my shader code:


    struct STestStruct
    {
    mediump vec4 kValue;
    };
    void TestFun( out STestStruct kParam )
    {
    kParam.kValue = vec4(1,0,0,0);
    }
    void main ()
    {
    STestStruct kStruct;
    TestFun( kStruct );
    gl_FragColor = kStruct.kValue;
    };

    The error message is: “Compile failed. ERROR: 0:1: ‘TestFun’ : no matching overloaded function found“.

    I do not know, so I change my shader code as below:


    struct STestStruct
    {
    mediump vec4 kValue;
    };
    STestStruct TestFun()
    {
    STestStruct kParam;
    kParam.kValue = vec4(1,0,0,0);
    return kParam;
    }
    void main ()
    {
    STestStruct kStruct = TestFun();
    gl_FragColor = kStruct.kValue;
    };

    But there is also has a error : ‘return’ : function return is not matching type.

    Is there a problem with my shader code? Wish somebody can help me. Thanks very much!

    #38315

    xie_dev
    Member

    oh… maybe I found the reason in the document “Structure declarations are not permitted as part of parameter declarations or return type declarations.”

    #38316

    Arron
    Member

    Hi,
    You first example shader appears to be valid and compiles successfully with PVRShaderEditor and SGX 1.9 compilers (apart from the small syntax error appending the semicolon to the end of the main() scope braces). Did you solve this problem and/or are you targeting a particular device?

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.