mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Add C++ API and example for borrowing OpenGL textures
This commit is contained in:
parent
eadfec64a3
commit
f51ca82f10
3 changed files with 314 additions and 50 deletions
|
@ -68,6 +68,42 @@ private:
|
|||
SharedVector<Pixel> m_data;
|
||||
};
|
||||
|
||||
/// This structure contains fields to identify and render an OpenGL texture that Slint borrows from
|
||||
/// the applicatin code. Use this to embed a native OpenGL texture into a Slint scene, by
|
||||
/// constructing the `BorrowedOpenGLTexture` and then a `Image` from it.
|
||||
///
|
||||
/// The ownership of the texture remains with the application. It is the application's
|
||||
/// responsibility to delete the texture when it is not used anymore.
|
||||
///
|
||||
/// Note that only 2D RGBA textures are supported.
|
||||
struct BorrowedOpenGLTexture
|
||||
{
|
||||
public:
|
||||
BorrowedOpenGLTexture() = delete;
|
||||
/// Constructs a new BorrowedOpenGLTexture with the given \a texture_id and \a size. The \a
|
||||
/// texture_id and \a size must be non-zero. The underlying texture must be a 2D RGBA texture
|
||||
/// and ownership remains with the caller.
|
||||
BorrowedOpenGLTexture(uint32_t texture_id, Size<unsigned int> size) : inner { texture_id, size }
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the OpenGL texture id.
|
||||
uint32_t texture_id() const { return inner.texture_id; }
|
||||
/// Returns the size of the texture in pixels.
|
||||
Size<unsigned int> size() const { return inner.size; }
|
||||
|
||||
/// Compares two borrowed OpenGL textures. They are considered equal if all their ids and sizes
|
||||
/// are equal.
|
||||
bool operator==(const BorrowedOpenGLTexture &other) const = default;
|
||||
/// Compares two borrowed OpenGL textures. They are considered equal if any of their ids and
|
||||
/// sizes differ.
|
||||
bool operator!=(const BorrowedOpenGLTexture &other) const = default;
|
||||
|
||||
private:
|
||||
cbindgen_private::types::BorrowedOpenGLTexture inner;
|
||||
friend struct Image;
|
||||
};
|
||||
|
||||
/// An image type that can be displayed by the Image element
|
||||
///
|
||||
/// You can construct Image objects from a path to an image file on disk, using
|
||||
|
@ -143,6 +179,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
/// Construct an image from a borrowed OpenGL texture.
|
||||
Image(BorrowedOpenGLTexture texture)
|
||||
: data(Data::ImageInner_BorrowedOpenGLTexture(texture.inner))
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the size of the Image in pixels.
|
||||
Size<unsigned int> size() const { return cbindgen_private::types::slint_image_size(&data); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue