Browse Source

Added bounds meshes to lights in the renderer

BearishSun 10 years ago
parent
commit
3882f40373

+ 57 - 0
BansheeCore/Include/BsMesh.h

@@ -63,6 +63,63 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual void readSubresource(UINT32 subresourceIdx, MeshData& data);
 		virtual void readSubresource(UINT32 subresourceIdx, MeshData& data);
 
 
+		/**
+		 * @brief	Creates a new empty mesh. Created mesh will have no sub-meshes.
+		 *
+		 * @param	numVertices		Number of vertices in the mesh.
+		 * @param	numIndices		Number of indices in the mesh. 
+		 * @param	vertexDesc		Vertex description structure that describes how are vertices organized in the
+		 *							vertex buffer. When binding a mesh to the pipeline you must ensure vertex description
+		 *							at least partially matches the input description of the currently bound vertex GPU program.
+		 * @param	usage			Optimizes performance depending on planned usage of the mesh.
+		 * @param	drawOp			Determines how should the provided indices be interpreted by the pipeline. Default option 
+		 *							is a triangle list, where three indices represent a single triangle.
+		 * @param	indexType		Size of indices, use smaller size for better performance, however be careful not to go over
+		 *							the number of vertices limited by the size.
+		 */
+		static SPtr<MeshCore> create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, int usage = MU_STATIC,
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexType indexType = IT_32BIT);
+
+		/**
+		 * @brief	Creates a new empty mesh. Created mesh will have specified sub-meshes you may render independently.
+		 *
+		 * @param	numVertices		Number of vertices in the mesh.
+		 * @param	numIndices		Number of indices in the mesh. 
+		 * @param	vertexDesc		Vertex description structure that describes how are vertices organized in the
+		 *							vertex buffer. When binding a mesh to the pipeline you must ensure vertex description
+		 *							at least partially matches the input description of the currently bound vertex GPU program.
+		 * @param	subMeshes		Defines how are indices separated into sub-meshes, and how are those sub-meshes rendered.
+		 *							Sub-meshes may be rendered independently.
+		 * @param	usage			Optimizes performance depending on planned usage of the mesh.
+		 * @param	indexType		Size of indices, use smaller size for better performance, however be careful not to go over
+		 *							the number of vertices limited by the size.
+		 */
+		static SPtr<MeshCore> create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, const Vector<SubMesh>& subMeshes,
+			int usage = MU_STATIC, IndexType indexType = IT_32BIT);
+
+		/**
+		 * @brief	Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
+		 *			by the mesh data exactly. Mesh will have no sub-meshes.
+		 *
+		 * @param	initialMeshData	Vertex and index data to initialize the mesh with.
+		 * @param	usage			Optimizes performance depending on planned usage of the mesh.
+		 * @param	drawOp			Determines how should the provided indices be interpreted by the pipeline. Default option 
+		 *							is a triangle strip, where three indices represent a single triangle.
+		 */
+		static SPtr<MeshCore> create(const MeshDataPtr& initialMeshData, int usage = MU_STATIC,
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST);
+
+		/**
+		 * @brief	Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
+		 *			by the mesh data exactly. Mesh will have specified the sub-meshes.
+		 *
+		 * @param	initialMeshData	Vertex and index data used for initializing the mesh. 
+		 * @param	subMeshes		Defines how are indices separated into sub-meshes, and how are those sub-meshes rendered.
+		 *							Sub-meshes may be rendered independently.
+		 * @param	usage			Optimizes performance depending on planned usage of the mesh.
+		 */
+		static SPtr<MeshCore> create(const MeshDataPtr& initialMeshData, const Vector<SubMesh>& subMeshes, int usage = MU_STATIC);
+
 	protected:
 	protected:
 		friend class Mesh;
 		friend class Mesh;
 
 

+ 58 - 0
BansheeCore/Source/BsMesh.cpp

@@ -272,6 +272,64 @@ namespace BansheeEngine
 		// TODO - Sync this to sim-thread possibly?
 		// TODO - Sync this to sim-thread possibly?
 	}
 	}
 
 
+	SPtr<MeshCore> MeshCore::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
+		int usage, DrawOperationType drawOp, IndexType indexType)
+	{
+		SubMesh subMesh(0, numIndices, drawOp);
+
+		SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices, 
+			vertexDesc, { subMesh }, usage, indexType, nullptr));
+		mesh->_setThisPtr(mesh);
+		mesh->initialize();
+
+		return mesh;
+	}
+
+	SPtr<MeshCore> MeshCore::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
+		const Vector<SubMesh>& subMeshes, int usage, IndexType indexType)
+	{
+		SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
+			vertexDesc, subMeshes, usage, indexType, nullptr));
+
+		mesh->_setThisPtr(mesh);
+		mesh->initialize();
+
+		return mesh;
+	}
+
+	SPtr<MeshCore> MeshCore::create(const MeshDataPtr& initialMeshData, int usage, DrawOperationType drawOp)
+	{
+		UINT32 numVertices = initialMeshData->getNumVertices();
+		UINT32 numIndices = initialMeshData->getNumIndices();
+		VertexDataDescPtr vertexDesc = initialMeshData->getVertexDesc();
+		SubMesh subMesh(0, numIndices, drawOp);
+		IndexType indexType = initialMeshData->getIndexType();
+		
+		SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
+			vertexDesc, { subMesh }, usage, indexType, initialMeshData));
+
+		mesh->_setThisPtr(mesh);
+		mesh->initialize();
+
+		return mesh;
+	}
+
+	SPtr<MeshCore> MeshCore::create(const MeshDataPtr& initialMeshData, const Vector<SubMesh>& subMeshes, int usage)
+	{
+		UINT32 numVertices = initialMeshData->getNumVertices();
+		UINT32 numIndices = initialMeshData->getNumIndices();
+		VertexDataDescPtr vertexDesc = initialMeshData->getVertexDesc();
+		IndexType indexType = initialMeshData->getIndexType();
+
+		SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(numVertices, numIndices,
+			vertexDesc, subMeshes, usage, indexType, initialMeshData));
+
+		mesh->_setThisPtr(mesh);
+		mesh->initialize();
+
+		return mesh;
+	}
+
 	Mesh::Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
 	Mesh::Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
 		int usage, DrawOperationType drawOp, IndexType indexType)
 		int usage, DrawOperationType drawOp, IndexType indexType)
 		:MeshBase(numVertices, numIndices, drawOp), mVertexDesc(vertexDesc), mUsage(usage),
 		:MeshBase(numVertices, numIndices, drawOp), mVertexDesc(vertexDesc), mUsage(usage),

+ 18 - 1
BansheeEngine/Include/BsLight.h

@@ -171,7 +171,7 @@ namespace BansheeEngine
 		 * @brief	Updates the internal bounds for the light. Call this whenever a property affecting
 		 * @brief	Updates the internal bounds for the light. Call this whenever a property affecting
 		 *			the bounds changes.
 		 *			the bounds changes.
 		 */
 		 */
-		void updateBounds();
+		virtual void updateBounds();
 
 
 		Vector3 mPosition; /**< World space position. */
 		Vector3 mPosition; /**< World space position. */
 		Quaternion mRotation; /**< World space rotation. */
 		Quaternion mRotation; /**< World space rotation. */
@@ -207,6 +207,11 @@ namespace BansheeEngine
 		 */
 		 */
 		UINT32 getRendererId() const { return mRendererId; }
 		UINT32 getRendererId() const { return mRendererId; }
 
 
+		/**
+		 * @brief	Returns a mesh that represents the light's bounds.
+		 */
+		SPtr<MeshCore> getMesh() const { return mMesh; }
+
 	protected:
 	protected:
 		friend class Light;
 		friend class Light;
 
 
@@ -223,7 +228,19 @@ namespace BansheeEngine
 		 */
 		 */
 		void syncToCore(const CoreSyncData& data) override;
 		void syncToCore(const CoreSyncData& data) override;
 
 
+		/**
+		 * @copydoc	CoreObject::updateBounds
+		 */
+		void updateBounds() override;
+
+		/**
+		 * @brief	Generates a mesh that represents the light's bounds. Uses current light properties
+		 * 			for determining the mesh type and size.
+		 */
+		void generateMesh();
+
 		UINT32 mRendererId;
 		UINT32 mRendererId;
