Init/release VR interfaces in ryzom client, ref #43

This commit is contained in:
kaetemi 2013-07-05 02:04:34 +02:00
parent 59edf6ea13
commit 541f75920b
11 changed files with 185 additions and 53 deletions

View file

@ -65,6 +65,10 @@ public:
/// Sets driver and generates necessary render targets /// Sets driver and generates necessary render targets
virtual void setDriver(NL3D::UDriver *driver); virtual void setDriver(NL3D::UDriver *driver);
void releaseTextures();
void initTextures();
void setTextures();
void verifyTextures();
/// Gets the required screen resolution for this device /// Gets the required screen resolution for this device
virtual bool getScreenResolution(uint &width, uint &height); virtual bool getScreenResolution(uint &width, uint &height);

View file

@ -96,21 +96,13 @@ CStereoDebugger::CStereoDebugger() : m_Driver(NULL), m_Stage(0), m_SubStage(0),
CStereoDebugger::~CStereoDebugger() CStereoDebugger::~CStereoDebugger()
{ {
releaseTextures();
if (!m_Mat.empty()) if (!m_Mat.empty())
{ {
m_Mat.getObjectPtr()->setTexture(0, NULL);
m_Mat.getObjectPtr()->setTexture(1, NULL);
m_Driver->deleteMaterial(m_Mat); m_Driver->deleteMaterial(m_Mat);
} }
delete m_LeftTexU;
m_LeftTexU = NULL;
m_LeftTex = NULL; // CSmartPtr
delete m_RightTexU;
m_RightTexU = NULL;
m_RightTex = NULL; // CSmartPtr
delete m_PixelProgram; delete m_PixelProgram;
m_PixelProgram = NULL; m_PixelProgram = NULL;
@ -143,33 +135,7 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
{ {
m_Driver = driver; m_Driver = driver;
// todo: handle reso change! initTextures();
uint32 width, height;
driver->getWindowSize(width, height);
m_LeftTex = new CTextureBloom();
m_LeftTex->setRenderTarget(true);
m_LeftTex->setReleasable(false);
m_LeftTex->resize(width, height);
m_LeftTex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
m_LeftTex->setWrapS(ITexture::Clamp);
m_LeftTex->setWrapT(ITexture::Clamp);
drvInternal->setupTexture(*m_LeftTex);
m_LeftTexU = new CTextureUser(m_LeftTex);
nlassert(!drvInternal->isTextureRectangle(m_LeftTex)); // not allowed
m_RightTex = new CTextureBloom();
m_RightTex->setRenderTarget(true);
m_RightTex->setReleasable(false);
m_RightTex->resize(width, height);
m_RightTex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
m_RightTex->setWrapS(ITexture::Clamp);
m_RightTex->setWrapT(ITexture::Clamp);
drvInternal->setupTexture(*m_RightTex);
m_RightTexU = new CTextureUser(m_RightTex);
nlassert(!drvInternal->isTextureRectangle(m_RightTex)); // not allowed
m_Mat = m_Driver->createMaterial(); m_Mat = m_Driver->createMaterial();
m_Mat.initUnlit(); m_Mat.initUnlit();
@ -182,9 +148,8 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
mat->setZWrite(false); mat->setZWrite(false);
mat->setZFunc(CMaterial::always); mat->setZFunc(CMaterial::always);
mat->setDoubleSided(true); mat->setDoubleSided(true);
mat->setTexture(0, m_LeftTex);
mat->setTexture(1, m_RightTex); setTextures();
m_QuadUV.V0 = CVector(0.f, 0.f, 0.5f); m_QuadUV.V0 = CVector(0.f, 0.f, 0.5f);
m_QuadUV.V1 = CVector(1.f, 0.f, 0.5f); m_QuadUV.V1 = CVector(1.f, 0.f, 0.5f);
@ -198,6 +163,79 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
} }
} }
void CStereoDebugger::releaseTextures()
{
if (!m_Mat.empty())
{
m_Mat.getObjectPtr()->setTexture(0, NULL);
m_Mat.getObjectPtr()->setTexture(1, NULL);
m_Driver->deleteMaterial(m_Mat);
}
delete m_LeftTexU;
m_LeftTexU = NULL;
m_LeftTex = NULL; // CSmartPtr
delete m_RightTexU;
m_RightTexU = NULL;
m_RightTex = NULL; // CSmartPtr
}
void CStereoDebugger::initTextures()
{
uint32 width, height;
m_Driver->getWindowSize(width, height);
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(m_Driver))->getDriver();
m_LeftTex = new CTextureBloom();
m_LeftTex->setRenderTarget(true);
m_LeftTex->setReleasable(false);
m_LeftTex->resize(width, height);
m_LeftTex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
m_LeftTex->setWrapS(ITexture::Clamp);
m_LeftTex->setWrapT(ITexture::Clamp);
drvInternal->setupTexture(*m_LeftTex);
m_LeftTexU = new CTextureUser(m_LeftTex);
nlassert(!drvInternal->isTextureRectangle(m_LeftTex)); // not allowed
m_RightTex = new CTextureBloom();
m_RightTex->setRenderTarget(true);
m_RightTex->setReleasable(false);
m_RightTex->resize(width, height);
m_RightTex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
m_RightTex->setWrapS(ITexture::Clamp);
m_RightTex->setWrapT(ITexture::Clamp);
drvInternal->setupTexture(*m_RightTex);
m_RightTexU = new CTextureUser(m_RightTex);
nlassert(!drvInternal->isTextureRectangle(m_RightTex)); // not allowed
}
void CStereoDebugger::setTextures()
{
NL3D::CMaterial *mat = m_Mat.getObjectPtr();
mat->setTexture(0, m_LeftTex);
mat->setTexture(1, m_RightTex);
}
void CStereoDebugger::verifyTextures()
{
if (m_Driver)
{
uint32 width, height;
m_Driver->getWindowSize(width, height);
if (m_LeftTex->getWidth() != width
|| m_RightTex->getWidth() != width
|| m_LeftTex->getHeight() != height
|| m_RightTex->getHeight() != height)
{
nldebug("Rebuild textures");
releaseTextures();
initTextures();
setTextures();
}
}
}
/// Gets the required screen resolution for this device /// Gets the required screen resolution for this device
bool CStereoDebugger::getScreenResolution(uint &width, uint &height) bool CStereoDebugger::getScreenResolution(uint &width, uint &height)
{ {

View file

@ -233,11 +233,6 @@ CStereoOVR::~CStereoOVR()
void CStereoOVR::setDriver(NL3D::UDriver *driver) void CStereoOVR::setDriver(NL3D::UDriver *driver)
{ {
// Do not allow weird stuff.
uint32 width, height;
driver->getWindowSize(width, height);
nlassert(width == m_DevicePtr->HMDInfo.HResolution);
nlassert(height == m_DevicePtr->HMDInfo.VResolution);
nlassert(!m_PixelProgram); nlassert(!m_PixelProgram);
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver(); NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver();
@ -264,7 +259,7 @@ void CStereoOVR::setDriver(NL3D::UDriver *driver)
m_BarrelTex = new CTextureBloom(); // lol bloom m_BarrelTex = new CTextureBloom(); // lol bloom
m_BarrelTex->setRenderTarget(true); m_BarrelTex->setRenderTarget(true);
m_BarrelTex->setReleasable(false); m_BarrelTex->setReleasable(false);
m_BarrelTex->resize(width, height); m_BarrelTex->resize(m_DevicePtr->HMDInfo.HResolution, m_DevicePtr->HMDInfo.VResolution);
m_BarrelTex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff); m_BarrelTex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
m_BarrelTex->setWrapS(ITexture::Clamp); m_BarrelTex->setWrapS(ITexture::Clamp);
m_BarrelTex->setWrapT(ITexture::Clamp); m_BarrelTex->setWrapT(ITexture::Clamp);
@ -358,6 +353,12 @@ void CStereoOVR::updateCamera(uint cid, const NL3D::UCamera *camera)
bool CStereoOVR::nextPass() bool CStereoOVR::nextPass()
{ {
// Do not allow weird stuff.
uint32 width, height;
m_Driver->getWindowSize(width, height);
nlassert(width == m_DevicePtr->HMDInfo.HResolution);
nlassert(height == m_DevicePtr->HMDInfo.VResolution);
switch (m_Stage) switch (m_Stage)
{ {
case 0: case 0:

View file

@ -17,7 +17,7 @@
#include <nel/misc/types_nl.h> #include <nel/misc/types_nl.h>
#include "camera.h" #include "camera.h"
#include <nel/3d/stereo_ovr.h> #include <nel/3d/stereo_display.h>
#include "global.h" #include "global.h"
#include "misc.h" #include "misc.h"

View file

@ -302,6 +302,10 @@ CClientConfig::CClientConfig()
Contrast = 0.f; // Default Monitor Contrast. Contrast = 0.f; // Default Monitor Contrast.
Luminosity = 0.f; // Default Monitor Luminosity. Luminosity = 0.f; // Default Monitor Luminosity.
Gamma = 0.f; // Default Monitor Gamma. Gamma = 0.f; // Default Monitor Gamma.
VREnable = false;
VRDisplayDevice = "Auto";
VRDisplayDeviceId = "";
Local = false; // Default is Net Mode. Local = false; // Default is Net Mode.
FSHost = ""; // Default Host. FSHost = ""; // Default Host.
@ -847,6 +851,9 @@ void CClientConfig::setValues()
else else
cfgWarning ("Default value used for 'Driver3D' !!!"); cfgWarning ("Default value used for 'Driver3D' !!!");
READ_BOOL_FV(VREnable)
READ_STRING_FV(VRDisplayDevice)
READ_STRING_FV(VRDisplayDeviceId)
//////////// ////////////
// INPUTS // // INPUTS //

View file

@ -146,6 +146,11 @@ struct CClientConfig
/// Monitor Gamma [-1 ~ 1], default 0 /// Monitor Gamma [-1 ~ 1], default 0
float Gamma; float Gamma;
// VR
bool VREnable;
std::string VRDisplayDevice;
std::string VRDisplayDeviceId;
/// Client in Local mode or not. /// Client in Local mode or not.
bool Local; bool Local;
/// Host. /// Host.

View file

@ -26,8 +26,8 @@ using namespace NLMISC;
// *************************************************************************** // ***************************************************************************
// Main System // Main System
NL3D::UDriver *Driver = 0; // The main 3D Driver NL3D::UDriver *Driver = 0; // The main 3D Driver
NL3D::CStereoOVR *StereoDisplay = NULL; // Stereo display NL3D::IStereoDisplay *StereoDisplay = NULL; // Stereo display
NL3D::CStereoOVR *StereoHMD = NULL; // Head mount display NL3D::IStereoHMD *StereoHMD = NULL; // Head mount display
CSoundManager *SoundMngr = 0; // the sound manager CSoundManager *SoundMngr = 0; // the sound manager
NL3D::UMaterial GenericMat; // Generic Material NL3D::UMaterial GenericMat; // Generic Material
NL3D::UTextContext *TextContext = 0; // Context for all the text in the client. NL3D::UTextContext *TextContext = 0; // Context for all the text in the client.

View file

@ -40,7 +40,8 @@ namespace NL3D
class UMaterial; class UMaterial;
class UTextContext; class UTextContext;
class UWaterEnvMap; class UWaterEnvMap;
class CStereoOVR; class IStereoDisplay;
class IStereoHMD;
} }
class CEntityAnimationManager; class CEntityAnimationManager;
@ -78,8 +79,8 @@ const float ExtraZoneLoadingVision = 100.f;
// *************************************************************************** // ***************************************************************************
// Main System // Main System
extern NL3D::UDriver *Driver; // The main 3D Driver extern NL3D::UDriver *Driver; // The main 3D Driver
extern NL3D::CStereoOVR *StereoDisplay; // Stereo display extern NL3D::IStereoDisplay *StereoDisplay; // Stereo display
extern NL3D::CStereoOVR *StereoHMD; extern NL3D::IStereoHMD *StereoHMD; // Head mount display
extern CSoundManager *SoundMngr; // the sound manager extern CSoundManager *SoundMngr; // the sound manager
extern NL3D::UMaterial GenericMat; // Generic Material extern NL3D::UMaterial GenericMat; // Generic Material
extern NL3D::UTextContext *TextContext; // Context for all the text in the client. extern NL3D::UTextContext *TextContext; // Context for all the text in the client.

View file

@ -39,6 +39,7 @@
#include "nel/3d/u_driver.h" #include "nel/3d/u_driver.h"
#include "nel/3d/u_text_context.h" #include "nel/3d/u_text_context.h"
#include "nel/3d/u_shape_bank.h" #include "nel/3d/u_shape_bank.h"
#include "nel/3d/stereo_hmd.h"
// Net. // Net.
#include "nel/net/email.h" #include "nel/net/email.h"
// Ligo. // Ligo.
@ -46,6 +47,7 @@
// Std. // Std.
#include <fstream> #include <fstream>
#include <sstream>
// Game Share // Game Share
#include "game_share/ryzom_version.h" #include "game_share/ryzom_version.h"
// Client // Client
@ -792,6 +794,59 @@ void prelogInit()
// Check driver version // Check driver version
checkDriverVersion(); checkDriverVersion();
// Initialize the VR devices (even more important than the most important part of the client)
nmsg = "Initializing VR devices...";
ProgressBar.newMessage ( ClientCfg.buildLoadingString(nmsg) );
if (ClientCfg.VREnable)
{
nldebug("VR [C]: Enabled");
std::vector<NL3D::CStereoDeviceInfo> devices;
IStereoDisplay::listDevices(devices);
for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
{
std::stringstream name;
name << std::string("[") << it->Serial << "] [" << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName << "]";
nlinfo("VR [C]: Stereo Display: %s", name.str().c_str());
}
CStereoDeviceInfo *deviceInfo = NULL;
if (ClientCfg.VRDisplayDevice == std::string("Auto")
&& devices.begin() != devices.end())
{
deviceInfo = &devices[0];
}
else
{
for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
{
std::stringstream name;
name << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName;
if (name.str() == ClientCfg.VRDisplayDevice)
deviceInfo = &(*it);
if (ClientCfg.VRDisplayDeviceId == it->Serial)
break;
}
}
if (deviceInfo)
{
nlinfo("VR [C]: Create VR stereo display device");
StereoDisplay = IStereoDisplay::createDevice(*deviceInfo);
if (StereoDisplay)
{
if (deviceInfo->Class == CStereoDeviceInfo::StereoHMD)
{
nlinfo("VR [C]: Stereo display device is a HMD");
StereoHMD = static_cast<IStereoHMD *>(StereoDisplay);
}
}
}
}
else
{
nldebug("VR [C]: NOT Enabled");
}
IStereoDisplay::releaseUnusedLibraries();
// Create the driver (most important part of the client). // Create the driver (most important part of the client).
nmsg = "Creating 3d driver..."; nmsg = "Creating 3d driver...";
ProgressBar.newMessage ( ClientCfg.buildLoadingString(nmsg) ); ProgressBar.newMessage ( ClientCfg.buildLoadingString(nmsg) );
@ -860,6 +915,11 @@ void prelogInit()
Driver->setSwapVBLInterval(1); Driver->setSwapVBLInterval(1);
else else
Driver->setSwapVBLInterval(0); Driver->setSwapVBLInterval(0);
if (StereoDisplay)
{
// override mode TODO
}
// Set the mode of the window. // Set the mode of the window.
if (!Driver->setDisplay (mode, false)) if (!Driver->setDisplay (mode, false))
@ -1102,6 +1162,12 @@ void prelogInit()
// init bloom effect // init bloom effect
CBloomEffect::getInstance().init(driver != UDriver::Direct3d); CBloomEffect::getInstance().init(driver != UDriver::Direct3d);
if (StereoDisplay)
{
// Init stereo display resources
StereoDisplay->setDriver(Driver);
}
nlinfo ("PROFILE: %d seconds for prelogInit", (uint32)(ryzomGetLocalTime ()-initStart)/1000); nlinfo ("PROFILE: %d seconds for prelogInit", (uint32)(ryzomGetLocalTime ()-initStart)/1000);

View file

@ -42,7 +42,7 @@
#include "nel/3d/u_material.h" #include "nel/3d/u_material.h"
#include "nel/3d/u_instance_material.h" #include "nel/3d/u_instance_material.h"
#include "nel/3d/u_cloud_scape.h" #include "nel/3d/u_cloud_scape.h"
#include "nel/3d/stereo_ovr.h" #include "nel/3d/stereo_hmd.h"
// game share // game share
#include "game_share/brick_types.h" #include "game_share/brick_types.h"
#include "game_share/light_cycle.h" #include "game_share/light_cycle.h"

View file

@ -35,6 +35,7 @@
#include "nel/3d/u_scene.h" #include "nel/3d/u_scene.h"
#include "nel/3d/u_visual_collision_manager.h" #include "nel/3d/u_visual_collision_manager.h"
#include "nel/3d/u_shape_bank.h" #include "nel/3d/u_shape_bank.h"
#include "nel/3d/stereo_hmd.h"
// Client // Client
#include "global.h" #include "global.h"
#include "release.h" #include "release.h"
@ -559,6 +560,15 @@ void release()
CEntityAnimationManager::delInstance(); CEntityAnimationManager::delInstance();
EAM= NULL; EAM= NULL;
nldebug("VR [C]: VR Shutting down");
if (StereoDisplay)
{
delete StereoDisplay;
StereoDisplay = NULL;
StereoHMD = NULL;
}
IStereoDisplay::releaseAllLibraries();
// Delete the driver. // Delete the driver.
if(Driver) if(Driver)
{ {