|
|
@ -14,6 +14,7 @@
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/resource/imagemanager.hpp>
|
|
|
|
#include <components/resource/imagemanager.hpp>
|
|
|
|
|
|
|
|
#include <components/shader/shadermanager.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
|
|
|
|
|
|
@ -127,9 +128,13 @@ public:
|
|
|
|
state->apply();
|
|
|
|
state->apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A GUI element without an associated texture would be extremely rare.
|
|
|
|
|
|
|
|
// It is worth it to use a dummy 1x1 black texture sampler instead of either adding a conditional or relinking shaders.
|
|
|
|
osg::Texture2D* texture = batch.mTexture;
|
|
|
|
osg::Texture2D* texture = batch.mTexture;
|
|
|
|
if(texture)
|
|
|
|
if(texture)
|
|
|
|
state->applyTextureAttribute(0, texture);
|
|
|
|
state->applyTextureAttribute(0, texture);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
state->applyTextureAttribute(0, mDummyTexture);
|
|
|
|
|
|
|
|
|
|
|
|
osg::GLBufferObject* bufferobject = state->isVertexBufferObjectSupported() ? vbo->getOrCreateGLBufferObject(state->getContextID()) : nullptr;
|
|
|
|
osg::GLBufferObject* bufferobject = state->isVertexBufferObjectSupported() ? vbo->getOrCreateGLBufferObject(state->getContextID()) : nullptr;
|
|
|
|
if (bufferobject)
|
|
|
|
if (bufferobject)
|
|
|
@ -189,6 +194,10 @@ public:
|
|
|
|
mStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
|
|
|
|
mStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
|
|
|
|
mStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
|
|
|
|
mStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDummyTexture = new osg::Texture2D;
|
|
|
|
|
|
|
|
mDummyTexture->setInternalFormat(GL_RGB);
|
|
|
|
|
|
|
|
mDummyTexture->setTextureSize(1,1);
|
|
|
|
|
|
|
|
|
|
|
|
// need to flip tex coords since MyGUI uses DirectX convention of top left image origin
|
|
|
|
// need to flip tex coords since MyGUI uses DirectX convention of top left image origin
|
|
|
|
osg::Matrix flipMat;
|
|
|
|
osg::Matrix flipMat;
|
|
|
|
flipMat.preMultTranslate(osg::Vec3f(0,1,0));
|
|
|
|
flipMat.preMultTranslate(osg::Vec3f(0,1,0));
|
|
|
@ -201,6 +210,7 @@ public:
|
|
|
|
, mStateSet(copy.mStateSet)
|
|
|
|
, mStateSet(copy.mStateSet)
|
|
|
|
, mWriteTo(0)
|
|
|
|
, mWriteTo(0)
|
|
|
|
, mReadFrom(0)
|
|
|
|
, mReadFrom(0)
|
|
|
|
|
|
|
|
, mDummyTexture(copy.mDummyTexture)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -231,6 +241,11 @@ public:
|
|
|
|
mBatchVector[mWriteTo].clear();
|
|
|
|
mBatchVector[mWriteTo].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::StateSet* getDrawableStateSet()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return mStateSet;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
META_Object(osgMyGUI, Drawable)
|
|
|
|
META_Object(osgMyGUI, Drawable)
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
@ -242,6 +257,8 @@ private:
|
|
|
|
|
|
|
|
|
|
|
|
int mWriteTo;
|
|
|
|
int mWriteTo;
|
|
|
|
mutable int mReadFrom;
|
|
|
|
mutable int mReadFrom;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> mDummyTexture;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OSGVertexBuffer : public MyGUI::IVertexBuffer
|
|
|
|
class OSGVertexBuffer : public MyGUI::IVertexBuffer
|
|
|
@ -417,6 +434,16 @@ void RenderManager::shutdown()
|
|
|
|
mSceneRoot->removeChild(mGuiRoot);
|
|
|
|
mSceneRoot->removeChild(mGuiRoot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RenderManager::enableShaders(Shader::ShaderManager& shaderManager)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto vertexShader = shaderManager.getShader("gui_vertex.glsl", {}, osg::Shader::VERTEX);
|
|
|
|
|
|
|
|
auto fragmentShader = shaderManager.getShader("gui_fragment.glsl", {}, osg::Shader::FRAGMENT);
|
|
|
|
|
|
|
|
auto program = shaderManager.getProgram(vertexShader, fragmentShader);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDrawable->getDrawableStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
mDrawable->getDrawableStateSet()->addUniform(new osg::Uniform("diffuseMap", 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MyGUI::IVertexBuffer* RenderManager::createVertexBuffer()
|
|
|
|
MyGUI::IVertexBuffer* RenderManager::createVertexBuffer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new OSGVertexBuffer();
|
|
|
|
return new OSGVertexBuffer();
|
|
|
|