Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Question about OpenGL : difference between VBO & Shader

  1. #1
    Newbie Newbie
    Join Date
    Aug 2018
    Posts
    3

    Arrow Question about OpenGL : difference between VBO & Shader

    Hello! I have an question about difference between VBO & Shader!!
    Thank you for read this question!.




    Above all, I want to show part of the codes that draw a cube(VBO and Shader). Ofcourse that codes work well.
    Through this, I want you understand two terms(VBO and Shader) properly.


    VBO :

    Code c++:
            ...
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
            ...
            ...
        glVertexPointer(3, GL_FLOAT, 0, 0);
            ...
            ...
        glColorPointer(3, GL_FLOAT, 0, 0);
     
            glDrawArrays(GL_TRIANGLES, 0, 36);
     
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);

    Shader :

    Code c++:
        static const GLchar * vertex_shader_source[] =
        {
                    ...
                    ...
            "layout(location = 0) in vec3 vertexPosition_modelspace; \n"
            "layout(location = 1) in vec3 vertexColor_modelspace; \n"
                    ...
                    ...
            "void main(void)                             \n"
            "{                                           \n"
            "    gl_Position = pMat * vec4(vertexPosition_modelspace, 1.0); \n"
            "    fragmentColor = vertexColor_modelspace; \n"
            "}                                           \n"
        };
     
        static const GLchar * fragment_shader_source[] =
        {
                    ...
                    ...
            "in vec3 fragmentColor;                   \n"
            "out vec3 color;                            \n"
            "void main(void)                            \n"
            "{                                          \n"
            "    color = fragmentColor ;      \n"
            "}                                          \n"
        };
            ...
            ...
            glUseProgram(program);
            glDrawArrays(GL_TRIANGLES, 0, 36);
            ...
            ...

    Thank you for read.. and my question list is..

    1. Whether two options(VBO and Shader) use video card memory or not
    2. Which is faster
    3. Which is proper for use
    4. Etc.


    If you answer about upper questions, I really appreciate for you!.
    Cheers.
    Last edited by Dark Photon; 08-21-2018 at 07:34 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,926
    Quote Originally Posted by asnyyy View Post
    VBO :

    Code c++:
            ...
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
            ...
            ...
        glVertexPointer(3, GL_FLOAT, 0, 0);
            ...
            ...
        glColorPointer(3, GL_FLOAT, 0, 0);
     
        glDrawArrays(GL_TRIANGLES, 0, 36);
     
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
    There are no references to VBOs here. It's implied that VBOs are used, because otherwise you're passing null pointers to glVertexPointer() and glColorPointer() (in C++, you should use "(GLvoid *)0" rather than just "0").

    Quote Originally Posted by asnyyy View Post
    1. Whether two options(VBO and Shader) use video card memory or not
    Yes.

    VBOs are likely to be stored in video memory. That's the whole point of VBOs. And to clarify, a VBO (vertex buffer object) is a buffer object bound to GL_ARRAY_BUFFER. If a buffer is bound to that target prior to calling glVertexPointer() etc, then the vertex data will be sourced from the buffer. If no buffer is bound, the data will be sourced from system memory. But in the above code, if no buffer is bound then the data would be sourced from address zero, which will likely trigger an exception.

    Shader programs have to be stored in video memory in order for the GPU to execute them.

    Quote Originally Posted by asnyyy View Post
    2. Which is faster
    3. Which is proper for use
    VBOs and shaders aren't mutually exclusive. Prior to 3.1 and in 3.2+ compatibility profile, you can use VBOs with or without shaders, shaders with or without VBOs. In 3.1 and in 3.2+ core profile, both VBOs and shaders are required: client-side vertex arrays aren't supported, nor is the fixed-function pipeline.

  3. #3
    Newbie Newbie
    Join Date
    Aug 2018
    Posts
    3

    Tank you for reply

    Thank you for answer!
    I really appreciate for this answer!.






    and.. what is difference between VBO and Shader?...


    1 "Shader programs have to be stored in video memory in order for the GPU to execute them" and "VBOs are likely to be stored in video memory".

    In this case, GPU execute VBOs too?
    Otherwise, CPU execute VBOs(which is stored in video memory)? or CPU take VBOs from video memory to RAM and then execute this?



    2 Are there any other differences( for example, speed etc...) between VBO and Shader?....




    Thank you for read this question!
    And please answer me one more time.

    best regard.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,926
    Quote Originally Posted by asnyyy View Post
    and.. what is difference between VBO and Shader?...
    A VBO is just an array of numbers stored in video memory. A shader is a program which runs on the GPU.

  5. #5
    Newbie Newbie
    Join Date
    Aug 2018
    Posts
    3

    Thank you for reply

    Yes. I understand your answer!.


    Through this, I will search more information about this theme.


    Thank you for answer me
    best regards.

Posting Permissions

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