summaryrefslogtreecommitdiff
path: root/src/render/Texture.hpp
blob: e0ef5503e291f9200f8dad070507b23572f6ca84 (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 "../defines.hpp"
#include <aquamarine/buffer/Buffer.hpp>
#include <hyprutils/math/Misc.hpp>

class IHLBuffer;
HYPRUTILS_FORWARD(Math, CRegion);
using namespace Hyprutils::Math;

enum TEXTURETYPE {
    TEXTURE_INVALID,  // Invalid
    TEXTURE_RGBA,     // 4 channels
    TEXTURE_RGBX,     // discard A
    TEXTURE_EXTERNAL, // EGLImage
};

class CTexture {
  public:
    CTexture();

    CTexture(CTexture&)        = delete;
    CTexture(CTexture&&)       = delete;
    CTexture(const CTexture&&) = delete;
    CTexture(const CTexture&)  = delete;

    CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size);

    CTexture(const SP<Aquamarine::IBuffer> buffer);
    // this ctor takes ownership of the eglImage.
    CTexture(const Aquamarine::SDMABUFAttrs&, void* image);
    ~CTexture();

    void        destroyTexture();
    void        allocate();
    void        update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const CRegion& damage);

    TEXTURETYPE m_iType      = TEXTURE_RGBA;
    GLenum      m_iTarget    = GL_TEXTURE_2D;
    GLuint      m_iTexID     = 0;
    Vector2D    m_vSize      = {};
    void*       m_pEglImage  = nullptr;
    eTransform  m_eTransform = HYPRUTILS_TRANSFORM_NORMAL;
    bool        m_bOpaque    = false;

  private:
    void createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size);
    void createFromDma(const Aquamarine::SDMABUFAttrs&, void* image);
};