void DepthPeelingStage::postProcess(DrawEnv *pEnv, bool isPing)
{
    Window *win = pEnv->getWindow();

    if(win->hasExtOrVersion(_uiFramebufferObjectExt, 0x0300, 0x0200) == false)
    {
        FNOTICE(("Framebuffer objects not supported on Window %p!\n", win));
        return;
    }

    DepthPeelingStageData *pData =
        pEnv->getData<DepthPeelingStageData *>(_iDataSlotId);

    if(!pData)
        return;

    FrameBufferObject *pBlendFBO  = pData->getBlendFBO();
    pBlendFBO->activate(pEnv);

    ChunkMaterial *pMaterial;
    if (isPing)
        pMaterial = pData->getPeelPingMaterial();
    else
        pMaterial = pData->getPeelPongMaterial();

    pEnv->activateState(pMaterial->getState(), NULL);

    drawQuad();

    pEnv->deactivateState();

    pBlendFBO->deactivate(pEnv);
}
Action::ResultE MaterialDrawable::renderActionEnterHandler(Action *action)
{
    RenderAction  *a = dynamic_cast<RenderAction *>(action);

    Material      *m         = a->getMaterial();
    PrimeMaterial *pPrimeMat = NULL;

    if(m == NULL)
    {
        if(this->getMaterial() != NULL)
        {
            pPrimeMat =
                this->getMaterial()->finalize(a->getRenderProperties(),
                                              a->getWindow()          );
        }
    }
    else
    {
        pPrimeMat = m->finalize(a->getRenderProperties(),
                                a->getWindow          ());
    }

    if(pPrimeMat == NULL)
    {
        pPrimeMat = getDefaultMaterial();

        FNOTICE(("MaterialDrawable::render: no Material!?!\n"));
    }

    UInt32 uiNPasses = pPrimeMat->getNPasses();

    for(UInt32 uiPass = 0; uiPass < uiNPasses; ++uiPass)
    {
        State *st = pPrimeMat->getState(uiPass);

        if(st != NULL)
        {
            a->dropFunctor(_drawFunc,
                           st,
                           pPrimeMat->getSortKey() + uiPass);
        }
        else
        {
            FINFO(("%s: Material %p has NULL state for pass %d\n",
                   OSG_FUNCNAME_MACRO, pPrimeMat, uiPass));
        }
    }

    if(a->pushVisibility())
    {
        if(a->selectVisibles() == 0)
        {
            a->popVisibility();
            return Action::Skip;
        }
    }

    return Action::Continue;
}
Пример #3
0
void PostShaderStage::postProcess(DrawEnv *pEnv)
{
    Window *win = pEnv->getWindow();

    if(win->hasExtension(_uiFramebuffer_object_extension) == false ||
       win->hasExtension(_extDepthTexture     ) == false)
    {
        FNOTICE(("Framebuffer objects not supported on Window %p!\n", win));
        return;        
    }

    GLDrawBuffersEXTProcT glDrawBuffersEXTProc =
        reinterpret_cast<GLDrawBuffersEXTProcT>(
            win->getFunction(_uiFuncDrawBuffers));

    glColor3f(1.f, 1.f, 1.f);
    
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    glLoadIdentity();

    PostShaderStageData *pData = pEnv->getData<PostShaderStageData *>(_iDataSlotId);

    if(pData == NULL)
    {
        return;
    }

    if((pData->getWidth () != pEnv->getPixelWidth() ) ||
       (pData->getHeight() != pEnv->getPixelHeight())  )
    {
        resizeStageData(pData, 
                        pEnv->getPixelWidth(),
                        pEnv->getPixelHeight());
    }

    // PostShader pass
    glDisable(GL_DEPTH_TEST);

    //Render each pass
    for(RenderPassVector::iterator PassItor(_PostProcessPasses.begin()) ;
        PassItor != _PostProcessPasses.end() ;
        ++PassItor)
    {
        (*PassItor)->draw(pEnv, pData);
    }

    glEnable(GL_DEPTH_TEST);

    pEnv->deactivateState();

    glPopMatrix();
}
void DrawableStatsAttachment::attachTo(AttachmentContainer *obj)
{
    if(getMFParents()->size())
    {
        FNOTICE(("GeoStatsAttachment::attachTo: "
                 "already attached, detaching!\n"));

        while(getMFParents()->size())
        {
            AttachmentContainer *p =
                dynamic_cast<AttachmentContainer *>(this->getParents(0));

            p->subChangedFunctor(&DrawableStatsAttachment::invalidateFunctor);
            p->subAttachment    (this                                       );
        }
    }

    obj->addAttachment(this);

    reset();

    obj->addChangedFunctor(&DrawableStatsAttachment::invalidateFunctor,
                           "DrawableStats invalidator");
}
Пример #5
0
void TreeRenderer::initialize(Window *win)
{
    if(!_initDone)
    {
        // without this the registered extensions are not valid yet!
        win->frameInit();

        //check support for ShadowExtension
        if(!win->hasExtension(_depth_texture_extension))
        {
            SWARNING <<
                "No ARB_depth_texture-Extension available! All shadow modes disabled." << endLog;
            _useShadowExt = false;
        }
        else if(!win->hasExtension(_shadow_extension))
        {
            SWARNING <<
                "No ARB_shadow-Extension available! All shadow modes disabled."
                << endLog;
            _useShadowExt = false;
        }

        //check support for framebuffer objects
        _useFBO = _shadowVP->getFboOn();

        if(!win->hasExtension("GL_EXT_framebuffer_object"))
            _useFBO = false;

        if(_useFBO)
        {
            FNOTICE(("framebuffer objects supported.\n"));
        }
        else
        {
            FNOTICE(
                (
                "framebuffer objects not supported, try new video drivers. Some shadow modes will be disabled.\n"));
        }

        //check support for non-power-of-two textures
        _useNPOTTextures = true;

        if(!win->hasExtension("GL_ARB_texture_non_power_of_two"))
            _useNPOTTextures = false;

        if(_useNPOTTextures)
        {
            FNOTICE(("texture_non_power_of_two supported.\n"));
        }
        else
        {
            FNOTICE(("texture_non_power_of_two not supported by hardware.\n"));
        }

        //check if GLSL is available
        _useGLSL = true;
        if(!win->hasExtension("GL_ARB_shading_language_100") ||
           !win->hasExtension("GL_ARB_fragment_shader") ||
           !win->hasExtension("GL_ARB_vertex_shader") ||
           !win->hasExtension("GL_ARB_shader_objects"))
        {
            _useGLSL = false;
        }

        if(!_useGLSL)
        {
            FNOTICE(
                (
                "GLSL not supported, some shadow modes and real point lights will be disabled.\n"));
        }
        else
        {
            FNOTICE(("GLSL supported.\n"));
        }

        //check for Shader Model 3.0
        _useShaderModel3 = false;

        if(win->hasExtension("GL_NV_vertex_program3") ||
           win->hasExtension("GL_ATI_shader_texture_lod"))
            _useShaderModel3 = true;

        if(!_useShaderModel3)
        {
            FNOTICE(("Shader Model 3.0 NOT supported.\n"));
        }
        else
        {
            FNOTICE(("Shader Model 3.0 supported.\n"));
        }

        //No NPOTTextures supportet if FBOs are disabled
        if(!_useFBO)
            _useNPOTTextures = false;

        if(_useFBO)
        {
            GLenum  errCode;
            bool    FBOerror = false;

            glBindFramebufferEXT =
                reinterpret_cast<OSGGLBINDFRAMEBUFFEREXTPROC>(
                    win->getFunction(_funcBindFramebuffer));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glBindRenderbufferEXT =
                reinterpret_cast<OSGGLBINDRENDERBUFFEREXTPROC>(
                    win->getFunction(_funcBindRenderbuffer));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glCheckFramebufferStatusEXT =
                reinterpret_cast<OSGGLCHECKFRAMEBUFFERSTATUSEXTPROC>(
                    win->getFunction(_funcCheckFramebufferStatus));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glDeleteFramebuffersEXT =
                reinterpret_cast<OSGGLDELETEFRAMEBUFFERSEXTPROC>(
                    win->getFunction(_funcDeleteFramebuffers));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glDeleteRenderbuffersEXT =
                reinterpret_cast<OSGGLDELETERENDERBUFFERSEXTPROC>(
                    win->getFunction(_funcDeleteRenderbuffers));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glFramebufferRenderbufferEXT =
                reinterpret_cast<OSGGLFRAMEBUFFERRENDERBUFFEREXTPROC>(
                    win->getFunction(_funcFramebufferRenderbuffer));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glFramebufferTexture1DEXT =
                reinterpret_cast<OSGGLFRAMEBUFFERTEXTURE1DEXTPROC>(
                    win->getFunction(_funcFramebufferTexture1D));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glFramebufferTexture2DEXT =
                reinterpret_cast<OSGGLFRAMEBUFFERTEXTURE2DEXTPROC>(
                    win->getFunction(_funcFramebufferTexture2D));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glFramebufferTexture3DEXT =
                reinterpret_cast<OSGGLFRAMEBUFFERTEXTURE3DEXTPROC>(
                    win->getFunction(_funcFramebufferTexture3D));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glGenFramebuffersEXT =
                reinterpret_cast<OSGGLGENFRAMEBUFFERSEXTPROC>(
                    win->getFunction(_funcGenFramebuffers));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glGenRenderbuffersEXT =
                reinterpret_cast<OSGGLGENRENDERBUFFERSEXTPROC>(
                    win->getFunction(_funcGenRenderbuffers));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glGenerateMipmapEXT =
                reinterpret_cast<OSGGLGENERATEMIPMAPEXTPROC>(
                    win->getFunction(_funcGenerateMipmap));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glGetFramebufferAttachmentParameterivEXT =
                reinterpret_cast<
                    OSGGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC>(
                        win->getFunction(
                            _funcGetFramebufferAttachmentParameteriv));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glGetRenderbufferParameterivEXT =
                reinterpret_cast<OSGGLGETRENDERBUFFERPARAMETERIVEXTPROC>(
                    win->getFunction(_funcGetRenderbufferParameteriv));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glIsFramebufferEXT =
                reinterpret_cast<OSGGLISFRAMEBUFFEREXTPROC>(
                    win->getFunction(_funcIsFramebuffer));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glIsRenderbufferEXT =
                reinterpret_cast<OSGGLISRENDERBUFFEREXTPROC>(
                    win->getFunction(_funcIsRenderbuffer));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glRenderbufferStorageEXT =
                reinterpret_cast<OSGGLRENDERBUFFERSTORAGEEXTPROC>(
                    win->getFunction(_funcRenderbufferStorage));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            glDrawBuffersARB =
                reinterpret_cast<OSGGLDRAWBUFFERSARBPROC>(
                    win->getFunction(_funcDrawBuffers));

            if((errCode = glGetError()) != GL_NO_ERROR)
                FBOerror = true;

            GLenum  status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

            if(FBOerror)
            {
                FNOTICE(
                    (
                    "Needed FBO functions could not be initialized (error code %d), FBOs disabled. Try new video drivers!\n", errCode));
                _useFBO = false;
            }

            switch(status)
            {
                case GL_FRAMEBUFFER_COMPLETE_EXT:
                    FINFO(("%x: framebuffer complete!\n", status));
                    break;
                case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
                    FWARNING(
                        ("%x: framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT\n",
                         status));
                    break;
                default:
                    break;
            }
        }
        _initDone = true;
    }
}
Пример #6
0
bool DATImageFileType::read(      Image *image,
                            const Char8 *fileName)
{
    bool retCode = false;

    std::ifstream inDat(fileName), inVolS;
    std::istream *inVol;
    std::string keyStr, objectFileName;
    const UInt32 lineBufferSize = 1024;
    Char8 *value, *keySepPos, lineBuffer[lineBufferSize];
    const Char8 keySep = ':';
    int fileOffset, keyL, valueL;
    std::map<std::string, KeyType>::iterator keyI;
    std::map<std::string, FormatDesc>::iterator formatI;
    KeyType key;
    Image::Type formatType;
    UInt32 channel = 1;
    UInt32 res[3];
    UInt32 dataSize = 0;
    Image::PixelFormat pixelFormat = Image::OSG_L_PF;
    char *dataBuffer = 0;
    bool needConversion = false;
    // default endian type is big endian
    bool big_endian = true;

    res[0] = res[1] = res[2] = 0;
    fileOffset = 0;
    formatType = Image::OSG_INVALID_IMAGEDATATYPE;
    dataSize = 0;
    dataBuffer = 0;

    initTypeMap();

    // read the data file
    for(lineBuffer[0] = 0;
        inDat.getline(lineBuffer, lineBufferSize);
        lineBuffer[0] = 0)
    {
        if((keySepPos = strchr(lineBuffer,keySep)))
        {
            keyL = keySepPos - lineBuffer;
            keyStr.assign( lineBuffer, keyL );
            keyI = _keyStrMap.find(keyStr);
            key = ((keyI == _keyStrMap.end()) ? UNKNOWN_KT : keyI->second);
            value = keySepPos + 1;

            while (value && isspace(*value))
                value++;

            valueL = int(strlen(value));

            while (isspace(value[valueL-1]))
                value[--valueL] = 0;

            switch (key)
            {
                case OBJECT_FILE_NAME_KT:
                    objectFileName = value;
                    image->setAttachmentField ( keyStr, value );
                    break;
                case CHANNEL_KT:
                    sscanf ( value, "%u", &(channel) );
                    image->setAttachmentField ( keyStr, value );
                    break;
                case RESOLUTION_KT:
                    sscanf ( value, "%u %u %u",
                             &(res[0]), &(res[1]), &(res[2]));
                    image->setAttachmentField ( keyStr, value );
                    break;
                case FORMAT_KT:
                    formatI = _formatStrMap.find(value);
                    if (formatI != _formatStrMap.end())
                    {
                        formatType = formatI->second.type;
                    }
                    else
                    {
                        formatType = Image::OSG_INVALID_IMAGEDATATYPE;
                    }
                    image->setAttachmentField ( keyStr, value );
                    break;
                case ENDIAN_KT:
                    if(!strcmp(value, "LITTLE"))
                        big_endian = false;
                    image->setAttachmentField ( keyStr, value );
                    break;
                case FILE_OFFSET_KT:
                    sscanf ( value, "%d", &fileOffset );
                    image->setAttachmentField ( keyStr, value );
                    break;
                case UNKNOWN_KT:
                    FNOTICE (( "Uknown DAT file key: >%s<\n",
                                 keyStr.c_str() ));
                    image->setAttachmentField ( keyStr, value );
                    break;
                case SLICE_THICKNESS_KT:
                default:
                    image->setAttachmentField ( keyStr, value );
                    break;
            }
        }
        else
        {
            FINFO (("Skip DAT line\n"));
        }
    }

    // set pixelformat
    switch (channel) 
    {
        case 4:
            pixelFormat = Image::OSG_RGBA_PF;
            break;
        case 3:
            pixelFormat = Image::OSG_RGB_PF;
            break;
        case 2:
            pixelFormat = Image::OSG_LA_PF;
            break;
        default:
            pixelFormat = Image::OSG_L_PF;
            break;
    }

    // check the setting and read the raw vol data
    if (objectFileName.empty() == false)
    {
        if((res[0] > 0) && (res[1] > 0) && (res[2] > 0))
        {
            if(formatType != Image::OSG_INVALID_IMAGEDATATYPE)
            {
                inVolS.open(objectFileName.c_str(),
                            std::ios::in | std::ios::binary);

                if (inVolS.fail() && ImageFileHandler::the()->getPathHandler())
                {
                    // Try to find the file in the search path
                    inVolS.clear(); // reset the error state

                    PathHandler *ph =
                        ImageFileHandler::the()->getPathHandler();

                    inVolS.open(ph->findFile(objectFileName.c_str()).c_str(),
                                std::ios::in | std::ios::binary );
                }

                if(inVolS.fail())
                {
                    // Maybe compressed and name not changed?
                    std::string gzname = objectFileName + ".gz";

                    inVolS.clear(); // reset the error state

                    inVolS.open(gzname.c_str(),
                                std::ios::in | std::ios::binary );

                    if(inVolS.fail() &&
                       ImageFileHandler::the()->getPathHandler())
                    {
                        // Try to find the file in the search path
                        inVolS.clear(); // reset the error state

                        PathHandler *ph =
                            ImageFileHandler::the()->getPathHandler();

                        inVolS.open(ph->findFile(gzname.c_str()).c_str(),
                                    std::ios::in | std::ios::binary );
                    }
                }

                if(inVolS.good())
                {
#ifdef OSG_WITH_ZLIB
                    zip_istream *unzipper = NULL;
#endif

                    image->set(pixelFormat,
                               res[0], res[1], res[2],
                               1, 1, 0.0, 0,
                               formatType);

                    image->clear();

                    dataSize = image->getSize();

                    UInt32 fileDataSize = dataSize;

                    if(isGZip(inVolS))
                    {
#ifdef OSG_WITH_ZLIB
                        unzipper = new zip_istream(inVolS);
                        inVol = unzipper;
#else
                        SFATAL << "Compressed streams are not supported! "
                               << "Configure with --enable-png "
                               << "--with-png=DIR options." << std::endl;
#endif
                    }
                    else
                    {
                        inVol = &inVolS;

                        // get length of the stream.
                        inVol->seekg(0, std::ios::end);
                        UInt64 length = inVol->tellg();
                        inVol->seekg(0, std::ios::beg);

                        if(length < dataSize - fileOffset)
                        {
                            // correct dataSize.
                            fileDataSize = length;
                            FWARNING (( "RAW file length to small!\n" ));
                        }
                        else if(length > dataSize - fileOffset)
                        {
                            FWARNING (( "RAW file length to big!\n" ));
                        }
                    }

                    if(needConversion)
                    {
                        dataBuffer = new char [ dataSize ];
                    }
                    else
                    {
                        dataBuffer = 
                            reinterpret_cast<char *>(image->editData());
                    }

                    if(fileOffset != 0)
                        inVol->ignore (fileOffset);

                    inVol->read ( dataBuffer, fileDataSize );

#ifdef OSG_WITH_ZLIB
                    if(unzipper != NULL)
                        delete unzipper;
#endif
                }
                else
                {
                    FWARNING (( "Can not open %s image data\n",
                                objectFileName.c_str() ));
                }
            }
            else
            {
                FWARNING (( "Invalid/Missing DAT Format\n" ));
            }
        }
        else
        {
            FWARNING (( "Invalid/Missing DAT Resolution\n" ));
        }
    }
    else
    {
        FWARNING (( "Invalid/Missing DAT ObjectFileName\n" ));
    }

    // check/reformat vol data
    if (dataSize && dataBuffer)
    {
        // check host endian type
        UInt16 word = 0x0001;
        UInt8 *byte = reinterpret_cast<UInt8 *>(&word);
        bool host_big_endian = byte[0] ? false : true;

        if(big_endian != host_big_endian)
            image->swapDataEndian();

        if (needConversion)
        {
            FLOG (("DAT-Data convert not impl. yet !\n"));
            {
                switch (formatType)
                {
                    case Image::OSG_UINT8_IMAGEDATA:
                        break;
                    case Image::OSG_UINT16_IMAGEDATA:
                        break;
                    case Image::OSG_UINT32_IMAGEDATA:
                        break;
                    case Image::OSG_FLOAT32_IMAGEDATA:
                        break;
                    default:
                        ;
                }
            }
        }
        else
        {
            retCode = true;
        }
    }


    /* TODO
       std::ifstream in(fileName);
       Head head;
       void *headData = (void*)(&head);
       unsigned dataSize, headSize = sizeof(Head);

       if ( in &&
       in.read(static_cast<char *>(headData),
       headSize) && head.netToHost() &&
       image.set ( Image::PixelFormat(head.pixelFormat),
       head.width, head.height, head.depth, head.mipmapCount,
       head.frameCount, float(head.frameDelay) / 1000.0) &&
       (dataSize = image.getSize()) &&
       in.read((char *)(image.getData()), dataSize ))
       retCode = true;
       else
       retCode = false;
    */

    return retCode;
}
Пример #7
0
void HDRStage::postProcess(DrawEnv *pEnv)
{
    Window *win = pEnv->getWindow();

    if(win->hasExtension(_uiFramebuffer_object_extension) == false)
    {
        FNOTICE(("Framebuffer objects not supported on Window %p!\n", win));
        return;        
    }

    GLDrawBuffersEXTProcT glDrawBuffersEXTProc =
        reinterpret_cast<GLDrawBuffersEXTProcT>(
            win->getFunction(_uiFuncDrawBuffers));

    glColor3f(1.f, 1.f, 1.f);
    
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    glLoadIdentity();

    HDRStageData *pData = pEnv->getData<HDRStageData *>(_iDataSlotId);

    if(pData == NULL)
    {
        return;
    }

    if((pData->getWidth () != pEnv->getPixelWidth() ) ||
       (pData->getHeight() != pEnv->getPixelHeight())  )
    {
        resizeStageData(pData, 
                        pEnv->getPixelWidth(),
                        pEnv->getPixelHeight());
    }
    

    // Shrink to w/2 h/2

    FrameBufferObject *pShrinkTarget = pData->getShrinkRenderTarget();
    ChunkMaterial     *pSHM          = pData->getShrinkMaterial();


    pShrinkTarget->activate(pEnv);

    glViewport(0,
               0, 
               pEnv->getPixelWidth () / 2,
               pEnv->getPixelHeight() / 2);


    State *pShrinkState = pSHM->getState();

    pEnv->activateState(pShrinkState, NULL);
    
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.00, 0.00);
        glVertex2f  (0.00, 0.00);
        
        glTexCoord2f(1.00, 0.00);
        glVertex2f  (1.00, 0.00);
        
        glTexCoord2f(1.00, 1.00);
        glVertex2f  (1.00, 1.00);
        
        glTexCoord2f(0.00, 1.00);
        glVertex2f  (0.00, 1.00);
    }
    glEnd();

    pShrinkTarget->deactivate(pEnv);


    // Shrink to w/4 h/4

    FrameBufferObject *pBlurTarget = pData->getBlurRenderTarget();

    pBlurTarget->editMFDrawBuffers()->clear();

    pBlurTarget->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

    pBlurTarget->activate(pEnv);

    glViewport(0,
               0, 
               pEnv->getPixelWidth () / 4,
               pEnv->getPixelHeight() / 4);

    ChunkMaterial    *pBLM       = pData->getBlurMaterial();

    State            *pBlurState = pBLM->getState();

    pEnv->activateState(pBlurState, NULL);

    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.00, 0.00);
        glVertex2f  (0.00, 0.00);
        
        glTexCoord2f(1.00, 0.00);
        glVertex2f  (1.00, 0.00);
        
        glTexCoord2f(1.00, 1.00);
        glVertex2f  (1.00, 1.00);
        
        glTexCoord2f(0.00, 1.00);
        glVertex2f  (0.00, 1.00);
    }
    glEnd();

    // HBlur

    StateOverride oOverride;        

    GLenum aDrawBuffers[] = { GL_COLOR_ATTACHMENT1_EXT };

    oOverride.addOverride(pData->getHBlurShader()->getClassId(), 
                          pData->getHBlurShader());


    pEnv->activateState(pBlurState, &oOverride);
            
    glDrawBuffersEXTProc(1, aDrawBuffers);


    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.00, 0.00);
        glVertex2f  (0.00, 0.00);
        
        glTexCoord2f(1.00, 0.00);
        glVertex2f  (1.00, 0.00);
        
        glTexCoord2f(1.00, 1.00);
        glVertex2f  (1.00, 1.00);
        
        glTexCoord2f(0.00, 1.00);
        glVertex2f  (0.00, 1.00);
    }
    glEnd();



    // VBlur
           
    StateOverride oOverride1;        

    oOverride1.addOverride(pData->getVBlurShader()->getClassId(), 
                           pData->getVBlurShader());
    

    pEnv->activateState(pBlurState, &oOverride1);

    aDrawBuffers[0] = GL_COLOR_ATTACHMENT0_EXT;
    
    glDrawBuffersEXTProc(1, aDrawBuffers);
    
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.00, 0.00);
        glVertex2f  (0.00, 0.00);
        
        glTexCoord2f(1.00, 0.00);
        glVertex2f  (1.00, 0.00);
        
        glTexCoord2f(1.00, 1.00);
        glVertex2f  (1.00, 1.00);
        
        glTexCoord2f(0.00, 1.00);
        glVertex2f  (0.00, 1.00);
    }
    glEnd();
    
    
    pBlurTarget->deactivate(pEnv);



    // Tonemap pass

    glDisable(GL_DEPTH_TEST);

    glViewport(pEnv->getPixelLeft  (), 
               pEnv->getPixelBottom(),
               pEnv->getPixelWidth (),
               pEnv->getPixelHeight());

    ChunkMaterial *pTCM = pData->getToneMappingMaterial();

    State *pTState = pTCM->getState();
        
    pEnv->activateState(pTState, NULL);
            
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.00, 0.00);
        glVertex2f  (0.00, 0.00);
        
        glTexCoord2f(1.00, 0.00);
        glVertex2f  (1.00, 0.00);
        
        glTexCoord2f(1.00, 1.00);
        glVertex2f  (1.00, 1.00);
        
        glTexCoord2f(0.00, 1.00);
        glVertex2f  (0.00, 1.00);
    }
    glEnd();

    glEnable(GL_DEPTH_TEST);
            
    pEnv->deactivateState();


    glPopMatrix();
}
Пример #8
0
void HDRStage::postProcess(DrawEnv *pEnv)
{
    UInt32  uiActiveFBO = pEnv->getActiveFBO();
    Window *win         = pEnv->getWindow();

    if(win->hasExtOrVersion(_uiFramebufferObjectExt, 0x0300, 0x0200) == false)
    {
        FNOTICE(("Framebuffer objects not supported on Window %p!\n", 
                 static_cast<void *>(win)));
        return;        
    }

    OSGGETGLFUNCBYID_GL3( glDrawBuffers,
                          osgGlDrawBuffers,
                         _uiFuncDrawBuffers,
                          win);

    glColor3f(1.f, 1.f, 1.f);
    
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    glLoadIdentity();

    HDRStageData *pData = pEnv->getData<HDRStageData *>(_iDataSlotId);

    if(pData == NULL)
    {
        return;
    }



    // Shrink to w/2 h/2

    FrameBufferObject *pShrinkTarget = pData->getShrinkRenderTarget();
    ChunkMaterial     *pSHM          = pData->getShrinkMaterial();


    pShrinkTarget->activate(pEnv);

    glViewport(0,
               0, 
               pEnv->getPixelWidth () / 2,
               pEnv->getPixelHeight() / 2);


    State *pShrinkState = pSHM->getState();

    pEnv->activateState(pShrinkState, NULL);
    
    this->renderQuad();

    pShrinkTarget->deactivate(pEnv);




    // Shrink to w/4 h/4

    FrameBufferObject *pBlurTarget = pData->getBlurRenderTarget();

    pBlurTarget->editMFDrawBuffers()->clear();

    pBlurTarget->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

    pBlurTarget->activate(pEnv);

    glViewport(0,
               0, 
               pEnv->getPixelWidth () / 4,
               pEnv->getPixelHeight() / 4);

    ChunkMaterial    *pBLM       = pData->getBlurMaterial();

    State            *pBlurState = pBLM->getState();

    pEnv->activateState(pBlurState, NULL);

    this->renderQuad();



    GLenum aDrawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT };




    // HBlur

    pBlurTarget->activate(pEnv);

    glViewport(0,
               0, 
               pEnv->getPixelWidth () / 4,
               pEnv->getPixelHeight() / 4);

#define OVERSHADER 1

#if OVERSHADER
    StateOverride oOverride;        

    oOverride.addOverride(pData->getHBlurShader()->getClassId(), 
                          pData->getHBlurShader());


    pEnv->activateState(pBlurState, &oOverride);
#else
    pData->getHBlurShader()->activate(pEnv);
#endif

    aDrawBuffers[0] = GL_COLOR_ATTACHMENT1_EXT;

    osgGlDrawBuffers(1, aDrawBuffers);

    this->renderQuad();

#if !OVERSHADER
    pData->getHBlurShader()->deactivate(pEnv);
#endif

    // VBlur
           
#if OVERSHADER
    StateOverride oOverride1;        

    oOverride1.addOverride(pData->getVBlurShader()->getClassId(), 
                           pData->getVBlurShader());
    

    pEnv->activateState(pBlurState, &oOverride1);
#else
    pData->getVBlurShader()->activate(pEnv);
#endif

    aDrawBuffers[0] = GL_COLOR_ATTACHMENT0_EXT;
    
    osgGlDrawBuffers(1, aDrawBuffers);
    
    this->renderQuad();
    
#if !OVERSHADER
    pData->getVBlurShader()->deactivate(pEnv);
#endif
    
    if(uiActiveFBO == 0)
    {
        pBlurTarget->deactivate(pEnv);
    }
    else
    {
        FrameBufferObject::activateFBOById(pEnv, uiActiveFBO);
    }

    // Tonemap pass

    glDisable(GL_DEPTH_TEST);

    glViewport(pEnv->getPixelLeft  (), 
               pEnv->getPixelBottom(),
               pEnv->getPixelWidth (),
               pEnv->getPixelHeight());

    ChunkMaterial *pTCM = pData->getToneMappingMaterial();

    State *pTState = pTCM->getState();
        
    pEnv->activateState(pTState, NULL);
            
    this->renderQuad();

    glEnable(GL_DEPTH_TEST);
            
    pEnv->deactivateState();

    glPopMatrix();
}
Пример #9
0
std::string NFIOBase::readFCFields(const FieldContainerPtr &fc,
                                   const std::string &exclude,
                                   const std::string &endMarkers)
{
    FieldContainerType  &fcType = fc->getType();

    std::string fieldName;
    while(true)
    {
        _in->getValue(fieldName);
        // check for fieldcontainer end marker.
        if(fieldName.empty() || (!endMarkers.empty() &&
                                 endMarkers.find("'" + fieldName + "'") != std::string::npos))
        {
            FDEBUG(("NFIOBase::readFCPtr: found fieldcontainer end marker.\n"));
            break;
        }
        
        std::string fieldType;
        _in->getValue(fieldType);
        UInt32 size;
        _in->getValue(size);
        
        FDEBUG(("NFIOBase::readFCPtr: field: '%s' '%s' %u\n",
                fieldName.c_str(), fieldType.c_str(), size));
        
        Field *field = fc->getField(fieldName.c_str());
        FieldDescription *fDesc = fcType.findFieldDescription(fieldName.c_str());
        BitVector mask;
        if(fDesc != NULL)
        {
            mask = fDesc->getFieldMask();
            // now check for the same type, ok nobody should change a field type but ...
            if(fieldType != field->getType().getCName())
            {
                // for equal sizes try to read it, could be a type change from UInt32 to Int32
                // and that's tolerable.
                FWARNING(("NFIOBase::readFCPtr: found conflicting field types field '%s' with "
                            "types '%s' and '%s'!\n", fieldName.c_str(),
                            fieldType.c_str(), field->getType().getCName()));

                if(size != fc->getBinSize(mask))
                {
                    // ok in this case we skip the field!
                    FFATAL(("NFIOBase::readFCPtr: found conflicting field types with different sizes skipping field '%s' with "
                            "types '%s' and '%s'!\n", fieldName.c_str(),
                            fieldType.c_str(), field->getType().getCName()));
                    _in->skip(size);
                    continue;
                }
            }
        }
        else
        {
            FNOTICE(("NFIOBase::readFCPtr: skipping unknown field '%s' with "
                      "type '%s'!\n", fieldName.c_str(),
                      fieldType.c_str()));
            _in->skip(size);
            continue;
        }

        if(!exclude.empty() && exclude.find("'" + fieldName + "'") != std::string::npos)
        {
            FDEBUG(("NFIOBase::readFCPtr: skipping field '%s'!\n",
                    fieldName.c_str()));
            _in->skip(size);
            continue;
        }

        // ignore parents field.
        if(!strcmp(fieldName.c_str(), "parents"))
        {
            _in->skip(size);
            continue;
        }

        if(strstr(fieldType.c_str(), "Ptr") != NULL)
        {
            if(fieldType[0] == 'S' && fieldType[1] == 'F') // single field
            {
                readSFFieldContainerPtr(fc, mask, field);
            }
            else if(fieldType[0] == 'M' && fieldType[1] == 'F') // multi field
            {
                UInt32 noe;
                _in->getValue(noe);
                readMFFieldContainerPtr(fc, mask, field, noe);
            }
        }
        else if(!strcmp(fieldName.c_str(), "attachments"))
        {
            UInt32 noe;
            _in->getValue(noe);
            // old buggy format without binding info but we want to keep the
            // osb format backward and forward compatible!
            if(size == sizeof(UInt32) + sizeof(UInt32) * noe)
                readMFFieldContainerPtr(fc, mask, field, noe);
            else
                readSFAttachmentMap(fc, mask, field, noe);
        }
        else
        {
            beginEditCP(fc, mask);
                fc->copyFromBin(*_in, mask);
            endEditCP(fc, mask);
        }
    }
    return fieldName;
}
Пример #10
0
bool osgDoInit(OSG::Int32, 
               OSG::Char8 **,
               OSG::UInt16   major,
               OSG::UInt16   minor,
               OSG::UInt16   release,
               bool          debug,
               bool          dll,
               bool          mt)
{
    CompileConfig prog(major, 
                       minor, 
                       release, 
                       debug, 
                       dll, 
                       mt);

    CompileConfig lib (OSG_MAJOR_VERSION, 
                       OSG_MINOR_VERSION, 
                       OSG_RELEASE_VERSION,
                       OSG_INIT_DEBUG,
                       OSG_INIT_DLL,
                       OSG_INIT_MT);
    
    if(lib.compare(prog))
    {
        exit(1);
    }

#ifdef WIN32 
    // Very crude way to safeguard on low level cast, have to find a better
    // way later.
    OSG_ASSERT(sizeof(UInt32) == sizeof(long));
#endif

    bool returnValue = true;
    
    if(GlobalSystemState != Startup)
    {
        FFATAL(("osgInit: System was already initialized; repeated calls are "
                "NOT allowed.\n"));
                
        returnValue = false;
    }

    if(returnValue == false)
        return returnValue;

    returnValue = SharedObjectHandler::the()->initialize();

    if(osgPreloadSharedObject != NULL)
    {
        for(UInt32 i = 0; i < osgPreloadSharedObject->size(); ++i)
        {
            SharedObjectHandler::the()->getOSGSharedObject(
                (*osgPreloadSharedObject)[i].c_str());
        }
    }

#ifdef WIN32
    std::string pathSep(";");
#else
    std::string pathSep(":");
#endif

    char *szEnvLibs = getenv("OSG_LOAD_LIBS");

    if(szEnvLibs != NULL)
    {
        std::string tmpString(szEnvLibs);
        string_token_iterator libIt(tmpString, pathSep.c_str());

        string_token_iterator libEnd;

        while(libIt != libEnd)
        {
            SharedObjectHandler::the()->getOSGSharedObject(
                (*libIt).c_str());

            ++libIt;
        }
    }

    const char *szEnvPlugins       = getenv("OSG_PLUGIN_PATH");
    const char *szEnvPluginPattern = getenv("OSG_PLUGIN_PATTERN");

    //SharedObjectHandler::the()->dump();

    if(szEnvPlugins != NULL)
    {
        if(szEnvPluginPattern == NULL)
        {
            szEnvPluginPattern = PluginPattern;
        }

        fprintf(stderr, "Get Plugins %s from %s\n", 
                szEnvPluginPattern,
                szEnvPlugins);

        std::vector<Char8 *> *pPlugins = 
            Directory::getEntries(szEnvPlugins, szEnvPluginPattern);

        if(pPlugins != NULL)
        {
            std::string szPluginName;

            for(UInt32 i = 0; i < pPlugins->size(); ++i)
            {
                if((*pPlugins)[i][0] == '.')
                {
                    if((*pPlugins)[i][1] == '\0')
                    {
                        continue;
                    }
                    else if((*pPlugins)[i][1] == '.' &&
                            (*pPlugins)[i][2] == '\0')
                    {
                        continue;
                    }
                }

                szPluginName.assign(szEnvPlugins);
                szPluginName += '/';
                szPluginName += (*pPlugins)[i];

                fprintf(stderr, "plugin : %s\n", szPluginName.c_str());

                SharedObjectHandler::the()->getSharedObject(
                    szPluginName.c_str());
            }
        }

        delete pPlugins;
    }

    if(osgLibraryVersions != NULL)
    {
        FNOTICE(("osgInit:  Main Version                  : %s\n", OSG_VERSION_STRING));
        for(LibVersionMap::const_iterator LibMapItor(osgLibraryVersions->begin());
            LibMapItor != osgLibraryVersions->end();
            ++LibMapItor)
        {
            FNOTICE(("osgInit:  %-30s: %-10s  Rev: %s\n",
                     LibMapItor->first.c_str(),
                     LibMapItor->second.first.c_str(),
                     LibMapItor->second.second.c_str()));
        }
    }
    
    //SharedObjectHandler::the()->dump();

    if(returnValue == false)
        return returnValue;

    // without it floats could be written as "1,456" ...
    setlocale(LC_NUMERIC, "English");

    if(osgPreMPInitFunctions != NULL)
    {
        for(UInt32 i = 0; i < osgPreMPInitFunctions->size(); i++)
        {
            returnValue &= (*osgPreMPInitFunctions)[i]();

            if(returnValue == false)
                break;
        }

        osgPreMPInitFunctions->clear();
    }

    if(returnValue == false)
        return returnValue;

    returnValue &= ThreadManager::initialize();

    if(returnValue == false)
        return returnValue;

    if(osgPreFactoryInitFunctions != NULL)
    {
        for(UInt32 i = 0; i < osgPreFactoryInitFunctions->size(); i++)
        {
            returnValue &= (*osgPreFactoryInitFunctions)[i]();

            if(returnValue == false)
                break;
        }

        osgPreFactoryInitFunctions->clear();
    }

    if(returnValue == false)
        return returnValue;

    returnValue &= FactoryController::the()->initialize();

    if(returnValue == false)
        return returnValue;

    if(osgPostFactoryInitFunctions != NULL)
    {
        for(UInt32 i = 0; i < osgPostFactoryInitFunctions->size(); i++)
        {
            returnValue &= (*osgPostFactoryInitFunctions)[i]();

            if(returnValue == false)
                break;
        }

        osgPostFactoryInitFunctions->clear();
    }

    GlobalSystemState = Running;

    osgLog().setLogLevel(OSG_DEFAULT_LOG_LEVEL);

    return returnValue;
}
Пример #11
0
bool CompileConfig::compare(const CompileConfig &c)
{
    FDEBUG(("CompileConfig::compare: lib: version %d.%d.%d, %sdebug, %sdll, "
            "%smt \n",
            _major, 
            _minor, 
            _release, 
            _debug ? "" : "non-", 
            _dll   ? "" : "non-", 
            _mt    ? "" : "non-"));

    FDEBUG(("CompileConfig::compare: prog: version %d.%d.%d, %sdebug, %sdll, "
            "%smt \n",
            c._major, 
            c._minor, 
            c._release, 
            c._debug ? "" : "non-", 
            c._dll   ? "" : "non-", 
            c._mt    ? "" : "non-"));
             
    if(_major != c._major)
    {
        FFATAL(("The program is compiled against version %d headers, "
                "but the library is version %d! It's a miracle it linked, "
                "but it will not work.\n", 
                  _major, 
                c._major));
        return true;
    }

    if(_minor != c._minor)
    {
        FWARNING(("The program is compiled against version %d.%d headers, "
                  "but the library is version %d.%d! This is not recommended "
                  "use at your own risk.\n", 
                    _major, 
                    _minor, 
                  c._major, 
                  c._minor));
    }

    if(_release != c._release)
    {
        FNOTICE(("The program is compiled against version %d.%d.%d headers, "
                 "but the library is version %d.%d.%d! This should "
                 "work fine, but if you have problems please mention it "
                 "in your report.\n", 
                   _major, 
                   _minor, 
                   _release,
                 c._major, 
                 c._minor, 
                 c._release));
    }

    if(_mt != c._mt)
    {
        FFATAL(("The program is linked against the %s-threaded runtime lib, "
                "but the library is linked against the %s-threaded one! "
                "This will lead to memory corruption, please link the "
                "%s-threaded lib (use /M%s%s instead of /M%s%s)!\n", 
                c._mt    ? "multi" : "single", 
                  _mt    ? "multi" : "single", 
                  _mt    ? "multi" : "single",
                  _mt    ? "D"     : "L", 
                  _debug ? "d"     : "",
                  _mt    ? "L"     : "D", 
                  _debug ? "d"     : ""));
        return true;
    }
    
#ifdef WIN32
    if(_debug != c._debug)
    {
        FFATAL(("The program is linked against the %sdebug runtime lib, "
                "but the library is linked against the %sdebug one! "
                "This will lead to memory corruption, please link the "
                "%sdebug lib (use /M%s%s instead of /M%s%s)!\n", 
                c._debug ? ""  : "non-", 
                  _debug ? ""  : "non-", 
                  _debug ? ""  : "non-",
                  _mt    ? "D" : "L", 
                  _debug ? "d" : "", 
                  _mt    ? "D" : "L", 
                  _debug ? "d" : ""));

        return true;
    }
#endif

    return false;
}