From e7427e1d58d74812911b6d9460699395a8618266 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 25 Oct 2020 21:29:07 +0300 Subject: [PATCH] Add integer pixel formats & restructure pixel.hpp --- libs/gfx/include/psemek/gfx/pixel.hpp | 271 +++++++++++++++++++++++--- 1 file changed, 246 insertions(+), 25 deletions(-) diff --git a/libs/gfx/include/psemek/gfx/pixel.hpp b/libs/gfx/include/psemek/gfx/pixel.hpp index 588b6d8f..560538f6 100644 --- a/libs/gfx/include/psemek/gfx/pixel.hpp +++ b/libs/gfx/include/psemek/gfx/pixel.hpp @@ -25,9 +25,14 @@ namespace psemek::gfx struct uint10; struct uint12; + template + struct integer; + template struct pixel_traits; + // Normalized 8-bit + template <> struct pixel_traits { @@ -60,6 +65,36 @@ namespace psemek::gfx static constexpr GLenum type = gl::UNSIGNED_BYTE; }; + // Normalized 10-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::RGB10; + static constexpr GLenum format = gl::RGB; + static constexpr GLenum type = gl::UNSIGNED_BYTE; + }; + + // Normalized 12-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::RGB12; + static constexpr GLenum format = gl::RGB; + static constexpr GLenum type = gl::UNSIGNED_BYTE; + }; + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::RGBA12; + static constexpr GLenum format = gl::RGBA; + static constexpr GLenum type = gl::UNSIGNED_BYTE; + }; + + // Normalized 16-bit + template <> struct pixel_traits { @@ -92,62 +127,212 @@ namespace psemek::gfx static constexpr GLenum type = gl::UNSIGNED_BYTE; }; + // Unsigned 8-bit + template <> - struct pixel_traits> + struct pixel_traits> { - static constexpr GLenum internal_format = gl::RGB10; - static constexpr GLenum format = gl::RGB; + static constexpr GLenum internal_format = gl::R8UI; + static constexpr GLenum format = gl::RED_INTEGER; static constexpr GLenum type = gl::UNSIGNED_BYTE; }; template <> - struct pixel_traits> + struct pixel_traits, 2>> { - static constexpr GLenum internal_format = gl::RGB12; - static constexpr GLenum format = gl::RGB; + static constexpr GLenum internal_format = gl::RG8UI; + static constexpr GLenum format = gl::RG_INTEGER; static constexpr GLenum type = gl::UNSIGNED_BYTE; }; template <> - struct pixel_traits> + struct pixel_traits, 3>> { - static constexpr GLenum internal_format = gl::RGBA12; - static constexpr GLenum format = gl::RGBA; + static constexpr GLenum internal_format = gl::RGB8UI; + static constexpr GLenum format = gl::RGB_INTEGER; static constexpr GLenum type = gl::UNSIGNED_BYTE; }; template <> - struct pixel_traits + struct pixel_traits, 4>> { - static constexpr GLenum internal_format = gl::R32F; - static constexpr GLenum format = gl::RED; - static constexpr GLenum type = gl::FLOAT; + static constexpr GLenum internal_format = gl::RGBA8UI; + static constexpr GLenum format = gl::RGBA_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_BYTE; + }; + + // Unsigned 16-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::R16UI; + static constexpr GLenum format = gl::RED_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_SHORT; }; template <> - struct pixel_traits> + struct pixel_traits, 2>> { - static constexpr GLenum internal_format = gl::RG32F; - static constexpr GLenum format = gl::RG; - static constexpr GLenum type = gl::FLOAT; + static constexpr GLenum internal_format = gl::RG16UI; + static constexpr GLenum format = gl::RG_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_SHORT; }; template <> - struct pixel_traits> + struct pixel_traits, 3>> { - static constexpr GLenum internal_format = gl::RGB32F; - static constexpr GLenum format = gl::RGB; - static constexpr GLenum type = gl::FLOAT; + static constexpr GLenum internal_format = gl::RGB16UI; + static constexpr GLenum format = gl::RGB_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_SHORT; }; template <> - struct pixel_traits> + struct pixel_traits, 4>> { - static constexpr GLenum internal_format = gl::RGBA32F; - static constexpr GLenum format = gl::RGBA; - static constexpr GLenum type = gl::FLOAT; + static constexpr GLenum internal_format = gl::RGBA16UI; + static constexpr GLenum format = gl::RGBA_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_SHORT; }; + // Unsigned 32-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::R32UI; + static constexpr GLenum format = gl::RED_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_INT; + }; + + template <> + struct pixel_traits, 2>> + { + static constexpr GLenum internal_format = gl::RG32UI; + static constexpr GLenum format = gl::RG_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_INT; + }; + + template <> + struct pixel_traits, 3>> + { + static constexpr GLenum internal_format = gl::RGB32UI; + static constexpr GLenum format = gl::RGB_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_INT; + }; + + template <> + struct pixel_traits, 4>> + { + static constexpr GLenum internal_format = gl::RGBA32UI; + static constexpr GLenum format = gl::RGBA_INTEGER; + static constexpr GLenum type = gl::UNSIGNED_INT; + }; + + // Signed 8-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::R8I; + static constexpr GLenum format = gl::RED_INTEGER; + static constexpr GLenum type = gl::BYTE; + }; + + template <> + struct pixel_traits, 2>> + { + static constexpr GLenum internal_format = gl::RG8I; + static constexpr GLenum format = gl::RG_INTEGER; + static constexpr GLenum type = gl::BYTE; + }; + + template <> + struct pixel_traits, 3>> + { + static constexpr GLenum internal_format = gl::RGB8I; + static constexpr GLenum format = gl::RGB_INTEGER; + static constexpr GLenum type = gl::BYTE; + }; + + template <> + struct pixel_traits, 4>> + { + static constexpr GLenum internal_format = gl::RGBA8I; + static constexpr GLenum format = gl::RGBA_INTEGER; + static constexpr GLenum type = gl::BYTE; + }; + + // Signed 16-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::R16I; + static constexpr GLenum format = gl::RED_INTEGER; + static constexpr GLenum type = gl::SHORT; + }; + + template <> + struct pixel_traits, 2>> + { + static constexpr GLenum internal_format = gl::RG16I; + static constexpr GLenum format = gl::RG_INTEGER; + static constexpr GLenum type = gl::SHORT; + }; + + template <> + struct pixel_traits, 3>> + { + static constexpr GLenum internal_format = gl::RGB16I; + static constexpr GLenum format = gl::RGB_INTEGER; + static constexpr GLenum type = gl::SHORT; + }; + + template <> + struct pixel_traits, 4>> + { + static constexpr GLenum internal_format = gl::RGBA16I; + static constexpr GLenum format = gl::RGBA_INTEGER; + static constexpr GLenum type = gl::SHORT; + }; + + // Signed 32-bit + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::R32I; + static constexpr GLenum format = gl::RED_INTEGER; + static constexpr GLenum type = gl::INT; + }; + + template <> + struct pixel_traits, 2>> + { + static constexpr GLenum internal_format = gl::RG32I; + static constexpr GLenum format = gl::RG_INTEGER; + static constexpr GLenum type = gl::INT; + }; + + template <> + struct pixel_traits, 3>> + { + static constexpr GLenum internal_format = gl::RGB32I; + static constexpr GLenum format = gl::RGB_INTEGER; + static constexpr GLenum type = gl::INT; + }; + + template <> + struct pixel_traits, 4>> + { + static constexpr GLenum internal_format = gl::RGBA32I; + static constexpr GLenum format = gl::RGBA_INTEGER; + static constexpr GLenum type = gl::INT; + }; + + // Float 16-bit + template <> struct pixel_traits { @@ -180,6 +365,42 @@ namespace psemek::gfx static constexpr GLenum type = gl::FLOAT; }; + // Float 32-bit + + template <> + struct pixel_traits + { + static constexpr GLenum internal_format = gl::R32F; + static constexpr GLenum format = gl::RED; + static constexpr GLenum type = gl::FLOAT; + }; + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::RG32F; + static constexpr GLenum format = gl::RG; + static constexpr GLenum type = gl::FLOAT; + }; + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::RGB32F; + static constexpr GLenum format = gl::RGB; + static constexpr GLenum type = gl::FLOAT; + }; + + template <> + struct pixel_traits> + { + static constexpr GLenum internal_format = gl::RGBA32F; + static constexpr GLenum format = gl::RGBA; + static constexpr GLenum type = gl::FLOAT; + }; + + // Depth-stencil + template <> struct pixel_traits {