00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined SoOpenCLBUFFEROBJECT_H
00024 #define SoOpenCLBUFFEROBJECT_H
00025
00026 #include <Inventor/devices/SoBufferObject.h>
00027 #include <Inventor/devices/SoOpenCLContext.h>
00028 #include <Inventor/OpenCL/SoOpenCLDefs.h>
00029
00030 #include <Inventor/sys/SoCL.h>
00031
00032 class SoCpuBufferObject;
00033 class SoGLBufferObject;
00034
00054 class INVENTOROPENCL_API SoOpenCLBufferObject : public SoBufferObject
00055 {
00056 SO_TYPED_CLASS_HEADER();
00057
00058 public:
00059
00063 SoOpenCLBufferObject();
00064
00076 virtual bool setSize( size_t size );
00077
00092 virtual void memcpy( SoBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00093
00100 virtual void memcpy( SoCpuBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00101
00110 virtual void memcpy( SoOpenCLBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00111
00117 virtual void memcpy( SoGLBufferObject* sourceBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00118
00122 virtual void memset( void* value, size_t valueSize = 1, size_t offset = 0, size_t count = SO_BUFFER_SIZE_ALL );
00123
00137 virtual void map( SoBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
00138
00145 virtual void map( SoOpenCLBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
00146
00153 virtual void map( SoCpuBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
00154
00161 virtual void map( SoGLBufferObject* targetBufferObject, AccessMode accessMode, size_t startPosition = 0, size_t mappingSize = SO_BUFFER_SIZE_ALL );
00162
00166 virtual void unmap( SoBufferObject* bufferObject );
00167
00174 virtual void unmap( SoOpenCLBufferObject* bufferObject );
00175
00182 virtual void unmap( SoCpuBufferObject* bufferObject );
00183
00190 virtual void unmap( SoGLBufferObject* bufferObject );
00191
00199 virtual cl_mem getLocation();
00200
00206 virtual SoBufferObject* createInstance() const;
00207
00208 virtual void clearInstance();
00209
00210
00211
00212 private:
00213
00214 virtual void copyToCpuBuffer( SoCpuBufferObject* targetBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00215
00216 void copyToGLBuffer( SoGLBufferObject* targetBufferObject, size_t destOffset = 0, size_t sourceOffset = 0, size_t copySize = SO_BUFFER_SIZE_ALL );
00217
00218
00219 private:
00221 virtual ~SoOpenCLBufferObject();
00222
00223
00224 cl_context getOpenCLContext() const
00225 {
00226 SoOpenCLContext* ctx = (SoOpenCLContext *)getContext();
00227 return ctx->getOpenCLContext();
00228 }
00229
00230 cl_command_queue getDefaultCommandQueue() const
00231 {
00232 SoOpenCLContext* ctx = (SoOpenCLContext *)getContext();
00233 return ctx->getOpenCLCommandQueue();
00234 }
00235
00239 virtual void copyHostToDevice( void* sourceBuffer, size_t sourceOffset, size_t destOffset, size_t copySize );
00240
00244 virtual void copyDeviceToHost( void* targetBuffer, size_t targetOffset, size_t sourceOffset, size_t copySize );
00245
00246 private:
00247
00249 void setBuffer( cl_mem buffer, size_t size );
00250
00251 cl_mem m_buffer;
00252
00253 bool m_isOwner;
00254 };
00255
00256
00257 #endif //SoOpenCLBUFFEROBJECT_H
00258
00259
00260