Skip to content

Commit fb89089

Browse files
committed
RenderDevice::maxAnisotropy
1 parent b98a463 commit fb89089

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

Sources/ObjectivelyGPU/RenderDevice.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ static Sampler *createSampler(RenderDevice *self, const SDL_GPUSamplerCreateInfo
262262
}
263263

264264
/**
265-
* @fn Sampler *RenderDevice::createSamplerLinearRepeat(RenderDevice *self, float maxAnisotropy)
265+
* @fn Sampler *RenderDevice::createSamplerLinearRepeat(RenderDevice *self)
266266
* @memberof RenderDevice
267267
*/
268-
static Sampler *createSamplerLinearRepeat(RenderDevice *self, float maxAnisotropy) {
268+
static Sampler *createSamplerLinearRepeat(RenderDevice *self) {
269269

270270
return $(self, createSampler, &(const SDL_GPUSamplerCreateInfo) {
271271
.min_filter = SDL_GPU_FILTER_LINEAR,
@@ -274,8 +274,8 @@ static Sampler *createSamplerLinearRepeat(RenderDevice *self, float maxAnisotrop
274274
.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
275275
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
276276
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
277-
.enable_anisotropy = maxAnisotropy > 0.f,
278-
.max_anisotropy = maxAnisotropy,
277+
.enable_anisotropy = self->maxAnisotropy > 0.f,
278+
.max_anisotropy = self->maxAnisotropy,
279279
});
280280
}
281281

@@ -292,6 +292,8 @@ static Sampler *createSamplerLinearClamp(RenderDevice *self) {
292292
.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
293293
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
294294
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
295+
.enable_anisotropy = self->maxAnisotropy > 0.f,
296+
.max_anisotropy = self->maxAnisotropy,
295297
});
296298
}
297299

@@ -424,6 +426,8 @@ static RenderDevice *init(RenderDevice *self) {
424426

425427
self->shaderFormats = SDL_GetGPUShaderFormats(self->device);
426428
GPU_Assert(self->shaderFormats, "SDL_GetGPUShaderFormats");
429+
430+
self->maxAnisotropy = 0.f;
427431
}
428432

429433
return self;

Sources/ObjectivelyGPU/RenderDevice.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ struct RenderDevice {
8585
*/
8686
SDL_GPUShaderFormat shaderFormats;
8787

88+
/**
89+
* @brief The anisotropic filtering level applied by `createSamplerLinearRepeat`
90+
* and `createSamplerLinearClamp`. Defaults to `0` (anisotropic filtering
91+
* disabled). Assign directly; only affects Samplers created afterward, since
92+
* SDL_gpu Samplers are immutable once created.
93+
*/
94+
float maxAnisotropy;
95+
8896
/**
8997
* @brief The present-target Framebuffer driven by `beginFrame`/`endFrame`, or `NULL`.
9098
* @details Set via `setFramebuffer` (retained). `beginFrame` resizes it to the
@@ -241,25 +249,25 @@ struct RenderDeviceInterface {
241249
Sampler *(*createSampler)(RenderDevice *self, const SDL_GPUSamplerCreateInfo *info);
242250

243251
/**
244-
* @fn Sampler *RenderDevice::createSamplerLinearRepeat(RenderDevice *self, float maxAnisotropy)
252+
* @fn Sampler *RenderDevice::createSamplerLinearRepeat(RenderDevice *self)
245253
* @brief Creates a trilinear, wrapping Sampler -- the common preset for tiled surface textures.
246254
* @details Linear min/mag filter, linear mipmap mode, `REPEAT` addressing on all
247-
* three axes. Anisotropic filtering is enabled when @p maxAnisotropy is greater
248-
* than zero.
255+
* three axes. Anisotropic filtering is enabled when `self->maxAnisotropy` is
256+
* greater than `0`.
249257
* @param self The RenderDevice.
250-
* @param maxAnisotropy The maximum anisotropy level, or `0` to disable anisotropic filtering.
251258
* @return A new, retained Sampler. GPU_Asserts on failure. Free with `release`.
252259
* @memberof RenderDevice
253260
*/
254-
Sampler *(*createSamplerLinearRepeat)(RenderDevice *self, float maxAnisotropy);
261+
Sampler *(*createSamplerLinearRepeat)(RenderDevice *self);
255262

256263
/**
257264
* @fn Sampler *RenderDevice::createSamplerLinearClamp(RenderDevice *self)
258265
* @brief Creates a trilinear, edge-clamped Sampler -- the common preset for
259266
* continuously-sampled volumes and non-tiling images (ambient/voxel volumes,
260267
* cubemaps, post-process targets, UI images).
261268
* @details Linear min/mag filter, linear mipmap mode, `CLAMP_TO_EDGE` addressing
262-
* on all three axes, no anisotropic filtering.
269+
* on all three axes. Anisotropic filtering is enabled when `self->maxAnisotropy`
270+
* is greater than `0`.
263271
* @param self The RenderDevice.
264272
* @return A new, retained Sampler. GPU_Asserts on failure. Free with `release`.
265273
* @memberof RenderDevice

0 commit comments

Comments
 (0)