User:Hooray/Foo

From FlightGear wiki
Jump to: navigation, search


$FG_ROOT/Docs/README.multiscreen $FG_SRC/Viewer/CameraGroup.cxx

<?xml version="1.0"?>
<PropertyList>

<camera>
    <name>slaveCam</name>
    <window>FlightGear</window>

    <texture>
        <name>myRTTCam</name>
        <width>640</width>
        <height>480</height>
    </texture>

    <host-name type="string"></host-name>
    <display>0</display>
    <screen>0</screen>
    <shear-x>2</shear-x>
    <shear-y>1</shear-y>
    <width>320</width>
    <height>240</height>
    <fullscreen type="bool">false</fullscreen>
</camera>

</PropertyList>


https://gitorious.org/fg/flightgear/source/4038ba3d511f887f0f166d8f60eed4a322e96e66:src/Viewer/CameraGroup.cxx#L758

TextureMap::iterator itr = _textureTargets.find(texName);
    if (itr == _textureTargets.end()) {
        // error
        return;
    }

http://trac.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00891.html


https://gitorious.org/fg/flightgear/source/4038ba3d511f887f0f166d8f60eed4a322e96e66:src/Viewer/CameraGroup.cxx#L994

const SGPropertyNode* textureNode = cameraNode->getNode("texture");
    if (textureNode) {
        string texName = textureNode->getStringValue("name");
        int tex_width = textureNode->getIntValue("width");
        int tex_height = textureNode->getIntValue("height");
        TextureRectangle* texture = new TextureRectangle;
 
        texture->setTextureSize(tex_width, tex_height);
        texture->setInternalFormat(GL_RGB);
        texture->setFilter(Texture::MIN_FILTER, Texture::LINEAR);
        texture->setFilter(Texture::MAG_FILTER, Texture::LINEAR);
        texture->setWrap(Texture::WRAP_S, Texture::CLAMP_TO_EDGE);
        texture->setWrap(Texture::WRAP_T, Texture::CLAMP_TO_EDGE);
        camera->setDrawBuffer(GL_FRONT);
        camera->setReadBuffer(GL_FRONT);
        camera->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
        camera->attach(Camera::COLOR_BUFFER, texture);
        _textureTargets[texName] = texture;
    } else {
        camera->setDrawBuffer(GL_BACK);
        camera->setReadBuffer(GL_BACK);
    }

https://gitorious.org/fg/flightgear/source/4038ba3d511f887f0f166d8f60eed4a322e96e66:src/Viewer/CameraGroup.cxx#L1018

CameraInfo* info = globals->get_renderer()->buildRenderingPipeline(this, cameraFlags, camera, vOff, pOff,
                                                                        window->gc.get(), useMasterSceneGraph);

https://gitorious.org/fg/flightgear/source/4038ba3d511f887f0f166d8f60eed4a322e96e66:src/Viewer/renderer.cxx#L650

CameraInfo*
FGRenderer::buildClassicalPipeline(CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
                                const osg::Matrix& view,
                                const osg::Matrix& projection,
                                bool useMasterSceneData)
{
    CameraInfo* info = new CameraInfo(flags);
    // The camera group will always update the camera
    camera->setReferenceFrame(Transform::ABSOLUTE_RF);
    info->name = "classic";
    
    Camera* farCamera = 0;
    if ((flags & (CameraGroup::GUI | CameraGroup::ORTHO)) == 0) {
        farCamera = new Camera;
        farCamera->setName("farCamera");
        farCamera->setAllowEventFocus(camera->getAllowEventFocus());
        farCamera->setGraphicsContext(camera->getGraphicsContext());
        farCamera->setCullingMode(camera->getCullingMode());
        farCamera->setInheritanceMask(camera->getInheritanceMask());
        farCamera->setReferenceFrame(Transform::ABSOLUTE_RF);
        // Each camera's viewport is written when the window is
        // resized; if the the viewport isn't copied here, it gets updated
        // twice and ends up with the wrong value.
        farCamera->setViewport(simgear::clone(camera->getViewport()));
        farCamera->setDrawBuffer(camera->getDrawBuffer());
        farCamera->setReadBuffer(camera->getReadBuffer());
        farCamera->setRenderTargetImplementation(
            camera->getRenderTargetImplementation());
        const Camera::BufferAttachmentMap& bufferMap
            = camera->getBufferAttachmentMap();
        if (bufferMap.count(Camera::COLOR_BUFFER) != 0) {
            farCamera->attach(
                Camera::COLOR_BUFFER,
                bufferMap.find(Camera::COLOR_BUFFER)->second._texture.get());
        }
        cgroup->getViewer()->addSlave(farCamera, projection, view, useMasterSceneData);
        installCullVisitor(farCamera);
        int farSlaveIndex = cgroup->getViewer()->getNumSlaves() - 1;
        info->addCamera( FAR_CAMERA, farCamera, farSlaveIndex );
        farCamera->setRenderOrder(Camera::POST_RENDER, farSlaveIndex);
        camera->setCullMask(camera->getCullMask() & ~simgear::BACKGROUND_BIT);
        camera->setClearMask(GL_DEPTH_BUFFER_BIT);
    }
    cgroup->getViewer()->addSlave(camera, projection, view, useMasterSceneData);
    installCullVisitor(camera);
    int slaveIndex = cgroup->getViewer()->getNumSlaves() - 1;
    info->addCamera( MAIN_CAMERA, camera, slaveIndex );
    camera->setRenderOrder(Camera::POST_RENDER, slaveIndex);
    cgroup->addCamera(info);
    return info;
}


// add this slave camera to the viewer, with a shift left of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd());