YARP
Yet Another Robot Platform
TextureBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef YARP_OVRHEADSET_TEXTUREBUFFER_H
20 #define YARP_OVRHEADSET_TEXTUREBUFFER_H
21 
22 #include <GL/glew.h>
23 #include <OVR_Math.h>
24 #include <mutex>
25 #include <yarp/sig/Image.h>
26 
27 
29 {
30 public:
31 
32  void fromImage(ovrSession inSession, const yarp::sig::Image& img, double alpha = 1.0);
33 
34  //only for single thread contexts
35  TextureBuffer();
36 
37  //multithread safe
38  TextureBuffer(int w, int h, int eye, ovrSession session);
39 
41 
42  void resize(size_t w = 0, size_t h = 0);
43  void update(const yarp::sig::Image& img);
44  void update();
45  void lock();
46  void unlock();
47 
48  ovrSession session;
49  ovrTextureSwapChain textureSwapChain;
51 
52  size_t width;
53  size_t height;
54  unsigned int components;
55  unsigned int padding;
56  size_t rowSize;
57  size_t bufferSize;
58  double alpha;
59 
60  ovrPosef eyePose;
61 
62  GLuint *pboIds;
63 
64  GLubyte* ptr;
65  bool dataReady;
66  std::mutex mutex;
67 
68  unsigned int missingFrames;
69 
70  size_t imageWidth;
71  size_t imageHeight;
72 
73 private:
74 
75  bool initialized;
76  bool singleThread;
77 
78  void createTextureAndBuffers();
79  void deleteTextureAndBuffers();
80  int eye;
81 };
82 
83 #endif // YARP_OVRHEADSET_TEXTUREBUFFER_H
TextureBuffer::missingFrames
unsigned int missingFrames
Definition: TextureBuffer.h:68
TextureBuffer::imageWidth
size_t imageWidth
Definition: TextureBuffer.h:70
TextureBuffer::textureSwapChainSize
int textureSwapChainSize
Definition: TextureBuffer.h:50
TextureBuffer::padding
unsigned int padding
Definition: TextureBuffer.h:55
TextureBuffer::~TextureBuffer
~TextureBuffer()
Definition: TextureBuffer.cpp:124
TextureBuffer::imageHeight
size_t imageHeight
Definition: TextureBuffer.h:71
TextureBuffer::textureSwapChain
ovrTextureSwapChain textureSwapChain
Definition: TextureBuffer.h:49
TextureBuffer::session
ovrSession session
Definition: TextureBuffer.h:48
TextureBuffer::alpha
double alpha
Definition: TextureBuffer.h:58
TextureBuffer::resize
void resize(size_t w=0, size_t h=0)
Definition: TextureBuffer.cpp:131
TextureBuffer::lock
void lock()
Definition: TextureBuffer.cpp:159
TextureBuffer::mutex
std::mutex mutex
Definition: TextureBuffer.h:66
TextureBuffer::bufferSize
size_t bufferSize
Definition: TextureBuffer.h:57
TextureBuffer::fromImage
void fromImage(ovrSession inSession, const yarp::sig::Image &img, double alpha=1.0)
Definition: TextureBuffer.cpp:46
TextureBuffer::dataReady
bool dataReady
Definition: TextureBuffer.h:65
TextureBuffer::pboIds
GLuint * pboIds
Definition: TextureBuffer.h:62
TextureBuffer::unlock
void unlock()
Definition: TextureBuffer.cpp:169
TextureBuffer::height
size_t height
Definition: TextureBuffer.h:53
Image.h
TextureBuffer::width
size_t width
Definition: TextureBuffer.h:52
TextureBuffer::update
void update()
Definition: TextureBuffer.cpp:179
TextureBuffer::components
unsigned int components
Definition: TextureBuffer.h:54
TextureBuffer::ptr
GLubyte * ptr
Definition: TextureBuffer.h:64
yarp::sig::Image
Base class for storing images.
Definition: Image.h:85
TextureBuffer::TextureBuffer
TextureBuffer()
Definition: TextureBuffer.cpp:82
TextureBuffer::rowSize
size_t rowSize
Definition: TextureBuffer.h:56
TextureBuffer::eyePose
ovrPosef eyePose
Definition: TextureBuffer.h:60
TextureBuffer
Definition: TextureBuffer.h:29