VVISF & VVGL
GLCPUToTexCopier.hpp
1 #ifndef VVGL_GLCPUToTexCopier_hpp
2 #define VVGL_GLCPUToTexCopier_hpp
3 
4 #include "VVGL_Defines.hpp"
5 #include "GLBufferPool.hpp"
6 
7 #include <mutex>
8 #include <queue>
9 
10 
11 
12 
13 // none of this stuff should be available if we're running ES
14 #if !defined(VVGL_TARGETENV_GLES) && !defined(VVGL_TARGETENV_GLES3)
15 
16 
17 
18 
19 namespace VVGL
20 {
21 
22 
23 
24 
25 using namespace std;
26 
27 
28 
29 
31 
36 class VVGL_EXPORT GLCPUToTexCopier {
37  private:
38  recursive_mutex _queueLock; // this should be used to serialize access to all member vars
39  GLContextRef _queueCtx = nullptr; // this is the context used to perform all GL action
40  int _queueSize = 2; // the number of buffers that should be in 'queue' before popping a new buffer off of it (double-buffering is 1)
41  queue<GLBufferRef> _cpuQueue; // queue of CPU-based images
42  queue<GLBufferRef> _pboQueue; // queue of PBOs
43  queue<GLBufferRef> _texQueue; // queue of textures
44  bool _swapBytes = false;
45  GLBufferPoolRef _privatePool = nullptr; // by default this is null and the scene will try to use the global buffer pool to create interim resources (temp/persistent buffers). if non-null, the scene will use this pool to create interim resources.
46 
47  private:
48  // before calling either of these functions, _queueLock should be locked and a GL context needs to be made current on this thread.
49  void _beginProcessing(const GLBufferRef & inCPUBuffer, const GLBufferRef & inPBOBuffer, const GLBufferRef & inTexBuffer);
50  void _finishProcessing(const GLBufferRef & inCPUBuffer, const GLBufferRef & inPBOBuffer, const GLBufferRef & inTexBuffer);
51 
52  public:
54  GLCPUToTexCopier(const GLContextRef & inCtx) : _queueCtx(inCtx) {};
56 
58  GLContextRef context() { return _queueCtx; }
59 
61  void clearStream();
62 
64  void setQueueSize(const int & inNewQueueSize);
66  inline int queueSize() { lock_guard<recursive_mutex> lock(_queueLock); return _queueSize; };
67 
68  void setSwapBytes(const bool & n) { lock_guard<recursive_mutex> lock(_queueLock); _swapBytes=n; }
69  bool swapBytes() { lock_guard<recursive_mutex> lock(_queueLock); return _swapBytes; }
70 
72  GLBufferRef uploadCPUToTex(const GLBufferRef & inCPUBuffer, const bool & createInCurrentContext=false);
74  GLBufferRef uploadCPUToTex(const GLBufferRef & inCPUBuffer, const GLBufferRef & inTexBuffer, const bool & createInCurrentContext=false);
75 
77 
82  GLBufferRef streamCPUToTex(const GLBufferRef & inCPUBuffer, const bool & createInCurrentContext=false);
84 
89  GLBufferRef streamCPUToTex(const GLBufferRef & inCPUBuffer, const GLBufferRef & inTexBuffer, const bool & createInCurrentContext=false);
90 
92  void setPrivatePool(const GLBufferPoolRef & n) { _privatePool=n; }
94  GLBufferPoolRef privatePool() { return _privatePool; }
95 };
96 
97 
98 
99 
104 inline GLCPUToTexCopierRef CreateGLCPUToTexCopierRef() { return make_shared<GLCPUToTexCopier>(); }
109 inline GLCPUToTexCopierRef CreateGLCPUToTexCopierRefUsing(const GLContextRef & inCtx) { return make_shared<GLCPUToTexCopier>(inCtx); }
110 
111 
112 
113 
114 }
115 
116 
117 
118 
119 #endif // !defined(VVGL_TARGETENV_GLES) && !defined(VVGL_TARGETENV_GLES3)
120 
121 
122 
123 
124 #endif /* VVGL_GLCPUToTexCopier_hpp */
Definition: GLBuffer.hpp:13
shared_ptr< GLCPUToTexCopier > GLCPUToTexCopierRef
A GLCPUToTexCopierRef is a shared pointer around a GLCPUToTexCopier.
Definition: VVGL_Base.hpp:85
GLContextRef context()
Gets the context.
Definition: GLCPUToTexCopier.hpp:58
STL namespace.
void setPrivatePool(const GLBufferPoolRef &n)
Sets the receiver&#39;s private buffer pool (which should default to null). If non-null, this buffer pool will be used to generate any GL resources required by this scene. Handy if you have a variety of GL contexts that aren&#39;t shared and you have to switch between them rapidly on a per-frame basis.
Definition: GLCPUToTexCopier.hpp:92
Uploads CPU-based GLBuffers (Type_CPU) to textures.
Definition: GLCPUToTexCopier.hpp:36
GLCPUToTexCopierRef CreateGLCPUToTexCopierRef()
Creates and returns a GLCPUToTexCopier. The scene makes a new GL context which shares the context of ...
Definition: GLCPUToTexCopier.hpp:104
GLCPUToTexCopierRef CreateGLCPUToTexCopierRefUsing(const GLContextRef &inCtx)
Creates and returns a GLCPUToTexCopier. The downloader uses the passed GL context to perform its GL o...
Definition: GLCPUToTexCopier.hpp:109
GLBufferPoolRef privatePool()
Gets the receiver&#39;s private buffer pool- null by default, only non-null if something called setPrivat...
Definition: GLCPUToTexCopier.hpp:94
int queueSize()
Returns the size of the queue used for streaming.
Definition: GLCPUToTexCopier.hpp:66