|
| 1 | +/* |
| 2 | + * Copyright 2023 The Emscripten Authors. All rights reserved. |
| 3 | + * Emscripten is available under two separate licenses, the MIT license and the |
| 4 | + * University of Illinois/NCSA Open Source License. Both these licenses can be |
| 5 | + * found in the LICENSE file. |
| 6 | + */ |
| 7 | + |
| 8 | +#include <GLFW/glfw3.h> |
| 9 | +#include <assert.h> |
| 10 | +#include <emscripten/html5.h> |
| 11 | + |
| 12 | +static void checkDefaultWindowHints() { |
| 13 | + int ok = EM_ASM_INT({ |
| 14 | + var res = 1; |
| 15 | + for (var k in TEST_GLFW3_DEFAULTS_HINTS) { |
| 16 | + if (GLFW.defaultHints[k] !== TEST_GLFW3_DEFAULTS_HINTS[k]) |
| 17 | + res = 0; |
| 18 | + } |
| 19 | + return res; |
| 20 | + }); |
| 21 | + assert(ok == 1); |
| 22 | +} |
| 23 | + |
| 24 | +int main() { |
| 25 | + |
| 26 | + EM_ASM( |
| 27 | + TEST_GLFW3_DEFAULTS_HINTS = {}; |
| 28 | + TEST_GLFW3_DEFAULTS_HINTS[0x00020001] = 0; |
| 29 | + TEST_GLFW3_DEFAULTS_HINTS[0x00020002] = 0; |
| 30 | + TEST_GLFW3_DEFAULTS_HINTS[0x00020003] = 1; |
| 31 | + TEST_GLFW3_DEFAULTS_HINTS[0x00020004] = 1; |
| 32 | + TEST_GLFW3_DEFAULTS_HINTS[0x00020005] = 1; |
| 33 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002000A] = 0; |
| 34 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002200C] = 0; |
| 35 | + |
| 36 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021001] = 8; |
| 37 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021002] = 8; |
| 38 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021003] = 8; |
| 39 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021004] = 8; |
| 40 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021005] = 24; |
| 41 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021006] = 8; |
| 42 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021007] = 0; |
| 43 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021008] = 0; |
| 44 | + TEST_GLFW3_DEFAULTS_HINTS[0x00021009] = 0; |
| 45 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002100A] = 0; |
| 46 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002100B] = 0; |
| 47 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002100C] = 0; |
| 48 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002100D] = 0; |
| 49 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002100E] = 0; |
| 50 | + TEST_GLFW3_DEFAULTS_HINTS[0x0002100F] = 0; |
| 51 | + |
| 52 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022001] = 0x00030001; |
| 53 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022002] = 1; |
| 54 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022003] = 0; |
| 55 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022004] = 0; |
| 56 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022005] = 0; |
| 57 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022006] = 0; |
| 58 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022007] = 0; |
| 59 | + TEST_GLFW3_DEFAULTS_HINTS[0x00022008] = 0; |
| 60 | + ); |
| 61 | + |
| 62 | + assert(glfwInit() == GL_TRUE); |
| 63 | + |
| 64 | + // Use case: after glfwInit, default window hints are correct |
| 65 | + { |
| 66 | + checkDefaultWindowHints(); |
| 67 | + } |
| 68 | + |
| 69 | + // Use case: updates a window hint |
| 70 | + // Expected results: window hint is properly updated |
| 71 | + // default window hints are not affected |
| 72 | + { |
| 73 | + // GLFW_DEPTH_BITS |
| 74 | + assert(EM_ASM_INT(return GLFW.hints[0x00021005];) == 24); |
| 75 | + glfwWindowHint(GLFW_DEPTH_BITS, 16); |
| 76 | + assert(EM_ASM_INT(return GLFW.hints[0x00021005];) == 16); |
| 77 | + checkDefaultWindowHints(); |
| 78 | + } |
| 79 | + |
| 80 | + // Use case: resets window hints to default |
| 81 | + // Expected results: previously changed window hint is back to its default value |
| 82 | + // default window hints are not affected |
| 83 | + { |
| 84 | + glfwDefaultWindowHints(); |
| 85 | + assert(EM_ASM_INT(return GLFW.hints[0x00021005];) == 24); |
| 86 | + checkDefaultWindowHints(); |
| 87 | + } |
| 88 | + |
| 89 | + // Use case: change window hint, create window, then change window hint |
| 90 | + // Expected results: the window hint set at creation time (which is now a |
| 91 | + // window attribute that can be read with glfwGetWindowAttrib) |
| 92 | + // does not change |
| 93 | + { |
| 94 | + glfwDefaultWindowHints(); |
| 95 | + glfwWindowHint(GLFW_DEPTH_BITS, 16); |
| 96 | + GLFWwindow* window = glfwCreateWindow(640, 480, "test_glfw3_default_hints.c", NULL, NULL); |
| 97 | + assert(glfwGetWindowAttrib(window, GLFW_DEPTH_BITS) == 16); |
| 98 | + glfwWindowHint(GLFW_DEPTH_BITS, 24); |
| 99 | + assert(glfwGetWindowAttrib(window, GLFW_DEPTH_BITS) == 16); |
| 100 | + } |
| 101 | + |
| 102 | + glfwTerminate(); |
| 103 | + |
| 104 | + return 0; |
| 105 | +} |
0 commit comments