List stereo devices, see #43

--HG--
branch : multipass-stereo
hg/feature/sound
kaetemi 12 years ago
parent c188dd3e17
commit 64821ab4de

@ -0,0 +1,96 @@
/**
* \file stereo_ovr.h
* \brief CStereoOVR
* \date 2013-06-25 22:22GMT
* \author Jan Boon (Kaetemi)
* CStereoOVR
*/
/*
* Copyright (C) 2013 by authors
*
* This file is part of NL3D.
* NL3D is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* NL3D is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
* Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with NL3D. If not, see
* <http://www.gnu.org/licenses/>.
*
* Linking this library statically or dynamically with other modules
* is making a combined work based on this library. Thus, the terms
* and conditions of the GNU General Public License cover the whole
* combination.
*
* As a special exception, the copyright holders of this library give
* you permission to link this library with the Oculus SDK to produce
* an executable, regardless of the license terms of the Oculus SDK,
* and distribute linked combinations including the two, provided that
* you also meet the terms and conditions of the license of the Oculus
* SDK. You must obey the GNU General Public License in all respects
* for all of the code used other than the Oculus SDK. If you modify
* this file, you may extend this exception to your version of the
* file, but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version.
*/
#ifndef NL3D_STEREO_OVR_H
#define NL3D_STEREO_OVR_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#include <nel/misc/smart_ptr.h>
// Project includes
namespace NL3D {
struct CStereoDeviceInfo
{
public:
uint8 Class;
uint8 Identifier;
NLMISC::CSmartPtr<NLMISC::CRefCount> Factory;
std::string Manufacturer;
std::string ProductName;
};
class CStereoOVRDevicePtr;
/**
* \brief CStereoOVR
* \date 2013-06-25 22:22GMT
* \author Jan Boon (Kaetemi)
* CStereoOVR
*/
class CStereoOVR
{
public:
CStereoOVR(const CStereoDeviceInfo &deviceInfo);
virtual ~CStereoOVR();
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
static CStereoOVR *createDevice(const CStereoDeviceInfo &deviceInfo);
static bool isLibraryInUse();
static void releaseLibrary();
private:
CStereoOVRDevicePtr *m_DevicePtr;
}; /* class CStereoOVR */
} /* namespace NL3D */
#endif /* #ifndef NL3D_STEREO_OVR_H */
/* end of file */

