Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3033

Merged
merged 11 commits into from
Feb 17, 2024
10 changes: 10 additions & 0 deletions Components/Bites/include/OgreApplicationContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern "C" struct SDL_Window;

namespace Ogre {
class OverlaySystem;
class ImGuiOverlay;
}

#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
Expand Down Expand Up @@ -283,6 +284,13 @@ namespace OgreBites
* same as OGRE_MEDIA_DIR in CMake
*/
static Ogre::String getDefaultMediaDir();

/**
* Set up the overlay system for usage with ImGui
*/
Ogre::ImGuiOverlay* initialiseImGui();

InputListener* getImGuiInputListener() const { return mImGuiListener.get(); }
protected:
/// internal method to destroy both the render and the native window
virtual void _destroyWindow(const NativeWindowPair& win);
Expand All @@ -302,6 +310,8 @@ namespace OgreBites
typedef std::set<std::pair<uint32_t, InputListener*> > InputListenerList;
InputListenerList mInputListeners;

std::unique_ptr<InputListener> mImGuiListener;

#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
Ogre::RTShader::ShaderGenerator* mShaderGenerator; // The Shader generator instance.
SGTechniqueResolverListener* mMaterialMgrListener; // Shader generator material manager listener.
Expand Down
8 changes: 8 additions & 0 deletions Components/Bites/include/OgreInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,20 @@ class _OgreBitesExport InputListenerChain : public InputListener
InputListenerChain() {}
InputListenerChain(std::vector<InputListener*> chain) : mListenerChain(chain) {}

bool empty() const { return mListenerChain.empty(); }

InputListenerChain& operator=(const InputListenerChain& o)
{
mListenerChain = o.mListenerChain;
return *this;
}

void frameRendered(const Ogre::FrameEvent& evt) override
{
for (auto listener : mListenerChain)
listener->frameRendered(evt);
}

bool keyPressed(const KeyboardEvent& evt) override
{
for (auto listner : mListenerChain)
Expand Down
20 changes: 20 additions & 0 deletions Components/Bites/src/OgreApplicationContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "OgreApplicationContextBase.h"

#include "OgreImGuiOverlay.h"
#include "OgreOverlayManager.h"
#include "OgreImGuiInputListener.h"
#include "OgreRoot.h"
#include "OgreGpuProgramManager.h"
#include "OgreConfigFile.h"
Expand Down Expand Up @@ -495,6 +498,23 @@ void ApplicationContextBase::loadResources()
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

Ogre::ImGuiOverlay* ApplicationContextBase::initialiseImGui()
{
if(auto overlay = Ogre::OverlayManager::getSingleton().getByName("ImGuiOverlay"))
return static_cast<Ogre::ImGuiOverlay*>(overlay);

auto imguiOverlay = new Ogre::ImGuiOverlay();
Ogre::OverlayManager::getSingleton().addOverlay(imguiOverlay); // now owned by overlaymgr

// handle DPI scaling
float vpScale = Ogre::OverlayManager::getSingleton().getPixelRatio();
ImGui::GetStyle().ScaleAllSizes(vpScale);

mImGuiListener.reset(new ImGuiInputListener());

return imguiOverlay;
}

void ApplicationContextBase::reconfigure(const Ogre::String &renderer, Ogre::NameValuePairList &options)
{
mNextRenderer = renderer;
Expand Down
7 changes: 7 additions & 0 deletions Components/Overlay/include/OgreImGuiOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

namespace Ogre
{
/** Draws a renderer configuration menu using ImGui
*
* Wrap this in a Begin() and End() call to draw the dialog.
* @param renderSystemName The name of the render system that the user selected
*/
_OgreOverlayExport void RenderingSettings(String& renderSystemName);

///Ogre's integrated support for [Dear ImGui](https://github.com/ocornut/imgui)
class _OgreOverlayExport ImGuiOverlay : public Overlay
{
Expand Down
1 change: 1 addition & 0 deletions Components/Overlay/include/OgreOverlay.i
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ SHARED_PTR(TextAreaOverlayElement);
%include "OgreTextAreaOverlayElement.h"

#ifdef HAVE_IMGUI
%apply Ogre::String* INOUT { Ogre::String& renderSystemName };
%include "OgreImGuiOverlay.h"
#endif
42 changes: 42 additions & 0 deletions Components/Overlay/src/OgreImGuiOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,44 @@
namespace Ogre
{

static void DrawConfigOption(RenderSystem* rs, const ConfigOption& opt)
{
if(ImGui::BeginCombo(opt.name.c_str(), opt.currentValue.c_str()))
{
for(const auto& it : opt.possibleValues)
{
if(ImGui::Selectable(it.c_str(), it == opt.currentValue))
rs->setConfigOption(opt.name, it);
}
ImGui::EndCombo();
}
}

void RenderingSettings(String& rsName)
{
auto root = Root::getSingletonPtr();
OgreAssert(root, "Root must be created");

if(rsName.empty())
rsName = root->getRenderSystem()->getName();

if(ImGui::BeginCombo("Render System", rsName.c_str()))
{
for(const auto& it : root->getAvailableRenderers())
{
if(ImGui::Selectable(it->getName().c_str(), it->getName() == rsName))
rsName = it->getName();
}
ImGui::EndCombo();
}

ImGui::SeparatorText("Options");

auto rs = root->getRenderSystemByName(rsName);
for(const auto& it : rs->getConfigOptions())
DrawConfigOption(rs, it.second);
}

ImGuiOverlay::ImGuiOverlay() : Overlay("ImGuiOverlay")
{
ImGui::CreateContext();
Expand Down Expand Up @@ -296,6 +334,10 @@ void ImGuiOverlay::ImGUIRenderable::initialise(void)
//-----------------------------------------------------------------------------------
ImGuiOverlay::ImGUIRenderable::~ImGUIRenderable()
{
if(mFontTex)
TextureManager::getSingleton().remove(mFontTex);
if(mMaterial)
MaterialManager::getSingleton().remove(mMaterial);
OGRE_DELETE mRenderOp.vertexData;
OGRE_DELETE mRenderOp.indexData;
}
Expand Down
6 changes: 6 additions & 0 deletions OgreMain/src/OgreResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ namespace Ogre {
{
OgreAssert(res, "attempting to remove nullptr");

#if OGRE_RESOURCEMANAGER_STRICT
if (res->getCreator() != this)
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Resource '" + res->getName() + "' was not created by the '" +
getResourceType() + "' ResourceManager");
#endif

OGRE_LOCK_AUTO_MUTEX;

if(ResourceGroupManager::getSingleton().isResourceGroupInGlobalPool(res->getGroup()))
Expand Down
Loading
Loading