Texture2D.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. virtual bool is_texture_2d() const override { return true; }
  24. void upload_texture_data(GLuint lod, GLint internal_format, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid const* pixels, GLsizei pixels_per_row, u8 byte_alignment);
  25. void replace_sub_texture_data(GLuint lod, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid const* pixels, GLsizei pixels_per_row, u8 byte_alignment);
  26. MipMap const& mipmap(unsigned lod) const
  27. {
  28. if (lod >= m_mipmaps.size())
  29. return m_mipmaps.back();
  30. return m_mipmaps.at(lod);
  31. }
  32. GLenum internal_format() const { return m_internal_format; }
  33. Sampler2D const& sampler() const { return m_sampler; }
  34. Sampler2D& sampler() { return m_sampler; }
  35. int width_at_lod(unsigned level) const { return (level >= m_mipmaps.size()) ? 0 : m_mipmaps.at(level).width(); }
  36. int height_at_lod(unsigned level) const { return (level >= m_mipmaps.size()) ? 0 : m_mipmaps.at(level).height(); }
  37. private:
  38. // FIXME: Mipmaps are currently unused, but we have the plumbing for it at least
  39. Array<MipMap, LOG2_MAX_TEXTURE_SIZE> m_mipmaps;
  40. GLenum m_internal_format;
  41. Sampler2D m_sampler;
  42. };
  43. }