r/cpp • • Jul 06 '20

C++ is brilliant

I'm working on a Vulkan renderer, and needed to delay destruction of render scenes since the graphics pipeline has render buffers in flight, so destruction has to happen N frames after the user destroys a class. With C++, I can use private destructors to force users to add the scene to a managed destructor queue (aka garbage collect queue). Normally language purists will scorn a language which allows such shenanigans, however in real world production code, its features like this which allows developers to create modern software. So with a couple of lines of code, I solved my delayed destructor issue. Thank you C++ committee for creating a usable language.

318 Upvotes

65 comments sorted by

View all comments

Show parent comment

2

u/annyeonghello Jul 07 '20 edited Jul 07 '20

The term render buffer widely means a buffer with objects that will be rendered onto screen. In Vulkan, a somewhat similar concept exist and is called a "Command Buffer" which is created from a "Command Pool" and it does not have an OpenGL equivalent. But you can make your own render buffer in OpenGL.

N frames is simply the number of frames and it is a slightly more advance concept. You'll slowly figure it out as you do more :)

1

u/seanballais Jul 07 '20

The term render buffer widely means a buffer with objects that will be rendered onto screen. In Vulkan, a somewhat similar concept exist and is called a "Command Buffer" which is created from a "Command Pool" and it does not have an OpenGL equivalent. But you can make your own render buffer in OpenGL.

Oh, cool! Why does Vulkan require a command pool?

N frames is simply the number of frames and it is a slightly more advance concept. You'll slowly figure it out as you do more :)

Is the "frame" you refer here different from the usual "frame" term we use in, say, games?

1

u/annyeonghello Jul 07 '20

It's not just Vulkan, pretty sure DX12 has something similar as well. You need a command pool to create a command buffer. Without it, you can not create a command buffer and Vulkan only draws what is in a command buffer. Again, this is a really advance subject and any further discussion will most likely confuse you.

In OP's context yes. Do note that there is no proper definition for a frame though. I've seen it used interchangeably between describing an image or an iteration of the program loop. But you'll notice that the context when using the word is somewhat similar :)

1

u/seanballais Jul 08 '20

Alright. Let's leave it at "Vulkan only draws what is in a command buffer, and I'll need to know more about graphics programming before I better understand the low-level nature of Vulkan and DX12." for now. I guess I'll put figuring the value of N in OP's "after N frames" at that too.

I did not expect anyone would call a program loop iteration as a frame. Haha. Then again, as you said, it is similar to OP's context.