Opengl, DrawArrays without VBO binding

I get an array of points with a custom vertex shader. Shaders look like this:

void mainVP() in varying int in_vertex_id : VERTEXID { foo(in_vertex_id); } 

So the only thing I need is the vertex identifier. But I need a lot of vertices, and I don’t want to store fake VBOs for them (it takes about 16 MB of memory).

I tried to run my code without binding to VBO. It is working. So my rendering is as follows:

 size_t num_vertices = ... glDrawArrays(GL_POINTS, 0, num_vertices); 

But can I be sure that rendering without binding to VBO is safe?

+6
source share
1 answer

But can I be sure that rendering without binding to VBO is safe?

You can not.

The base profile of the OpenGL specification (3.2 and above) clearly states that it must be enabled so that you can display all disabled attributes. The compatibility profile of the OpenGL specification, or any version prior to 3.2, also clearly indicates that you cannot do this.

Of course, that doesn't matter. NVIDIA drivers allow you to do this in any version and profile of OpenGL. ATI drivers do not allow you to do this in any version or profile of OpenGL. Both of them are driver errors, in different ways.

You just need to recognize that you need a dummy vertex attribute. However:

But I need a lot of vertices, and I don’t want to store fake VBOs for them (it takes about 16 MB of memory).

The dummy attribute will occupy 4 bytes (one float or 4-vector of normalized bytes. Remember: you do not need data). So you could place 4 million of them in 16 MB.

Alternatively, you can use instance rendering through glDrawArraysInstanced. There you simply render one vertex, but with instances of num_vertices . Of course, your shader will have to use the instance id.

+9
source

Source: https://habr.com/ru/post/900955/


All Articles