rufuss
rufuss

Reputation: 60

What is the difference between glGenRenderbuffers and glCreateRenderbuffers?

SPEC:

  1. glCreateRenderbuffers: glCreateRenderbuffers — create renderbuffer objects

void glCreateRenderbuffers(GLsizei n, GLuint *renderbuffers);

n: Number of renderbuffer objects to create. renderbuffers: Specifies an array in which names of the new renderbuffer objects are stored.

glCreateRenderbuffers returns n previously unused renderbuffer object names in renderbuffers, each representing a new renderbuffer object initialized to the default state.

  1. glGenRenderbuffers — generate renderbuffer object names void glGenRenderbuffers(GLsizei n, GLuint *renderbuffers);

n: Specifies the number of renderbuffer object names to generate. renderbuffers: Specifies an array in which the generated renderbuffer object names are stored.

glGenRenderbuffers returns n renderbuffer object names in renderbuffers. There is no guarantee that the names form a contiguous set of integers; however, it is guaranteed that none of the returned names was in use immediately before the call to glGenRenderbuffers.

Renderbuffer object names returned by a call to glGenRenderbuffers are not returned by subsequent calls, unless they are first deleted with glDeleteRenderbuffers.

The names returned in renderbuffers are marked as used, for the purposes of glGenRenderbuffers only, but they acquire state and type only when they are first bound.

so what is the difference between them?

I've tried to use glCreateRenderbuffers to replace glGenRenderbuffers in learn OpenGL tutorial https://learnopengl.com/Advanced-OpenGL/Framebuffers but it reports an error.

Upvotes: 1

Views: 243

Answers (1)

user7860670
user7860670

Reputation: 37582

glGenRenderbuffers is part of the established OpenGL API available since v3. This function only generates object handles ("names"). They become reserved so other OpenGL functions producing object names won't use them until generated handles are destroyed via call to glDeleteRenderbuffers. But otherwise these handles are not actually associated with backing object until they are bound to pipeline via call to glBindRenderbuffer for the first time and pretty much useless until that point.

In contrast glCreateRenderbuffers is part of Direct State Access extension and also available in the later versions of OpenGL API since v4.5 (so it will cause an error if you are using older API without extension). The core idea of this extension was to reduce need for indirect access to object that is currently bound to pipeline. Functions from this extension accept object handles so only a single call is required instead of going through bind object -> do something -> unbind object sequence. glCreateRenderbuffers not only generates object names, but also creates backing objects without any additional calls so produced object handles can be immediately used.

A good introduction into DSA extension as part of OpenGL 4.5 could be found in Nvidia GTC presentation.

Upvotes: 3

Related Questions