Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
CDynamicMeshBuffer.hpp
1// Copyright (C) 2008-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_C_DYNAMIC_MESHBUFFER_HPP_INCLUDED
6#define NIRT_C_DYNAMIC_MESHBUFFER_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/IDynamicMeshBuffer.hpp>
9
10#include <nirtcpp/core/engine/CVertexBuffer.hpp>
11#include <nirtcpp/core/engine/CIndexBuffer.hpp>
12
13namespace nirt
14{
15namespace scene
16{
19 {
20 public:
22 CDynamicMeshBuffer(video::E_VERTEX_TYPE vertexType, video::E_INDEX_TYPE indexType)
24 {
25 VertexBuffer=new CVertexBuffer(vertexType);
26 IndexBuffer=new CIndexBuffer(indexType);
27 }
28
31 {
32 if (VertexBuffer)
33 VertexBuffer->drop();
34 if (IndexBuffer)
35 IndexBuffer->drop();
36 }
37
38 virtual IVertexBuffer& getVertexBuffer() const override
39 {
40 return *VertexBuffer;
41 }
42
43 virtual IIndexBuffer& getIndexBuffer() const override
44 {
45 return *IndexBuffer;
46 }
47
48 virtual void setVertexBuffer(IVertexBuffer *newVertexBuffer) override
49 {
50 if (newVertexBuffer)
51 newVertexBuffer->grab();
52 if (VertexBuffer)
53 VertexBuffer->drop();
54
55 VertexBuffer=newVertexBuffer;
56 }
57
58 virtual void setIndexBuffer(IIndexBuffer *newIndexBuffer) override
59 {
60 if (newIndexBuffer)
61 newIndexBuffer->grab();
62 if (IndexBuffer)
63 IndexBuffer->drop();
64
65 IndexBuffer=newIndexBuffer;
66 }
67
69 virtual const video::SMaterial& getMaterial() const override
70 {
71 return Material;
72 }
73
75 virtual video::SMaterial& getMaterial() override
76 {
77 return Material;
78 }
79
81 virtual const core::aabbox3d<f32>& getBoundingBox() const override
82 {
83 return BoundingBox;
84 }
85
87 virtual void setBoundingBox( const core::aabbox3df& box) override
88 {
89 BoundingBox = box;
90 }
91
93 virtual void recalculateBoundingBox() override
94 {
95 if (!getVertexBuffer().size())
96 BoundingBox.reset(0,0,0);
97 else
98 {
99 BoundingBox.reset(getVertexBuffer()[0].Pos);
100 for (u32 i=1; i<getVertexBuffer().size(); ++i)
101 BoundingBox.addInternalPoint(getVertexBuffer()[i].Pos);
102 }
103 }
104
106
111 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override
112 {
113 // TODO
114 }
115
117
119 virtual void append(const IMeshBuffer* const other) override
120 {
121 // TODO
122 }
123
124
126 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
127 {
128 PrimitiveType = type;
129 }
130
132 virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
133 {
134 return PrimitiveType;
135 }
136
138 virtual EMESH_BUFFER_TYPE getType() const override
139 {
140 return EMBT_DYNAMIC;
141 }
142
144 virtual IMeshBuffer* createClone(int cloneFlags) const override
145 {
146 CDynamicMeshBuffer* clone = new CDynamicMeshBuffer(VertexBuffer->getType(), IndexBuffer->getType());
147
148 if (cloneFlags & ECF_VERTICES)
149 {
150 const u32 numVertices = VertexBuffer->size();
151 clone->VertexBuffer->reallocate(numVertices);
152 for ( u32 i=0; i<numVertices; ++i )
153 {
154 clone->VertexBuffer->push_back((*VertexBuffer)[i]);
155 }
156 clone->BoundingBox = BoundingBox;
157 }
158
159 if (cloneFlags & ECF_INDICES)
160 {
161 const u32 numIndices = IndexBuffer->size();
162 clone->IndexBuffer->reallocate(numIndices);
163 for ( u32 i=0; i<numIndices; ++i )
164 {
165 clone->IndexBuffer->push_back((*IndexBuffer)[i]);
166 }
167 }
168
169 clone->VertexBuffer->setHardwareMappingHint(VertexBuffer->getHardwareMappingHint());
170 clone->IndexBuffer->setHardwareMappingHint(clone->IndexBuffer->getHardwareMappingHint());
171 clone->Material = Material;
173
174 return clone;
175 }
176
177 video::SMaterial Material;
178 core::aabbox3d<f32> BoundingBox;
181 private:
182 CDynamicMeshBuffer(const CDynamicMeshBuffer&); // = delete in c++11, prevent copying
183
184 IVertexBuffer *VertexBuffer;
185 IIndexBuffer *IndexBuffer;
186 };
187
188
189} // end namespace scene
190} // end namespace nirt
191
192#endif
bool drop() const
Drops the object. Decrements the reference counter by one.
Definition IReferenceCounted.hpp:126
void grab() const
Grabs the object. Increments the reference counter by one.
Definition IReferenceCounted.hpp:96
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.hpp:74
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
Implementation of the IMeshBuffer interface for which can work with 16 and 32 bit indices as well as ...
Definition CDynamicMeshBuffer.hpp:19
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
Describe what kind of primitive geometry is used by the meshbuffer.
Definition CDynamicMeshBuffer.hpp:126
virtual void append(const IMeshBuffer *const other) override
Append the meshbuffer to the current buffer.
Definition CDynamicMeshBuffer.hpp:119
virtual video::SMaterial & getMaterial() override
Get Material of this buffer.
Definition CDynamicMeshBuffer.hpp:75
virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
Get the kind of primitive geometry which is used by the meshbuffer.
Definition CDynamicMeshBuffer.hpp:132
virtual EMESH_BUFFER_TYPE getType() const override
Returns type of the class implementing the IMeshBuffer.
Definition CDynamicMeshBuffer.hpp:138
virtual const video::SMaterial & getMaterial() const override
Get Material of this buffer.
Definition CDynamicMeshBuffer.hpp:69
CDynamicMeshBuffer(video::E_VERTEX_TYPE vertexType, video::E_INDEX_TYPE indexType)
constructor
Definition CDynamicMeshBuffer.hpp:22
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override
Append the vertices and indices to the current buffer.
Definition CDynamicMeshBuffer.hpp:111
virtual void recalculateBoundingBox() override
Recalculate bounding box.
Definition CDynamicMeshBuffer.hpp:93
virtual const core::aabbox3d< f32 > & getBoundingBox() const override
Get bounding box.
Definition CDynamicMeshBuffer.hpp:81
virtual void setBoundingBox(const core::aabbox3df &box) override
Set bounding box.
Definition CDynamicMeshBuffer.hpp:87
E_PRIMITIVE_TYPE PrimitiveType
Primitive type used for rendering (triangles, lines, ...)
Definition CDynamicMeshBuffer.hpp:180
virtual IMeshBuffer * createClone(int cloneFlags) const override
Create copy of the meshbuffer.
Definition CDynamicMeshBuffer.hpp:144
virtual ~CDynamicMeshBuffer()
destructor
Definition CDynamicMeshBuffer.hpp:30
Definition CIndexBuffer.hpp:16
Definition CVertexBuffer.hpp:17
Definition IDynamicMeshBuffer.hpp:19
Definition IIndexBuffer.hpp:20
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const =0
get the current hardware mapping hint
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint)=0
set the hardware mapping hint, for driver
virtual u32 size() const =0
Number of elements.
virtual void push_back(u32 value)=0
Add value to end. Note that for 16 bit index types values shouldn't be larger than u16.
Class for holding a mesh with a single material.
Definition IMeshBuffer.hpp:41
@ ECF_INDICES
clone the vertices (or copy pointer for SSharedMeshBuffer)
Definition IMeshBuffer.hpp:205
Definition IVertexBuffer.hpp:19
virtual void push_back(const video::S3DVertex &element)=0
Add vertex to end.
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const =0
get the current hardware mapping hint
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint)=0
set the hardware mapping hint, for driver
virtual u32 size() const =0
Number of elements.
Class for holding parameters for a material renderer.
Definition SMaterial.hpp:304
E_PRIMITIVE_TYPE
Enumeration for all primitive types there are.
Definition EPrimitiveTypes.hpp:15
@ EPT_TRIANGLES
Explicitly set all vertices for each triangle.
Definition EPrimitiveTypes.hpp:37
EMESH_BUFFER_TYPE
An enumeration for all types of built-in mesh buffers.
Definition EMeshBufferTypes.hpp:18
@ EMBT_DYNAMIC
CDynamicMeshBuffer (16 or 32 bit buffers)
Definition EMeshBufferTypes.hpp:29
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.hpp:19
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print