[SOLVED]:Rendering to Ogre texture from an other OpenGL system. Topic is solved

Problems building or running the engine, queries about how to use features etc.
phaO
Gnoblar
Posts: 2
Joined: Mon Aug 26, 2024 11:03 am
x 2

[SOLVED]:Rendering to Ogre texture from an other OpenGL system.

Post by phaO »

Ogre-next Version: 3.0
Operating System: Ubuntu20.04
Render System: GL3Plus

I am currently updating an older project to ogre-next from ogre where we use libmpv which takes a URL video stream and render it to an ogre Opengl texture using the textures fboid.

Previously we could do something like this to get the fboid, which we then used with libmpv mpv_opengl_fbo to let libmpv render to that texture.

Code: Select all

uint32_t id;
auto target = texture->getBuffer()->getRenderTarget();
target->getCustomAttribute("GL_FBOID", &id);

But this does not work anymore. I currently only need it to work with GL3Plus as the render system.
I have tried a couple of things. Getting the texture id with

Code: Select all

 texture->getCustomAttribute(Ogre::TextureGpu::msFinalTextureBuffer, &textureID); 

And then manual creating my own frame buffer

Code: Select all

glGenFramebuffers(1, &m_fbo);

then temporarily binding my texture to that frame buffer with

Code: Select all

glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); 
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureID, 0);

and letting libmpv render to m_fbo.
But the texture does not get rendered to. I do not get any error or warnings while I do this. I have also tried using the frame buffers from GL3PlusTextureGpuManager, but when I try to use them I get included problems with gl3w.

This is how the texture get created.

Code: Select all

m_texture = textureGPUManager->createOrRetrieveTexture(textureName,
                                                    Ogre::GpuPageOutStrategy::Discard,
                                                    Ogre::TextureFlags::RenderToTexture,
                                                    Ogre::TextureTypes::Type2D);

m_texture->setResolution(getWidth(), getHeight());
m_texture->setPixelFormat(Ogre::PFG_RGBA8_UNORM);
m_texture->scheduleTransitionTo(Ogre::GpuResidency::Resident);
m_texture->waitForData();

Any help on how to go about this would be appreciated.

Last edited by phaO on Wed Oct 02, 2024 1:58 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5429
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1337

Re: Rendering to Ogre texture from an other OpenGL system.

Post by dark_sylinc »

I can't see anything wrong with what you posted, but perhaps the problem is not in what you posted; but rather in how you're using that texture later on.

If you're using that texture alone in an Unlit shader, it should work.
But if you're using the texture in a Pbs shader (or using it in an Unlit shader with multiple other textures on top of it), the Pbs shader actually expects a Type2DArray texture instead of Type2D.

This is because most textures are of the type AutomaticBatching, which pretends to have individual Type2D textures; where actually they're all part of a larger Type2DArray, internally.

Which means you would need to do:

Code: Select all

m_texture = textureGPUManager->createOrRetrieveTexture(textureName,
                                                    Ogre::GpuPageOutStrategy::Discard,
                                                    Ogre::TextureFlags::RenderToTexture,
                                                    Ogre::TextureTypes::Type2DArray);

And then:

Code: Select all

// Instead of glFramebufferTexture
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texId, 0, 0 );

If it still doesn't know, then perhaps RenderDoc can shed some answers on when it goes wrong.

phaO
Gnoblar
Posts: 2
Joined: Mon Aug 26, 2024 11:03 am
x 2

Re: Rendering to Ogre texture from an other OpenGL system.

Post by phaO »

dark_sylinc wrote: Sun Sep 22, 2024 11:21 pm

I can't see anything wrong with what you posted, but perhaps the problem is not in what you posted; but rather in how you're using that texture later on.

If you're using that texture alone in an Unlit shader, it should work.
But if you're using the texture in a Pbs shader (or using it in an Unlit shader with multiple other textures on top of it), the Pbs shader actually expects a Type2DArray texture instead of Type2D.

This is because most textures are of the type AutomaticBatching, which pretends to have individual Type2D textures; where actually they're all part of a larger Type2DArray, internally.

Which means you would need to do:

Code: Select all

m_texture = textureGPUManager->createOrRetrieveTexture(textureName,
                                                    Ogre::GpuPageOutStrategy::Discard,
                                                    Ogre::TextureFlags::RenderToTexture,
                                                    Ogre::TextureTypes::Type2DArray);

And then:

Code: Select all

// Instead of glFramebufferTexture
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texId, 0, 0 );

If it still doesn't know, then perhaps RenderDoc can shed some answers on when it goes wrong.

Thanks that was the problem, and it works now.

3David
Gnoblar
Posts: 1
Joined: Thu Sep 16, 2010 12:12 pm
x 1

Re: [SOLVED]:Rendering to Ogre texture from an other OpenGL system.

Post by 3David »

Many thanks dark_sylinc, with your help phaO managed to get it working. 8)

(I don't what happened to phaOs original post though.)