mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57: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
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
||||
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -12,6 +13,8 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGL/GL/gl.h>
|
||||
#include <LibGL/Tex/MipMap.h>
|
||||
#include <LibGL/Tex/Sampler2D.h>
|
||||
#include <LibGfx/Vector2.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
|
||||
|
@ -23,46 +26,22 @@ public:
|
|||
static constexpr u16 MAX_TEXTURE_SIZE = 2048;
|
||||
static constexpr u8 LOG2_MAX_TEXTURE_SIZE = 11;
|
||||
|
||||
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; }
|
||||
|
||||
private:
|
||||
GLsizei m_width;
|
||||
GLsizei m_height;
|
||||
Vector<u32> m_pixel_data;
|
||||
};
|
||||
|
||||
// To quote the Khronos documentation:
|
||||
// "You could say that a texture object contains a sampler object, which you access through the texture interface."
|
||||
// FIXME: Better name?
|
||||
struct TextureSamplerParamaters {
|
||||
GLint m_min_filter { GL_NEAREST_MIPMAP_LINEAR };
|
||||
GLint m_mag_filter { GL_LINEAR };
|
||||
GLint m_wrap_s_mode { GL_REPEAT };
|
||||
GLint m_wrap_t_mode { GL_REPEAT };
|
||||
};
|
||||
|
||||
public:
|
||||
Texture2D() = default;
|
||||
Texture2D()
|
||||
: m_sampler(*this)
|
||||
{
|
||||
}
|
||||
~Texture2D() { }
|
||||
|
||||
virtual bool is_texture_2d() const override { return true; }
|
||||
|
||||
void upload_texture_data(GLenum target, GLint lod, GLint internal_format, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
|
||||
void replace_sub_texture_data(GLint lod, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* data);
|
||||
FloatVector4 sample_texel(const FloatVector2& uv) const;
|
||||
|
||||
MipMap const& mipmap(unsigned lod) const;
|
||||
|
||||
GLenum internal_format() const { return m_internal_format; }
|
||||
Sampler2D const& sampler() const { return m_sampler; }
|
||||
|
||||
private:
|
||||
template<typename TCallback>
|
||||
|
@ -76,7 +55,7 @@ private:
|
|||
// FIXME: Mipmaps are currently unused, but we have the plumbing for it at least
|
||||
Array<MipMap, LOG2_MAX_TEXTURE_SIZE> m_mipmaps;
|
||||
GLenum m_internal_format;
|
||||
TextureSamplerParamaters m_sampler_params;
|
||||
Sampler2D m_sampler;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue