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 :

[highlight=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 :

[highlight=c++]
    static const GLchar * vertex_shader_source[] =
    {
                ...
                ...
        "layout(location = 0) in vec3 vertexPosition_modelspace; 
"
        "layout(location = 1) in vec3 vertexColor_modelspace; 
"
                ...
                ...
        "void main(void)                             
"
        "{                                           
"
        "    gl_Position = pMat * vec4(vertexPosition_modelspace, 1.0); 
"
        "    fragmentColor = vertexColor_modelspace; 
"
        "}                                           
"
    };

    static const GLchar * fragment_shader_source[] =
    {
                ...
                ...
        "in vec3 fragmentColor;                   
"
        "out vec3 color;                            
"
        "void main(void)                            
"
        "{                                          
"
        "    color = fragmentColor ;      
"
        "}                                          
"
    };
        ...
        ...
        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.

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”).

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.

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.

Thank you for answer! :slight_smile:
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.

A VBO is just an array of numbers stored in video memory. A shader is a program which runs on the GPU.

Yes. I understand your answer!.

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

Thank you for answer me:)
best regards.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.