| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "BsResource.h"
- #include "BsBounds.h"
- #include "BsSubMesh.h"
- namespace BansheeEngine
- {
- /** @addtogroup Resources
- * @{
- */
- /**
- * Planned usage for the mesh. These options usually affect performance and you should specify static if you don't plan
- * on modifying the mesh often, otherwise specify dynamic.
- */
- enum MeshUsage
- {
- MU_STATIC, /**< Specify for a mesh that is not often updated from the CPU. */
- MU_DYNAMIC, /**< Specify for a mesh that is often updated from the CPU. */
- /** All mesh data will also be cached in CPU memory, making it available for fast read access from the CPU. */
- MU_CPUCACHED = 0x1000,
- MU_CPUREADABLE = 0x2000 /**< Allows the CPU to directly read the mesh data buffers from the GPU. */
- };
- /** Properties of a Mesh. Shared between sim and core thread versions of a Mesh. */
- class BS_CORE_EXPORT MeshProperties
- {
- public:
- MeshProperties();
- MeshProperties(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp);
- MeshProperties(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes);
- /**
- * Retrieves a sub-mesh containing data used for rendering a certain portion of this mesh. If no sub-meshes are
- * specified manually a special sub-mesh containing all indices is returned.
- */
- const SubMesh& getSubMesh(UINT32 subMeshIdx = 0) const;
- /** Retrieves a total number of sub-meshes in this mesh. */
- UINT32 getNumSubMeshes() const;
- /** Returns maximum number of vertices the mesh may store. */
- UINT32 getNumVertices() const { return mNumVertices; }
- /** Returns maximum number of indices the mesh may store. */
- UINT32 getNumIndices() const { return mNumIndices; }
- /** Returns bounds of the geometry contained in the vertex buffers for all sub-meshes. */
- const Bounds& getBounds() const { return mBounds; }
- protected:
- friend class MeshBase;
- friend class MeshCoreBase;
- friend class Mesh;
- friend class MeshCore;
- friend class TransientMesh;
- friend class TransientMeshCore;
- friend class MeshBaseRTTI;
- Vector<SubMesh> mSubMeshes;
- UINT32 mNumVertices;
- UINT32 mNumIndices;
- Bounds mBounds;
- };
- /** @} */
- /** @addtogroup Implementation
- * @{
- */
- /**
- * Core version of a class used as a basis for all implemenations of meshes.
- *
- * @see MeshBase
- *
- * @note Core thread.
- */
- class BS_CORE_EXPORT MeshCoreBase : public CoreObjectCore
- {
- public:
- MeshCoreBase(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes);
- virtual ~MeshCoreBase() { }
- /** Get vertex data used for rendering. */
- virtual SPtr<VertexData> getVertexData() const = 0;
- /** Get index data used for rendering. */
- virtual SPtr<IndexBufferCore> getIndexBuffer() const = 0;
- /**
- * Returns an offset into the vertex buffers that is returned by getVertexData() that signifies where this meshes
- * vertices begin.
- *
- * @note Used when multiple meshes share the same buffers.
- */
- virtual UINT32 getVertexOffset() const { return 0; }
- /**
- * Returns an offset into the index buffer that is returned by getIndexData() that signifies where this meshes
- * indices begin.
- *
- * @note Used when multiple meshes share the same buffers.
- */
- virtual UINT32 getIndexOffset() const { return 0; }
- /** Returns a structure that describes how are the vertices stored in the mesh's vertex buffer. */
- virtual SPtr<VertexDataDesc> getVertexDesc() const = 0;
- /**
- * Called whenever this mesh starts being used on the GPU.
- *
- * @note Needs to be called after all commands referencing this mesh have been sent to the GPU.
- */
- virtual void _notifyUsedOnGPU() { }
- /** Returns properties that contain information about the mesh. */
- const MeshProperties& getProperties() const { return mProperties; }
- protected:
- /** @copydoc CoreObjectCore::syncToCore */
- void syncToCore(const CoreSyncData& data) override;
- MeshProperties mProperties;
- };
- /**
- * Base class all mesh implementations derive from. Meshes hold geometry information, normally in the form of one or
- * several index or vertex buffers. Different mesh implementations might choose to manage those buffers differently.
- *
- * @note Sim thread.
- */
- class BS_CORE_EXPORT MeshBase : public Resource
- {
- public:
- /**
- * Constructs a new mesh with no sub-meshes.
- *
- * @param[in] numVertices Number of vertices in the mesh.
- * @param[in] numIndices Number of indices in the mesh.
- * @param[in] drawOp Determines how should the provided indices be interpreted by the pipeline. Default
- * option is triangles, where three indices represent a single triangle.
- */
- MeshBase(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
- /**
- * Constructs a new mesh with one or multiple sub-meshes. (When using just one sub-mesh it is equivalent to using
- * the other overload).
- *
- * @param[in] numVertices Number of vertices in the mesh.
- * @param[in] numIndices Number of indices in the mesh.
- * @param[in] subMeshes Defines how are indices separated into sub-meshes, and how are those sub-meshes
- * rendered.
- */
- MeshBase(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes);
- virtual ~MeshBase();
- /** Returns properties that contain information about the mesh. */
- const MeshProperties& getProperties() const { return mProperties; }
- /** Retrieves a core implementation of a mesh usable only from the core thread. */
- SPtr<MeshCoreBase> getCore() const;
- protected:
- /** @copydoc CoreObject::syncToCore */
- CoreSyncData syncToCore(FrameAlloc* allocator) override;
- MeshProperties mProperties;
- /************************************************************************/
- /* SERIALIZATION */
- /************************************************************************/
- private:
- MeshBase() { } // Serialization only
- public:
- friend class MeshBaseRTTI;
- static RTTITypeBase* getRTTIStatic();
- RTTITypeBase* getRTTI() const override;
- };
- /** @} */
- }
|