Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
omni::visual::util Namespace Reference

Functions

double now ()
 Get current time in nano seconds. More...
 
void checkOpenGLError ()
 Convenience function for handling glGetError() More...
 
QRectF viewRect (int _imageWidth, int _imageHeight, int _canvasWidth, int _canvasHeight, float _border=0.0)
 Calculate view rectangle on 2D OpenGL surface. More...
 
void resetOpenGLState ()
 Reset openGL state to its defaults. More...
 
template<typename F >
void for_each_circle_point (size_t _numVertices, float _radius, F _f)
 
template<typename F >
void for_each_arc_point (size_t _numVertices, float _radius, float _beginAngle, float _endAngle, F _f)
 
template<typename SIZE >
qreal aspect (SIZE const &_size)
 Calculates the aspect ratio from a QSize. More...
 
template<typename FRAMEBUFFER , typename PROJECTION , typename MODELVIEW >
void draw_on_framebuffer (FRAMEBUFFER *_f, PROJECTION _p, MODELVIEW _m)
 Draw into QOpenGLFramebufferObject with given projection and model. More...
 
template<typename WIDGET >
void viewport (WIDGET *_widget)
 Set viewport for widget. More...
 

Function Documentation

template<typename SIZE >
qreal omni::visual::util::aspect ( SIZE const &  _size)

Calculates the aspect ratio from a QSize.

89  {
90  return _size.width() / qreal(_size.height());
91  }
void omni::visual::util::checkOpenGLError ( )

Convenience function for handling glGetError()

39  {
40  withCurrentContext([&](QOpenGLFunctions& _) {
41  GLenum err(_.glGetError());
42 
43  while (err != GL_NO_ERROR) {
44  std::string error = "GL_";
45 
46  switch (err) {
47  case GL_INVALID_OPERATION: error += "INVALID_OPERATION"; break;
48  case GL_INVALID_ENUM: error += "INVALID_ENUM"; break;
49  case GL_INVALID_VALUE: error += "INVALID_VALUE"; break;
50  case GL_OUT_OF_MEMORY: error += "OUT_OF_MEMORY"; break;
51  case GL_INVALID_FRAMEBUFFER_OPERATION: error += "INVALID_FRAMEBUFFER_OPERATION"; break;
52  }
53 
54  OMNI_DEBUG << error.c_str();
55  err = _.glGetError();
56  }
57  });
58  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
#define OMNI_DEBUG
Definition: util.h:122
template<typename FRAMEBUFFER , typename PROJECTION , typename MODELVIEW >
void omni::visual::util::draw_on_framebuffer ( FRAMEBUFFER *  _f,
PROJECTION  _p,
MODELVIEW  _m 
)

Draw into QOpenGLFramebufferObject with given projection and model.

104  {
105  withCurrentContext([&](QOpenGLFunctions& _) {
106  _f->bind();
107  _.glViewport(0, 0, _f->width(), _f->height());
108 // _.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
109 // GL_STENCIL_BUFFER_BIT);
110 
111  glMatrixMode(GL_TEXTURE);
112  glLoadIdentity();
113 
114  // Projection matrix setup
115  glMatrixMode(GL_PROJECTION);
116  glLoadIdentity();
117  _p(_); // Projection operation
118 
119  // Model view matrix setup
120  glMatrixMode(GL_MODELVIEW);
121  glLoadIdentity();
122 
123  _m(_); // ModelView operation
124 
125  _f->release();
126  });
127  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
template<typename F >
void omni::visual::util::for_each_arc_point ( size_t  _numVertices,
float  _radius,
float  _beginAngle,
float  _endAngle,
_f 
)
68  {
69  float _cos = cos(_beginAngle), _sin = sin(_beginAngle);
70  size_t i = 0;
71 
72  _f(0, QPointF(_cos * _radius, _sin * _radius));
73 
74  for (; i < _numVertices; ++i)
75  {
76  float _m = _beginAngle + float(i) / _numVertices *
77  (_endAngle - _beginAngle);
78  _cos = cos(_m), _sin = sin(_m);
79  _f(i, QPointF(_cos * _radius, _sin * _radius));
80  }
81  _cos = cos(_endAngle), _sin = sin(_endAngle);
82  _f(i, QPointF(_cos * _radius, _sin * _radius));
83  }
template<typename F >
void omni::visual::util::for_each_circle_point ( size_t  _numVertices,
float  _radius,
_f 
)
45  {
46  for (size_t i = 0; i < _numVertices; ++i)
47  {
48  float _m = 2.0 * M_PI * float(i) / _numVertices;
49  float _cos = cos(_m), _sin = sin(_m);
50  _f(i, QPointF(_cos * _radius, _sin * _radius));
51  }
52  }
double omni::visual::util::now ( )

Get current time in nano seconds.

33  {
34  return std::chrono::high_resolution_clock::now().time_since_epoch().count()
35  /
36  1000000000.0;
37  }
double now()
Get current time in nano seconds.
Definition: util.cpp:33
void omni::visual::util::resetOpenGLState ( )

Reset openGL state to its defaults.

86  {
87  withCurrentContext([&](QOpenGLFunctions& _gl) {
88  _gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
89  _gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
90 
91  if (QOpenGLContext::currentContext()->isOpenGLES() ||
92  (_gl.openGLFeatures() & QOpenGLFunctions::FixedFunctionPipeline)) {
93  int maxAttribs;
94  _gl.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttribs);
95 
96  for (int i = 0; i < maxAttribs; ++i) {
97  _gl.glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, 0, 0);
98  _gl.glDisableVertexAttribArray(i);
99  }
100  }
101  _gl.glActiveTexture(GL_TEXTURE0);
102  _gl.glBindTexture(GL_TEXTURE_2D, 0);
103  _gl.glDisable(GL_DEPTH_TEST);
104  _gl.glDisable(GL_STENCIL_TEST);
105  _gl.glDisable(GL_SCISSOR_TEST);
106  _gl.glDisable(GL_CULL_FACE);
107  _gl.glColorMask(true, true, true, true);
108  _gl.glClearColor(0, 0, 0, 1);
109 
110  _gl.glDepthMask(true);
111  _gl.glDepthFunc(GL_LESS);
112  _gl.glClearDepthf(1);
113 
114  _gl.glStencilMask(0xff);
115  _gl.glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
116  _gl.glStencilFunc(GL_ALWAYS, 0, 0xff);
117  _gl.glUseProgram(0);
118  _gl.glEnable(GL_DEPTH_TEST);
119  _gl.glDepthFunc(GL_LEQUAL);
120  _gl.glEnable(GL_BLEND);
121  _gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
122  _gl.glEnable(GL_LINE_SMOOTH);
123  _gl.glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
124  _gl.glEnable(GL_POINT_SMOOTH);
125  _gl.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
126  _gl.glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
127  _gl.glEnable(GL_NORMALIZE);
128 
129  // fix outlines z-fighting with quads
130  _gl.glPolygonOffset(1, 1);
131  QOpenGLFramebufferObject::bindDefault();
132  });
133  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
template<typename WIDGET >
void omni::visual::util::viewport ( WIDGET *  _widget)

Set viewport for widget.

132  {
133  withCurrentContext([&_widget](QOpenGLFunctions& _)
134  {
135  int d = _widget->devicePixelRatio();
136  _.glViewport(0, 0, _widget->width() * d, _widget->height() * d);
137  });
138  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
QRectF omni::visual::util::viewRect ( int  _imageWidth,
int  _imageHeight,
int  _canvasWidth,
int  _canvasHeight,
float  _border 
)

Calculate view rectangle on 2D OpenGL surface.

64  {
65  float _projAspect = float(_imageWidth) /
66  _imageHeight;
67  float _viewAspect = float(_canvasWidth) / _canvasHeight;
68  float b = _border * 0.5;
69  float _left = -0.5 - b, _right = 0.5 + b, _bottom = -0.5 - b,
70  _top = 0.5 + b;
71 
72  if (_projAspect > _viewAspect)
73  {
74  _top *= _projAspect / _viewAspect;
75  _bottom *= _projAspect / _viewAspect;
76  }
77  else
78  {
79  _left *= _viewAspect / _projAspect;
80  _right *= _viewAspect / _projAspect;
81  }
82 
83  return QRectF(QPointF(_left, _top), QPointF(_right, _bottom));
84  }