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.
ImageSource File Format
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:
<img src="my_custom_image.imgsrc" />
Creating from a GPU Texture
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.
- Note
- If the GPU renderer is not enabled for the View or pixel data is needed for other purposes, the library will sample the backing bitmap instead.
Creating from a Bitmap
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.
Invalidating Images
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.
|
| 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.
|
| virtual void | AddRef () const =0 |
| | Increment the reference count (thread-safe).
|
| virtual void | Release () const =0 |
| | Decrement the reference count (thread-safe).
|
| virtual int | ref_count () const =0 |
| | Get the current reference count.
|
| virtual WeakControlBlock * | weak_control_block () const |
| | Get the control block used to track weak references to this object.
|