SoftwareRasterizer.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_depth_write { true };
  21. bool enable_alpha_test { false };
  22. GLenum alpha_test_func { GL_ALWAYS };
  23. float alpha_test_ref_value { 0 };
  24. bool enable_blending { false };
  25. GLenum blend_source_factor { GL_ONE };
  26. GLenum blend_destination_factor { GL_ONE };
  27. };
  28. class SoftwareRasterizer final {
  29. public:
  30. SoftwareRasterizer(const Gfx::IntSize& min_size);
  31. void submit_triangle(const GLTriangle& triangle, const Array<TextureUnit, 32>& texture_units);
  32. void submit_triangle(const GLTriangle& triangle);
  33. void resize(const Gfx::IntSize& min_size);
  34. void clear_color(const FloatVector4&);
  35. void clear_depth(float);
  36. void blit_to(Gfx::Bitmap&);
  37. void wait_for_all_threads() const;
  38. void set_options(const RasterizerOptions&);
  39. RasterizerOptions options() const { return m_options; }
  40. Gfx::RGBA32 get_backbuffer_pixel(int x, int y);
  41. float get_depthbuffer_value(int x, int y);
  42. private:
  43. RefPtr<Gfx::Bitmap> m_render_target;
  44. OwnPtr<DepthBuffer> m_depth_buffer;
  45. RasterizerOptions m_options;
  46. };
  47. }