summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-11-29 20:57:27 +0100
committerAndreas Kling <kling@serenityos.org>2021-12-01 10:21:13 +0100
commit5788a139d89eb6d2b405531da801e68068aaa371 (patch)
tree0e76140d5703f5de3b9b5cc2d0f487a3125a3002 /Userland/Libraries
parentc7b90fa7d310dec30da393280a00223464ab5569 (diff)
downloadserenity-5788a139d89eb6d2b405531da801e68068aaa371.zip
LibGL: Implement texture unit texturing states
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h3
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp36
-rw-r--r--Userland/Libraries/LibGL/SoftwareRasterizer.cpp13
-rw-r--r--Userland/Libraries/LibGL/Tex/TextureUnit.cpp4
-rw-r--r--Userland/Libraries/LibGL/Tex/TextureUnit.h15
5 files changed, 67 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index a0fb0bac3d..bf94263349 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -188,7 +188,10 @@ extern "C" {
#define GL_REPLACE 0x1E01
// Texture targets
+#define GL_TEXTURE_1D 0x0DE0
#define GL_TEXTURE_2D 0x0DE1
+#define GL_TEXTURE_3D 0x806F
+#define GL_TEXTURE_CUBE_MAP 0x8513
// Texture Unit indices
#define GL_TEXTURE0 0x84C0
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 60d46741ca..ef0a63c695 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -553,6 +553,18 @@ void SoftwareGLContext::gl_enable(GLenum capability)
rasterizer_options.scissor_enabled = true;
update_rasterizer_options = true;
break;
+ case GL_TEXTURE_1D:
+ m_active_texture_unit->set_texture_1d_enabled(true);
+ break;
+ case GL_TEXTURE_2D:
+ m_active_texture_unit->set_texture_2d_enabled(true);
+ break;
+ case GL_TEXTURE_3D:
+ m_active_texture_unit->set_texture_3d_enabled(true);
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ m_active_texture_unit->set_texture_cube_map_enabled(true);
+ break;
default:
RETURN_WITH_ERROR_IF(true, GL_INVALID_ENUM);
}
@@ -597,6 +609,18 @@ void SoftwareGLContext::gl_disable(GLenum capability)
rasterizer_options.scissor_enabled = false;
update_rasterizer_options = true;
break;
+ case GL_TEXTURE_1D:
+ m_active_texture_unit->set_texture_1d_enabled(false);
+ break;
+ case GL_TEXTURE_2D:
+ m_active_texture_unit->set_texture_2d_enabled(false);
+ break;
+ case GL_TEXTURE_3D:
+ m_active_texture_unit->set_texture_3d_enabled(false);
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ m_active_texture_unit->set_texture_cube_map_enabled(false);
+ break;
default:
RETURN_WITH_ERROR_IF(true, GL_INVALID_ENUM);
}
@@ -1458,6 +1482,18 @@ void SoftwareGLContext::gl_get_booleanv(GLenum pname, GLboolean* data)
case GL_CULL_FACE:
*data = m_cull_faces ? GL_TRUE : GL_FALSE;
break;
+ case GL_TEXTURE_1D:
+ *data = m_active_texture_unit->texture_1d_enabled() ? GL_TRUE : GL_FALSE;
+ break;
+ case GL_TEXTURE_2D:
+ *data = m_active_texture_unit->texture_2d_enabled() ? GL_TRUE : GL_FALSE;
+ break;
+ case GL_TEXTURE_3D:
+ *data = m_active_texture_unit->texture_3d_enabled() ? GL_TRUE : GL_FALSE;
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ *data = m_active_texture_unit->texture_cube_map_enabled() ? GL_TRUE : GL_FALSE;
+ break;
default:
// According to the Khronos docs, we always return GL_INVALID_ENUM if we encounter a non-accepted value
// for `pname`
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
index 9ebeeb2a1e..fac9d59924 100644
--- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
+++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
@@ -498,8 +498,17 @@ void SoftwareRasterizer::submit_triangle(const GLTriangle& triangle, const Array
if (!texture_unit.is_bound())
continue;
- // FIXME: Don't assume Texture2D
- auto texel = texture_unit.bound_texture_2d()->sampler().sample(uv);
+ // FIXME: implement GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_CUBE_MAP
+ FloatVector4 texel;
+ switch (texture_unit.currently_bound_target()) {
+ case GL_TEXTURE_2D:
+ if (!texture_unit.texture_2d_enabled() || texture_unit.texture_3d_enabled() || texture_unit.texture_cube_map_enabled())
+ continue;
+ texel = texture_unit.bound_texture_2d()->sampler().sample(uv);
+ break;
+ default:
+ VERIFY_NOT_REACHED();
+ }
// FIXME: Implement more blend modes
switch (texture_unit.env_mode()) {
diff --git a/Userland/Libraries/LibGL/Tex/TextureUnit.cpp b/Userland/Libraries/LibGL/Tex/TextureUnit.cpp
index b8a180c447..06dab3a314 100644
--- a/Userland/Libraries/LibGL/Tex/TextureUnit.cpp
+++ b/Userland/Libraries/LibGL/Tex/TextureUnit.cpp
@@ -14,8 +14,8 @@ void TextureUnit::bind_texture_to_target(GLenum texture_target, const RefPtr<Tex
switch (texture_target) {
case GL_TEXTURE_2D:
m_texture_target_2d = static_ptr_cast<Texture2D>(texture);
- m_currently_bound_texture = texture;
m_currently_bound_target = GL_TEXTURE_2D;
+ m_currently_bound_texture = texture;
break;
default:
VERIFY_NOT_REACHED();
@@ -27,7 +27,7 @@ void TextureUnit::unbind_texture(GLenum texture_target)
switch (texture_target) {
case GL_TEXTURE_2D:
m_texture_target_2d = nullptr;
- m_currently_bound_target = 0;
+ m_currently_bound_target = GL_NONE;
break;
default:
VERIFY_NOT_REACHED();
diff --git a/Userland/Libraries/LibGL/Tex/TextureUnit.h b/Userland/Libraries/LibGL/Tex/TextureUnit.h
index 2433012515..af1f20e7ed 100644
--- a/Userland/Libraries/LibGL/Tex/TextureUnit.h
+++ b/Userland/Libraries/LibGL/Tex/TextureUnit.h
@@ -27,11 +27,26 @@ public:
void set_env_mode(GLenum mode) { m_env_mode = mode; }
GLenum env_mode() const { return m_env_mode; }
+ bool texture_1d_enabled() const { return m_texture_1d_enabled; };
+ void set_texture_1d_enabled(bool texture_1d_enabled) { m_texture_1d_enabled = texture_1d_enabled; }
+ bool texture_2d_enabled() const { return m_texture_2d_enabled; };
+ void set_texture_2d_enabled(bool texture_2d_enabled) { m_texture_2d_enabled = texture_2d_enabled; }
+ bool texture_3d_enabled() const { return m_texture_3d_enabled; };
+ void set_texture_3d_enabled(bool texture_3d_enabled) { m_texture_3d_enabled = texture_3d_enabled; }
+ bool texture_cube_map_enabled() const { return m_texture_cube_map_enabled; };
+ void set_texture_cube_map_enabled(bool texture_cube_map_enabled) { m_texture_cube_map_enabled = texture_cube_map_enabled; }
+
private:
mutable RefPtr<Texture2D> m_texture_target_2d { nullptr };
mutable RefPtr<Texture> m_currently_bound_texture { nullptr };
GLenum m_currently_bound_target;
GLenum m_env_mode { GL_MODULATE };
+
+ // Texturing state per unit, in increasing priority:
+ bool m_texture_1d_enabled { false };
+ bool m_texture_2d_enabled { false };
+ bool m_texture_3d_enabled { false };
+ bool m_texture_cube_map_enabled { false };
};
}