Skip to content

Commit eda1ffb

Browse files
gmtaawesomekling
authored andcommitted
LibGL: Implement GL_TEXTURE_LOD_BIAS for texture objects
1 parent 59fc2a4 commit eda1ffb

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Userland/Libraries/LibGL/Tex/Texture.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
3+
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
34
* Copyright (c) 2022, the SerenityOS developers.
45
*
56
* SPDX-License-Identifier: BSD-2-Clause
@@ -25,8 +26,12 @@ class Texture : public RefCounted<Texture> {
2526
RefPtr<GPU::Image> device_image() { return m_device_image; }
2627
void set_device_image(RefPtr<GPU::Image> image) { m_device_image = image; }
2728

29+
float level_of_detail_bias() const { return m_level_of_detail_bias; }
30+
void set_level_of_detail_bias(float level_of_detail_bias) { m_level_of_detail_bias = level_of_detail_bias; }
31+
2832
private:
2933
RefPtr<GPU::Image> m_device_image;
34+
float m_level_of_detail_bias { 0.f };
3035
};
3136

3237
}

Userland/Libraries/LibGL/Texture.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ void GLContext::gl_tex_parameter(GLenum target, GLenum pname, GLfloat param)
588588

589589
// FIXME: implement the remaining parameters. (https://docs.gl/gl2/glTexParameter)
590590
RETURN_WITH_ERROR_IF(pname != GL_GENERATE_MIPMAP
591+
&& pname != GL_TEXTURE_LOD_BIAS
591592
&& pname != GL_TEXTURE_MIN_FILTER
592593
&& pname != GL_TEXTURE_MAG_FILTER
593594
&& pname != GL_TEXTURE_WRAP_S
@@ -603,6 +604,9 @@ void GLContext::gl_tex_parameter(GLenum target, GLenum pname, GLfloat param)
603604
RETURN_WITH_ERROR_IF(param != GL_TRUE && param != GL_FALSE, GL_INVALID_ENUM);
604605
texture_2d->set_generate_mipmaps(param == GL_TRUE);
605606
break;
607+
case GL_TEXTURE_LOD_BIAS:
608+
texture_2d->set_level_of_detail_bias(param);
609+
break;
606610
case GL_TEXTURE_MIN_FILTER:
607611
RETURN_WITH_ERROR_IF(!(param == GL_NEAREST
608612
|| param == GL_LINEAR
@@ -733,7 +737,7 @@ void GLContext::sync_device_sampler_config()
733737
auto texture_2d = texture_unit.texture_2d_target_texture();
734738
VERIFY(!texture_2d.is_null());
735739
config.bound_image = texture_2d->device_image();
736-
config.level_of_detail_bias = texture_unit.level_of_detail_bias();
740+
config.level_of_detail_bias = texture_2d->level_of_detail_bias() + texture_unit.level_of_detail_bias();
737741

738742
auto const& sampler = texture_2d->sampler();
739743

Userland/Libraries/LibSoftGPU/Sampler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d(Vector2<AK::SIMD::f32x4> const& uv)
134134
if (m_config.mipmap_filter == GPU::MipMapFilter::None)
135135
return sample_2d_lod(uv, expand4(base_level), m_config.texture_min_filter);
136136

137-
// FIXME: add texture-level support for GL_TEXTURE_LOD_BIAS; below is only texture unit-level
138137
auto texture_lod_bias = AK::clamp(m_config.level_of_detail_bias, -MAX_TEXTURE_LOD_BIAS, MAX_TEXTURE_LOD_BIAS);
139138
// FIXME: Instead of clamping to num_levels - 1, actually make the max mipmap level configurable with glTexParameteri(GL_TEXTURE_MAX_LEVEL, max_level)
140139
auto min_level = expand4(static_cast<float>(base_level));

0 commit comments

Comments
 (0)