OpenCS: Set up an osgQt GraphicsWindow in SceneWidget

c++11
scrawl 10 years ago
parent 40fc097722
commit 34d503017a

@ -221,7 +221,7 @@ if (${OGRE_VERSION} VERSION_LESS "1.9")
message(FATAL_ERROR "OpenMW requires Ogre 1.9 or later, please install the latest stable version from http://ogre3d.org")
endif()
find_package(OpenSceneGraph 3.2.0 REQUIRED osgDB osgViewer osgGA osgAnimation osgParticle)
find_package(OpenSceneGraph 3.2.0 REQUIRED osgDB osgViewer osgGA osgAnimation osgParticle osgQt)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
find_package(MyGUI REQUIRED)

@ -157,7 +157,7 @@ endif(WIN32)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED)
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork QtOpenGL REQUIRED)
include(${QT_USE_FILE})
qt4_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})
@ -201,6 +201,7 @@ target_link_libraries(openmw-cs
${OGRE_LIBRARIES}
${OGRE_Overlay_LIBRARIES}
${OGRE_STATIC_PLUGINS}
${OPENSCENEGRAPH_LIBRARIES}
${SHINY_LIBRARIES}
${Boost_LIBRARIES}
${BULLET_LIBRARIES}

@ -44,6 +44,9 @@ int main(int argc, char *argv[])
{
try
{
// To allow background thread drawing in OSG
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
Q_INIT_RESOURCE (resources);
qRegisterMetaType<std::string> ("std::string");

@ -56,7 +56,7 @@ namespace CSVRender
//
MouseState::MouseState(WorldspaceWidget *parent)
: mParent(parent), mPhysics(parent->mDocument.getPhysics()), mSceneManager(parent->getSceneManager())
: mParent(parent), mPhysics(parent->mDocument.getPhysics()), mSceneManager(0/*parent->getSceneManager()*/)
, mCurrentObj(""), mMouseState(Mouse_Default), mOldPos(0,0), mMouseEventTimer(0), mPlane(0)
, mGrabbedSceneNode(""), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3())
, mCurrentMousePos(Ogre::Vector3()), mOffset(0.0f)
@ -447,17 +447,17 @@ namespace CSVRender
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *>::iterator iter = sceneWidgets.begin();
for(; iter != sceneWidgets.end(); ++iter)
{
(*iter).second->updateScene();
//(*iter).second->updateScene();
}
}
Ogre::Camera *MouseState::getCamera()
{
return mParent->getCamera();
return 0;//mParent->getCamera();
}
Ogre::Viewport *MouseState::getViewport()
{
return mParent->getCamera()->getViewport();
return 0;//mParent->getCamera()->getViewport();
}
}

@ -29,7 +29,7 @@
bool CSVRender::PagedWorldspaceWidget::adjustCells()
{
bool modified = false;
bool setCamera = false;
//bool setCamera = false;
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells();
@ -53,7 +53,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
}
// destroy manual objects
getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace));
//getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace));
delete iter->second;
mCells.erase (iter++);
@ -98,8 +98,8 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
}
}
if (mCells.begin()==mCells.end())
setCamera = true;
//if (mCells.begin()==mCells.end())
//setCamera = true;
// add
for (CSMWorld::CellSelection::Iterator iter (mSelection.begin()); iter!=mSelection.end();
@ -110,6 +110,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
if (index > 0 && cells.getRecord (index).mState!=CSMWorld::RecordBase::State_Deleted &&
mCells.find (*iter)==mCells.end())
{
#if 0
Cell *cell = new Cell (mDocument.getData(), getSceneManager(),
iter->getId (mWorldspace), mDocument.getPhysics());
mCells.insert (std::make_pair (*iter, cell));
@ -167,6 +168,8 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
}
*/
#endif
modified = true;
}
}
@ -242,28 +245,6 @@ void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
"terrain-move");
}
void CSVRender::PagedWorldspaceWidget::updateOverlay()
{
if(getCamera()->getViewport())
{
if((uint32_t)getCamera()->getViewport()->getVisibilityMask()
& (uint32_t)CSVRender::Element_CellMarker)
mDisplayCellCoord = true;
else
mDisplayCellCoord = false;
}
if(!mTextOverlays.empty())
{
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.begin();
for(; it != mTextOverlays.end(); ++it)
{
it->second->enable(mDisplayCellCoord);
it->second->update();
}
}
}
void CSVRender::PagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{
@ -329,6 +310,7 @@ void CSVRender::PagedWorldspaceWidget::referenceAdded (const QModelIndex& parent
std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
{
/*
Ogre::Vector3 position = getCamera()->getPosition();
std::ostringstream stream;
@ -339,6 +321,8 @@ std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
<< ", 0";
return stream.str();
*/
return "";
}
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
@ -363,7 +347,7 @@ CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
{
delete iter->second;
getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace));
//getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace));
}
for (std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator iter (mTextOverlays.begin());

@ -86,8 +86,6 @@ namespace CSVRender
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);
virtual void updateOverlay();
virtual void mousePressEvent (QMouseEvent *event);
virtual void mouseReleaseEvent (QMouseEvent *event);

@ -9,10 +9,9 @@
CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
const std::string& id, bool referenceable, QWidget *parent)
: SceneWidget (parent), mData (data),
mObject (data, getSceneManager()->getRootSceneNode(), id, referenceable, boost::shared_ptr<CSVWorld::PhysicsSystem>(), true)
: SceneWidget (parent), mData (data)
{
setNavigation (&mOrbit);
//setNavigation (&mOrbit);
QAbstractItemModel *referenceables =
mData.getTableModel (CSMWorld::UniversalId::Type_Referenceables);
@ -37,6 +36,7 @@ CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
void CSVRender::PreviewWidget::referenceableDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{
#if 0
if (mObject.referenceableDataChanged (topLeft, bottomRight))
flagAsModified();
@ -51,11 +51,13 @@ void CSVRender::PreviewWidget::referenceableDataChanged (const QModelIndex& topL
if (referenceables.data (index).toInt()==CSMWorld::RecordBase::State_Deleted)
emit closeRequest();
}
#endif
}
void CSVRender::PreviewWidget::referenceableAboutToBeRemoved (const QModelIndex& parent, int start,
int end)
{
#if 0
if (mObject.referenceableAboutToBeRemoved (parent, start, end))
flagAsModified();
@ -75,11 +77,13 @@ void CSVRender::PreviewWidget::referenceableAboutToBeRemoved (const QModelIndex&
emit closeRequest();
}
}
#endif
}
void CSVRender::PreviewWidget::referenceDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{
#if 0
if (mObject.referenceDataChanged (topLeft, bottomRight))
flagAsModified();
@ -108,11 +112,13 @@ void CSVRender::PreviewWidget::referenceDataChanged (const QModelIndex& topLeft,
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row())
if (index.column()>=topLeft.column() && index.column()<=bottomRight.row())
emit referenceableIdChanged (mObject.getReferenceableId());
#endif
}
void CSVRender::PreviewWidget::referenceAboutToBeRemoved (const QModelIndex& parent, int start,
int end)
{
#if 0
if (mObject.getReferenceId().empty())
return;
@ -123,4 +129,5 @@ void CSVRender::PreviewWidget::referenceAboutToBeRemoved (const QModelIndex& par
if (index.row()>=start && index.row()<=end)
emit closeRequest();
#endif
}

@ -21,7 +21,7 @@ namespace CSVRender
CSMWorld::Data& mData;
CSVRender::NavigationOrbit mOrbit;
Object mObject;
//Object mObject;
public:

@ -4,13 +4,7 @@
#include <QResizeEvent>
#include <QTimer>
#include <QShortcut>
#include <OgreRoot.h>
#include <OgreRenderWindow.h>
#include <OgreEntity.h>
#include <OgreCamera.h>
#include <OgreSceneNode.h>
#include <OgreViewport.h>
#include <QLayout>
#include "../widget/scenetoolmode.hpp"
#include "../../model/settings/usersettings.hpp"
@ -18,445 +12,75 @@
#include "navigation.hpp"
#include "lighting.hpp"
namespace CSVRender
{
SceneWidget::SceneWidget(QWidget *parent)
: QWidget(parent)
, mCamera(NULL)
, mSceneMgr(NULL)
, mWindow(NULL)
, mViewport(NULL)
, mNavigation (0), mLighting (0), mUpdate (false), mKeyForward (false)
, mKeyBackward (false), mKeyLeft (false), mKeyRight (false)
, mKeyRollLeft (false), mKeyRollRight (false)
, mFast (false), mDragging (false), mMod1 (false)
, mFastFactor (4)
, mDefaultAmbient (0, 0, 0, 0), mHasDefaultAmbient (false)
{
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setFocusPolicy (Qt::StrongFocus);
mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
mSceneMgr->setAmbientLight (Ogre::ColourValue (0,0,0,1));
mCamera = mSceneMgr->createCamera("foo");
mCamera->setPosition (300, 0, 0);
mCamera->lookAt (0, 0, 0);
mCamera->setNearClipDistance (0.1);
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
float farClipDist = userSettings.setting("3d-render/far-clip-distance", QString("300000")).toFloat();
mCamera->setFarClipDistance (farClipDist);
mFastFactor = userSettings.setting("scene-input/fast-factor", QString("4")).toInt();
mCamera->roll (Ogre::Degree (90));
setLighting (&mLightingDay);
QTimer *timer = new QTimer (this);
connect (timer, SIGNAL (timeout()), this, SLOT (update()));
int timerStart = userSettings.setting("scene-input/timer", QString("20")).toInt();
timer->start (timerStart);
/// \todo make shortcut configurable
QShortcut *focusToolbar = new QShortcut (Qt::Key_T, this, 0, 0, Qt::WidgetWithChildrenShortcut);
connect (focusToolbar, SIGNAL (activated()), this, SIGNAL (focusToolbarRequest()));
}
CSVWidget::SceneToolMode *SceneWidget::makeLightingSelector (CSVWidget::SceneToolbar *parent)
{
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent, "Lighting Mode");
/// \todo replace icons
tool->addButton (":scenetoolbar/day", "day",
"Day"
"<ul><li>Cell specific ambient in interiors</li>"
"<li>Low ambient in exteriors</li>"
"<li>Strong directional light source/lir>"
"<li>This mode closely resembles day time in-game</li></ul>");
tool->addButton (":scenetoolbar/night", "night",
"Night"
"<ul><li>Cell specific ambient in interiors</li>"
"<li>Low ambient in exteriors</li>"
"<li>Weak directional light source</li>"
"<li>This mode closely resembles night time in-game</li></ul>");
tool->addButton (":scenetoolbar/bright", "bright",
"Bright"
"<ul><li>Maximum ambient</li>"
"<li>Strong directional light source</li></ul>");
connect (tool, SIGNAL (modeChanged (const std::string&)),
this, SLOT (selectLightingMode (const std::string&)));
return tool;
}
void SceneWidget::setDefaultAmbient (const Ogre::ColourValue& colour)
{
mDefaultAmbient = colour;
mHasDefaultAmbient = true;
if (mLighting)
mLighting->setDefaultAmbient (colour);
}
void SceneWidget::updateOgreWindow()
{
if (mWindow)
{
Ogre::Root::getSingleton().destroyRenderTarget(mWindow);
mWindow = NULL;
}
std::stringstream windowHandle;
#ifdef WIN32
windowHandle << Ogre::StringConverter::toString((uintptr_t)(this->winId()));
#else
windowHandle << this->winId();
#endif
std::stringstream windowTitle;
static int count=0;
windowTitle << ++count;
Ogre::NameValuePairList params;
params.insert(std::make_pair("externalWindowHandle", windowHandle.str()));
params.insert(std::make_pair("title", windowTitle.str()));
std::string antialiasing =
CSMSettings::UserSettings::instance().settingValue("3d-render/antialiasing").toStdString();
if(antialiasing == "MSAA 16") antialiasing = "16";
else if(antialiasing == "MSAA 8") antialiasing = "8";
else if(antialiasing == "MSAA 4") antialiasing = "4";
else if(antialiasing == "MSAA 2") antialiasing = "2";
else antialiasing = "0";
params.insert(std::make_pair("FSAA", antialiasing));
params.insert(std::make_pair("vsync", "false")); // TODO setting
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
params.insert(std::make_pair("macAPI", "cocoa"));
params.insert(std::make_pair("macAPICocoaUseNSView", "true"));
#endif
mWindow = Ogre::Root::getSingleton().createRenderWindow(windowTitle.str(), this->width(), this->height(), false, &params);
mViewport = mWindow->addViewport (mCamera);
mViewport->setBackgroundColour (Ogre::ColourValue (0.3,0.3,0.3,1));
Ogre::Real aspectRatio = Ogre::Real(width()) / Ogre::Real(height());
mCamera->setAspectRatio(aspectRatio);
}
SceneWidget::~SceneWidget()
{
if (mWindow)
Ogre::Root::getSingleton().destroyRenderTarget (mWindow);
if (mSceneMgr)
Ogre::Root::getSingleton().destroySceneManager (mSceneMgr);
}
void SceneWidget::setVisibilityMask (unsigned int mask)
{
mViewport->setVisibilityMask (mask);
}
void SceneWidget::setNavigation (Navigation *navigation)
{
if ((mNavigation = navigation))
{
mNavigation->setFastModeFactor (mFast ? mFastFactor : 1);
if (mNavigation->activate (mCamera))
mUpdate = true;
}
}
void SceneWidget::addRenderTargetListener(Ogre::RenderTargetListener *listener)
{
mWindow->addListener(listener);
}
void SceneWidget::removeRenderTargetListener(Ogre::RenderTargetListener *listener)
{
mWindow->removeListener(listener);
}
#include <osgQt/GraphicsWindowQt>
#include <osg/GraphicsContext>
Ogre::Viewport *SceneWidget::getViewport()
{
if (!mWindow)
updateOgreWindow();
#include <osgGA/TrackballManipulator>
return mViewport;
}
Ogre::SceneManager *SceneWidget::getSceneManager()
{
return mSceneMgr;
}
Ogre::Camera *SceneWidget::getCamera()
{
return mCamera;
}
void SceneWidget::flagAsModified()
{
mUpdate = true;
}
void SceneWidget::paintEvent(QPaintEvent* e)
{
if (!mWindow)
updateOgreWindow();
mWindow->update();
e->accept();
}
QPaintEngine* SceneWidget::paintEngine() const
{
// We don't want another paint engine to get in the way.
// So we return nothing.
return NULL;
}
void SceneWidget::resizeEvent(QResizeEvent *e)
{
if (!mWindow)
return;
namespace CSVRender
{
const QSize &newSize = e->size();
SceneWidget::SceneWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
{
// TODO: Fix Ogre to handle this more consistently (fixed in 1.9)
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
mWindow->resize(newSize.width(), newSize.height());
#if QT_VERSION >= 0x050000
// Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4
osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded;
#else
mWindow->windowMovedOrResized();
osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
#endif
Ogre::Real aspectRatio = Ogre::Real(newSize.width()) / Ogre::Real(newSize.height());
mCamera->setAspectRatio(aspectRatio);
}
bool SceneWidget::event(QEvent *e)
{
if (e->type() == QEvent::WinIdChange)
{
// I haven't actually seen this happen yet.
if (mWindow)
updateOgreWindow();
}
return QWidget::event(e);
}
void SceneWidget::keyPressEvent (QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_W: mKeyForward = true; break;
case Qt::Key_S: mKeyBackward = true; break;
case Qt::Key_A: mKeyLeft = true; break;
case Qt::Key_D: mKeyRight = true; break;
case Qt::Key_Q: mKeyRollLeft = true; break;
case Qt::Key_E: mKeyRollRight = true; break;
case Qt::Key_Control: mMod1 = true; break;
case Qt::Key_Shift:
mFast = true;
if (mNavigation)
mNavigation->setFastModeFactor (mFastFactor);
break;
default: QWidget::keyPressEvent (event);
}
}
void SceneWidget::keyReleaseEvent (QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_W: mKeyForward = false; break;
case Qt::Key_S: mKeyBackward = false; break;
case Qt::Key_A: mKeyLeft = false; break;
case Qt::Key_D: mKeyRight = false; break;
case Qt::Key_Q: mKeyRollLeft = false; break;
case Qt::Key_E: mKeyRollRight = false; break;
case Qt::Key_Control: mMod1 = false; break;
case Qt::Key_Shift:
mFast = false;
if (mNavigation)
mNavigation->setFastModeFactor (1);
setThreadingModel(threadingModel);
break;
// disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone(0);
default: QWidget::keyReleaseEvent (event);
}
}
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = "";
traits->windowDecoration = true;
traits->x = 0;
traits->y = 0;
traits->width = width();
traits->height = height();
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
void SceneWidget::wheelEvent (QWheelEvent *event)
{
if (mNavigation)
if (event->delta())
if (mNavigation->wheelMoved (event->delta()))
mUpdate = true;
}
osgQt::GraphicsWindowQt* window = new osgQt::GraphicsWindowQt(traits.get());
QLayout* layout = new QHBoxLayout(this);
layout->addWidget(window->getGLWidget());
setLayout(layout);
void SceneWidget::leaveEvent (QEvent *event)
{
mDragging = false;
}
getCamera()->setGraphicsContext(window);
void SceneWidget::mouseMoveEvent (QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
if (mDragging)
{
QPoint diff = mOldPos-event->pos();
mOldPos = event->pos();
getCamera()->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
getCamera()->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
//getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f, 10000.0f );
if (mNavigation)
if (mNavigation->mouseMoved (diff, mMod1 ? 1 : 0))
mUpdate = true;
}
else
{
mDragging = true;
mOldPos = event->pos();
}
}
}
osg::Node* root = new osg::Node;
setSceneData(root);
void SceneWidget::mouseReleaseEvent (QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
mDragging = false;
}
setCameraManipulator(new osgGA::TrackballManipulator);
void SceneWidget::focusOutEvent (QFocusEvent *event)
{
mKeyForward = false;
mKeyBackward = false;
mKeyLeft = false;
mKeyRight = false;
mFast = false;
mMod1 = false;
// Only render when the camera position changed, or content flagged dirty
//setRunFrameScheme(osgViewer::ViewerBase::ON_DEMAND);
QWidget::focusOutEvent (event);
}
void SceneWidget::update()
{
if (mNavigation)
{
int horizontal = 0;
int vertical = 0;
if (mKeyForward && !mKeyBackward)
vertical = 1;
else if (!mKeyForward && mKeyBackward)
vertical = -1;
if (mKeyLeft && !mKeyRight)
horizontal = -1;
else if (!mKeyLeft && mKeyRight)
horizontal = 1;
if (horizontal || vertical)
if (mNavigation->handleMovementKeys (vertical, horizontal))
mUpdate = true;
int roll = 0;
if (mKeyRollLeft && !mKeyRollRight)
roll = 1;
else if (!mKeyRollLeft && mKeyRollRight)
roll = -1;
if (roll)
if (mNavigation->handleRollKeys (roll))
mUpdate = true;
}
if (mUpdate && mWindow)
{
mUpdate = false;
mWindow->update();
updateOverlay();
}
}
void SceneWidget::updateScene()
{
flagAsModified();
}
void SceneWidget::updateOverlay()
{ }
void SceneWidget::setLighting (Lighting *lighting)
{
if (mLighting)
mLighting->deactivate();
mLighting = lighting;
mLighting->activate (mSceneMgr, mHasDefaultAmbient ? &mDefaultAmbient : 0);
if (mWindow)
mWindow->update();
}
void SceneWidget::selectLightingMode (const std::string& mode)
{
if (mode=="day")
setLighting (&mLightingDay);
else if (mode=="night")
setLighting (&mLightingNight);
else if (mode=="bright")
setLighting (&mLightingBright);
}
connect( &mTimer, SIGNAL(timeout()), this, SLOT(update()) );
mTimer.start( 10 );
}
void SceneWidget::updateUserSetting (const QString &key, const QStringList &list)
{
if(key.contains(QRegExp("^\\b(Objects|Shader|Scene)", Qt::CaseInsensitive)))
flagAsModified();
void SceneWidget::paintEvent(QPaintEvent *event)
{
frame();
}
if(key == "3d-render/far-clip-distance" && !list.empty())
{
if(mCamera->getFarClipDistance() != list.at(0).toFloat())
mCamera->setFarClipDistance(list.at(0).toFloat());
}
void SceneWidget::flagAsModified()
{
_requestRedraw = true;
}
// minimise unnecessary ogre window creation by updating only when there is a change
if(key == "3d-render/antialiasing")
{
unsigned int aa = mWindow->getFSAA();
unsigned int antialiasing = 0;
if(!list.empty())
{
if(list.at(0) == "MSAA 16") antialiasing = 16;
else if(list.at(0) == "MSAA 8") antialiasing = 8;
else if(list.at(0) == "MSAA 4") antialiasing = 4;
else if(list.at(0) == "MSAA 2") antialiasing = 2;
}
if(aa != antialiasing)
updateOgreWindow();
}
}
}

@ -2,21 +2,13 @@
#define OPENCS_VIEW_SCENEWIDGET_H
#include <QWidget>
#include <OgreColourValue.h>
#include <QTimer>
#include "lightingday.hpp"
#include "lightingnight.hpp"
#include "lightingbright.hpp"
namespace Ogre
{
class Camera;
class SceneManager;
class RenderWindow;
class Viewport;
class RenderTargetListener;
}
#include <osgViewer/Viewer>
namespace CSVWidget
{
@ -29,110 +21,22 @@ namespace CSVRender
class Navigation;
class Lighting;
class SceneWidget : public QWidget
class SceneWidget : public QWidget, public osgViewer::Viewer
{
Q_OBJECT
public:
SceneWidget(QWidget *parent);
virtual ~SceneWidget();
QPaintEngine* paintEngine() const;
CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent);
///< \attention The created tool is not added to the toolbar (via addTool). Doing that
/// is the responsibility of the calling function.
virtual void setVisibilityMask (unsigned int mask);
virtual void updateScene();
protected:
void setNavigation (Navigation *navigation);
///< \attention The ownership of \a navigation is not transferred to *this.
void addRenderTargetListener(Ogre::RenderTargetListener *listener);
void removeRenderTargetListener(Ogre::RenderTargetListener *listener);
Ogre::Viewport *getViewport();
Ogre::SceneManager *getSceneManager();
Ogre::Camera *getCamera();
void flagAsModified();
void setDefaultAmbient (const Ogre::ColourValue& colour);
///< \note The actual ambient colour may differ based on lighting settings.
public:
SceneWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual void updateOverlay();
virtual void paintEvent( QPaintEvent* event );
virtual void mouseReleaseEvent (QMouseEvent *event);
void flagAsModified();
virtual void mouseMoveEvent (QMouseEvent *event);
protected:
void wheelEvent (QWheelEvent *event);
void keyPressEvent (QKeyEvent *event);
private:
void paintEvent(QPaintEvent* e);
void resizeEvent(QResizeEvent* e);
bool event(QEvent* e);
void keyReleaseEvent (QKeyEvent *event);
void focusOutEvent (QFocusEvent *event);
void leaveEvent (QEvent *event);
void updateOgreWindow();
void setLighting (Lighting *lighting);
///< \attention The ownership of \a lighting is not transferred to *this.
Ogre::Camera* mCamera;
Ogre::SceneManager* mSceneMgr;
Ogre::RenderWindow* mWindow;
Ogre::Viewport *mViewport;
Navigation *mNavigation;
Lighting *mLighting;
bool mUpdate;
bool mKeyForward;
bool mKeyBackward;
bool mKeyLeft;
bool mKeyRight;
bool mKeyRollLeft;
bool mKeyRollRight;
bool mFast;
bool mDragging;
bool mMod1;
QPoint mOldPos;
int mFastFactor;
Ogre::ColourValue mDefaultAmbient;
bool mHasDefaultAmbient;
LightingDay mLightingDay;
LightingNight mLightingNight;
LightingBright mLightingBright;
public slots:
void updateUserSetting (const QString &key, const QStringList &list);
private slots:
void update();
void selectLightingMode (const std::string& mode);
signals:
void focusToolbarRequest();
QTimer mTimer;
};
}
#endif

@ -26,11 +26,11 @@ void CSVRender::UnpagedWorldspaceWidget::update()
Ogre::ColourValue colour;
colour.setAsABGR (record.get().mAmbi.mAmbient);
setDefaultAmbient (colour);
//setDefaultAmbient (colour);
/// \todo deal with mSunlight and mFog/mForDensity
flagAsModified();
//flagAsModified();
}
CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, QWidget* parent)
@ -49,7 +49,7 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string&
update();
mCell.reset (new Cell (document.getData(), getSceneManager(), mCellId, document.getPhysics()));
//mCell.reset (new Cell (document.getData(), getSceneManager(), mCellId, document.getPhysics()));
}
void CSVRender::UnpagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft,
@ -91,7 +91,7 @@ bool CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector<CSMWorld:
return false;
mCellId = data.begin()->getId();
mCell.reset (new Cell (getDocument().getData(), getSceneManager(), mCellId, getDocument().getPhysics()));
//mCell.reset (new Cell (getDocument().getData(), getSceneManager(), mCellId, getDocument().getPhysics()));
update();
emit cellChanged(*data.begin());
@ -163,6 +163,7 @@ void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
std::string CSVRender::UnpagedWorldspaceWidget::getStartupInstruction()
{
/*
Ogre::Vector3 position = getCamera()->getPosition();
std::ostringstream stream;
@ -173,6 +174,8 @@ std::string CSVRender::UnpagedWorldspaceWidget::getStartupInstruction()
<< ", 0, \"" << mCellId << "\"";
return stream.str();
*/
return "";
}
CSVRender::WorldspaceWidget::dropRequirments CSVRender::UnpagedWorldspaceWidget::getDropRequirements (CSVRender::WorldspaceWidget::DropType type) const

