summaryrefslogtreecommitdiff
path: root/src/render/gl/GLTexture.hpp
blob: 34510e903f36c1e22bd711e3e5ec69fa42b9e89f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include "../Texture.hpp"
#include <aquamarine/buffer/Buffer.hpp>
#include <hyprutils/math/Misc.hpp>

class CGLTexture : public ITexture {
  public:
    using ITexture::ITexture;

    CGLTexture(CGLTexture&)        = delete;
    CGLTexture(CGLTexture&&)       = delete;
    CGLTexture(const CGLTexture&&) = delete;
    CGLTexture(const CGLTexture&)  = delete;

    CGLTexture(bool opaque = false);
    CGLTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size, bool keepDataCopy = false, bool opaque = false);
    CGLTexture(const Aquamarine::SDMABUFAttrs&, void* image, bool opaque = false);
    CGLTexture(std::span<const float> lut3D, size_t N);
    ~CGLTexture();

    void allocate(const Vector2D& size, uint32_t drmFormat = 0) override;
    void update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const CRegion& damage) override;
    void bind() override;
    void unbind() override;
    void setTexParameter(GLenum pname, GLint param) override;
    bool ok() override;
    bool isDMA() override;

  private:
    void* m_eglImage = nullptr;

    enum eTextureParam : uint8_t {
        TEXTURE_PAR_WRAP_S = 0,
        TEXTURE_PAR_WRAP_T,
        TEXTURE_PAR_MAG_FILTER,
        TEXTURE_PAR_MIN_FILTER,
        TEXTURE_PAR_SWIZZLE_R,
        TEXTURE_PAR_SWIZZLE_B,
        TEXTURE_PAR_LAST,
    };

    GLenum                                             m_target = GL_TEXTURE_2D;

    void                                               swizzle(const std::array<GLint, 4>& colors);
    constexpr std::optional<size_t>                    getCacheStateIndex(GLenum pname);

    std::array<std::optional<GLint>, TEXTURE_PAR_LAST> m_cachedStates;
};