Skip to content

Commit 2d2dbc3

Browse files
committed
Update CAPI.h headers (expose GPUDriver and Clipboard)
1 parent 32445a1 commit 2d2dbc3

File tree

1 file changed

+386
-0
lines changed

1 file changed

+386
-0
lines changed

Ultralight/CAPI.h

Lines changed: 386 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,364 @@ typedef struct {
14761476
ULLoggerLogMessageCallback log_message;
14771477
} ULLogger;
14781478

1479+
1480+
/******************************************************************************
1481+
* GPUDriver
1482+
*****************************************************************************/
1483+
1484+
///
1485+
/// @note This pragma pack(push, 1) command is important! Vertex layouts
1486+
/// should not be padded with any bytes.
1487+
///
1488+
#pragma pack(push, 1)
1489+
1490+
///
1491+
/// Render buffer description.
1492+
///
1493+
typedef struct {
1494+
unsigned int texture_id; // The backing texture for this RenderBuffer
1495+
unsigned int width; // The width of the RenderBuffer texture
1496+
unsigned int height; // The height of the RenderBuffer texture
1497+
bool has_stencil_buffer; // Currently unused, always false.
1498+
bool has_depth_buffer; // Currently unsued, always false.
1499+
} ULRenderBuffer;
1500+
1501+
///
1502+
/// Vertex layout for path vertices.
1503+
///
1504+
typedef struct {
1505+
float pos[2];
1506+
unsigned char color[4];
1507+
float obj[2];
1508+
} ULVertex_2f_4ub_2f;
1509+
1510+
///
1511+
/// Vertex layout for quad vertices.
1512+
///
1513+
typedef struct {
1514+
float pos[2];
1515+
unsigned char color[4];
1516+
float tex[2];
1517+
float obj[2];
1518+
float data0[4];
1519+
float data1[4];
1520+
float data2[4];
1521+
float data3[4];
1522+
float data4[4];
1523+
float data5[4];
1524+
float data6[4];
1525+
} ULVertex_2f_4ub_2f_2f_28f;
1526+
1527+
///
1528+
/// Vertex formats.
1529+
///
1530+
typedef enum {
1531+
kVertexBufferFormat_2f_4ub_2f,
1532+
kVertexBufferFormat_2f_4ub_2f_2f_28f,
1533+
} ULVertexBufferFormat;
1534+
1535+
///
1536+
/// Vertex buffer data.
1537+
///
1538+
typedef struct {
1539+
ULVertexBufferFormat format;
1540+
unsigned int size;
1541+
unsigned char* data;
1542+
} ULVertexBuffer;
1543+
1544+
///
1545+
/// Vertex index type.
1546+
///
1547+
typedef unsigned int ULIndexType;
1548+
1549+
///
1550+
/// Vertex index buffer data.
1551+
///
1552+
typedef struct {
1553+
unsigned int size;
1554+
unsigned char* data;
1555+
} ULIndexBuffer;
1556+
1557+
///
1558+
/// Shader types, used with ULGPUState::shader_type
1559+
///
1560+
/// Each of these correspond to a vertex/pixel shader pair. You can find
1561+
/// stock shader code for these in the `shaders` folder of the AppCore repo.
1562+
///
1563+
typedef enum {
1564+
kShaderType_Fill, // Shader program for quad geometry
1565+
kShaderType_FillPath, // Shader program for path geometry
1566+
} ULShaderType;
1567+
1568+
///
1569+
/// Raw 4x4 matrix as an array of floats
1570+
///
1571+
typedef struct {
1572+
float data[16];
1573+
} ULMatrix4x4;
1574+
1575+
///
1576+
/// 4-component float vector
1577+
///
1578+
typedef struct {
1579+
float value[4];
1580+
} ULvec4;
1581+
1582+
///
1583+
/// GPU State description.
1584+
///
1585+
typedef struct {
1586+
/// Viewport width in pixels
1587+
unsigned int viewport_width;
1588+
1589+
/// Viewport height in pixels
1590+
unsigned int viewport_height;
1591+
1592+
/// Transform matrix-- you should multiply this with the screen-space
1593+
/// orthographic projection matrix then pass to the vertex shader.
1594+
ULMatrix4x4 transform;
1595+
1596+
/// Whether or not we should enable texturing for the current draw command.
1597+
bool enable_texturing;
1598+
1599+
/// Whether or not we should enable blending for the current draw command.
1600+
/// If blending is disabled, any drawn pixels should overwrite existing.
1601+
/// Mainly used so we can modify alpha values of the RenderBuffer during
1602+
/// scissored clears.
1603+
bool enable_blend;
1604+
1605+
/// The vertex/pixel shader program pair to use for the current draw command.
1606+
/// You should cast this to ShaderType to get the corresponding enum.
1607+
unsigned char shader_type;
1608+
1609+
/// The render buffer to use for the current draw command.
1610+
unsigned int render_buffer_id;
1611+
1612+
/// The texture id to bind to slot #1. (Will be 0 if none)
1613+
unsigned int texture_1_id;
1614+
1615+
/// The texture id to bind to slot #2. (Will be 0 if none)
1616+
unsigned int texture_2_id;
1617+
1618+
/// The texture id to bind to slot #3. (Will be 0 if none)
1619+
unsigned int texture_3_id;
1620+
1621+
/// The following four members are passed to the pixel shader via uniforms.
1622+
float uniform_scalar[8];
1623+
ULvec4 uniform_vector[8];
1624+
unsigned int clip_size;
1625+
ULMatrix4x4 clip[8];
1626+
1627+
/// Whether or not scissor testing should be used for the current draw
1628+
/// command.
1629+
bool enable_scissor;
1630+
1631+
/// The scissor rect to use for scissor testing (units in pixels)
1632+
ULIntRect scissor_rect;
1633+
} ULGPUState;
1634+
1635+
///
1636+
/// Command types, used with ULCommand::command_type
1637+
///
1638+
typedef enum {
1639+
kCommandType_ClearRenderBuffer,
1640+
kCommandType_DrawGeometry,
1641+
} ULCommandType;
1642+
1643+
///
1644+
/// Command description.
1645+
///
1646+
typedef struct {
1647+
unsigned char command_type; // The type of command to dispatch.
1648+
ULGPUState gpu_state; // GPU state parameters for current command.
1649+
1650+
/// The following members are only used with kCommandType_DrawGeometry
1651+
unsigned int geometry_id; // The geometry ID to bind
1652+
unsigned int indices_count; // The number of indices
1653+
unsigned int indices_offset; // The index to start from
1654+
} ULCommand;
1655+
1656+
///
1657+
/// Command list, @see ULGPUDriverUpdateCommandList
1658+
typedef struct {
1659+
unsigned int size;
1660+
ULCommand* commands;
1661+
} ULCommandList;
1662+
1663+
#pragma pack(pop)
1664+
1665+
///
1666+
/// The callback invoked when the GPUDriver will begin dispatching commands
1667+
/// (such as CreateTexture and UpdateCommandList) during the current call to
1668+
/// ulRender().
1669+
///
1670+
typedef void
1671+
(*ULGPUDriverBeginSynchronize) ();
1672+
1673+
///
1674+
/// The callback invoked when the GPUDriver has finished dispatching commands.
1675+
/// during the current call to ulRender().
1676+
///
1677+
typedef void
1678+
(*ULGPUDriverEndSynchronize) ();
1679+
1680+
///
1681+
/// The callback invoked when the GPUDriver wants to get the next available
1682+
/// texture ID.
1683+
///
1684+
typedef unsigned int
1685+
(*ULGPUDriverNextTextureId) ();
1686+
1687+
///
1688+
/// The callback invoked when the GPUDriver wants to create a texture with a
1689+
/// certain ID and optional bitmap.
1690+
///
1691+
/// **NOTE**: If the Bitmap is empty (ulBitmapIsEmpty), then a RTT Texture
1692+
/// should be created instead. This will be used as a backing
1693+
/// texture for a new RenderBuffer.
1694+
///
1695+
typedef void
1696+
(*ULGPUDriverCreateTexture) (unsigned int texture_id,
1697+
ULBitmap bitmap);
1698+
1699+
///
1700+
/// The callback invoked when the GPUDriver wants to update an existing non-RTT
1701+
/// texture with new bitmap data.
1702+
///
1703+
typedef void
1704+
(*ULGPUDriverUpdateTexture) (unsigned int texture_id,
1705+
ULBitmap bitmap);
1706+
1707+
///
1708+
/// The callback invoked when the GPUDriver wants to destroy a texture.
1709+
///
1710+
typedef void
1711+
(*ULGPUDriverDestroyTexture) (unsigned int texture_id);
1712+
1713+
///
1714+
/// The callback invoked when the GPUDriver wants to generate the next
1715+
/// available render buffer ID.
1716+
///
1717+
typedef unsigned int
1718+
(*ULGPUDriverNextRenderBufferId) ();
1719+
1720+
///
1721+
/// The callback invoked when the GPUDriver wants to create a render buffer
1722+
/// with certain ID and buffer description.
1723+
///
1724+
typedef void
1725+
(*ULGPUDriverCreateRenderBuffer) (unsigned int render_buffer_id,
1726+
ULRenderBuffer buffer);
1727+
1728+
///
1729+
/// The callback invoked when the GPUDriver wants to destroy a render buffer
1730+
///
1731+
typedef void
1732+
(*ULGPUDriverDestroyRenderBuffer) (unsigned int render_buffer_id);
1733+
1734+
///
1735+
/// The callback invoked when the GPUDriver wants to generate the next
1736+
/// available geometry ID.
1737+
///
1738+
typedef unsigned int
1739+
(*ULGPUDriverNextGeometryId) ();
1740+
1741+
///
1742+
/// The callback invoked when the GPUDriver wants to create geometry with
1743+
/// certain ID and vertex/index data.
1744+
///
1745+
typedef void
1746+
(*ULGPUDriverCreateGeometry) (unsigned int geometry_id,
1747+
ULVertexBuffer vertices,
1748+
ULIndexBuffer indices);
1749+
1750+
///
1751+
/// The callback invoked when the GPUDriver wants to update existing geometry
1752+
/// with new vertex/index data.
1753+
///
1754+
typedef void
1755+
(*ULGPUDriverUpdateGeometry) (unsigned int geometry_id,
1756+
ULVertexBuffer vertices,
1757+
ULIndexBuffer indices);
1758+
1759+
///
1760+
/// The callback invoked when the GPUDriver wants to destroy geometry.
1761+
///
1762+
typedef void
1763+
(*ULGPUDriverDestroyGeometry) (unsigned int geometry_id);
1764+
1765+
///
1766+
/// The callback invoked when the GPUDriver wants to update the command list
1767+
/// (you should copy the commands to your own structure).
1768+
///
1769+
typedef void
1770+
(*ULGPUDriverUpdateCommandList) (ULCommandList list);
1771+
1772+
typedef struct {
1773+
ULGPUDriverBeginSynchronize begin_synchronize;
1774+
ULGPUDriverEndSynchronize end_synchronize;
1775+
ULGPUDriverNextTextureId next_texture_id;
1776+
ULGPUDriverCreateTexture create_texture;
1777+
ULGPUDriverUpdateTexture update_texture;
1778+
ULGPUDriverDestroyTexture destroy_texture;
1779+
ULGPUDriverNextRenderBufferId next_render_buffer_id;
1780+
ULGPUDriverCreateRenderBuffer create_render_buffer;
1781+
ULGPUDriverDestroyRenderBuffer destroy_render_buffer;
1782+
ULGPUDriverNextGeometryId next_geometry_id;
1783+
ULGPUDriverCreateGeometry create_geometry;
1784+
ULGPUDriverUpdateGeometry update_geometry;
1785+
ULGPUDriverDestroyGeometry destroy_geometry;
1786+
ULGPUDriverUpdateCommandList update_command_list;
1787+
} ULGPUDriver;
1788+
1789+
///
1790+
/// Sets up an orthographic projection matrix with a certain viewport width
1791+
/// and height, multiplies it by 'transform', and returns the result.
1792+
///
1793+
/// This should be used to calculate the model-view projection matrix for the
1794+
/// vertex shaders using the current ULGPUState.
1795+
///
1796+
/// The 'flip_y' can be optionally used to flip the Y coordinate-space.
1797+
/// (Usually flip_y == true for OpenGL)
1798+
///
1799+
ULExport ULMatrix4x4 ulApplyProjection(ULMatrix4x4 transform,
1800+
float viewport_width,
1801+
float viewport_height,
1802+
bool flip_y);
1803+
1804+
/******************************************************************************
1805+
* Clipboard
1806+
*****************************************************************************/
1807+
1808+
///
1809+
/// The callback invoked when the library wants to clear the system's
1810+
/// clipboard.
1811+
///
1812+
typedef void
1813+
(*ULClipboardClear) ();
1814+
1815+
///
1816+
/// The callback invoked when the library wants to read from the system's
1817+
/// clipboard.
1818+
///
1819+
/// You should store the result (if any) in 'result'.
1820+
///
1821+
typedef void
1822+
(*ULClipboardReadPlainText) (ULString result);
1823+
1824+
///
1825+
/// The callback invoked when the library wants to write to the system's
1826+
/// clipboard.
1827+
///
1828+
typedef void
1829+
(*ULClipboardWritePlainText) (ULString text);
1830+
1831+
typedef struct {
1832+
ULClipboardClear clear;
1833+
ULClipboardReadPlainText read_plain_text;
1834+
ULClipboardWritePlainText write_plain_text;
1835+
} ULClipboard;
1836+
14791837
/******************************************************************************
14801838
* Platform
14811839
*****************************************************************************/
@@ -1526,6 +1884,34 @@ ULExport void ulPlatformSetFileSystem(ULFileSystem file_system);
15261884
///
15271885
ULExport void ulPlatformSetSurfaceDefinition(ULSurfaceDefinition surface_definition);
15281886

1887+
///
1888+
/// Set a custom GPUDriver implementation.
1889+
///
1890+
/// This should be used if you have enabled the GPU renderer in the Config and
1891+
/// are using ulCreateRenderer() (which does not provide its own GPUDriver
1892+
/// implementation).
1893+
///
1894+
/// The GPUDriver interface is used by the library to dispatch GPU calls to
1895+
/// your native GPU context (eg, D3D11, Metal, OpenGL, Vulkan, etc.) There
1896+
/// are reference implementations for this interface in the AppCore repo.
1897+
///
1898+
/// You should call this before ulCreateRenderer().
1899+
///
1900+
ULExport void ulPlatformSetGPUDriver(ULGPUDriver gpu_driver);
1901+
1902+
///
1903+
/// Set a custom Clipboard implementation.
1904+
///
1905+
/// This should be used if you are using ulCreateRenderer() (which does not
1906+
/// provide its own clipboard implementation).
1907+
///
1908+
/// The Clipboard interface is used by the library to make calls to the
1909+
/// system's native clipboard (eg, cut, copy, paste).
1910+
///
1911+
/// You should call this before ulCreateRenderer().
1912+
///
1913+
ULExport void ulPlatformSetClipboard(ULClipboard clipboard);
1914+
15291915
#ifdef __cplusplus
15301916
}
15311917
#endif

0 commit comments

Comments
 (0)