From afcb2abbd42503d3f9a97b81f71e953d4bf42085 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 4 Oct 2010 19:32:39 +0200 Subject: [PATCH 1/5] Added simple context sharing test program. --- tests/CMakeLists.txt | 4 +- tests/sharing.c | 144 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 tests/sharing.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fcd76746..822f603f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,17 +16,19 @@ if(APPLE) # Set fancy names for bundles add_executable(Accuracy MACOSX_BUNDLE accuracy.c) add_executable(FSAA MACOSX_BUNDLE fsaa.c) + add_executable(Sharing MACOSX_BUNDLE sharing.c) add_executable(Tearing MACOSX_BUNDLE tearing.c) add_executable(Windows MACOSX_BUNDLE windows.c) else() # Set boring names for executables add_executable(accuracy WIN32 accuracy.c) + add_executable(sharing WIN32 sharing.c) add_executable(tearing WIN32 tearing.c) add_executable(fsaa WIN32 fsaa.c) add_executable(windows WIN32 windows.c) endif(APPLE) -set(WINDOWS_BINARIES accuracy tearing windows) +set(WINDOWS_BINARIES accuracy sharing tearing windows) set(CONSOLE_BINARIES defaults events fsaa fsfocus iconify joysticks peter reopen version) if(MSVC) diff --git a/tests/sharing.c b/tests/sharing.c new file mode 100644 index 00000000..765b4ec2 --- /dev/null +++ b/tests/sharing.c @@ -0,0 +1,144 @@ +//======================================================================== +// Context sharing test program +// Copyright (c) Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== +// +// This program is used to test sharing of objects between contexts +// +//======================================================================== + +#include + +#include +#include + +static GLFWwindow open_window(const char* title, GLFWwindow share) +{ + GLFWwindow window; + + window = glfwOpenWindow(400, 400, GLFW_WINDOWED, title, share); + if (!window) + return NULL; + + glfwSwapInterval(1); + + return window; +} + +static GLuint create_texture(void) +{ + int x, y; + char pixels[256 * 256]; + GLuint texture; + + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + + for (y = 0; y < 256; y++) + { + for (x = 0; x < 256; x++) + pixels[y * 256 + x] = rand() % 256; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + return texture; +} + +static void draw_quad(GLuint texture) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0.f, 1.f, 0.f, 1.f); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glColor3f(0.6f, 0.f, 0.6f); + + glBegin(GL_QUADS); + + glTexCoord2f(0.f, 0.f); + glVertex2f(0.f, 0.f); + + glTexCoord2f(1.f, 0.f); + glVertex2f(1.f, 0.f); + + glTexCoord2f(1.f, 1.f); + glVertex2f(1.f, 1.f); + + glTexCoord2f(0.f, 1.f); + glVertex2f(0.f, 1.f); + + glEnd(); +} + +int main(int argc, char** argv) +{ + GLFWwindow windows[2]; + GLuint texture; + + if (!glfwInit()) + { + fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + windows[0] = open_window("First", NULL); + if (!windows[0]) + { + fprintf(stderr, "Failed to open first GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + texture = create_texture(); + + windows[1] = open_window("Second", windows[0]); + if (!windows[1]) + { + fprintf(stderr, "Failed to open second GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1])) + { + glfwMakeWindowCurrent(windows[0]); + glClear(GL_COLOR_BUFFER_BIT); + draw_quad(texture); + glfwSwapBuffers(); + + glfwMakeWindowCurrent(windows[1]); + glClear(GL_COLOR_BUFFER_BIT); + draw_quad(texture); + glfwSwapBuffers(); + + glfwWaitEvents(); + } + + glfwTerminate(); + exit(EXIT_SUCCESS); +} + From 8dff22d9de002239f6abd0f1aafc0994d00c4e70 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 4 Oct 2010 19:35:28 +0200 Subject: [PATCH 2/5] Removed superfluous clear, added comment. --- tests/sharing.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/sharing.c b/tests/sharing.c index 765b4ec2..ea451a3b 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -114,6 +114,9 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + // This is the one and only time we create a texture + // It is created inside the first context created above + // It will then be shared with the second context created below texture = create_texture(); windows[1] = open_window("Second", windows[0]); @@ -126,12 +129,10 @@ int main(int argc, char** argv) while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1])) { glfwMakeWindowCurrent(windows[0]); - glClear(GL_COLOR_BUFFER_BIT); draw_quad(texture); glfwSwapBuffers(); glfwMakeWindowCurrent(windows[1]); - glClear(GL_COLOR_BUFFER_BIT); draw_quad(texture); glfwSwapBuffers(); From 2899e8765cb7b95c84b4178dfeba9b2279406469 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 4 Oct 2010 21:08:42 +0200 Subject: [PATCH 3/5] Added window positioning to sharing test. --- tests/sharing.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/sharing.c b/tests/sharing.c index ea451a3b..0c6f5988 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -32,11 +32,14 @@ #include #include +#define WIDTH 400 +#define HEIGHT 400 + static GLFWwindow open_window(const char* title, GLFWwindow share) { GLFWwindow window; - window = glfwOpenWindow(400, 400, GLFW_WINDOWED, title, share); + window = glfwOpenWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share); if (!window) return NULL; @@ -100,6 +103,7 @@ int main(int argc, char** argv) { GLFWwindow windows[2]; GLuint texture; + int x, y; if (!glfwInit()) { @@ -114,6 +118,8 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + glfwGetWindowPos(windows[0], &x, &y); + // This is the one and only time we create a texture // It is created inside the first context created above // It will then be shared with the second context created below @@ -126,6 +132,8 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + glfwSetWindowPos(windows[1], x + WIDTH + 50, y); + while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1])) { glfwMakeWindowCurrent(windows[0]); From afb1c68791c1b6705adb4305dcdb1a12c36fea2d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 4 Oct 2010 21:14:19 +0200 Subject: [PATCH 4/5] Removed executable flag again (wtf). --- src/win32/win32_window.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/win32/win32_window.c diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c old mode 100755 new mode 100644 From 9e1031a35adb5c90b8e73229048a4bc9b07d9d69 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 4 Oct 2010 21:14:58 +0200 Subject: [PATCH 5/5] Moved listmodes test program to tests directory. --- examples/CMakeLists.txt | 10 ++-------- tests/CMakeLists.txt | 4 +++- {examples => tests}/listmodes.c | 0 3 files changed, 5 insertions(+), 9 deletions(-) rename {examples => tests}/listmodes.c (100%) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1390ab13..3f5a7c4f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,8 +5,6 @@ link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include ${OPENGL_INCLUDE_DIR}) -add_executable(listmodes listmodes.c) - if(APPLE) # Set fancy names for bundles add_executable(Boing MACOSX_BUNDLE boing.c) @@ -25,21 +23,17 @@ else(APPLE) endif(APPLE) set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) -set(CONSOLE_BINARIES listmodes) if(MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables - set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} + set_target_properties(${WINDOWS_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif(MSVC) if(CYGWIN) # Set cross-compile and subsystem compile and link flags - set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} - PROPERTIES COMPILE_FLAGS "-mno-cygwin") set_target_properties(${WINDOWS_BINARIES} + PROPERTIES COMPILE_FLAGS "-mno-cygwin" PROPERTIES LINK_FLAGS "-mno-cygwin -mwindows") - set_target_properties(${CONSOLE_BINARIES} - PROPERTIES LINK_FLAGS "-mno-cygwin -mconsole") endif(CYGWIN) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 822f603f..085b6b67 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable(events events.c) add_executable(fsfocus fsfocus.c) add_executable(iconify iconify.c getopt.c) add_executable(joysticks joysticks.c) +add_executable(listmodes listmodes.c) add_executable(peter peter.c) add_executable(reopen reopen.c) add_executable(version version.c getopt.c) @@ -29,7 +30,8 @@ else() endif(APPLE) set(WINDOWS_BINARIES accuracy sharing tearing windows) -set(CONSOLE_BINARIES defaults events fsaa fsfocus iconify joysticks peter reopen version) +set(CONSOLE_BINARIES defaults events fsaa fsfocus iconify joysticks listmodes + peter reopen version) if(MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables diff --git a/examples/listmodes.c b/tests/listmodes.c similarity index 100% rename from examples/listmodes.c rename to tests/listmodes.c