summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-14 14:03:58 +0100
committerskal <pascal.massimino@gmail.com>2026-02-14 14:03:58 +0100
commit61ced8aa1946cc32de4328cc75b5faf6b77723be (patch)
tree142bad05c24362d7051e80acabaddd6bac2bb753 /src/tests
parent197a03c24baba3acc35327e0e126ec49754f9945 (diff)
Refactor: add gpu_create_texture_view_2d helper
Reduces WGPUTextureViewDescriptor boilerplate from 5-7 lines to 1-2. Helper supports optional mip_levels parameter (defaults to 1). Updated 17 call sites across gpu/, tests/, and tools/. Net: -82 lines. All tests passing (34/34). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/3d/test_3d_physics.cc9
-rw-r--r--src/tests/3d/test_3d_render.cc9
-rw-r--r--src/tests/common/offscreen_render_target.cc11
-rw-r--r--src/tests/gpu/test_post_process_helper.cc10
4 files changed, 5 insertions, 34 deletions
diff --git a/src/tests/3d/test_3d_physics.cc b/src/tests/3d/test_3d_physics.cc
index 2ee5a4a..736cfc0 100644
--- a/src/tests/3d/test_3d_physics.cc
+++ b/src/tests/3d/test_3d_physics.cc
@@ -185,15 +185,8 @@ int main(int argc, char** argv) {
wgpuSurfaceGetCurrentTexture(g_surface, &surface_tex);
if (surface_tex.status ==
WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal) {
- const WGPUTextureViewDescriptor view_desc = {
- .format = g_format,
- .dimension = WGPUTextureViewDimension_2D,
- .mipLevelCount = 1,
- .arrayLayerCount = 1,
- };
-
const WGPUTextureView view =
- wgpuTextureCreateView(surface_tex.texture, &view_desc);
+ gpu_create_texture_view_2d(surface_tex.texture, g_format);
g_renderer.render(g_scene, g_camera, time, view);
wgpuTextureViewRelease(view);
wgpuSurfacePresent(g_surface);
diff --git a/src/tests/3d/test_3d_render.cc b/src/tests/3d/test_3d_render.cc
index 49a265f..06e95c4 100644
--- a/src/tests/3d/test_3d_render.cc
+++ b/src/tests/3d/test_3d_render.cc
@@ -215,15 +215,8 @@ int main(int argc, char** argv) {
wgpuSurfaceGetCurrentTexture(g_surface, &surface_tex);
if (surface_tex.status ==
WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal) {
- const WGPUTextureViewDescriptor view_desc = {
- .format = g_format,
- .dimension = WGPUTextureViewDimension_2D,
- .mipLevelCount = 1,
- .arrayLayerCount = 1,
- };
-
const WGPUTextureView view =
- wgpuTextureCreateView(surface_tex.texture, &view_desc);
+ gpu_create_texture_view_2d(surface_tex.texture, g_format);
g_renderer.render(g_scene, g_camera, time, view);
wgpuTextureViewRelease(view);
wgpuSurfacePresent(g_surface);
diff --git a/src/tests/common/offscreen_render_target.cc b/src/tests/common/offscreen_render_target.cc
index 10775a1..d322a7c 100644
--- a/src/tests/common/offscreen_render_target.cc
+++ b/src/tests/common/offscreen_render_target.cc
@@ -3,6 +3,7 @@
// Provides pixel readback for validation.
#include "offscreen_render_target.h"
+#include "gpu/gpu.h"
#include "gpu/texture_readback.h"
#include <cassert>
#include <cstdio>
@@ -27,15 +28,7 @@ OffscreenRenderTarget::OffscreenRenderTarget(WGPUInstance instance,
assert(texture_ && "Failed to create offscreen texture");
// Create texture view
- const WGPUTextureViewDescriptor view_desc = {
- .format = format,
- .dimension = WGPUTextureViewDimension_2D,
- .baseMipLevel = 0,
- .mipLevelCount = 1,
- .baseArrayLayer = 0,
- .arrayLayerCount = 1,
- };
- view_ = wgpuTextureCreateView(texture_, &view_desc);
+ view_ = gpu_create_texture_view_2d(texture_, format);
assert(view_ && "Failed to create offscreen texture view");
}
diff --git a/src/tests/gpu/test_post_process_helper.cc b/src/tests/gpu/test_post_process_helper.cc
index 13fd856..08b9e49 100644
--- a/src/tests/gpu/test_post_process_helper.cc
+++ b/src/tests/gpu/test_post_process_helper.cc
@@ -38,15 +38,7 @@ static WGPUTexture create_post_process_texture(WGPUDevice device, int width,
// Helper: Create texture view
static WGPUTextureView create_texture_view(WGPUTexture texture,
WGPUTextureFormat format) {
- const WGPUTextureViewDescriptor view_desc = {
- .format = format,
- .dimension = WGPUTextureViewDimension_2D,
- .baseMipLevel = 0,
- .mipLevelCount = 1,
- .baseArrayLayer = 0,
- .arrayLayerCount = 1,
- };
- return wgpuTextureCreateView(texture, &view_desc);
+ return gpu_create_texture_view_2d(texture, format);
}
// Minimal valid post-process shader for testing