Regarding your questions, from the way I've implemented in Farso, which is very different, as far as I seen, from the way it is implemented in MyGui:
mrmclovin wrote:
Are there any scene nodes involved?
Yes. On Farso each 'root' widget (without parents) is associated to a renderer. The renderer is defined by its own Renderable and Movable, which are associated to a SceneNode to be visible.
mrmclovin wrote:
Are vertex buffers etc. necessary even though it's 2D only?
Yes. In fact, to render anything you always need to define its vertices. In Farso, as it uses a Ogre::Renderable implementation, each one needs its own VertexArrayObject (for 2D they'll be very simple... you could check
OgreWidgetRenderable::createVAO() for that). Also, for 2D render, the renderable must be set to use the Identity Matrix:
Code: Select all
bool getUseIdentityWorldMatrix(void) const { return true; };
mrmclovin wrote:
At what stage do you define the screen position where the texture should end up?
Not sure if it is the best to do, but I direct define it on the VAO, and let the SceneNode just be at (0.0f, 0.0f, 0.0f). (maybe I should use the scene node for setting the position instead... need to recheck this part... it was implemented as 'make it work, check it latter' approach).
mrmclovin wrote:
Where does Hlms Unlit fit into the picture?
At the WidgetRenderer, I set its renderable to use the respective datablock. The widget, when dirty, is rendered to a Surface (I use a SDL surface for that, so, working on CPU/RAM side) and them blited to the related Ogre::Texture (GPU side).
The relevant parts:
The Ogre texture is manually created with (only once):
Code: Select all
this->texture = Ogre::TextureManager::getSingleton().createManual(
name,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, realWidth, realHeight, 0, Ogre::PF_A8R8G8B8,
Ogre::TU_DYNAMIC_WRITE_ONLY);
The Texture is assigned to the datablock with (only once):
Code: Select all
/* Using Ogre's Unlit HLMS */
Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingleton().getHlmsManager();
Ogre::HlmsUnlit* hlmsUnlit = static_cast<Ogre::HlmsUnlit*>(
hlmsManager->getHlms(Ogre::HLMS_UNLIT));
/* Macroblock with depth write, depth check and culling disabled */
Ogre::HlmsMacroblock macroBlock;
macroBlock.mDepthCheck = false;
macroBlock.mDepthWrite = false;
macroBlock.mCullMode = Ogre::CULL_NONE;
Ogre::HlmsBlendblock blendBlock;
blendBlock.mDestBlendFactor = Ogre::SBF_ONE_MINUS_SOURCE_ALPHA;
/* Let's create and define our datablock */
datablock = static_cast<Ogre::HlmsUnlitDatablock*>(
hlmsUnlit->createDatablock(name, name,
macroBlock, blendBlock, Ogre::HlmsParamVec()));
datablock->setTexture(Ogre::PBSM_DIFFUSE, 0, texture);
The SDL Surface is blited to the Ogre::Texture (only when the widget is dirty) with:
Code: Select all
void OgreWidgetRenderer::uploadSurface()
{
/* The idea here is similar to the OpenGL implementation: we just update
* the texture with the contents of the rendering surface (represented
* by its PixelBox bellow). */
OgreSurface* ogreSurface = static_cast<OgreSurface*>(surface);
ogreSurface->lock();
texture->getBuffer()->blitFromMemory(pixelBox);
ogreSurface->unlock();
}
The PixelBox is simple:
Code: Select all
pixelBox = Ogre::PixelBox(width, height, 1, Ogre::PF_A8B8G8R8, ogreSurface->getSurface()->pixels);
Being ogreSurface->getSurface() a pointer to the SDLSurface.
mrmclovin wrote:
I'm currently investigating whether it's possible to render SDL2 Textures (which has been drawn onto by Cairo graphics) with Ogre.
Probably is. But, as SDL2 Textures are defined to the better system SDL wants (for example, could be an OpenGL texture, but could also be an DirectX one, which will be a problem for you if you are at windows using, for example, Ogre's OpenGL Renderer and the SDL texture was created as a DirectX one). Using SDL Surface is easier, and, as they are on memory and not on GPU as SDL Textures, cheaper to access its contents if you need to change something before sending it to the GPU.
Not sure if I'm clear, if not, feel free to ask what is confusing and I'll try to explain better.