| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <geogram_gfx/basic/common.h> | ||
| 41 | #include <geogram_gfx/basic/GLSL.h> | ||
| 42 | #include <geogram_gfx/GLUP/GLUP_context.h> | ||
| 43 | #include <geogram/basic/logger.h> | ||
| 44 | #include <cstdlib> | ||
| 45 | |||
| 46 | #ifdef GEO_OS_EMSCRIPTEN | ||
| 47 | #include <GLFW/glfw3.h> | ||
| 48 | |||
| 49 | extern "C" { | ||
| 50 | using namespace GEO; | ||
| 51 | |||
| 52 | /*****************/ | ||
| 53 | |||
| 54 | // Functions used by Dear Imgui but not implemented by Emscripten's GLFW | ||
| 55 | // (declare dummy stubs) | ||
| 56 | |||
| 57 | struct GLFWgamepadstate; | ||
| 58 | |||
| 59 | int glfwGetError(const char** description); | ||
| 60 | int glfwGetGamepadState(int jid, GLFWgamepadstate* state); | ||
| 61 | void glfwGetMonitorContentScale ( | ||
| 62 | GLFWmonitor *monitor, float *xscale, float *yscale | ||
| 63 | ); | ||
| 64 | void glfwGetMonitorWorkarea ( | ||
| 65 | GLFWmonitor *monitor, int* xpos, int* ypos, int* width, int* height | ||
| 66 | ); | ||
| 67 | void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value); | ||
| 68 | void glfwSetWindowOpacity(GLFWwindow *window, float opacity); | ||
| 69 | |||
| 70 | /*****************/ | ||
| 71 | |||
| 72 | int glfwGetError(const char** description) { | ||
| 73 | geo_argused(description); | ||
| 74 | return 0; // GLFW_NO_ERROR | ||
| 75 | } | ||
| 76 | |||
| 77 | int glfwGetGamepadState(int jid, GLFWgamepadstate* state) { | ||
| 78 | geo_argused(jid); | ||
| 79 | geo_argused(state); | ||
| 80 | return GLFW_FALSE; | ||
| 81 | } | ||
| 82 | |||
| 83 | void glfwGetMonitorContentScale ( | ||
| 84 | GLFWmonitor *monitor, float *xscale, float *yscale | ||
| 85 | ) { | ||
| 86 | geo_argused(monitor); | ||
| 87 | if(xscale != nullptr) { | ||
| 88 | *xscale = 1.0f; | ||
| 89 | } | ||
| 90 | if(yscale != nullptr) { | ||
| 91 | *yscale = 1.0f; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | void glfwGetMonitorWorkarea ( | ||
| 96 | GLFWmonitor *monitor, int* xpos, int* ypos, int* width, int* height | ||
| 97 | ) { | ||
| 98 | geo_argused(monitor); | ||
| 99 | if(xpos != nullptr) { | ||
| 100 | *xpos = 0; | ||
| 101 | } | ||
| 102 | if(ypos != nullptr) { | ||
| 103 | *ypos = 0; | ||
| 104 | } | ||
| 105 | if(width != nullptr) { | ||
| 106 | *width = 1024; | ||
| 107 | } | ||
| 108 | if(height != nullptr) { | ||
| 109 | *height = 1024; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value) { | ||
| 114 | geo_argused(window); | ||
| 115 | geo_argused(attrib); | ||
| 116 | geo_argused(value); | ||
| 117 | } | ||
| 118 | |||
| 119 | void glfwSetWindowOpacity(GLFWwindow *window, float opacity) { | ||
| 120 | geo_argused(window); | ||
| 121 | geo_argused(opacity); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | |||
| 127 | namespace GEO { | ||
| 128 | |||
| 129 | namespace Graphics { | ||
| 130 | |||
| 131 | ✗ | void initialize() { | |
| 132 | #if !defined(GEO_OS_EMSCRIPTEN) && !defined(GEO_OS_ANDROID) | ||
| 133 | ✗ | if(!gladLoadGL()) { | |
| 134 | ✗ | Logger::err("GLAD") << "Could not load OpenGL" | |
| 135 | << std::endl; | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | ✗ | GL::initialize(); | |
| 139 | ✗ | GLSL::initialize(); | |
| 140 | ✗ | } | |
| 141 | |||
| 142 | ✗ | void terminate() { | |
| 143 | ✗ | GLSL::terminate(); | |
| 144 | ✗ | GL::terminate(); | |
| 145 | ✗ | } | |
| 146 | |||
| 147 | } | ||
| 148 | |||
| 149 | } | ||
| 150 |