@ -0,0 +1,209 @@
/**
* \file stereo_ovr.cpp
* \brief CStereoOVR
* \date 2013-06-25 22:22GMT
* \author Jan Boon (Kaetemi)
* CStereoOVR
*/
/*
* Copyright (C) 2013 by authors
*
* This file is part of NL3D.
* NL3D is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* NL3D is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
* Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with NL3D. If not, see
* <http://www.gnu.org/licenses/>.
*
* Linking this library statically or dynamically with other modules
* is making a combined work based on this library. Thus, the terms
* and conditions of the GNU General Public License cover the whole
* combination.
*
* As a special exception, the copyright holders of this library give
* you permission to link this library with the Oculus SDK to produce
* an executable, regardless of the license terms of the Oculus SDK,
* and distribute linked combinations including the two, provided that
* you also meet the terms and conditions of the license of the Oculus
* SDK. You must obey the GNU General Public License in all respects
* for all of the code used other than the Oculus SDK. If you modify
* this file, you may extend this exception to your version of the
* file, but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version.
*/
#include <nel/misc/types_nl.h>
#include <nel/3d/stereo_ovr.h>
// STL includes
// External includes
#include <OVR.h>
// NeL includes
// #include <nel/misc/debug.h>
// Project includes
using namespace std;
// using namespace NLMISC;
namespace NL3D {
namespace {
class CStereoOVRLog : public OVR::Log
{
public:
CStereoOVRLog(unsigned logMask = OVR::LogMask_All) : OVR::Log(logMask)
{
}
virtual void LogMessageVarg(OVR::LogMessageType messageType, const char* fmt, va_list argList)
{
if (NLMISC::INelContext::isContextInitialised())
{
char buffer[MaxLogBufferMessageSize];
FormatLog(buffer, MaxLogBufferMessageSize, messageType, fmt, argList);
if (IsDebugMessage(messageType))
NLMISC::INelContext::getInstance().getDebugLog()->displayNL("OVR: %s", buffer);
else
NLMISC::INelContext::getInstance().getInfoLog()->displayNL("OVR: %s", buffer);
}
}
};
CStereoOVRLog *s_StereoOVRLog = NULL;
OVR::Ptr<OVR::DeviceManager> s_DeviceManager;
class CStereoOVRSystem
{
public:
~CStereoOVRSystem()
{
Release();
}
void Init()
{
if (!s_StereoOVRLog)
{
nldebug("Initialize OVR");
s_StereoOVRLog = new CStereoOVRLog();
}
if (!OVR::System::IsInitialized())
OVR::System::Init(s_StereoOVRLog);
if (!s_DeviceManager)
s_DeviceManager = OVR::DeviceManager::Create();
}
void Release()
{
if (s_DeviceManager)
{
nldebug("Release OVR");
s_DeviceManager->Release();
}
s_DeviceManager.Clear();
if (OVR::System::IsInitialized())
OVR::System::Destroy();
if (s_StereoOVRLog)
nldebug("Release OVR Ok");
delete s_StereoOVRLog;
s_StereoOVRLog = NULL;
}
};
CStereoOVRSystem s_StereoOVRSystem;
class CStereoOVRDeviceHandle : public NLMISC::CRefCount
{
public:
OVR::DeviceHandle DeviceHandle;
};
sint s_DeviceCounter = 0;
}
class CStereoOVRDevicePtr
{
public:
OVR::Ptr<OVR::HMDDevice> HMDDevice;
};
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
{
++s_DeviceCounter;
m_DevicePtr = new CStereoOVRDevicePtr();
// CStereoOVRDeviceHandle *handle = static_cast<CStereoOVRDeviceHandle *>(deviceInfo.Factory.getPtr());
// OVR::DeviceHandle dh = handle->DeviceHandle;
// dh.CreateDevice();
}
CStereoOVR::~CStereoOVR()
{
// ...
delete m_DevicePtr;
m_DevicePtr = NULL;
--s_DeviceCounter;
}
void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
{
s_StereoOVRSystem.Init();
OVR::DeviceEnumerator<OVR::HMDDevice> devices = s_DeviceManager->EnumerateDevices<OVR::HMDDevice>();
uint8 id = 1;
do
{
CStereoDeviceInfo deviceInfoOut;
OVR::DeviceInfo deviceInfo;
if (devices.IsAvailable())
{
devices.GetDeviceInfo(&deviceInfo);
CStereoOVRDeviceHandle *handle = new CStereoOVRDeviceHandle();
deviceInfoOut.Factory = static_cast<NLMISC::CRefCount *>(handle);
handle->DeviceHandle = devices;
deviceInfoOut.Class = 1; // OVR::HMDDevice
deviceInfoOut.Identifier = id;
deviceInfoOut.Manufacturer = deviceInfo.Manufacturer;
deviceInfoOut.ProductName = deviceInfo.ProductName;
devicesOut.push_back(deviceInfoOut);
++id;
}
} while (devices.Next());
}
CStereoOVR *CStereoOVR::createDevice(const CStereoDeviceInfo &deviceInfo)
{
return NULL;
}
bool CStereoOVR::isLibraryInUse()
{
nlassert(s_DeviceCounter >= 0);
return s_DeviceCounter > 0;
}
void CStereoOVR::releaseLibrary()
{
nlassert(s_DeviceCounter == 0);
s_StereoOVRSystem.Release();
}
} /* namespace NL3D */
/* end of file */

@ -47,8 +47,8 @@ FpsSmoothing = 64;
OpenGL = 1;
// Resolution of the screen
ScreenWidth = 800;
ScreenHeight = 600;
ScreenWidth = 1280;
ScreenHeight = 800;
ScreenDepth = 32;
// If 1, run in fullscreen mode, 0 for windowed
@ -58,6 +58,15 @@ ScreenFull = 0;
StartPoint = { 1840.0, -970.0, 0.0 };
//////////////////////////////////////////////////////////////////////////////
// HMD Variables /////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
HMDEnable = 1;
HMDDeviceId = 0;
HMDDevice = "Auto";
//////////////////////////////////////////////////////////////////////////////
// Sound Variables ///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

@ -21,6 +21,7 @@
#include <nel/misc/types_nl.h>
#include <cmath>
#include <sstream>
#include <nel/misc/vectord.h>
#include <nel/misc/config_file.h>
#include <nel/3d/u_camera.h>
@ -33,6 +34,8 @@
#include <nel/3d/u_cloud_scape.h>
#include <nel/3d/viewport.h>
#include <nel/3d/stereo_ovr.h>
#include "snowballs_client.h"
#include "entities.h"
#include "mouse_listener.h"
@ -67,12 +70,47 @@ static UInstance Sky = NULL;
static UCloudScape *Clouds = NULL;
static CStereoOVR *s_StereoHMD = NULL;
//
// Functions
//
void initCamera()
{
if (ConfigFile->getVar("HMDEnable").asBool())
{
std::vector<NL3D::CStereoDeviceInfo> devices;
CStereoOVR::listDevices(devices);
for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
{
std::stringstream name;
name << std::string("[") << (uint32)it->Identifier << "] [" << it->Manufacturer << " - " << it->ProductName << "]";
nlinfo("Stereo Device: %s", name.str().c_str());
}
CStereoDeviceInfo *deviceInfo = NULL;
std::string hmdDeviceCfg = ConfigFile->getVar("HMDDevice").asString();
if (hmdDeviceCfg == std::string("Auto")
&& devices.begin() != devices.end())
{
deviceInfo = &devices[0];
}
else
{
uint8 hmdDeviceId = (ConfigFile->getVar("HMDDeviceId").asInt() & 0xFF);
for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
{
std::stringstream name;
name << it->Manufacturer << " - " << it->ProductName;
if (name.str() == hmdDeviceCfg)
deviceInfo = &(*it);
if (hmdDeviceId == it->Identifier)
break;
}
}
//s_StereoHMD->createDevice(
}
// Set up directly the camera
Camera = Scene->getCam();
Camera.setTransformMode (UTransformable::DirectMatrix);
@ -114,6 +152,8 @@ void releaseCamera()
Driver->deleteScene(SkyScene);
Scene->deleteInstance(Snow);
VisualCollisionManager->deleteEntity(CamCollisionEntity);
CStereoOVR::releaseLibrary();
}
void updateCamera()

@ -356,6 +356,7 @@ void initIngame()
//#ifdef NL_OS_WINDOWS
// playMusic(SBCLIENT_MUSIC_WAIT);
//#endif
displayLoadingState("Initialize");
// Create a scene
Scene = Driver->createScene(false);
@ -366,7 +367,6 @@ void initIngame()
CBloomEffect::instance().init(ConfigFile->getVar("OpenGL").asInt() == 1);
CConfiguration::setAndCallback("SquareBloom", cbSquareBloom);
CConfiguration::setAndCallback("DensityBloom", cbDensityBloom);
// Init the landscape using the previously created UScene
displayLoadingState("Initialize Landscape");
initLandscape();
@ -1141,21 +1141,29 @@ sint main(int argc, char **argv)
FILE *f = _tfopen(_T(SBCLIENT_CONFIG_FILE_DEFAULT), _T("r"));
if (!f)
{
OutputDebugString(" ******************************** \n");
OutputDebugString(" * CHANGING WORKING DIRECTORY * \n");
OutputDebugString(" ******************************** \n\n");
char cwd[256];
_tgetcwd(cwd, 256);
tstring workdir(cwd);
workdir += "\\..\\bin\\";
_tchdir(workdir.c_str());
f = _tfopen(_T(SBCLIENT_CONFIG_FILE_DEFAULT), _T("r"));
f = _tfopen(_T(SBCLIENT_CONFIG_FILE), _T("r"));
if (!f)
{
OutputDebugString(" ******************************** \n");
OutputDebugString(" * DEFAULT CONFIG MISSING * \n");
OutputDebugString(" * CHANGING WORKING DIRECTORY * \n");
OutputDebugString(" ******************************** \n\n");
return EXIT_FAILURE;
char cwd[256];
_tgetcwd(cwd, 256);
tstring workdir(cwd);
workdir = "R:\\build\\devw_x86\\bin\\Debug\\";
_tchdir(workdir.c_str());
f = _tfopen(_T(SBCLIENT_CONFIG_FILE_DEFAULT), _T("r"));
if (!f)
{
f = _tfopen(_T(SBCLIENT_CONFIG_FILE), _T("r"));
if (!f)
{
OutputDebugString(" ******************************** \n");
OutputDebugString(" * DEFAULT CONFIG MISSING * \n");
OutputDebugString(" ******************************** \n\n");
return EXIT_FAILURE;
}
}
}
}
fclose(f);

@ -75,7 +75,7 @@
# ifndef SNOWBALLS_CONFIG
# define SBCLIENT_CONFIG_FILE "snowballs_client.cfg"
# else
# define SBCLIENT_CONFIG_FILE SNOWBALLS_CONFIG "client.cfg"
# define SBCLIENT_CONFIG_FILE SNOWBALLS_CONFIG "snowballs_client.cfg"
# endif
#endif

Loading…
Cancel
Save