Refactor: Use float for reading back depth values

Depth textures are always float, so we can skip the conversions. In this
case the depth value was converted to GPU_DATA_UINT_24_8 and back to
float again.
This commit is contained in:
Jeroen Bakker
2025-06-19 15:32:24 +02:00
parent 78ab68431c
commit b752195d2a

View File

@@ -2429,23 +2429,15 @@ static ViewDepths *view3d_depths_create(ARegion *region)
{
ViewDepths *d = MEM_callocN<ViewDepths>("ViewDepths");
{
GPUViewport *viewport = WM_draw_region_get_viewport(region);
GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport);
uint32_t *int_depths = static_cast<uint32_t *>(
GPU_texture_read(depth_tx, GPU_DATA_UINT_24_8, 0));
d->w = GPU_texture_width(depth_tx);
d->h = GPU_texture_height(depth_tx);
d->depths = (float *)int_depths;
/* Convert in-place. */
int pixel_count = d->w * d->h;
for (int i = 0; i < pixel_count; i++) {
d->depths[i] = (int_depths[i] >> 8u) / float(0xFFFFFF);
}
/* Assumed to be this as they are never changed. */
d->depth_range[0] = 0.0;
d->depth_range[1] = 1.0;
}
GPUViewport *viewport = WM_draw_region_get_viewport(region);
GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport);
d->w = GPU_texture_width(depth_tx);
d->h = GPU_texture_height(depth_tx);
d->depths = static_cast<float *>(GPU_texture_read(depth_tx, GPU_DATA_FLOAT, 0));
/* Assumed to be this as they are never changed. */
d->depth_range[0] = 0.0;
d->depth_range[1] = 1.0;
return d;
}