Commit 4a81a05b authored by Kenneth Moreland's avatar Kenneth Moreland

Support GLFW library for tests.

Previously we were using GLUT to create windows and OpenGL contexts.
However, the base GLUT is no longer maintained and APPLE as deprecated
its use. There is another project, FreeGLUT, that is poised to replace
the original GLUT library, but it does not support native Mac windows
yet.

There is another library named GLFW that is also a cross-platform
library for creating OpenGL windows, and this one supports the native
Mac windows. For now we are supporting both (with the default being
GLUT, which is still more common).
parent 866def6d
......@@ -5,7 +5,7 @@
## This source code is released under the New BSD License.
#
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
# Turn off policy 0017, which makes modules packaged with CMake find
# any module rather than just others packaged with CMake. This is
......@@ -254,8 +254,8 @@ MACRO(ICET_ADD_LIBRARY library_name)
)
IF (NOT ICET_INSTALL_NO_DEVELOPMENT)
INSTALL(EXPORT ${ICET_INSTALL_EXPORT_NAME}
DESTINATION ${ICET_INSTALL_LIB_DIR}
)
DESTINATION ${ICET_INSTALL_LIB_DIR}
)
ENDIF (NOT ICET_INSTALL_NO_DEVELOPMENT)
ENDIF(NOT ICET_INSTALL_NO_LIBRARIES)
ENDMACRO(ICET_ADD_LIBRARY)
......
......@@ -6,14 +6,40 @@
#
IF (ICET_USE_OPENGL)
FIND_PACKAGE(GLUT)
IF (GLUT_FOUND)
SET(ICET_TESTS_USE_OPENGL 1)
ENDIF (GLUT_FOUND)
SET(ICET_OPENGL_WINDOW_LIBRARY GLUT
CACHE STRING
"The name of the library the IceT tests will use to create windows for
OpenGL contexts. Supported values are GLUT and GLFW."
)
SET_PROPERTY(CACHE ICET_OPENGL_WINDOW_LIBRARY
PROPERTY STRINGS GLUT GLFW
)
MARK_AS_ADVANCED(ICET_OPENGL_WINDOW_LIBRARY)
IF (ICET_OPENGL_WINDOW_LIBRARY STREQUAL GLUT)
FIND_PACKAGE(GLUT)
IF (GLUT_FOUND)
INCLUDE_DIRECTORIES(${GLUT_INCLUDE_DIR})
SET(ICET_TESTS_USE_OPENGL 1)
SET(ICET_TESTS_USE_GLUT 1)
ELSE (GLUT_FOUND)
MESSAGE(WARNING "Cannot find GLUT library. OpenGL tests disabled.")
ENDIF (GLUT_FOUND)
ELSEIF (ICET_OPENGL_WINDOW_LIBRARY STREQUAL GLFW)
FIND_PACKAGE(GLFW)
IF (GLFW_FOUND)
INCLUDE_DIRECTORIES(${GLFW_INCLUDE_DIR})
SET(ICET_TESTS_USE_OPENGL 1)
SET(ICET_TESTS_USE_GLFW 1)
ELSE (GLFW_FOUND)
MESSAGE(WARNING "Cannot find GLFW library. OpenGL tests disabled.")
ENDIF (GLFW_FOUND)
ELSE ()
MESSAGE(SEND_ERROR "Invalid value for ICET_OPENGL_WINDOW_LIBRARY: ${ICET_OPENGL_WINDOW_LIBRARY}")
ENDIF ()
ENDIF (ICET_USE_OPENGL)
IF (NOT ICET_TESTS_USE_OPENGL)
MESSAGE(STATUS "Most tests require ICET_USE_OPENGL and Glut. Those tests are disabled.")
MESSAGE(STATUS "Most tests require ICET_USE_OPENGL and GLUT or GLFW. Those tests are disabled.")
ENDIF (NOT ICET_TESTS_USE_OPENGL)
SET(MyTests
......@@ -61,11 +87,13 @@ TARGET_LINK_LIBRARIES(icetTests_mpi
IceTMPI
)
IF (ICET_TESTS_USE_OPENGL)
TARGET_LINK_LIBRARIES(icetTests_mpi
IceTGL
${OPENGL_glu_LIBRARY}
${GLUT_LIBRARIES}
)
TARGET_LINK_LIBRARIES(icetTests_mpi IceTGL)
IF (ICET_TESTS_USE_GLUT)
TARGET_LINK_LIBRARIES(icetTests_mpi ${GLUT_LIBRARIES})
ENDIF (ICET_TESTS_USE_GLUT)
IF (ICET_TESTS_USE_GLFW)
TARGET_LINK_LIBRARIES(icetTests_mpi ${GLFW_LIBRARY})
ENDIF (ICET_TESTS_USE_GLFW)
ENDIF (ICET_TESTS_USE_OPENGL)
IF (ICET_MPIRUN_EXE)
......
......@@ -29,16 +29,18 @@
#include <sys/stat.h>
#include <fcntl.h>
#ifdef ICET_TESTS_USE_OPENGL
#ifdef ICET_TESTS_USE_GLUT
#ifndef __APPLE__
#include <GL/glut.h>
#include <GL/gl.h>
#else
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#endif
#endif
#ifdef ICET_TESTS_USE_GLFW
#include <GLFW/glfw3.h>
#endif
#ifndef WIN32
#include <unistd.h>
#else
......@@ -58,11 +60,13 @@ int SINGLE_IMAGE_STRATEGY_LIST_SIZE = 4;
IceTSizeType SCREEN_WIDTH;
IceTSizeType SCREEN_HEIGHT;
#ifdef ICET_TESTS_USE_OPENGL
#ifdef ICET_TESTS_USE_GLUT
static int windowId;
#endif
static int (*test_function)(void);
#endif /* ICET_TESTS_USE_OPENGL */
#ifdef ICET_TESTS_USE_GLFW
static GLFWwindow *window;
#endif
#ifdef ICET_TESTS_USE_OPENGL
static void checkOglError(void)
......@@ -200,11 +204,15 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
/* while (i == 0) sleep(1); */
/* } */
#ifdef ICET_TESTS_USE_OPENGL
#ifdef ICET_TESTS_USE_GLUT
/* Let Glut have first pass at the arguments to grab any that it can use. */
glutInit(argcp, *argvp);
#endif
#ifdef ICET_TESTS_USE_GLFW
if (!glfwInit()) { exit(1); }
#endif
/* Parse my arguments. */
for (arg = 1; arg < argc; arg++) {
if (strcmp(argv[arg], "-width") == 0) {
......@@ -250,8 +258,8 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
exit(1);
}
#ifdef ICET_TESTS_USE_OPENGL
/* Create a renderable window. */
#ifdef ICET_TESTS_USE_GLUT
/* Create a renderable window. */
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
glutInitWindowPosition(0, 0);
glutInitWindowSize(width, height);
......@@ -261,7 +269,25 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
sprintf(title, "IceT Test %d of %d", rank, num_proc);
windowId = glutCreateWindow(title);
}
#endif /* ICET_TESTS_USE_OPENGL */
#endif /* ICET_TESTS_USE_GLUT */
#ifdef ICET_TESTS_USE_GLFW
/* Create a renderable window. */
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_DEPTH_BITS, 24);
glfwWindowHint(GLFW_SAMPLES, 0);
{
char title[256];
sprintf(title, "IceT Test %d of %d", rank, num_proc);
window = glfwCreateWindow(width, height, title, NULL, NULL);
}
glfwMakeContextCurrent(window);
#endif /* ICET_TESTS_USE_GLFW */
SCREEN_WIDTH = width;
SCREEN_HEIGHT = height;
......@@ -319,7 +345,8 @@ IceTBoolean strategy_uses_single_image_strategy(IceTEnum strategy)
}
}
#ifdef ICET_TESTS_USE_OPENGL
#if defined(ICET_TESTS_USE_GLUT)
static int (*test_function)(void);
static void no_op()
{
......@@ -338,6 +365,8 @@ static void glut_draw()
finalize_test(result);
glutDestroyWindow(windowId);
exit(result);
}
......@@ -360,6 +389,31 @@ int run_test(int (*tf)(void))
return TEST_NOT_PASSED;
}
#elif defined(ICET_TESTS_USE_GLFW)
int run_test(int (*tf)(void))
{
int result;
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
swap_buffers();
result = tf();
finalize_test(result);
glfwDestroyWindow(window);
glfwTerminate();
return result;
}
#elif defined(ICET_TESTS_USE_OPENGL)
#error "ICET_TESTS_USE_OPENGL defined but no window library is defined."
#else /* ICET_TESTS_USE_OPENGL */
int run_test(int (*tf)(void))
......@@ -373,15 +427,23 @@ int run_test(int (*tf)(void))
return result;
}
#endif /* ICET_TESTS_USE_OPENGL */
#endif /* !ICET_TESTS_USE_OPENGL */
#ifdef ICET_TESTS_USE_OPENGL
#ifdef ICET_TESTS_USE_GLUT
void swap_buffers(void)
{
glutSwapBuffers();
}
#endif
#ifdef ICET_TESTS_USE_GLFW
void swap_buffers(void)
{
glfwSwapBuffers(window);
glfwPollEvents();
}
#endif
#define TEST_RESULT_TAG 3492
extern void finalize_communication(void);
void finalize_test(IceTInt result)
......@@ -428,7 +490,4 @@ void finalize_test(IceTInt result)
icetDestroyContext(context);
finalize_communication();
#ifdef ICET_TESTS_USE_OPENGL
glutDestroyWindow(windowId);
#endif
}
......@@ -8,3 +8,7 @@
*/
#cmakedefine ICET_TESTS_USE_OPENGL
#cmakedefine ICET_TESTS_USE_GLUT
#cmakedefine ICET_TESTS_USE_GLFW
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment