diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2021-08-11 19:57:22 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-12 18:58:41 +0200 |
commit | 12785849aa534ad0dbce87626c567d3d78b3d16d (patch) | |
tree | 32a05ae485de088b68f1678f5be2713d14daa0a3 /Userland/Libraries/LibGL/Tex/Texture2D.cpp | |
parent | fdde19d616c7ffd3b4789535ee235b92f27ab3bd (diff) | |
download | serenity-12785849aa534ad0dbce87626c567d3d78b3d16d.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibGL/Tex/Texture2D.cpp')
-rw-r--r-- | Userland/Libraries/LibGL/Tex/Texture2D.cpp | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/Userland/Libraries/LibGL/Tex/Texture2D.cpp b/Userland/Libraries/LibGL/Tex/Texture2D.cpp index 3e684e7ebd..ebc7465d9d 100644 --- a/Userland/Libraries/LibGL/Tex/Texture2D.cpp +++ b/Userland/Libraries/LibGL/Tex/Texture2D.cpp @@ -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 */ @@ -112,24 +113,12 @@ void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GL mip.set_height(height); } -FloatVector4 Texture2D::sample_texel(const FloatVector2& uv) const +MipMap const& Texture2D::mipmap(unsigned lod) const { - auto& mip = m_mipmaps.at(0); + if (lod >= m_mipmaps.size()) + return m_mipmaps.at(m_mipmaps.size() - 1); - // FIXME: Remove this to prevent a crash when we have proper texture binding - if (mip.width() == 0 || mip.height() == 0) - return { 1.0f, 1.0f, 1.0f, 1.0f }; - - u32 u = static_cast<u32>(uv.x() * mip.width()); - u32 v = static_cast<u32>(uv.y() * mip.height()); - - u32 pixel = mip.pixel_data().at(v * mip.width() + u); - - float b0 = ((pixel)&0xff) / 255.0f; - float b1 = ((pixel >> 8) & 0xff) / 255.0f; - float b2 = ((pixel >> 16) & 0xff) / 255.0f; - - return { b0, b1, b2, 1.0f }; + return m_mipmaps.at(lod); } } |