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

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2013-07-05 02:04:34 +02:00
parent ffe05eae62
commit b1aaf05bf6
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,10 +135,57 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
{ {
m_Driver = driver; m_Driver = driver;
// todo: handle reso change! initTextures();
m_Mat = m_Driver->createMaterial();
m_Mat.initUnlit();
m_Mat.setColor(CRGBA::White);
m_Mat.setBlend (false);
m_Mat.setAlphaTest (false);
NL3D::CMaterial *mat = m_Mat.getObjectPtr();
mat->setShader(NL3D::CMaterial::PostProcessing);
mat->setBlendFunc(CMaterial::one, CMaterial::zero);
mat->setZWrite(false);
mat->setZFunc(CMaterial::always);
mat->setDoubleSided(true);
setTextures();
m_QuadUV.V0 = CVector(0.f, 0.f, 0.5f);
m_QuadUV.V1 = CVector(1.f, 0.f, 0.5f);
m_QuadUV.V2 = CVector(1.f, 1.f, 0.5f);
m_QuadUV.V3 = CVector(0.f, 1.f, 0.5f);
m_QuadUV.Uv0 = CUV(0.f, 0.f);
m_QuadUV.Uv1 = CUV(1.f, 0.f);
m_QuadUV.Uv2 = CUV(1.f, 1.f);
m_QuadUV.Uv3 = CUV(0.f, 1.f);
}
}
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; uint32 width, height;
driver->getWindowSize(width, height); m_Driver->getWindowSize(width, height);
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(m_Driver))->getDriver();
m_LeftTex = new CTextureBloom(); m_LeftTex = new CTextureBloom();
m_LeftTex->setRenderTarget(true); m_LeftTex->setRenderTarget(true);
@ -169,32 +208,31 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
drvInternal->setupTexture(*m_RightTex); drvInternal->setupTexture(*m_RightTex);
m_RightTexU = new CTextureUser(m_RightTex); m_RightTexU = new CTextureUser(m_RightTex);
nlassert(!drvInternal->isTextureRectangle(m_RightTex)); // not allowed nlassert(!drvInternal->isTextureRectangle(m_RightTex)); // not allowed
}
void CStereoDebugger::setTextures()
m_Mat = m_Driver->createMaterial(); {
m_Mat.initUnlit();
m_Mat.setColor(CRGBA::White);
m_Mat.setBlend (false);
m_Mat.setAlphaTest (false);
NL3D::CMaterial *mat = m_Mat.getObjectPtr(); NL3D::CMaterial *mat = m_Mat.getObjectPtr();
mat->setShader(NL3D::CMaterial::PostProcessing);
mat->setBlendFunc(CMaterial::one, CMaterial::zero);
mat->setZWrite(false);
mat->setZFunc(CMaterial::always);
mat->setDoubleSided(true);
mat->setTexture(0, m_LeftTex); mat->setTexture(0, m_LeftTex);
mat->setTexture(1, m_RightTex); mat->setTexture(1, m_RightTex);
}
void CStereoDebugger::verifyTextures()
m_QuadUV.V0 = CVector(0.f, 0.f, 0.5f); {
m_QuadUV.V1 = CVector(1.f, 0.f, 0.5f); if (m_Driver)
m_QuadUV.V2 = CVector(1.f, 1.f, 0.5f); {
m_QuadUV.V3 = CVector(0.f, 1.f, 0.5f); uint32 width, height;
m_Driver->getWindowSize(width, height);
m_QuadUV.Uv0 = CUV(0.f, 0.f); if (m_LeftTex->getWidth() != width
m_QuadUV.Uv1 = CUV(1.f, 0.f); || m_RightTex->getWidth() != width
m_QuadUV.Uv2 = CUV(1.f, 1.f); || m_LeftTex->getHeight() != height
m_QuadUV.Uv3 = CUV(0.f, 1.f); || m_RightTex->getHeight() != height)
{
nldebug("Rebuild textures");
releaseTextures();
initTextures();
setTextures();
}
} }
} }

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

@ -303,6 +303,10 @@ CClientConfig::CClientConfig()
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) );
@ -861,6 +916,11 @@ void prelogInit()
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))
{ {
@ -1103,6 +1163,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);
FPU_CHECKER_ONCE FPU_CHECKER_ONCE

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)
{ {