Texture2D.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
  3. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  4. * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include "Texture.h"
  10. #include <AK/IntegralMath.h>
  11. #include <LibGL/GL/gl.h>
  12. #include <LibGL/Tex/Sampler2D.h>
  13. #include <LibGPU/ImageDataLayout.h>
  14. namespace GL {
  15. class Texture2D final : public Texture {
  16. public:
  17. virtual bool is_texture_2d() const override { return true; }
  18. void download_texture_data(GLuint lod, GPU::ImageDataLayout output_layout, GLvoid* pixels);
  19. void upload_texture_data(GLuint lod, GLenum internal_format, GPU::ImageDataLayout input_layout, GLvoid const* pixels);
  20. void replace_sub_texture_data(GLuint lod, GPU::ImageDataLayout input_layout, Vector3<i32> const& output_offset, GLvoid const* pixels);
  21. void set_generate_mipmaps(bool generate_mipmaps);
  22. GLenum internal_format() const { return m_internal_format; }
  23. Sampler2D const& sampler() const { return m_sampler; }
  24. Sampler2D& sampler() { return m_sampler; }
  25. int width_at_lod(unsigned level) const { return static_cast<int>(device_image()->width_at_level(level)); }
  26. int height_at_lod(unsigned level) const { return static_cast<int>(device_image()->height_at_level(level)); }
  27. int depth_at_lod(unsigned level) const { return static_cast<int>(device_image()->depth_at_level(level)); }
  28. private:
  29. bool m_generate_mipmaps { false };
  30. GLenum m_internal_format;
  31. Sampler2D m_sampler;
  32. };
  33. }