| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // Urho3D Engine
- // Copyright (c) 2008-2012 Lasse Öörni
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "ArrayPtr.h"
- #include "GraphicsDefs.h"
- #include "Object.h"
- class IndexBuffer;
- class Ray;
- class Graphics;
- class VertexBuffer;
- /// Defines one or more vertex buffers, an index buffer and a draw range.
- class Geometry : public Object
- {
- OBJECT(Geometry);
-
- public:
- /// Construct with one empty vertex buffer.
- Geometry(Context* context);
- /// Destruct.
- virtual ~Geometry();
-
- /// %Set number of vertex buffer.
- bool SetNumVertexBuffers(unsigned num);
- /// %Set a vertex buffer by index.
- bool SetVertexBuffer(unsigned index, VertexBuffer* buffer, unsigned elementMask = MASK_DEFAULT);
- /// %Set the index buffer.
- void SetIndexBuffer(IndexBuffer* buffer);
- /// %Set the draw range.
- bool SetDrawRange(PrimitiveType type, unsigned indexStart, unsigned indexCount, bool GetUsedVertexRange = true);
- /// %Set the draw range.
- bool SetDrawRange(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount);
- /// %Set the LOD distance.
- void SetLodDistance(float distance);
- /// %Set vertex and index raw data for CPU access. Vertex raw data should contain positions only.
- void SetRawData(const SharedArrayPtr<unsigned char>& vertexData, const SharedArrayPtr<unsigned char>& indexData);
- /// Draw.
- void Draw(Graphics* graphics);
-
- /// Return all vertex buffers.
- const Vector<SharedPtr<VertexBuffer> >& GetVertexBuffers() const { return vertexBuffers_; }
- /// Return vertex element masks.
- const PODVector<unsigned>& GetVertexElementMasks() const { return elementMasks_; }
- /// Return number of vertex buffers.
- unsigned GetNumVertexBuffers() const { return vertexBuffers_.Size(); }
- /// Return vertex buffer by index.
- VertexBuffer* GetVertexBuffer(unsigned index) const;
- /// Return vertex element mask by index.
- unsigned GetVertexElementMask(unsigned index) const;
- /// Return the index buffer.
- IndexBuffer* GetIndexBuffer() const { return indexBuffer_; }
- /// Return primitive type.
- PrimitiveType GetPrimitiveType() const { return primitiveType_; }
- /// Return start index.
- unsigned GetIndexStart() const { return indexStart_; }
- /// Return number of indices.
- unsigned GetIndexCount() const { return indexCount_; }
- /// Return first used vertex.
- unsigned GetVertexStart() const { return vertexStart_; }
- /// Return number of used vertices.
- unsigned GetVertexCount() const { return vertexCount_; }
- /// Return LOD distance.
- float GetLodDistance() const { return lodDistance_; }
- /// Return buffers' combined hash value for state sorting.
- unsigned short GetBufferHash() const;
- /// Return raw vertex and index data for CPU operations, or null pointers if not available.
- void GetRawData(const unsigned char*& vertexData, unsigned& vertexSize, const unsigned char*& indexData, unsigned& indexSize);
- /// Return the raw vertex data array.
- const SharedArrayPtr<unsigned char>& GetRawVertexData() const { return rawVertexData_; }
- /// Return the raw index data array.
- const SharedArrayPtr<unsigned char>& GetRawIndexData() const { return rawIndexData_; }
- /// Return ray hit distance or infinity if no hit. Requires raw data to be set.
- float GetDistance(const Ray& ray);
-
- private:
- /// Locate vertex buffer with position data.
- void GetPositionBufferIndex();
-
- /// Vertex buffers.
- Vector<SharedPtr<VertexBuffer> > vertexBuffers_;
- /// Vertex element masks.
- PODVector<unsigned> elementMasks_;
- /// Index buffer.
- SharedPtr<IndexBuffer> indexBuffer_;
- /// Primitive type.
- PrimitiveType primitiveType_;
- /// Start index.
- unsigned indexStart_;
- /// Number of indices.
- unsigned indexCount_;
- /// First used vertex.
- unsigned vertexStart_;
- /// Number of used vertices.
- unsigned vertexCount_;
- /// Index of vertex buffer with position data.
- unsigned positionBufferIndex_;
- /// LOD distance.
- float lodDistance_;
- /// Raw vertex data (positions only) for CPU operations.
- SharedArrayPtr<unsigned char> rawVertexData_;
- /// Raw index data for CPU operations.
- SharedArrayPtr<unsigned char> rawIndexData_;
- };
|