SoftwareRasterizer.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/scene/Common.h>
  7. #include <anki/Math.h>
  8. #include <anki/collision/Plane.h>
  9. namespace anki
  10. {
  11. /// @addtogroup scene
  12. /// @{
  13. /// Software rasterizer for visibility tests.
  14. class SoftwareRasterizer
  15. {
  16. public:
  17. SoftwareRasterizer()
  18. {
  19. }
  20. ~SoftwareRasterizer()
  21. {
  22. m_zbuffer.destroy(m_alloc);
  23. }
  24. /// Initialize.
  25. void init(const GenericMemoryPoolAllocator<U8>& alloc)
  26. {
  27. m_alloc = alloc;
  28. }
  29. /// Prepare for rendering. Call it before every draw.
  30. void prepare(const Mat4& mv, const Mat4& p, U width, U height);
  31. /// Render some verts.
  32. /// @param[in] verts Pointer to the first vertex to draw.
  33. /// @param vertCount The number of verts to draw.
  34. /// @param stride The stride (in bytes) of the next vertex.
  35. void draw(const F32* verts, U vertCount, U stride);
  36. /// Perform visibility tests.
  37. /// @param cs The collision shape in world space.
  38. /// @param aabb The Aabb in of the cs in world space.
  39. /// @return Return true if it's visible and false otherwise.
  40. Bool visibilityTest(const CollisionShape& cs, const Aabb& aabb) const;
  41. public: // XXX
  42. GenericMemoryPoolAllocator<U8> m_alloc;
  43. Mat4 m_mv; ///< ModelView.
  44. Mat4 m_p; ///< Projection.
  45. Mat4 m_mvp;
  46. Array<Plane, 6> m_planesL; ///< In view space.
  47. Array<Plane, 6> m_planesW; ///< In world space.
  48. U32 m_width;
  49. U32 m_height;
  50. DynamicArray<Atomic<U32>> m_zbuffer;
  51. /// @param tri In clip space.
  52. void rasterizeTriangle(const Vec4* tri);
  53. Bool computeBarycetrinc(const Vec2& a,
  54. const Vec2& b,
  55. const Vec2& c,
  56. const Vec2& p,
  57. Vec3& uvw) const;
  58. /// Clip triangle in the near plane.
  59. /// @note Triangles in view space.
  60. void clipTriangle(
  61. const Vec4* inTriangle, Vec4* outTriangles, U& outTriangleCount) const;
  62. Bool visibilityTestInternal(
  63. const CollisionShape& cs, const Aabb& aabb) const;
  64. };
  65. /// @}
  66. } // end namespace anki