SoftwareRasterizer.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/Texture2D.h"
  11. #include "Tex/TextureUnit.h"
  12. #include <AK/Array.h>
  13. #include <AK/OwnPtr.h>
  14. #include <LibGfx/Bitmap.h>
  15. #include <LibGfx/Vector4.h>
  16. namespace GL {
  17. struct RasterizerOptions {
  18. bool shade_smooth { true };
  19. bool enable_depth_test { false };
  20. bool enable_alpha_test { false };
  21. GLenum alpha_test_func { GL_ALWAYS };
  22. float alpha_test_ref_value { 0 };
  23. bool enable_blending { false };
  24. GLenum blend_source_factor { GL_ONE };
  25. GLenum blend_destination_factor { GL_ONE };
  26. };
  27. class SoftwareRasterizer final {
  28. public:
  29. SoftwareRasterizer(const Gfx::IntSize& min_size);
  30. void submit_triangle(const GLTriangle& triangle, const Array<TextureUnit, 32>& texture_units);
  31. void submit_triangle(const GLTriangle& triangle);
  32. void resize(const Gfx::IntSize& min_size);
  33. void clear_color(const FloatVector4&);
  34. void clear_depth(float);
  35. void blit_to(Gfx::Bitmap&);
  36. void wait_for_all_threads() const;
  37. void set_options(const RasterizerOptions&);
  38. RasterizerOptions options() const { return m_options; }
  39. Gfx::RGBA32 get_backbuffer_pixel(int x, int y);
  40. float get_depthbuffer_value(int x, int y);
  41. private:
  42. RefPtr<Gfx::Bitmap> m_render_target;
  43. OwnPtr<DepthBuffer> m_depth_buffer;
  44. RasterizerOptions m_options;
  45. };
  46. }