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
00193 class SoBufferObject: public SoRefCounter, public SoTypedObject
00194 {
00195 SO_TYPED_CLASS_ABSTRACT_HEADER()
00196 SO_PIMPL_BASE_PUBLIC_HEADER(SoBufferObject)
00197 RENDERER_RESOURCE(SoBufferObject);
00198
00199 public:
00200
00202 enum AccessMode
00203 {
00206 READ_ONLY,
00207
00212 SET,
00213
00218 READ_WRITE
00219 };
00220
00226 void lockBuffer();
00227
00233 void unlockBuffer();
00234
00246 virtual bool setSize( size_t size );
00247
00253 virtual size_t getSize() const;
00254
00265 virtual void* map(AccessMode accessMode, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL);
00266
00270 virtual void unmap();
00271
00294 virtual void map( SoBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
00295
00305 virtual void unmap( SoBufferObject* bufferObject );
00306
00319 virtual void memcpy( SoBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00320
00353 virtual void memset( void* value, size_t valueSize = 1, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL );
00354
00359 virtual SoBufferObject* createInstance() const = 0;
00360
00364 virtual void clearInstance() = 0;
00365
00371 SoDeviceContext* getContext() const;
00372
00376 SoBufferObject* getMappedBufferObject();
00377
00381 AccessMode getMappedBufferObjectAccessMode();
00382
00388 size_t getMappedBufferObjectPosition() const;
00389
00395 size_t getMappedBufferObjectSize() const;
00396
00405 static SoCpuBufferObjectCache* getBufferObjectCache();
00406
00407 private:
00408
00409
00410 void forceSize(size_t size);
00411
00412
00413 virtual void copyToCpuBuffer( SoCpuBufferObject* targetBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00414
00416 virtual SoBufferObject* clone() const;
00417
00418
00419 void setMappedBufferObject(SoBufferObject* bufferObject, SoBufferObject::AccessMode accessMode,
00420 size_t startPosition, size_t size);
00421
00422
00423 void clearMappedBufferObject();
00424
00429 uint64_t getModificationsCounter() const;
00430
00434 void incrementModificationsCounter() const;
00435
00436 private:
00437
00444 SoBufferObject();
00445
00450 virtual ~SoBufferObject();
00451
00456 void setDeviceContext(SoDeviceContext* context);
00457
00461 bool checkCopyConditions(size_t sourceSize, size_t sourceOffset,
00462 size_t targetSize, size_t targetOffset, size_t copySize);
00463
00468 void touch();
00469
00470 private:
00471
00476 SoBufferObject(const SoBufferObject&)
00477 : SoRefCounter(), SoTypedObject() {}
00478
00479
00480 static SoCpuBufferObjectCache* s_bufferObjectCache;
00481
00482 friend class SoCpuBufferObject;
00483 };
00484
00485
00486 #ifdef _WIN32
00487 #pragma warning(pop)
00488 #endif
00489