Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Concerning combining shaders

  1. #11
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Oh, that explains a lot. ...
    I did not know this but for some reasons i suspected something like this - at least since i had to set a special gluexperimental (or something like this) -flag to avoid crashes usig glTranformfeebackveryings...

    FYI: no, there doesn't have to be an array. Your VAO can be completely empty, with no attached buffer objects, so long as you're only using built-in input variables.
    Okay... But, without "glBufferData(GL_ARRAY_BUFFER, size, data, ......);", with data might be NULL, it won't work. As far as i understand this, the GPU is caused to allocate an array of type GL_ARRAY_BUFFER, and a given size.

    So....
    There is an existing array and one to be allocated - either as source or as destination. But there are needed always two, even if one isn't filled with data (NULL-pointer). For me that means: giving a ram-pointer (sorry, don't know how to express it better) will cause the CPU to tranfer data to GPU. Using NULL as data-pointer does not.

    Now my destination is (re)written. Therefore i don't care what is inside (tt may be trash-data from compleatly other things), but the source-data i need in some cases (when i use it as source for feedbacks).
    As explained i have to allocate (glBufferData) the memory anyway. So i see no reason, why i sould not allocate a new destination instead of a temporary source, to simply swap pointers after drawing and to be free to use or to ignore / overwrite the previous data in the shader-program or to use it as feedback-souce.

    So... what happens if you want to render two spheres in two different locations?
    Again: Puh!
    Almost nothing in my program is fixed. It has it's own programming-lanuage, that is controlling everything. So, what happens if.... depends on what you program, like i.e. this, which is one of the text-file interpreted by my interpreter to create vertex-arrays:
    Code :
        var Type         = "MACRO";
        var Title        = 'Render TFF';
     
        InitControl      ( Type, __File, 'Array functions');
        LinkTimer        ( _T_THREAD_IDX_ARRAYS );
     
        SetPosition      ( x,  y);
        SetSize          ( 1,  2);
     
        var TitleBar     = new titleBar ('_MD_BUTTONS_ALL', '_MD_STORE_TEXTURE_MENU');
            TitleBar     : ModuleMenu   : CommandItem (20, "Save array as CSV");  
            TitleBar     : ModuleMenu   : CommandItem (21, "Save vertex-shader");  
     
        var OnMenu       = '
            if (caller.MenuValue == 20) {
                SaveArray("txt", _DYNAMIC_FOLDER + "Array functions/" + CreateFileName("Vertex-array") );
            };
            if (caller.MenuValue == 21) {
                Shader.VertexShader.Save(_DYNAMIC_FOLDER + "Array functions/" + (parent.CreateFileName("Vertex-shader")) );
            };
    '; 
     
        var Shader       = new IncludeShader ( 0, 0, (_DYNAMIC_FOLDER + "Array functions/shader/shader-vbo.txt"));
     
            Shader       : AddUniforms  ('
    uniform   float DrawType;
    uniform   vec2  MapSize;
    uniform   vec2  Cc1;
    uniform   vec4  Cc2;
    ');
     
        var vcW          = new valAny   ('Width',          3.0, 0,  3.0,     1, 500,   1,    24);
        var vcH          = new valAny   ('Height',         6.0, 0,  3.0,     1, 500,   1,    24);
     
        var vc1          = new valAny   ('Cc1.x',           0.0, 1,  3.0,     0,   1,   0.01,  0.25);
        var vc2          = new valAny   ('Cc2.x',           3.0, 1,  3.0,     0,   1,   0.01,  1);
        var vc3          = new valAny   ('Cc2.y',           6.0, 1,  3.0,     0,   1,   0.01,  1);
        var vc4          = new valAny   ('Cc2.z',           9.0, 1,  3.0,    -1,   1,   0.01,  0);
        var vc5          = new valAny   ('Cc2.r',          12.0, 1,  3.0,    -1,   1,   0.01,  0);
     
        var OnPrepare    = '0;';
     
        var OnNext       = '
     
            Shader       . Apply        ( "", GlobalUniforms, "tff_out", 8);
     
            PrepareArray ( vcW.GetInt(), vcH.GetInt(), 4, "tff_in", GL_T2F_N3F_V3F);
     
            Shader       . glUniform    ( "DrawType", GL_QUADS ); 
            Shader       . glUniform    ( "MapSize",  vcW.GetInt(), vcH.GetInt() ); 
            Shader       . glUniform    ( "Cc1",      vc1.Get01(),  vc2.Get01()  ); 
            Shader       . glUniform    ( "Cc2",      vc2.Get01(),  vc3.Get01(),  vc4.Get01(),  vc5.Get01() ); 
     
            RefeedArray  ();
     
         //   ResetGL      ();
    ';
     
        var OnApply      = '
            DrawInterleaved ( GL_T2F_N3F_V3F, GL_QUADS );
     
    ';

    So, if i want to use a sphere-vertex-array several times, i add several times
    [code]
    glPush();
    glTranlate3f(vc1.GetValue(), vc2.GetValue(), vc3.GetValue());
    DrawInterleaved ( GL_T2F_N3F_V3F, GL_QUADS );
    glPop();
    [code]
    ... to the OnApply-string. And the vertex-array will be drawn several times on different positions.

    As all of this is kept in strings and interpreted by my interpreter at runtime. Therfore there is, just some copy/paste needed, to draw the same array several times.



    Best,
    Frank
    Last edited by art-ganseforth; 10-09-2018 at 07:48 PM.

  2. #12
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,048
    But, without "glBufferData(GL_ARRAY_BUFFER, size, data, ......);", with data might be NULL, it won't work.
    If that's the case, it is only because of your broken graphics drivers, not because of what OpenGL says or allows. Equally important, that line does not set a buffer to be used by a VAO. It is only `glVertexAttrib*Pointer` calls that attach a buffer to a VAO.

    My point is that if you are not using any user-defined vertex shader inputs, then you do not need buffers for the attributes that you are not actually using.

    And the vertex-array will be drawn several times on different positions.
    When I asked how that would work, I wasn't asking about some high-level scripting language. I wasn't asking what was responsible for making OpenGL calls. I was asking about what OpenGL commands you use to actually cause it to happen. How those commands get generated is essentially irrelevant.


    As for the specifics of what you wrote, you didn't really explain what you're doing. The code you posted suggests that you are using fixed-function OpenGL to render your feedback-generated data, as the `glTranslate` call suggest. If so, then you're cannot be using a vertex shader of any kind. So your original question about "generating" your VS is kind of moot; you're not using a VS and you can't unless you're willing to ditch the fixed-function pipeline.

    And when it comes time to switch to a VS, you are going to have to send matrix data to the shader in order to do the equivalent of that `glTranslate` call. Which was part of my point: it will not be a "pass-through" vertex shader; it needs to do actual work.

    Lastly, you keep dodging my question: why are you using transform feedback at all, instead of just rendering the generated vertices directly? Do you think that writing and then reading memory is faster than executing shader code? Everything you are doing can be achieved without feedback, and unless your vertex generation code is exceedingly complex (FYI: spheres and torii are not), it will likely be faster without the feedback operation.

  3. #13
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Lastly, you keep dodging my question
    I'm very sory about this. I probably need a lot more experience, even to understand your questions.

    Like i.e.:
    instead of just rendering the generated vertices directly?
    ... where i've no idea, what "directly" or (as opposite) "indirectly" may mean.

    Also:
    Do you think that writing and then reading memory is faster than executing shader code?
    Surely not, but i don't really see where i do things like i.e. "writing and then reading memory". Might be, that i still don't understand what i'm doing. So i hope taht i don't lose motivation and i find the time to read some more tutorials these days.


    Best,
    Frank

  4. #14
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,048
    Quote Originally Posted by art-ganseforth View Post
    I'm very sory about this. I probably need a lot more experience, even to understand your questions.

    Like i.e.:

    ... where i've no idea, what "directly" or (as opposite) "indirectly" may mean.
    What you're doing is basically:

    1. Render using transform feedback to build some vertex data, using a vertex shader that generates vertex data.
    2. Render the stuff you built in step 1 to the screen.

    So you're "rendering" to generate vertex data. And then rendering the vertex data you generated. That's "indirectly" rendering, since it requires an intermediate step.

    What I'm saying you should do is:

    1. Render, using a vertex shader that generates vertex data, to the screen.

    No transform feedback, no writing to buffer objects, no intermediate step. You just take your VS that generates the vertex data and link it to the fragment shader that you would have used in your step 2. And you render with the same drawing command you would have used in step 1.

  5. #15
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Now i understand you.

    In fact, this helps to correct an older missunderstanding. A long time ago, i wanted to do so. The result was distorted which was (after now remembering this) surely some matrix-problem. That time, i posted some questions concerning this, but i probably missunderstood somesthing. So i thought this was not possible. Therefore i was not able to understand you.



    By the way:
    I know that for using more then one transformfeedback-varyings the function glTransformFeedbackVaryings takes an array of name-stings as parameter. Now i was wondering if it is also possible to use several calls. Like instead of calling it once with an array containing two names, calling it twice each time with one name?


    Best,
    Frank

  6. #16
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,048
    Quote Originally Posted by art-ganseforth View Post
    I know that for using more then one transformfeedback-varyings the function glTransformFeedbackVaryings takes an array of name-stings as parameter. Now i was wondering if it is also possible to use several calls. Like instead of calling it once with an array containing two names, calling it twice each time with one name?
    No. `glTransformFeedbackVaryings` sets *all* of the feedback variables, overriding all prior invocations of this function on that program (before linking).

  7. #17
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Thank you. I thougt so, but i was not sure...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •