00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #pragma once
00022
00023 #include <Inventor/SbBase.h>
00024 #include <Inventor/SbPImpl.h>
00025 #include <Inventor/misc/SoRefCounter.h>
00026 #include <Inventor/SoTypedObject.h>
00027 #include <Inventor/SoSubTypedClass.h>
00028 #include <Inventor/devices/SoDeviceContext.h>
00029 #include <Inventor/threads/SbThreadSpinlock.h>
00030 #include <Inventor/STL/limits>
00031 #include <Inventor/renderer/RendererResourceMacro.h>
00032
00033 #ifdef _WIN32
00034 #pragma warning(push)
00035 #pragma warning(disable:4251)
00036 #endif
00037
00038 class SoDeviceContext;
00039 class SoCpuBufferObject;
00040 class SoCpuBufferObjectCache;
00041
00042 SO_PIMPL_BASE_PUBLIC_DECLARATION(SoBufferObject)
00043
00044
00047 #define SO_BUFFER_SIZE_ALL ((std::numeric_limits<size_t>::max)())
00048
00191 class SoBufferObject: public SoRefCounter, public SoTypedObject
00192 {
00193 SO_TYPED_CLASS_ABSTRACT_HEADER()
00194 SO_PIMPL_BASE_PUBLIC_HEADER(SoBufferObject)
00195 RENDERER_RESOURCE(SoBufferObject);
00196
00197 public:
00198
00200 enum AccessMode
00201 {
00204 READ_ONLY,
00205
00210 SET,
00211
00216 READ_WRITE
00217 };
00218
00224 void lockBuffer();
00225
00231 void unlockBuffer();
00232
00244 virtual bool setSize( size_t size );
00245
00251 virtual size_t getSize() const;
00252
00263 virtual void* map(AccessMode accessMode, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL);
00264
00268 virtual void unmap();
00269
00292 virtual void map( SoBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
00293
00303 virtual void unmap( SoBufferObject* bufferObject );
00304
00317 virtual void memcpy( SoBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00318
00351 virtual void memset( void* value, size_t valueSize = 1, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL );
00352
00357 virtual SoBufferObject* createInstance() const = 0;
00358
00362 virtual void clearInstance() = 0;
00363
00369 SoDeviceContext* getContext() const;
00370
00374 SoBufferObject* getMappedBufferObject();
00375
00379 AccessMode getMappedBufferObjectAccessMode();
00380
00386 size_t getMappedBufferObjectPosition() const;
00387
00393 size_t getMappedBufferObjectSize() const;
00394
00403 static SoCpuBufferObjectCache* getBufferObjectCache();
00404
00405 private:
00406
00407
00408 void forceSize(size_t size);
00409
00410
00411 virtual void copyToCpuBuffer( SoCpuBufferObject* targetBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00412
00414 virtual SoBufferObject* clone() const;
00415
00416
00417 void setMappedBufferObject(SoBufferObject* bufferObject, SoBufferObject::AccessMode accessMode,
00418 size_t startPosition, size_t size);
00419
00420
00421 void clearMappedBufferObject();
00422
00427 uint64_t getModificationsCounter() const;
00428
00432 void incrementModificationsCounter() const;
00433
00434 private:
00435
00442 SoBufferObject();
00443
00448 virtual ~SoBufferObject();
00449
00454 void setDeviceContext(SoDeviceContext* context);
00455
00459 bool checkCopyConditions(size_t sourceSize, size_t sourceOffset,
00460 size_t targetSize, size_t targetOffset, size_t copySize);
00461
00466 void touch();
00467
00468 private:
00469
00474 SoBufferObject(const SoBufferObject&)
00475 : SoRefCounter(), SoTypedObject() {}
00476
00477
00478 static SoCpuBufferObjectCache* s_bufferObjectCache;
00479
00480 friend class SoCpuBufferObject;
00481 };
00482
00483
00484 #ifdef _WIN32
00485 #pragma warning(pop)
00486 #endif
00487