SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLOculusFB Class Reference

Wrapper around Oculus Rift and its Frame Buffer Objects. More...

#include <SLGLOculusFB.h>

Public Member Functions

 SLGLOculusFB ()
 
 ~SLGLOculusFB ()
 
void bindFramebuffer (SLint scrWidth, SLint scrHeight)
 
void drawFramebuffer (SLGLProgram *stereoOculusProgram)
 
void updateSize (SLint scrWidth, SLint scrHeight)
 
SLint width ()
 
SLint halfWidth ()
 
SLint height ()
 
SLuint texID ()
 

Private Member Functions

void dispose ()
 
void generateFBO ()
 

Private Attributes

SLint _width
 
SLint _height
 Width of the buffer. More...
 
SLint _halfWidth
 Height of the buffer. More...
 
SLint _halfHeight
 Half the width of the buffer. More...
 
SLuint _fbID
 Half the height of the buffer. More...
 
SLuint _depthRbID
 OpenGL id of frame buffer. More...
 
SLuint _texID
 OpenGL id of depth render buffer. More...
 
SLGLVertexArray _vao
 OpenGL id of. More...
 

Detailed Description

Wrapper around Oculus Rift and its Frame Buffer Objects.

This class is deprecated since the lib_ovr from Oculus completely changed The lib_ovr that connects the Oculus hardware was removed since it only worked for devkit2 under windows.

Definition at line 24 of file SLGLOculusFB.h.

Constructor & Destructor Documentation

◆ SLGLOculusFB()

SLGLOculusFB::SLGLOculusFB ( )

Constructor initializing with default values

Definition at line 19 of file SLGLOculusFB.cpp.

20  : _width(0),
21  _height(0),
22  _halfWidth(0),
23  _halfHeight(0),
24  _fbID(0),
25  _depthRbID(0),
26  _texID(0)
27 {
28 }
SLint _halfHeight
Half the width of the buffer.
Definition: SLGLOculusFB.h:49
SLuint _fbID
Half the height of the buffer.
Definition: SLGLOculusFB.h:50
SLint _height
Width of the buffer.
Definition: SLGLOculusFB.h:47
SLuint _depthRbID
OpenGL id of frame buffer.
Definition: SLGLOculusFB.h:51
SLint _halfWidth
Height of the buffer.
Definition: SLGLOculusFB.h:48
SLuint _texID
OpenGL id of depth render buffer.
Definition: SLGLOculusFB.h:52

◆ ~SLGLOculusFB()

SLGLOculusFB::~SLGLOculusFB ( )

Destructor calling dispose

Definition at line 32 of file SLGLOculusFB.cpp.

33 {
34  dispose();
35 }

Member Function Documentation

◆ bindFramebuffer()

void SLGLOculusFB::bindFramebuffer ( SLint  scrWidth,
SLint  scrHeight 
)

Activates the frame buffer. On the first time it calls the updateSize to determine the size and then creates the FBO.

Definition at line 49 of file SLGLOculusFB.cpp.

51 {
52  if (!_fbID)
54  if (_fbID)
55  glBindFramebuffer(GL_FRAMEBUFFER, _fbID);
56 }
static SLint scrHeight
Window height at start up.
Definition: AppGLFW.cpp:38
static SLint scrWidth
Window width at start up.
Definition: AppGLFW.cpp:37
void updateSize(SLint scrWidth, SLint scrHeight)

◆ dispose()

void SLGLOculusFB::dispose ( )
private

Deletes the buffer object

Definition at line 39 of file SLGLOculusFB.cpp.

40 {
41  if (_fbID) glDeleteFramebuffers(1, &_fbID);
42  if (_texID) glDeleteTextures(1, &_texID);
43  if (_depthRbID) glDeleteRenderbuffers(1, &_depthRbID);
44 }

◆ drawFramebuffer()

void SLGLOculusFB::drawFramebuffer ( SLGLProgram stereoOculusProgram)

Draws the intermediate render target (the texture) into the real framebuffer.

Definition at line 178 of file SLGLOculusFB.cpp.

