Skip to content
Permalink
Browse files

Make the OpenGL reference renderer example opt-in

  • Loading branch information...
emilk committed Jun 18, 2018
1 parent a0a9d2e commit a99a26bb7e6490304a247eef2e114cb1a8e17304
Showing with 36 additions and 29 deletions.
  1. +0 −1 README.md
  2. +18 −18 build.sh
  3. +5 −4 src/libs.cpp
  4. +13 −6 src/main.cpp
@@ -14,7 +14,6 @@ This renders in 7 ms on my MacBook Pro:

# Future work:
* We do not yet support painting with any other texture than the default font texture.
* Allow compiling the example app without OpenGL.
* Optimize rendering of gradient rectangles (common for color pickers)

# How to test it
@@ -12,15 +12,20 @@ BINARY_NAME="$FOLDER_NAME.bin"

mkdir -p build

OPENGL_REFERENCE_RENDERER=false # Set to true to try the OpenGL reference renderer

CXX="ccache g++"

# -----------------------------------------------------------------------------
# Flags for compiler and linker:

CPPFLAGS="--std=c++14"
# CPPFLAGS="--std=c++1z" # C++17
if $OPENGL_REFERENCE_RENDERER; then
CPPFLAGS="--std=c++14"
else
CPPFLAGS="--std=c++11"
fi

CPPFLAGS="$CPPFLAGS -Werror -Wall -Wpedantic -Wextra -Weverything -Wunreachable-code"
# CPPFLAGS="$CPPFLAGS -Werror -Wall -Wpedantic -Wextra -Weverything -Wunreachable-code" # These can all be turned on, but are off just to make the example compile everywhere.

CPPFLAGS="$CPPFLAGS -Wno-double-promotion" # Implicitly converting a float to a double is fine
CPPFLAGS="$CPPFLAGS -Wno-float-equal" # Comparing floating point numbers is fine if you know what you're doing
@@ -74,9 +79,7 @@ CPPFLAGS="$CPPFLAGS -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS"
COMPILE_FLAGS="$CPPFLAGS"
COMPILE_FLAGS="$COMPILE_FLAGS -I ."
COMPILE_FLAGS="$COMPILE_FLAGS -isystem third_party"
COMPILE_FLAGS="$COMPILE_FLAGS -isystem third_party/emath"
COMPILE_FLAGS="$COMPILE_FLAGS -isystem third_party/emilib"
COMPILE_FLAGS="$COMPILE_FLAGS -isystem third_party/visit_struct/include"

# -----------------------------------------------------------------------------
# Custom compile-time flags:
@@ -88,19 +91,16 @@ COMPILE_FLAGS="$COMPILE_FLAGS -DLOGURU_REDEFINE_ASSERT=1"
# Libraries to link with:

LDLIBS="-lstdc++ -lpthread -ldl"
LDLIBS="$LDLIBS -lSDL2 -lGLEW"
# LDLIBS="$LDLIBS -lceres -lglog"
# LDLIBS="$LDLIBS -lfftw3f"

# Platform specific flags:
if [ "$(uname)" == "Darwin" ]; then
COMPILE_FLAGS="$COMPILE_FLAGS -isystem /opt/local/include/eigen3" # port
COMPILE_FLAGS="$COMPILE_FLAGS -isystem /usr/local/include/eigen3" # brew
LDLIBS="$LDLIBS -framework OpenAL"
LDLIBS="$LDLIBS -framework OpenGL"
else
COMPILE_FLAGS="$COMPILE_FLAGS -isystem /usr/include/eigen3"
LDLIBS="$LDLIBS -lGL -lkqueue"
LDLIBS="$LDLIBS -lSDL2"

if $OPENGL_REFERENCE_RENDERER; then
COMPILE_FLAGS="$COMPILE_FLAGS -DOPENGL_REFERENCE_RENDERER"
LDLIBS="$LDLIBS -lGLEW"
if [ "$(uname)" == "Darwin" ]; then
LDLIBS="$LDLIBS -framework OpenGL"
else
LDLIBS="$LDLIBS -lGL"
fi
fi

# -----------------------------------------------------------------------------
@@ -9,7 +9,8 @@
#include <emilib/imgui_sdl.cpp>
#include <emilib/timer.cpp>

// For gl path:
#include <emilib/gl_lib.cpp>
#include <emilib/gl_lib_sdl.cpp>
#include <emilib/imgui_gl_lib.cpp>
#ifdef OPENGL_REFERENCE_RENDERER
#include <emilib/gl_lib.cpp>
#include <emilib/gl_lib_sdl.cpp>
#include <emilib/imgui_gl_lib.cpp>
#endif
@@ -5,10 +5,12 @@
#include <emilib/timer.hpp>
#include <loguru.hpp>

// For gl path:
#include <emilib/gl_lib_opengl.hpp>
#include <emilib/gl_lib_sdl.hpp>
#include <emilib/imgui_gl_lib.hpp>
#ifdef OPENGL_REFERENCE_RENDERER
// For gl path:
#include <emilib/gl_lib_opengl.hpp>
#include <emilib/gl_lib_sdl.hpp>
#include <emilib/imgui_gl_lib.hpp>
#endif // OPENGL_REFERENCE_RENDERER

#include "imgui_sw.hpp"

@@ -193,6 +195,7 @@ void run_software()
}
}

#ifdef OPENGL_REFERENCE_RENDERER
void run_gl()
{
sdl::Params sdl_params;
@@ -235,12 +238,16 @@ void run_gl()
SDL_GL_SwapWindow(sdl.window);
}
}
#endif // OPENGL_REFERENCE_RENDERER

int main(int argc, char* argv[])
{
loguru::g_colorlogtostderr = false;
loguru::init(argc, argv);

run_software();
// run_gl(); // Reference renderer.
#ifdef OPENGL_REFERENCE_RENDERER
run_gl();
#else
run_software();
#endif
}

0 comments on commit a99a26b

Please sign in to comment.
You can’t perform that action at this time.