Skip to content
Permalink
Browse files

Merge commit 'refs/pull/336/head' of https://github.com/coelckers/gzdoom

  • Loading branch information...
madame-rachelle committed May 28, 2017
2 parents 0fb1a06 + a149b54 commit a05c38fefd43c879926c0114f21f7aa4b906a4f1
@@ -50,3 +50,4 @@
/llvm
/src/r_drawersasm.obj
/src/r_drawersasm.o
/build_cmake
@@ -300,6 +300,8 @@ endif()

set( LZMA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lzma/C" )

option( GZDOOM_USE_OPENVR "Support OpenVR API for virtual reality head mounted displays" OFF )

if( NOT CMAKE_CROSSCOMPILING )
if( NOT CROSS_EXPORTS )
set( CROSS_EXPORTS "" )
@@ -473,6 +473,29 @@ if( NOT DYN_FLUIDSYNTH )
endif()
endif()

if (GZDOOM_USE_OPENVR)
find_path(OPENVR_SDK_PATH
NAMES
headers/openvr.h
PATHS
C:/Users/cmbruns/git/openvr
)
find_path(OPENVR_INCLUDE_DIRECTORY
NAMES
openvr.h
PATHS
${OPENVR_SDK_PATH}/headers
)
include_directories("${OPENVR_INCLUDE_DIRECTORY}")
find_library(OPENVR_LIBRARY
NAMES openvr_api
# TODO: Generalize for Mac and Linux and 64-bit Windows
PATHS "${OPENVR_SDK_PATH}/lib/win32/"
)
list(APPEND ZDOOM_LIBS ${OPENVR_LIBRARY})
add_definitions("-DUSE_OPENVR")
endif()

# Start defining source files for ZDoom
set( PLAT_WIN32_SOURCES
sound/mididevices/music_win_mididevice.cpp
@@ -805,6 +828,7 @@ set( FASTMATH_SOURCES
gl/scene/gl_vertex.cpp
gl/scene/gl_spritelight.cpp
gl/dynlights/gl_dynlight1.cpp
gl/dynlights/gl_dynlight1.cpp
gl/system/gl_load.c
gl/models/gl_models.cpp
)
@@ -1006,6 +1030,7 @@ set (PCH_SOURCES
gl/stereo3d/gl_stereo_leftright.cpp
gl/stereo3d/scoped_view_shifter.cpp
gl/stereo3d/gl_anaglyph.cpp
gl/stereo3d/gl_openvr.cpp
gl/stereo3d/gl_quadstereo.cpp
gl/stereo3d/gl_sidebyside3d.cpp
gl/stereo3d/gl_interleaved3d.cpp
@@ -62,7 +62,7 @@ class VSMatrix {
void perspective(FLOATTYPE fov, FLOATTYPE ratio, FLOATTYPE nearp, FLOATTYPE farp);
void ortho(FLOATTYPE left, FLOATTYPE right, FLOATTYPE bottom, FLOATTYPE top, FLOATTYPE nearp=-1.0f, FLOATTYPE farp=1.0f);
void frustum(FLOATTYPE left, FLOATTYPE right, FLOATTYPE bottom, FLOATTYPE top, FLOATTYPE nearp, FLOATTYPE farp);
void copy(FLOATTYPE * pDest)
void copy(FLOATTYPE * pDest) const
{
memcpy(pDest, mMatrix, 16 * sizeof(FLOATTYPE));
}
@@ -458,7 +458,8 @@ void FGLRenderBuffers::CreateEyeBuffers(int eye)

while (mEyeFBs.Size() <= unsigned(eye))
{
GLuint texture = Create2DTexture("EyeTexture", GL_RGBA16F, mWidth, mHeight);
// GL_RGBA16F, GL_RGBA16, GL_RGBA32F all do not work with OpenVR and HTC Vive
GLuint texture = Create2DTexture("EyeTexture", GL_RGBA12, mWidth, mHeight);
mEyeTextures.Push(texture);
mEyeFBs.Push(CreateFrameBuffer("EyeFB", texture));
}
@@ -485,6 +486,7 @@ GLuint FGLRenderBuffers::Create2DTexture(const FString &name, GLuint format, int
switch (format)
{
case GL_RGBA8: dataformat = GL_RGBA; datatype = GL_UNSIGNED_BYTE; break;
case GL_RGBA12: dataformat = GL_RGBA; datatype = GL_UNSIGNED_SHORT; break;
case GL_RGBA16: dataformat = GL_RGBA; datatype = GL_UNSIGNED_SHORT; break;
case GL_RGBA16F: dataformat = GL_RGBA; datatype = GL_FLOAT; break;
case GL_RGBA32F: dataformat = GL_RGBA; datatype = GL_FLOAT; break;
@@ -740,6 +742,10 @@ void FGLRenderBuffers::BindEyeFB(int eye, bool readBuffer)
glBindFramebuffer(readBuffer ? GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER, mEyeFBs[eye]);
}

GLuint FGLRenderBuffers::GetEyeTextureGLHandle(int eye) const { // Needed for OpenVR API
return mEyeTextures[eye];
}

//==========================================================================
//
// Shadow map texture and frame buffers
@@ -50,6 +50,7 @@ class FGLRenderBuffers
void BlitToEyeTexture(int eye);
void BindEyeTexture(int eye, int texunit);
void BindEyeFB(int eye, bool readBuffer = false);
GLuint GetEyeTextureGLHandle(int eye) const; // Needed for OpenVR API

void BindShadowMapFB();
void BindShadowMapTexture(int index);
@@ -0,0 +1,162 @@
/*
** LSMatrix.h
** less-simple matrix class
**
**---------------------------------------------------------------------------
** Copyright 2016 Christopher Bruns
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
**
*/


#ifndef VR_LS_MATRIX_H_
#define VR_LS_MATRIX_H_

#include "gl/data/gl_matrix.h"
#include "openvr.h"

namespace vr {
HmdMatrix34_t;
}

class LSVec3
{
public:
LSVec3(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w=1.0f)
: x(mVec[0]), y(mVec[1]), z(mVec[2]), w(mVec[3])
{
mVec[0] = x;
mVec[1] = y;
mVec[2] = z;
mVec[3] = w;
}

LSVec3(const LSVec3& rhs)
: x(mVec[0]), y(mVec[1]), z(mVec[2]), w(mVec[3])
{
*this = rhs;
}

LSVec3& operator=(const LSVec3& rhs) {
LSVec3& lhs = *this;
for (int i = 0; i < 4; ++i)
lhs[i] = rhs[i];
return *this;
}

const FLOATTYPE& operator[](int i) const {return mVec[i];}
FLOATTYPE& operator[](int i) { return mVec[i]; }

LSVec3 operator-(const LSVec3& rhs) const {
const LSVec3& lhs = *this;
LSVec3 result = *this;
for (int i = 0; i < 4; ++i)
result[i] -= rhs[i];
return result;
}

FLOATTYPE mVec[4];
FLOATTYPE& x;
FLOATTYPE& y;
FLOATTYPE& z;
FLOATTYPE& w;
};

LSVec3 operator*(FLOATTYPE s, const LSVec3& rhs) {
LSVec3 result = rhs;
for (int i = 0; i < 4; ++i)
result[i] *= s;
return result;
}

class LSMatrix44 : public VSMatrix
{
public:
LSMatrix44()
{
loadIdentity();
}

LSMatrix44(const vr::HmdMatrix34_t& m) {
loadIdentity();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 4; ++j) {
(*this)[i][j] = m.m[i][j];
}
}
}

LSMatrix44(const VSMatrix& m) {
m.copy(mMatrix);
}

// overload bracket operator to return one row of the matrix, so you can invoke, say, m[2][3]
FLOATTYPE* operator[](int i) {return &mMatrix[i*4];}
const FLOATTYPE* operator[](int i) const { return &mMatrix[i * 4]; }

LSMatrix44 operator*(const VSMatrix& rhs) const {
LSMatrix44 result(*this);
result.multMatrix(rhs);
return result;
}

LSVec3 operator*(const LSVec3& rhs) const {
const LSMatrix44& lhs = *this;
LSVec3 result(0, 0, 0, 0);
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
result[i] += lhs[i][j] * rhs[j];
}
}
return result;
}

LSMatrix44 getWithoutTranslation() const {
LSMatrix44 m = *this;
// Remove translation component
m[3][3] = 1.0f;
m[3][2] = m[3][1] = m[3][0] = 0.0f;
m[2][3] = m[1][3] = m[0][3] = 0.0f;
return m;
}

LSMatrix44 transpose() const {
LSMatrix44 result;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 4; ++j) {
result[i][j] = (*this)[j][i];
}
}
return result;
}

};

#endif // VR_LS_MATRIX_H_


0 comments on commit a05c38f

Please sign in to comment.
You can’t perform that action at this time.