mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibGL: Implement basic texture units
These are merely a way to hold the different texture target bind points that a texture can be bound to.
This commit is contained in:
parent
2b5732ab77
commit
52e5d3c961
Notes:
sideshowbarker
2024-07-18 17:07:37 +09:00
Author: https://github.com/Quaker762 Commit: https://github.com/SerenityOS/serenity/commit/52e5d3c9617 Pull-request: https://github.com/SerenityOS/serenity/pull/7586 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/sunverwerth ✅
4 changed files with 74 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
set(SOURCES
|
||||
Tex/NameAllocator.cpp
|
||||
Tex/Texture2D.cpp
|
||||
Tex/TextureUnit.cpp
|
||||
Clipper.cpp
|
||||
GLBlend.cpp
|
||||
GLColor.cpp
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "SoftwareRasterizer.h"
|
||||
#include "Tex/NameAllocator.h"
|
||||
#include "Tex/Texture.h"
|
||||
#include "Tex/TextureUnit.h"
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Tuple.h>
|
||||
|
@ -138,6 +139,8 @@ private:
|
|||
// Texture objects
|
||||
TextureNameAllocator m_name_allocator;
|
||||
HashMap<GLuint, RefPtr<Texture>> m_allocated_textures;
|
||||
Array<TextureUnit, 32> m_texture_units;
|
||||
TextureUnit* m_active_texture_unit { &m_texture_units[0] };
|
||||
|
||||
SoftwareRasterizer m_rasterizer;
|
||||
|
||||
|
|
39
Userland/Libraries/LibGL/Tex/TextureUnit.cpp
Normal file
39
Userland/Libraries/LibGL/Tex/TextureUnit.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGL/GL/gl.h>
|
||||
#include <LibGL/Tex/TextureUnit.h>
|
||||
|
||||
namespace GL {
|
||||
|
||||
void TextureUnit::bind_texture_to_target(GLenum texture_target, const RefPtr<Texture>& 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;
|
||||
}
|
||||
|
||||
}
|
31
Userland/Libraries/LibGL/Tex/TextureUnit.h
Normal file
31
Userland/Libraries/LibGL/Tex/TextureUnit.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibGL/Tex/Texture2D.h>
|
||||
|
||||
namespace GL {
|
||||
|
||||
class TextureUnit {
|
||||
public:
|
||||
TextureUnit() = default;
|
||||
|
||||
void bind_texture_to_target(GLenum texture_target, const RefPtr<Texture>& texture);
|
||||
void unbind_texture(GLenum texture_target);
|
||||
const RefPtr<Texture>& 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<Texture2D> m_texture_target_2d { nullptr };
|
||||
RefPtr<Texture> m_currently_bound_texture { nullptr };
|
||||
GLenum m_currently_bound_target;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue