Skip to content

Commit

Permalink
separate osgl
Browse files Browse the repository at this point in the history
  • Loading branch information
StasJ committed Mar 11, 2024
1 parent 96c04e4 commit 5d4fb27
Show file tree
Hide file tree
Showing 43 changed files with 335 additions and 254 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ option (BUILD_TEST_APPS "Build test applications" OFF)
option (DIST_INSTALLER "Generate installer for distributing vapor binaries. Will generate standard make install if off" OFF)
option (USE_OMP "Use OpenMP on some calculations" OFF)
option (CONDA_BUILD "Use Conda to build" OFF)
option (BUNDLED_OSGL "Use bundled copy of OSGL" ON)

if( USE_OMP )
find_package(OpenMP REQUIRED)
Expand Down Expand Up @@ -184,14 +185,20 @@ find_library(GEOTIFF geotiff)
find_library(JPEG jpeg)
find_library(HDF5_LIB hdf5)
find_library(EXPAT expat)
if (BUNDLED_OSGL)
set(OSGL osgl)
else()
find_library(OSGL osgl)
endif()

message("Library NETCDF = ${NETCDF}")
message("Library UDUNITS2 = ${UDUNITS2}")
message("Library FREETYPE = ${FREETYPE}")
message("Library GEOTIFF = ${GEOTIFF}")
message("Library JPEG = ${JPEG}")
message("Library HDF5_LIB = ${HDF5_LIB}")
message("Library EXPAT = ${EXPAT}")
message("Library EXPAT = ${EXPAT}")
message("Library EXPAT = ${OSGL}")

# find_package(Python)
# Output
Expand Down
1 change: 1 addition & 0 deletions conda/vapor/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ cmake .. \
-DBUILD_UTL=OFF \
-DBUILD_GUI=OFF \
-DBUILD_OSP=OFF \
-DBUNDLED_OSGL=OFF \
-DPython_EXECUTABLE="$PYTHON" \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
$CMAKE_EXTRA \
Expand Down
2 changes: 2 additions & 0 deletions conda/vapor/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ requirements:
- mesalib=21.2.5
- expat=2.4
- libcxx=14.0
- osgl
run:
# Run only
- xarray=2022 #=2022.3.0
Expand Down Expand Up @@ -66,3 +67,4 @@ requirements:
- {{ pin_compatible('mesalib') }}
- {{ pin_compatible('expat') }}
- {{ pin_compatible('libcxx') }}
- {{ pin_compatible('osgl') }}
2 changes: 1 addition & 1 deletion include/vapor/glutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
#endif

#include <vapor/GLInclude.h>
#include <osgl/GLInclude.h>
#include <cmath>
#include <vector>
#include <string>
Expand Down
7 changes: 5 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ endif()


if (BUILD_GUI OR BUILD_PYTHON)
add_subdirectory(osgl)
if (BUNDLED_OSGL)
add_subdirectory(osgl)
export (TARGETS osgl NAMESPACE VAPOR:: APPEND FILE vapor-exports.cmake)
endif()
add_subdirectory (params)
add_subdirectory( flow )
add_subdirectory (render)
if (NOT WIN32)
add_subdirectory (vapi)
export (TARGETS vapi NAMESPACE VAPOR:: APPEND FILE vapor-exports.cmake)
endif()
export (TARGETS render params flow osgl NAMESPACE VAPOR:: APPEND FILE vapor-exports.cmake)
export (TARGETS render params flow NAMESPACE VAPOR:: APPEND FILE vapor-exports.cmake)
endif()

52 changes: 0 additions & 52 deletions lib/osgl/CMakeCopy.cmake

This file was deleted.

63 changes: 19 additions & 44 deletions lib/osgl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
set(LIB osgl)

include(CMakeCopy.cmake)

set(BUILD_MESA_DEFAULT OFF)
if (BUILD_PYTHON AND (UNIX AND NOT APPLE))
if (UNIX AND NOT APPLE)
set(BUILD_MESA_DEFAULT ON)
endif()

option (BUILD_MESA "Build with OSMesa" ${BUILD_MESA_DEFAULT})
option (BUILD_OSGL_TESTS "Build tests" ON)

option (SOFTWARE_ONLY "Disable EGL" OFF)
if (NOT SOFTWARE_ONLY)
Expand All @@ -19,11 +19,9 @@ if (NOT PROJECT_NAME)
cmake_minimum_required (VERSION 3.10)
project (${LIB})
set (CMAKE_CXX_STANDARD 11)
# find_package (OpenGL REQUIRED)
# include_directories (${OPENGL_INCLUDE_DIRS})
set(CMAKE_INSTALL_BINDIR bin)
set(CMAKE_INSTALL_LIBDIR lib)
set(CMAKE_INSTALL_INCLUDEDIR include/vapor)
set(CMAKE_INSTALL_INCLUDEDIR include)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
endif()
Expand All @@ -33,25 +31,21 @@ else ()
set(CMAKE_INSTALL_INCLUDEDIR ${INSTALL_INCLUDE_DIR})
endif ()

file (GLOB HDRS ./include/vapor/*.h)
file (GLOB SRCS ./*.cpp)
file (GLOB HDRS ./include/osgl/*.h)
file (GLOB SRCS ./src/*.cpp)
if (APPLE)
file (GLOB OBJC_SRCS ./*.mm)
file (GLOB OBJC_SRCS ./src/*.mm)
list (APPEND SRCS ${OBJC_SRCS})
endif ()

list(FILTER SRCS EXCLUDE REGEX "test_[^/]*\\.cpp$")
list(FILTER SRCS EXCLUDE REGEX "ext_[^/]*\\.cpp$")

list(APPEND SRCS glad/src/egl.c glad/src/gl.c)
list(APPEND HDRS glad/include/glad/egl.h glad/include/glad/gl.h)
# file(COPY glad/include DESTINATION ${CMAKE_BINARY_DIR})
# list(APPEND HDRS glad/include/glad/egl.h glad/include/glad/gl.h)
if (WIN32)
list(APPEND SRCS glad/src/wgl.c)
# list(APPEND HDRS glad/include/glad/wgl.h)
endif()

add_library (${LIB} SHARED ${SRCS} ${HDRS})
# if (NOT SOFTWARE_ONLY)
# target_link_libraries (${LIB} ${OPENGL_LIBRARIES})
# endif()
target_link_libraries (${LIB} common)

if (APPLE)
find_library (APPKIT AppKit)
Expand All @@ -70,27 +64,17 @@ if (UNIX AND NOT APPLE)
endif ()
endif ()

# if (CONDA_BUILD AND UNIX AND NOT APPLE)
# target_link_libraries (${LIB} rt)
# endif()

if (NOT WIN32)
target_compile_options(${LIB} PRIVATE -Wno-deprecated-declarations)
endif()
# target_compile_options(${LIB} PRIVATE -Wno-unknown-warning-option)

# file(COPY ${HDRS} DESTINATION ${CMAKE_BINARY_DIR}/include/vapor)
# foreach (HDR ${HDRS})
# copy(${HDR} ${CMAKE_BINARY_DIR}/include/vapor) # Does not work with xcode...
# endforeach()
# target_include_directories (${LIB} PUBLIC ${CMAKE_BINARY_DIR}/include)

target_include_directories (${LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories (${LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)

if (WIN32)
add_definitions (-DOSGL_EXPORTS)
add_definitions (-DGLAD_API_CALL_EXPORT_BUILD)
target_compile_definitions(${LIB} PUBLIC GLAD_API_CALL_EXPORT=1)
target_compile_definitions(${LIB} PRIVATE GLAD_API_CALL_EXPORT_BUILD=1)
target_compile_definitions(${LIB} PRIVATE OSGL_EXPORTS=1)
endif()

install (
Expand All @@ -101,7 +85,7 @@ install (

install (
FILES ${HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/osgl
COMPONENT Libraries
)

Expand All @@ -111,16 +95,7 @@ install (
COMPONENT Libraries
)

set (BUILD_OSGL_TESTS OFF)

if (NOT WIN32 AND BUILD_OSGL_TESTS)
file (GLOB TESTS ./test_*.cpp)
foreach (TEST ${TESTS})
get_filename_component(TEST_NAME "${TEST}" NAME_WE)
set(TEST_TARGET "${LIB}_${TEST_NAME}")
add_executable(${TEST_TARGET} "${TEST}")
target_link_libraries(${TEST_TARGET} ${LIB})
target_compile_options(${TEST_TARGET} PRIVATE -Wno-deprecated-declarations)
install(TARGETS ${TEST_TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Libraries)
endforeach()
if (BUILD_OSGL_TESTS)
add_subdirectory (tests)
endif()

20 changes: 20 additions & 0 deletions lib/osgl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OSGL

OSGL is an open source, cross-platform library designed to simplify the use of OpenGL in headless environments. It uses OS and vendor specific extensions, as well as EGL to aquire an OpenGL context without needing to go through the window manager. It will fallback to providing a software OpenGL context using OSMesa if getting a hardware context fails.

Getting an OpenGL context is now as simple as this:
```
#include <osgl/GLContextProvider.h>
#include <osgl/GLInclude.h>
int main(int argc, char **argv)
{
auto ctx = OSGL::GLContextProvider::CreateContext();
printf("OpenGL Context: %s\n", glGetString(GL_VERSION));
return 0;
}
```

Since the context will not be bound to a window, you need to create and bind your own target framebuffer. An complete example can be found in `tests/test_framebuffer.cpp`.

OSGL currently supports macOS and Linux. Windows support is planned.
53 changes: 0 additions & 53 deletions lib/osgl/build.sh

This file was deleted.

44 changes: 44 additions & 0 deletions lib/osgl/conda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

# Inputs
[[ -z "$DEBUG" ]] && DEBUG=false

CMAKE_EXTRA=""

# The env can be either PREFIX or BUILD_PREFIX depending on the build requirements.
# Conda does not configure its variables accordingly.
export ENV="$BUILD_PREFIX"
export PATH="$ENV/bin:$PATH"

if $DEBUG; then
# If optimizations are disabled, need to disable fortify source otherwise will get barraged with warnings
export CPPFLAGS="`echo $CPPFLAGS|sed 's/-D_FORTIFY_SOURCE=2//g'`"
CMAKE_EXTRA="$CMAKE_EXTRA -DCMAKE_BUILD_TYPE=Debug"
else
CMAKE_EXTRA="$CMAKE_EXTRA -DCMAKE_BUILD_TYPE=Release"
fi

export CPPFLAGS="$CPPFLAGS -isystem $ENV/include"

# cmake ignores CPPFLAGS
export CXXFLAGS="$CXXFLAGS $CPPFLAGS"
export CFLAGS="$CFLAGS $CPPFLAGS"

# Conda will sometimes set these to invalid values which end up breaking the build
unset CMAKE_ARGS
unset CMAKE_PREFIX_PATH

# Prevent linking outside libraries
export CMAKE_LIBRARY_PATH="$PREFIX/lib:$BUILD_PREFIX/lib"
export CMAKE_PREFIX_PATH="$PREFIX:$BUILD_PREFIX"

mkdir build
cd build

cmake .. \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
$CMAKE_EXTRA \

make -j$(($CPU_COUNT+1))
make install

22 changes: 22 additions & 0 deletions lib/osgl/conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package:
name: osgl
version: "0.9.0"

source:
path: ..

build:
script_env:
- DEBUG

requirements:
build:
- {{ compiler('cxx') }}
- make=4.3
- cmake=3.21.3
- mesalib=21.2.5 # [not win]
- libcxx=14.0 # [not win]
- libcxx # [win]
run:
- {{ pin_compatible('mesalib') }} # [not win]
- {{ pin_compatible('libcxx') }}
File renamed without changes.
Loading

0 comments on commit 5d4fb27

Please sign in to comment.