Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5200: Introduce WxGLWidgetManager which acts as global GL widget reg…
…istration instance. It will create the shared wxGLContext and send it to the GL context holder.
- Loading branch information
1 parent
cf97407
commit 564f6c3
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "igl.h" | ||
|
||
namespace wxutil { class GLWidget; } | ||
|
||
namespace ui | ||
{ | ||
|
||
// Application wide manager for wxGLWidgets | ||
// All GLWidgets need to register themselves to this module | ||
// since the shared wxGLContext creation will be bound to | ||
// the first registered widget | ||
class IWxGLWidgetManager : | ||
public RegisterableModule | ||
{ | ||
public: | ||
/// Registers a GL widget, storing the shared context if necessary | ||
virtual void registerGLWidget(wxutil::GLWidget* widget) = 0; | ||
|
||
/// Notifies the GL module that a GLWidget has been destroyed | ||
virtual void unregisterGLWidget(wxutil::GLWidget* widget) = 0; | ||
}; | ||
|
||
} | ||
|
||
const char* const MODULE_WXGLWIDGET_MANAGER("wxGLWidgetManager"); | ||
|
||
inline ui::IWxGLWidgetManager& GlobalWxGlWidgetManager() | ||
{ | ||
// Cache the reference locally | ||
static ui::IWxGLWidgetManager& _instance( | ||
*std::static_pointer_cast<ui::IWxGLWidgetManager>( | ||
module::GlobalModuleRegistry().getModule(MODULE_WXGLWIDGET_MANAGER) | ||
) | ||
); | ||
return _instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "WxGLWidgetManager.h" | ||
|
||
#include "module/StaticModule.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
void WxGLWidgetManager::registerGLWidget(wxutil::GLWidget* widget) | ||
{ | ||
auto result = _wxGLWidgets.insert(widget); | ||
|
||
if (result.second && _wxGLWidgets.size() == 1) | ||
{ | ||
// TODO | ||
#if 0 | ||
// First non-duplicated widget registered, take this as context holder | ||
_wxSharedContext = new wxGLContext(widget); | ||
|
||
// Create a context | ||
widget->SetCurrent(*_wxSharedContext); | ||
assertNoErrors(); | ||
|
||
_wxContextValid = true; | ||
|
||
sharedContextCreated(); | ||
#endif | ||
} | ||
} | ||
|
||
void WxGLWidgetManager::unregisterGLWidget(wxutil::GLWidget* widget) | ||
{ | ||
assert(_wxGLWidgets.find(widget) != _wxGLWidgets.end()); | ||
|
||
_wxGLWidgets.erase(widget); | ||
|
||
if (_wxGLWidgets.empty()) | ||
{ | ||
#if 0 | ||
// This is the last active GL widget | ||
_wxContextValid = false; | ||
|
||
sharedContextDestroyed(); | ||
|
||
delete _wxSharedContext; | ||
_wxSharedContext = NULL; | ||
#endif | ||
} | ||
} | ||
|
||
const std::string& WxGLWidgetManager::getName() const | ||
{ | ||
static std::string _name(MODULE_WXGLWIDGET_MANAGER); | ||
return _name; | ||
} | ||
|
||
const StringSet& WxGLWidgetManager::getDependencies() const | ||
{ | ||
static StringSet _dependencies; | ||
return _dependencies; | ||
} | ||
|
||
void WxGLWidgetManager::initialiseModule(const IApplicationContext& ctx) | ||
{ | ||
rMessage() << getName() << "::initialiseModule called." << std::endl; | ||
} | ||
|
||
void WxGLWidgetManager::shutdownModule() | ||
{ | ||
_wxGLWidgets.clear(); | ||
} | ||
|
||
module::StaticModule<WxGLWidgetManager> wxGLWidgetManagerModule; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <set> | ||
#include "iwxgl.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
class WxGLWidgetManager : | ||
public IWxGLWidgetManager | ||
{ | ||
private: | ||
std::set<wxutil::GLWidget*> _wxGLWidgets; | ||
|
||
public: | ||
void registerGLWidget(wxutil::GLWidget* widget) override; | ||
void unregisterGLWidget(wxutil::GLWidget* widget) override; | ||
|
||
// RegisterableModule implementation | ||
const std::string& getName() const override; | ||
const StringSet& getDependencies() const override; | ||
void initialiseModule(const IApplicationContext& ctx) override; | ||
void shutdownModule() override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters