22 SViewPort::SViewPort()
27 SViewPort::SViewPort(
SWindow* parent,
SCamera* camera,
int priority,
const float& x,
const float& y,
const float&
w,
const float& h)
31 Ogre::RenderWindow* renderWindow =
const_cast <Ogre::RenderWindow*
> (
const_cast <SWindow*
> (scolWindow)->GetOgreRenderWindowPointer());
32 priority = renderWindow->getNumViewports();
39#ifdef SO3_BUILD_DEFERRED
40 bDeferredEnable =
false;
45 O3ViewPort->setVisibilityMask(SO3_VISIBILITY_MASK_DEFAULT);
51 catch(Ogre::Exception& e)
54 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"An exception has occurred: " + e.getDescription());
61 catch (Ogre::Exception& e)
64 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"An exception has occurred: " + e.getDescription());
72 O3ViewPort->addListener(
this);
73 O3ViewPort->setMaterialScheme(Ogre::MSN_SHADERGEN);
78 O3ViewPort->removeListener(
this);
80#ifdef SO3_BUILD_DEFERRED
84 SAFE_DELETE(ssaoHandler);
85 SAFE_DELETE(hdrHandler);
94 const_cast <Ogre::RenderWindow*
> (
const_cast <SWindow*
> (scolWindow)->GetOgreRenderWindowPointer())->removeViewport(O3ViewPort->getZOrder());
110 std::string schemeName = O3ViewPort->getMaterialScheme();
112 if (schemeName.find(
"ShaderGenerator") != std::string::npos)
113 schemeName = schemeName.erase(0, 15);
120 if (existingScheme.empty() || existingScheme ==
"Default" || existingScheme ==
"DefaultScheme")
121 O3ViewPort->setMaterialScheme(Ogre::MSN_SHADERGEN);
124 std::string newScheme = existingScheme;
125 O3ViewPort->setMaterialScheme(newScheme);
133 O3ViewPort->setDimensions(
static_cast <Ogre::Real
> (x),
static_cast <Ogre::Real
> (y),
static_cast <Ogre::Real
> (
w),
static_cast <Ogre::Real
> (h));
148 MMechostr(MSKDEBUG,
"SO3ViewportResize %i %i %f %f\n", rw, rh, (
float)
w / (
float)rw, (
float)h / (
float)rh);
149 SetPositionAndSize(O3ViewPort->getLeft(), O3ViewPort->getTop(), (
float)
w / (
float)rw, (
float)h / (
float)rh);
155 return O3ViewPort->getLeft();
160 return O3ViewPort->getTop();
165 return O3ViewPort->getWidth();
170 return O3ViewPort->getHeight();
175 return O3ViewPort->getActualLeft();
180 return O3ViewPort->getActualTop();
185 return O3ViewPort->getActualWidth();
190 return O3ViewPort->getActualHeight();
195 return O3ViewPort->getZOrder();
200 return O3ViewPort->getShadowsEnabled();
205 O3ViewPort->setShadowsEnabled(enableShadows);
245 cRatio = (float)O3ViewPort->getActualWidth() / (float)O3ViewPort->getActualHeight();
256 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->invalidateScheme(O3ViewPort->getMaterialScheme());
259 if (ssaoHandler && ssaoHandler->
GetEnable())
275 O3ViewPort->setCamera(0);
346 int mode = Ogre::FBT_DEPTH;
347 if (bClearColor && !bClearDepth)
349 mode = Ogre::FBT_COLOUR;
352 else if (bClearColor && bClearDepth)
354 mode = mode | Ogre::FBT_COLOUR;
357 O3ViewPort->setClearEveryFrame(bClear, mode);
373 int mode = Ogre::FBT_COLOUR;
374 if (bClearDepth && !bClearColor)
376 mode = Ogre::FBT_DEPTH;
379 else if (bClearDepth && bClearColor)
381 mode = mode | Ogre::FBT_DEPTH;
384 O3ViewPort->setClearEveryFrame(bClear, mode);
390 O3ViewPort->setSkiesEnabled(value);
396 return O3ViewPort->getSkiesEnabled();
401 O3ViewPort->setOverlaysEnabled(value);
407 return O3ViewPort->getOverlaysEnabled();
410#ifdef SO3_BUILD_DEFERRED
414 if (deferredManager != 0)
421 deferredManager->
SetSSAO(
this, bSSAOEnable);
439 bDeferredEnable = value;
445 return bDeferredEnable;
451 if (deferredManager != 0)
461 bDeferredAntiAliasingMode = value;
466 return bDeferredAntiAliasingMode;
472 if (deferredManager != 0)
478 catch (Ogre::Exception&)
486 int currentDebugMode = 0;
489 if (deferredManager != 0)
491 currentDebugMode =
static_cast<int>(deferredManager->
GetMode());
493 return currentDebugMode;
502#ifdef SO3_BUILD_DEFERRED
504 if ((deferredManager != 0) && bDeferredEnable)
509 deferredManager->
SetSSAO(
this, value);
573 O3ViewPort->setVisibilityMask(mask);
580 return O3ViewPort->getVisibilityMask();
585 assert((flagIndex > 0) && (flagIndex < 32));
586 Ogre::uint32 flag = 1 << flagIndex;
587 Ogre::uint32
flags = O3ViewPort->getVisibilityMask();
589 O3ViewPort->setVisibilityMask(
flags | flag);
591 O3ViewPort->setVisibilityMask(
flags & ~flag);
599 assert((flagIndex > 0) && (flagIndex < 32));
600 Ogre::uint32 flag = 1 << flagIndex;
601 if ((flag & O3ViewPort->getVisibilityMask()) > 0)
611 O3ViewPort->update();
613 catch (Ogre::Exception& e)
615 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"An exception has occurred: " + e.getDescription());
621 SCompositorMap::iterator iCompositorSearched = compList.find(compositorName);
622 if (iCompositorSearched != compList.end())
623 return iCompositorSearched->second;
636 if (newCompositor == 0)
638 newCompositor =
new SCompositor(
this, newCompositorName, newSchemeName);
641 return newCompositor;
652 SO3_SAFE_DELETE(existingCompositor);
658 SCompositorMap::iterator iCompositorList = compList.begin();
661 while (iCompositorList != compList.end())
663 SO3_SAFE_DELETE(iCompositorList->second);
671 string name = existingCompositor->
GetName();
672 SCompositorMap::iterator iCompositorSearched = compList.find(name);
673 if (iCompositorSearched == compList.end())
675 compList.insert(SCompositorMap::value_type(name, existingCompositor));
680 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM,
"Can not add Compositor named \"" + name +
"\", an element with the same name already exist!",
"SViewPort::AddCompositor");
691 SCompositorMap::iterator iCompositorSearched = compList.find(compositorName);
692 if (iCompositorSearched != compList.end())
694 compList.erase(iCompositorSearched);
699 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Can not remove Compositor named \"" + compositorName +
"\", element not found!",
"SViewPort::RemoveCompositor");
711 Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(cam->getDerivedOrientation().zAxis()), cam->getDerivedPosition());
712 if (cameraPlane.getSide(worldPosition) != Ogre::Plane::NEGATIVE_SIDE)
715 Ogre::Vector3 screenPoint = cam->getProjectionMatrix() * cam->getViewMatrix() * worldPosition;
716 float x = (screenPoint.x * 0.5f) + 0.5f;
717 float y = 1.0f - ((screenPoint.y * 0.5f) + 0.5f);
720 if ((x < 0.0f) || (x > 1.0f) || (y < 0.0f) || (y > 1.0f))
723 screenPos = Ogre::Vector2(O3ViewPort->getActualWidth() * x, O3ViewPort->getActualHeight() * y);
742 if (subEntitySelector)
745 Ogre::SubEntity* subEntity = 0;
747 Ogre::Vector3 pos(0.0f, 0.0f, 0.0f);
748 float rayLenght = 0.0f;
749 if (subEntitySelector != 0)
757 Ogre::Camera* camera = O3ViewPort->getCamera();
761 Ogre::Real nx = (2.0f * xR) - 1.0f;
762 Ogre::Real ny = 1.0f - (2.0f * yR);
763 Ogre::Vector3 nearPoint(nx, ny, -1.0f);
764 Ogre::Vector3 midPoint(nx, ny, 0.0f);
767 Ogre::Matrix4 invViewMat = (camera->getProjectionMatrix() * camera->getViewMatrix(
true)).inverse();
768 Ogre::Vector3 rayOrigin = invViewMat * nearPoint;
769 Ogre::Vector3 rayDest = invViewMat * midPoint;
770 Ogre::Vector3 rayDirection = rayDest - rayOrigin;
771 rayDirection.normalise();
773 float farclip = camera->getFarClipDistance();
774 float nearclip = camera->getNearClipDistance();
777 if (camera->getProjectionType() == Ogre::PT_PERSPECTIVE)
780 Ogre::Vector4 viewpos = camera->getProjectionMatrixWithRSDepth().inverse() * Ogre::Vector4(nx, ny, zdepth, 1.0f);
781 zdepth = viewpos.z / viewpos.w;
796 double ylenght = Ogre::Math::Tan(camera->getFOVy().valueRadians() / 2.0f);
797 double xlenght = ylenght * camera->getAspectRatio();
798 double opx = zdepth * abs(xlenght * nx);
799 double opy = zdepth * abs(ylenght * ny);
800 rayLenght = Ogre::Math::Sqrt((Ogre::Real)((zdepth * zdepth) + (opx * opx) + (opy * opy)));
804 zdepth *= (farclip - nearclip);
815 pos = rayOrigin + (rayDirection * rayLenght);
826 for (
unsigned int i = 0; i < subEntity->getParent()->getNumSubEntities() && (subid == -1); i++)
828 if (subEntity->getParent()->getSubEntity(i) == subEntity)
837 Ogre::Any bindedCustomEntity = subEntity->getUserObjectBindings().getUserAny(
"SEntity");
838 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
842 raycastReturn.
entity = entity;
844 raycastReturn.
scene = scene;
851 raycastReturn =
SRaycast::Cast(scolCamera, xR, yR, subEntity,
true);
853 raycastReturn.
point = pos;
858 Ogre::Any bindedCustomEntity = subEntity->getUserObjectBindings().getUserAny(
"SEntity");
859 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
866 raycastReturn.
entity = entity;
868 raycastReturn.
scene = scene;
872 raycastReturn =
SRaycast::Cast(scolCamera, xR, yR, subEntity,
true);
882 if (raycastReturn.
scene == 0)
884 raycastReturn.
entity = entity;
886 raycastReturn.
scene = scene;
917 return raycastReturn;
926 return scolWindow->
RayCast(O3ViewPort->getActualLeft() + x, O3ViewPort->getActualTop() + y);
929 Ogre::Vector3
SViewPort::RayCastCamera(
const int& pixelsX,
const int& pixelsY,
const float distance, Ogre::Vector3 &outDirection)
932 OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE,
"There is now active camera on viewport",
"SViewPort::RayCastCamera");
937 outDirection = ray.getDirection();
938 return ray.getOrigin() + ray.getDirection() * distance;
947 Ogre::CompositorManager &compositorManager = Ogre::CompositorManager::getSingleton();
948 if (compositorManager.hasCompositorChain(O3ViewPort))
950 Ogre::CompositorChain* chain = compositorManager.getCompositorChain(O3ViewPort);
954 Ogre::CompositorChain::Instances instances = chain->getCompositorInstances();
955 for (
unsigned int i = 0; i < instances.size(); i++)
957 Ogre::CompositorInstance *compositorInstance = instances.at(i);
958 Ogre::Compositor *compositor = compositorInstance->getCompositor();
959 bool state = compositorInstance->getEnabled();
962 compositorInstance->setEnabled(
false);
963 compositorInstance->setEnabled(
true);
971 Ogre::Technique*
SViewPort::handleSchemeNotFound(
unsigned short schemeIndex,
const Ogre::String& schemeName, Ogre::Material* originalMaterial,
unsigned short lodIndex,
const Ogre::Renderable* rend)
973 MMechostr(MSKDEBUG,
">>>>>>>>> Material scheme missed : %s for material : %s\n", schemeName.c_str(), originalMaterial->getName().c_str());
974 Ogre::MaterialPtr smat =
static_cast<Ogre::MaterialPtr
>(Ogre::MaterialManager::getSingleton().getByName(
"SO3/Internal/Default", SO3_INTERNAL_RESOURCE_GROUP));
976 return smat->getTechnique(0);
985 unsigned int numFaces = 0;
987 Ogre::CompositorManager &compositorManager = Ogre::CompositorManager::getSingleton();
988 if (compositorManager.hasCompositorChain(O3ViewPort))
990 Ogre::CompositorChain* chain = compositorManager.getCompositorChain(O3ViewPort);
994 Ogre::CompositorChain::Instances instances = chain->getCompositorInstances();
995 for (
unsigned int i = 0; i < instances.size(); i++)
997 Ogre::CompositorInstance *compositorInstance = instances.at(i);
998 if (compositorInstance->getEnabled())
1000 Ogre::CompositionTechnique::TargetPasses passList = compositorInstance->getTechnique()->getTargetPasses();
1001 for (
unsigned int j = 0; j < passList.size(); ++j)
1003 Ogre::RenderTarget* rendTarget = 0;
1007 rendTarget = compositorInstance->getRenderTarget(passList[j]->getOutputName());
1009 catch (Ogre::Exception &)
1015 numFaces += rendTarget->getStatistics().triangleCount;
1022 numFaces += O3ViewPort->_getNumRenderedFaces();
1033 unsigned int numBatches = 0;
1035 Ogre::CompositorManager &compositorManager = Ogre::CompositorManager::getSingleton();
1036 if (compositorManager.hasCompositorChain(O3ViewPort))
1038 Ogre::CompositorChain* chain = compositorManager.getCompositorChain(O3ViewPort);
1042 Ogre::CompositorChain::Instances instances = chain->getCompositorInstances();
1043 for (
unsigned int i = 0; i < instances.size(); i++)
1045 Ogre::CompositorInstance *compositorInstance = instances.at(i);
1046 if (compositorInstance->getEnabled())
1048 Ogre::CompositionTechnique::TargetPasses passList = compositorInstance->getTechnique()->getTargetPasses();
1049 for (
unsigned int j = 0; j < passList.size(); ++j)
1051 Ogre::RenderTarget* rendTarget = 0;
1055 rendTarget = compositorInstance->getRenderTarget(passList[j]->getOutputName());
1057 catch (Ogre::Exception &)
1063 numBatches += rendTarget->getStatistics().batchCount;
1069 numBatches += O3ViewPort->_getNumRenderedBatches();
1079 ScolWindowHandle awindow = (ScolWindowHandle)SCgetExtra(
"hscol");
1080 int nwidth = (int)ANativeWindow_getWidth(awindow);
1081 int nheight = (int)ANativeWindow_getHeight(awindow);
1086#elif defined(APPLE_IOS)
1097 ScolWindowHandle awindow = (ScolWindowHandle)SCgetExtra(
"hscol");
1098 int nwidth = (int)ANativeWindow_getWidth(awindow);
1099 int nheight = (int)ANativeWindow_getHeight(awindow);
1104#elif defined(APPLE_IOS)
1115 ScolWindowHandle awindow = (ScolWindowHandle)SCgetExtra(
"hscol");
1116 int nwidth = (int)ANativeWindow_getWidth(awindow);
1117 int nheight = (int)ANativeWindow_getHeight(awindow);
1122#elif defined(APPLE_IOS)
1125 px = (int)((
float)px / ratio);
1126 py = (int)((
float)py / ratio);
1133 ScolWindowHandle awindow = (ScolWindowHandle)SCgetExtra(
"hscol");
1134 int nwidth = (int)ANativeWindow_getWidth(awindow);
1135 int nheight = (int)ANativeWindow_getHeight(awindow);
1140#elif defined(APPLE_IOS)
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
void SetCurrentViewPort(SViewPort *mViewPort)
Ogre::Camera * GetOgreCameraPointer()
std::string GetName() const
void SetAntiAliasing(SViewPort *existingViewport, DeferredShadingAntiAliasingMode newMode)
DeferredShadingAntiAliasingMode
void SetSSAO(SViewPort *existingViewport, bool ssao)
void UnregisterViewport(SViewPort *existingViewport)
void RegisterViewport(SViewPort *targetViewport)
DeferredShadingMode GetMode() const
void SetMode(DeferredShadingMode mode)
std::string GetGroupName()
Base class for SO3 custom exception.
void SetEnable(bool enable)
void SetEffectAmount(float amount)
void SetBlurAmount(float amount)
void SetGamma(float gamma)
SWidget * GetAssociatedWidget()
SScene * GetParentScene()
virtual Ogre::Vector3 GetGlobalPosition()
static SRaycastResult Cast(SCamera *camera, const float &relativePosX, const float &relativePosY, Ogre::SubEntity *subEntity, bool getUvCoordonate=false)
SDeferredShading * GetDeferredManager()
RenderSystem GetRenderSystem()
void UpdateCamera(SViewPort *viewport)
static SRoot & getSingleton()
static SRoot * getSingletonPtr()
SMaterial * GetMaterial(const std::string &groupName, const std::string &materialName, bool searchOtherGroups=true)
void GetSimpleRayCast(Ogre::Ray cameraRay, SRaycastResult &result)
void SetEnable(bool enable)
float GetSelectedZdepth(int posX, int posY)
Ogre::SubEntity * GetSelectedSubEntity(int posX, int posY)
void SetVisibilityMaskIndexEnable(const Ogre::uint32 flagIndex, const bool enable)
SHdrHandler * GetHDRhandler()
void SetSkyEnable(const bool &value)
void SetVisibilityMask(const Ogre::uint32 &mask)
void AddCompositor(SCompositor *existingCompositor)
void ToWindowPos(int &px, int &py)
void SetDeferredEnable(const bool &value)
bool GetVisibilityMaskIndexEnable(const Ogre::uint32 flagIndex)
void SetHDREnable(const bool &value)
void RegisterStereoViewport()
SCompositor * GetCompositor(const std::string &compositorName)
void SetPositionAndSize(const float &x, const float &y, const float &w, const float &h)
void ToPixelPos(int &px, int &py)
void UnregisterStereoViewport()
Ogre::Vector3 RayCastCamera(const int &pixelsX, const int &pixelsY, const float distance, Ogre::Vector3 &outDirection)
void SetShadowsEnabled(const bool &enableShadows)
void SetMaterialScheme(const std::string &existingScheme)
void SetOverlayEnable(const bool &value)
void SetDeferredDebugMode(const int &value)
SDeferredShading::DeferredShadingAntiAliasingMode GetDeferredAntiAliasingMode()
Ogre::uint32 GetVisibilityMask()
void SetSSAOEnable(const bool &value)
void SetHDREffectAmount(const float &value)
void RestoreStereoCamera()
bool IsStereoViewportRegistered()
void ResizeToWindow(const float &w, const float &h)
unsigned int GetNumRenderedBatches()
SRaycastResult RayCast(const int &pixelsX, const int &pixelsY, SSubEntitySelectorBuffer *subEntitySelector)
unsigned int GetNumRenderedFaces()
int GetDeferredDebugMode()
void SetBackgroundColour(const int &backgroundColor)
SWindow * GetParentWindow() const
void UpdateStereoCamera(Ogre::Camera *camera)
const SCompositorMap & GetCompositorList() const
void RemoveCompositor(SCompositor *existingCompositor)
Ogre::Viewport * GetOgreViewPortPointer()
SCompositor * CreateCompositor(const std::string &newCompositorName, const std::string &newSchemeName)
void SetClearDepth(const bool &state)
void SetDeferredAntiAliasingMode(const SDeferredShading::DeferredShadingAntiAliasingMode &value)
void UpdateStereoCameraMatrix(Ogre::Camera *camera)
void SetHDRBlurAmount(const float &value)
std::string GetMaterialScheme()
SSsaoHandler * GetSSAOhandler()
void SetCamera(SCamera *camera)
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
bool GetScreenPosFromWorldPos(Ogre::Vector3 worldPosition, Ogre::Vector2 &screenPos)
void SetHDRGamma(const float &value)
bool UpdateStereoCompositorState(const Ogre::String compname, bool state)
void SetClearColor(const bool &value)
virtual void viewportDimensionsChanged(Ogre::Viewport *viewport)
void DeleteCompositor(SCompositor *existingCompositor)
void RegisterStereoViewport(SViewPort *viewport)
bool UpdateStereoCompositorState(SViewPort *viewport, const Ogre::String compname, bool state)
void UpdateStereoCameraMatrix(SViewPort *viewport, Ogre::Camera *camera)
void UpdateStereoCamera(SViewPort *viewport, Ogre::Camera *camera)
Ogre::RenderWindow * GetOgreRenderWindowPointer()
void RestoreStereoCamera(SViewPort *viewport)
void SynchStereoViewportSetup(SViewPort *viewport, bool overlay=false, bool shadow=false)
SelectorMode GetSelectorMode()
void UnregisterStereoViewport(SViewPort *viewport)
bool IsStereoViewportRegistered(SViewPort *viewport)
unsigned int GetHeight() const
SRaycastResult RayCast(const int &pixelsX, const int &pixelsY)
unsigned int GetWidth() const
void RefreshSelector(const bool &forceRefresh=false)
std::unordered_map< std::string, SCompositor * > SCompositorMap
STBI_EXTERN unsigned long flags