Core renderer singleton for the library, coordinates all library functions.
The Renderer class is responsible for creating and painting Views, managing Sessions, as well as coordinating network requests, events, JavaScript execution, and more.
Creating the Renderer
- Note
- A Renderer will be created for you automatically when you call App::Create() (access it via App::renderer).
-
App::Create() is part of the AppCore API and automatically manages window creation, run loop, input, painting, and most platform-specific functionality. (Available on desktop platforms only)
Defining Platform Handlers
Before creating the Renderer, you should define your platform handlers via the Platform singleton. This can be used to customize file loading, font loading, clipboard access, and other functionality typically provided by the OS.
Default implementations for most platform handlers are available in the AppCore repo. You can use these stock implementations by copying the code into your project, or you can write your own.
At a minimum, you should provide a FileSystem and FontLoader otherwise Renderer creation will fail.
Setting Up the Config
You can configure various library options by creating a Config object and passing it to Platform::instance().set_config()
.
Creating the Renderer
Once you've set up the Platform handlers and Config, you can create the Renderer by calling Renderer::Create()
. You should store the result in a RefPtr to keep it alive.
- Example creation code
platform.set_config(my_config);
MyFileSystem* file_system = new MyFileSystem();
MyFontLoader* font_loader = new MyFontLoader();
platform.set_file_system(file_system);
platform.set_font_loader(font_loader);
A nullable smart pointer.
Definition RefPtr.h:79
static RefPtr< Renderer > Create()
Create the core renderer singleton for the library.
Core configuration for the renderer.
Definition Config.h:95
Updating Renderer Logic
You should call Renderer::Update() from your main update loop as often as possible to give the library an opportunity to dispatch events and timers:
- Example update code
void mainLoop()
{
while(true)
{
renderer.Update();
}
}
Rendering Each Frame
When your program is ready to display a new frame (usually in synchrony with the monitor refresh rate), you should call Renderer::RefreshDisplay()
and Renderer::Render()
so the library can render all active Views as needed.
- Example per-frame render code
void displayFrame()
{
renderer.RefreshDisplay(0);
renderer.Render();
}
}
|
virtual RefPtr< Session > | CreateSession (bool is_persistent, const String &name)=0 |
| Create a unique, named Session to store browsing data in (cookies, local storage, application cache, indexed db, etc).
|
|
virtual RefPtr< Session > | default_session ()=0 |
| Get the default Session.
|
|
virtual RefPtr< View > | CreateView (uint32_t width, uint32_t height, const ViewConfig &config, RefPtr< Session > session)=0 |
| Create a new View to load and display web pages in.
|
|
virtual void | Update ()=0 |
| Update timers and dispatch callbacks.
|
|
virtual void | RefreshDisplay (uint32_t display_id)=0 |
| Notify the renderer that a display has refreshed (you should call this after vsync).
|
|
virtual void | Render ()=0 |
| Render all active views to their respective render-targets/surfaces.
|
|
virtual void | RenderOnly (View **view_array, size_t view_array_len)=0 |
| Render a subset of views to their respective surfaces and render targets.
|
|
virtual void | PurgeMemory ()=0 |
| Attempt to release as much memory as possible.
|
|
virtual void | LogMemoryUsage ()=0 |
| Print detailed memory usage statistics to the log.
|
|
virtual bool | StartRemoteInspectorServer (const char *address, uint16_t port)=0 |
| Start the remote inspector server.
|
|
virtual void | SetGamepadDetails (uint32_t index, const String &id, uint32_t axis_count, uint32_t button_count)=0 |
| Describe the details of a gamepad, to be used with FireGamepadEvent and related events below.
|
|
virtual void | FireGamepadEvent (const GamepadEvent &evt)=0 |
| Fire a gamepad event (connection / disconnection).
|
|
virtual void | FireGamepadAxisEvent (const GamepadAxisEvent &evt)=0 |
| Fire a gamepad axis event (to be called when an axis value is changed).
|
|
virtual void | FireGamepadButtonEvent (const GamepadButtonEvent &evt)=0 |
| Fire a gamepad button event (to be called when a button value is changed).
|
|
virtual void | AddRef () const =0 |
|
virtual void | Release () const =0 |
|
virtual int | ref_count () const =0 |
|