From 546c99a3a33f5b6f96bd82ed18b704ab0e811904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 6 Nov 2017 00:32:23 +0100 Subject: [PATCH] Made sharing an example --- .gitignore | 2 +- docs/context.dox | 2 +- examples/CMakeLists.txt | 4 +++- {tests => examples}/sharing.c | 43 ++++------------------------------- tests/CMakeLists.txt | 4 +--- 5 files changed, 11 insertions(+), 44 deletions(-) rename {tests => examples}/sharing.c (86%) diff --git a/.gitignore b/.gitignore index dd88e65e..f6103c22 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ examples/heightmap examples/offscreen examples/particles examples/splitview +examples/sharing examples/simple examples/wave tests/*.app @@ -74,7 +75,6 @@ tests/joysticks tests/monitors tests/msaa tests/reopen -tests/sharing tests/tearing tests/threads tests/timeout diff --git a/docs/context.dox b/docs/context.dox index 08aa1a98..58c62217 100644 --- a/docs/context.dox +++ b/docs/context.dox @@ -61,7 +61,7 @@ information. The name and number of this chapter unfortunately varies between versions and APIs, but has at times been named _Shared Objects and Multiple Contexts_. -GLFW comes with a barebones object sharing test program called `sharing`. +GLFW comes with a barebones object sharing example program called `sharing`. @subsection context_offscreen Offscreen contexts diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f7a2ebe4..b458609f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -35,6 +35,7 @@ add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD}) add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD}) add_executable(offscreen offscreen.c ${ICON} ${GLAD}) add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD}) +add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${ICON} ${GLAD}) add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD}) add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD}) add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD}) @@ -44,7 +45,7 @@ if (RT_LIBRARY) target_link_libraries(particles "${RT_LIBRARY}") endif() -set(WINDOWS_BINARIES boing gears heightmap particles simple splitview wave) +set(WINDOWS_BINARIES boing gears heightmap particles sharing simple splitview wave) set(CONSOLE_BINARIES offscreen) set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES @@ -61,6 +62,7 @@ if (APPLE) set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") + set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple") set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView") set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") diff --git a/tests/sharing.c b/examples/sharing.c similarity index 86% rename from tests/sharing.c rename to examples/sharing.c index e5ffadc9..be35faff 100644 --- a/tests/sharing.c +++ b/examples/sharing.c @@ -1,5 +1,5 @@ //======================================================================== -// Context sharing test program +// Context sharing example // Copyright (c) Camilla Löwy // // This software is provided 'as-is', without any express or implied @@ -22,15 +22,10 @@ // distribution. // //======================================================================== -// -// This program is used to test sharing of objects between contexts -// -//======================================================================== #include #include -#include #include #include @@ -71,17 +66,6 @@ static void error_callback(int error, const char* description) fprintf(stderr, "Error: %s\n", description); } -void APIENTRY debug_callback(GLenum source, - GLenum type, - GLuint id, - GLenum severity, - GLsizei length, - const GLchar* message, - const void* user) -{ - fprintf(stderr, "Error: %s\n", message); -} - static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) @@ -90,28 +74,15 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, int main(int argc, char** argv) { - int ch; GLFWwindow* windows[2]; GLuint texture, program, vertex_buffer; GLint mvp_location, vpos_location, color_location, texture_location; - srand((unsigned int) time(NULL)); - glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); - while ((ch = getopt(argc, argv, "d")) != -1) - { - switch (ch) - { - case 'd': - glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); - break; - } - } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); @@ -134,12 +105,6 @@ int main(int argc, char** argv) // pointers should be re-usable between them gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); - if (GLAD_GL_KHR_debug) - { - glDebugMessageCallback(debug_callback, NULL); - glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); - } - // Create the OpenGL objects inside the first context, created above // All objects will be shared with the second context, created below { @@ -150,6 +115,8 @@ int main(int argc, char** argv) glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); + srand((unsigned int) glfwGetTimerValue()); + for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) @@ -235,8 +202,8 @@ int main(int argc, char** argv) int i; const vec3 colors[2] = { - { 0.3f, 0.4f, 1.f }, - { 0.8f, 0.4f, 1.f } + { 0.8f, 0.4f, 1.f }, + { 0.3f, 0.4f, 1.f } }; for (i = 0; i < 2; i++) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1a39d59d..278127b6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,6 @@ add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD}) add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD}) add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD}) add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD}) -add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${GETOPT} ${GLAD}) add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT} ${GLAD}) add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD}) add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD}) @@ -46,7 +45,7 @@ if (RT_LIBRARY) target_link_libraries(threads "${RT_LIBRARY}") endif() -set(WINDOWS_BINARIES empty gamma icon inputlag joysticks sharing tearing threads +set(WINDOWS_BINARIES empty gamma icon inputlag joysticks tearing threads timeout title windows) set(CONSOLE_BINARIES clipboard events msaa glfwinfo iconify monitors reopen cursor) @@ -76,7 +75,6 @@ if (APPLE) set_target_properties(gamma PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gamma") set_target_properties(inputlag PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Input Lag") set_target_properties(joysticks PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Joysticks") - set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout")