Example #1
0
bool GLTextureCubeMap::set( GLCubeMapFace face,
    Array2DView< const uint8x4 > data,
    GLImageFormat format,
    const Vector2i& dstOffset )
{
    if( dstOffset.x + data.width() > sideLength() ||
        dstOffset.y + data.height() > sideLength() )
    {
        return false;
    }
    if( format != GLImageFormat::RGBA &&
        format != GLImageFormat::BGRA )
    {
        return false;
    }

    //glPushClientAttribDefaultEXT( GL_CLIENT_PIXEL_STORE_BIT );
    // TODO: alignment, strides, ..., has to be packed

    // DSA treats a cube map as a 2D array texture.
    glTextureSubImage3D
    (
        id(), 0,
        dstOffset.x, dstOffset.y, static_cast< int >( face ),
        data.width(), data.height(), 1, // 1 face
        static_cast< GLenum >( format ), GL_UNSIGNED_BYTE,
        data.pointer()
    );

    //glPopClientAttrib();

    return true;
}
Example #2
0
bool GLTextureCubeMap::get( GLCubeMapFace face, Array2DView< uint8x4 > output, GLImageFormat format )
{
    // TODO: glPixelStorei allows some packing?
    // GL_PACK_ALIGNMENT

    if( output.isNull() ||
        output.width() != sideLength() ||
        output.height() != sideLength() ||
        !( output.packed() ) )
    {
        return false;
    }

    if( format != GLImageFormat::RGBA &&
        format != GLImageFormat::BGRA )
    {
        return false;
    }

    // TODO: mipmap level
    glGetTextureSubImage( id(), 0,
        0, 0, static_cast< GLenum >( face ),
        sideLength(), sideLength(), 1,
        static_cast< GLenum >( format ), GL_UNSIGNED_BYTE,
        output.width() * output.height() * output.elementStrideBytes(), output );
    return true;
}
Example #3
0
void ECKeyPad::initPins(unsigned numCols) {
    if (numCols < 3)
        numCols = 3;
    else if (numCols > 9)
        numCols = 9;

    if (numCols == m_numCols)
        return;

    int w = sideLength(numCols);
    int h = sideLength(4);

    setSize(-int(w / 16)*8, -int(h / 16)*8, w, h, true);

    if (numCols > m_numCols) {
        // Adding columns
        for (unsigned i = 0; i < 4; i++) {
            for (unsigned j = m_numCols; j < numCols; j++)
                addButton(buttonID(i, j), QRect(0, 0, 20, 20), text[i][j]);
        }

        ECNode *cols[9];

        for (unsigned j = m_numCols; j < numCols; j++)
            cols[j] = createPin(0, 64, 270, "col_" + QString::number(j));

        for (unsigned i = 0; i < 4; i++) {
            Pin *row = &ecNodeWithID("row_" + QString::number(i))->pin();

            for (unsigned j = m_numCols; j < numCols; j++)
                m_switch[i][j] = new Switch(this, cols[j]->pin(), *row, Switch::Open);
        }
    } else {
        // Remove columns
        for (unsigned i = 0; i < 4; i++) {
            for (unsigned j = numCols; j < m_numCols; j++)
                removeWidget(buttonID(i, j));
        }

        for (unsigned j = numCols; j < m_numCols; j++)
            removeNode("col_" + QString::number(j));

        for (unsigned i = 0; i < 4; i++) {
            for (unsigned j = m_numCols; j < numCols; j++)
                delete m_switch[i][j];
        }
    }

    //BEGIN Update Positions
    m_numCols = numCols;

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < int(m_numCols); j++) {
            widgetWithID(buttonID(i, j))->setOriginalRect(
                QRect(offsetX() + 6 + 24*j, offsetY() + 6 + 24*i, 20, 20));
        }
    }

    for (int i = 0; i < 4; i++)
        m_nodeMap["row_" + QString::number(i)].x = width() + offsetX();

    for (int j = 0; j < int(m_numCols); j++)
        m_nodeMap["col_" + QString::number(j)].x = 24 * j + offsetX() + 16;

    updateAttachedPositioning();
    //END Update Positions
}