Check OpenGL readback byte counts

This commit is contained in:
2026-06-02 18:09:45 +02:00
parent 0fc73d51d2
commit 8c99454bf5
4 changed files with 39 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
#include "renderer_gl/opengl_capabilities.h"
#include <array>
#include <limits>
namespace pp::renderer::gl {
@@ -284,7 +285,22 @@ std::uint64_t readback_byte_count(
std::uint32_t width,
std::uint32_t height) noexcept
{
return static_cast<std::uint64_t>(width) * height * format.bytes_per_pixel;
if (format.bytes_per_pixel == 0U) {
return 0U;
}
const auto wide_width = static_cast<std::uint64_t>(width);
const auto wide_height = static_cast<std::uint64_t>(height);
if (wide_width != 0U && wide_height > std::numeric_limits<std::uint64_t>::max() / wide_width) {
return 0U;
}
const auto pixels = wide_width * wide_height;
if (pixels != 0U && format.bytes_per_pixel > std::numeric_limits<std::uint64_t>::max() / pixels) {
return 0U;
}
return pixels * format.bytes_per_pixel;
}
std::uint32_t pixel_pack_buffer_target() noexcept