Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoBufferObject.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20
21#pragma once
22
23#include <Inventor/SbBase.h>
24#include <Inventor/SbPImpl.h>
25#include <Inventor/misc/SoRefCounter.h>
26#include <Inventor/SoTypedObject.h>
27#include <Inventor/SoSubTypedClass.h>
28#include <Inventor/devices/SoDeviceContext.h>
29#include <Inventor/threads/SbThreadSpinlock.h>
30#include <Inventor/STL/limits>
31#include <Inventor/renderer/RendererResourceMacro.h>
32
33#ifdef _WIN32
34#pragma warning(push)
35#pragma warning(disable:4251)
36#endif
37
38class SoDeviceContext;
40class SoCpuBufferObjectCache;
41
42SO_PIMPL_BASE_PUBLIC_DECLARATION(SoBufferObject)
43
44
49#define SO_BUFFER_SIZE_ALL ((std::numeric_limits<size_t>::max)())
50
196{
197 SO_TYPED_CLASS_ABSTRACT_HEADER()
198 SO_PIMPL_BASE_PUBLIC_HEADER(SoBufferObject)
199 RENDERER_RESOURCE(SoBufferObject);
200
201public:
202
205 {
209
215
221 };
222
229
236
248 virtual bool setSize( size_t size );
249
255 virtual size_t getSize() const;
256
267 virtual void* map(AccessMode accessMode, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL);
268
272 virtual void unmap();
273
296 virtual void map( SoBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
297
307 virtual void unmap( SoBufferObject* bufferObject );
308
321 virtual void memcpy( SoBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
322
355 virtual void memset( void* value, size_t valueSize = 1, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL );
356
361 virtual SoBufferObject* createInstance() const = 0;
362
366 virtual void clearInstance() = 0;
367
374
379
384
391
398
399private:
400
401 // should not be used elsewhere than in SoMemoryObject for compatibility purpose
402 void forceSize(size_t size);
403
404 // This function does a copy of the buffer to a CPU buffer object
405 virtual void copyToCpuBuffer( SoCpuBufferObject* targetBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
406
408 virtual SoBufferObject* clone() const;
409
410 // Set mapped buffer object info
411 void setMappedBufferObject(SoBufferObject* bufferObject, SoBufferObject::AccessMode accessMode,
412 size_t startPosition, size_t size);
413
414 // Clear mapped buffer object info
415 void clearMappedBufferObject();
416
421 uint64_t getModificationsCounter() const;
422
426 void incrementModificationsCounter() const;
427
436 static SoCpuBufferObjectCache* getBufferObjectCache();
437
438private:
439
447
452 virtual ~SoBufferObject();
453
458 void setDeviceContext(SoDeviceContext* context);
459
463 bool checkCopyConditions(size_t sourceSize, size_t sourceOffset,
464 size_t targetSize, size_t targetOffset, size_t copySize);
465
470 void touch();
471
472private:
473
480
481 // Instance of the class responsible for the cache of BufferObject.
482 static SoCpuBufferObjectCache* s_bufferObjectCache;
483
484 friend class SoCpuBufferObject;
485};
486
487
488#ifdef _WIN32
489#pragma warning(pop)
490#endif
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
AccessMode
This enum provides the possible access modes for a mapped buffer object.
@ READ_ONLY
The target buffer initially has the same contents as the source buffer.
@ SET
The target buffer contents are initially undefined (although they may be the same as the source buffe...
@ READ_WRITE
The target buffer initially has the same contents as the source buffer and the source buffer will con...
virtual void map(SoBufferObject *targetBufferObject, AccessMode accessMode, size_t startPosition=0, size_t mappingSize=SO_BUFFER_SIZE_ALL)
Maps the current buffer object into the specified buffer object.
virtual void * map(AccessMode accessMode, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL)
Map the buffer to a system memory address and allows the mapping of a sub part of the buffer object i...
virtual size_t getSize() const
Returns the size, in bytes, of the buffer object.
virtual void unmap(SoBufferObject *bufferObject)
Unmap this buffer from the specified buffer object.
virtual void memcpy(SoBufferObject *sourceBufferObject, size_t destOffset=0, size_t sourceOffset=0, size_t copySize=SO_BUFFER_SIZE_ALL)
Copies data from the specified buffer object into this buffer object.
void unlockBuffer()
Unlocks the buffer object.
virtual void memset(void *value, size_t valueSize=1, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL)
This function sets the contents of (or a portion of) this buffer object to the specified value.
AccessMode getMappedBufferObjectAccessMode()
Returns the access mode used for the buffer mapping.
size_t getMappedBufferObjectSize() const
Returns the size of the mapped area in bytes.
size_t getMappedBufferObjectPosition() const
Returns the position in the source buffer mapped in this buffer.
virtual bool setSize(size_t size)
Sets the size in bytes of the buffer object.
SoDeviceContext * getContext() const
Returns the device context where this buffer is valid.
SoBufferObject * getMappedBufferObject() const
Returns a pointer to the buffer object which is mapped by the actual object.
virtual void unmap()
Unmaps the buffer from CPU address space.
virtual SoBufferObject * createInstance() const =0
Create a new buffer with the same properties as the current one.
virtual void clearInstance()=0
Free the memory allocated by the buffer object.
#define SO_BUFFER_SIZE_ALL
Used to indicate that we want to use the whole buffer.
void lockBuffer()
Locks the buffer against concurrent calls from different threads.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPU buffer objec...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
Base class for ref-counted objects.
Base class for object storing runtime type information.