summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGL/Tex/MipMap.h
blob: 01bfd02397ac4a7cf0cc3be327c26ce51c4e5755 (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
/*
 * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
 * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Vector.h>
#include <LibGL/GL/gl.h>
#include <LibGfx/Vector4.h>

namespace GL {

class MipMap {
public:
    MipMap() = default;
    ~MipMap() = default;

    void set_width(GLsizei width) { m_width = width; }
    void set_height(GLsizei height) { m_height = height; }
    GLsizei width() const { return m_width; }
    GLsizei height() const { return m_height; }

    Vector<u32>& pixel_data() { return m_pixel_data; }
    const Vector<u32>& pixel_data() const { return m_pixel_data; }

    FloatVector4 texel(unsigned x, unsigned y) const
    {
        if (x >= (unsigned)m_width || y >= (unsigned)m_height)
            return { 0, 0, 0, 0 };

        u32 texel = m_pixel_data.at(y * m_width + x);

        return {
            ((texel >> 16) & 0xff) / 255.f,
            ((texel >> 8) & 0xff) / 255.f,
            (texel & 0xff) / 255.f,
            ((texel >> 24) & 0xff) / 255.f
        };
    }

private:
    GLsizei m_width { 0 };
    GLsizei m_height { 0 };
    Vector<u32> m_pixel_data;
};
}