SoftwareRasterizer.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. u32 color_mask { 0xffffffff };
  28. float depth_min { 0 };
  29. float depth_max { 1 };
  30. GLenum depth_func { GL_LESS };
  31. GLenum polygon_mode { GL_FILL };
  32. FloatVector4 fog_color {
  33. 0.0f,
  34. 0.0f,
  35. 0.0f,
  36. 0.0f,
  37. };
  38. GLfloat fog_density { 1.0f };
  39. GLenum fog_mode { GL_EXP };
  40. };
  41. class SoftwareRasterizer final {
  42. public:
  43. SoftwareRasterizer(const Gfx::IntSize& min_size);
  44. void submit_triangle(const GLTriangle& triangle, const Array<TextureUnit, 32>& texture_units);
  45. void submit_triangle(const GLTriangle& triangle);
  46. void resize(const Gfx::IntSize& min_size);
  47. void clear_color(const FloatVector4&);
  48. void clear_depth(float);
  49. void blit_to(Gfx::Bitmap&);
  50. void wait_for_all_threads() const;
  51. void set_options(const RasterizerOptions&);
  52. RasterizerOptions options() const { return m_options; }
  53. Gfx::RGBA32 get_backbuffer_pixel(int x, int y);
  54. float get_depthbuffer_value(int x, int y);
  55. private:
  56. RefPtr<Gfx::Bitmap> m_render_target;
  57. OwnPtr<DepthBuffer> m_depth_buffer;
  58. RasterizerOptions m_options;
  59. };
  60. }