1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 17:38:12 +00:00
serenity/Userland/Libraries/LibGL/Tex/Texture2D.h
Jelle Raaijmakers eb7c3d16fb LibGL+LibGPU+LibSoftGPU: Implement flexible pixel format conversion
A GPU (driver) is now responsible for reading and writing pixels from
and to user data. The client (LibGL) is responsible for specifying how
the user data must be interpreted or written to.

This allows us to centralize all pixel format conversion in one class,
`LibSoftGPU::PixelConverter`. For both the input and output image, it
takes a specification containing the image dimensions, the pixel type
and the selection (basically a clipping rect), and converts the pixels
from the input image to the output image.

Effectively this means we now support almost all OpenGL 1.5 formats,
and all custom logic has disappeared from:
  - `glDrawPixels`
  - `glReadPixels`
  - `glTexImage2D`
  - `glTexSubImage2D`

The new logic is still unoptimized, but on my machine I experienced no
noticeable slowdown. :^)
2022-08-27 12:28:05 +02:00

55 lines
1.8 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/Array.h>
#include <LibGL/GL/gl.h>
#include <LibGL/Tex/MipMap.h>
#include <LibGL/Tex/Sampler2D.h>
#include <LibGPU/ImageDataLayout.h>
#include <LibGfx/Vector3.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 = 11;
virtual bool is_texture_2d() const override { return true; }
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);
MipMap const& mipmap(unsigned lod) const
{
if (lod >= m_mipmaps.size())
return m_mipmaps.last();
return m_mipmaps.at(lod);
}
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 (level >= m_mipmaps.size()) ? 0 : m_mipmaps.at(level).width(); }
int height_at_lod(unsigned level) const { return (level >= m_mipmaps.size()) ? 0 : m_mipmaps.at(level).height(); }
private:
// FIXME: Mipmaps are currently unused, but we have the plumbing for it at least
Array<MipMap, LOG2_MAX_TEXTURE_SIZE> m_mipmaps;
GLenum m_internal_format;
Sampler2D m_sampler;
};
}