Ultralight C++ API 1.4.0
|
#include <Ultralight/ImageSource.h>
User-defined image source to display custom images on a web-page.
This API allows you to composite your own images into a web-page. This is useful for displaying in-game textures, external image assets, or other custom content.
To use an ImageSource, you must first create an .imgsrc
file containing a string identifying the image source. This string will be used to lookup the ImageSource from ImageSourceProvider when it is loaded on a web-page.
The file format is as follows:
You can use the .imgsrc
file anywhere in your web-page that typically accepts an image URL. For example:
To composite your own GPU texture on a web-page, you should first reserve a texture ID from GPUDriver::NextTextureId() and then create an ImageSource from that texture ID. Next, you should register the ImageSource with ImageSourceProvider using the identifier from the .imgsrc
file.
When the image element is drawn on the web-page, the library will draw geometry using the specified texture ID and UV coordinates. You should bind your own texture when the specified texture ID is used.
To composite your own bitmap on a web-page, you should create an ImageSource from a Bitmap. Next, you should register the ImageSource with ImageSourceProvider using the identifier from the .imgsrc
file.
When the image element is drawn on the web-page, the library will sample this bitmap directly.
If you modify the texture or bitmap pixels after creating the ImageSource, you should call ImageSource::Invalidate() to notify the library that the image should be redrawn.
Static Public Member Functions | |
static RefPtr< ImageSource > | CreateFromTexture (uint32_t width, uint32_t height, uint32_t texture_id, const Rect &texture_uv, RefPtr< Bitmap > bitmap=nullptr) |
Create an ImageSource from a GPU texture with optional backing bitmap. | |
static RefPtr< ImageSource > | CreateFromBitmap (RefPtr< Bitmap > bitmap) |
Create an ImageSource from a Bitmap. | |
Public Member Functions | |
virtual uint32_t | width () const =0 |
Get the width of the image in pixels. | |
virtual uint32_t | height () const =0 |
Get the height of the image in pixels. | |
virtual uint32_t | texture_id () const =0 |
Get the GPU texture identifier to bind when drawing the quad for this image. | |
virtual Rect | texture_uv () const =0 |
Get the UV coordinates of the texture. | |
virtual RefPtr< Bitmap > | bitmap ()=0 |
Get the backing bitmap for this image source. | |
virtual void | Invalidate ()=0 |
Invalidate the image. | |
virtual void | AddListener (ImageSourceListener *listener)=0 |
Add a listener to the image source. | |
virtual void | RemoveListener (ImageSourceListener *listener)=0 |
Remove a listener from the image source. | |
Public Member Functions inherited from RefCounted | |
virtual void | AddRef () const =0 |
virtual void | Release () const =0 |
virtual int | ref_count () const =0 |
Protected Member Functions | |
ImageSource ()=default | |
virtual | ~ImageSource ()=default |
ImageSource (const ImageSource &)=delete | |
void | operator= (const ImageSource &)=delete |
Protected Member Functions inherited from RefCounted | |
virtual | ~RefCounted () |
|
protecteddefault |
|
protectedvirtualdefault |
|
protecteddelete |
|
pure virtual |
Add a listener to the image source.
listener | The listener to add. |
|
static |
Create an ImageSource from a Bitmap.
bitmap | The backing bitmap for this image source. |
|
static |
Create an ImageSource from a GPU texture with optional backing bitmap.
width | The width of the image in pixels (used for layout). |
height | The height of the image in pixels (used for layout). |
texture_id | The GPU texture identifier to bind when drawing the quad for this image. This should be non-zero and obtained from GPUDriver::NextTextureId(). |
texture_uv | The UV coordinates of the texture. |
bitmap | Optional backing bitmap for this image source. This is used when drawing the image using the CPU renderer or when pixel data is needed for other purposes. You should update this bitmap when the texture changes. |
|
pure virtual |
Get the height of the image in pixels.
|
pure virtual |
Invalidate the image.
This will notify the library that the image has changed and should be redrawn.
|
protecteddelete |
|
pure virtual |
Remove a listener from the image source.
listener | The listener to remove. |
|
pure virtual |
Get the GPU texture identifier to bind when drawing the quad for this image.
|
pure virtual |
Get the UV coordinates of the texture.
|
pure virtual |
Get the width of the image in pixels.