+		SPtr<MeshCore> mMesh;
 	};
 	};
 
 
 	/**
 	/**

+ 138 - 130
BansheeEngine/Include/BsShapeMeshes3D.h

@@ -335,6 +335,144 @@ namespace BansheeEngine
 		static void antialiasedLineList(const Vector<Vector3>& linePoints, const Vector3& up, float width, float borderWidth,
 		static void antialiasedLineList(const Vector<Vector3>& linePoints, const Vector3& up, float width, float borderWidth,
 			const Color& color, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
 			const Color& color, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
 
 
+/**
+		 * @brief	Fills the provided buffers with position and index data representing an outline of an axis aligned box.
+		 * 			Use ::getNumElementsWireAABox todetermine the required sizes of the output buffers.
+		 *
+		 * @param	box				Box to create geometry for.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes.
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 */
+		static void wireAABox(const AABox& box, UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride,
+			UINT32* outIndices, UINT32 indexOffset);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing a solid axis aligned box.
+		 * 			Use ::getNumElementsAABox todetermine the required sizes of the output buffers.
+		 *
+		 * @param	box				Box to create geometry for.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 */
+		static void solidAABox(const AABox& box, UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride,
+			UINT32* outIndices, UINT32 indexOffset);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing a sphere.
+		 * 			Use ::getNumElementsSphere todetermine the required sizes of the output buffers.
+		 *
+		 * @param	sphere			Sphere to create geometry for.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	outNormals		Pre-allocated output buffer that will store the vertex normal data. Can be null if normals aren't needed.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 * @param	quality			Represents the level of tessellation the sphere will have. Higher level means higher quality
+		 *							but also more vertices and primitives.
+		 */
+		static void solidSphere(const Sphere& sphere, UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride,
+			UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing an outline of an arc. 
+		 * 			Use ::getNumElementWiresArc to determine the required sizes of the output buffers.
+		 *
+		 * @param	center			Center of the arc to generate geometry for.
+		 * @param	radius			Radius of the arc to generate geometry for.
+		 * @param	normal			Normal around which the arc is generated. Arc geometry will be perpendicular to the normal.
+		 * @param	startAngle		Angle at which the arc starts.
+		 * @param	amountAngle		Angle that the arc spans.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes.
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 * @param	quality			Represents the level of tessellation the arc will have. Higher level means higher quality
+		 *							but also more vertices and primitives.
+		 */
+		static void wireArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle,
+			UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing a solid arc. 
+		 * 			Use ::getNumElementsArc to determine the required sizes of the output buffers.
+		 *
+		 * @param	center			Center of the arc to generate geometry for.
+		 * @param	radius			Radius of the arc to generate geometry for.
+		 * @param	normal			Normal around which the arc is generated. Arc geometry will be perpendicular to the normal.
+		 * @param	startAngle		Angle at which the arc starts.
+		 * @param	amountAngle		Angle that the arc spans.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	outNormals		Pre-allocated output buffer that will store the vertex normal data.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 * @param	quality			Represents the level of tessellation the arc will have. Higher level means higher quality
+		 *							but also more vertices and primitives.
+		 */
+		static void solidArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle,
+			UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing an outline of a camera frustum.
+		 * 			Use ::getNumElementsFrustum to determine the required sizes of the output buffers.
+		 *
+		 * @param	position		Starting point for the frustum.
+		 * @param	aspect			Aspect ratio (width / height).
+		 * @param	FOV				Horizontal field of view angle.
+		 * @param	near			Distance to near clipping plane.
+		 * @param	far				Distance to far clipping plane.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes.
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 */
+		static void wireFrustum(const Vector3& position, float aspect, Degree FOV, float near, float far,
+			UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing a solid cone.
+		 * 			Use ::getNumElementsCone to determine the required sizes of the output buffers.
+		 *
+		 * @param	base			World position of the cone base.
+		 * @param	normal			Direction of the pointed part of the cone.
+		 * @param	height			Cone height (distance from base to the top).
+		 * @param	radius			Cone radius (distance from base center to outer edge).
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	outNormals		Pre-allocated output buffer that will store the vertex normal data. Can be null if normals aren't needed.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 * @param	quality			Represents the level of tessellation the cone will have. Higher level means higher quality
+		 *							but also more vertices and primitives.
+		 */
+		static void solidCone(const Vector3& base, const Vector3& normal, float height, float radius,
+			UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
+
+		/**
+		 * @brief	Fills the provided buffers with position and index data representing a solid quad.
+		 * 			Use ::getNumElementsCone to determine the required sizes of the output buffers.
+		 *
+		 * @param	area			Area covered by the quad.
+		 * @param	outVertices		Pre-allocated output buffer that will store the vertex position data.
+		 * @param	outNormals		Pre-allocated output buffer that will store the vertex normal data.
+		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
+		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
+		 * @param	outIndices		Pre-allocated output buffer that will store the index data. Indices are 32bit.
+		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
+		 */
+		static void solidQuad(const Rect3& area, UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
+
 		/**
 		/**
 		 * @brief	Calculates number of vertices and indices required for geometry of a solid axis aligned box.
 		 * @brief	Calculates number of vertices and indices required for geometry of a solid axis aligned box.
 		 */
 		 */
@@ -478,136 +616,6 @@ namespace BansheeEngine
 		static void antialiasedPolygon(const Vector<Vector3>& points, const Vector3& up, float borderWidth, const Color& color, UINT8* outVertices, UINT8* outColors,
 		static void antialiasedPolygon(const Vector<Vector3>& points, const Vector3& up, float borderWidth, const Color& color, UINT8* outVertices, UINT8* outColors,
 			UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
 			UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
 
 
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing an outline of an axis aligned box.
-		 *
-		 * @param	box				Box to create geometry for.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes.
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 */
-		static void wireAABox(const AABox& box, UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride,
-			UINT32* outIndices, UINT32 indexOffset);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing a solid axis aligned box.
-		 *
-		 * @param	box				Box to create geometry for.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 */
-		static void solidAABox(const AABox& box, UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride,
-			UINT32* outIndices, UINT32 indexOffset);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing a sphere.
-		 *
-		 * @param	sphere			Sphere to create geometry for.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	outNormals		Output buffer that will store the vertex normal data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 * @param	quality			Represents the level of tessellation the sphere will have. Higher level means higher quality
-		 *							but also more vertices and primitives.
-		 */
-		static void solidSphere(const Sphere& sphere, UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride,
-			UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing an outline of an arc.
-		 *
-		 * @param	center			Center of the arc to generate geometry for.
-		 * @param	radius			Radius of the arc to generate geometry for.
-		 * @param	normal			Normal around which the arc is generated. Arc geometry will be perpendicular to the normal.
-		 * @param	startAngle		Angle at which the arc starts.
-		 * @param	amountAngle		Angle that the arc spans.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes.
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 * @param	quality			Represents the level of tessellation the arc will have. Higher level means higher quality
-		 *							but also more vertices and primitives.
-		 */
-		static void wireArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle,
-			UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing a solid arc.
-		 *
-		 * @param	center			Center of the arc to generate geometry for.
-		 * @param	radius			Radius of the arc to generate geometry for.
-		 * @param	normal			Normal around which the arc is generated. Arc geometry will be perpendicular to the normal.
-		 * @param	startAngle		Angle at which the arc starts.
-		 * @param	amountAngle		Angle that the arc spans.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	outNormals		Output buffer that will store the vertex normal data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 * @param	quality			Represents the level of tessellation the arc will have. Higher level means higher quality
-		 *							but also more vertices and primitives.
-		 */
-		static void solidArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle,
-			UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing an outline of an axis aligned box.
-		 *
-		 * @param	position		Starting point for the frustum.
-		 * @param	aspect			Aspect ratio (width / height).
-		 * @param	FOV				Horizontal field of view angle.
-		 * @param	near			Distance to near clipping plane.
-		 * @param	far				Distance to far clipping plane.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes.
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 */
-		static void wireFrustum(const Vector3& position, float aspect, Degree FOV, float near, float far,
-			UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing a solid cone.
-		 *
-		 * @param	base			World position of the cone base.
-		 * @param	normal			Direction of the pointed part of the cone.
-		 * @param	height			Cone height (distance from base to the top).
-		 * @param	radius			Cone radius (distance from base center to outer edge).
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	outNormals		Output buffer that will store the vertex normal data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 * @param	quality			Represents the level of tessellation the cone will have. Higher level means higher quality
-		 *							but also more vertices and primitives.
-		 */
-		static void solidCone(const Vector3& base, const Vector3& normal, float height, float radius,
-			UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality);
-
-		/**
-		 * @brief	Fills the provided buffers with position and index data representing a solid quad.
-		 *
-		 * @param	area			Area covered by the quad.
-		 * @param	outVertices		Output buffer that will store the vertex position data.
-		 * @param	outNormals		Output buffer that will store the vertex normal data.
-		 * @param	vertexOffset	Offset in number of vertices from the start of the buffer to start writing at.
-		 * @param	vertexStride	Size of a single vertex, in bytes. (Same for both position and normal buffer)
-		 * @param	outIndices		Output buffer that will store the index data. Indices are 32bit.
-		 * @param	indexOffset 	Offset in number of indices from the start of the buffer to start writing at.
-		 */
-		static void solidQuad(const Rect3& area, UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
-
 	private:
 	private:
 		/**
 		/**
 		 * @brief	Calculates the center of the provided vertices.
 		 * @brief	Calculates the center of the provided vertices.

+ 70 - 1
BansheeEngine/Source/BsLight.cpp

@@ -4,6 +4,9 @@
 #include "BsRenderer.h"
 #include "BsRenderer.h"
 #include "BsFrameAlloc.h"
 #include "BsFrameAlloc.h"
 #include "BsSceneObject.h"
 #include "BsSceneObject.h"
+#include "BsVertexDataDesc.h"
+#include "BsMesh.h"
+#include "BsShapeMeshes3D.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -86,6 +89,7 @@ namespace BansheeEngine
 
 
 	void LightCore::initialize()
 	void LightCore::initialize()
 	{
 	{
+		updateBounds();
 		gRenderer()->_notifyLightAdded(this);
 		gRenderer()->_notifyLightAdded(this);
 
 
 		CoreObjectCore::initialize();
 		CoreObjectCore::initialize();
@@ -111,6 +115,8 @@ namespace BansheeEngine
 		dataPtr = rttiReadElem(dirtyFlags, dataPtr);
 		dataPtr = rttiReadElem(dirtyFlags, dataPtr);
 		dataPtr = rttiReadElem(mBounds, dataPtr);
 		dataPtr = rttiReadElem(mBounds, dataPtr);
 
 
+		updateBounds();
+
 		if (dirtyFlags == (UINT32)LightDirtyFlag::Transform)
 		if (dirtyFlags == (UINT32)LightDirtyFlag::Transform)
 		{
 		{
 			if (mIsActive)
 			if (mIsActive)
@@ -133,6 +139,68 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	void LightCore::updateBounds()
+	{
+		LightBase::updateBounds();
+
+		generateMesh();
+	}
+
+	void LightCore::generateMesh()
+	{
+		switch (mType)
+		{
+		case LightType::Directional:
+			mMesh = nullptr;
+			return;
+		case LightType::Point:
+		{
+			SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
+			vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
+
+			UINT32 numVertices = 0;
+			UINT32 numIndices = 0;
+
+			ShapeMeshes3D::getNumElementsSphere(1, numVertices, numIndices);
+			MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
+
+			UINT32* indexData = meshData->getIndices32();
+			UINT8* positionData = meshData->getElementData(VES_POSITION);
+
+			ShapeMeshes3D::solidSphere(mBounds, positionData, nullptr, 0,
+				vertexDesc->getVertexStride(), indexData, 0, 1);
+
+			mMesh = MeshCore::create(meshData);
+		}
+			return;
+		case LightType::Spot:
+		{
+			SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
+			vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
+
+			UINT32 numVertices = 0;
+			UINT32 numIndices = 0;
+
+			ShapeMeshes3D::getNumElementsCone(1, numVertices, numIndices);
+			MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
+
+			UINT32* indexData = meshData->getIndices32();
+			UINT8* positionData = meshData->getElementData(VES_POSITION);
+
+			Vector3 normal = -Vector3::UNIT_X;
+			Vector3 base = -normal * mRange;
+			
+			float radius = Math::sin(mSpotFalloffAngle) * mRange;
+
+			ShapeMeshes3D::solidCone(base, normal, mRange, radius, positionData, nullptr, 0,
+				vertexDesc->getVertexStride(), indexData, 0, 1);
+
+			mMesh = MeshCore::create(meshData);
+		}
+			return;
+		}
+	}
+
 	Light::Light()
 	Light::Light()
 		:mLastUpdateHash(0)
 		:mLastUpdateHash(0)
 	{
 	{
@@ -144,7 +212,8 @@ namespace BansheeEngine
 		: LightBase(type, color, intensity, range, castsShadows, spotAngle, spotFalloffAngle),
 		: LightBase(type, color, intensity, range, castsShadows, spotAngle, spotFalloffAngle),
 		mLastUpdateHash(0)
 		mLastUpdateHash(0)
 	{
 	{
-
+		// Calling virtual method is okay here because this is the most derived type
+		updateBounds();
 	}
 	}
 
 
 	SPtr<LightCore> Light::getCore() const
 	SPtr<LightCore> Light::getCore() const

+ 44 - 33
BansheeEngine/Source/BsShapeMeshes3D.cpp

@@ -625,9 +625,11 @@ namespace BansheeEngine
 		UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality)
 		UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality)
 	{
 	{
 		outVertices += vertexOffset * vertexStride;
 		outVertices += vertexOffset * vertexStride;
-		outNormals += vertexOffset * vertexStride;
 		outIndices += indexOffset;
 		outIndices += indexOffset;
 
 
+		if (outNormals != nullptr)
+			outNormals += vertexOffset * vertexStride;
+
 		// Generate base disc
 		// Generate base disc
 		UINT32 numArcVertices = (quality + 1) * 4;
 		UINT32 numArcVertices = (quality + 1) * 4;
 
 
@@ -639,10 +641,11 @@ namespace BansheeEngine
 
 
 		UINT32 baseIdx = numArcVertices;
 		UINT32 baseIdx = numArcVertices;
 
 
-		UINT32 totalNumBaseVertices = numArcVertices + 1;
-		for (UINT32 i = 0; i < totalNumBaseVertices; i++)
+		if (outNormals != nullptr)
 		{
 		{
-			outNormals = writeVector3(outNormals, vertexStride, -normal);
+			UINT32 totalNumBaseVertices = numArcVertices + 1;
+			for (UINT32 i = 0; i < totalNumBaseVertices; i++)
+				outNormals = writeVector3(outNormals, vertexStride, -normal);
 		}
 		}
 
 
 		UINT32 numTriangles = numArcVertices;
 		UINT32 numTriangles = numArcVertices;
@@ -668,30 +671,33 @@ namespace BansheeEngine
 		Vector3 topVertex = base + normal * height;
 		Vector3 topVertex = base + normal * height;
 
 
 		// Normals
 		// Normals
-		UINT8* outNormalsBase = outNormals;
-		UINT8* outNormalsTop = outNormals + numArcVertices * vertexStride;
-		for (INT32 i = 0; i < (INT32)numArcVertices; i++)
+		if (outNormals != nullptr)
 		{
 		{
-			int offsetA = i == 0 ? numArcVertices - 1 : i - 1;
-			int offsetB = i;
-			int offsetC = (i + 1) % numArcVertices;
+			UINT8* outNormalsBase = outNormals;
+			UINT8* outNormalsTop = outNormals + numArcVertices * vertexStride;
+			for (INT32 i = 0; i < (INT32)numArcVertices; i++)
+			{
+				int offsetA = i == 0 ? numArcVertices - 1 : i - 1;
+				int offsetB = i;
+				int offsetC = (i + 1) % numArcVertices;
 
 
-			Vector3* a = (Vector3*)(outVertices + (offsetA * vertexStride));
-			Vector3* b = (Vector3*)(outVertices + (offsetB * vertexStride));
-			Vector3* c = (Vector3*)(outVertices + (offsetC * vertexStride));
+				Vector3* a = (Vector3*)(outVertices + (offsetA * vertexStride));
+				Vector3* b = (Vector3*)(outVertices + (offsetB * vertexStride));
+				Vector3* c = (Vector3*)(outVertices + (offsetC * vertexStride));
 
 
-			Vector3 toTop = topVertex - *b;
+				Vector3 toTop = topVertex - *b;
 
 
-			Vector3 normalLeft = Vector3::cross(toTop, *a - *b);
-			normalLeft.normalize();
+				Vector3 normalLeft = Vector3::cross(toTop, *a - *b);
+				normalLeft.normalize();
 
 
-			Vector3 normalRight = Vector3::cross(*c - *b, toTop);
-			normalRight.normalize();
+				Vector3 normalRight = Vector3::cross(*c - *b, toTop);
+				normalRight.normalize();
 
 
-			Vector3 triNormal = Vector3::normalize(normalLeft + normalRight);
+				Vector3 triNormal = Vector3::normalize(normalLeft + normalRight);
 
 
-			outNormalsBase = writeVector3(outNormalsBase, vertexStride, triNormal);
-			outNormalsTop = writeVector3(outNormalsTop, vertexStride, triNormal);
+				outNormalsBase = writeVector3(outNormalsBase, vertexStride, triNormal);
+				outNormalsTop = writeVector3(outNormalsTop, vertexStride, triNormal);
+			}
 		}
 		}
 
 
 		// Top vertices (All same position, but need them separate because of different normals)
 		// Top vertices (All same position, but need them separate because of different normals)
@@ -958,7 +964,9 @@ namespace BansheeEngine
 		UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride)
 		UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride)
 	{
 	{
 		outVertices += (vertexOffset * vertexStride);
 		outVertices += (vertexOffset * vertexStride);
-		outNormals += (vertexOffset * vertexStride);
+
+		if (outNormals != nullptr)
+			outNormals += (vertexOffset * vertexStride);
 
 
 		UINT32 numVertices = 0;
 		UINT32 numVertices = 0;
 
 
@@ -982,22 +990,25 @@ namespace BansheeEngine
 		else
 		else
 		{
 		{
 			*((Vector3*)outVertices) = center + a * radius;
 			*((Vector3*)outVertices) = center + a * radius;
-			*((Vector3*)outNormals) = a;
-
 			outVertices += vertexStride;
 			outVertices += vertexStride;
-			outNormals += vertexStride;
-
+			
 			*((Vector3*)outVertices) = center + b * radius;
 			*((Vector3*)outVertices) = center + b * radius;
-			*((Vector3*)outNormals) = b;
-
 			outVertices += vertexStride;
 			outVertices += vertexStride;
-			outNormals += vertexStride;
-
+			
 			*((Vector3*)outVertices) = center + c * radius;
 			*((Vector3*)outVertices) = center + c * radius;
-			*((Vector3*)outNormals) = c;
-
 			outVertices += vertexStride;
 			outVertices += vertexStride;
-			outNormals += vertexStride;
+
+			if (outNormals != nullptr)
+			{
+				*((Vector3*)outNormals) = a;
+				outNormals += vertexStride;
+
+				*((Vector3*)outNormals) = b;
+				outNormals += vertexStride;
+
+				*((Vector3*)outNormals) = c;
+				outNormals += vertexStride;
+			}
 
 
 			numVertices += 3;
 			numVertices += 3;
 		}
 		}

+ 0 - 2
TODOExperimentation.txt

@@ -15,8 +15,6 @@ Next week:
 
 
 When doing viewport clear in DX11 it will only clear the first render target
 When doing viewport clear in DX11 it will only clear the first render target
 RenderTexturePool needs support for cube and 3D textures
 RenderTexturePool needs support for cube and 3D textures
-Lights need getLightMesh() method
- - Need cone to use when rendering spot light, sphere otherwise
 Load up and set up a test-bed with Ribek's scene
 Load up and set up a test-bed with Ribek's scene
 Quantize buffer sizes so they're divideable by 8 when requesting them from RenderTexturePool
 Quantize buffer sizes so they're divideable by 8 when requesting them from RenderTexturePool