diff --git a/Userland/Libraries/LibGL/CMakeLists.txt b/Userland/Libraries/LibGL/CMakeLists.txt index 1814b6a328..82a62d6082 100644 --- a/Userland/Libraries/LibGL/CMakeLists.txt +++ b/Userland/Libraries/LibGL/CMakeLists.txt @@ -1,6 +1,7 @@ set(SOURCES Tex/NameAllocator.cpp Tex/Texture2D.cpp + Tex/TextureUnit.cpp Clipper.cpp GLBlend.cpp GLColor.cpp diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 5e04504c03..7ad4c77ba8 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -12,6 +12,7 @@ #include "SoftwareRasterizer.h" #include "Tex/NameAllocator.h" #include "Tex/Texture.h" +#include "Tex/TextureUnit.h" #include #include #include @@ -138,6 +139,8 @@ private: // Texture objects TextureNameAllocator m_name_allocator; HashMap> m_allocated_textures; + Array m_texture_units; + TextureUnit* m_active_texture_unit { &m_texture_units[0] }; SoftwareRasterizer m_rasterizer; diff --git a/Userland/Libraries/LibGL/Tex/TextureUnit.cpp b/Userland/Libraries/LibGL/Tex/TextureUnit.cpp new file mode 100644 index 0000000000..8b4f487045 --- /dev/null +++ b/Userland/Libraries/LibGL/Tex/TextureUnit.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021, Jesse Buhagiar + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace GL { + +void TextureUnit::bind_texture_to_target(GLenum texture_target, const RefPtr& texture) +{ + switch (texture_target) { + case GL_TEXTURE_2D: + m_texture_target_2d = texture; + m_currently_bound_texture = texture; + m_currently_bound_target = GL_TEXTURE_2D; + break; + default: + VERIFY_NOT_REACHED(); + } +} + +void TextureUnit::unbind_texture(GLenum texture_target) +{ + switch (texture_target) { + case GL_TEXTURE_2D: + m_texture_target_2d = nullptr; + m_currently_bound_target = 0; + break; + default: + VERIFY_NOT_REACHED(); + } + + m_currently_bound_texture = nullptr; +} + +} diff --git a/Userland/Libraries/LibGL/Tex/TextureUnit.h b/Userland/Libraries/LibGL/Tex/TextureUnit.h new file mode 100644 index 0000000000..df760cf48f --- /dev/null +++ b/Userland/Libraries/LibGL/Tex/TextureUnit.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021, Jesse Buhagiar + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace GL { + +class TextureUnit { +public: + TextureUnit() = default; + + void bind_texture_to_target(GLenum texture_target, const RefPtr& texture); + void unbind_texture(GLenum texture_target); + const RefPtr& get_bound_texture() const { return m_currently_bound_texture; } + + GLenum currently_bound_target() const { return m_currently_bound_target; } + bool is_bound() const { return m_currently_bound_texture != nullptr; } + +private: + RefPtr m_texture_target_2d { nullptr }; + RefPtr m_currently_bound_texture { nullptr }; + GLenum m_currently_bound_target; +}; + +}