Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
GPUDriver.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8#pragma once
9#pragma warning(disable : 4251)
10#include <Ultralight/Defines.h>
11#include <Ultralight/Geometry.h>
12#include <Ultralight/Matrix.h>
13#include <Ultralight/Bitmap.h>
14
15namespace ultralight {
16
17///
18/// @note This pragma pack(push, 1) command is important! Vertex layouts
19/// should not be padded with any bytes.
20///
21#pragma pack(push, 1)
22
23///
24/// RenderBuffer description, @see GPUDriver::CreateRenderBuffer.
25///
27 uint32_t texture_id; // The backing texture for this RenderBuffer
28 uint32_t width; // The width of the RenderBuffer texture
29 uint32_t height; // The height of the RenderBuffer texture
30 bool has_stencil_buffer; // Currently unused, always false.
31 bool has_depth_buffer; // Currently unsued, always false.
32};
33
34///
35/// Vertex layout for path vertices, useful for synthesizing or modifying
36/// vertex data.
37///
39 float pos[2];
40 unsigned char color[4];
41 float obj[2];
42};
43
44///
45/// Vertex layout for quad vertices, useful for synthesizing or modifying
46/// vertex data.
47///
49 float pos[2];
50 unsigned char color[4];
51 float tex[2];
52 float obj[2];
53 float data0[4];
54 float data1[4];
55 float data2[4];
56 float data3[4];
57 float data4[4];
58 float data5[4];
59 float data6[4];
60};
61
62///
63/// Vertex buffer formats (identifiers start with underscore due to C++ naming rules)
64///
65enum class UExport VertexBufferFormat : uint8_t {
68};
69
70///
71/// Vertex buffer, @see GPUDriver::CreateGeometry
72///
75 uint32_t size;
76 uint8_t* data;
77};
78
79///
80/// Vertex index type
81///
82typedef uint32_t IndexType;
83
84///
85/// Vertex index buffer, @see GPUDriver::CreateGeometry
86///
88 uint32_t size;
89 uint8_t* data;
90};
91
92///
93/// Shader types, used by GPUState::shader_type
94///
95/// Each of these correspond to a vertex/pixel shader pair. You can find stock shader code for
96/// these in the `shaders` folder of the AppCore repo.
97///
98enum class UExport ShaderType : uint8_t {
99 Fill, // Shader program for quad geometry
100 FillPath, // Shader program for path geometry
101};
102
103///
104/// GPU state description.
105///
107 /// Viewport width in pixels
109
110 /// Viewport height in pixels
112
113 /// Transform matrix-- you should multiply this with the screen-space orthographic projection
114 /// matrix then pass to the vertex shader.
116
117 /// Whether or not we should enable texturing for the current draw command.
119
120 /// Whether or not we should enable blending for the current draw command. If blending is
121 /// disabled, any drawn pixels should overwrite existing. This is mainly used so we can modify
122 /// alpha values of the RenderBuffer during scissored clears.
124
125 /// The vertex/pixel shader program pair to use for the current draw command.
127
128 /// The render buffer to use for the current draw command.
130
131 /// The texture id to bind to slot #1. (Will be 0 if none)
132 uint32_t texture_1_id;
133
134 /// The texture id to bind to slot #2. (Will be 0 if none)
135 uint32_t texture_2_id;
136
137 /// The texture id to bind to slot #3. (Will be 0 if none)
138 uint32_t texture_3_id;
139
140 /// The following four members are passed to the pixel shader via uniforms.
141 float uniform_scalar[8];
142 vec4 uniform_vector[8];
143 uint8_t clip_size;
144 Matrix4x4 clip[8];
145
146 /// Whether or not scissor testing should be used for the current draw command.
148
149 /// The scissor rect to use for scissor testing (units in pixels)
151};
152
153///
154/// Command types, used by Command::command_type
155///
156enum class UExport CommandType : uint8_t {
159};
160
161///
162/// Command description.
163///
165 CommandType command_type; // The type of command to dispatch.
166 GPUState gpu_state; // GPU state parameters for current command.
167
168 /// The following members are only used with kCommandType_DrawGeometry
169 uint32_t geometry_id; // The geometry ID to bind
170 uint32_t indices_count; // The number of indices
171 uint32_t indices_offset; // The index to start from
172};
173
174///
175/// Command list, @see GPUDriver::UpdateCommandList
176///
178 uint32_t size;
180};
181
182#pragma pack(pop)
183
184///
185/// User-defined GPU driver interface.
186///
187/// The library uses this to optionally render Views directly on the GPU.
188///
189/// @pre Only used if the View is accelerated (see ViewConfig::is_accelerated)
190///
191/// This is automatically provided for you when you use App::Create(), AppCore provides
192/// platform-specific implementations of GPUDriver for each OS.
193///
194/// If you are using Renderer::Create(), you will need to provide your own implementation of this
195/// class if you have enabled the GPU renderer in the Config.
196///
197/// @see Platform::set_gpu_driver()
198///
200 public:
201 virtual ~GPUDriver();
202
203 ///
204 /// Called before any commands are dispatched during a frame.
205 ///
206 virtual void BeginSynchronize() = 0;
207
208 ///
209 /// Called after any commands are dispatched during a frame.
210 ///
211 virtual void EndSynchronize() = 0;
212
213 ///
214 /// Get the next available texture ID.
215 ///
216 virtual uint32_t NextTextureId() = 0;
217
218 ///
219 /// Create a texture with a certain ID and optional bitmap.
220 ///
221 /// **NOTE**: If the Bitmap is empty (Bitmap::IsEmpty), then a RTT Texture should be created
222 /// instead. This will be used as a backing texture for a new RenderBuffer.
223 ///
224 virtual void CreateTexture(uint32_t texture_id, RefPtr<Bitmap> bitmap) = 0;
225
226 ///
227 /// Update an existing non-RTT texture with new bitmap data.
228 ///
229 virtual void UpdateTexture(uint32_t texture_id, RefPtr<Bitmap> bitmap) = 0;
230
231 ///
232 /// Destroy a texture.
233 ///
234 virtual void DestroyTexture(uint32_t texture_id) = 0;
235
236 ///
237 /// Generate the next available render buffer ID.
238 ///
239 virtual uint32_t NextRenderBufferId() = 0;
240
241 ///
242 /// Create a render buffer with certain ID and buffer description.
243 ///
244 virtual void CreateRenderBuffer(uint32_t render_buffer_id, const RenderBuffer& buffer) = 0;
245
246 ///
247 /// Destroy a render buffer
248 ///
249 virtual void DestroyRenderBuffer(uint32_t render_buffer_id) = 0;
250
251 ///
252 /// Generate the next available geometry ID.
253 ///
254 virtual uint32_t NextGeometryId() = 0;
255
256 ///
257 /// Create geometry with certain ID and vertex/index data.
258 ///
259 virtual void CreateGeometry(uint32_t geometry_id, const VertexBuffer& vertices,
260 const IndexBuffer& indices)
261 = 0;
262
263 ///
264 /// Update existing geometry with new vertex/index data.
265 ///
266 virtual void UpdateGeometry(uint32_t geometry_id, const VertexBuffer& vertices,
267 const IndexBuffer& indices)
268 = 0;
269
270 ///
271 /// Destroy geometry.
272 ///
273 virtual void DestroyGeometry(uint32_t geometry_id) = 0;
274
275 ///
276 /// Update command list (you should copy the commands to your own structure).
277 ///
278 virtual void UpdateCommandList(const CommandList& list) = 0;
279};
280
281} // namespace ultralight
#define UExport
Definition Defines.h:65
User-defined GPU driver interface.
Definition GPUDriver.h:199
virtual uint32_t NextRenderBufferId()=0
Generate the next available render buffer ID.
virtual void EndSynchronize()=0
Called after any commands are dispatched during a frame.
virtual void CreateTexture(uint32_t texture_id, RefPtr< Bitmap > bitmap)=0
Create a texture with a certain ID and optional bitmap.
virtual uint32_t NextTextureId()=0
Get the next available texture ID.
virtual void DestroyRenderBuffer(uint32_t render_buffer_id)=0
Destroy a render buffer.
virtual void UpdateGeometry(uint32_t geometry_id, const VertexBuffer &vertices, const IndexBuffer &indices)=0
Update existing geometry with new vertex/index data.
virtual void DestroyTexture(uint32_t texture_id)=0
Destroy a texture.
virtual void UpdateTexture(uint32_t texture_id, RefPtr< Bitmap > bitmap)=0
Update an existing non-RTT texture with new bitmap data.
virtual void BeginSynchronize()=0
Called before any commands are dispatched during a frame.
virtual uint32_t NextGeometryId()=0
Generate the next available geometry ID.
virtual void CreateGeometry(uint32_t geometry_id, const VertexBuffer &vertices, const IndexBuffer &indices)=0
Create geometry with certain ID and vertex/index data.
virtual void DestroyGeometry(uint32_t geometry_id)=0
Destroy geometry.
virtual void UpdateCommandList(const CommandList &list)=0
Update command list (you should copy the commands to your own structure).
virtual void CreateRenderBuffer(uint32_t render_buffer_id, const RenderBuffer &buffer)=0
Create a render buffer with certain ID and buffer description.
A nullable smart pointer.
Definition RefPtr.h:79
Definition App.h:14
ShaderType
Shader types, used by GPUState::shader_type.
Definition GPUDriver.h:98
VertexBufferFormat
Vertex buffer formats (identifiers start with underscore due to C++ naming rules)
Definition GPUDriver.h:65
CommandType
Command types, used by Command::command_type.
Definition GPUDriver.h:156
uint32_t IndexType
Vertex index type.
Definition GPUDriver.h:82
Command description.
Definition GPUDriver.h:164
GPUState gpu_state
Definition GPUDriver.h:166
uint32_t indices_offset
Definition GPUDriver.h:171
CommandType command_type
Definition GPUDriver.h:165
uint32_t indices_count
Definition GPUDriver.h:170
uint32_t geometry_id
The following members are only used with kCommandType_DrawGeometry.
Definition GPUDriver.h:169
Command list,.
Definition GPUDriver.h:177
Command * commands
Definition GPUDriver.h:179
uint32_t size
Definition GPUDriver.h:178
GPU state description.
Definition GPUDriver.h:106
IntRect scissor_rect
The scissor rect to use for scissor testing (units in pixels)
Definition GPUDriver.h:150
uint32_t render_buffer_id
The render buffer to use for the current draw command.
Definition GPUDriver.h:129
uint8_t clip_size
Definition GPUDriver.h:143
bool enable_blend
Whether or not we should enable blending for the current draw command.
Definition GPUDriver.h:123
bool enable_texturing
Whether or not we should enable texturing for the current draw command.
Definition GPUDriver.h:118
uint32_t texture_1_id
The texture id to bind to slot #1. (Will be 0 if none)
Definition GPUDriver.h:132
ShaderType shader_type
The vertex/pixel shader program pair to use for the current draw command.
Definition GPUDriver.h:126
uint32_t texture_2_id
The texture id to bind to slot #2. (Will be 0 if none)
Definition GPUDriver.h:135
uint32_t viewport_width
Viewport width in pixels.
Definition GPUDriver.h:108
uint32_t viewport_height
Viewport height in pixels.
Definition GPUDriver.h:111
bool enable_scissor
Whether or not scissor testing should be used for the current draw command.
Definition GPUDriver.h:147
uint32_t texture_3_id
The texture id to bind to slot #3. (Will be 0 if none)
Definition GPUDriver.h:138
Matrix4x4 transform
Transform matrix– you should multiply this with the screen-space orthographic projection matrix then ...
Definition GPUDriver.h:115
Vertex index buffer,.
Definition GPUDriver.h:87
uint8_t * data
Definition GPUDriver.h:89
uint32_t size
Definition GPUDriver.h:88
Integer Rectangle Helper.
Definition Geometry.h:529
4x4 Matrix Helper
Definition Matrix.h:18
RenderBuffer description,.
Definition GPUDriver.h:26
uint32_t width
Definition GPUDriver.h:28
uint32_t height
Definition GPUDriver.h:29
uint32_t texture_id
Definition GPUDriver.h:27
bool has_stencil_buffer
Definition GPUDriver.h:30
bool has_depth_buffer
Definition GPUDriver.h:31
Vertex layout for quad vertices, useful for synthesizing or modifying vertex data.
Definition GPUDriver.h:48
float data0[4]
Definition GPUDriver.h:53
unsigned char color[4]
Definition GPUDriver.h:50
float tex[2]
Definition GPUDriver.h:51
float obj[2]
Definition GPUDriver.h:52
float data2[4]
Definition GPUDriver.h:55
float data4[4]
Definition GPUDriver.h:57
float data5[4]
Definition GPUDriver.h:58
float data6[4]
Definition GPUDriver.h:59
float data3[4]
Definition GPUDriver.h:56
float data1[4]
Definition GPUDriver.h:54
float pos[2]
Definition GPUDriver.h:49
Vertex layout for path vertices, useful for synthesizing or modifying vertex data.
Definition GPUDriver.h:38
float pos[2]
Definition GPUDriver.h:39
float obj[2]
Definition GPUDriver.h:41
unsigned char color[4]
Definition GPUDriver.h:40
Vertex buffer,.
Definition GPUDriver.h:73
VertexBufferFormat format
Definition GPUDriver.h:74
uint32_t size
Definition GPUDriver.h:75
uint8_t * data
Definition GPUDriver.h:76
4D Vector Helper
Definition Geometry.h:283