ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
Loading...
Searching...
No Matches
ObjectivelyGPU

Object oriented graphics framework for SDL3 and C.

View on GitHub — Zlib license.

About

ObjectivelyGPU is a cross-platform object oriented graphics framework for the C programming language. Built on Objectively and SDL3_gpu, it provides a unified API for modern GPU programming with Metal, Vulkan, and Direct3D 12.

Features

  • Cross-platform support for Android, iOS, macOS, Linux and Windows
  • Resource objects with automatic lifecycle — Buffer, Texture, Sampler, Shader, GraphicsPipeline ComputePipeline and RenderDevice initialize and tear themselves down
  • Typed passes: RenderPass, ComputePass and CopyPass with command-lifecycle validation that catches mistakes upfront
  • Framebuffer abstracts multiple render targets, depth, and MSAA with automatic resolve — convenience without forfeiting the low-level API
  • Shaders loaded by name, with the formats supported by your platform
  • Mathlib — vector, matrix, and quaternion math for 3D graphics

tl;dr

The verbose, error-prone handling of a raw GPU API collapses into reference-counted objects and a handful of intuitive methods.

Uploading an image to the GPU is a single call — the staging buffer and copy pass are handled for you:

SDL_Surface *surface = IMG_Load("crate.png");
Texture *texture = $(device, createTextureFromSurface, surface, SDL_GPU_TEXTUREUSAGE_SAMPLER);
SDL_DestroySurface(surface);
static Texture * createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
Definition RenderDevice.c:391
An SDL_GPUTexture and the metadata describing it.
Definition Texture.h:60

And a whole frame — acquire the swapchain, clear, draw a multisampled scene, resolve, and present:

CommandBuffer *commands = $(device, beginFrame);
if (commands) {
const SDL_FColor clearColor = { 0.1f, 0.1f, 0.2f, 1.f };
const SDL_GPUColorTargetInfo color = $(framebuffer, colorTargetInfo, 0, SDL_GPU_LOADOP_CLEAR, SDL_GPU_STOREOP_STORE, &clearColor);
const SDL_GPUDepthStencilTargetInfo depth = $(framebuffer, depthTargetInfo, SDL_GPU_LOADOP_CLEAR, SDL_GPU_STOREOP_DONT_CARE, 1.f);
RenderPass *pass = $(commands, beginRenderPass, &color, 1, &depth);
$(pass, bindPipeline, pipeline);
$(pass, bindVertexBuffers, 0, &(SDL_GPUBufferBinding) { .buffer = vertexBuffer->buffer }, 1);
$(pass, drawPrimitives, 36, 1, 0, 0);
pass = release(pass);
$(device, endFrame);
}
static RenderPass * beginRenderPass(CommandBuffer *self, const SDL_GPUColorTargetInfo *colorTargets, Uint32 numColorTargets, const SDL_GPUDepthStencilTargetInfo *depthStencil)
Definition CommandBuffer.c:114
static void bindPipeline(ComputePass *self, ComputePipeline *pipeline)
Definition ComputePass.c:57
static SDL_GPUColorTargetInfo colorTargetInfo(const Framebuffer *self, Uint32 index, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp, const SDL_FColor *clearColor)
Definition Framebuffer.c:59
static SDL_GPUDepthStencilTargetInfo depthTargetInfo(const Framebuffer *self, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp, float clearDepth)
Definition Framebuffer.c:90
static CommandBuffer * beginFrame(RenderDevice *self)
Definition RenderDevice.c:152
static void endFrame(RenderDevice *self)
Definition RenderDevice.c:209
static void drawPrimitives(const RenderPass *self, Uint32 numVertices, Uint32 numInstances, Uint32 firstVertex, Uint32 firstInstance)
Definition RenderPass.c:179
static void bindVertexBuffers(const RenderPass *self, Uint32 firstSlot, const SDL_GPUBufferBinding *bindings, Uint32 num)
Definition RenderPass.c:103
A recorded sequence of GPU commands for a single frame.
Definition CommandBuffer.h:80
A scoped render pass for recording draw commands into a CommandBuffer.
Definition RenderPass.h:57

The endFrame method resolves the multisampled Framebuffer and presents to the swapchain for you. No manual resolve targets, no store-op bookkeeping, no presentation plumbing.

Getting Started

Consult the Installing ObjectivelyGPU for dependencies, building, and linking.

User Guide

Consult the ObjectivelyGPU User Guide to draw your first frame — the render device, resource objects, framebuffers and MSAA, the typed passes, and shaders.

Class Hierarchy

Browse the Class Hierarchy to navigate the full API.

Project Showcase

  1. Hello renders a spinning, multisampled 3D cube.
  1. HelloCompute animates particles with a compute shader and draws them as points.
  1. ObjectivelyMVC is a framework for modern game interfaces built on SDL3, Objectively and ObjectivelyGPU.
  1. Quetoo is a free first-person shooter that uses Objectively, ObjectivelyGPU and ObjectivelyMVC extensively.