1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 22:25:07 +00:00
serenity/Userland/Libraries/LibGL/Tex/Texture2D.h
Jelle Raaijmakers 1540c56e6c LibGL+LibGPU+LibSoftGPU: Implement GL_GENERATE_MIPMAP
We can now generate texture mipmaps on the fly if the client requests
it. This fixes the missing textures in our PrBoom+ port.
2022-09-11 22:37:07 +01:00

47 lines
1.7 KiB
C++

/*
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Texture.h"
#include <AK/IntegralMath.h>
#include <LibGL/GL/gl.h>
#include <LibGL/Tex/Sampler2D.h>
#include <LibGPU/ImageDataLayout.h>
namespace GL {
class Texture2D final : public Texture {
public:
// FIXME: These shouldn't really belong here, they're context specific.
static constexpr u16 MAX_TEXTURE_SIZE = 2048;
static constexpr u8 LOG2_MAX_TEXTURE_SIZE = AK::log2(MAX_TEXTURE_SIZE);
virtual bool is_texture_2d() const override { return true; }
void download_texture_data(GLuint lod, GPU::ImageDataLayout output_layout, GLvoid* pixels);
void upload_texture_data(GLuint lod, GLenum internal_format, GPU::ImageDataLayout input_layout, GLvoid const* pixels);
void replace_sub_texture_data(GLuint lod, GPU::ImageDataLayout input_layout, Vector3<i32> const& output_offset, GLvoid const* pixels);
void set_generate_mipmaps(bool generate_mipmaps);
GLenum internal_format() const { return m_internal_format; }
Sampler2D const& sampler() const { return m_sampler; }
Sampler2D& sampler() { return m_sampler; }
int width_at_lod(unsigned level) const { return static_cast<int>(device_image()->width_at_level(level)); }
int height_at_lod(unsigned level) const { return static_cast<int>(device_image()->height_at_level(level)); }
int depth_at_lod(unsigned level) const { return static_cast<int>(device_image()->depth_at_level(level)); }
private:
bool m_generate_mipmaps { false };
GLenum m_internal_format;
Sampler2D m_sampler;
};
}