Today, we just finished the port for librocket. We first upgraded it inside our engine but we decided to then upgrade the example from the wiki found here:
http://www.ogre3d.org/tikiwiki/tiki-ind ... =libRocket
Here is the new Ogre3d 2.1 supporting version which has both working DX11 and OpenGL3+ for librocket. No mobile tests have been made yet.
Download: http://www.chi-ad.com/Downloads/Ogre3D/ ... Rocket.zip ( I would have uploaded it to the forum but it is a bit big lol )
Note: It requires Ogre3d 2.1 most recent build at time of posting, OIS & LibRocket.
Included in the archive is a working demo example that can run in both render systems.
For more interesting read now, these were the rough changes that had to be made.
> I had to use a Custom Compositor Pass Provider that would create a RocketPass which would execute the rendering at the end of the workspace render_window.
> In the workspace compositor_node for rendering, i added a pass that used
Code: Select all
pass custom LibRocket
{
}
> Since Fixed Function no longer exists, shaders took its place with a material. These can be found in the zip archive above.
> The Rendering function inside "RenderInterfaceOgre3D" needed complete reworking to engage. The example calls it "OgreRocket::RenderInterface".
Here is the new code:
Code: Select all
void RenderInterface::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
{
// This function has been edited by Jayce Young and Hannah Young from Aurasoft UK
// It was built for the Skyline Game Engine // http://home.aurasoft-skyline.co.uk
// Edited on 15/03/2016
mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);
// Grab Projection Matrix
Ogre::Matrix4 projection_matrix = getProjectionMatrix();
// Create Transform Matrix for positioning.
Ogre::Matrix4 transform;
transform.makeTrans(translation.x, translation.y, 0);
RocketCompiledGeometry* ogre3d_geometry = (RocketCompiledGeometry*)geometry;
// No more Fixed Function, Shaders are now required! Check media folder for RocketShaders
Ogre::MaterialPtr mMaterial = Ogre::MaterialManager::getSingleton().getByName("Rocket2D");
if (!mMaterial->isLoaded())mMaterial->load();
// Set the pass to the scene manager
//scene.sceneManager->_setPass(mMaterial->getTechnique(0)->getPass(0)); // <<<<< MIGHTNEED!!!!Seems to work without though.
// Set the vertex and fragment program from the material we are loading from.
Ogre::GpuProgramPtr vertexProgram = mMaterial->getTechnique(0)->getPass(0)->getVertexProgram();
Ogre::GpuProgramPtr pixelProgram = mMaterial->getTechnique(0)->getPass(0)->getFragmentProgram();
if (ogre3d_geometry->mTexture != NULL)
{
mRenderSystem->_setTexture(0, true, ogre3d_geometry->mTexture->mTexture.get());
Ogre::HlmsSamplerblock sampler;
sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);
mRenderSystem->_setHlmsSamplerblock(0, &sampler);
mRenderSystem->_disableTextureUnitsFrom(1);
}
else{
// Choose a program that does not require a texture to render and use pure color with instead.
if (mRenderSystem->getName() == "Direct3D11 Rendering Subsystem"){
Ogre::GpuProgramPtr noTexPixelShader = Ogre::GpuProgramManager::getSingleton().getByName("rocket2DFPHLSL_NoTexture");
if (!noTexPixelShader.isNull()){
if (!noTexPixelShader->isLoaded()){ noTexPixelShader->load(); }
pixelProgram = noTexPixelShader;
}
}
else if (mRenderSystem->getName() == "OpenGL 3+ Rendering Subsystem"){
Ogre::GpuProgramPtr noTexPixelShader = Ogre::GpuProgramManager::getSingleton().getByName("rocket2DFPGLSL_NoTexture");
if (!noTexPixelShader.isNull()){
if (!noTexPixelShader->isLoaded()){ noTexPixelShader->load(); }
pixelProgram = noTexPixelShader;
}
}/*else if (mRenderSystem->getName() == "OpenGLSLES......."){ // Put correct render system name into play
Ogre::GpuProgramPtr noTexPixelShader = Ogre::GpuProgramManager::getSingleton().getByName("rocket2DFPGLSLES_NoTexture");
if (!noTexPixelShader.isNull()){
if (!noTexPixelShader->isLoaded()){ noTexPixelShader->load(); }
pixelProgram = noTexPixelShader;
}
}*/
// Finally Disable the texture unit
mRenderSystem->_disableTextureUnit(0);
}
Ogre::HlmsCache hlmsCache;
hlmsCache.vertexShader = vertexProgram;
hlmsCache.pixelShader = pixelProgram;
hlmsCache.type = Ogre::HlmsTypes::HLMS_LOW_LEVEL;
mRenderSystem->_setProgramsFromHlms(&hlmsCache);
// Bind the necessary shader settings to the Vertex Shader to send in the transform matrix information.
Ogre::GpuProgramParametersSharedPtr vsParams = hlmsCache.vertexShader->getDefaultParameters();
vsParams->setNamedConstant("transformMat", projection_matrix * transform);
mRenderSystem->bindGpuProgramParameters(Ogre::GPT_VERTEX_PROGRAM, vsParams, Ogre::GPV_ALL);
// Set the macro and blending information for the HLMS system.
mRenderSystem->_setHlmsMacroblock(mMaterial->getTechnique(0)->getPass(0)->getMacroblock());
mRenderSystem->_setHlmsBlendblock(mMaterial->getTechnique(0)->getPass(0)->getBlendblock());
mRenderSystem->_render(ogre3d_geometry->mRenderOperation);
}
Note: projection matrix creation is handled outside of the RenderInterface as it only needs called once per frame, whereas the render for rocket is called many times over with different transforms.
> Again, a hlms cache is used to handle the generation of shaders and shader parameters.
> This required 2 pixel shaders to work, one for the Texture related passes and another for simple Colour backgrounds. Hence the if statement to switch pixel shader
> There are more changes, but you can see all the code in the archive above.
The only thing that has not been upgraded is the "render_system->setScissorTest" as we haven't come across a librocket document that needs it yet.
If we need them and add them, then we will try to update the archive again.
Q) (Ogre Devs)Do you want to add this to the wiki for keepsakes, it won't be disappearing of our server anytime soon lol
Anyway, Thanks for the great rendering engine and we hope that this feature give back helps someone