コード例 #1
0
void DeferredShadingStage::updateGBuffer(
    TextureBuffer *buf, UInt32 index, Int32 width, Int32 height)
{
    TextureObjChunk *bufTex = buf   ->getTexture();
    Image           *bufImg = bufTex->getImage  ();

    if((_changeCache & (PixelFormatsFieldMask |
                        PixelTypesFieldMask    )) != 0)
    {
        bufImg->setPixelFormat(_mfPixelFormats[index]);
        bufImg->setDataType   (_mfPixelTypes  [index]);
    }

    if(_targetSizeChanged == true)
    {
        bufImg->setWidth (width );
        bufImg->setHeight(height);
    }
}
コード例 #2
0
void DisplayFilterStage::resizeStageData(DisplayFilterStageData *pData,
                                         Int32                   iPixelWidth,
                                         Int32                   iPixelHeight)
{
    FrameBufferObject *pFBO = pData->getTarget();

    if(pFBO == NULL)
        return;

    TextureBuffer *pTexBuffer = 
        dynamic_cast<TextureBuffer *>(pFBO->getColorAttachments(0));

    if(pTexBuffer == NULL)
        return;

    TextureObjChunk *pTex = pTexBuffer->getTexture();

    if(pTex == NULL)
        return;

    Image *pImg = pTex->getImage();

    if(pImg == NULL)
        return;

    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth, 
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_UINT8_IMAGEDATA,
              false);

    pFBO->setSize(iPixelWidth, iPixelHeight);

    pData->setWidth (iPixelWidth );
    pData->setHeight(iPixelHeight);

    commitChanges();
}
コード例 #3
0
static Action::ResultE modifyMaterial(Node * const node)
{   
    MaterialGroup *mg = dynamic_cast<MaterialGroup *>(node->getCore());
    
    if(mg == NULL)
        return Action::Continue; 
    
    ChunkMaterial *cmat = dynamic_cast<ChunkMaterial *>(mg->getMaterial());
    
    if(cmat == NULL)
        return Action::Continue; 
    
    TextureObjChunk *texc = 
        dynamic_cast<TextureObjChunk *>(
            cmat->find(TextureObjChunk::getClassType()));
    
    if(texc == NULL)
        return Action::Continue;
    
    MaterialChunk *matc = 
        dynamic_cast<MaterialChunk *>(
            cmat->find(MaterialChunk::getClassType()));

    TextureEnvChunkUnrecPtr texe = 
        dynamic_cast<TextureEnvChunk *>(
            cmat->find(TextureEnvChunk::getClassType()));
    
    if(texe == NULL)
    {
        texe = TextureEnvChunk::create();
        cmat->addChunk(texe);
    }

    if(matc == NULL)
    {
        // no material chunk so we use the replace mode.
        texe->setEnvMode(GL_REPLACE);
        return Action::Continue;
    }
    
    if(matc != NULL)
    {
        Image *img = texc->getImage();

        texe->setEnvMode(GL_MODULATE);

        if(img != NULL && img->getBpp() > 2)
        {
            // for color textures the texture replaces only the diffuse part.
            matc->setDiffuse(Color4f(1.0f, 1.0f, 1.0f, 1.0f));
        }
        
        
        // check for textures with alpha
        if(!matc->isTransparent()         && 
            img                   != NULL &&
            img->getBpp()         ==    4   )
        {
            BlendChunkUnrecPtr blendc = 
                dynamic_cast<BlendChunk *>(
                    cmat->find(BlendChunk::getClassType()));

            if(blendc == NULL)
            {
                blendc = OSG::BlendChunk::create();

                blendc->setSrcFactor (GL_SRC_ALPHA);
                blendc->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    
                cmat->addChunk(blendc);
            }
        }
    }

    return Action::Continue;
}
コード例 #4
0
void TextureBuffer::processPreDeactivate(DrawEnv *pEnv, UInt32 index)
{
    if(_sfReadBack.getValue() == true)
    {
        TextureObjChunk *pTexObj = this->getTexture();
        
        if(pTexObj == NULL)
            return;
        
        Image *pTexImg = pTexObj->getImage();
                    
        if(pTexImg->getData() == NULL)
        {
            SINFO << "TextureBuffer::render: (Re)Allocating image "
                  << "for read-back."
                  << endLog;
            
            pTexImg->set(pTexImg->getPixelFormat(),
                         pTexImg->getWidth      (),
                         pTexImg->getHeight     (),
                         pTexImg->getDepth      (),
                         pTexImg->getMipMapCount(),
                         pTexImg->getFrameCount (),
                         pTexImg->getFrameDelay (),
                         NULL,
                         pTexImg->getDataType   (),
                         true,
                         pTexImg->getSideCount  () );
        }

        UInt32  mipMapLevel = _sfLevel.getValue();
        UInt32  frame       = 0;
        UInt32  side        = 0;
        GLenum  target;
        Window *pWindow = pEnv->getWindow();

        if(_sfTexTarget.getValue() != GL_NONE)
        {
            target = _sfTexTarget.getValue();
        }
        else
        {
            target = _sfTexture.getValue()->determineTextureTarget(pWindow);
        }

        switch(target)
        {
            case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
                side = 0;
                break;
            case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
                side = 1;
                break;
            case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
                side = 2;
                break;
            case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
                side = 3;
                break;
            case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
                side = 4;
                break;
            case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
                side = 5;
                break;
        }

        // select GL_COLORATTACHMENTn and read data into image
        glReadBuffer(index);
        glReadPixels(0, 0, 
                     pTexImg->getWidth      (),
                     pTexImg->getHeight     (),
                     pTexImg->getPixelFormat(),
                     pTexImg->getDataType   (),
                     pTexImg->editData      (mipMapLevel, frame, side));
        
        glReadBuffer(GL_NONE);
    }
}