mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Code cleanup
This commit is contained in:
parent
07f7cc42ad
commit
ea2d75addc
1 changed files with 20 additions and 17 deletions
|
@ -41,8 +41,8 @@ ovrHmdDesc OculusManager::_ovrHmdDesc;
|
||||||
ovrFovPort OculusManager::_eyeFov[ovrEye_Count];
|
ovrFovPort OculusManager::_eyeFov[ovrEye_Count];
|
||||||
ovrSizei OculusManager::_renderTargetSize;
|
ovrSizei OculusManager::_renderTargetSize;
|
||||||
ovrVector2f OculusManager::_UVScaleOffset[ovrEye_Count][2];
|
ovrVector2f OculusManager::_UVScaleOffset[ovrEye_Count][2];
|
||||||
GLuint OculusManager::_vbo[ovrEye_Count] = { 0, 0 };
|
GLuint OculusManager::_vertices[ovrEye_Count] = { 0, 0 };
|
||||||
GLuint OculusManager::_indicesVbo[ovrEye_Count] = { 0, 0 };
|
GLuint OculusManager::_indices[ovrEye_Count] = { 0, 0 };
|
||||||
GLsizei OculusManager::_meshSize[ovrEye_Count] = { 0, 0 };
|
GLsizei OculusManager::_meshSize[ovrEye_Count] = { 0, 0 };
|
||||||
ovrFrameTiming OculusManager::_hmdFrameTiming;
|
ovrFrameTiming OculusManager::_hmdFrameTiming;
|
||||||
unsigned int OculusManager::_frameIndex = 0;
|
unsigned int OculusManager::_frameIndex = 0;
|
||||||
|
@ -122,13 +122,13 @@ void OculusManager::disconnect() {
|
||||||
|
|
||||||
//Free the distortion mesh data
|
//Free the distortion mesh data
|
||||||
for (int i = 0; i < ovrEye_Count; i++) {
|
for (int i = 0; i < ovrEye_Count; i++) {
|
||||||
if (_vbo[i] != 0) {
|
if (_vertices[i] != 0) {
|
||||||
glDeleteBuffers(1, &(_vbo[i]));
|
glDeleteBuffers(1, &(_vertices[i]));
|
||||||
_vbo[i] = 0;
|
_vertices[i] = 0;
|
||||||
}
|
}
|
||||||
if (_indicesVbo[i] != 0) {
|
if (_indices[i] != 0) {
|
||||||
glDeleteBuffers(1, &(_indicesVbo[i]));
|
glDeleteBuffers(1, &(_indices[i]));
|
||||||
_indicesVbo[i] = 0;
|
_indices[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,8 +136,8 @@ void OculusManager::disconnect() {
|
||||||
|
|
||||||
void OculusManager::generateDistortionMesh() {
|
void OculusManager::generateDistortionMesh() {
|
||||||
#ifdef HAVE_LIBOVR
|
#ifdef HAVE_LIBOVR
|
||||||
//Already have the distortion mesh
|
//Check if we already have the distortion mesh
|
||||||
if (_vbo[0] != 0) {
|
if (_vertices[0] != 0) {
|
||||||
printf("WARNING: Tried to generate Oculus distortion mesh twice without freeing the VBOs.");
|
printf("WARNING: Tried to generate Oculus distortion mesh twice without freeing the VBOs.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ void OculusManager::generateDistortionMesh() {
|
||||||
DistortionVertex* pVBVerts = (DistortionVertex*)OVR_ALLOC(sizeof(DistortionVertex) * meshData.VertexCount);
|
DistortionVertex* pVBVerts = (DistortionVertex*)OVR_ALLOC(sizeof(DistortionVertex) * meshData.VertexCount);
|
||||||
_meshSize[eyeNum] = meshData.IndexCount;
|
_meshSize[eyeNum] = meshData.IndexCount;
|
||||||
|
|
||||||
|
// Convert the oculus vertex data to the DistortionVertex format.
|
||||||
DistortionVertex* v = pVBVerts;
|
DistortionVertex* v = pVBVerts;
|
||||||
ovrDistortionVertex* ov = meshData.pVertexData;
|
ovrDistortionVertex* ov = meshData.pVertexData;
|
||||||
for (unsigned int vertNum = 0; vertNum < meshData.VertexCount; vertNum++) {
|
for (unsigned int vertNum = 0; vertNum < meshData.VertexCount; vertNum++) {
|
||||||
|
@ -182,18 +183,19 @@ void OculusManager::generateDistortionMesh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//vertices
|
//vertices
|
||||||
glGenBuffers(1, &(_vbo[eyeNum]));
|
glGenBuffers(1, &(_vertices[eyeNum]));
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo[eyeNum]);
|
glBindBuffer(GL_ARRAY_BUFFER, _vertices[eyeNum]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(DistortionVertex) * meshData.VertexCount, pVBVerts, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(DistortionVertex) * meshData.VertexCount, pVBVerts, GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
OVR_FREE(pVBVerts);
|
|
||||||
|
|
||||||
//indices
|
//indices
|
||||||
glGenBuffers(1, &(_indicesVbo[eyeNum]));
|
glGenBuffers(1, &(_indices[eyeNum]));
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indicesVbo[eyeNum]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices[eyeNum]);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * meshData.IndexCount, meshData.pIndexData, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * meshData.IndexCount, meshData.pIndexData, GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
//Now that we have the VBOs we can get rid of the mesh data
|
||||||
|
OVR_FREE(pVBVerts);
|
||||||
ovrHmd_DestroyDistortionMesh(&meshData);
|
ovrHmd_DestroyDistortionMesh(&meshData);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -354,7 +356,7 @@ void OculusManager::display(Camera& whichCamera) {
|
||||||
|
|
||||||
glUniformMatrix4fv(_eyeRotationEndLocation, 1, GL_FALSE, (GLfloat *)transposeMatrices[1].M);
|
glUniformMatrix4fv(_eyeRotationEndLocation, 1, GL_FALSE, (GLfloat *)transposeMatrices[1].M);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo[eyeNum]);
|
glBindBuffer(GL_ARRAY_BUFFER, _vertices[eyeNum]);
|
||||||
|
|
||||||
glVertexAttribPointer(_positionAttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(DistortionVertex), (void *)0);
|
glVertexAttribPointer(_positionAttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(DistortionVertex), (void *)0);
|
||||||
glVertexAttribPointer(_texCoord0AttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(DistortionVertex), (void *)8);
|
glVertexAttribPointer(_texCoord0AttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(DistortionVertex), (void *)8);
|
||||||
|
@ -362,7 +364,7 @@ void OculusManager::display(Camera& whichCamera) {
|
||||||
glVertexAttribPointer(_texCoord2AttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(DistortionVertex), (void *)24);
|
glVertexAttribPointer(_texCoord2AttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(DistortionVertex), (void *)24);
|
||||||
glVertexAttribPointer(_colorAttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(DistortionVertex), (void *)32);
|
glVertexAttribPointer(_colorAttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(DistortionVertex), (void *)32);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indicesVbo[eyeNum]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices[eyeNum]);
|
||||||
glDrawElements(GL_TRIANGLES, _meshSize[eyeNum], GL_UNSIGNED_SHORT, 0);
|
glDrawElements(GL_TRIANGLES, _meshSize[eyeNum], GL_UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,6 +382,7 @@ void OculusManager::display(Camera& whichCamera) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Tries to reconnect to the sensors
|
||||||
void OculusManager::reset() {
|
void OculusManager::reset() {
|
||||||
#ifdef HAVE_LIBOVR
|
#ifdef HAVE_LIBOVR
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
Loading…
Reference in a new issue