Texture2D.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
  3. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include "Texture.h"
  9. #include <AK/Array.h>
  10. #include <AK/RefCounted.h>
  11. #include <AK/Vector.h>
  12. #include <LibGL/GL/gl.h>
  13. #include <LibGL/Tex/MipMap.h>
  14. #include <LibGL/Tex/Sampler2D.h>
  15. #include <LibGfx/Vector2.h>
  16. #include <LibGfx/Vector4.h>
  17. namespace GL {
  18. class Texture2D final : public Texture {
  19. public:
  20. // FIXME: These shouldn't really belong here, they're context specific.
  21. static constexpr u16 MAX_TEXTURE_SIZE = 2048;
  22. static constexpr u8 LOG2_MAX_TEXTURE_SIZE = 11;
  23. public:
  24. virtual bool is_texture_2d() const override { return true; }
  25. void upload_texture_data(GLuint lod, GLint internal_format, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels, GLsizei pixels_per_row, u8 byte_alignment);
  26. void replace_sub_texture_data(GLuint lod, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels, GLsizei pixels_per_row, u8 byte_alignment);
  27. MipMap const& mipmap(unsigned lod) const
  28. {
  29. if (lod >= m_mipmaps.size())
  30. return m_mipmaps.back();
  31. return m_mipmaps.at(lod);
  32. }
  33. GLenum internal_format() const { return m_internal_format; }
  34. Sampler2D const& sampler() const { return m_sampler; }
  35. Sampler2D& sampler() { return m_sampler; }
  36. int width_at_lod(unsigned level) const { return (level >= m_mipmaps.size()) ? 0 : m_mipmaps.at(level).width(); }
  37. int height_at_lod(unsigned level) const { return (level >= m_mipmaps.size()) ? 0 : m_mipmaps.at(level).height(); }
  38. private:
  39. // FIXME: Mipmaps are currently unused, but we have the plumbing for it at least
  40. Array<MipMap, LOG2_MAX_TEXTURE_SIZE> m_mipmaps;
  41. GLenum m_internal_format;
  42. Sampler2D m_sampler;
  43. };
  44. }