mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:07:44 +00:00
LibGL: Turn Sampler2D into an actual class
This extracts the sampler functionality into its own class. Beginning with OpenGL 3 samplers are actual objects, separate from textures. It makes sense to do this already as it also cleans up code organization quite a bit.
This commit is contained in:
parent
fdde19d616
commit
12785849aa
7 changed files with 164 additions and 49 deletions
49
Userland/Libraries/LibGL/Tex/MipMap.h
Normal file
49
Userland/Libraries/LibGL/Tex/MipMap.h
Normal file
|
@ -0,0 +1,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 & 0xff) / 255.f,
|
||||
((texel >> 8) & 0xff) / 255.f,
|
||||
((texel >> 16) & 0xff) / 255.f,
|
||||
((texel >> 24) & 0xff) / 255.f
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
GLsizei m_width;
|
||||
GLsizei m_height;
|
||||
Vector<u32> m_pixel_data;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue