| 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 | #ifndef GEOGRAM_GFX_GLUP_GLUP_CONTEXT_GLSL | ||
| 41 | #define GEOGRAM_GFX_GLUP_GLUP_CONTEXT_GLSL | ||
| 42 | |||
| 43 | #include <geogram_gfx/basic/common.h> | ||
| 44 | #include <geogram_gfx/GLUP/GLUP_context.h> | ||
| 45 | |||
| 46 | /** | ||
| 47 | * \file geogram_gfx/GLUP/GLUP_context_GLSL.h | ||
| 48 | * \brief Internal implementation of GLUP using modern OpenGL and GLSL shaders. | ||
| 49 | */ | ||
| 50 | |||
| 51 | |||
| 52 | namespace GLUP { | ||
| 53 | using namespace GEO; | ||
| 54 | |||
| 55 | |||
| 56 | /*********************************************************************/ | ||
| 57 | |||
| 58 | #ifdef GEO_GL_140 | ||
| 59 | |||
| 60 | /** | ||
| 61 | * \brief Implementation of GLUP using modern OpenGL with GLSL 1.40 | ||
| 62 | * shaders. | ||
| 63 | * \details We do not have geometry shaders, hence array mode is supported | ||
| 64 | * only for points, spheres and triangles (but picking works fine because | ||
| 65 | * fragment shader has gl_PrimitiveID). | ||
| 66 | */ | ||
| 67 | ✗ | class Context_GLSL140 : public Context { | |
| 68 | public: | ||
| 69 | /** | ||
| 70 | * \brief Context_GLSL140 constructor. | ||
| 71 | */ | ||
| 72 | Context_GLSL140(); | ||
| 73 | |||
| 74 | /** | ||
| 75 | * \copydoc Context::profile_name() | ||
| 76 | */ | ||
| 77 | const char* profile_name() const override; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * \copydoc Context::setup() | ||
| 81 | */ | ||
| 82 | void setup() override; | ||
| 83 | |||
| 84 | protected: | ||
| 85 | /** | ||
| 86 | * \copydoc Context::setup_GLUP_POINTS() | ||
| 87 | */ | ||
| 88 | void setup_GLUP_POINTS() override; | ||
| 89 | |||
| 90 | /** | ||
| 91 | * \copydoc Context::setup_GLUP_LINES() | ||
| 92 | */ | ||
| 93 | void setup_GLUP_LINES() override; | ||
| 94 | |||
| 95 | /** | ||
| 96 | * \copydoc Context::setup_GLUP_THICK_LINES() | ||
| 97 | */ | ||
| 98 | void setup_GLUP_THICK_LINES() override; | ||
| 99 | |||
| 100 | /** | ||
| 101 | * \copydoc Context::setup_GLUP_TRIANGLES() | ||
| 102 | */ | ||
| 103 | void setup_GLUP_TRIANGLES() override; | ||
| 104 | |||
| 105 | /** | ||
| 106 | * \copydoc Context::setup_GLUP_SPHERES() | ||
| 107 | */ | ||
| 108 | void setup_GLUP_SPHERES() override; | ||
| 109 | |||
| 110 | /** | ||
| 111 | * \copydoc Context::get_vertex_shader_preamble_pseudo_file() | ||
| 112 | */ | ||
| 113 | void get_vertex_shader_preamble_pseudo_file( | ||
| 114 | std::vector<GLSL::Source>& sources | ||
| 115 | ) override; | ||
| 116 | |||
| 117 | /** | ||
| 118 | * \copydoc Context::get_fragment_shader_preamble_pseudo_file() | ||
| 119 | */ | ||
| 120 | void get_fragment_shader_preamble_pseudo_file( | ||
| 121 | std::vector<GLSL::Source>& sources | ||
| 122 | ) override; | ||
| 123 | |||
| 124 | /** | ||
| 125 | * \copydoc Context::get_primitive_pseudo_file() | ||
| 126 | */ | ||
| 127 | void get_primitive_pseudo_file( | ||
| 128 | std::vector<GLSL::Source>& sources | ||
| 129 | ) override; | ||
| 130 | }; | ||
| 131 | |||
| 132 | #endif | ||
| 133 | |||
| 134 | /*********************************************************************/ | ||
| 135 | |||
| 136 | |||
| 137 | #ifdef GEO_GL_150 | ||
| 138 | /** | ||
| 139 | * \brief Implementation of GLUP using modern OpenGL with GLSL 1.50 | ||
| 140 | * shaders. | ||
| 141 | * \details All the primitives are implemented with good performance. | ||
| 142 | * Hexahedra and prisms do not support array mode (glupDrawArrays(), | ||
| 143 | * glupDrawElements()). This is because there is no standard OpenGL | ||
| 144 | * primitive with 8 or 5 vertices (except the configurable GL_PATCH | ||
| 145 | * that requires GLSL 4.40). | ||
| 146 | */ | ||
| 147 | ✗ | class Context_GLSL150 : public Context_GLSL140 { | |
| 148 | public: | ||
| 149 | |||
| 150 | /** | ||
| 151 | * \brief Context_GLSL150 constructor. | ||
| 152 | */ | ||
| 153 | Context_GLSL150(); | ||
| 154 | |||
| 155 | /** | ||
| 156 | * \copydoc Context::profile_name() | ||
| 157 | */ | ||
| 158 | const char* profile_name() const override; | ||
| 159 | |||
| 160 | /** | ||
| 161 | * \copydoc Context::setup() | ||
| 162 | */ | ||
| 163 | void setup() override; | ||
| 164 | |||
| 165 | protected: | ||
| 166 | /** | ||
| 167 | * \copydoc Context::setup_GLUP_THICK_LINES() | ||
| 168 | */ | ||
| 169 | void setup_GLUP_THICK_LINES() override; | ||
| 170 | |||
| 171 | /** | ||
| 172 | * \copydoc Context::setup_GLUP_TRIANGLES() | ||
| 173 | */ | ||
| 174 | void setup_GLUP_TRIANGLES() override; | ||
| 175 | |||
| 176 | /** | ||
| 177 | * \copydoc Context::setup_GLUP_QUADS() | ||
| 178 | */ | ||
| 179 | void setup_GLUP_QUADS() override; | ||
| 180 | |||
| 181 | /** | ||
| 182 | * \copydoc Context::setup_GLUP_TETRAHEDRA() | ||
| 183 | */ | ||
| 184 | void setup_GLUP_TETRAHEDRA() override; | ||
| 185 | |||
| 186 | /** | ||
| 187 | * \copydoc Context::setup_GLUP_PRISMS() | ||
| 188 | */ | ||
| 189 | void setup_GLUP_PRISMS() override; | ||
| 190 | |||
| 191 | /** | ||
| 192 | * \copydoc Context::setup_GLUP_HEXAHEDRA() | ||
| 193 | */ | ||
| 194 | void setup_GLUP_HEXAHEDRA() override; | ||
| 195 | |||
| 196 | /** | ||
| 197 | * \copydoc Context::setup_GLUP_PYRAMIDS() | ||
| 198 | */ | ||
| 199 | void setup_GLUP_PYRAMIDS() override; | ||
| 200 | |||
| 201 | /** | ||
| 202 | * \copydoc Context::setup_GLUP_CONNECTORS() | ||
| 203 | */ | ||
| 204 | void setup_GLUP_CONNECTORS() override; | ||
| 205 | |||
| 206 | /** | ||
| 207 | * \copydoc Context::get_geometry_shader_preamble_pseudo_file() | ||
| 208 | */ | ||
| 209 | void get_geometry_shader_preamble_pseudo_file( | ||
| 210 | std::vector<GLSL::Source>& sources | ||
| 211 | ) override; | ||
| 212 | |||
| 213 | /** | ||
| 214 | * \brief Deduces from the current primitive_source_ the | ||
| 215 | * input and output layout that should be used by the | ||
| 216 | * geometry shader. | ||
| 217 | */ | ||
| 218 | virtual void get_geometry_shader_layout( | ||
| 219 | std::vector<GLSL::Source>& sources | ||
| 220 | ); | ||
| 221 | |||
| 222 | /** | ||
| 223 | * \copydoc Context::get_primitive_pseudo_file() | ||
| 224 | */ | ||
| 225 | void get_primitive_pseudo_file( | ||
| 226 | std::vector<GLSL::Source>& sources | ||
| 227 | ) override; | ||
| 228 | }; | ||
| 229 | |||
| 230 | /*********************************************************************/ | ||
| 231 | |||
| 232 | /** | ||
| 233 | * \brief Implementation of GLUP using modern OpenGL with GLSL 4.40 | ||
| 234 | * shaders. | ||
| 235 | * \details This mostly reuses the GLSL 1.50 implementation, except | ||
| 236 | * for hexahedra and prisms, where it uses a tessellation shader to | ||
| 237 | * fetch the vertices. This is because GL_PATCH has a configurable | ||
| 238 | * number of vertices. | ||
| 239 | */ | ||
| 240 | class Context_GLSL440 : public Context_GLSL150 { | ||
| 241 | public: | ||
| 242 | |||
| 243 | /** | ||
| 244 | * \brief Context_GLSL440 constructor. | ||
| 245 | */ | ||
| 246 | Context_GLSL440(); | ||
| 247 | |||
| 248 | /** | ||
| 249 | * \copydoc Context::profile_name() | ||
| 250 | */ | ||
| 251 | const char* profile_name() const override; | ||
| 252 | |||
| 253 | protected: | ||
| 254 | /** | ||
| 255 | * \copydoc Context::setup_GLUP_HEXAHEDRA() | ||
| 256 | */ | ||
| 257 | void setup_GLUP_HEXAHEDRA() override; | ||
| 258 | |||
| 259 | /** | ||
| 260 | * \copydoc Context::setup_GLUP_PYRAMIDS() | ||
| 261 | */ | ||
| 262 | void setup_GLUP_PYRAMIDS() override; | ||
| 263 | |||
| 264 | /** | ||
| 265 | * \copydoc Context::get_vertex_shader_preamble_pseudo_file() | ||
| 266 | */ | ||
| 267 | void get_vertex_shader_preamble_pseudo_file( | ||
| 268 | std::vector<GLSL::Source>& sources | ||
| 269 | ) override; | ||
| 270 | |||
| 271 | /** | ||
| 272 | * \copydoc Context::get_fragment_shader_preamble_pseudo_file() | ||
| 273 | */ | ||
| 274 | void get_fragment_shader_preamble_pseudo_file( | ||
| 275 | std::vector<GLSL::Source>& sources | ||
| 276 | ) override; | ||
| 277 | |||
| 278 | /** | ||
| 279 | * \copydoc Context::get_geometry_shader_preamble_pseudo_file() | ||
| 280 | */ | ||
| 281 | void get_geometry_shader_preamble_pseudo_file( | ||
| 282 | std::vector<GLSL::Source>& sources | ||
| 283 | ) override; | ||
| 284 | |||
| 285 | /** | ||
| 286 | * \copydoc Context::get_tess_evaluation_shader_preamble_pseudo_file() | ||
| 287 | */ | ||
| 288 | void get_tess_evaluation_shader_preamble_pseudo_file( | ||
| 289 | std::vector<GLSL::Source>& sources | ||
| 290 | ) override; | ||
| 291 | |||
| 292 | /** | ||
| 293 | * \copydoc Context::get_primitive_pseudo_file() | ||
| 294 | */ | ||
| 295 | void get_primitive_pseudo_file( | ||
| 296 | std::vector<GLSL::Source>& sources | ||
| 297 | ) override; | ||
| 298 | |||
| 299 | /** | ||
| 300 | * \copydoc Context_GLSL150::get_geometry_shader_layout() | ||
| 301 | */ | ||
| 302 | void get_geometry_shader_layout( | ||
| 303 | std::vector<GLSL::Source>& sources | ||
| 304 | ) override; | ||
| 305 | |||
| 306 | bool use_tessellation_; | ||
| 307 | }; | ||
| 308 | |||
| 309 | /*********************************************************************/ | ||
| 310 | #endif | ||
| 311 | |||
| 312 | } | ||
| 313 | |||
| 314 | #endif | ||
| 315 |