-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Use unique_resource for GL objects #5172
Conversation
namespace mbgl { | ||
namespace gl { | ||
|
||
constexpr GLsizei TextureMax = 64; | ||
|
||
using UniqueObject = std_experimental::unique_resource<GLuint, std::function<void(GLuint)>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using std::function
polymorphism, create a unique *Deleter
functor and Unique*
typedef for each resource type as sketched in #5141 (comment). This adds additional type safety: mistaken use of the wrong resource type will be a compile time error.
d59f361
to
1dfa2db
Compare
Changes since last review:
|
4d59236
to
37ff9e6
Compare
69bf354
to
927c00c
Compare
if (buffer.created()) { | ||
MBGL_CHECK_ERROR(glBindBuffer(bufferType, getID())); | ||
if (buffer) { | ||
MBGL_CHECK_ERROR(glBindBuffer(bufferType, (*buffer).get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't *buffer
work, using the unique_resource
implicit conversion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept .get()
to keep in sync with the other Unique*
usage elsewhere, but your suggestion looks better, thanks!
3298927
to
c7e697f
Compare
@brunoabinader this is looking really nice. Do you think it would be possible to make utests for these holders? (not just that, but also the other wrappers we have for GL stuff) |
Source: https://github.com/okdshin/unique_resource These replace the complexity of manually handling moveable-RAII objects with a type specific for that purpose. As suggested in #5141 (comment).
c7e697f
to
3175358
Compare
Neat, thanks for adding the tests. |
Source: https://github.com/okdshin/unique_resource
These replace the complexity of manually handling moveable-RAII objects with a type specific for that purpose.
As suggested in #5141 (comment).
👀 @jfirebaugh @kkaefer @tmpsantos @1ec5