summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChuanbo Weng <chuanbo.weng@intel.com>2017-02-10 15:47:18 +0800
committerYang Rong <rong.r.yang@intel.com>2017-02-10 18:18:06 +0800
commitf54b7a2112975404d6d45b8fbf32c4d025524c71 (patch)
tree847eca210cf35ba46ac43db77c455eee66f068ae /examples
parent1e6d0103aba114f5a424dcdb3143ac95919a4d70 (diff)
Add example of using cl_khr_gl_sharing to do gl buffer sharing.
Signed-off-by: Chuanbo Weng <chuanbo.weng@intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt80
-rw-r--r--examples/gl_buffer_sharing/gl_buffer_sharing.cpp115
2 files changed, 165 insertions, 30 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 850b3d90..a9e35c24 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,44 +1,64 @@
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../utests
${CMAKE_CURRENT_SOURCE_DIR}/../include
- ${X11_INCLUDE_DIR})
+ ${X11_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_DIRS}
+ ${EGL_INCLUDE_DIRS})
+
+set (ocl_example_helper_sources
+ ../utests/utest_error.c
+ ../utests/utest_assert.cpp
+ ../utests/utest_file_map.cpp
+ ../utests/utest_helper.cpp)
+
+IF(OPENGL_FOUND AND EGL_FOUND AND X11_FOUND)
+ ADD_DEFINITIONS(-DHAS_GL_EGL_X11)
+ENDIF(OPENGL_FOUND AND EGL_FOUND AND X11_FOUND)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
+
+ADD_LIBRARY(ocl_example_helper SHARED ${ocl_example_helper_sources})
+
+TARGET_LINK_LIBRARIES(ocl_example_helper cl m ${X11_LIBRARIES} ${OPENGL_LIBRARIES} ${EGL_LIBRARIES})
IF(LIBVA_BUF_SH_DEP OR V4L2_BUF_SH_DEP)
-EXECUTE_PROCESS(COMMAND ls "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva" OUTPUT_VARIABLE LS_RESULT)
-IF ("LS_RESULT" STREQUAL "")
-EXECUTE_PROCESS(COMMAND git submodule init WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
-EXECUTE_PROCESS(COMMAND git submodule update WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
-EXECUTE_PROCESS(COMMAND git checkout master WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva)
-ENDIF ("LS_RESULT" STREQUAL "")
+ EXECUTE_PROCESS(COMMAND ls "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva" OUTPUT_VARIABLE LS_RESULT)
+ IF ("LS_RESULT" STREQUAL "")
+ EXECUTE_PROCESS(COMMAND git submodule init WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
+ EXECUTE_PROCESS(COMMAND git submodule update WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
+ EXECUTE_PROCESS(COMMAND git checkout master WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva)
+ ENDIF ("LS_RESULT" STREQUAL "")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva/va
- ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva/test/common)
+ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva/va
+ ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libva/test/common)
-link_directories (${LIBVA_LIBDIR}
- ${LIBVA-X11_LIBDIR})
+ link_directories (${LIBVA_LIBDIR}
+ ${LIBVA-X11_LIBDIR})
-set (va_ocl_basic_sources
- ../utests/utest_error.c
- ../utests/utest_assert.cpp
- ../utests/utest_file_map.cpp
- ../utests/utest_helper.cpp
- ./thirdparty/libva/test/common/va_display.c
- ./thirdparty/libva/test/common/va_display_x11.c)
+ set (va_display_sources
+ ./thirdparty/libva/test/common/va_display.c
+ ./thirdparty/libva/test/common/va_display_x11.c)
-ADD_DEFINITIONS(-DHAVE_VA_X11)
+ ADD_DEFINITIONS(-DHAVE_VA_X11)
-ADD_LIBRARY(va_ocl_basic SHARED ${va_ocl_basic_sources})
+ ADD_LIBRARY(va_display SHARED ${va_display_sources})
-TARGET_LINK_LIBRARIES(va_ocl_basic cl m va va-x11 ${X11_X11_LIB})
+ TARGET_LINK_LIBRARIES(va_display cl m va va-x11 ${X11_LIBRARIES})
-IF(LIBVA_BUF_SH_DEP)
-ADD_DEFINITIONS(-DINPUT_NV12_DEFAULT="${CMAKE_CURRENT_SOURCE_DIR}/libva_buffer_sharing/256_128.nv12")
-ADD_EXECUTABLE(example-libva_buffer_sharing ./libva_buffer_sharing/libva_buffer_sharing.cpp)
-TARGET_LINK_LIBRARIES(example-libva_buffer_sharing va_ocl_basic)
-ENDIF(LIBVA_BUF_SH_DEP)
+ IF(LIBVA_BUF_SH_DEP)
+ ADD_DEFINITIONS(-DINPUT_NV12_DEFAULT="${CMAKE_CURRENT_SOURCE_DIR}/libva_buffer_sharing/256_128.nv12")
+ ADD_EXECUTABLE(example-libva_buffer_sharing ./libva_buffer_sharing/libva_buffer_sharing.cpp)
+ TARGET_LINK_LIBRARIES(example-libva_buffer_sharing ocl_example_helper va_display)
+ ENDIF(LIBVA_BUF_SH_DEP)
-IF(V4L2_BUF_SH_DEP)
-ADD_EXECUTABLE(example-v4l2_buffer_sharing ./v4l2_buffer_sharing/v4l2_buffer_sharing.cpp)
-TARGET_LINK_LIBRARIES(example-v4l2_buffer_sharing va_ocl_basic)
-ENDIF(V4L2_BUF_SH_DEP)
+ IF(V4L2_BUF_SH_DEP)
+ ADD_EXECUTABLE(example-v4l2_buffer_sharing ./v4l2_buffer_sharing/v4l2_buffer_sharing.cpp)
+ TARGET_LINK_LIBRARIES(example-v4l2_buffer_sharing ocl_example_helper va_display)
+ ENDIF(V4L2_BUF_SH_DEP)
ENDIF(LIBVA_BUF_SH_DEP OR V4L2_BUF_SH_DEP)
+
+IF(OPENGL_FOUND AND EGL_FOUND AND X11_FOUND)
+ ADD_EXECUTABLE(example-gl_buffer_sharing ./gl_buffer_sharing/gl_buffer_sharing.cpp)
+ TARGET_LINK_LIBRARIES(example-gl_buffer_sharing ocl_example_helper ${OPENGL_LIBRARIES} ${EGL_LIBRARIES})
+ENDIF(OPENGL_FOUND AND EGL_FOUND AND X11_FOUND)
diff --git a/examples/gl_buffer_sharing/gl_buffer_sharing.cpp b/examples/gl_buffer_sharing/gl_buffer_sharing.cpp
new file mode 100644
index 00000000..2d7e10d4
--- /dev/null
+++ b/examples/gl_buffer_sharing/gl_buffer_sharing.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "utest_helper.hpp"
+#include <stdio.h>
+
+static cl_int cl_status;
+
+const size_t w = EGL_WINDOW_WIDTH;
+const size_t h = EGL_WINDOW_HEIGHT;
+static GLuint tex;
+
+static void draw(){
+ XEvent event;
+
+ float vertices[8] = {-1, 1, 1, 1, 1, -1, -1, -1};
+ float tex_coords[8] = {0, 0, 1, 0, 1, 1, 0, 1};
+ uint32_t color0 = 0x0000ff00;
+
+ for (;;)
+ {
+ XNextEvent(xDisplay, &event);
+
+ if (event.type == Expose)
+ {
+ glClearColor(0.0, 1.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(color0), &color0);
+ globals[0] = w;
+ globals[1] = h;
+ locals[0] = 16;
+ locals[1] = 16;
+ glFinish();
+ OCL_ENQUEUE_ACQUIRE_GL_OBJECTS(0);
+ OCL_NDRANGE(2);
+ OCL_ENQUEUE_RELEASE_GL_OBJECTS(0);
+ OCL_FINISH();
+
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glEnable(GL_TEXTURE_2D);
+ glDisable(GL_BLEND);
+ glVertexPointer(2, GL_FLOAT, sizeof(float) * 2, vertices);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glClientActiveTexture(GL_TEXTURE0);
+ glTexCoordPointer(2, GL_FLOAT, sizeof(float) * 2, tex_coords);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glFinish();
+ eglSwapBuffers(eglDisplay, eglSurface);
+ }
+ if (event.type == KeyPress)
+ break;
+ }
+}
+
+
+static void initialize_ocl_gl(){
+
+ //ocl initialization: basic & create kernel & check extension
+ printf("\n***********************OpenCL info: ***********************\n");
+ if ((cl_status = cl_test_init("runtime_fill_gl_image.cl", "runtime_fill_gl_image", SOURCE)) != 0){
+ fprintf(stderr, "cl_test_init error\n");
+ exit(1);
+ }
+
+ if (eglContext == EGL_NO_CONTEXT) {
+ fprintf(stderr, "There is no valid egl context! Exit!\n");
+ exit(1);
+ }
+
+ XMapWindow(xDisplay, xWindow);
+
+ // Setup kernel and images
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL);
+
+ //Create cl image from miplevel 0
+ OCL_CREATE_GL_IMAGE(buf[0], 0, GL_TEXTURE_2D, 0, tex);
+}
+
+int main(int argc, char *argv[])
+{
+ initialize_ocl_gl();
+
+ draw();
+
+ //destroy resource of cl & gl
+ cl_test_destroy();
+
+ printf("\nExample run successfully!\n");
+}