Define a kUtilityFramebuffer context attachment
A framebuffer object is often needed to render to a texture or read data from it. Currently we create one in each GlCalculatorHelper, but that is redundant (we only need one per context, and multiple calculators can share the same context). Other times, the code that needs to use this doesn't own a helper. For both reasons, this should be attached to the context. We could just make this a member of GlContext since it's so common. However, I figured we might as well use the attachment system. PiperOrigin-RevId: 490160214
This commit is contained in:
parent
54a684717f
commit
a8b7761022
|
@ -1054,4 +1054,16 @@ void GlContext::SetStandardTextureParams(GLenum target, GLint internal_format) {
|
||||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GlContext::Attachment<GLuint> kUtilityFramebuffer(
|
||||||
|
[](GlContext&) -> GlContext::Attachment<GLuint>::Ptr {
|
||||||
|
GLuint framebuffer;
|
||||||
|
glGenFramebuffers(1, &framebuffer);
|
||||||
|
if (!framebuffer) return nullptr;
|
||||||
|
return {new GLuint(framebuffer), [](void* ptr) {
|
||||||
|
GLuint* fb = static_cast<GLuint*>(ptr);
|
||||||
|
glDeleteFramebuffers(1, fb);
|
||||||
|
delete fb;
|
||||||
|
}};
|
||||||
|
});
|
||||||
|
|
||||||
} // namespace mediapipe
|
} // namespace mediapipe
|
||||||
|
|
|
@ -474,6 +474,12 @@ class GlContext : public std::enable_shared_from_this<GlContext> {
|
||||||
bool destructing_ = false;
|
bool destructing_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A framebuffer that the framework can use to attach textures for rendering
|
||||||
|
// etc.
|
||||||
|
// This could just be a member of GlContext, but it serves as a basic example
|
||||||
|
// of an attachment.
|
||||||
|
ABSL_CONST_INIT extern const GlContext::Attachment<GLuint> kUtilityFramebuffer;
|
||||||
|
|
||||||
// For backward compatibility. TODO: migrate remaining callers.
|
// For backward compatibility. TODO: migrate remaining callers.
|
||||||
ABSL_DEPRECATED(
|
ABSL_DEPRECATED(
|
||||||
"Prefer passing an explicit GlVersion argument (use "
|
"Prefer passing an explicit GlVersion argument (use "
|
||||||
|
|
Loading…
Reference in New Issue
Block a user