From 4152ac76d0813d9d0f67d2f04653a13fa6e17433 Mon Sep 17 00:00:00 2001 From: UjinT34 <41110182+UjinT34@users.noreply.github.com> Date: Sat, 7 Mar 2026 00:44:10 +0300 Subject: renderer: refactor Texture, Framebuffer and Renderbuffer (#13437) Part 1 of the renderer refactors --- src/render/OpenGL.hpp | 138 ++++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 66 deletions(-) (limited to 'src/render/OpenGL.hpp') diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 82b34119..c9008447 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -20,6 +20,7 @@ #include "Texture.hpp" #include "Framebuffer.hpp" #include "Renderbuffer.hpp" +#include "desktop/DesktopTypes.hpp" #include "pass/Pass.hpp" #include @@ -32,9 +33,14 @@ #include "../debug/TracyDefines.hpp" #include "../protocols/core/Compositor.hpp" #include "render/ShaderLoader.hpp" +#include "render/gl/GLFramebuffer.hpp" +#include "render/gl/GLRenderbuffer.hpp" +#include "render/gl/GLTexture.hpp" + +#define GLFB(ifb) dc(ifb.get()) struct gbm_device; -class CHyprRenderer; +class IHyprRenderer; struct SVertex { float x, y; // position @@ -108,17 +114,17 @@ struct SPreparedShaders { }; struct SMonitorRenderData { - CFramebuffer offloadFB; - CFramebuffer mirrorFB; // these are used for some effects, - CFramebuffer mirrorSwapFB; // etc - CFramebuffer offMainFB; - CFramebuffer monitorMirrorFB; // used for mirroring outputs / screencopy, does not contain artifacts like offloadFB and is in sRGB - CFramebuffer blurFB; + SP offloadFB; + SP mirrorFB; // these are used for some effects, + SP mirrorSwapFB; // etc + SP offMainFB; + SP monitorMirrorFB; // used for mirroring outputs, does not contain artifacts like offloadFB + SP blurFB; - SP stencilTex = makeShared(); + SP stencilTex = makeShared(); - bool blurFBDirty = true; - bool blurFBShouldRender = false; + bool blurFBDirty = true; + bool blurFBShouldRender = false; }; struct SCurrentRenderData { @@ -129,9 +135,9 @@ struct SCurrentRenderData { // FIXME: raw pointer galore! SMonitorRenderData* pCurrentMonData = nullptr; - CFramebuffer* currentFB = nullptr; // current rendering to - CFramebuffer* mainFB = nullptr; // main to render to - CFramebuffer* outFB = nullptr; // out to render to (if offloaded, etc) + SP currentFB = nullptr; // current rendering to + SP mainFB = nullptr; // main to render to + SP outFB = nullptr; // out to render to (if offloaded, etc) CRegion damage; CRegion finalDamage; // damage used for funal off -> main @@ -213,7 +219,7 @@ class CHyprOpenGLImpl { bool noCM = false; bool finalMonitorCM = false; SP cmBackToSRGBSource; - SP blurredBG; + SP blurredBG; }; struct SBorderRenderData { @@ -224,17 +230,17 @@ class CHyprOpenGLImpl { int outerRound = -1; /* use round */ }; - void begin(PHLMONITOR, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional finalDamage = {}); - void beginSimple(PHLMONITOR, const CRegion& damage, SP rb = nullptr, CFramebuffer* fb = nullptr); + void begin(PHLMONITOR, const CRegion& damage, SP fb = nullptr, std::optional finalDamage = {}); + void beginSimple(PHLMONITOR, const CRegion& damage, SP rb = nullptr, SP fb = nullptr); void end(); void renderRect(const CBox&, const CHyprColor&, SRectRenderData data); - void renderTexture(SP, const CBox&, STextureRenderData data); + void renderTexture(SP, const CBox&, STextureRenderData data); void renderRoundedShadow(const CBox&, int round, float roundingPower, int range, const CHyprColor& color, float a = 1.0); void renderBorder(const CBox&, const CGradientValueData&, SBorderRenderData data); void renderBorder(const CBox&, const CGradientValueData&, const CGradientValueData&, float lerp, SBorderRenderData data); - void renderTextureMatte(SP tex, const CBox& pBox, CFramebuffer& matte); - void renderTexturePrimitive(SP tex, const CBox& box); + void renderTextureMatte(SP tex, const CBox& pBox, SP matte); + void renderTexturePrimitive(SP tex, const CBox& box); void pushMonitorTransformEnabled(bool enabled); void popMonitorTransformEnabled(); @@ -271,49 +277,49 @@ class CHyprOpenGLImpl { void applyScreenShader(const std::string& path); void bindOffMain(); - void renderOffToMain(CFramebuffer* off); + void renderOffToMain(CGLFramebuffer* off); void bindBackOnMain(); bool needsACopyFB(PHLMONITOR mon); std::string resolveAssetPath(const std::string& file); - SP loadAsset(const std::string& file); - SP texFromCairo(cairo_surface_t* cairo); - SP renderText(const std::string& text, CHyprColor col, int pt, bool italic = false, const std::string& fontFamily = "", int maxWidth = 0, int weight = 400); + SP loadAsset(const std::string& file); + SP texFromCairo(cairo_surface_t* cairo); + SP renderText(const std::string& text, CHyprColor col, int pt, bool italic = false, const std::string& fontFamily = "", int maxWidth = 0, int weight = 400); void setDamage(const CRegion& damage, std::optional finalDamage = {}); DRMFormat getPreferredReadFormat(PHLMONITOR pMonitor); - std::vector getDRMFormats(); - std::vector getDRMFormatModifiers(DRMFormat format); - EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); + std::vector getDRMFormats(); + std::vector getDRMFormatModifiers(DRMFormat format); + EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); - bool initShaders(const std::string& path = ""); + bool initShaders(const std::string& path = ""); - WP useShader(WP prog); + WP useShader(WP prog); - bool explicitSyncSupported(); - WP getShaderVariant(Render::ePreparedFragmentShader frag, Render::ShaderFeatureFlags features = 0); + bool explicitSyncSupported(); + WP getShaderVariant(Render::ePreparedFragmentShader frag, Render::ShaderFeatureFlags features = 0); - bool m_shadersInitialized = false; - SP m_shaders; + bool m_shadersInitialized = false; + SP m_shaders; - SCurrentRenderData m_renderData; + SCurrentRenderData m_renderData; - Hyprutils::OS::CFileDescriptor m_gbmFD; - gbm_device* m_gbmDevice = nullptr; - EGLContext m_eglContext = nullptr; - EGLDisplay m_eglDisplay = nullptr; - EGLDeviceEXT m_eglDevice = nullptr; - uint m_failedAssetsNo = 0; + Hyprutils::OS::CFileDescriptor m_gbmFD; + gbm_device* m_gbmDevice = nullptr; + EGLContext m_eglContext = nullptr; + EGLDisplay m_eglDisplay = nullptr; + EGLDeviceEXT m_eglDevice = nullptr; + uint m_failedAssetsNo = 0; - bool m_reloadScreenShader = true; // at launch it can be set + bool m_reloadScreenShader = true; // at launch it can be set - std::map m_windowFramebuffers; - std::map m_layerFramebuffers; - std::map, CFramebuffer> m_popupFramebuffers; - std::map m_monitorRenderResources; - std::map m_monitorBGFBs; + std::map> m_windowFramebuffers; + std::map> m_layerFramebuffers; + std::map, SP> m_popupFramebuffers; + std::map m_monitorRenderResources; + std::map> m_monitorBGFBs; struct { PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr; @@ -344,7 +350,7 @@ class CHyprOpenGLImpl { bool EGL_ANDROID_native_fence_sync_ext = false; } m_exts; - SP m_screencopyDeniedTexture; + SP m_screencopyDeniedTexture; enum eEGLContextVersion : uint8_t { EGL_CONTEXT_GLES_2_0 = 0, @@ -385,10 +391,10 @@ class CHyprOpenGLImpl { bool m_monitorTransformEnabled = false; // do not modify directly std::stack m_monitorTransformStack; - SP m_missingAssetTexture; - SP m_lockDeadTexture; - SP m_lockDead2Texture; - SP m_lockTtyTextTexture; + SP m_missingAssetTexture; + SP m_lockDeadTexture; + SP m_lockDead2Texture; + SP m_lockTtyTextTexture; SP m_finalScreenShader; CTimer m_globalTimer; GLuint m_currentProgram; @@ -414,22 +420,22 @@ class CHyprOpenGLImpl { std::optional> getModsForFormat(EGLint format); // returns the out FB, can be either Mirror or MirrorSwap - CFramebuffer* blurMainFramebufferWithDamage(float a, CRegion* damage); - CFramebuffer* blurFramebufferWithDamage(float a, CRegion* damage, CFramebuffer& source); - - void passCMUniforms(WP, const NColorManagement::PImageDescription imageDescription, const NColorManagement::PImageDescription targetImageDescription, - bool modifySDR = false, float sdrMinLuminance = -1.0f, int sdrMaxLuminance = -1); - void passCMUniforms(WP, const NColorManagement::PImageDescription imageDescription); - void renderSplash(cairo_t* const, cairo_surface_t* const, double offset, const Vector2D& size); - void renderRectInternal(const CBox&, const CHyprColor&, const SRectRenderData& data); - void renderRectWithBlurInternal(const CBox&, const CHyprColor&, const SRectRenderData& data); - void renderRectWithDamageInternal(const CBox&, const CHyprColor&, const SRectRenderData& data); - WP renderToOutputInternal(); - WP renderToFBInternal(const STextureRenderData& data, eTextureType texType, const CBox& newBox); - void renderTextureInternal(SP, const CBox&, const STextureRenderData& data); - void renderTextureWithBlurInternal(SP, const CBox&, const STextureRenderData& data); - - void preBlurForCurrentMonitor(); + SP blurMainFramebufferWithDamage(float a, CRegion* damage); + SP blurFramebufferWithDamage(float a, CRegion* damage, CGLFramebuffer& source); + + void passCMUniforms(WP, const NColorManagement::PImageDescription imageDescription, const NColorManagement::PImageDescription targetImageDescription, + bool modifySDR = false, float sdrMinLuminance = -1.0f, int sdrMaxLuminance = -1); + void passCMUniforms(WP, const NColorManagement::PImageDescription imageDescription); + void renderSplash(cairo_t* const, cairo_surface_t* const, double offset, const Vector2D& size); + void renderRectInternal(const CBox&, const CHyprColor&, const SRectRenderData& data); + void renderRectWithBlurInternal(const CBox&, const CHyprColor&, const SRectRenderData& data); + void renderRectWithDamageInternal(const CBox&, const CHyprColor&, const SRectRenderData& data); + WP renderToOutputInternal(); + WP renderToFBInternal(const STextureRenderData& data, eTextureType texType, const CBox& newBox); + void renderTextureInternal(SP, const CBox&, const STextureRenderData& data); + void renderTextureWithBlurInternal(SP, const CBox&, const STextureRenderData& data); + + void preBlurForCurrentMonitor(); friend class CHyprRenderer; friend class CTexPassElement; -- cgit v1.2.3