SoftwareRasterizer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "DepthBuffer.h"
  8. #include "GL/gl.h"
  9. #include "GLStruct.h"
  10. #include "Tex/Texture.h"
  11. #include <AK/OwnPtr.h>
  12. #include <LibGfx/Bitmap.h>
  13. #include <LibGfx/Vector4.h>
  14. namespace GL {
  15. struct RasterizerOptions {
  16. bool shade_smooth { true };
  17. bool enable_depth_test { false };
  18. bool enable_alpha_test { false };
  19. GLenum alpha_test_func { GL_ALWAYS };
  20. float alpha_test_ref_value { 0 };
  21. bool enable_blending { false };
  22. GLenum blend_source_factor { GL_ONE };
  23. GLenum blend_destination_factor { GL_ONE };
  24. };
  25. class SoftwareRasterizer final {
  26. public:
  27. SoftwareRasterizer(const Gfx::IntSize& min_size);
  28. void submit_triangle(const GLTriangle& triangle, const Texture& texture);
  29. void resize(const Gfx::IntSize& min_size);
  30. void clear_color(const FloatVector4&);
  31. void clear_depth(float);
  32. void blit_to(Gfx::Bitmap&);
  33. void wait_for_all_threads() const;
  34. void set_options(const RasterizerOptions&);
  35. RasterizerOptions options() const { return m_options; }
  36. Gfx::RGBA32 get_backbuffer_pixel(int x, int y);
  37. float get_depthbuffer_value(int x, int y);
  38. private:
  39. RefPtr<Gfx::Bitmap> m_render_target;
  40. OwnPtr<DepthBuffer> m_depth_buffer;
  41. RasterizerOptions m_options;
  42. };
  43. }