@ -56,31 +56,33 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
this, SLOT (debugProfileAboutToBeRemoved (const QModelIndex&, int, int)));
mPhysics = document.getPhysics(); // create physics if one doesn't exist
mPhysics->addSceneManager(getSceneManager(), this);
//mPhysics->addSceneManager(getSceneManager(), this);
mMouse = new MouseState(this);
}
CSVRender::WorldspaceWidget::~WorldspaceWidget ()
{
delete mMouse;
mPhysics->removeSceneManager(getSceneManager());
//mPhysics->removeSceneManager(getSceneManager());
}
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode)
{
/*
if (mode=="1st")
setNavigation (&m1st);
else if (mode=="free")
setNavigation (&mFree);
else if (mode=="orbit")
setNavigation (&mOrbit);
*/
}
void CSVRender::WorldspaceWidget::useViewHint (const std::string& hint) {}
void CSVRender::WorldspaceWidget::selectDefaultNavigationMode()
{
setNavigation (&m1st);
//setNavigation (&m1st);
}
CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
@ -355,7 +357,7 @@ void CSVRender::WorldspaceWidget::debugProfileAboutToBeRemoved (const QModelInde
void CSVRender::WorldspaceWidget::elementSelectionChanged()
{
setVisibilityMask (getVisibilityMask());
//setVisibilityMask (getVisibilityMask());
flagAsModified();
updateOverlay();
}
@ -386,11 +388,13 @@ void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
/*
if(!getViewport())
{
SceneWidget::mouseReleaseEvent(event);
return;
}
*/
mMouse->mouseReleaseEvent(event);
}
SceneWidget::mouseReleaseEvent(event);

@ -30,8 +30,8 @@ CSVWorld::PreviewSubView::PreviewSubView (const CSMWorld::UniversalId& id, CSMDo
CSVWidget::SceneToolbar *toolbar = new CSVWidget::SceneToolbar (48+6, this);
CSVWidget::SceneToolMode *lightingTool = mScene->makeLightingSelector (toolbar);
toolbar->addTool (lightingTool);
//CSVWidget::SceneToolMode *lightingTool = mScene->makeLightingSelector (toolbar);
//toolbar->addTool (lightingTool);
layout->addWidget (toolbar, 0);
@ -67,4 +67,4 @@ void CSVWorld::PreviewSubView::referenceableIdChanged (const std::string& id)
setWindowTitle (QString::fromUtf8 (mTitle.c_str()));
emit updateTitle();
}
}

@ -107,8 +107,8 @@ CSVWidget::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::Worldsp
CSVWidget::SceneToolMode *navigationTool = widget->makeNavigationSelector (toolbar);
toolbar->addTool (navigationTool);
CSVWidget::SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar);
toolbar->addTool (lightingTool);
//CSVWidget::SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar);
//toolbar->addTool (lightingTool);
CSVWidget::SceneToolToggle2 *sceneVisibilityTool =
widget->makeSceneVisibilitySelector (toolbar);

Loading…
Cancel
Save