|
|
@@ -9,11 +9,15 @@
|
|
|
|
|
|
#include <boost/core/noncopyable.hpp>
|
|
|
|
|
|
+#include <filesystem>
|
|
|
+
|
|
|
+extern std::filesystem::path shader_folder;
|
|
|
+
|
|
|
cv::Size query_viewport_size();
|
|
|
|
|
|
void check_framebuffer();
|
|
|
|
|
|
-GLuint compile_shader(GLenum type, const char *path);
|
|
|
+GLuint compile_shader(GLenum type, const char *filename);
|
|
|
|
|
|
void check_program(const char *name, GLuint id);
|
|
|
|
|
|
@@ -48,36 +52,42 @@ struct simple_rect {
|
|
|
simple_rect fit_aspect(float aspect) const;
|
|
|
};
|
|
|
|
|
|
-// only upload
|
|
|
-class smart_texture : private boost::noncopyable {
|
|
|
+class smart_pixel_buffer : private boost::noncopyable {
|
|
|
public:
|
|
|
GLuint id = 0;
|
|
|
- GLenum format = 0;
|
|
|
- cv::Size size;
|
|
|
+ GLsizeiptr size = 0;
|
|
|
|
|
|
// used for CUDA inter-op
|
|
|
- cudaGraphicsResource_t cuda_res = nullptr;
|
|
|
+ cudaGraphicsResource_t cuda_res_up = nullptr; // for upload
|
|
|
+ cudaGraphicsResource_t cuda_res_down = nullptr; // for download
|
|
|
std::shared_ptr<void> img_ptr;
|
|
|
|
|
|
- ~smart_texture();
|
|
|
+ ~smart_pixel_buffer();
|
|
|
|
|
|
- void create(GLenum format, cv::Size size);
|
|
|
+ void create(GLsizeiptr size);
|
|
|
|
|
|
- void set_filter(GLint min_filter, GLint max_filter);
|
|
|
+ // download from current viewport
|
|
|
+ void download_viewport(GLenum format, GLenum type);
|
|
|
|
|
|
template<typename T>
|
|
|
void upload(const image_info_type<T> &img, smart_cuda_stream *stream) {
|
|
|
- // direct upload only supports 1, 2 or 4 components
|
|
|
- static_assert(!std::is_same_v<T, uchar3>);
|
|
|
-
|
|
|
- create(get_tex_internal_format<T>(), img.size);
|
|
|
+ create(sizeof(T) * img.size.area());
|
|
|
upload_impl(img.mem_info(), stream);
|
|
|
}
|
|
|
|
|
|
template<typename T>
|
|
|
- void upload(GLuint pbo_id, cv::Size _size) {
|
|
|
- create(get_tex_internal_format<T>(), _size);
|
|
|
- upload_impl(pbo_id, get_tex_format<T>(), get_tex_type<T>());
|
|
|
+ void download(const image_info_type<T> &img, smart_cuda_stream *stream) {
|
|
|
+ assert(size == sizeof(T) * img.size.area());
|
|
|
+ download_impl(img.mem_info(), stream);
|
|
|
+ }
|
|
|
+
|
|
|
+ // memory location maintains as img->loc.
|
|
|
+ template<typename T>
|
|
|
+ void download_viewport(image_info_type<T> *img, GLenum format,
|
|
|
+ GLenum type, smart_cuda_stream *stream) {
|
|
|
+ img->create(query_viewport_size(), img->loc);
|
|
|
+ download_viewport(format, type);
|
|
|
+ download(*img, stream);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -86,46 +96,47 @@ private:
|
|
|
|
|
|
void upload_impl(const image_mem_info &img, smart_cuda_stream *stream);
|
|
|
|
|
|
- void upload_impl(GLuint pbo_id, GLenum format, GLenum type);
|
|
|
+ void download_impl(const image_mem_info &img, smart_cuda_stream *stream);
|
|
|
|
|
|
};
|
|
|
|
|
|
-class smart_pixel_buffer : private boost::noncopyable {
|
|
|
+// only upload
|
|
|
+class smart_texture : private boost::noncopyable {
|
|
|
public:
|
|
|
GLuint id = 0;
|
|
|
- GLsizeiptr size = 0;
|
|
|
+ GLenum format = 0;
|
|
|
+ cv::Size size;
|
|
|
|
|
|
// used for CUDA inter-op
|
|
|
- cudaGraphicsResource_t cuda_res_up = nullptr; // for upload
|
|
|
- cudaGraphicsResource_t cuda_res_down = nullptr; // for download
|
|
|
+ cudaGraphicsResource_t cuda_res = nullptr;
|
|
|
std::shared_ptr<void> img_ptr;
|
|
|
|
|
|
- ~smart_pixel_buffer();
|
|
|
+ // for image upload
|
|
|
+ smart_pixel_buffer img_pbo;
|
|
|
|
|
|
- void create(GLsizeiptr size);
|
|
|
+ ~smart_texture();
|
|
|
|
|
|
- // download from current viewport
|
|
|
- void download_viewport(GLenum format, GLenum type);
|
|
|
+ void create(GLenum format, cv::Size size);
|
|
|
|
|
|
- template<typename T>
|
|
|
- void upload(const image_info_type<T> &img, smart_cuda_stream *stream) {
|
|
|
- create(sizeof(T) * img.size.area());
|
|
|
- upload_impl(img.mem_info(), stream);
|
|
|
- }
|
|
|
+ void set_filter(GLint min_filter, GLint max_filter);
|
|
|
|
|
|
template<typename T>
|
|
|
- void download(const image_info_type<T> &img, smart_cuda_stream *stream) {
|
|
|
- assert(size == sizeof(T) * img.size.area());
|
|
|
- download_impl(img.mem_info(), stream);
|
|
|
+ void upload(GLuint pbo_id, cv::Size _size) {
|
|
|
+ create(get_tex_internal_format<T>(), _size);
|
|
|
+ upload_impl(pbo_id, get_tex_format<T>(), get_tex_type<T>());
|
|
|
}
|
|
|
|
|
|
- // memory location maintains as img->loc.
|
|
|
template<typename T>
|
|
|
- void download_viewport(image_info_type<T> *img, GLenum format,
|
|
|
- GLenum type, smart_cuda_stream *stream) {
|
|
|
- img->create(query_viewport_size(), img->loc);
|
|
|
- download_viewport(format, type);
|
|
|
- download(*img, stream);
|
|
|
+ void upload(const image_info_type<T> &img, smart_cuda_stream *stream) {
|
|
|
+ create(get_tex_internal_format<T>(), img.size);
|
|
|
+
|
|
|
+ // direct upload only supports 1, 2 or 4 components
|
|
|
+ if constexpr (std::is_same_v<T, uchar3>) {
|
|
|
+ img_pbo.upload(img, stream);
|
|
|
+ upload<T>(img_pbo.id, size);
|
|
|
+ } else {
|
|
|
+ upload_impl(img.mem_info(), stream);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -134,7 +145,7 @@ private:
|
|
|
|
|
|
void upload_impl(const image_mem_info &img, smart_cuda_stream *stream);
|
|
|
|
|
|
- void download_impl(const image_mem_info &img, smart_cuda_stream *stream);
|
|
|
+ void upload_impl(GLuint pbo_id, GLenum format, GLenum type);
|
|
|
|
|
|
};
|
|
|
|