// Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include #include namespace anki { /// @addtogroup scene /// @{ /// Software rasterizer for visibility tests. class SoftwareRasterizer { public: SoftwareRasterizer() { } ~SoftwareRasterizer() { m_zbuffer.destroy(m_alloc); } /// Initialize. void init(const GenericMemoryPoolAllocator& alloc) { m_alloc = alloc; } /// Prepare for rendering. Call it before every draw. void prepare(const Mat4& mv, const Mat4& p, U width, U height); /// Render some verts. /// @param[in] verts Pointer to the first vertex to draw. /// @param vertCount The number of verts to draw. /// @param stride The stride (in bytes) of the next vertex. void draw(const F32* verts, U vertCount, U stride); /// Perform visibility tests. /// @param cs The collision shape in world space. /// @param aabb The Aabb in of the cs in world space. /// @return Return true if it's visible and false otherwise. Bool visibilityTest(const CollisionShape& cs, const Aabb& aabb) const; public: // XXX GenericMemoryPoolAllocator m_alloc; Mat4 m_mv; ///< ModelView. Mat4 m_p; ///< Projection. Mat4 m_mvp; Array m_planesL; ///< In view space. Array m_planesW; ///< In world space. U32 m_width; U32 m_height; DynamicArray> m_zbuffer; /// @param tri In clip space. void rasterizeTriangle(const Vec4* tri); Bool computeBarycetrinc(const Vec2& a, const Vec2& b, const Vec2& c, const Vec2& p, Vec3& uvw) const; /// Clip triangle in the near plane. /// @note Triangles in view space. void clipTriangle( const Vec4* inTriangle, Vec4* outTriangles, U& outTriangleCount) const; Bool visibilityTestInternal( const CollisionShape& cs, const Aabb& aabb) const; }; /// @} } // end namespace anki