【Overload游戏引擎】源码分析之五:OvRendering函数库(三)

2021SC@SDUSC

目录

IMesh.h与Mesh.h

1.CreateBuffers

2.ComputeBoundingSphere

3.其他函数


回顾一下前几篇文章,我们讲到了有关图形学三维空间的变换与各种数据存储对象的信息,接下来就是关于三维空间中物体的网格表示。

IMesh.h与Mesh.h

与网格相关的类有两个其中IMesh是一个基类,定义了4个纯虚函数用于子类继承。

namespace OvRendering::Resources
{
	/**
	* Interface for any mesh
	*/
	class IMesh
	{
	public:
		virtual void Bind() = 0;
		virtual void Unbind() = 0;
		virtual uint32_t GetVertexCount() = 0;
		virtual uint32_t GetIndexCount() = 0;
	};
}

而重点则是以下这个Mesh类,它对IMesh进行公有继承,用于实现网格的相关操作。

class Mesh : public IMesh
	{
	public:
		Mesh(const std::vector<Geometry::Vertex>& p_vertices, const std::vector<uint32_t>& p_indices, uint32_t p_materialIndex);
		virtual void Bind() override;
		virtual void Unbind() override;
		virtual uint32_t GetVertexCount() override;
		virtual uint32_t GetIndexCount() override;
		uint32_t GetMaterialIndex() const;
		const OvRendering::Geometry::BoundingSphere& GetBoundingSphere() const;

	private:
		void CreateBuffers(const std::vector<Geometry::Vertex>& p_vertices, const std::vector<uint32_t>& p_indices);
		void ComputeBoundingSphere(const std::vector<Geometry::Vertex>& p_vertices);

	private:
		const uint32_t m_vertexCount;
		const uint32_t m_indicesCount;
		const uint32_t m_materialIndex;

		Buffers::VertexArray							m_vertexArray;
		std::unique_ptr<Buffers::VertexBuffer<float>>	m_vertexBuffer;
		std::unique_ptr<Buffers::IndexBuffer>			m_indexBuffer;

		Geometry::BoundingSphere m_boundingSphere;
	};

Mesh类中包含了以下几个成员变量:

m_vertexCount:网格中的顶点个数;

m_indicesCount:顶点索引个数;

m_materialIndex:材质索引个数; 

m_vertexArray:顶点数组对象;</

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值