/*! Creates a 2D OpenCL image object from \a image with the specified \a access mode. OpenCL kernels that access the image will read and write the QImage contents directly. Returns the new 2D OpenCL image object, or a null object if the image could not be created. If \a image is null or has a zero size, this function will return a null QCLImage2D object. \sa createImage2DDevice(), createImage2DCopy() */ QCLImage2D QCLContext::createImage2DHost(QImage *image, QCLMemoryObject::Access access) { Q_D(QCLContext); // Validate the image. if (!image || image->width() < 1 || image->height() < 1) return QCLImage2D(); QCLImageFormat format(image->format()); if (format.isNull()) { qWarning("QCLContext::createImage2DHost: QImage format %d " "does not have an OpenCL equivalent", int(image->format())); return QCLImage2D(); } // Create the image object. cl_int error = CL_INVALID_CONTEXT; cl_mem_flags flags = cl_mem_flags(access) | CL_MEM_USE_HOST_PTR; cl_mem mem = clCreateImage2D (d->id, flags, &(format.m_format), image->width(), image->height(), image->bytesPerLine(), image->bits(), &error); reportError("QCLContext::createImage2DHost:", error); if (mem) return QCLImage2D(this, mem, format); else return QCLImage2D(); }
/*! Creates a 2D OpenCL image object from \a image with the specified \a access mode. The OpenCL image is initialized with a copy of the contents of \a image. The application's \a image can be discarded after the OpenCL image is created. Returns the new 2D OpenCL image object, or a null object if the image could not be created. If \a image has a zero size, this function will return a null QCLImage2D object. \sa createImage2DDevice(), createImage2DHost() */ QCLImage2D QCLContext::createImage2DCopy (const QImage &image, QCLMemoryObject::Access access) { Q_D(QCLContext); // Validate the image. if (image.width() < 1 || image.height() < 1) return QCLImage2D(); QCLImageFormat format(image.format()); if (format.isNull()) { qWarning("QCLContext::createImage2DCopy: QImage format %d " "does not have an OpenCL equivalent", int(image.format())); return QCLImage2D(); } // Create the image object. cl_int error = CL_INVALID_CONTEXT; cl_mem_flags flags = cl_mem_flags(access) | CL_MEM_COPY_HOST_PTR; cl_mem mem = clCreateImage2D (d->id, flags, &(format.m_format), image.width(), image.height(), image.bytesPerLine(), const_cast<uchar *>(image.bits()), &error); reportError("QCLContext::createImage2DCopy:", error); if (mem) return QCLImage2D(this, mem); else return QCLImage2D(); }
/*! Creates a 2D OpenCL image object with the specified \a format, \a size, and \a access mode. The image memory is created on the device and will not be accessible to the host via a direct pointer. Use createImage2DHost() to create a host-accessible image. Returns the new 2D OpenCL image object, or a null object if the image could not be created. \sa createImage2DHost(), createImage2DCopy() */ QCLImage2D QCLContext::createImage2DDevice (const QCLImageFormat &format, const QSize &size, QCLMemoryObject::Access access) { Q_D(QCLContext); cl_int error = CL_INVALID_CONTEXT; cl_mem_flags flags = cl_mem_flags(access); cl_mem mem = clCreateImage2D (d->id, flags, &(format.m_format), size.width(), size.height(), 0, 0, &error); reportError("QCLContext::createImage2DDevice:", error); if (mem) return QCLImage2D(this, mem, format); else return QCLImage2D(); }
/*! Creates a 2D OpenCL image object with the specified \a format, \a size, and \a access mode. If \a bytesPerLine is not zero, it indicates the number of bytes between lines in \a data. The image is initialized with a copy of the contents of \a data. The application's \a data can be discarded after the image is created. Returns the new 2D OpenCL image object, or a null object if the image could not be created. \sa createImage2DDevice(), createImage2DHost() */ QCLImage2D QCLContext::createImage2DCopy (const QCLImageFormat &format, const void *data, const QSize &size, QCLMemoryObject::Access access, int bytesPerLine) { Q_D(QCLContext); cl_int error = CL_INVALID_CONTEXT; cl_mem_flags flags = cl_mem_flags(access) | CL_MEM_COPY_HOST_PTR; cl_mem mem = clCreateImage2D (d->id, flags, &(format.m_format), size.width(), size.height(), bytesPerLine, const_cast<void *>(data), &error); reportError("QCLContext::createImage2DCopy:", error); if (mem) return QCLImage2D(this, mem); else return QCLImage2D(); }
/*! Creates a 2D OpenCL image object from the specified OpenGL \a renderbuffer object, and the \a access mode. This function will only work if supportsObjectSharing() is true. \sa createTexture2D() */ QCLImage2D QCLContextGL::createRenderbuffer (GLuint renderbuffer, 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 = clCreateFromGLRenderbuffer (contextId(), flags, renderbuffer, &error); reportError("QCLContextGL::createGLRenderbuffer:", error); if (mem) return QCLImage2D(this, mem); else return QCLImage2D(); #else Q_UNUSED(renderbuffer); Q_UNUSED(access); reportError("QCLContextGL::createRenderbuffer:", CL_INVALID_VALUE); return QCLImage2D(); #endif }
/*! Creates a 2D OpenCL image object with the specified \a format, \a size, and \a access mode. If \a bytesPerLine is not zero, it indicates the number of bytes between lines in \a data. If \a data is not null, then it will be used as the storage for the image. If \a data is null, then a new block of host-accessible memory will be allocated. Returns the new 2D OpenCL image object, or a null object if the image could not be created. \sa createImage2DDevice(), createImage2DCopy() */ QCLImage2D QCLContext::createImage2DHost (const QCLImageFormat &format, void *data, const QSize &size, QCLMemoryObject::Access access, int bytesPerLine) { 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 = clCreateImage2D (d->id, flags, &(format.m_format), size.width(), size.height(), bytesPerLine, data, &error); reportError("QCLContext::createImage2DHost:", error); if (mem) return QCLImage2D(this, mem, format); else return QCLImage2D(); }
/*! Creates a 2D OpenCL image object from the specified \a mipmapLevel, OpenGL \a texture object, and \a access mode. The \a type must be one of \c{GL_TEXTURE_2D}, \c{GL_TEXTURE_CUBE_MAP_POSITIVE_X}, \c{GL_TEXTURE_CUBE_MAP_POSITIVE_Y}, \c{GL_TEXTURE_CUBE_MAP_POSITIVE_Z}, \c{GL_TEXTURE_CUBE_MAP_NEGATIVE_X}, \c{GL_TEXTURE_CUBE_MAP_NEGATIVE_Y}, \c{GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}, or \c{GL_TEXTURE_RECTANGLE}. The \a texture does not need to be bound to an OpenGL texture target. This function will only work if supportsObjectSharing() is true. \sa createTexture3D(), createRenderbuffer() */ QCLImage2D QCLContextGL::createTexture2D (GLenum type, GLuint texture, GLint mipmapLevel, 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 = clCreateFromGLTexture2D (contextId(), flags, type, mipmapLevel, texture, &error); reportError("QCLContextGL::createGLTexture2D:", error); if (mem) return QCLImage2D(this, mem); else return QCLImage2D(); #else Q_UNUSED(type); Q_UNUSED(texture); Q_UNUSED(mipmapLevel); Q_UNUSED(access); reportError("QCLContextGL::createGLTexture2D:", CL_INVALID_VALUE); return QCLImage2D(); #endif }