Ultralight  1.0.0
A fast, lightweight, HTML UI engine for native apps.
GPUDriver.h
Go to the documentation of this file.
1 #pragma once
15 #pragma warning(disable: 4251)
16 #include <Ultralight/Defines.h>
17 #include <Ultralight/Geometry.h>
18 #include <Ultralight/Matrix.h>
19 #include <Ultralight/Bitmap.h>
20 
21 namespace ultralight {
22 
27 #pragma pack(push, 1)
28 
32 struct UExport RenderBuffer {
33  uint32_t texture_id;
34  uint32_t width;
35  uint32_t height;
36  bool has_stencil_buffer;
37  bool has_depth_buffer;
38 };
39 
45  float pos[2];
46  unsigned char color[4];
47  float obj[2];
48 };
49 
55  float pos[2];
56  unsigned char color[4];
57  float tex[2];
58  float obj[2];
59  float data0[4];
60  float data1[4];
61  float data2[4];
62  float data3[4];
63  float data4[4];
64  float data5[4];
65  float data6[4];
66 };
67 
71 enum UExport VertexBufferFormat {
72  kVertexBufferFormat_2f_4ub_2f,
73  kVertexBufferFormat_2f_4ub_2f_2f_28f,
74 };
75 
79 struct UExport VertexBuffer {
80  VertexBufferFormat format;
81  uint32_t size;
82  uint8_t* data;
83 };
84 
88 typedef uint32_t IndexType;
89 
93 struct UExport IndexBuffer {
94  uint32_t size;
95  uint8_t* data;
96 };
97 
101 enum UExport ShaderType {
102  kShaderType_Fill,
103  kShaderType_FillPath,
104 };
105 
109 struct UExport GPUState {
110  float viewport_width;
111  float viewport_height;
112  Matrix4x4 transform;
113  bool enable_texturing;
114  bool enable_blend;
115  uint8_t shader_type;
116  uint32_t render_buffer_id;
117  uint32_t texture_1_id;
118  uint32_t texture_2_id;
119  uint32_t texture_3_id;
120  float uniform_scalar[8];
121  vec4 uniform_vector[8];
122  uint8_t clip_size;
123  Matrix4x4 clip[8];
124 };
125 
129 enum UExport CommandType {
130  kCommandType_ClearRenderBuffer,
131  kCommandType_DrawGeometry,
132 };
133 
138 struct UExport Command {
139  uint8_t command_type;
140  GPUState gpu_state;
141  uint32_t geometry_id;
142  uint32_t indices_count;
143  uint32_t indices_offset;
144 };
145 
149 struct UExport CommandList {
150  uint32_t size;
151  Command* commands;
152 };
153 
154 #pragma pack(pop)
155 
166 class UExport GPUDriver {
167 public:
168  virtual ~GPUDriver();
169 
173  virtual void BeginSynchronize() = 0;
174 
178  virtual void EndSynchronize() = 0;
179 
183  virtual uint32_t NextTextureId() = 0;
184 
188  virtual void CreateTexture(uint32_t texture_id,
189  Ref<Bitmap> bitmap) = 0;
190 
194  virtual void UpdateTexture(uint32_t texture_id,
195  Ref<Bitmap> bitmap) = 0;
196 
200  virtual void BindTexture(uint8_t texture_unit,
201  uint32_t texture_id) = 0;
202 
206  virtual void DestroyTexture(uint32_t texture_id) = 0;
207 
211  virtual uint32_t NextRenderBufferId() = 0;
212 
216  virtual void CreateRenderBuffer(uint32_t render_buffer_id,
217  const RenderBuffer& buffer) = 0;
218 
222  virtual void BindRenderBuffer(uint32_t render_buffer_id) = 0;
223 
227  virtual void ClearRenderBuffer(uint32_t render_buffer_id) = 0;
228 
232  virtual void DestroyRenderBuffer(uint32_t render_buffer_id) = 0;
233 
237  virtual uint32_t NextGeometryId() = 0;
238 
242  virtual void CreateGeometry(uint32_t geometry_id,
243  const VertexBuffer& vertices,
244  const IndexBuffer& indices) = 0;
245 
249  virtual void UpdateGeometry(uint32_t geometry_id,
250  const VertexBuffer& vertices,
251  const IndexBuffer& indices) = 0;
252 
256  virtual void DrawGeometry(uint32_t geometry_id,
257  uint32_t indices_count,
258  uint32_t indices_offset,
259  const GPUState& state) = 0;
260 
264  virtual void DestroyGeometry(uint32_t geometry_id) = 0;
265 
269  virtual void UpdateCommandList(const CommandList& list) = 0;
270 
274  virtual bool HasCommandsPending() = 0;
275 
280  virtual void DrawCommandList() = 0;
281 };
282 
283 } // namespace ultralight
GPU state description.
Definition: GPUDriver.h:109
Vertex buffer,.
Definition: GPUDriver.h:79
RenderBuffer description,.
Definition: GPUDriver.h:32
The header for the Bitmap class.
The header for various geometry definitions and helpers.
The header for Matrix helpers.
A non-nullable smart pointer.
Definition: RefPtr.h:64
Command description, handling one of these should result in either a call to GPUDriver::ClearRenderBu...
Definition: GPUDriver.h:138
This is a set of common JavaScriptCore Helper functions to simplify sample code.
Definition: App.h:19
4x4 Matrix Helper
Definition: Matrix.h:110
Command list,.
Definition: GPUDriver.h:149
Vertex layout for quad vertices, useful for synthesizing or modifying vertex data.
Definition: GPUDriver.h:54
Vertex layout for path vertices, useful for synthesizing or modifying vertex data.
Definition: GPUDriver.h:44
uint32_t IndexType
Vertex index type.
Definition: GPUDriver.h:88
GPUDriver interface, dispatches GPU calls to the native driver.
Definition: GPUDriver.h:166
4D Vector Helper
Definition: Geometry.h:294
Vertex index buffer,.
Definition: GPUDriver.h:93