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 15 of 15

Thread: Transform-feedback / glGetAttribLocation

  1. #11
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Going to put everything that is needed in the tff-function now and not to call my standard-shader-compiling-function. Might take a while...

  2. #12
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Here it is as solid function - still returning GL_INVALID_OPERATION after glBeginTransformFeedback

    Note that the "clsControl *Control" is only needed to access the error-output, which still uses the standerd-function of my program. Therefore also the handels from there ("Control->prgNewHandle" etc.) are used.

    Code :
    void ParseDrawRenderTFF(clsControl *Control, clsLst &list) {
     
        Print("ENTER TFF-FUNCTION");                                                            CheckGL("Errors left in cue");
     
        char *vShLinkC___ =                      "\n"
            "#version 330                         \n"
            "                                     \n"
            "in  float tffInput;                  \n"
            "out float cppReturn;                 \n"
            "                                     \n"
            "void main() {                        \n"
            "                                     \n"
            "    cppReturn = sqrt ( tffInput );   \n"
            "}                                    \n";   
     
        char *fShLinkC___ =                      "\n"
            "in float cppReturn;                  \n"
            "out vec4 color;                      \n"
            "                                     \n"
            "void main() {                        \n"
            "                                     \n"
            "    color = vec4(cppReturn);         \n"
            "}                                    \n";    
     
        const GLchar* feedbackVaryings[] = { "cppReturn" };    
    //    Control->vShLinkC = vShLinkC___;Control->fShLinkC = fShLinkC___;
     
     
        Control->vShNewHandle  = glCreateShader  (GL_VERTEX_SHADER); 
        Control->fShNewHandle  = glCreateShader  (GL_FRAGMENT_SHADER);   
        Control->prgNewHandle  = glCreateProgram ();                                            CheckGL("glCreateProgram");
     
        Control->success       = GL_FALSE;                                                     
        Control->errHandle     = Control->vShNewHandle;   
        glShaderSource          (Control->vShNewHandle, 1, &vShLinkC___, NULL);                 CheckGL("glShaderSource     (Control->vShNewHandle, 1, &vShLinkC___, NULL);");
        glCompileShader         (Control->vShNewHandle);                                        CheckGL("glCompileShader    (Control->vShNewHandle);");
        glGetShaderiv           (Control->vShNewHandle, GL_COMPILE_STATUS, &Control->success);  if     (Control->success != GL_TRUE) goto ex;
        glAttachShader          (Control->prgNewHandle, Control->vShNewHandle);                 CheckGL("glAttachShader     (prgNewHandle, vShNewHandle);");
     
        Control->success       = GL_FALSE;                                                     
        Control->errHandle     = Control->fShNewHandle;   
        glShaderSource          (Control->fShNewHandle, 1, &fShLinkC___, NULL);                 CheckGL("glShaderSource     (Control->fShNewHandle, 1, &fShLinkC___, NULL);");
        glCompileShader         (Control->fShNewHandle);                                        CheckGL("glCompileShader    (Control->fShNewHandle);");
        glGetShaderiv           (Control->fShNewHandle, GL_COMPILE_STATUS, &Control->success);  if     (Control->success != GL_TRUE) goto ex;
        glAttachShader          (Control->prgNewHandle, Control->fShNewHandle);                 CheckGL("glAttachShader     (prgNewHandle, fShNewHandle);");
     
     
        glTransformFeedbackVaryings (Control->prgNewHandle, 0, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);  CheckGL("glTransformFeedbackVaryings");  
     
    //    glBindAttribLocation        (prgNewHandle, 0, "tffInput");                               CheckGL("glBindAttribLocation");  
     
        Control->success       = GL_FALSE;                                                     
        Control->errHandle     = Control->prgNewHandle;   
        glLinkProgram           (Control->prgNewHandle);                                        CheckGL("glLinkProgram"); 
        glUseProgram            (Control->prgNewHandle);                                        CheckGL("glUseProgram"); 
        glGetProgramiv          (Control->prgNewHandle, GL_LINK_STATUS,   &Control->success);   if     (Control->success != GL_TRUE) goto ex;
     
     
     
     
        if                      (Control->success != GL_FALSE)   {
     
            Control->OutStatus               (); 
     
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
     
     
            glDisable(GL_TEXTURE_2D);                                               CheckGL("Error left in cue");  
    //    theorie:
    //    ----------------
    //    Shader ist bereits aktiviert. Enthält:
    //      in  float tffInput; 
    //      out float cppReturn
    //
    //    VAO erzeugen (noch nie gemacht - wofür?)
            GLuint vao;
            glGenVertexArrays(1, &vao);
            glBindVertexArray(vao);                                                 CheckGL("VAO-Creation");  
     
    //    Array von "list" erzeugen
            GLfloat data[list.size];                    
            for (int i=0; i < list.size; i++) data[i] = list[i][0];
     
    //    Aktiven Shader-Programm-Index ermitteln
            GLint prg;
            glGetIntegerv(GL_CURRENT_PROGRAM, &prg);
            Print(tostr(prg) + " - " + tostr(curPRG));
     
    //    VBO von array" erzeugen
            GLuint vbo;
            glGenBuffers(1, &vbo);
            glBindBuffer(GL_ARRAY_BUFFER, vbo);
            glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);      CheckGL("VBO-Creation");  
     
    //    Übergabeadress für Attribut "inValue" ermitteln
     
    //        glBindAttribLocation(prg, 0, "tffInput");                               CheckGL("glBindAttribLocation");  
     
            GLint tffInput = glGetAttribLocation(prg, "tffInput");                  CheckGL("glGetAttribLocation");  
    //
            Print ("Index of tffInput: " + tostr(tffInput));
     
            glEnableVertexAttribArray(tffInput);                                    CheckGL("glEnableVertexAttribArray"); 
     
     
            glVertexAttribPointer(tffInput, 1, GL_FLOAT, GL_FALSE, 0, 0);           CheckGL("glVertexAttribPointer"); 
     
    //    Gleich großen Zielbuffer erzeugen mit
            GLuint tbo;
            glGenBuffers(1, &tbo);
            glBindBuffer(GL_ARRAY_BUFFER, tbo);
            glBufferData(GL_ARRAY_BUFFER, sizeof(data), NULL, GL_STATIC_READ);      CheckGL("TBO-Creation");  
     
    //    PROZESS:
            glEnable(GL_RASTERIZER_DISCARD);                                        CheckGL("glEnable(GL_RASTERIZER_DISCARD)"); 
            glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo);                 CheckGL("glBindBufferBase"); 
     
            glBeginTransformFeedback(GL_POINTS);                                    CheckGL("glBeginTransformFeedback"); 
                glDrawArrays(GL_POINTS, 0, list.size);                              CheckGL("glDrawArrays"); 
            glEndTransformFeedback();                                               CheckGL("glEndTransformFeedback"); 
     
            glFlush();                                                              CheckGL("glFlush"); 
     
    //    Ergebnis auslesen:
            GLfloat feedback[list.size];
            glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(data), feedback);
     
            Print(tostr(data[0]) + " - " + tostr(feedback[1]) + " - " + tostr(feedback[2]) + " - " + tostr(data[3]) + " - " + tostr(data[4]));
    //    Aufräumen:
            // glDisable           (GL_RASTERIZER_DISCARD);    muss nicht - ist in ResetGL();
     
            glBindBuffer(GL_ARRAY_BUFFER, 0);
            glDeleteBuffers(1, &tbo);
            glDeleteBuffers(1, &vbo);
            glDeleteVertexArrays(1, &vao);
        }
     
    ex: if(Control->success != GL_TRUE)Control->OutStatus               (); 
     
        glUseProgram            (0);        
        glDeleteProgram         (Control->prgNewHandle);
        glDeleteShader          (Control->vShNewHandle); 
        glDeleteShader          (Control->fShNewHandle); 
    }



    At his point, there is nothing really left anymore, which i could simplify. Also the shader-program is not kept, but just created for a single call. Only the function ResetGL is still used as i posted it before. I also red the documentation here https://www.khronos.org/registry/Ope...Feedback.xhtml. But i don't find any reason concerning the GL_INVALID_OPERATION -error, that seems possible to me....
    Last edited by art-ganseforth; 10-02-2018 at 11:00 AM.

  3. #13
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,955
    Quote Originally Posted by art-ganseforth View Post
    Here it is as solid function - still returning GL_INVALID_OPERATION after glBeginTransformFeedback
    According to the glBeginTransformFeedback() reference page:

    GL_INVALID_OPERATION is generated if glBeginTransformFeedback is executed while transform feedback is active.
    ...
    GL_INVALID_OPERATION is generated by glBeginTransformFeedback if any binding point used in transform feedback mode does not have a buffer object bound.
    ...
    GL_INVALID_OPERATION is generated by glBeginTransformFeedback if no binding points would be used, either because no program object is active or because the active program object has specified no varying variables to record.
    The call to glTransformFeedbackVaryings() in the code you've shown has a count of zero, which would correspond to the last of the three reasons above:
    Quote Originally Posted by art-ganseforth View Post
    Code :
        glTransformFeedbackVaryings (Control->prgNewHandle, 0, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);

  4. #14
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Wow!!! This it was!

    You won't believe how much i thank you for this!!!

    This tff-thing is most important for me. I have this interpreter, which can control my UI, calculate GLfloats, handle strings and can call gl-functions. But it's not usable for bigger amounts of data-calculations. I always thougth to give this to GPU, but comute-shaders are far away for my skills. For the moment this is a good solution. Now i can combine my interpreter-functions with things done on GPU.

    So, i'll start to figure out the possibilities now...


    Best,
    Frank

  5. #15
    Intern Contributor
    Join Date
    Apr 2016
    Location
    Berlin / Germany
    Posts
    61
    Addendum:

    That's fantastic! I have intgrated a (first) type of tff-functions now and porgrammed a shader, that calculates a complete VAO for drawing geometrical objects, like a torus, a sphere, moving waverings etc. with (uniform) parameters, set by controls of my UI. All of this was done by CPU in before. The resolution of my objects is ~10x finer then before without losing frames.


    Best,
    Frank

Posting Permissions

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