commit 34c1c727ec92536180074f3a83a1804e76c1e079
parent 7f24a2187d65049727abe7e82d45c6c9f8c46119
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 8 Jun 2016 15:54:41 +0200
Add a CMakeList and implement the s2d_device API
Diffstat:
| A | cmake/CMakeLists.txt | | | 131 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/s2d_backend.h | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/s2d_device.c | | | 105 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/s2d_device_c.h | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 340 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -0,0 +1,131 @@
+# Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+#
+# This software is governed by the CeCILL license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# In this respect, the user's attention is drawn to the risks associated
+# with loading, using, modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean that it is complicated to manipulate, and that also
+# therefore means that it is reserved for developers and experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and, more generally, to use and operate it in the
+# same conditions as regards security.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+cmake_minimum_required(VERSION 2.8)
+project(star-2d C CXX)
+enable_testing()
+
+set(S2D_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
+option(NO_TEST "Disable the test" OFF)
+
+################################################################################
+# Check dependencies
+################################################################################
+find_package(Embree 2.9 REQUIRED)
+find_package(RCMake 0.2.2 REQUIRED)
+find_package(RSys 0.2.1 REQUIRED)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
+include(rcmake)
+include(rcmake_runtime)
+
+include_directories(${EMBREE_INCLUDE_DIRS} ${RSys_INCLUDE_DIR})
+
+rcmake_append_runtime_dirs(_runtime_dirs RSys Embree)
+
+################################################################################
+# Configure and define targets
+################################################################################
+set(VERSION_MAJOR 0)
+set(VERSION_MINOR 0)
+set(VERSION_PATCH 0)
+set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
+
+set(S2D_FILES_SRC
+ s2d_device.c)
+set(S2D_FILES_INC_API s2d.h)
+set(S2D_FILES_INC
+ s2d_device_c.h)
+set(S2D_FILES_DOC COPYING.fr COPYING.en README.md)
+
+# Prepend each file in the `S2D_FILES_<SRC|INC>' list by `S2D_SOURCE_DIR'
+rcmake_prepend_path(S2D_FILES_SRC ${S2D_SOURCE_DIR})
+rcmake_prepend_path(S2D_FILES_INC ${S2D_SOURCE_DIR})
+rcmake_prepend_path(S2D_FILES_INC_API ${S2D_SOURCE_DIR})
+rcmake_prepend_path(S2D_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
+set_source_files_properties(${S2D_FILES_SRC} PROPERTIES LANGUAGE CXX)
+
+add_library(s2d SHARED ${S2D_FILES_SRC} ${S2D_FILES_INC} ${S2D_FILES_INC_API})
+target_link_libraries(s2d RSys ${EMBREE_LIBRARY})
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ target_link_libraries(s2d m)
+endif()
+
+set_target_properties(s2d PROPERTIES
+ DEFINE_SYMBOL S2D_SHARED_BUILD
+ LINKER_LANGUAGE CXX
+ VERSION ${VERSION}
+ SOVERSION ${VERSION_MAJOR})
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ # Shut up the use of variadic macros by Embree and the use of long long
+ # constants by RSys
+ set_target_properties(s2d PROPERTIES
+ COMPILE_FLAGS "-Wno-variadic-macros -Wno-long-long")
+endif()
+
+rcmake_setup_devel(s2d Star2D ${VERSION} star/s2d_version.h)
+
+################################################################################
+# Add tests
+################################################################################
+if(NOT NO_TEST)
+ function(build_test _name)
+ add_executable(${_name}
+ ${S2D_SOURCE_DIR}/${_name}.c
+ ${S2D_SOURCE_DIR}/test_s2d_utils.h)
+ target_link_libraries(${_name} s2d RSys)
+ set(_libraries ${ARGN})
+ foreach(_lib ${_libraries})
+ target_link_libraries(${_name} ${_lib})
+ endforeach()
+ endfunction()
+
+ function(register_test _name)
+ add_test(${_name} ${ARGN})
+ rcmake_set_test_runtime_dirs(${_name} _runtime_dirs)
+ endfunction()
+
+ function(new_test _name)
+ build_test(${_name} ${ARGN})
+ register_test(${_name} ${_name})
+ endfunction()
+
+ #new_test(test_s2d_device)
+endif(NOT NO_TEST)
+
+################################################################################
+# Define output & install directories
+################################################################################
+install(TARGETS s2d
+ ARCHIVE DESTINATION bin
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION bin)
+install(FILES ${S2D_FILES_INC_API} DESTINATION include/star)
+install(FILES ${S2D_FILES_DOC} DESTINATION share/doc/star-2d)
+
diff --git a/src/s2d_backend.h b/src/s2d_backend.h
@@ -0,0 +1,57 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This software is a computer program whose purpose is to describe a
+ * virtual 3D environment that can be ray-traced and sampled both robustly
+ * and efficiently.
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#ifndef S2D_BACKEND_H
+#define S2D_BACKEND_H
+
+#include <rsys/rsys.h>
+
+#ifdef COMPILER_GCC
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpedantic"
+ #pragma GCC diagnostic ignored "-Wsign-compare"
+#elif defined(COMPILER_CL)
+ #pragma warning(push)
+ #pragma warning(disable:4324) /* Structure was padded due to alignment */
+#endif
+
+#include <embree2/rtcore.h>
+#include <embree2/rtcore_ray.h>
+
+#ifdef COMPILER_GCC
+ #pragma GCC diagnostic pop
+#elif defined(COMPILER_CL)
+ #pragma warning(pop)
+#endif
+
+#endif /* S2D_BACKEND_H */
+
diff --git a/src/s2d_device.c b/src/s2d_device.c
@@ -0,0 +1,105 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#include "s2d.h"
+#include "s2d_device_c.h"
+
+#include <rsys/logger.h>
+#include <rsys/mem_allocator.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void
+device_release(ref_T* ref)
+{
+ struct s2d_device* dev;
+ ASSERT(ref);
+ dev = CONTAINER_OF(ref, struct s2d_device, ref);
+ rtcDeleteDevice(dev->rtc);
+ MEM_RM(dev->allocator, dev);
+}
+
+/*******************************************************************************
+ * Exported s2d_device functions
+ ******************************************************************************/
+res_T
+s2d_device_create
+ (struct logger* logger,
+ struct mem_allocator* mem_allocator,
+ const int verbose,
+ struct s2d_device** out_dev)
+{
+ struct s2d_device* dev = NULL;
+ struct mem_allocator* allocator;
+ res_T res = RES_OK;
+
+ if(!out_dev) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ allocator = mem_allocator ? mem_allocator : &mem_default_allocator;
+ dev = (struct s2d_device*)MEM_CALLOC(allocator, 1, sizeof(struct s2d_device));
+ if(!dev) {
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ dev->logger = logger ? logger : LOGGER_DEFAULT;
+ dev->allocator = allocator;
+ dev->verbose = verbose;
+ ref_init(&dev->ref);
+ dev->rtc = rtcNewDevice(verbose ? "verbose=1" : NULL);
+
+exit:
+ if(out_dev) *out_dev = dev;
+ return res;
+error:
+ if(dev) {
+ S2D(device_ref_put(dev));
+ dev = NULL;
+ }
+ goto exit;
+}
+
+res_T
+s2d_device_ref_get(struct s2d_device* dev)
+{
+ if(!dev) return RES_BAD_ARG;
+ ref_get(&dev->ref);
+ return RES_OK;
+}
+
+res_T
+s2d_device_ref_put(struct s2d_device* dev)
+{
+ if(!dev) return RES_BAD_ARG;
+ ref_put(&dev->ref, device_release);
+ return RES_OK;
+}
+
diff --git a/src/s2d_device_c.h b/src/s2d_device_c.h
@@ -0,0 +1,47 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#ifndef S2D_DEVICE_C_H
+#define S2D_DEVICE_C_H
+
+#include "s2d_backend.h"
+
+#include <rsys/ref_count.h>
+
+struct s2d_device {
+ int verbose;
+ struct logger* logger;
+ struct mem_allocator* allocator;
+
+ RTCDevice rtc; /* Embree device */
+
+ ref_T ref;
+};
+
+#endif /* S2D_DEVICE_C_H */
+