Add mygui backend by chris

pull/638/head
scrawl 10 years ago
parent 9f12e53956
commit 42d6c6140c

@ -44,7 +44,7 @@ add_openmw_dir (mwgui
itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview
tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog
recharge mode videowidget backgroundimage itemwidget screenfader debugwindow spellmodel spellview
draganddrop timeadvancer jailscreen
draganddrop timeadvancer jailscreen myguiplatform myguirendermanager myguidatamanager
)
add_openmw_dir (mwdialogue
@ -107,6 +107,9 @@ endif(WIN32)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
# for MyGUI platform
find_package(OpenGL REQUIRED)
if (NOT ANDROID)
add_executable(openmw
${OPENMW_FILES}
@ -137,6 +140,7 @@ target_link_libraries(openmw
${MYGUI_LIBRARIES}
${SDL2_LIBRARY}
${MYGUI_PLATFORM_LIBRARIES}
${OPENGL_gl_LIBRARY}
"osg-ffmpeg-videoplayer"
"oics"
components

@ -218,13 +218,6 @@ OMW::Engine::~Engine()
SDL_Quit();
}
// add resources directory
// \note This function works recursively.
void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path)
{
}
void OMW::Engine::enableFSStrict(bool fsStrict)
{
mFSStrict = fsStrict;
@ -309,16 +302,6 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
#endif
}
// This has to be added BEFORE MyGUI is initialized, as it needs
// to find core.xml here.
addResourcesDirectory(mCfgMgr.getCachePath ().string());
addResourcesDirectory(mResDir / "mygui");
addResourcesDirectory(mResDir / "water");
addResourcesDirectory(mResDir / "shadows");
addResourcesDirectory(mResDir / "materials");
//OEngine::Render::WindowSettings windowSettings;
//windowSettings.fullscreen = settings.getBool("fullscreen", "Video");
//windowSettings.window_border = settings.getBool("window border", "Video");
@ -369,9 +352,12 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
//MWInput::InputManager* input = new MWInput::InputManager (*mOgre, *this, keybinderUser, keybinderUserExists, gameControllerdb, mGrab);
//mEnvironment.setInputManager (input);
MWGui::WindowManager* window = new MWGui::WindowManager(
mExtensions, mCfgMgr.getLogPath().string() + std::string("/"),
mCfgMgr.getCachePath ().string(), mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap);
std::string myguiResources = (mResDir / "mygui").string();
osg::ref_ptr<osg::Group> guiRoot = new osg::Group;
rootNode->addChild(guiRoot);
MWGui::WindowManager* window = new MWGui::WindowManager(&mViewer, guiRoot, mResourceSystem->getTextureManager(),
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap);
mEnvironment.setWindowManager (window);
// Create sound system

@ -99,16 +99,10 @@ namespace OMW
bool mScriptBlacklistUse;
bool mNewGame;
//Nif::Cache mNifCache;
// not implemented
Engine (const Engine&);
Engine& operator= (const Engine&);
/// add resources directory
/// \note This function works recursively.
void addResourcesDirectory (const boost::filesystem::path& path);
void executeLocalScripts();
virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt);

@ -53,7 +53,7 @@ namespace MWGui
std::string output = sstream.str();
mVersionText->setCaption(output);
mHasAnimatedMenu = (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup("video\\menu_background.bik"));
mHasAnimatedMenu = 0;//(Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup("video\\menu_background.bik"));
updateMenu();
}

@ -0,0 +1,64 @@
#include "myguidatamanager.hpp"
#include <MyGUI_DataFileStream.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
namespace MWGui
{
void DataManager::setResourcePath(const std::string &path)
{
mResourcePath = path;
}
MyGUI::IDataStream *DataManager::getData(const std::string &name)
{
std::string fullpath = getDataPath(name);
std::auto_ptr<boost::filesystem::ifstream> stream;
stream.reset(new boost::filesystem::ifstream);
stream->open(fullpath, std::ios::binary);
if (stream->fail())
{
std::cerr << "DataManager::getData: Failed to open '" << name << "'" << std::endl;
return NULL;
}
return new MyGUI::DataFileStream(stream.release());
}
void DataManager::freeData(MyGUI::IDataStream *data)
{
delete data;
}
bool DataManager::isDataExist(const std::string &name)
{
std::string fullpath = mResourcePath + "/" + name;
return boost::filesystem::exists(fullpath);
}
const MyGUI::VectorString &DataManager::getDataListNames(const std::string &pattern)
{
// TODO: pattern matching (unused?)
static MyGUI::VectorString strings;
strings.clear();
strings.push_back(getDataPath(pattern));
return strings;
}
const std::string &DataManager::getDataPath(const std::string &name)
{
static std::string result;
result.clear();
if (!isDataExist(name))
{
return result;
}
result = mResourcePath + "/" + name;
return result;
}
}

@ -0,0 +1,50 @@
#ifndef OPENMW_MWGUI_MYGUIDATAMANAGER_H
#define OPENMW_MWGUI_MYGUIDATAMANAGER_H
#include <MyGUI_DataManager.h>
namespace MWGui
{
class DataManager : public MyGUI::DataManager
{
public:
void initialise() {}
void shutdown() {}
void setResourcePath(const std::string& path);
/** Get data stream from specified resource name.
@param _name Resource name (usually file name).
*/
virtual MyGUI::IDataStream* getData(const std::string& _name);
/** Free data stream.
@param _data Data stream.
*/
virtual void freeData(MyGUI::IDataStream* _data);
/** Is data with specified name exist.
@param _name Resource name.
*/
virtual bool isDataExist(const std::string& _name);
/** Get all data names with names that matches pattern.
@param _pattern Pattern to match (for example "*.layout").
*/
virtual const MyGUI::VectorString& getDataListNames(const std::string& _pattern);
/** Get full path to data.
@param _name Resource name.
@return Return full path to specified data.
*/
virtual const std::string& getDataPath(const std::string& _name);
private:
std::string mResourcePath;
};
}
#endif

@ -0,0 +1,2 @@
#include "myguiplatform.hpp"

@ -0,0 +1,74 @@
#ifndef OPENMW_MWGUI_MYGUIPLATFORM_H
#define OPENMW_MWGUI_MYGUIPLATFORM_H
#include "MyGUI_Prerequest.h"
#include "MyGUI_DummyRenderManager.h"
#include "MyGUI_DummyDataManager.h"
#include "MyGUI_DummyDiagnostic.h"
#include "MyGUI_LogManager.h"
#include "myguirendermanager.hpp"
#include "myguidatamanager.hpp"
namespace MWGui
{
class Platform
{
public:
Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager) :
mLogManager(nullptr),
mRenderManager(nullptr),
mDataManager(nullptr)
{
mLogManager = new MyGUI::LogManager();
mRenderManager = new RenderManager(viewer, guiRoot, textureManager);
mDataManager = new DataManager();
}
~Platform()
{
delete mRenderManager;
mRenderManager = nullptr;
delete mDataManager;
mDataManager = nullptr;
delete mLogManager;
mLogManager = nullptr;
}
void initialise(const std::string& resourcePath, const std::string& _logName = MYGUI_PLATFORM_LOG_FILENAME)
{
if (!_logName.empty())
MyGUI::LogManager::getInstance().createDefaultSource(_logName);
mDataManager->setResourcePath(resourcePath);
mRenderManager->initialise();
mDataManager->initialise();
}
void shutdown()
{
//mRenderManager->shutdown();
mDataManager->shutdown();
}
RenderManager* getRenderManagerPtr()
{
return mRenderManager;
}
DataManager* getDataManagerPtr()
{
return mDataManager;
}
private:
RenderManager* mRenderManager;
DataManager* mDataManager;
MyGUI::LogManager* mLogManager;
};
}
#endif

@ -0,0 +1,626 @@
#include "myguirendermanager.hpp"
#include <stdexcept>
#include <MyGUI_Gui.h>
#include <MyGUI_Timer.h>
#include <osg/Drawable>
#include <osg/Geode>
#include <osg/PolygonMode>
#include <osg/BlendFunc>
#include <osg/Depth>
#include <osg/TexEnv>
#include <osg/Texture2D>
#include <osgViewer/Viewer>
#include <osgGA/GUIEventHandler>
#include <components/resource/texturemanager.hpp>
#define MYGUI_PLATFORM_LOG_SECTION "Platform"
#define MYGUI_PLATFORM_LOG(level, text) MYGUI_LOGGING(MYGUI_PLATFORM_LOG_SECTION, level, text)
#define MYGUI_PLATFORM_EXCEPT(dest) do { \
MYGUI_PLATFORM_LOG(Critical, dest); \
MYGUI_DBG_BREAK;\
std::ostringstream stream; \
stream << dest << "\n"; \
MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
} while(0)
#define MYGUI_PLATFORM_ASSERT(exp, dest) do { \
if ( ! (exp) ) \
{ \
MYGUI_PLATFORM_LOG(Critical, dest); \
MYGUI_DBG_BREAK;\
std::ostringstream stream; \
stream << dest << "\n"; \
MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
} \
} while(0)
namespace
{
// Proxy to forward a Drawable's draw call to RenderManager::drawFrame
class Renderable : public osg::Drawable {
MWGui::RenderManager *mParent;
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
{ mParent->drawFrame(renderInfo); }
public:
Renderable(MWGui::RenderManager *parent=nullptr) : mParent(parent) { }
Renderable(const Renderable &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
: osg::Drawable(copy, copyop)
, mParent(copy.mParent)
{ }
META_Object(MWGui, Renderable)
};
// Proxy to forward an OSG resize event to RenderManager::setViewSize
class ResizeHandler : public osgGA::GUIEventHandler {
MWGui::RenderManager *mParent;
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{
if(ea.getEventType() == osgGA::GUIEventAdapter::RESIZE)
{
int width = ea.getWindowWidth();
int height = ea.getWindowHeight();
mParent->setViewSize(width, height);
}
return false;
}
public:
ResizeHandler(MWGui::RenderManager *parent=nullptr) : mParent(parent) { }
ResizeHandler(const ResizeHandler &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
: osg::Object(copy, copyop), osgGA::GUIEventHandler(copy, copyop)
, mParent(copy.mParent)
{ }
META_Object(MWGui, ResizeHandler)
};
}
namespace MWGui
{
class OSGVertexBuffer : public MyGUI::IVertexBuffer
{
osg::ref_ptr<osg::VertexBufferObject> mBuffer;
osg::ref_ptr<osg::Vec3Array> mPositionArray;
osg::ref_ptr<osg::Vec4ubArray> mColorArray;
osg::ref_ptr<osg::Vec2Array> mTexCoordArray;
std::vector<MyGUI::Vertex> mLockedData;
size_t mNeedVertexCount;
public:
OSGVertexBuffer();
virtual ~OSGVertexBuffer();
virtual void setVertexCount(size_t count);
virtual size_t getVertexCount();
virtual MyGUI::Vertex *lock();
virtual void unlock();
/*internal:*/
void destroy();
void create();
osg::VertexBufferObject *getBuffer() const { return mBuffer.get(); }
};
OSGVertexBuffer::OSGVertexBuffer()
: mNeedVertexCount(0)
{
}
OSGVertexBuffer::~OSGVertexBuffer()
{
destroy();
}
void OSGVertexBuffer::setVertexCount(size_t count)
{
if(count == mNeedVertexCount)
return;
mNeedVertexCount = count;
destroy();
create();
}
size_t OSGVertexBuffer::getVertexCount()
{
return mNeedVertexCount;
}
MyGUI::Vertex *OSGVertexBuffer::lock()
{
MYGUI_PLATFORM_ASSERT(mBuffer.valid(), "Vertex buffer is not created");
// NOTE: Unfortunately, MyGUI wants the VBO data to be interleaved as a
// MyGUI::Vertex structure. However, OSG uses non-interleaved elements, so
// we have to give back a "temporary" structure array then copy it to the
// actual VBO arrays on unlock. This is extra unfortunate since the VBO may
// be backed by VRAM, meaning we could have up to 3 copies of the data
// (which we'll need to keep for VBOs that are continually updated).
mLockedData.resize(mNeedVertexCount, MyGUI::Vertex());
return mLockedData.data();
}
void OSGVertexBuffer::unlock()
{
osg::Vec3 *vec = &mPositionArray->front();
for (std::vector<MyGUI::Vertex>::const_iterator it = mLockedData.begin(); it != mLockedData.end(); ++it)
{
const MyGUI::Vertex& elem = *it;
vec->set(elem.x, elem.y, elem.z);
++vec;
}
osg::Vec4ub *clr = &mColorArray->front();
for (std::vector<MyGUI::Vertex>::const_iterator it = mLockedData.begin(); it != mLockedData.end(); ++it)
{
const MyGUI::Vertex& elem = *it;
union {
MyGUI::uint32 ui;
unsigned char ub4[4];
} val = { elem.colour };
clr->set(val.ub4[0], val.ub4[1], val.ub4[2], val.ub4[3]);
++clr;
}
osg::Vec2 *crds = &mTexCoordArray->front();
for (std::vector<MyGUI::Vertex>::const_iterator it = mLockedData.begin(); it != mLockedData.end(); ++it)
{
const MyGUI::Vertex& elem = *it;
crds->set(elem.u, elem.v);
++crds;
}
mBuffer->dirty();
}
void OSGVertexBuffer::destroy()
{
mBuffer = nullptr;
mPositionArray = nullptr;
mColorArray = nullptr;
mTexCoordArray = nullptr;
std::vector<MyGUI::Vertex>().swap(mLockedData);
}
void OSGVertexBuffer::create()
{
MYGUI_PLATFORM_ASSERT(!mBuffer.valid(), "Vertex buffer already exist");
mPositionArray = new osg::Vec3Array(mNeedVertexCount);
mColorArray = new osg::Vec4ubArray(mNeedVertexCount);
mTexCoordArray = new osg::Vec2Array(mNeedVertexCount);
mColorArray->setNormalize(true);
mBuffer = new osg::VertexBufferObject;
mBuffer->setDataVariance(osg::Object::DYNAMIC);
mBuffer->setUsage(GL_STREAM_DRAW);
mBuffer->setArray(0, mPositionArray.get());
mBuffer->setArray(1, mColorArray.get());
mBuffer->setArray(2, mTexCoordArray.get());
}
// ---------------------------------------------------------------------------
class OSGTexture : public MyGUI::ITexture {
std::string mName;
Resource::TextureManager* mTextureManager;
osg::ref_ptr<osg::Image> mLockedImage;
osg::ref_ptr<osg::Texture2D> mTexture;
MyGUI::PixelFormat mFormat;
MyGUI::TextureUsage mUsage;
size_t mNumElemBytes;
public:
OSGTexture(const std::string &name, Resource::TextureManager* textureManager);
virtual ~OSGTexture();
virtual const std::string& getName() const { return mName; }
virtual void createManual(int width, int height, MyGUI::TextureUsage usage, MyGUI::PixelFormat format);
virtual void loadFromFile(const std::string &fname);
virtual void saveToFile(const std::string &fname);
virtual void destroy();
virtual void* lock(MyGUI::TextureUsage access);
virtual void unlock();
virtual bool isLocked();
virtual int getWidth();
virtual int getHeight();
virtual MyGUI::PixelFormat getFormat() { return mFormat; }
virtual MyGUI::TextureUsage getUsage() { return mUsage; }
virtual size_t getNumElemBytes() { return mNumElemBytes; }
virtual MyGUI::IRenderTarget *getRenderTarget();
/*internal:*/
osg::Texture2D *getTexture() const { return mTexture.get(); }
};
OSGTexture::OSGTexture(const std::string &name, Resource::TextureManager* textureManager)
: mName(name)
, mTextureManager(textureManager)
, mFormat(MyGUI::PixelFormat::Unknow)
, mUsage(MyGUI::TextureUsage::Default)
, mNumElemBytes(0)
{
}
OSGTexture::~OSGTexture()
{
}
void OSGTexture::createManual(int width, int height, MyGUI::TextureUsage usage, MyGUI::PixelFormat format)
{
GLenum glfmt = GL_NONE;
size_t numelems = 0;
switch(format.getValue())
{
case MyGUI::PixelFormat::L8:
glfmt = GL_LUMINANCE;
numelems = 1;
break;
case MyGUI::PixelFormat::L8A8:
glfmt = GL_LUMINANCE_ALPHA;
numelems = 2;
break;
case MyGUI::PixelFormat::R8G8B8:
glfmt = GL_RGB;
numelems = 3;
break;
case MyGUI::PixelFormat::R8G8B8A8:
glfmt = GL_RGBA;
numelems = 4;
break;
}
if(glfmt == GL_NONE)
throw std::runtime_error("Texture format not supported");
mTexture = new osg::Texture2D();
mTexture->setTextureSize(width, height);
mTexture->setSourceFormat(glfmt);
mTexture->setSourceType(GL_UNSIGNED_BYTE);
mTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
mTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
mTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
mTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
mFormat = format;
mUsage = usage;
mNumElemBytes = numelems;
}
void OSGTexture::destroy()
{
mTexture = nullptr;
mFormat = MyGUI::PixelFormat::Unknow;
mUsage = MyGUI::TextureUsage::Default;
mNumElemBytes = 0;
}
void OSGTexture::loadFromFile(const std::string &fname)
{
mTexture = mTextureManager->getTexture2D(fname, osg::Texture2D::CLAMP, osg::Texture2D::CLAMP);
// FIXME
mFormat = MyGUI::PixelFormat::R8G8B8;
mUsage = MyGUI::TextureUsage::Static | MyGUI::TextureUsage::Write;
mNumElemBytes = 3; // FIXME
}
void OSGTexture::saveToFile(const std::string &fname)
{
std::cerr << "Would save image to file " << fname << std::endl;
}
int OSGTexture::getWidth()
{
if(!mTexture.valid())
return 0;
osg::Image *image = mTexture->getImage();
if(image) return image->s();
return mTexture->getTextureWidth();
}
int OSGTexture::getHeight()
{
if(!mTexture.valid())
return 0;
osg::Image *image = mTexture->getImage();
if(image) return image->t();
return mTexture->getTextureHeight();
}
void *OSGTexture::lock(MyGUI::TextureUsage /*access*/)
{
MYGUI_PLATFORM_ASSERT(mTexture.valid(), "Texture is not created");
MYGUI_PLATFORM_ASSERT(!mLockedImage.valid(), "Texture already locked");
mLockedImage = mTexture->getImage();
if(!mLockedImage.valid())
{
mLockedImage = new osg::Image();
mLockedImage->allocateImage(
mTexture->getTextureWidth(), mTexture->getTextureHeight(), mTexture->getTextureDepth(),
mTexture->getSourceFormat(), mTexture->getSourceType()
);
}
return mLockedImage->data();
}
void OSGTexture::unlock()
{
MYGUI_PLATFORM_ASSERT(mLockedImage.valid(), "Texture not locked");
// Tell the texture it can get rid of the image for static textures (since
// they aren't expected to update much at all).
mTexture->setImage(mLockedImage.get());
mTexture->setUnRefImageDataAfterApply(mUsage.isValue(MyGUI::TextureUsage::Static) ? true : false);
mTexture->dirtyTextureObject();
mLockedImage = nullptr;
}
bool OSGTexture::isLocked()
{
return mLockedImage.valid();
}
// FIXME: Render-to-texture not currently implemented.
MyGUI::IRenderTarget* OSGTexture::getRenderTarget()
{
return nullptr;
}
// ---------------------------------------------------------------------------
RenderManager::RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::TextureManager* textureManager)
: mViewer(viewer)
, mSceneRoot(sceneroot)
, mTextureManager(textureManager)
, mUpdate(false)
, mIsInitialise(false)
{
}
RenderManager::~RenderManager()
{
MYGUI_PLATFORM_LOG(Info, "* Shutdown: "<<getClassTypeName());
if(mGuiRoot.valid())
mSceneRoot->removeChild(mGuiRoot.get());
mGuiRoot = nullptr;
mSceneRoot = nullptr;
mViewer = nullptr;
destroyAllResources();
MYGUI_PLATFORM_LOG(Info, getClassTypeName()<<" successfully shutdown");
mIsInitialise = false;
}
void RenderManager::initialise()
{
MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName()<<" initialised twice");
MYGUI_PLATFORM_LOG(Info, "* Initialise: "<<getClassTypeName());
mVertexFormat = MyGUI::VertexColourType::ColourABGR;
mUpdate = false;
osg::ref_ptr<osg::Drawable> drawable = new Renderable(this);
drawable->setSupportsDisplayList(false);
drawable->setUseVertexBufferObjects(true);
drawable->setDataVariance(osg::Object::DYNAMIC);
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(drawable.get());
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setProjectionResizePolicy(osg::Camera::FIXED);
camera->setProjectionMatrix(osg::Matrix::identity());
camera->setViewMatrix(osg::Matrix::identity());
camera->setRenderOrder(osg::Camera::POST_RENDER);
camera->setClearMask(GL_NONE);
osg::StateSet *state = new osg::StateSet;
state->setTextureMode(0, GL_TEXTURE_GEN_S, osg::StateAttribute::OFF);
state->setTextureMode(0, GL_TEXTURE_GEN_T, osg::StateAttribute::OFF);
state->setTextureMode(0, GL_TEXTURE_GEN_R, osg::StateAttribute::OFF);
state->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
state->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
state->setMode(GL_LIGHT0, osg::StateAttribute::OFF);
state->setMode(GL_BLEND, osg::StateAttribute::ON);
state->setMode(GL_FOG, osg::StateAttribute::OFF);
state->setTextureAttribute(0, new osg::TexEnv(osg::TexEnv::MODULATE));
state->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT, osg::PolygonMode::FILL));
state->setAttribute(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
state->setRenderBinDetails(11, "RenderBin");
state->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
geode->setStateSet(state);
geode->setCullingActive(false);
camera->addChild(geode.get());
mGuiRoot = camera;
mSceneRoot->addChild(mGuiRoot.get());
mViewer->addEventHandler(new ResizeHandler(this));
osg::ref_ptr<osg::Viewport> vp = mViewer->getCamera()->getViewport();
setViewSize(vp->width(), vp->height());
MYGUI_PLATFORM_LOG(Info, getClassTypeName()<<" successfully initialized");
mIsInitialise = true;
}
MyGUI::IVertexBuffer* RenderManager::createVertexBuffer()
{
return new OSGVertexBuffer();
}
void RenderManager::destroyVertexBuffer(MyGUI::IVertexBuffer *buffer)
{
delete buffer;
}
void RenderManager::begin()
{
osg::State *state = mRenderInfo->getState();
state->disableAllVertexArrays();
}
void RenderManager::doRender(MyGUI::IVertexBuffer *buffer, MyGUI::ITexture *texture, size_t count)
{
osg::State *state = mRenderInfo->getState();
osg::VertexBufferObject *vbo = static_cast<OSGVertexBuffer*>(buffer)->getBuffer();
MYGUI_PLATFORM_ASSERT(vbo, "Vertex buffer is not created");
if(texture)
{
osg::Texture2D *tex = static_cast<OSGTexture*>(texture)->getTexture();
MYGUI_PLATFORM_ASSERT(tex, "Texture is not created");
state->applyTextureAttribute(0, tex);
}
state->setVertexPointer(vbo->getArray(0));
state->setColorPointer(vbo->getArray(1));
state->setTexCoordPointer(0, vbo->getArray(2));
glDrawArrays(GL_TRIANGLES, 0, count);
}
void RenderManager::end()
{
osg::State *state = mRenderInfo->getState();
state->disableTexCoordPointer(0);
state->disableColorPointer();
state->disableVertexPointer();
state->unbindVertexBufferObject();
}
void RenderManager::drawFrame(osg::RenderInfo &renderInfo)
{
MyGUI::Gui *gui = MyGUI::Gui::getInstancePtr();
if(gui == nullptr) return;
mRenderInfo = &renderInfo;
static MyGUI::Timer timer;
static unsigned long last_time = timer.getMilliseconds();
unsigned long now_time = timer.getMilliseconds();
unsigned long time = now_time - last_time;
onFrameEvent((float)((double)(time) / (double)1000));
last_time = now_time;
begin();
onRenderToTarget(this, mUpdate);
end();
mUpdate = false;
}
void RenderManager::setViewSize(int width, int height)
{
if(width < 1) width = 1;
if(height < 1) height = 1;
mGuiRoot->setViewport(0, 0, width, height);
mViewSize.set(width, height);
mInfo.maximumDepth = 1;
mInfo.hOffset = 0;
mInfo.vOffset = 0;
mInfo.aspectCoef = float(mViewSize.height) / float(mViewSize.width);
mInfo.pixScaleX = 1.0f / float(mViewSize.width);
mInfo.pixScaleY = 1.0f / float(mViewSize.height);
std::cout << "setviewsize " << width << " " << height << std::endl;
onResizeView(mViewSize);
mUpdate = true;
}
bool RenderManager::isFormatSupported(MyGUI::PixelFormat /*format*/, MyGUI::TextureUsage /*usage*/)
{
return true;
}
MyGUI::ITexture* RenderManager::createTexture(const std::string &name)
{
MapTexture::const_iterator item = mTextures.find(name);
MYGUI_PLATFORM_ASSERT(item == mTextures.end(), "Texture '"<<name<<"' already exist");
OSGTexture* texture = new OSGTexture(name, mTextureManager);
mTextures.insert(std::make_pair(name, texture));
return texture;
}
void RenderManager::destroyTexture(MyGUI::ITexture *texture)
{
if(texture == nullptr)
return;
MapTexture::iterator item = mTextures.find(texture->getName());
MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '"<<texture->getName()<<"' not found");
mTextures.erase(item);
delete texture;
}
MyGUI::ITexture* RenderManager::getTexture(const std::string &name)
{
MapTexture::const_iterator item = mTextures.find(name);
if(item == mTextures.end())
{
MyGUI::ITexture* tex = createTexture(name);
tex->loadFromFile(name);
return tex;
}
return item->second;
}
void RenderManager::destroyAllResources()
{
for (MapTexture::iterator it = mTextures.begin(); it != mTextures.end(); ++it)
delete it->second;
mTextures.clear();
}
bool RenderManager::checkTexture(MyGUI::ITexture* _texture)
{
for (MapTexture::const_iterator item = mTextures.begin(); item != mTextures.end(); ++item)
{
if (item->second == _texture)
return true;
}
return false;
}
}

@ -0,0 +1,101 @@
#ifndef OPENMW_MWGUI_MYGUIRENDERMANAGER_H
#define OPENMW_MWGUI_MYGUIRENDERMANAGER_H
#include <MyGUI_RenderManager.h>
#include <osg/ref_ptr>
namespace Resource
{
class TextureManager;
}
namespace osgViewer
{
class Viewer;
}
namespace osg
{
class Group;
class Camera;
class RenderInfo;
}
namespace MWGui
{
class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
{
osg::ref_ptr<osgViewer::Viewer> mViewer;
osg::ref_ptr<osg::Group> mSceneRoot;
Resource::TextureManager* mTextureManager;
MyGUI::IntSize mViewSize;
bool mUpdate;
MyGUI::VertexColourType mVertexFormat;
MyGUI::RenderTargetInfo mInfo;
typedef std::map<std::string, MyGUI::ITexture*> MapTexture;
MapTexture mTextures;
bool mIsInitialise;
osg::ref_ptr<osg::Camera> mGuiRoot;
// Only valid during drawFrame()!
osg::RenderInfo *mRenderInfo;
void destroyAllResources();
public:
RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::TextureManager* textureManager);
virtual ~RenderManager();
void initialise();
static RenderManager& getInstance() { return *getInstancePtr(); }
static RenderManager* getInstancePtr()
{ return static_cast<RenderManager*>(MyGUI::RenderManager::getInstancePtr()); }
/** @see RenderManager::getViewSize */
virtual const MyGUI::IntSize& getViewSize() const { return mViewSize; }
/** @see RenderManager::getVertexFormat */
virtual MyGUI::VertexColourType getVertexFormat() { return mVertexFormat; }
/** @see RenderManager::isFormatSupported */
virtual bool isFormatSupported(MyGUI::PixelFormat format, MyGUI::TextureUsage usage);
/** @see RenderManager::createVertexBuffer */
virtual MyGUI::IVertexBuffer* createVertexBuffer();
/** @see RenderManager::destroyVertexBuffer */
virtual void destroyVertexBuffer(MyGUI::IVertexBuffer *buffer);
/** @see RenderManager::createTexture */
virtual MyGUI::ITexture* createTexture(const std::string &name);
/** @see RenderManager::destroyTexture */
virtual void destroyTexture(MyGUI::ITexture* _texture);
/** @see RenderManager::getTexture */
virtual MyGUI::ITexture* getTexture(const std::string &name);
/** @see IRenderTarget::begin */
virtual void begin();
/** @see IRenderTarget::end */
virtual void end();
/** @see IRenderTarget::doRender */
virtual void doRender(MyGUI::IVertexBuffer *buffer, MyGUI::ITexture *texture, size_t count);
/** @see IRenderTarget::getInfo */
virtual const MyGUI::RenderTargetInfo& getInfo() { return mInfo; }
bool checkTexture(MyGUI::ITexture* _texture);
/*internal:*/
void drawFrame(osg::RenderInfo &renderInfo);
void setViewSize(int width, int height);
};
}
#endif

@ -19,8 +19,6 @@
#include <MyGUI_ClipboardManager.h>
#include <MyGUI_RenderManager.h>
#include <MyGUI_DummyPlatform.h>
#include <SDL_keyboard.h>
#include <SDL_clipboard.h>
@ -93,14 +91,16 @@
#include "controllers.hpp"
#include "jailscreen.hpp"
#include "myguiplatform.hpp"
namespace MWGui
{
WindowManager::WindowManager(
const Compiler::Extensions& extensions, const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager
, const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap)
: mConsoleOnlyScripts(consoleOnlyScripts)
//, mGuiManager(NULL)
, mHud(NULL)
, mMap(NULL)
, mMenu(NULL)
@ -173,11 +173,8 @@ namespace MWGui
, mCurrentModals()
, mFallbackMap(fallbackMap)
{
// Set up the GUI system
//mGuiManager = new OEngine::GUI::MyGUIManager(mRendering->getWindow(), mRendering->getScene(), false, logpath);
MyGUI::DummyPlatform* platform = new MyGUI::DummyPlatform;
platform->initialise(logpath);
Platform* platform = new Platform(viewer, guiRoot, textureManager);
platform->initialise(resourcePath, logpath);
MyGUI::Gui* gui = new MyGUI::Gui;
gui->initialise("");
@ -248,7 +245,6 @@ namespace MWGui
void WindowManager::initUI()
{
/*
// Get size info from the Gui object
int w = MyGUI::RenderManager::getInstance().getViewSize().width;
int h = MyGUI::RenderManager::getInstance().getViewSize().height;
@ -304,8 +300,8 @@ namespace MWGui
std::string hitFaderTexture = "textures\\bm_player_hit_01.dds";
// fall back to player_hit_01.dds if bm_player_hit_01.dds is not available
// TODO: check if non-BM versions actually use player_hit_01.dds
if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(hitFaderTexture))
hitFaderTexture = "textures\\player_hit_01.dds";
//if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(hitFaderTexture))
// hitFaderTexture = "textures\\player_hit_01.dds";
mHitFader = new ScreenFader(hitFaderTexture);
mScreenFader = new ScreenFader("black.png");
@ -331,8 +327,7 @@ namespace MWGui
// Set up visibility
updateVisible();
MWBase::Environment::get().getInputManager()->changeInputMode(false);
*/
//MWBase::Environment::get().getInputManager()->changeInputMode(false);
}
void WindowManager::renderWorldMap()
@ -416,8 +411,6 @@ namespace MWGui
//delete mCursorManager;
cleanupGarbage();
//delete mGuiManager;
}
void WindowManager::cleanupGarbage()
@ -928,7 +921,6 @@ namespace MWGui
void WindowManager::changeCell(MWWorld::CellStore* cell)
{
/*
std::string name = MWBase::Environment::get().getWorld()->getCellName (cell);
mMap->setCellName( name );
@ -953,12 +945,10 @@ namespace MWGui
MWBase::Environment::get().getWorld()->getPlayer().setLastKnownExteriorPosition(worldPos);
mMap->setGlobalMapPlayerPosition(worldPos.x, worldPos.y);
}
*/
}
void WindowManager::setActiveMap(int x, int y, bool interior)
{
/*
if (!interior)
{
mMap->setCellPrefix("Cell");
@ -967,22 +957,19 @@ namespace MWGui
mMap->setActiveCell(x,y, interior);
mHud->setActiveCell(x,y, interior);
*/
}
void WindowManager::setPlayerPos(int cellX, int cellY, const float x, const float y)
{
//mMap->setPlayerPos(cellX, cellY, x, y);
//mHud->setPlayerPos(cellX, cellY, x, y);
mMap->setPlayerPos(cellX, cellY, x, y);
mHud->setPlayerPos(cellX, cellY, x, y);
}
void WindowManager::setPlayerDir(const float x, const float y)
{
/*
mMap->setPlayerDir(x,y);
mMap->setGlobalMapPlayerDir(x, y);
mHud->setPlayerDir(x,y);
*/
}
void WindowManager::setDrowningBarVisibility(bool visible)
@ -1098,7 +1085,7 @@ namespace MWGui
void WindowManager::windowResized(int x, int y)
{
sizeVideo(x, y);
//mGuiManager->windowResized();
if (!mHud)
return; // UI not initialized yet
@ -1279,7 +1266,7 @@ namespace MWGui
void WindowManager::executeInConsole (const std::string& path)
{
//mConsole->executeFile (path);
mConsole->executeFile (path);
}
void WindowManager::wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount)
@ -1520,7 +1507,7 @@ namespace MWGui
void WindowManager::updatePlayer()
{
//mInventoryWindow->updatePlayer();
mInventoryWindow->updatePlayer();
const MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
if (player.getClass().getNpcStats(player).isWerewolf())
@ -1808,29 +1795,23 @@ namespace MWGui
void WindowManager::fadeScreenIn(const float time, bool clearQueue)
{
/*
if (clearQueue)
mScreenFader->clearQueue();
mScreenFader->fadeOut(time);
*/
}
void WindowManager::fadeScreenOut(const float time, bool clearQueue)
{
/*
if (clearQueue)
mScreenFader->clearQueue();
mScreenFader->fadeIn(time);
*/
}
void WindowManager::fadeScreenTo(const int percent, const float time, bool clearQueue)
{
/*
if (clearQueue)
mScreenFader->clearQueue();
mScreenFader->fadeTo(percent, time);
*/
}
void WindowManager::setBlindness(const int percent)

@ -52,6 +52,20 @@ namespace OEngine
}
}
namespace osg
{
class Group;
}
namespace osgViewer
{
class Viewer;
}
namespace Resource
{
class TextureManager;
}
namespace SFO
{
class CursorManager;
@ -99,8 +113,8 @@ namespace MWGui
typedef std::pair<std::string, int> Faction;
typedef std::vector<Faction> FactionList;
WindowManager(const Compiler::Extensions& extensions, const std::string& logpath,
const std::string& cacheDir, bool consoleOnlyScripts,
WindowManager(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager,
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap);
virtual ~WindowManager();
@ -364,7 +378,6 @@ namespace MWGui
// Markers placed manually by the player. Must be shared between both map views (the HUD map and the map window).
CustomMarkerCollection mCustomMarkers;
OEngine::GUI::MyGUIManager *mGuiManager;
HUD *mHud;
MapWindow *mMap;
MainMenu *mMenu;

@ -101,9 +101,9 @@ namespace MWRender
mSunLight->setConstantAttenuation(1.f);
lightRoot->addChild(source);
mRootNode->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
mRootNode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
mRootNode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
lightRoot->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
lightRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
lightRoot->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
source->setStateSetModes(*mRootNode->getOrCreateStateSet(), osg::StateAttribute::ON);

@ -1,680 +0,0 @@
#include "manager.hpp"
#include "loglistener.hpp"
#include <MyGUI_Gui.h>
#include <MyGUI_OgrePlatform.h>
#include <MyGUI_Timer.h>
#include <MyGUI_LevelLogFilter.h>
#include <MyGUI_LogSource.h>
#include <MyGUI_ConsoleLogListener.h>
#include <cassert>
#include <extern/shiny/Main/Factory.hpp>
#include <extern/shiny/Platforms/Ogre/OgreMaterial.hpp>
using namespace OEngine::GUI;
namespace MyGUI
{
/*
* As of MyGUI 3.2.0, MyGUI::OgreDataManager::isDataExist is unnecessarily complex
* this override fixes the resulting performance issue.
*/
// Remove for MyGUI 3.2.2
class FixedOgreDataManager : public MyGUI::OgreDataManager
{
public:
bool isDataExist(const std::string& _name)
{
return Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup (_name);
}
};
/*
* As of MyGUI 3.2.0, rendering with shaders is not supported.
* We definitely need this though to run in GL3 core / DX11 at all.
* To make matters worse, subclassing OgreRenderManager doesn't seem to be possible here. :/
*/
class ShaderBasedRenderManager : public RenderManager,
public IRenderTarget,
public Ogre::WindowEventListener,
public Ogre::RenderQueueListener,
public Ogre::RenderSystem::Listener
{
// флаг для обновления всех и вся
bool mUpdate;
IntSize mViewSize;
Ogre::SceneManager* mSceneManager;
VertexColourType mVertexFormat;
// окно, на которое мы подписываемся для изменения размеров
Ogre::RenderWindow* mWindow;
// вьюпорт, с которым работает система
unsigned short mActiveViewport;
Ogre::RenderSystem* mRenderSystem;
Ogre::TextureUnitState::UVWAddressingMode mTextureAddressMode;
Ogre::LayerBlendModeEx mColorBlendMode, mAlphaBlendMode;
RenderTargetInfo mInfo;
typedef std::map<std::string, ITexture*> MapTexture;
MapTexture mTextures;
bool mIsInitialise;
bool mManualRender;
size_t mCountBatch;
// ADDED
Ogre::GpuProgram* mVertexProgramNoTexture;
Ogre::GpuProgram* mVertexProgramOneTexture;
Ogre::GpuProgram* mFragmentProgramNoTexture;
Ogre::GpuProgram* mFragmentProgramOneTexture;
public:
ShaderBasedRenderManager& getInstance()
{
return *getInstancePtr();
}
ShaderBasedRenderManager* getInstancePtr()
{
return static_cast<ShaderBasedRenderManager*>(RenderManager::getInstancePtr());
}
ShaderBasedRenderManager() :
mUpdate(false),
mSceneManager(nullptr),
mWindow(nullptr),
mActiveViewport(0),
mRenderSystem(nullptr),
mIsInitialise(false),
mManualRender(false),
mCountBatch(0),
mVertexProgramNoTexture(NULL),
mFragmentProgramNoTexture(NULL),
mVertexProgramOneTexture(NULL),
mFragmentProgramOneTexture(NULL)
{
mTextureAddressMode.u = Ogre::TextureUnitState::TAM_CLAMP;
mTextureAddressMode.v = Ogre::TextureUnitState::TAM_CLAMP;
mTextureAddressMode.w = Ogre::TextureUnitState::TAM_CLAMP;
}
void initialise(Ogre::RenderWindow* _window, Ogre::SceneManager* _scene)
{
MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());
mColorBlendMode.blendType = Ogre::LBT_COLOUR;
mColorBlendMode.source1 = Ogre::LBS_TEXTURE;
mColorBlendMode.source2 = Ogre::LBS_DIFFUSE;
mColorBlendMode.operation = Ogre::LBX_MODULATE;
mAlphaBlendMode.blendType = Ogre::LBT_ALPHA;
mAlphaBlendMode.source1 = Ogre::LBS_TEXTURE;
mAlphaBlendMode.source2 = Ogre::LBS_DIFFUSE;
mAlphaBlendMode.operation = Ogre::LBX_MODULATE;
mTextureAddressMode.u = Ogre::TextureUnitState::TAM_CLAMP;
mTextureAddressMode.v = Ogre::TextureUnitState::TAM_CLAMP;
mTextureAddressMode.w = Ogre::TextureUnitState::TAM_CLAMP;
mSceneManager = nullptr;
mWindow = nullptr;
mUpdate = false;
mRenderSystem = nullptr;
mActiveViewport = 0;
Ogre::Root* root = Ogre::Root::getSingletonPtr();
if (root != nullptr)
setRenderSystem(root->getRenderSystem());
setRenderWindow(_window);
setSceneManager(_scene);
MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void shutdown()
{
MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());
destroyAllResources();
setSceneManager(nullptr);
setRenderWindow(nullptr);
setRenderSystem(nullptr);
MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void setRenderSystem(Ogre::RenderSystem* _render)
{
// отписываемся
if (mRenderSystem != nullptr)
{
mRenderSystem->removeListener(this);
mRenderSystem = nullptr;
}
mRenderSystem = _render;
// подписываемся на рендер евент
if (mRenderSystem != nullptr)
{
mRenderSystem->addListener(this);
// формат цвета в вершинах
Ogre::VertexElementType vertex_type = mRenderSystem->getColourVertexElementType();
if (vertex_type == Ogre::VET_COLOUR_ARGB)
mVertexFormat = VertexColourType::ColourARGB;
else if (vertex_type == Ogre::VET_COLOUR_ABGR)
mVertexFormat = VertexColourType::ColourABGR;
updateRenderInfo();
}
}
Ogre::RenderSystem* getRenderSystem()
{
return mRenderSystem;
}
void setRenderWindow(Ogre::RenderWindow* _window)
{
// отписываемся
if (mWindow != nullptr)
{
Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
mWindow = nullptr;
}
mWindow = _window;
if (mWindow != nullptr)
{
Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
windowResized(mWindow);
}
}
void setSceneManager(Ogre::SceneManager* _scene)
{
if (nullptr != mSceneManager)
{
mSceneManager->removeRenderQueueListener(this);
mSceneManager = nullptr;
}
mSceneManager = _scene;
if (nullptr != mSceneManager)
{
mSceneManager->addRenderQueueListener(this);
}
}
void setActiveViewport(unsigned short _num)
{
mActiveViewport = _num;
if (mWindow != nullptr)
{
Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
// рассылка обновлений
windowResized(mWindow);
}
}
void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
{
Gui* gui = Gui::getInstancePtr();
if (gui == nullptr)
return;
if (Ogre::RENDER_QUEUE_OVERLAY != queueGroupId)
return;
Ogre::Viewport* viewport = mSceneManager->getCurrentViewport();
if (nullptr == viewport
|| !viewport->getOverlaysEnabled())
return;
if (mWindow->getNumViewports() <= mActiveViewport
|| viewport != mWindow->getViewport(mActiveViewport))
return;
mCountBatch = 0;
static Timer timer;
static unsigned long last_time = timer.getMilliseconds();
unsigned long now_time = timer.getMilliseconds();
unsigned long time = now_time - last_time;
onFrameEvent((float)((double)(time) / (double)1000));
last_time = now_time;
//begin();
setManualRender(true);
onRenderToTarget(this, mUpdate);
//end();
// сбрасываем флаг
mUpdate = false;
}
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation)
{
}
void eventOccurred(const Ogre::String& eventName, const Ogre::NameValuePairList* parameters)
{
if (eventName == "DeviceLost")
{
}
else if (eventName == "DeviceRestored")
{
// обновить всех
mUpdate = true;
}
}
IVertexBuffer* createVertexBuffer()
{
return new OgreVertexBuffer();
}
void destroyVertexBuffer(IVertexBuffer* _buffer)
{
delete _buffer;
}
// для оповещений об изменении окна рендера
void windowResized(Ogre::RenderWindow* _window)
{
if (_window->getNumViewports() > mActiveViewport)
{
Ogre::Viewport* port = _window->getViewport(mActiveViewport);
#if OGRE_VERSION >= MYGUI_DEFINE_VERSION(1, 7, 0) && OGRE_NO_VIEWPORT_ORIENTATIONMODE == 0
Ogre::OrientationMode orient = port->getOrientationMode();
if (orient == Ogre::OR_DEGREE_90 || orient == Ogre::OR_DEGREE_270)
mViewSize.set(port->getActualHeight(), port->getActualWidth());
else
mViewSize.set(port->getActualWidth(), port->getActualHeight());
#else
mViewSize.set(port->getActualWidth(), port->getActualHeight());
#endif
// обновить всех
mUpdate = true;
updateRenderInfo();
onResizeView(mViewSize);
}
}
void updateRenderInfo()
{
if (mRenderSystem != nullptr)
{
mInfo.maximumDepth = mRenderSystem->getMaximumDepthInputValue();
mInfo.hOffset = mRenderSystem->getHorizontalTexelOffset() / float(mViewSize.width);
mInfo.vOffset = mRenderSystem->getVerticalTexelOffset() / float(mViewSize.height);
mInfo.aspectCoef = float(mViewSize.height) / float(mViewSize.width);
mInfo.pixScaleX = 1.0f / float(mViewSize.width);
mInfo.pixScaleY = 1.0f / float(mViewSize.height);
}
}
void initShaders()
{
// ADDED
sh::MaterialInstance* mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/NoTexture");
sh::Factory::getInstance()._ensureMaterial("MyGUI/NoTexture", "Default");
mVertexProgramNoTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
->getVertexProgram()->_getBindingDelegate();
mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/OneTexture");
sh::Factory::getInstance()._ensureMaterial("MyGUI/OneTexture", "Default");
mVertexProgramOneTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
->getVertexProgram()->_getBindingDelegate();
mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/NoTexture");
sh::Factory::getInstance()._ensureMaterial("MyGUI/NoTexture", "Default");
mFragmentProgramNoTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
->getFragmentProgram()->_getBindingDelegate();
mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/OneTexture");
sh::Factory::getInstance()._ensureMaterial("MyGUI/OneTexture", "Default");
mFragmentProgramOneTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
->getFragmentProgram()->_getBindingDelegate();
}
void doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count)
{
if (getManualRender())
{
begin();
setManualRender(false);
}
// ADDED
if (!mVertexProgramNoTexture)
initShaders();
if (_texture)
{
Ogre::Root::getSingleton().getRenderSystem()->bindGpuProgram(mVertexProgramOneTexture);
Ogre::Root::getSingleton().getRenderSystem()->bindGpuProgram(mFragmentProgramOneTexture);
}
else
{
Ogre::Root::getSingleton().getRenderSystem()->bindGpuProgram(mVertexProgramNoTexture);
Ogre::Root::getSingleton().getRenderSystem()->bindGpuProgram(mFragmentProgramNoTexture);
}
if (_texture)
{
OgreTexture* texture = static_cast<OgreTexture*>(_texture);
Ogre::TexturePtr texture_ptr = texture->getOgreTexture();
if (!texture_ptr.isNull())
{
mRenderSystem->_setTexture(0, true, texture_ptr);
mRenderSystem->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_NONE);
}
}
OgreVertexBuffer* buffer = static_cast<OgreVertexBuffer*>(_buffer);
Ogre::RenderOperation* operation = buffer->getRenderOperation();
operation->vertexData->vertexCount = _count;
mRenderSystem->_render(*operation);
++ mCountBatch;
}
void begin()
{
// set-up matrices
mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);
#if OGRE_VERSION >= MYGUI_DEFINE_VERSION(1, 7, 0) && OGRE_NO_VIEWPORT_ORIENTATIONMODE == 0
Ogre::OrientationMode orient = mWindow->getViewport(mActiveViewport)->getOrientationMode();
mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY * Ogre::Quaternion(Ogre::Degree(orient * 90.f), Ogre::Vector3::UNIT_Z));
#else
mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
#endif
// initialise render settings
mRenderSystem->setLightingEnabled(false);
mRenderSystem->_setDepthBufferParams(false, false);
mRenderSystem->_setDepthBias(0, 0);
mRenderSystem->_setCullingMode(Ogre::CULL_NONE);
mRenderSystem->_setFog(Ogre::FOG_NONE);
mRenderSystem->_setColourBufferWriteEnabled(true, true, true, true);
mRenderSystem->unbindGpuProgram(Ogre::GPT_FRAGMENT_PROGRAM);
mRenderSystem->unbindGpuProgram(Ogre::GPT_VERTEX_PROGRAM);
mRenderSystem->setShadingType(Ogre::SO_GOURAUD);
// initialise texture settings
mRenderSystem->_setTextureCoordCalculation(0, Ogre::TEXCALC_NONE);
mRenderSystem->_setTextureCoordSet(0, 0);
mRenderSystem->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_NONE);
mRenderSystem->_setTextureAddressingMode(0, mTextureAddressMode);
mRenderSystem->_setTextureMatrix(0, Ogre::Matrix4::IDENTITY);
#if OGRE_VERSION < MYGUI_DEFINE_VERSION(1, 6, 0)
mRenderSystem->_setAlphaRejectSettings(Ogre::CMPF_ALWAYS_PASS, 0);
#else
mRenderSystem->_setAlphaRejectSettings(Ogre::CMPF_ALWAYS_PASS, 0, false);
#endif
mRenderSystem->_setTextureBlendMode(0, mColorBlendMode);
mRenderSystem->_setTextureBlendMode(0, mAlphaBlendMode);
mRenderSystem->_disableTextureUnitsFrom(1);
// enable alpha blending
mRenderSystem->_setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
// always use wireframe
mRenderSystem->_setPolygonMode(Ogre::PM_SOLID);
}
void end()
{
}
ITexture* createTexture(const std::string& _name)
{
MapTexture::const_iterator item = mTextures.find(_name);
MYGUI_PLATFORM_ASSERT(item == mTextures.end(), "Texture '" << _name << "' already exist");
OgreTexture* texture = new OgreTexture(_name, OgreDataManager::getInstance().getGroup());
mTextures[_name] = texture;
return texture;
}
void destroyTexture(ITexture* _texture)
{
if (_texture == nullptr) return;
MapTexture::iterator item = mTextures.find(_texture->getName());
MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '" << _texture->getName() << "' not found");
mTextures.erase(item);
delete _texture;
}
ITexture* getTexture(const std::string& _name)
{
MapTexture::const_iterator item = mTextures.find(_name);
if (item == mTextures.end())
{
Ogre::TexturePtr texture = (Ogre::TexturePtr)Ogre::TextureManager::getSingleton().getByName(_name);
if (!texture.isNull())
{
ITexture* result = createTexture(_name);
static_cast<OgreTexture*>(result)->setOgreTexture(texture);
return result;
}
return nullptr;
}
return item->second;
}
bool isFormatSupported(PixelFormat _format, TextureUsage _usage)
{
return Ogre::TextureManager::getSingleton().isFormatSupported(
Ogre::TEX_TYPE_2D,
OgreTexture::convertFormat(_format),
OgreTexture::convertUsage(_usage));
}
void destroyAllResources()
{
for (MapTexture::const_iterator item = mTextures.begin(); item != mTextures.end(); ++item)
{
delete item->second;
}
mTextures.clear();
}
#if MYGUI_DEBUG_MODE == 1
bool checkTexture(ITexture* _texture)
{
for (MapTexture::const_iterator item = mTextures.begin(); item != mTextures.end(); ++item)
{
if (item->second == _texture)
return true;
}
return false;
}
#endif
const IntSize& getViewSize() const
{
return mViewSize;
}
VertexColourType getVertexFormat()
{
return mVertexFormat;
}
const RenderTargetInfo& getInfo()
{
return mInfo;
}
size_t getActiveViewport()
{
return mActiveViewport;
}
Ogre::RenderWindow* getRenderWindow()
{
return mWindow;
}
bool getManualRender()
{
return mManualRender;
}
void setManualRender(bool _value)
{
mManualRender = _value;
}
size_t getBatchCount() const
{
return mCountBatch;
}
};
/// \brief Helper class holding data that required during
/// MyGUI log creation
class LogFacility
{
ConsoleLogListener mConsole;
CustomLogListener mFile;
LevelLogFilter mFilter;
LogSource mSource;
public:
LogFacility(const std::string &output, bool console)
: mFile(output)
{
mConsole.setEnabled(console);
mFilter.setLoggingLevel(LogLevel::Info);
mSource.addLogListener(&mFile);
mSource.addLogListener(&mConsole);
mSource.setLogFilter(&mFilter);
mSource.open();
}
LogSource *getSource() { return &mSource; }
};
}
void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging, const std::string& logDir)
{
assert(wnd);
assert(mgr);
mSceneMgr = mgr;
mShaderRenderManager = NULL;
mRenderManager = NULL;
using namespace MyGUI;
// Enable/disable MyGUI logging to stdout. (Logging to MyGUI.log is
// still enabled.) In order to do this we have to initialize the log
// manager before the main gui system itself, otherwise the main
// object will get the chance to spit out a few messages before we
// can able to disable it.
std::string theLogFile = std::string(MYGUI_PLATFORM_LOG_FILENAME);
if(!logDir.empty())
theLogFile.insert(0, logDir);
// Set up OGRE platform (bypassing OgrePlatform). We might make this more generic later.
mLogManager = new LogManager();
if (!Ogre::Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_FIXED_FUNCTION))
mShaderRenderManager = new MyGUI::ShaderBasedRenderManager();
else
mRenderManager = new MyGUI::OgreRenderManager();
mDataManager = new MyGUI::FixedOgreDataManager();
// Do not use default log since it don't support Unicode path on Windows.
// Instead, manually create log source using LogFacility and pass it.
mLogFacility = new MyGUI::LogFacility(theLogFile, logging);
LogManager::getInstance().addLogSource(mLogFacility->getSource());
if (mShaderRenderManager)
mShaderRenderManager->initialise(wnd, mgr);
else
mRenderManager->initialise(wnd, mgr);
mDataManager->initialise("General");
// Create GUI
mGui = new Gui();
mGui->initialise("");
}
void MyGUIManager::windowResized()
{
#ifndef ANDROID
mRenderManager->setActiveViewport(0);
#endif
}
void MyGUIManager::shutdown()
{
mGui->shutdown ();
delete mGui;
if(mRenderManager)
{
mRenderManager->shutdown();
delete mRenderManager;
mRenderManager = NULL;
}
if(mShaderRenderManager)
{
mShaderRenderManager->shutdown();
delete mShaderRenderManager;
mShaderRenderManager = NULL;
}
if(mDataManager)
{
mDataManager->shutdown();
delete mDataManager;
mDataManager = NULL;
}
if (mLogManager)
{
delete mLogManager;
mLogManager = NULL;
}
delete mLogFacility;
mGui = NULL;
}

@ -1,53 +0,0 @@
#ifndef OENGINE_MYGUI_MANAGER_H
#define OENGINE_MYGUI_MANAGER_H
#include <string>
namespace MyGUI
{
class Gui;
class LogManager;
class OgreDataManager;
class OgreRenderManager;
class ShaderBasedRenderManager;
class LogFacility;
}
namespace Ogre
{
class RenderWindow;
class SceneManager;
}
namespace OEngine {
namespace GUI
{
class MyGUIManager
{
MyGUI::Gui *mGui;
MyGUI::LogManager* mLogManager;
MyGUI::LogFacility* mLogFacility;
MyGUI::OgreDataManager* mDataManager;
MyGUI::OgreRenderManager* mRenderManager;
MyGUI::ShaderBasedRenderManager* mShaderRenderManager;
Ogre::SceneManager* mSceneMgr;
public:
MyGUIManager(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false, const std::string& logDir = std::string(""))
{
setup(wnd,mgr,logging, logDir);
}
~MyGUIManager()
{
shutdown();
}
void windowResized();
void setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false, const std::string& logDir = std::string(""));
void shutdown();
};
}
}
#endif
Loading…
Cancel
Save