Skip to content

Commit 83f4b9c

Browse files
committed
Cosmetics
1 parent 3933ad3 commit 83f4b9c

6 files changed

Lines changed: 21 additions & 30 deletions

File tree

Documentation/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Object oriented graphics framework for SDL3 and C.
1111
## Features
1212

1313
- **Cross-platform** support for Android, iOS, macOS, Linux and Windows
14-
- **RenderDevice** owns the swapchain — drive frames with a simple `beginFrame` / `endFrame` loop and an unambiguous order of operations
15-
- **Resource objects** with automatic lifecycle — Buffer, Texture, Sampler, Shader, GraphicsPipeline and ComputePipeline initialize and tear themselves down
14+
- **Resource objects** with automatic lifecycle — Buffer, Texture, Sampler, Shader, GraphicsPipeline ComputePipeline and RenderDevice initialize and tear themselves down
1615
- **Typed passes**: RenderPass, ComputePass and CopyPass with command-lifecycle validation that catches mistakes upfront
1716
- **Framebuffer** abstracts multiple render targets, depth, and MSAA with automatic resolve — convenience without forfeiting the low-level API
1817
- **Shaders** loaded by name, with the formats supported by your platform
@@ -26,14 +25,14 @@ Uploading an image to the GPU is a single call — the staging buffer and copy p
2625

2726
```c
2827
SDL_Surface *surface = IMG_Load("crate.png");
29-
Texture *texture = $(renderDevice, createTextureFromSurface, surface, SDL_GPU_TEXTUREUSAGE_SAMPLER);
28+
Texture *texture = $(device, createTextureFromSurface, surface, SDL_GPU_TEXTUREUSAGE_SAMPLER);
3029
SDL_DestroySurface(surface);
3130
```
3231
3332
And a whole frame — acquire the swapchain, clear, draw a multisampled scene, resolve, and present:
3433
3534
```c
36-
CommandBuffer *commands = $(renderDevice, beginFrame);
35+
CommandBuffer *commands = $(device, beginFrame);
3736
if (commands) {
3837
3938
const SDL_FColor clearColor = { 0.1f, 0.1f, 0.2f, 1.f };
@@ -46,7 +45,7 @@ if (commands) {
4645
$(pass, drawPrimitives, 36, 1, 0, 0);
4746
pass = release(pass);
4847
49-
$(renderDevice, endFrame);
48+
$(device, endFrame);
5049
}
5150
```
5251

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Built on [Objectively](https://github.com/jdolan/Objectively) and [SDL_gpu](http
1313

1414
## Features
1515
* **Cross-platform** support for Android, iOS, macOS, Linux and Windows
16-
* **RenderDevice** owns the swapchain — drive frames with a simple `beginFrame` / `endFrame` loop and an unambiguous order of operations
17-
* **Resource objects** with automatic lifecycle — Buffer, Texture, Sampler, Shader, GraphicsPipeline and ComputePipeline initialize and tear themselves down
16+
* **Resource objects** with automatic lifecycle — Buffer, Texture, Sampler, Shader, GraphicsPipeline, ComputePipeline and RenderDevice initialize and tear themselves down
1817
* **Typed passes**: RenderPass, ComputePass and CopyPass with command-lifecycle validation that catches mistakes upfront
1918
* **Framebuffer** abstracts multiple render targets, depth, and MSAA with automatic resolve — convenience without forfeiting the low-level API
2019
* **Shaders** loaded by name, with the formats supported by your platform
@@ -28,14 +27,14 @@ Uploading an image to the GPU is a single call — the staging buffer and copy p
2827

2928
```c
3029
SDL_Surface *surface = IMG_Load("crate.png");
31-
Texture *texture = $(renderDevice, createTextureFromSurface, surface, SDL_GPU_TEXTUREUSAGE_SAMPLER);
30+
Texture *texture = $(device, createTextureFromSurface, surface, SDL_GPU_TEXTUREUSAGE_SAMPLER);
3231
SDL_DestroySurface(surface);
3332
```
3433
3534
And a whole frame — acquire the swapchain, clear, draw a multisampled scene, resolve, and present:
3635
3736
```c
38-
CommandBuffer *commands = $(renderDevice, beginFrame);
37+
CommandBuffer *commands = $(device, beginFrame);
3938
if (commands) {
4039
4140
const SDL_FColor clearColor = { 0.1f, 0.1f, 0.2f, 1.f };
@@ -48,7 +47,7 @@ if (commands) {
4847
$(pass, drawPrimitives, 36, 1, 0, 0);
4948
pass = release(pass);
5049
51-
$(renderDevice, endFrame);
50+
$(device, endFrame);
5251
}
5352
```
5453

Sources/ObjectivelyGPU/RenderDevice.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,12 @@ static SDL_GPUTransferBuffer *createTransferBuffer(const RenderDevice *self, con
366366
}
367367

368368
/**
369-
* @fn Texture *RenderDevice::createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage)
369+
* @fn Texture *RenderDevice::createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
370370
* @memberof RenderDevice
371371
*/
372-
static Texture *createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage,
373-
bool mipmaps) {
372+
static Texture *createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps) {
374373

375-
return $(alloc(Texture), initWithSurface, self, surface, usage, mipmaps);
374+
return $(alloc(Texture), initWithSurface, self, surface, usage, generateMipmaps);
376375
}
377376

378377
/**

Sources/ObjectivelyGPU/RenderDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ struct RenderDeviceInterface {
327327
Texture *(*createTexture)(RenderDevice *self, const SDL_GPUTextureCreateInfo *info, const void *pixels);
328328

329329
/**
330-
* @fn Texture *RenderDevice::createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool mipmaps)
330+
* @fn Texture *RenderDevice::createTextureFromSurface(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
331331
* @brief Creates a Texture from an `SDL_Surface`, uploading pixel data immediately.
332332
* @details Convenience factory for `Texture::initWithSurface`. Converts @p surface
333333
* to `SDL_PIXELFORMAT_RGBA32` if needed and uploads it as
@@ -339,7 +339,7 @@ struct RenderDeviceInterface {
339339
* @return A new, retained Texture. GPU_Asserts on failure. Free with `release`.
340340
* @memberof RenderDevice
341341
*/
342-
Texture *(*createTextureFromSurface)(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool mipmaps);
342+
Texture *(*createTextureFromSurface)(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps);
343343

344344
/**
345345
* @fn Texture *RenderDevice::createSolidColorTexture(RenderDevice *self, SDL_GPUTextureType type, Uint32 layerCount, Uint32 rgba)

Sources/ObjectivelyGPU/Texture.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,7 @@ static Texture *initWithDevice(Texture *self, RenderDevice *device, const SDL_GP
154154
self->sampleCount = info->sample_count;
155155

156156
if (pixels) {
157-
// Tightly-packed source: SDL_CalculateGPUTextureFormatSize accounts for
158-
// block-compressed formats, so this is correct for BCn/ASTC/etc. as well as
159-
// plain texel formats (where a naive width*height*texelSize would also work).
160-
const Uint32 size = SDL_CalculateGPUTextureFormatSize(info->format,
161-
info->width, info->height, info->layer_count_or_depth);
162-
157+
const Uint32 size = SDL_CalculateGPUTextureFormatSize(info->format, info->width, info->height, info->layer_count_or_depth);
163158
uploadPixels(self, pixels, size, info->width);
164159
}
165160
}
@@ -168,11 +163,10 @@ static Texture *initWithDevice(Texture *self, RenderDevice *device, const SDL_GP
168163
}
169164

170165
/**
171-
* @fn Texture *Texture::initWithSurface(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage)
166+
* @fn Texture *Texture::initWithSurface(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
172167
* @memberof Texture
173168
*/
174-
static Texture *initWithSurface(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage,
175-
bool mipmaps) {
169+
static Texture *initWithSurface(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps) {
176170

177171
assert(device);
178172
assert(surface);
@@ -182,8 +176,8 @@ static Texture *initWithSurface(Texture *self, RenderDevice *device, SDL_Surface
182176
: SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
183177
GPU_Assert(rgba, "SDL_ConvertSurface");
184178

185-
const Uint32 numLevels = mipmaps ? (Uint32) (floorf(log2f((float) SDL_min(rgba->w, rgba->h))) + 1) : 1;
186-
if (mipmaps) {
179+
const Uint32 numLevels = generateMipmaps ? (Uint32) (floorf(log2f((float) SDL_min(rgba->w, rgba->h))) + 1) : 1;
180+
if (generateMipmaps) {
187181
usage |= SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
188182
}
189183

@@ -207,7 +201,7 @@ static Texture *initWithSurface(Texture *self, RenderDevice *device, SDL_Surface
207201
(Uint32) rgba->pitch * (Uint32) rgba->h,
208202
(Uint32) rgba->pitch / bytesPerPixel);
209203

210-
if (mipmaps) {
204+
if (generateMipmaps) {
211205
// Mipmap generation is not a copy-pass operation and must run outside any pass,
212206
// so it gets its own one-shot command buffer after the base level upload above.
213207
CommandBuffer *commands = $(device, acquireCommandBuffer);

Sources/ObjectivelyGPU/Texture.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct TextureInterface {
151151
Texture *(*initWithDevice)(Texture *self, RenderDevice *device, const SDL_GPUTextureCreateInfo *info, const void *pixels);
152152

153153
/**
154-
* @fn Texture *Texture::initWithSurface(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool mipmaps)
154+
* @fn Texture *Texture::initWithSurface(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
155155
* @brief Initializes this Texture from an `SDL_Surface`, uploading its pixels immediately.
156156
* @details Converts @p surface to `SDL_PIXELFORMAT_RGBA32` if needed, derives the
157157
* dimensions from the surface, and uploads as `SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM`.
@@ -168,7 +168,7 @@ struct TextureInterface {
168168
* @return The initialized Texture, or `NULL` on failure.
169169
* @memberof Texture
170170
*/
171-
Texture *(*initWithSurface)(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool mipmaps);
171+
Texture *(*initWithSurface)(Texture *self, RenderDevice *device, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps);
172172

173173
/**
174174
* @fn void Texture::setName(Texture *self, const char *name)

0 commit comments

Comments
 (0)