diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2026-01-07 19:53:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-07 19:53:42 +0100 |
| commit | 918e2bb9be0e1d233f9394f1d569137788c43c01 (patch) | |
| tree | a1623c8cd20c7ad625f65adb05cfe82a9e06ee8c /src/helpers/Format.hpp | |
| parent | a383ca1866b04d175bc2cf208859147d22a6968e (diff) | |
renderer/gl: add internal gl formats and reduce internal driver format conversions (#12879)
* format: add internal formats for drm formats
cross referenced with weston and added internal formats and types for a
lot of missing ones. also added a isFormatYUV helper.
* framebuffer: ensure we use right internalformat
ensure we use the right internal format to avoid internal driver
blitting, also since we only attach the GL_STENCIL_ATTACHMENT we might
just aswell only use the GL_STENCIL_INDEX8 to not confuse drivers that
we want a depth aswell.
* texture: use external on yuv or non linear mods
using external makes us use the gpu's internal detiler.
and this is makes intel a lot happier then having to format convert it
to a linear format internally.
* shaders: add external support to CM frag
add external support to CM frag, and correct ext.frag typo.
* formats: remove duplicates and fix a typo in cm.frag
remove duplicate formats and a typo in cm.frag
* formats: add swizzle logic to all formats
add swizzle logic from weston for all formats and use it in shm texture
paths.
* format: more format changes
use monitor drm format instead of forcing something different.
* shader: remove external from cm.frag
drivers want this resolved at compiletime cant use both
samplerExternalOES and sampler2d and then runtime branch it.
* screencopy: swizzle textures in screencopy
swizzle textures in screencopy, to get the right colors when copying.
* screencopy: restore old behaviour
try restore old behaviour before the gles3 format changes.
glReadPixels had the wrong format, so i went to far trying to mitigate
it. should be like before now.
Diffstat (limited to 'src/helpers/Format.hpp')
| -rw-r--r-- | src/helpers/Format.hpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/helpers/Format.hpp b/src/helpers/Format.hpp index fe68f763..917fe3cb 100644 --- a/src/helpers/Format.hpp +++ b/src/helpers/Format.hpp @@ -2,22 +2,43 @@ #include <cstdint> #include <string> +#include <GLES3/gl32.h> #include "math/Math.hpp" #include <aquamarine/backend/Misc.hpp> using DRMFormat = uint32_t; using SHMFormat = uint32_t; +#define SWIZZLE_A1GB {GL_ALPHA, GL_ONE, GL_GREEN, GL_BLUE} +#define SWIZZLE_ABG1 {GL_ALPHA, GL_BLUE, GL_GREEN, GL_ONE} +#define SWIZZLE_ABGR {GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED} +#define SWIZZLE_ARGB {GL_ALPHA, GL_RED, GL_GREEN, GL_BLUE} +#define SWIZZLE_B1RG {GL_BLUE, GL_ONE, GL_RED, GL_GREEN} +#define SWIZZLE_BARG {GL_BLUE, GL_ALPHA, GL_RED, GL_GREEN} +#define SWIZZLE_BGR1 {GL_BLUE, GL_GREEN, GL_RED, GL_ONE} +#define SWIZZLE_BGRA {GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA} +#define SWIZZLE_G1AB {GL_GREEN, GL_ONE, GL_ALPHA, GL_BLUE} +#define SWIZZLE_GBA1 {GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE} +#define SWIZZLE_GBAR {GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED} +#define SWIZZLE_GRAB {GL_GREEN, GL_RED, GL_ALPHA, GL_BLUE} +#define SWIZZLE_R001 {GL_RED, GL_ZERO, GL_ZERO, GL_ONE} +#define SWIZZLE_R1BG {GL_RED, GL_ONE, GL_BLUE, GL_GREEN} +#define SWIZZLE_RABG {GL_RED, GL_ALPHA, GL_BLUE, GL_GREEN} +#define SWIZZLE_RG01 {GL_RED, GL_GREEN, GL_ZERO, GL_ONE} +#define SWIZZLE_GR01 {GL_GREEN, GL_RED, GL_ZERO, GL_ONE} +#define SWIZZLE_RGB1 {GL_RED, GL_GREEN, GL_BLUE, GL_ONE} +#define SWIZZLE_RGBA {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA} + struct SPixelFormat { - DRMFormat drmFormat = 0; /* DRM_FORMAT_INVALID */ - bool flipRB = false; - int glInternalFormat = 0; - int glFormat = 0; - int glType = 0; - bool withAlpha = true; - DRMFormat alphaStripped = 0; /* DRM_FORMAT_INVALID */ - uint32_t bytesPerBlock = 0; - Vector2D blockSize; + DRMFormat drmFormat = 0; /* DRM_FORMAT_INVALID */ + int glInternalFormat = 0; + int glFormat = 0; + int glType = 0; + bool withAlpha = true; + DRMFormat alphaStripped = 0; /* DRM_FORMAT_INVALID */ + uint32_t bytesPerBlock = 0; + Vector2D blockSize; + std::optional<std::array<GLint, 4>> swizzle = std::nullopt; }; using SDRMFormat = Aquamarine::SDRMFormat; @@ -28,6 +49,7 @@ namespace NFormatUtils { const SPixelFormat* getPixelFormatFromDRM(DRMFormat drm); const SPixelFormat* getPixelFormatFromGL(uint32_t glFormat, uint32_t glType, bool alpha); + bool isFormatYUV(uint32_t drmFormat); bool isFormatOpaque(DRMFormat drm); int pixelsPerBlock(const SPixelFormat* const fmt); int minStride(const SPixelFormat* const fmt, int32_t width); |
