From 1e4598ff3423190b5bf18819bd27863b334cb2ee Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 22 May 2016 22:11:08 +0200 Subject: gr-fosphor: On WIN32 platform, link and use GLEW to find GL extensions The FindGLEW is included because it seems the one shipping by CMake by default fails to find it on windows (which is the only platform where we use it ...) This is based on a patch from Geof Nieboer Signed-off-by: Sylvain Munaut --- cmake/Modules/FindGLEW.cmake | 50 ++++++++++++++++++++++++++++++++++++++++++++ lib/CMakeLists.txt | 7 +++++++ lib/base_sink_c_impl.cc | 12 +++++++++++ 3 files changed, 69 insertions(+) create mode 100644 cmake/Modules/FindGLEW.cmake diff --git a/cmake/Modules/FindGLEW.cmake b/cmake/Modules/FindGLEW.cmake new file mode 100644 index 0000000..14497ee --- /dev/null +++ b/cmake/Modules/FindGLEW.cmake @@ -0,0 +1,50 @@ +#.rst: +# FindGLEW +# -------- +# +# Find the OpenGL Extension Wrangler Library (GLEW) +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the :prop_tgt:`IMPORTED` target ``GLEW::GLEW``, +# if GLEW has been found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# GLEW_INCLUDE_DIRS - include directories for GLEW +# GLEW_LIBRARIES - libraries to link against GLEW +# GLEW_FOUND - true if GLEW has been found and can be used + +#============================================================================= +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +find_path(GLEW_INCLUDE_DIR GL/glew.h) +find_library(GLEW_LIBRARY NAMES GLEW glew64 glew32 glew glew32s PATH_SUFFIXES lib64 x86_64 x86 ) + +set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR}) +set(GLEW_LIBRARIES ${GLEW_LIBRARY}) + +if(GLEW_FOUND AND NOT TARGET GLEW::GLEW) + add_library(GLEW::GLEW UNKNOWN IMPORTED) + set_target_properties(GLEW::GLEW PROPERTIES + IMPORTED_LOCATION "${GLEW_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}") +endif() + +mark_as_advanced(GLEW_INCLUDE_DIR GLEW_LIBRARY) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index db29da7..dc669ab 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -48,6 +48,13 @@ link_directories( ${Boost_LIBRARY_DIRS} ) +if(WIN32) + find_package(GLEW REQUIRED) + include_directories(${GLEW_INCLUDE_DIRS}) + list(APPEND fosphor_libraries ${GLEW_LIBRARIES}) + add_definitions(-DENABLE_GLEW) +endif(WIN32) + if(ENABLE_PYTHON) add_definitions(-DENABLE_PYTHON) include_directories(${PYTHON_INCLUDE_DIRS}) diff --git a/lib/base_sink_c_impl.cc b/lib/base_sink_c_impl.cc index 725f633..c4af03e 100644 --- a/lib/base_sink_c_impl.cc +++ b/lib/base_sink_c_impl.cc @@ -31,6 +31,10 @@ #include "fifo.h" #include "base_sink_c_impl.h" +#ifdef ENABLE_GLEW +# include +#endif + extern "C" { #include "fosphor/fosphor.h" #include "fosphor/gl_platform.h" @@ -88,6 +92,14 @@ void base_sink_c_impl::worker() /* Init GL context */ this->glctx_init(); +#ifdef ENABLE_GLEW + GLenum glew_err = glewInit(); + if (glew_err != GLEW_OK) { + GR_LOG_ERROR(d_logger, boost::format("GLEW initialization error : %s") % glewGetErrorString(glew_err)); + goto error; + } +#endif + /* Init fosphor */ { /* (prevent // init of multiple instance to be gentle on the OpenCL -- cgit v1.2.3