Skip to content

Commit

Permalink
Use corefungi library for behaviour configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
berenm committed Aug 18, 2013
1 parent 52e1444 commit 6999868
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -76,3 +76,6 @@
[submodule "lib/logging"]
path = lib/logging
url = git://github.com/berenm/liblogging.git
[submodule "lib/corefungi"]
path = lib/corefungi
url = git://github.com/berenm/libcorefungi.git
11 changes: 7 additions & 4 deletions CMakeLists.txt
Expand Up @@ -17,8 +17,11 @@ if(NOT libgtulu_api_VERSION)
set(libgtulu_api_VERSION 4.3-comp)
endif()

add_submodule(logging git://github.com/berenm/liblogging.git lib/logging BRANCH master INCLUDE_DIRS include lib/boost-log)
include_directories(${boost-log_INCLUDE_DIRS})
add_submodule(libcorefungi git://github.com/berenm/libcorefungi.git lib/corefungi BRANCH master INCLUDE_DIRS include)
include_directories(${libcorefungi_INCLUDE_DIRS})

add_submodule(liblogging git://github.com/berenm/liblogging.git lib/logging BRANCH master INCLUDE_DIRS include lib/boost-log)
include_directories(${liblogging_INCLUDE_DIRS})

find_package(PkgConfig REQUIRED)

Expand Down Expand Up @@ -87,7 +90,7 @@ set_target_properties(${GTULU_TARGET_PREFIX}_ni PROPERTIES
OUTPUT_NAME gtulu-api-ni
${GTULU_LIBRARY_PROPERTIES}
)
target_link_libraries(${GTULU_TARGET_PREFIX}_ni logging)
target_link_libraries(${GTULU_TARGET_PREFIX}_ni corefungi logging)


add_library(${GTULU_TARGET_PREFIX} ${GTULU_API_HPP} ${GTULU_API_CPP} src/gtulu/error.cpp)
Expand All @@ -98,7 +101,7 @@ set_target_properties(${GTULU_TARGET_PREFIX} PROPERTIES
PUBLIC_HEADER src/gtulu/types.h
${GTULU_LIBRARY_PROPERTIES}
)
target_link_libraries(${GTULU_TARGET_PREFIX} ${GTULU_TARGET_PREFIX}_ni logging)
target_link_libraries(${GTULU_TARGET_PREFIX} ${GTULU_TARGET_PREFIX}_ni corefungi logging)

install(TARGETS ${GTULU_TARGET_PREFIX} ${GTULU_TARGET_PREFIX}_ni
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
1 change: 1 addition & 0 deletions lib/corefungi
Submodule corefungi added at 264323
2 changes: 1 addition & 1 deletion lib/logging
19 changes: 15 additions & 4 deletions src/gtulu/error.cpp
Expand Up @@ -6,19 +6,31 @@
#include <cstdlib>
#include <stdexcept>

#include <corefungi.hpp>

namespace gtulu {
namespace api {

static corefungi::sprout const o = {
"Gtulu API options", {
{ "gtulu.no-error-check","disable the error checking after each GL call", corefungi::bool_switch },
{ "gtulu.no-error-throw","disable the exception throw in case of error", corefungi::bool_switch },
{ "gtulu.notimp-throw","enable the exception throw in case of not-implemented function call", corefungi::bool_switch }
}
};

void __check_error() {
static char const* const __gtulu_error_nocheck = std::getenv("GTULU_ERROR_NOCHECK");
static bool const __gtulu_error_nocheck = corefungi::get("gtulu.no-error-check");
static bool const __gtulu_error_nothrow = corefungi::get("gtulu.no-error-throw");

if (__gtulu_error_nocheck != nullptr)
if (__gtulu_error_nocheck)
return;

gtu::constant const __gl_error = gtulu::api::get_error();
char const* __gl_error_string = nullptr;
switch (__gl_error) {
case gtu::cst::no_error:

return;

case gtu::cst::invalid_enum:
Expand Down Expand Up @@ -60,8 +72,7 @@ namespace gtulu {

__error() << __gl_error_string;

static char const* const __gtulu_error_nothrow = std::getenv("GTULU_ERROR_NOTHROW");
if (__gtulu_error_nothrow == nullptr)
if (!__gtulu_error_nothrow)
throw std::runtime_error(__gl_error_string);
} // __check_error

Expand Down
6 changes: 4 additions & 2 deletions src/gtulu/notimp.cpp
Expand Up @@ -5,14 +5,16 @@
#include <cstdlib>
#include <stdexcept>

#include <corefungi.hpp>

namespace gtulu {
namespace api {

void __not_implemented(char const* const name) {
__warn() << "not implemented: " << name;

static char const* const __gtulu_ni_throw = std::getenv("GTULU_NOTIMP_THROW");
if (__gtulu_ni_throw != nullptr)
static bool const __gtulu_ni_throw = corefungi::get("gtulu.notimp-throw");
if (__gtulu_ni_throw)
throw std::runtime_error(std::string("not implemented: ") + name);
}

Expand Down
4 changes: 4 additions & 0 deletions test/test1.cpp
Expand Up @@ -3,6 +3,9 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>

#include <boost/thread.hpp>
#include <corefungi.hpp>

template< typename ContextImpl >
struct context_info_base : ContextImpl {
template< typename ... Ts > context_info_base(Ts ... vs) : ContextImpl(vs ...) {}
Expand Down Expand Up @@ -147,6 +150,7 @@ static void destroy_context() {
}

int main(int argc, char const* argv[]) {
corefungi::init(argc, argv);
create_context();

__info() << "vendor: " << gtulu::api::get_string(gtulu::cst::vendor);
Expand Down

0 comments on commit 6999868

Please sign in to comment.