179 {
180  glViewport(0, 0, _width, _height);
181  glBindFramebuffer(GL_FRAMEBUFFER, 0);
182  glClear(GL_COLOR_BUFFER_BIT);
183  glDisable(GL_DEPTH_TEST);
184 
185  // bind the rift shader
186  SLGLProgram* sp = stereoOculusProgram;
187  sp->useProgram();
188  SLint location = AT_position;
189 
190  // Create VBO for screen quad once
191  if (!_vao.vaoID())
192  {
193  SLfloat P[] = {-1, -1, 1, -1, -1, 1, 1, 1};
194  _vao.setAttrib(AT_position, 2, location, P);
195  _vao.generate(4);
196  }
197 
198  glActiveTexture(GL_TEXTURE0);
199  glBindTexture(GL_TEXTURE_2D, _texID);
200 
202 
203  glEnable(GL_DEPTH_TEST);
204 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
@ AT_position
Vertex position as a 2, 3 or 4 component vectors.
Definition: SLGLEnums.h:58
@ PT_triangleStrip
Definition: SLGLEnums.h:36
SLGLVertexArray _vao
OpenGL id of.
Definition: SLGLOculusFB.h:53
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
void useProgram()
void setAttrib(SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
Adds a vertex attribute with data pointer and an element size.
void drawArrayAs(SLGLPrimitiveType primitiveType, SLint firstVertex=0, SLsizei countVertices=0)
Draws the VAO as an array with a primitive type.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB objects for a NO. of vertices.

◆ generateFBO()

void SLGLOculusFB::generateFBO ( )
private

Frame Buffer generation. This is called from within updateSize because the frame buffer size has to be calculated first

Definition at line 61 of file SLGLOculusFB.cpp.

62 {
63  // generate the intermediate screen texture
64  glGenTextures(1, &_texID);
65  glBindTexture(GL_TEXTURE_2D, _texID);
66  glTexParameteri(GL_TEXTURE_2D,
67  GL_TEXTURE_MAG_FILTER,
68  GL_LINEAR);
69  glTexParameteri(GL_TEXTURE_2D,
70  GL_TEXTURE_MIN_FILTER,
71  GL_LINEAR);
72  glTexParameteri(GL_TEXTURE_2D,
73  GL_TEXTURE_WRAP_S,
74  GL_CLAMP_TO_EDGE);
75  glTexParameteri(GL_TEXTURE_2D,
76  GL_TEXTURE_WRAP_T,
77  GL_CLAMP_TO_EDGE);
78  glTexImage2D(GL_TEXTURE_2D,
79  0,
80  PF_rgba,
81  _width,
82  _height,
83  0,
84  PF_rgba,
85  GL_UNSIGNED_BYTE,
86  nullptr);
87  glBindTexture(GL_TEXTURE_2D, 0);
88 
89  // generate the renderbuffer for the depth component
90  glGenRenderbuffers(1, &_depthRbID);
91  glBindRenderbuffer(GL_RENDERBUFFER, _depthRbID);
92 #if defined(SL_OS_MACIOS) || defined(SL_OS_ANDROID) || defined(SL_EMSCRIPTEN)
93  glRenderbufferStorage(GL_RENDERBUFFER,
94  GL_DEPTH_COMPONENT16,
95  _width,
96  _height);
97 #else
98  glRenderbufferStorage(GL_RENDERBUFFER,
99  GL_DEPTH_COMPONENT32,
100  _width,
101  _height);
102 #endif
103  glBindRenderbuffer(GL_RENDERBUFFER, 0);
104 
105  // finally generate the frame buffer and bind the targets
106  glGenFramebuffers(1, &_fbID);
107  glBindFramebuffer(GL_FRAMEBUFFER,
108  _fbID);
109  glFramebufferTexture2D(GL_FRAMEBUFFER,
110  GL_COLOR_ATTACHMENT0,
111  GL_TEXTURE_2D,
112  _texID,
113  0);
114  glFramebufferRenderbuffer(GL_FRAMEBUFFER,
115  GL_DEPTH_ATTACHMENT,
116  GL_RENDERBUFFER,
117  _depthRbID);
118 
119  // test if the generated fbo is valid
120  if ((glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
121  SL_EXIT_MSG("Frame buffer creation failed!");
122 
123  glBindFramebuffer(GL_FRAMEBUFFER, 0);
124  GET_GL_ERROR;
125 }
@ PF_rgba
Definition: CVImage.h:37
#define SL_EXIT_MSG(message)
Definition: SL.h:240
#define GET_GL_ERROR
Definition: SLGLState.h:56

◆ halfWidth()

SLint SLGLOculusFB::halfWidth ( )
inline

Definition at line 38 of file SLGLOculusFB.h.

38 { return _halfWidth; }

◆ height()

SLint SLGLOculusFB::height ( )
inline

Definition at line 39 of file SLGLOculusFB.h.

39 { return _height; }

◆ texID()

SLuint SLGLOculusFB::texID ( )
inline

Definition at line 40 of file SLGLOculusFB.h.

40 { return _texID; }

◆ updateSize()

void SLGLOculusFB::updateSize ( SLint  scrWidth,
SLint  scrHeight 
)

Updates everything when the screen gets resized:

  • Recalculates the stereo parameters
  • Creates or updates the FBO
  • Updates the shader uniforms

Definition at line 132 of file SLGLOculusFB.cpp.

134 {
135  _width = scrWidth;
136  _height = scrHeight;
137  _halfWidth = scrWidth >> 1;
138  _halfHeight = scrHeight >> 1;
139 
140  // Create FBO or resize it
141  if (!_fbID)
142  generateFBO();
143  else
144  { // Resize the intermediate render targets
145  glBindTexture(GL_TEXTURE_2D, _texID);
146  glTexImage2D(GL_TEXTURE_2D,
147  0,
148  PF_rgba,
149  _width,
150  _height,
151  0,
152  PF_rgba,
153  GL_UNSIGNED_BYTE,
154  nullptr);
155  glBindTexture(GL_TEXTURE_2D, 0);
156 
157  // Resize the depth render buffer
158  glBindRenderbuffer(GL_RENDERBUFFER, _depthRbID);
159 
160 #if defined(SL_OS_MACIOS) || defined(SL_OS_ANDROID) || defined(SL_EMSCRIPTEN)
161  glRenderbufferStorage(GL_RENDERBUFFER,
162  GL_DEPTH_COMPONENT16,
163  _width,
164  _height);
165 #else
166  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, _width, _height);
167 #endif
168 
169  glBindRenderbuffer(GL_RENDERBUFFER, 0);
170  }
171 
172  GET_GL_ERROR;
173 }
void generateFBO()

◆ width()

SLint SLGLOculusFB::width ( )
inline

Definition at line 37 of file SLGLOculusFB.h.

37 { return _width; }

Member Data Documentation

◆ _depthRbID

SLuint SLGLOculusFB::_depthRbID
private

OpenGL id of frame buffer.

Definition at line 51 of file SLGLOculusFB.h.

◆ _fbID

SLuint SLGLOculusFB::_fbID
private

Half the height of the buffer.

Definition at line 50 of file SLGLOculusFB.h.

◆ _halfHeight

SLint SLGLOculusFB::_halfHeight
private

Half the width of the buffer.

Definition at line 49 of file SLGLOculusFB.h.

◆ _halfWidth

SLint SLGLOculusFB::_halfWidth
private

Height of the buffer.

Definition at line 48 of file SLGLOculusFB.h.

◆ _height

SLint SLGLOculusFB::_height
private

Width of the buffer.

Definition at line 47 of file SLGLOculusFB.h.

◆ _texID

SLuint SLGLOculusFB::_texID
private

OpenGL id of depth render buffer.

Definition at line 52 of file SLGLOculusFB.h.

◆ _vao

SLGLVertexArray SLGLOculusFB::_vao
private

OpenGL id of.

Definition at line 53 of file SLGLOculusFB.h.

◆ _width

SLint SLGLOculusFB::_width
private

Definition at line 46 of file SLGLOculusFB.h.


The documentation for this class was generated from the following files: