stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_EIGEN_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_EIGEN_HPP
|
||||
|
||||
#include <boost/compute/interop/eigen/core.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_EIGEN_HPP
|
||||
@@ -0,0 +1,72 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
#include <boost/compute/algorithm/copy_n.hpp>
|
||||
#include <boost/compute/iterator/buffer_iterator.hpp>
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Copies \p matrix to \p buffer.
|
||||
template<class Derived>
|
||||
inline void eigen_copy_matrix_to_buffer(const Eigen::PlainObjectBase<Derived> &matrix,
|
||||
buffer_iterator<typename Derived::Scalar> buffer,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
::boost::compute::copy_n(matrix.data(), matrix.size(), buffer, queue);
|
||||
}
|
||||
|
||||
/// Copies \p buffer to \p matrix.
|
||||
template<class Derived>
|
||||
inline void eigen_copy_buffer_to_matrix(const buffer_iterator<typename Derived::Scalar> buffer,
|
||||
Eigen::PlainObjectBase<Derived> &matrix,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
::boost::compute::copy_n(buffer, matrix.size(), matrix.data(), queue);
|
||||
}
|
||||
|
||||
/// Converts an \c Eigen::Matrix4f to a \c float16_.
|
||||
inline float16_ eigen_matrix4f_to_float16(const Eigen::Matrix4f &matrix)
|
||||
{
|
||||
float16_ result;
|
||||
std::memcpy(&result, matrix.data(), 16 * sizeof(float));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts an \c Eigen::Matrix4d to a \c double16_.
|
||||
inline double16_ eigen_matrix4d_to_double16(const Eigen::Matrix4d &matrix)
|
||||
{
|
||||
double16_ result;
|
||||
std::memcpy(&result, matrix.data(), 16 * sizeof(double));
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2i, int2)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4i, int4)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2f, float2)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4f, float4)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2f, float8)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4f, float16)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2d, double2)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4d, double4)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2d, double8)
|
||||
BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4d, double16)
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
|
||||
@@ -0,0 +1,17 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENCV_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENCV_HPP
|
||||
|
||||
#include <boost/compute/interop/opencv/core.hpp>
|
||||
#include <boost/compute/interop/opencv/highgui.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENCV_HPP
|
||||
@@ -0,0 +1,141 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENCV_CORE_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENCV_CORE_HPP
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/compute/algorithm/copy_n.hpp>
|
||||
#include <boost/compute/exception/opencl_error.hpp>
|
||||
#include <boost/compute/image/image2d.hpp>
|
||||
#include <boost/compute/image/image_format.hpp>
|
||||
#include <boost/compute/iterator/buffer_iterator.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
template<class T>
|
||||
inline void opencv_copy_mat_to_buffer(const cv::Mat &mat,
|
||||
buffer_iterator<T> buffer,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
BOOST_ASSERT(mat.isContinuous());
|
||||
|
||||
::boost::compute::copy_n(
|
||||
reinterpret_cast<T *>(mat.data), mat.rows * mat.cols, buffer, queue
|
||||
);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void opencv_copy_buffer_to_mat(const buffer_iterator<T> buffer,
|
||||
cv::Mat &mat,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
BOOST_ASSERT(mat.isContinuous());
|
||||
|
||||
::boost::compute::copy_n(
|
||||
buffer, mat.cols * mat.rows, reinterpret_cast<T *>(mat.data), queue
|
||||
);
|
||||
}
|
||||
|
||||
inline void opencv_copy_mat_to_image(const cv::Mat &mat,
|
||||
image2d &image,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
BOOST_ASSERT(mat.data != 0);
|
||||
BOOST_ASSERT(mat.isContinuous());
|
||||
BOOST_ASSERT(image.get_context() == queue.get_context());
|
||||
|
||||
queue.enqueue_write_image(image, image.origin(), image.size(), mat.data);
|
||||
}
|
||||
|
||||
inline void opencv_copy_image_to_mat(const image2d &image,
|
||||
cv::Mat &mat,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
BOOST_ASSERT(mat.isContinuous());
|
||||
BOOST_ASSERT(image.get_context() == queue.get_context());
|
||||
|
||||
queue.enqueue_read_image(image, image.origin(), image.size(), mat.data);
|
||||
}
|
||||
|
||||
inline image_format opencv_get_mat_image_format(const cv::Mat &mat)
|
||||
{
|
||||
switch(mat.type()){
|
||||
case CV_8UC4:
|
||||
return image_format(CL_BGRA, CL_UNORM_INT8);
|
||||
case CV_16UC4:
|
||||
return image_format(CL_BGRA, CL_UNORM_INT16);
|
||||
case CV_32F:
|
||||
return image_format(CL_INTENSITY, CL_FLOAT);
|
||||
case CV_32FC4:
|
||||
return image_format(CL_RGBA, CL_FLOAT);
|
||||
case CV_8UC1:
|
||||
return image_format(CL_INTENSITY, CL_UNORM_INT8);
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
|
||||
}
|
||||
|
||||
inline cv::Mat opencv_create_mat_with_image2d(const image2d &image,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
BOOST_ASSERT(image.get_context() == queue.get_context());
|
||||
|
||||
cv::Mat mat;
|
||||
image_format format = image.get_format();
|
||||
const cl_image_format *cl_image_format = format.get_format_ptr();
|
||||
|
||||
if(cl_image_format->image_channel_data_type == CL_UNORM_INT8 &&
|
||||
cl_image_format->image_channel_order == CL_BGRA)
|
||||
{
|
||||
mat = cv::Mat(image.height(), image.width(), CV_8UC4);
|
||||
}
|
||||
else if(cl_image_format->image_channel_data_type == CL_UNORM_INT16 &&
|
||||
cl_image_format->image_channel_order == CL_BGRA)
|
||||
{
|
||||
mat = cv::Mat(image.height(), image.width(), CV_16UC4);
|
||||
}
|
||||
else if(cl_image_format->image_channel_data_type == CL_FLOAT &&
|
||||
cl_image_format->image_channel_order == CL_INTENSITY)
|
||||
{
|
||||
mat = cv::Mat(image.height(), image.width(), CV_32FC1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = cv::Mat(image.height(), image.width(), CV_8UC1);
|
||||
}
|
||||
|
||||
opencv_copy_image_to_mat(image, mat, queue);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
inline image2d opencv_create_image2d_with_mat(const cv::Mat &mat,
|
||||
cl_mem_flags flags,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
const context &context = queue.get_context();
|
||||
const image_format format = opencv_get_mat_image_format(mat);
|
||||
|
||||
image2d image(context, mat.cols, mat.rows, format, flags);
|
||||
|
||||
opencv_copy_mat_to_image(mat, image, queue);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENCV_CORE_HPP
|
||||
@@ -0,0 +1,33 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENCV_HIGHGUI_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENCV_HIGHGUI_HPP
|
||||
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
|
||||
#include <boost/compute/interop/opencv/core.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
inline void opencv_imshow(const std::string &winname,
|
||||
const image2d &image,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
const cv::Mat mat = opencv_create_mat_with_image2d(image, queue);
|
||||
|
||||
cv::imshow(winname, mat);
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENCV_HIGHGUI_HPP
|
||||
@@ -0,0 +1,51 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENCV_OCL_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENCV_OCL_HPP
|
||||
|
||||
#include <opencv2/ocl/ocl.hpp>
|
||||
|
||||
#include <boost/compute/buffer.hpp>
|
||||
#include <boost/compute/context.hpp>
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
context opencv_ocl_get_context()
|
||||
{
|
||||
void *ocl_context = cv::ocl::getoclContext();
|
||||
if(!ocl_context){
|
||||
return context();
|
||||
}
|
||||
|
||||
return context(*(static_cast<cl_context *>(ocl_context)));
|
||||
}
|
||||
|
||||
command_queue opencv_ocl_get_command_queue()
|
||||
{
|
||||
void *ocl_queue = cv::ocl::getoclCommandQueue();
|
||||
if(!ocl_queue){
|
||||
return command_queue();
|
||||
}
|
||||
|
||||
return command_queue(*(static_cast<cl_command_queue *>(ocl_queue)));
|
||||
}
|
||||
|
||||
buffer opencv_ocl_get_buffer(const cv::ocl::oclMat &mat)
|
||||
{
|
||||
return buffer(reinterpret_cast<cl_mem>(mat.data));
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENCV_OCL_HPP
|
||||
@@ -0,0 +1,24 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_HPP
|
||||
|
||||
/// \file
|
||||
///
|
||||
/// Meta-header to include all Boost.Compute OpenGL interop headers.
|
||||
|
||||
#include <boost/compute/interop/opengl/acquire.hpp>
|
||||
#include <boost/compute/interop/opengl/context.hpp>
|
||||
#include <boost/compute/interop/opengl/opengl_buffer.hpp>
|
||||
#include <boost/compute/interop/opengl/opengl_renderbuffer.hpp>
|
||||
#include <boost/compute/interop/opengl/opengl_texture.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_HPP
|
||||
@@ -0,0 +1,100 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
|
||||
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
#include <boost/compute/interop/opengl/cl_gl.hpp>
|
||||
#include <boost/compute/interop/opengl/opengl_buffer.hpp>
|
||||
#include <boost/compute/types/fundamental.hpp>
|
||||
#include <boost/compute/utility/wait_list.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Enqueues a command to acquire the specified OpenGL memory objects.
|
||||
///
|
||||
/// \see_opencl_ref{clEnqueueAcquireGLObjects}
|
||||
inline event opengl_enqueue_acquire_gl_objects(const uint_ num_objects,
|
||||
const cl_mem *mem_objects,
|
||||
command_queue &queue,
|
||||
const wait_list &events = wait_list())
|
||||
{
|
||||
BOOST_ASSERT(queue != 0);
|
||||
|
||||
event event_;
|
||||
|
||||
cl_int ret = clEnqueueAcquireGLObjects(queue.get(),
|
||||
num_objects,
|
||||
mem_objects,
|
||||
events.size(),
|
||||
events.get_event_ptr(),
|
||||
&event_.get());
|
||||
if(ret != CL_SUCCESS){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(ret));
|
||||
}
|
||||
|
||||
return event_;
|
||||
}
|
||||
|
||||
/// Enqueues a command to release the specified OpenGL memory objects.
|
||||
///
|
||||
/// \see_opencl_ref{clEnqueueReleaseGLObjects}
|
||||
inline event opengl_enqueue_release_gl_objects(const uint_ num_objects,
|
||||
const cl_mem *mem_objects,
|
||||
command_queue &queue,
|
||||
const wait_list &events = wait_list())
|
||||
{
|
||||
BOOST_ASSERT(queue != 0);
|
||||
|
||||
event event_;
|
||||
|
||||
cl_int ret = clEnqueueReleaseGLObjects(queue.get(),
|
||||
num_objects,
|
||||
mem_objects,
|
||||
events.size(),
|
||||
events.get_event_ptr(),
|
||||
&event_.get());
|
||||
if(ret != CL_SUCCESS){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(ret));
|
||||
}
|
||||
|
||||
return event_;
|
||||
}
|
||||
|
||||
/// Enqueues a command to acquire the specified OpenGL buffer.
|
||||
///
|
||||
/// \see_opencl_ref{clEnqueueAcquireGLObjects}
|
||||
inline event opengl_enqueue_acquire_buffer(const opengl_buffer &buffer,
|
||||
command_queue &queue,
|
||||
const wait_list &events = wait_list())
|
||||
{
|
||||
BOOST_ASSERT(buffer.get_context() == queue.get_context());
|
||||
|
||||
return opengl_enqueue_acquire_gl_objects(1, &buffer.get(), queue, events);
|
||||
}
|
||||
|
||||
/// Enqueues a command to release the specified OpenGL buffer.
|
||||
///
|
||||
/// \see_opencl_ref{clEnqueueReleaseGLObjects}
|
||||
inline event opengl_enqueue_release_buffer(const opengl_buffer &buffer,
|
||||
command_queue &queue,
|
||||
const wait_list &events = wait_list())
|
||||
{
|
||||
BOOST_ASSERT(buffer.get_context() == queue.get_context());
|
||||
|
||||
return opengl_enqueue_release_gl_objects(1, &buffer.get(), queue, events);
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
|
||||
@@ -0,0 +1,20 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_HPP
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenCL/cl_gl.h>
|
||||
#else
|
||||
#include <CL/cl_gl.h>
|
||||
#endif
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_HPP
|
||||
@@ -0,0 +1,20 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_EXT_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_EXT_HPP
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenCL/cl_gl_ext.h>
|
||||
#else
|
||||
#include <CL/cl_gl_ext.h>
|
||||
#endif
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_EXT_HPP
|
||||
@@ -0,0 +1,135 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_CONTEXT_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_CONTEXT_HPP
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/compute/device.hpp>
|
||||
#include <boost/compute/system.hpp>
|
||||
#include <boost/compute/context.hpp>
|
||||
#include <boost/compute/exception/unsupported_extension_error.hpp>
|
||||
#include <boost/compute/interop/opengl/cl_gl.hpp>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenCL/cl_gl_ext.h>
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Creates a shared OpenCL/OpenGL context for the currently active
|
||||
/// OpenGL context.
|
||||
///
|
||||
/// Once created, the shared context can be used to create OpenCL memory
|
||||
/// objects which can interact with OpenGL memory objects (e.g. VBOs).
|
||||
///
|
||||
/// \throws unsupported_extension_error if no CL-GL sharing capable devices
|
||||
/// are found.
|
||||
inline context opengl_create_shared_context()
|
||||
{
|
||||
// name of the OpenGL sharing extension for the system
|
||||
#if defined(__APPLE__)
|
||||
const char *cl_gl_sharing_extension = "cl_APPLE_gl_sharing";
|
||||
#else
|
||||
const char *cl_gl_sharing_extension = "cl_khr_gl_sharing";
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// get OpenGL share group
|
||||
CGLContextObj cgl_current_context = CGLGetCurrentContext();
|
||||
CGLShareGroupObj cgl_share_group = CGLGetShareGroup(cgl_current_context);
|
||||
|
||||
cl_context_properties properties[] = {
|
||||
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
|
||||
(cl_context_properties) cgl_share_group,
|
||||
0
|
||||
};
|
||||
|
||||
cl_int error = 0;
|
||||
cl_context cl_gl_context = clCreateContext(properties, 0, 0, 0, 0, &error);
|
||||
if(!cl_gl_context){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
|
||||
return context(cl_gl_context, false);
|
||||
#else
|
||||
typedef cl_int(*GetGLContextInfoKHRFunction)(
|
||||
const cl_context_properties*, cl_gl_context_info, size_t, void *, size_t *
|
||||
);
|
||||
|
||||
std::vector<platform> platforms = system::platforms();
|
||||
for(size_t i = 0; i < platforms.size(); i++){
|
||||
const platform &platform = platforms[i];
|
||||
|
||||
// load clGetGLContextInfoKHR() extension function
|
||||
GetGLContextInfoKHRFunction GetGLContextInfoKHR =
|
||||
reinterpret_cast<GetGLContextInfoKHRFunction>(
|
||||
reinterpret_cast<size_t>(
|
||||
platform.get_extension_function_address("clGetGLContextInfoKHR")
|
||||
)
|
||||
);
|
||||
if(!GetGLContextInfoKHR){
|
||||
continue;
|
||||
}
|
||||
|
||||
// create context properties listing the platform and current OpenGL display
|
||||
cl_context_properties properties[] = {
|
||||
CL_CONTEXT_PLATFORM, (cl_context_properties) platform.id(),
|
||||
#if defined(__linux__)
|
||||
CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext(),
|
||||
CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay(),
|
||||
#elif defined(WIN32)
|
||||
CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
|
||||
CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
|
||||
#endif
|
||||
0
|
||||
};
|
||||
|
||||
// lookup current OpenCL device for current OpenGL context
|
||||
cl_device_id gpu_id;
|
||||
cl_int ret = GetGLContextInfoKHR(
|
||||
properties,
|
||||
CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,
|
||||
sizeof(cl_device_id),
|
||||
&gpu_id,
|
||||
0
|
||||
);
|
||||
if(ret != CL_SUCCESS){
|
||||
continue;
|
||||
}
|
||||
|
||||
// create device object for the GPU and ensure it supports CL-GL sharing
|
||||
device gpu(gpu_id, false);
|
||||
if(!gpu.supports_extension(cl_gl_sharing_extension)){
|
||||
continue;
|
||||
}
|
||||
|
||||
// return CL-GL sharing context
|
||||
return context(gpu, properties);
|
||||
}
|
||||
#endif
|
||||
|
||||
// no CL-GL sharing capable devices found
|
||||
BOOST_THROW_EXCEPTION(
|
||||
unsupported_extension_error(cl_gl_sharing_extension)
|
||||
);
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_CONTEXT_HPP
|
||||
@@ -0,0 +1,20 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_GL_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_GL_HPP
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_GL_HPP
|
||||
@@ -0,0 +1,106 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP
|
||||
|
||||
#include <boost/compute/buffer.hpp>
|
||||
#include <boost/compute/interop/opengl/gl.hpp>
|
||||
#include <boost/compute/interop/opengl/cl_gl.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// \class opengl_buffer
|
||||
///
|
||||
/// A OpenCL buffer for accessing an OpenGL memory object.
|
||||
class opengl_buffer : public buffer
|
||||
{
|
||||
public:
|
||||
/// Creates a null OpenGL buffer object.
|
||||
opengl_buffer()
|
||||
: buffer()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL buffer object for \p mem.
|
||||
explicit opengl_buffer(cl_mem mem, bool retain = true)
|
||||
: buffer(mem, retain)
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL buffer object in \p context for \p bufobj
|
||||
/// with \p flags.
|
||||
///
|
||||
/// \see_opencl_ref{clCreateFromGLBuffer}
|
||||
opengl_buffer(const context &context,
|
||||
GLuint bufobj,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
cl_int error = 0;
|
||||
m_mem = clCreateFromGLBuffer(context, flags, bufobj, &error);
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL buffer object as a copy of \p other.
|
||||
opengl_buffer(const opengl_buffer &other)
|
||||
: buffer(other)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the OpenGL buffer object from \p other.
|
||||
opengl_buffer& operator=(const opengl_buffer &other)
|
||||
{
|
||||
if(this != &other){
|
||||
buffer::operator=(other);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Destroys the OpenGL buffer object.
|
||||
~opengl_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the OpenGL memory object ID.
|
||||
///
|
||||
/// \see_opencl_ref{clGetGLObjectInfo}
|
||||
GLuint get_opengl_object() const
|
||||
{
|
||||
GLuint object = 0;
|
||||
clGetGLObjectInfo(m_mem, 0, &object);
|
||||
return object;
|
||||
}
|
||||
|
||||
/// Returns the OpenGL memory object type.
|
||||
///
|
||||
/// \see_opencl_ref{clGetGLObjectInfo}
|
||||
cl_gl_object_type get_opengl_type() const
|
||||
{
|
||||
cl_gl_object_type type;
|
||||
clGetGLObjectInfo(m_mem, &type, 0);
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// set_kernel_arg specialization for opengl_buffer
|
||||
template<>
|
||||
struct set_kernel_arg<opengl_buffer> : set_kernel_arg<memory_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP
|
||||
|
||||
#include <boost/compute/image/image_object.hpp>
|
||||
#include <boost/compute/interop/opengl/gl.hpp>
|
||||
#include <boost/compute/interop/opengl/cl_gl.hpp>
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
#include <boost/compute/utility/extents.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// \class opengl_renderbuffer
|
||||
///
|
||||
/// A OpenCL buffer for accessing an OpenGL renderbuffer object.
|
||||
class opengl_renderbuffer : public image_object
|
||||
{
|
||||
public:
|
||||
/// Creates a null OpenGL renderbuffer object.
|
||||
opengl_renderbuffer()
|
||||
: image_object()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL renderbuffer object for \p mem.
|
||||
explicit opengl_renderbuffer(cl_mem mem, bool retain = true)
|
||||
: image_object(mem, retain)
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL renderbuffer object in \p context for
|
||||
/// \p renderbuffer with \p flags.
|
||||
///
|
||||
/// \see_opencl_ref{clCreateFromGLRenderbuffer}
|
||||
opengl_renderbuffer(const context &context,
|
||||
GLuint renderbuffer,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
m_mem = clCreateFromGLRenderbuffer(
|
||||
context, flags, renderbuffer, &error
|
||||
);
|
||||
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL renderbuffer object as a copy of \p other.
|
||||
opengl_renderbuffer(const opengl_renderbuffer &other)
|
||||
: image_object(other)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the OpenGL renderbuffer object from \p other.
|
||||
opengl_renderbuffer& operator=(const opengl_renderbuffer &other)
|
||||
{
|
||||
if(this != &other){
|
||||
image_object::operator=(other);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Destroys the OpenGL buffer object.
|
||||
~opengl_renderbuffer()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the size (width, height) of the renderbuffer.
|
||||
extents<2> size() const
|
||||
{
|
||||
extents<2> size;
|
||||
size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
|
||||
size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Returns the origin of the renderbuffer (\c 0, \c 0).
|
||||
extents<2> origin() const
|
||||
{
|
||||
return extents<2>();
|
||||
}
|
||||
|
||||
/// Returns the OpenGL memory object ID.
|
||||
///
|
||||
/// \see_opencl_ref{clGetGLObjectInfo}
|
||||
GLuint get_opengl_object() const
|
||||
{
|
||||
GLuint object = 0;
|
||||
clGetGLObjectInfo(m_mem, 0, &object);
|
||||
return object;
|
||||
}
|
||||
|
||||
/// Returns the OpenGL memory object type.
|
||||
///
|
||||
/// \see_opencl_ref{clGetGLObjectInfo}
|
||||
cl_gl_object_type get_opengl_type() const
|
||||
{
|
||||
cl_gl_object_type type;
|
||||
clGetGLObjectInfo(m_mem, &type, 0);
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// set_kernel_arg() specialization for opengl_renderbuffer
|
||||
template<>
|
||||
struct set_kernel_arg<opengl_renderbuffer> : public set_kernel_arg<image_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_renderbuffer, image2d_t)
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP
|
||||
@@ -0,0 +1,133 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
|
||||
|
||||
#include <boost/compute/image/image_object.hpp>
|
||||
#include <boost/compute/interop/opengl/gl.hpp>
|
||||
#include <boost/compute/interop/opengl/cl_gl.hpp>
|
||||
#include <boost/compute/detail/get_object_info.hpp>
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
#include <boost/compute/utility/extents.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// \class opengl_texture
|
||||
///
|
||||
/// A OpenCL image2d for accessing an OpenGL texture object.
|
||||
class opengl_texture : public image_object
|
||||
{
|
||||
public:
|
||||
/// Creates a null OpenGL texture object.
|
||||
opengl_texture()
|
||||
: image_object()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL texture object for \p mem.
|
||||
explicit opengl_texture(cl_mem mem, bool retain = true)
|
||||
: image_object(mem, retain)
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL texture object in \p context for \p texture
|
||||
/// with \p flags.
|
||||
///
|
||||
/// \see_opencl_ref{clCreateFromGLTexture}
|
||||
opengl_texture(const context &context,
|
||||
GLenum texture_target,
|
||||
GLint miplevel,
|
||||
GLuint texture,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
#ifdef CL_VERSION_1_2
|
||||
m_mem = clCreateFromGLTexture(context,
|
||||
flags,
|
||||
texture_target,
|
||||
miplevel,
|
||||
texture,
|
||||
&error);
|
||||
#else
|
||||
m_mem = clCreateFromGLTexture2D(context,
|
||||
flags,
|
||||
texture_target,
|
||||
miplevel,
|
||||
texture,
|
||||
&error);
|
||||
#endif
|
||||
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new OpenGL texture object as a copy of \p other.
|
||||
opengl_texture(const opengl_texture &other)
|
||||
: image_object(other)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the OpenGL texture object from \p other.
|
||||
opengl_texture& operator=(const opengl_texture &other)
|
||||
{
|
||||
if(this != &other){
|
||||
image_object::operator=(other);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Destroys the texture object.
|
||||
~opengl_texture()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the size (width, height) of the texture.
|
||||
extents<2> size() const
|
||||
{
|
||||
extents<2> size;
|
||||
size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
|
||||
size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Returns the origin of the texture (\c 0, \c 0).
|
||||
extents<2> origin() const
|
||||
{
|
||||
return extents<2>();
|
||||
}
|
||||
|
||||
/// Returns information about the texture.
|
||||
///
|
||||
/// \see_opencl_ref{clGetGLTextureInfo}
|
||||
template<class T>
|
||||
T get_texture_info(cl_gl_texture_info info) const
|
||||
{
|
||||
return detail::get_object_info<T>(clGetGLTextureInfo, m_mem, info);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// set_kernel_arg() specialization for opengl_texture
|
||||
template<>
|
||||
struct set_kernel_arg<opengl_texture> : public set_kernel_arg<image_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_texture, image2d_t)
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_TEXTURE_HPP
|
||||
@@ -0,0 +1,17 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_HPP
|
||||
|
||||
#include <boost/compute/interop/qt/qtcore.hpp>
|
||||
#include <boost/compute/interop/qt/qtgui.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_HPP
|
||||
@@ -0,0 +1,69 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
#include <boost/compute/exception/opencl_error.hpp>
|
||||
#include <boost/compute/image/image2d.hpp>
|
||||
#include <boost/compute/image/image_format.hpp>
|
||||
#include <boost/compute/utility/dim.hpp>
|
||||
|
||||
#include <QImage>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
inline image_format qt_qimage_format_to_image_format(const QImage::Format &format)
|
||||
{
|
||||
if(format == QImage::Format_RGB32){
|
||||
return image_format(image_format::bgra, image_format::unorm_int8);
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
|
||||
}
|
||||
|
||||
inline QImage::Format qt_image_format_to_qimage_format(const image_format &format)
|
||||
{
|
||||
if(format == image_format(image_format::bgra, image_format::unorm_int8)){
|
||||
return QImage::Format_RGB32;
|
||||
}
|
||||
|
||||
return QImage::Format_Invalid;
|
||||
}
|
||||
|
||||
inline image_format qt_qimage_get_format(const QImage &image)
|
||||
{
|
||||
return qt_qimage_format_to_image_format(image.format());
|
||||
}
|
||||
|
||||
inline void qt_copy_qimage_to_image2d(const QImage &qimage,
|
||||
image2d &image,
|
||||
command_queue &queue)
|
||||
{
|
||||
queue.enqueue_write_image(image, image.origin(), image.size(), qimage.constBits());
|
||||
}
|
||||
|
||||
inline void qt_copy_image2d_to_qimage(const image2d &image,
|
||||
QImage &qimage,
|
||||
command_queue &queue)
|
||||
{
|
||||
queue.enqueue_read_image(
|
||||
image, dim(0, 0), dim(qimage.width(), qimage.height()), qimage.bits()
|
||||
);
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
|
||||
@@ -0,0 +1,20 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_QPOINT_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_QPOINT_HPP
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(QPoint, "int2")
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_QPOINT_HPP
|
||||
@@ -0,0 +1,20 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_QPOINTF_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_QPOINTF_HPP
|
||||
|
||||
#include <QPointF>
|
||||
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(QPointF, "float2")
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_QPOINTF_HPP
|
||||
@@ -0,0 +1,18 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_QTCORE_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_QTCORE_HPP
|
||||
|
||||
#include <boost/compute/interop/qt/qpoint.hpp>
|
||||
#include <boost/compute/interop/qt/qpointf.hpp>
|
||||
#include <boost/compute/interop/qt/qvector.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_QTCORE_HPP
|
||||
@@ -0,0 +1,16 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_QTGUI_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_QTGUI_HPP
|
||||
|
||||
#include <boost/compute/interop/qt/qimage.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_QTGUI_HPP
|
||||
@@ -0,0 +1,48 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_QT_QVECTOR_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_QT_QVECTOR_HPP
|
||||
|
||||
#include <boost/compute/detail/is_contiguous_iterator.hpp>
|
||||
|
||||
#include <QVector>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
namespace detail {
|
||||
|
||||
template<class Iterator>
|
||||
struct _is_contiguous_iterator<
|
||||
Iterator,
|
||||
typename boost::enable_if<
|
||||
typename boost::is_same<
|
||||
Iterator,
|
||||
typename QVector<typename Iterator::value_type>::iterator
|
||||
>::type
|
||||
>::type
|
||||
> : public boost::true_type {};
|
||||
|
||||
template<class Iterator>
|
||||
struct _is_contiguous_iterator<
|
||||
Iterator,
|
||||
typename boost::enable_if<
|
||||
typename boost::is_same<
|
||||
Iterator,
|
||||
typename QVector<typename Iterator::value_type>::const_iterator
|
||||
>::type
|
||||
>::type
|
||||
> : public boost::true_type {};
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_QT_QVECTOR_HPP
|
||||
@@ -0,0 +1,19 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_VTK_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_VTK_HPP
|
||||
|
||||
#include <boost/compute/interop/vtk/bounds.hpp>
|
||||
#include <boost/compute/interop/vtk/data_array.hpp>
|
||||
#include <boost/compute/interop/vtk/matrix4x4.hpp>
|
||||
#include <boost/compute/interop/vtk/points.hpp>
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_VTK_HPP
|
||||
@@ -0,0 +1,59 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/compute/system.hpp>
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
#include <boost/compute/algorithm/copy_n.hpp>
|
||||
#include <boost/compute/algorithm/reduce.hpp>
|
||||
#include <boost/compute/container/array.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Calculates the bounds for the points in the range [\p first, \p last) and
|
||||
/// stores the result in \p bounds.
|
||||
///
|
||||
/// For example, this can be used to implement the GetBounds() method for a
|
||||
/// vtkMapper subclass.
|
||||
template<class PointIterator>
|
||||
inline void vtk_compute_bounds(PointIterator first,
|
||||
PointIterator last,
|
||||
double bounds[6],
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
typedef typename std::iterator_traits<PointIterator>::value_type T;
|
||||
|
||||
const context &context = queue.get_context();
|
||||
|
||||
// compute min and max point
|
||||
array<T, 2> extrema(context);
|
||||
reduce(first, last, extrema.begin() + 0, min<T>(), queue);
|
||||
reduce(first, last, extrema.begin() + 1, max<T>(), queue);
|
||||
|
||||
// copy results to host buffer
|
||||
std::vector<T> buffer(2);
|
||||
copy_n(extrema.begin(), 2, buffer.begin(), queue);
|
||||
|
||||
// copy to vtk-style bounds
|
||||
bounds[0] = buffer[0][0]; bounds[1] = buffer[1][0];
|
||||
bounds[2] = buffer[0][1]; bounds[3] = buffer[1][1];
|
||||
bounds[4] = buffer[0][2]; bounds[5] = buffer[1][2];
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
|
||||
@@ -0,0 +1,65 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_VTK_DATA_ARRAY_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_VTK_DATA_ARRAY_HPP
|
||||
|
||||
#include <vtkDataArray.h>
|
||||
#include <vtkDataArrayTemplate.h>
|
||||
|
||||
#include <boost/compute/system.hpp>
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
#include <boost/compute/algorithm/copy.hpp>
|
||||
#include <boost/compute/algorithm/copy_n.hpp>
|
||||
#include <boost/compute/iterator/buffer_iterator.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Copies the values in \p data to \p buffer.
|
||||
template<class T>
|
||||
inline void vtk_copy_data_array_to_buffer(const vtkDataArray *data,
|
||||
buffer_iterator<T> buffer,
|
||||
command_queue &queue = system::default_queue());
|
||||
|
||||
/// \internal_
|
||||
template<class T>
|
||||
inline void vtk_copy_data_array_to_buffer(const vtkDataArrayTemplate<T> *data,
|
||||
buffer_iterator<T> buffer,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
vtkDataArrayTemplate<T> *data_ = const_cast<vtkDataArrayTemplate<T> *>(data);
|
||||
const T *data_ptr = static_cast<const T *>(data_->GetVoidPointer(0));
|
||||
size_t data_size = data_->GetNumberOfComponents() * data_->GetNumberOfTuples();
|
||||
::boost::compute::copy_n(data_ptr, data_size, buffer, queue);
|
||||
}
|
||||
|
||||
/// Copies the values in the range [\p first, \p last) to \p data.
|
||||
template<class T>
|
||||
inline void vtk_copy_buffer_to_data_array(buffer_iterator<T> first,
|
||||
buffer_iterator<T> last,
|
||||
vtkDataArray *data,
|
||||
command_queue &queue = system::default_queue());
|
||||
|
||||
/// \internal_
|
||||
template<class T>
|
||||
inline void vtk_copy_buffer_to_data_array(buffer_iterator<T> first,
|
||||
buffer_iterator<T> last,
|
||||
vtkDataArrayTemplate<T> *data,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
T *data_ptr = static_cast<T *>(data->GetVoidPointer(0));
|
||||
::boost::compute::copy(first, last, data_ptr, queue);
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_VTK_DATA_ARRAY_HPP
|
||||
@@ -0,0 +1,46 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_VTK_MATRIX4X4_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_VTK_MATRIX4X4_HPP
|
||||
|
||||
#include <vtkMatrix4x4.h>
|
||||
|
||||
#include <boost/compute/types/fundamental.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Converts a \c vtkMatrix4x4 to a \c float16_.
|
||||
inline float16_ vtk_matrix4x4_to_float16(const vtkMatrix4x4 *matrix)
|
||||
{
|
||||
float16_ result;
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
for(int j = 0; j < 4; j++){
|
||||
result[i*4+j] = matrix->GetElement(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts a \c vtkMatrix4x4 to a \c double16_;
|
||||
inline double16_ vtk_matrix4x4_to_double16(const vtkMatrix4x4 *matrix)
|
||||
{
|
||||
double16_ result;
|
||||
std::memcpy(&result, matrix->Element, 16 * sizeof(double));
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_VTK_MATRIX4X4_HPP
|
||||
@@ -0,0 +1,55 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_INTEROP_VTK_POINTS_HPP
|
||||
#define BOOST_COMPUTE_INTEROP_VTK_POINTS_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <vtkPoints.h>
|
||||
|
||||
#include <boost/compute/system.hpp>
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
#include <boost/compute/algorithm/copy.hpp>
|
||||
#include <boost/compute/iterator/buffer_iterator.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Copies \p points to \p buffer.
|
||||
///
|
||||
/// For example, to copy from a \c vtkPoints object to a \c vector<float4_>:
|
||||
/// \code
|
||||
/// vtkPoints *points = ...
|
||||
/// vector<float4_> vector(points->GetNumberOfPoints(), context);
|
||||
/// vtk_copy_points_to_buffer(points, vector.begin(), queue);
|
||||
/// \endcode
|
||||
template<class PointType>
|
||||
inline void vtk_copy_points_to_buffer(const vtkPoints *points,
|
||||
buffer_iterator<PointType> buffer,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
vtkPoints *points_ = const_cast<vtkPoints *>(points);
|
||||
|
||||
// copy points to aligned buffer
|
||||
std::vector<PointType> tmp(points_->GetNumberOfPoints());
|
||||
for(vtkIdType i = 0; i < points_->GetNumberOfPoints(); i++){
|
||||
double *p = points_->GetPoint(i);
|
||||
tmp[i] = PointType(p[0], p[1], p[2], 1);
|
||||
}
|
||||
|
||||
// copy data to device
|
||||
copy(tmp.begin(), tmp.end(), buffer, queue);
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_INTEROP_VTK_POINTS_HPP
|
||||
Reference in New Issue
Block a user