Ogre 3d: RenderTexture bigger than RenderWindow

雨燕双飞 提交于 2019-12-22 12:23:36

问题


I have two ogre applications:

1) Sub application, that render to a window and to a texture (using same camera). The texture is "exported" to shared memory (shm in linux)

2) Main application, where a plane shows what is happening in the (1) "sub application", loading the texture from shared memory.

The texture where (1) renders has same size than texture used by plane in (2). E.g.: 512x512

All works fine if the RenderWindow is bigger or equal than RenderTexture. What you see in (1) is reflected in (2) plane with decent fps. Shared memory is powerful!

But if render window is smaller than texture, only a part of texture is updated.

This is what is happening to me:

Some examples show 1x1 window and big render texture, so i guess it's possible to have a render texture bigger than the window.

This is how the window is created:

window_ = root_->createRenderWindow("blablah"), 256, 256, false);

This is how the render texture is created:

TextureManager* tm = TextureManager::getSingletonPtr();
TexturePtr rttTexture = tm->createManual(
/**/"MainRTT"
/**/, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
/**/, TEX_TYPE_2D
/**/, 512
/**/, 512
/**/, 0
/**/, PF_R8G8B8A8
/**/, TU_RENDERTARGET);
RenderTexture* renderTarget = rttTexture->getBuffer()->getRenderTarget();
renderTarget->addViewport(camera_);
renderTarget->setAutoUpdated(false);
Viewport* vp = renderTarget->getViewport(0);
vp->setClearEveryFrame(true);
vp->setOverlaysEnabled(true);
vp->setBackgroundColour(ColourValue::Black);

This is how i update the render texture:

class ShmTexUpdater: public Ogre::FrameListener {
public:
    ShmTexUpdater(const int& width, const int& height, void* data,
            const TexturePtr& tex) :
        /**/width_(width)
        /**/, height_(height)
        /**/, data_(data)
        /**/, tex_(tex)
        /**/, buf_(tex->getBuffer())
        /**/, renderTarget_(tex->getBuffer()->getRenderTarget()){

    }
    virtual ~ShmTexUpdater() {

    }
private:
    virtual bool frameStarted(const FrameEvent& evt) {
        FrameWork::instance()->window()->update();
        buf_->lock(Ogre::HardwareBuffer::HBL_NORMAL);
        renderTarget_->update();
        tex_->getBuffer()->blitToMemory(
        /**/PixelBox(width_, height_, 1, ShmTexture4k::FORMAT, data_));
        buf_->unlock();
        return true;
    }
    int const width_;
    int const height_;
    void* const data_;
    TexturePtr const tex_;
    HardwarePixelBufferSharedPtr buf_;
    RenderTexture* renderTarget_;
};

Reading description of RenderWindow and RenderTexture, this is not what I'm expecting to happen. So... is this ogre bug, or opengl? Or am I doing it wrong?

  • OS: Linux
  • Ogre: Version 1.7.3 (Cthugha)
  • GL_VERSION = 4.0.0 NVIDIA 256.53

回答1:


I'm not sure if it's much of help (and probably too late) but some time ago I've read that OpenGL can't render to texture that is bigger than window it's using. DX is capable of doing this, but not OGL.

BTW Sorry it's answer and not comment, but I can't write comments yet ;]




回答2:


If the target change in size, your camera needs to be updated : http://www.ogre3d.org/docs/api/html/classOgre_1_1Viewport.html#a23c2b69bbc3d76fd52a4729a71caed08

A call to _updateDimensions() should fix it




回答3:


But if render window is smaller than texture, only a part of texture is updated.

Exactly this is to be expected and indeed the correct behaviour. Pixels of regular on-screen windows are only processed if they pass the so called pixel ownership test. What this means is, that only those pixels that will be visible to the user will be rendered at all. So if for example you drag a window in front of your OpenGL window, those pixels will not be rendered to either; on modern systems so called compositing window management is used, where obstruction by window will not fail the pixel ownership test.

To make a long story short: If you're rendering stuff for later processing you must do it on a framebuffer fully under your control: A PBuffer or a Frame Buffer Object.



来源:https://stackoverflow.com/questions/7930306/ogre-3d-rendertexture-bigger-than-renderwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!