SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
sbgl.h
Go to the documentation of this file.
1
9#ifndef SBGL_H
10#define SBGL_H
11
12#include "sbgl_types.h"
13#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
16
17#include "sbgl_input.h"
18
25
32
38
39// --- Scancodes (Subset of physical keys) ---
40
41#define SBGL_KEY_UNKNOWN SBGL_SCANCODE_UNKNOWN
42#define SBGL_KEY_A SBGL_SCANCODE_A
43#define SBGL_KEY_B SBGL_SCANCODE_B
44#define SBGL_KEY_C SBGL_SCANCODE_C
45#define SBGL_KEY_D SBGL_SCANCODE_D
46#define SBGL_KEY_E SBGL_SCANCODE_E
47#define SBGL_KEY_F SBGL_SCANCODE_F
48#define SBGL_KEY_G SBGL_SCANCODE_G
49#define SBGL_KEY_H SBGL_SCANCODE_H
50#define SBGL_KEY_I SBGL_SCANCODE_I
51#define SBGL_KEY_J SBGL_SCANCODE_J
52#define SBGL_KEY_K SBGL_SCANCODE_K
53#define SBGL_KEY_L SBGL_SCANCODE_L
54#define SBGL_KEY_M SBGL_SCANCODE_M
55#define SBGL_KEY_N SBGL_SCANCODE_N
56#define SBGL_KEY_O SBGL_SCANCODE_O
57#define SBGL_KEY_P SBGL_SCANCODE_P
58#define SBGL_KEY_Q SBGL_SCANCODE_Q
59#define SBGL_KEY_R SBGL_SCANCODE_R
60#define SBGL_KEY_S SBGL_SCANCODE_S
61#define SBGL_KEY_T SBGL_SCANCODE_T
62#define SBGL_KEY_U SBGL_SCANCODE_U
63#define SBGL_KEY_V SBGL_SCANCODE_V
64#define SBGL_KEY_W SBGL_SCANCODE_W
65#define SBGL_KEY_X SBGL_SCANCODE_X
66#define SBGL_KEY_Y SBGL_SCANCODE_Y
67#define SBGL_KEY_Z SBGL_SCANCODE_Z
68
69#define SBGL_KEY_1 SBGL_SCANCODE_1
70#define SBGL_KEY_2 SBGL_SCANCODE_2
71#define SBGL_KEY_3 SBGL_SCANCODE_3
72#define SBGL_KEY_4 SBGL_SCANCODE_4
73#define SBGL_KEY_5 SBGL_SCANCODE_5
74#define SBGL_KEY_6 SBGL_SCANCODE_6
75#define SBGL_KEY_7 SBGL_SCANCODE_7
76#define SBGL_KEY_8 SBGL_SCANCODE_8
77#define SBGL_KEY_9 SBGL_SCANCODE_9
78#define SBGL_KEY_0 SBGL_SCANCODE_0
79
80#define SBGL_KEY_MINUS SBGL_SCANCODE_MINUS
81#define SBGL_KEY_EQUAL SBGL_SCANCODE_EQUAL
82
83#define SBGL_KEY_RETURN SBGL_SCANCODE_RETURN
84#define SBGL_KEY_ESCAPE SBGL_SCANCODE_ESCAPE
85#define SBGL_KEY_BACKSPACE SBGL_SCANCODE_BACKSPACE
86#define SBGL_KEY_TAB SBGL_SCANCODE_TAB
87#define SBGL_KEY_SPACE SBGL_SCANCODE_SPACE
88#define SBGL_KEY_RIGHT SBGL_SCANCODE_RIGHT
89#define SBGL_KEY_LEFT SBGL_SCANCODE_LEFT
90#define SBGL_KEY_DOWN SBGL_SCANCODE_DOWN
91#define SBGL_KEY_UP SBGL_SCANCODE_UP
92#define SBGL_KEY_LSHIFT SBGL_SCANCODE_LSHIFT
93#define SBGL_KEY_LCTRL SBGL_SCANCODE_LCTRL
94#define SBGL_KEY_LALT SBGL_SCANCODE_LALT
95
96#define SBGL_MOUSE_LEFT SBGL_MOUSE_BUTTON_LEFT
97#define SBGL_MOUSE_RIGHT SBGL_MOUSE_BUTTON_RIGHT
98#define SBGL_MOUSE_MIDDLE SBGL_MOUSE_BUTTON_MIDDLE
99
100// --- API ---
101
113
126sbgl_InitResult sbgl_Init(int w, int h, const char* title);
127
132void sbgl_Shutdown(sbgl_Context* ctx);
133
145
154double sbgl_GetTime(sbgl_Context* ctx);
155
162void sbgl_GetWindowSize(sbgl_Context* ctx, int* w, int* h);
163
173
182
193
203
214
224void sbgl_SetClearColor(sbgl_Context* ctx, float r, float g, float b, float a);
225
229#define sbgl_Clear sbgl_SetClearColor
230
241
248
255
256// --- Rendering API ---
257
267sbgl_CreateBuffer(sbgl_Context* ctx, sbgl_BufferUsage usage, size_t size, const void* data);
268
278void
280
293void sbgl_FillBuffer(sbgl_Context* ctx, sbgl_Buffer buffer, size_t offset, size_t size, uint32_t value);
294
300uint32_t sbgl_GetFrameIndex(sbgl_Context* ctx);
301
311sbgl_LoadShader(sbgl_Context* ctx, sbgl_ShaderStage stage, const uint32_t* bytecode, size_t size);
312
322sbgl_LoadShaderFromFile(sbgl_Context* ctx, sbgl_ShaderStage stage, const char* filename);
323
334
345void* sbgl_MapBuffer(sbgl_Context* ctx, sbgl_Buffer buffer);
346
352void sbgl_UnmapBuffer(sbgl_Context* ctx, sbgl_Buffer buffer);
353
371
379
386
393
401void sbgl_DispatchCompute(sbgl_Context* ctx, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
402
409
415void sbgl_BindPipeline(sbgl_Context* ctx, sbgl_Pipeline pipeline);
416
424
435
443void sbgl_Draw(sbgl_Context* ctx, uint32_t vertexCount, uint32_t firstVertex, uint32_t instanceCount);
444
454 sbgl_Context* ctx,
455 uint32_t indexCount,
456 uint32_t firstIndex,
457 int32_t vertexOffset,
458 uint32_t instanceCount
459);
460
470 sbgl_Context* ctx,
471 sbgl_Buffer buffer,
472 size_t offset,
473 uint32_t drawCount
474);
475
482void sbgl_PushConstants(sbgl_Context* ctx, size_t size, const void* data);
483
484// --- Automated Batching API ---
485
486struct SblArena;
487
500
515void sbgl_SubmitDraw(
516 sbgl_RenderQueue* queue,
517 uint32_t mesh,
518 uint32_t material,
519 uint32_t blendMode,
520 uint32_t sidedness,
521 uint32_t tags,
522 sbgl_SortKey key,
523 const sbgl_InstanceData* data
524);
525
538void sbgl_RenderQueues(sbgl_Context* ctx, sbgl_RenderQueue** queues, uint32_t queueCount, const sbgl_Mat4* viewProj);
539
549void sbgl_RenderQueuesEx(sbgl_Context* ctx, sbgl_RenderQueue** queues, uint32_t queueCount, const sbgl_Mat4* viewProj, uint64_t userAddress);
550
551#endif // SBGL_H
Public input types and scancodes for SBgl.
sbgl_MouseMode
Mouse behavior modes.
Definition sbgl_input.h:153
void sbgl_SetClearColor(sbgl_Context *ctx, float r, float g, float b, float a)
Sets the clear color for the next frame.
Definition sbgl_core.c:401
sbgl_Result sbgl_GetResult(sbgl_Context *ctx)
Retrieves the last result code from the context.
Definition sbgl_core.c:71
void sbgl_RenderQueuesEx(sbgl_Context *ctx, sbgl_RenderQueue **queues, uint32_t queueCount, const sbgl_Mat4 *viewProj, uint64_t userAddress)
Extended version of sbgl_RenderQueues with user metadata.
Definition sbgl_core.c:817
void sbgl_DestroyComputePipeline(sbgl_Context *ctx, sbgl_ComputePipeline pipeline)
Destroys a compute pipeline.
Definition sbgl_core.c:629
void sbgl_FillBuffer(sbgl_Context *ctx, sbgl_Buffer buffer, size_t offset, size_t size, uint32_t value)
Fills a region of a GPU buffer with a fixed 32-bit value.
Definition sbgl_core.c:480
void sbgl_DrawIndirect(sbgl_Context *ctx, sbgl_Buffer buffer, size_t offset, uint32_t drawCount)
Submits a batch of draw calls stored in a GPU buffer.
Definition sbgl_core.c:720
sbgl_InitResult sbgl_Init(int w, int h, const char *title)
Initializes the engine and opens a window.
Definition sbgl_core.c:193
sbgl_Shader sbgl_LoadShaderFromFile(sbgl_Context *ctx, sbgl_ShaderStage stage, const char *filename)
Helper function to load a shader directly from a SPIR-V file.
Definition sbgl_core.c:534
void sbgl_SubmitDraw(sbgl_RenderQueue *queue, uint32_t mesh, uint32_t material, uint32_t blendMode, uint32_t sidedness, uint32_t tags, sbgl_SortKey key, const sbgl_InstanceData *data)
Appends a draw command to the render queue.
Definition sbgl_core.c:772
void sbgl_GetWindowSize(sbgl_Context *ctx, int *w, int *h)
Retrieves the current window dimensions.
Definition sbgl_core.c:252
sbgl_Telemetry sbgl_GetTelemetry(sbgl_Context *ctx)
Retrieves the performance telemetry data for the previous frame.
Definition sbgl_core.c:436
bool sbgl_WindowShouldClose(sbgl_Context *ctx)
Checks if the user or OS has requested to close the window.
Definition sbgl_core.c:238
sbgl_InitResult sbgl_InitWithConfig(const sbgl_InitConfig *config)
Initializes the engine and opens a window with explicit configuration.
Definition sbgl_core.c:112
const sbgl_InputState * sbgl_GetInputState(sbgl_Context *ctx)
Retrieves the input state for the current frame.
Definition sbgl_core.c:413
sbgl_Pipeline sbgl_CreatePipeline(sbgl_Context *ctx, const sbgl_PipelineConfig *config)
Creates a graphics pipeline.
Definition sbgl_core.c:587
void sbgl_DestroyShader(sbgl_Context *ctx, sbgl_Shader shader)
Destroys a shader module.
Definition sbgl_core.c:565
sbgl_Shader sbgl_LoadShader(sbgl_Context *ctx, sbgl_ShaderStage stage, const uint32_t *bytecode, size_t size)
Loads a shader from SPIR-V bytecode.
Definition sbgl_core.c:523
void sbgl_SetMouseMode(sbgl_Context *ctx, sbgl_MouseMode mode)
Sets the cursor behavior and visibility.
Definition sbgl_core.c:422
void sbgl_PushConstants(sbgl_Context *ctx, size_t size, const void *data)
Updates push constants for the currently bound pipeline.
Definition sbgl_core.c:733
void sbgl_EndDrawing(sbgl_Context *ctx)
Finalizes the current frame and presents it to the screen.
Definition sbgl_core.c:315
void sbgl_BindComputePipeline(sbgl_Context *ctx, sbgl_ComputePipeline pipeline)
Binds a compute pipeline for subsequent dispatch calls.
Definition sbgl_core.c:649
void sbgl_EndCompute(sbgl_Context *ctx)
Finalizes the compute phase.
Definition sbgl_core.c:385
void sbgl_BindPipeline(sbgl_Context *ctx, sbgl_Pipeline pipeline)
Binds a graphics pipeline for subsequent draw calls.
Definition sbgl_core.c:673
void sbgl_DestroyBuffer(sbgl_Context *ctx, sbgl_Buffer buffer)
Destroys a GPU buffer.
Definition sbgl_core.c:457
void sbgl_BeginCompute(sbgl_Context *ctx)
Prepares the engine for compute operations before the main drawing pass.
Definition sbgl_core.c:344
sbgl_ComputePipeline sbgl_CreateComputePipeline(sbgl_Context *ctx, sbgl_Shader shader)
Creates a compute pipeline.
Definition sbgl_core.c:619
sbgl_RenderQueue * sbgl_CreateRenderQueue(sbgl_Context *ctx, struct SblArena *arena)
Creates a thread-local render queue for collecting draw commands.
Definition sbgl_core.c:743
void * sbgl_MapBuffer(sbgl_Context *ctx, sbgl_Buffer buffer)
Maps a GPU buffer into the CPU's address space.
Definition sbgl_core.c:497
void sbgl_ClearResult(sbgl_Context *ctx)
Clears the result code to SBGL_SUCCESS.
Definition sbgl_core.c:103
void sbgl_MemoryBarrier(sbgl_Context *ctx, sbgl_BarrierType type)
Injects a memory barrier to synchronize compute and graphics operations.
Definition sbgl_core.c:665
void sbgl_UnmapBuffer(sbgl_Context *ctx, sbgl_Buffer buffer)
Unmaps a previously mapped GPU buffer.
Definition sbgl_core.c:511
sbgl_ErrorDetail sbgl_GetErrorDetail(sbgl_Context *ctx)
Retrieves detailed error information including backend-specific codes.
Definition sbgl_core.c:78
void sbgl_DeviceWaitIdle(sbgl_Context *ctx)
Synchronizes the CPU with the GPU, waiting for all commands to complete.
Definition sbgl_core.c:391
uint32_t sbgl_GetFrameIndex(sbgl_Context *ctx)
Retrieves the current frame index for double/triple buffering.
Definition sbgl_core.c:489
void sbgl_DrawIndexed(sbgl_Context *ctx, uint32_t indexCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t instanceCount)
Submits an indexed draw command.
Definition sbgl_core.c:706
double sbgl_GetTime(sbgl_Context *ctx)
Retrieves the current monotonic system time in seconds.
Definition sbgl_core.c:245
void sbgl_Draw(sbgl_Context *ctx, uint32_t vertexCount, uint32_t firstVertex, uint32_t instanceCount)
Submits a non-indexed draw command.
Definition sbgl_core.c:698
uint64_t sbgl_GetBufferDeviceAddress(sbgl_Context *ctx, sbgl_Buffer buffer)
Retrieves the 64-bit GPU virtual address for a buffer.
Definition sbgl_core.c:689
void sbgl_Shutdown(sbgl_Context *ctx)
Gracefully shuts down the engine and releases all resources.
Definition sbgl_core.c:204
void sbgl_BeginDrawing(sbgl_Context *ctx)
Prepares the engine for a new frame of drawing.
Definition sbgl_core.c:262
void sbgl_BindBuffer(sbgl_Context *ctx, sbgl_Buffer buffer, sbgl_BufferUsage usage)
Binds a buffer to the pipeline.
Definition sbgl_core.c:681
void sbgl_DestroyPipeline(sbgl_Context *ctx, sbgl_Pipeline pipeline)
Destroys a graphics pipeline.
Definition sbgl_core.c:597
sbgl_Buffer sbgl_CreateBuffer(sbgl_Context *ctx, sbgl_BufferUsage usage, size_t size, const void *data)
Creates a GPU buffer.
Definition sbgl_core.c:445
void sbgl_RenderQueues(sbgl_Context *ctx, sbgl_RenderQueue **queues, uint32_t queueCount, const sbgl_Mat4 *viewProj)
Merges, sorts, and submits pending draw commands to the GPU.
Definition sbgl_core.c:808
void sbgl_DispatchCompute(sbgl_Context *ctx, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
Dispatches a compute workload.
Definition sbgl_core.c:657
sbgl_BufferUsage
Buffer usage flags.
Definition sbgl_types.h:122
sbgl_Result
Result codes for engine operations.
Definition sbgl_types.h:214
sbgl_BarrierType
Memory barrier types for compute synchronization.
Definition sbgl_types.h:142
uint32_t sbgl_Buffer
Handle for a GPU-side buffer.
Definition sbgl_types.h:37
uint32_t sbgl_Shader
Handle for a shader module.
Definition sbgl_types.h:42
uint64_t sbgl_SortKey
Bit-packed key used for sorting draw commands to minimize state changes.
Definition sbgl_types.h:57
sbgl_ShaderStage
Shader stage flags.
Definition sbgl_types.h:133
uint32_t sbgl_ComputePipeline
Handle for a compute pipeline.
Definition sbgl_types.h:52
uint32_t sbgl_Pipeline
Handle for a graphics pipeline.
Definition sbgl_types.h:47
Arena allocator.
Definition sbl_arena.h:47
Engine context.
Definition sbgl_types.h:268
Detailed error information for debugging.
Definition sbgl_types.h:253
Configuration for engine initialization.
Definition sbgl_types.h:308
Result structure for initialization.
Definition sbgl_types.h:339
Represents the real-time state of physical inputs.
Definition sbgl_input.h:165
Per-instance data for automated batching.
Definition sbgl_types.h:19
4x4 Matrix, 16-byte aligned, column-major.
Definition sbgl_math.h:83
Configuration for creating a graphics pipeline.
Definition sbgl_types.h:204
Internal storage for draw packets awaiting submission.
Definition sbgl_core.c:25
Performance telemetry data for a single frame.
Definition sbgl_types.h:175