Exemplo n.º 1
0
void BezierWidget::freeVertices()
{
    positionBuffer = QCLBuffer();
    texCoordBuffer = QCLBuffer();
    if (positions) {
        std::free(positions);
        positions = 0;
    }
    if (texCoords) {
        std::free(texCoords);
        texCoords = 0;
    }
    if (indices) {
        std::free(indices);
        indices = 0;
    }
#ifdef USE_VBOS
    delete vertexBuffer;
    delete texBuffer;
    delete indexBuffer;
    vertexBuffer = 0;
    texBuffer = 0;
    indexBuffer = 0;
#endif
    lastSubdivisionSize = -1;
    numVertices = 0;
    numIndices = 0;
}
Exemplo n.º 2
0
/*!
    Returns the parent of this buffer if it is a sub-buffer;
    null otherwise.

    \sa createSubBuffer(), offset()
*/
QCLBuffer QCLBuffer::parentBuffer() const
{
    cl_mem parent;
    if (clGetMemObjectInfo(memoryId(), CL_MEM_ASSOCIATED_MEMOBJECT,
                           sizeof(parent), &parent, 0) != CL_SUCCESS)
        return QCLBuffer();
    if (parent)
        clRetainMemObject(parent);
    return QCLBuffer(context(), parent);
}
Exemplo n.º 3
0
/*!
    Creates an OpenCL memory buffer of \a size bytes in length,
    with the specified \a access mode.

    The memory is created on the device and will not be accessible
    to the host via a direct pointer.  Use createBufferHost() to
    create a host-accessible buffer.

    Returns the new OpenCL memory buffer object, or a null object
    if the buffer could not be created.

    \sa createBufferHost(), createBufferCopy(), createVector()
*/
QCLBuffer QCLContext::createBufferDevice(size_t size, QCLMemoryObject::Access access)
{
    Q_D(QCLContext);
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    cl_mem mem = clCreateBuffer(d->id, flags, size, 0, &error);
    reportError("QCLContext::createBufferDevice:", error);
    if (mem)
        return QCLBuffer(this, mem);
    else
        return QCLBuffer();
}
Exemplo n.º 4
0
/*!
    Creates an OpenCL memory buffer of \a size bytes in length,
    with the specified \a access mode.

    The buffer is initialized with a copy of the contents of \a data.
    The application's \a data can be discarded after the buffer
    is created.

    Returns the new OpenCL memory buffer object, or a null object
    if the buffer could not be created.

    \sa createBufferDevice(), createBufferHost(), createVector()
*/
QCLBuffer QCLContext::createBufferCopy
    (const void *data, size_t size, QCLMemoryObject::Access access)
{
    Q_ASSERT(data);
    Q_D(QCLContext);
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    flags |= CL_MEM_COPY_HOST_PTR;
    cl_mem mem = clCreateBuffer
        (d->id, flags, size, const_cast<void *>(data), &error);
    reportError("QCLContext::createBufferCopy:", error);
    if (mem)
        return QCLBuffer(this, mem);
    else
        return QCLBuffer();
}
Exemplo n.º 5
0
/*!
    Creates an OpenCL memory buffer of \a size bytes in length,
    with the specified \a access mode.

    If \a data is not null, then it will be used as the storage
    for the buffer.  If \a data is null, then a new block of
    host-accessible memory will be allocated.

    Returns the new OpenCL memory buffer object, or a null object
    if the buffer could not be created.

    \sa createBufferDevice(), createBufferCopy(), createVector()
*/
QCLBuffer QCLContext::createBufferHost
    (void *data, size_t size, QCLMemoryObject::Access access)
{
    Q_D(QCLContext);
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    if (data)
        flags |= CL_MEM_USE_HOST_PTR;
    else
        flags |= CL_MEM_ALLOC_HOST_PTR;
    cl_mem mem = clCreateBuffer(d->id, flags, size, data, &error);
    reportError("QCLContext::createBufferHost:", error);
    if (mem)
        return QCLBuffer(this, mem);
    else
        return QCLBuffer();
}
Exemplo n.º 6
0
/*!
    Creates an OpenCL memory buffer from the OpenGL buffer object
    \a bufobj, with the specified \a access mode.

    This function will only work if supportsObjectSharing() is true.
*/
QCLBuffer QCLContextGL::createGLBuffer(GLuint bufobj, QCLMemoryObject::Access access)
{
#ifndef QT_NO_CL_OPENGL
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    cl_mem mem = clCreateFromGLBuffer
        (contextId(), flags, bufobj, &error);
    reportError("QCLContextGL::createGLBuffer:", error);
    if (mem)
        return QCLBuffer(this, mem);
    else
        return QCLBuffer();
#else
    Q_UNUSED(bufobj);
    Q_UNUSED(access);
    reportError("QCLContextGL::createGLBuffer:", CL_INVALID_VALUE);
    return QCLBuffer();
#endif
}
Exemplo n.º 7
0
/*!
    Creates a new buffer that refers to the \a size bytes,
    starting at \a offset within this buffer.  The data in
    the new buffer will be accessed according to \a access.

    Sub-buffers are an OpenCL 1.1 feature.  On OpenCL 1.0,
    this function will return a null buffer.

    \sa parentBuffer(), offset()
*/
QCLBuffer QCLBuffer::createSubBuffer
(size_t offset, size_t size, QCLMemoryObject::Access access)
{
#ifdef QT_OPENCL_1_1
    cl_int error;
    cl_buffer_region region;
    region.origin = offset;
    region.size = size;
    cl_mem mem = clCreateSubBuffer
                 (memoryId(), cl_mem_flags(access),
                  CL_BUFFER_CREATE_TYPE_REGION, &region, &error);
    context()->reportError("QCLBuffer::createSubBuffer:", error);
    return QCLBuffer(context(), mem);
#else
    Q_UNUSED(offset);
    Q_UNUSED(size);
    Q_UNUSED(access);
    return QCLBuffer();
#endif
}
Exemplo n.º 8
0
/*!
    \overload

    Creates an OpenCL memory buffer from the OpenGL buffer object
    \a bufobj, with the specified \a access mode.

    This function will only work if supportsObjectSharing() is true.
*/
QCLBuffer QCLContextGL::createGLBuffer(QGLBuffer *bufobj, QCLMemoryObject::Access access)
{
    if (!bufobj)
        return QCLBuffer();
    return createGLBuffer(GLuint(bufobj->bufferId()), access);
}