Nebula
Loading...
Searching...
No Matches
nvx3streamreader.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "core/config.h"
15#include "io/streamreader.h"
16#include "coregraphics/vertexbuffer.h"
17#include "coregraphics/indexbuffer.h"
19#include "coregraphics/base/vertexbufferbase.h"
20#include "coregraphics/base/memoryvertexbufferloaderbase.h"
21#include "coregraphics/base/indexbufferbase.h"
22#include "coregraphics/base/memoryindexbufferloaderbase.h"
23
24//------------------------------------------------------------------------------
25namespace CoreGraphics
26{
28{
30public:
34 virtual ~Nvx3StreamReader();
35
37 void SetRawMode(bool b);
39 bool IsRawMode() const;
41 void SetUsage(Base::ResourceBase::Usage usage);
43 Base::ResourceBase::Usage GetUsage() const;
45 void SetAccess(Base::ResourceBase::Access access);
47 Base::ResourceBase::Access GetAccess() const;
49 virtual bool Open();
51 virtual void Close();
59 float* GetVertexData() const;
61 ushort* GetIndexData() const;
63 SizeT GetNumVertices() const;
65 SizeT GetNumIndices() const;
67 SizeT GetVertexWidth() const;
70
75
78
79private:
81 void ReadHeaderData();
89 void SetupVertexBuffer();
91 void SetupIndexBuffer();
92
95 {
96 N3Coord = (1<<0), // 3 floats
97 N3Normal = (1<<1), // 3 floats
98 N3NormalUB4N = (1<<2), // 4 unsigned bytes, normalized
99 N3Uv0 = (1<<3), // 2 floats
100 N3Uv0S2 = (1<<4), // 2 shorts, 4.12 fixed point
101 N3Uv1 = (1<<5), // 2 floats
102 N3Uv1S2 = (1<<6), // 2 shorts, 4.12 fixed point
103 N3Uv2 = (1<<7), // 2 floats
104 N3Uv2S2 = (1<<8), // 2 shorts, 4.12 fixed point
105 N3Uv3 = (1<<9), // 2 floats
106 N3Uv3S2 = (1<<10), // 2 shorts, 4.12 fixed point
107 N3Color = (1<<11), // 4 floats
108 N3ColorUB4N = (1<<12), // 4 unsigned bytes, normalized
109 N3Tangent = (1<<13), // 3 floats
110 N3TangentUB4N = (1<<14), // 4 unsigned bytes, normalized
111 N3Binormal = (1<<15), // 3 floats
112 N3BinormalUB4N = (1<<16), // 4 unsigned bytes, normalized
113 N3Weights = (1<<17), // 4 floats
114 N3WeightsUB4N = (1<<18), // 4 unsigned bytes, normalized
115 N3JIndices = (1<<19), // 4 floats
116 N3JIndicesUB4 = (1<<20), // 4 unsigned bytes
117
120 };
121
122 Base::ResourceBase::Usage usage;
123 Base::ResourceBase::Access access;
124
130
132 void* mapPtr;
136
140
147};
148
149//------------------------------------------------------------------------------
152inline void
157
158//------------------------------------------------------------------------------
161inline void
166
167//------------------------------------------------------------------------------
170inline void
172{
173 this->rawMode = b;
174}
175
176//------------------------------------------------------------------------------
179inline bool
181{
182 return this->rawMode;
183}
184
185//------------------------------------------------------------------------------
188inline const Ptr<Base::VertexBufferBase>&
190{
191 n_assert(!this->rawMode && this->vertexBuffer.isvalid());
192 return this->vertexBuffer;
193}
194
195//------------------------------------------------------------------------------
198inline const Ptr<Base::IndexBufferBase>&
200{
201 n_assert(!this->rawMode && this->indexBuffer.isvalid());
202 return this->indexBuffer;
203}
204
205//------------------------------------------------------------------------------
210{
211 return this->primGroups;
212}
213
214//------------------------------------------------------------------------------
217inline float*
219{
220 return (float*) this->vertexDataPtr;
221}
222
223//------------------------------------------------------------------------------
226inline ushort*
228{
229 return (ushort*) this->indexDataPtr;
230}
231
232//------------------------------------------------------------------------------
235inline SizeT
237{
238 return this->numVertices;
239}
240
241//------------------------------------------------------------------------------
244inline SizeT
246{
247 return this->numIndices;
248}
249
250//------------------------------------------------------------------------------
253inline SizeT
255{
256 return this->vertexWidth;
257}
258
259//------------------------------------------------------------------------------
264{
265 return this->vertexComponents;
266}
267
268//------------------------------------------------------------------------------
271inline void
272Nvx3StreamReader::SetUsage(Base::ResourceBase::Usage usage_)
273{
274 this->usage = usage_;
275}
276
277//------------------------------------------------------------------------------
280inline Base::ResourceBase::Usage
282{
283 return this->usage;
284}
285
286//------------------------------------------------------------------------------
289inline void
290Nvx3StreamReader::SetAccess(Base::ResourceBase::Access access_)
291{
292 this->access = access_;
293}
294
295//------------------------------------------------------------------------------
298inline Base::ResourceBase::Access
300{
301 return this->access;
302}
303
304} // namespace CoreGraphics
305//------------------------------------------------------------------------------
Definition nvx3streamreader.h:28
bool rawMode
Definition nvx3streamreader.h:125
virtual void Close()
end reading from the stream, destroys loaded objects
Definition nvx3streamreader.cc:90
SizeT vertexDataSize
Definition nvx3streamreader.h:138
void * vertexDataPtr
Definition nvx3streamreader.h:134
__DeclareClass(Nvx3StreamReader)
void SetupIndexBuffer()
setup the index buffer object (not called in raw mode)
Definition nvx3streamreader.cc:290
void SetVertexBufferLoader(const Ptr< Base::MemoryVertexBufferLoaderBase > &vBufLoader)
set the specialized vertex buffer reader
Definition nvx3streamreader.h:162
void SetupVertexBuffer()
setup the vertex buffer object (not called in raw mode)
Definition nvx3streamreader.cc:260
Ptr< Base::VertexBufferBase > vertexBuffer
Definition nvx3streamreader.h:126
uint vertexComponentMask
Definition nvx3streamreader.h:145
uint numIndices
Definition nvx3streamreader.h:144
static void ConvertVertexBufferEndianess(void *vertexPtr, SizeT numVertices, const Util::Array< CoreGraphics::VertexComponent > &vertexComps)
helper method to convert vertex buffer endianess
SizeT groupDataSize
Definition nvx3streamreader.h:137
Util::Array< CoreGraphics::PrimitiveGroup > primGroups
Definition nvx3streamreader.h:131
Base::ResourceBase::Usage usage
Definition nvx3streamreader.h:122
N3VertexComponent
Nebula vertex components, see Nebula's class for details.
Definition nvx3streamreader.h:95
@ N3Coord
Definition nvx3streamreader.h:96
@ N3Normal
Definition nvx3streamreader.h:97
@ N3Weights
Definition nvx3streamreader.h:113
@ N3TangentUB4N
Definition nvx3streamreader.h:110
@ N3Uv2S2
Definition nvx3streamreader.h:104
@ N3JIndices
Definition nvx3streamreader.h:115
@ N3Uv2
Definition nvx3streamreader.h:103
@ N3Uv3
Definition nvx3streamreader.h:105
@ N3Uv1S2
Definition nvx3streamreader.h:102
@ N3ColorUB4N
Definition nvx3streamreader.h:108
@ N3NormalUB4N
Definition nvx3streamreader.h:98
@ N3Uv3S2
Definition nvx3streamreader.h:106
@ N3NumVertexComponents
Definition nvx3streamreader.h:118
@ N3AllComponents
Definition nvx3streamreader.h:119
@ N3Uv1
Definition nvx3streamreader.h:101
@ N3WeightsUB4N
Definition nvx3streamreader.h:114
@ N3Tangent
Definition nvx3streamreader.h:109
@ N3Uv0S2
Definition nvx3streamreader.h:100
@ N3Color
Definition nvx3streamreader.h:107
@ N3Binormal
Definition nvx3streamreader.h:111
@ N3JIndicesUB4
Definition nvx3streamreader.h:116
@ N3Uv0
Definition nvx3streamreader.h:99
@ N3BinormalUB4N
Definition nvx3streamreader.h:112
void * indexDataPtr
Definition nvx3streamreader.h:135
void SetUsage(Base::ResourceBase::Usage usage)
set the intended resource usage (default is UsageImmutable)
Definition nvx3streamreader.h:272
Base::ResourceBase::Usage GetUsage() const
get resource usage
Definition nvx3streamreader.h:281
Ptr< Base::MemoryIndexBufferLoaderBase > indexBufferLoader
Definition nvx3streamreader.h:129
Base::ResourceBase::Access access
Definition nvx3streamreader.h:123
void SetAccess(Base::ResourceBase::Access access)
set the intended resource access (default is AccessNone)
Definition nvx3streamreader.h:290
void SetVertexBuffer(const Ptr< Base::VertexBufferBase > &vBuf)
set the specialized vertex buffer
Definition nvx3streamreader.h:153
const Ptr< Base::IndexBufferBase > & GetIndexBuffer() const
get index buffer (not valid in raw mode)
Definition nvx3streamreader.h:199
void ReadPrimitiveGroups()
read primitive groups from stream
Definition nvx3streamreader.cc:149
float * GetVertexData() const
get pointer to raw vertex data
Definition nvx3streamreader.h:218
virtual ~Nvx3StreamReader()
destructor
Definition nvx3streamreader.cc:47
SizeT indexDataSize
Definition nvx3streamreader.h:139
Util::Array< CoreGraphics::VertexComponent > vertexComponents
Definition nvx3streamreader.h:146
Nvx3StreamReader()
contructor
Definition nvx3streamreader.cc:24
uint numVertices
Definition nvx3streamreader.h:142
uint numGroups
Definition nvx3streamreader.h:141
uint vertexWidth
Definition nvx3streamreader.h:143
void * groupDataPtr
Definition nvx3streamreader.h:133
const Util::Array< CoreGraphics::PrimitiveGroup > & GetPrimitiveGroups() const
get primitive groups
Definition nvx3streamreader.h:209
SizeT GetVertexWidth() const
get vertex width
Definition nvx3streamreader.h:254
void UpdateGroupBoundingBoxes()
update primitive group bounding boxes
Definition nvx3streamreader.cc:230
void ReadHeaderData()
read header data from stream
Definition nvx3streamreader.cc:116
ushort * GetIndexData() const
get pointer to raw index data
Definition nvx3streamreader.h:227
Ptr< Base::MemoryVertexBufferLoaderBase > vertexBufferLoader
Definition nvx3streamreader.h:128
SizeT GetNumVertices() const
get number of vertices
Definition nvx3streamreader.h:236
const Ptr< Base::VertexBufferBase > & GetVertexBuffer() const
get vertex buffer (not valid in raw mode)
Definition nvx3streamreader.h:189
virtual bool Open()
begin reading from the stream, read entire data
Definition nvx3streamreader.cc:59
Ptr< Base::IndexBufferBase > indexBuffer
Definition nvx3streamreader.h:127
bool IsRawMode() const
get raw mode flag
Definition nvx3streamreader.h:180
void * mapPtr
Definition nvx3streamreader.h:132
void SetRawMode(bool b)
enable/disable raw mode (raw mode does not setup vertex/index buffers), default is false
Definition nvx3streamreader.h:171
Base::ResourceBase::Access GetAccess() const
get the resource access
Definition nvx3streamreader.h:299
SizeT GetNumIndices() const
get number of indices
Definition nvx3streamreader.h:245
void SetupVertexComponents()
setup vertex components array
Definition nvx3streamreader.cc:176
const Util::Array< CoreGraphics::VertexComponent > & GetVertexComponents() const
get vertex components
Definition nvx3streamreader.h:263
Stream reader classes provide a specialized read-interface for a stream.
Definition streamreader.h:24
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
bool isvalid() const
check if pointer is valid
Definition ptr.h:435
Nebula's dynamic array class.
Definition array.h:60
#define n_assert(exp)
Definition debug.h:50
Nebula compiler specific defines and configuration.
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
unsigned short ushort
Definition types.h:32