Пример #1
0
void RasterNode::blt(const glm::mat4& transform, const glm::vec2& destSize)
{
    GLContext* pContext = GLContext::getCurrent();
    FRect destRect;
    
    StandardShaderPtr pShader = pContext->getStandardShader();
    float opacity = getEffectiveOpacity();
    pContext->setBlendColor(glm::vec4(1.0f, 1.0f, 1.0f, opacity));
    pShader->setAlpha(opacity);
    if (m_pFXNode) {
        pContext->setBlendMode(m_BlendMode, true);
        m_pFXNode->getTex()->activate(GL_TEXTURE0);
        pShader->setColorModel(0);
        pShader->disableColorspaceMatrix();
        pShader->setGamma(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
        pShader->setPremultipliedAlpha(true);
        pShader->setMask(false);

        FRect relDestRect = m_pFXNode->getRelDestRect();
        destRect = FRect(relDestRect.tl.x*destSize.x, relDestRect.tl.y*destSize.y,
                relDestRect.br.x*destSize.x, relDestRect.br.y*destSize.y);
    } else {
        m_pSurface->activate(getMediaSize());
        pContext->setBlendMode(m_BlendMode, m_pSurface->isPremultipliedAlpha());
        destRect = FRect(glm::vec2(0,0), destSize);
    }
    glm::vec3 pos(destRect.tl.x, destRect.tl.y, 0);
    glm::vec3 scaleVec(destRect.size().x, destRect.size().y, 1);
    glm::mat4 localTransform = glm::translate(transform, pos);
    localTransform = glm::scale(localTransform, scaleVec);
    pShader->setTransform(localTransform);
    pShader->activate();
    m_pSubVA->draw();
}
Пример #2
0
void OGLSurface::activate(const IntPoint& logicalSize, bool bPremultipliedAlpha) const
{
    StandardShaderPtr pShader = StandardShader::get();

    GLContext::checkError("OGLSurface::activate()");
    switch (m_pf) {
        case YCbCr420p:
        case YCbCrJ420p:
            pShader->setColorModel(1);
            break;
        case YCbCrA420p:
            pShader->setColorModel(3);
            break;
        case A8:
            pShader->setColorModel(2);
            break;
        default:
            pShader->setColorModel(0);
    }

    m_pTextures[0]->activate(GL_TEXTURE0);

    if (pixelFormatIsPlanar(m_pf)) {
        m_pTextures[1]->activate(GL_TEXTURE1);
        m_pTextures[2]->activate(GL_TEXTURE2);
        if (m_pf == YCbCrA420p) {
            m_pTextures[3]->activate(GL_TEXTURE3);
        }
    }
    if (pixelFormatIsPlanar(m_pf) || colorIsModified()) {
        glm::mat4 mat = calcColorspaceMatrix();
        pShader->setColorspaceMatrix(mat);
    } else {
        pShader->disableColorspaceMatrix();
    }
    pShader->setGamma(glm::vec4(1/m_Gamma.x, 1/m_Gamma.y, 1/m_Gamma.z, 
                1./m_AlphaGamma));

    pShader->setPremultipliedAlpha(bPremultipliedAlpha);
    if (m_pMaskTexture) {
        m_pMaskTexture->activate(GL_TEXTURE4);
        // Special case for pot textures: 
        //   The tex coords in the vertex array are scaled to fit the image texture. We 
        //   need to undo this and fit to the mask texture. In the npot case, everything
        //   evaluates to (1,1);
        glm::vec2 texSize = glm::vec2(m_pTextures[0]->getGLSize());
        glm::vec2 imgSize = glm::vec2(m_pTextures[0]->getSize());
        glm::vec2 maskTexSize = glm::vec2(m_pMaskTexture->getGLSize());
        glm::vec2 maskImgSize = glm::vec2(m_pMaskTexture->getSize());
        glm::vec2 maskScale = glm::vec2(maskTexSize.x/maskImgSize.x, 
                maskTexSize.y/maskImgSize.y);
        glm::vec2 imgScale = glm::vec2(texSize.x/imgSize.x, texSize.y/imgSize.y);
        glm::vec2 maskPos = m_MaskPos/maskScale;
        // Special case for words nodes.
        if (logicalSize != IntPoint(0,0)) {
            maskScale *= glm::vec2((float)logicalSize.x/m_Size.x, 
                    (float)logicalSize.y/m_Size.y);
        }
        pShader->setMask(true, maskPos, m_MaskSize*maskScale/imgScale);
    } else {
        pShader->setMask(false);
    }
    pShader->activate();
    GLContext::checkError("OGLSurface::activate");
}