GCC Code Coverage Report


Directory: ./
File: lib/geogram_gfx/full_screen_effects/full_screen_effect.cpp
Date: 2026-09-07 02:37:58
Exec Total Coverage
Lines: 0 107 0.0%
Functions: 0 13 0.0%
Branches: 0 78 0.0%

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
41 #include <geogram_gfx/full_screen_effects/full_screen_effect.h>
42 #include <geogram_gfx/basic/GLSL.h>
43 #include <geogram_gfx/GLUP/shaders/embedded_shaders.h>
44 #include <geogram/basic/command_line.h>
45 #include <geogram/basic/logger.h>
46
47 namespace {
48 using namespace GEO;
49
50 void vertex_shader_preamble_pseudo_file(
51 GLSL::PseudoFileProvider* provider, std::vector<GLSL::Source>& sources
52 ) {
53 FullScreenEffectImpl* ctxt = dynamic_cast<FullScreenEffectImpl*>(
54 provider
55 );
56 geo_assert(ctxt != nullptr);
57 ctxt->get_vertex_shader_preamble_pseudo_file(sources);
58 }
59
60 void fragment_shader_preamble_pseudo_file(
61 GLSL::PseudoFileProvider* provider, std::vector<GLSL::Source>& sources
62 ) {
63 FullScreenEffectImpl* ctxt = dynamic_cast<FullScreenEffectImpl*>(
64 provider
65 );
66 geo_assert(ctxt != nullptr);
67 ctxt->get_fragment_shader_preamble_pseudo_file(sources);
68 }
69 }
70
71 namespace GEO {
72
73 FullScreenEffectImpl::FullScreenEffectImpl() :
74 initialized_(false),
75 OK_(true),
76 width_(0),
77 height_(0),
78 ES_profile_(false),
79 main_framebuffer_id_(0) {
80 }
81
82 FullScreenEffectImpl::~FullScreenEffectImpl() {
83 }
84
85 double FullScreenEffectImpl::required_GLSL_version() const {
86 return 1.0;
87 }
88
89 void FullScreenEffectImpl::get_vertex_shader_preamble_pseudo_file(
90 std::vector<GLSL::Source>& sources
91 ) {
92 if(ES_profile_) {
93 sources.push_back(
94 "#version 100 \n"
95 "#define GLUP_VERTEX_SHADER \n"
96 );
97 } else {
98 sources.push_back(
99 #ifdef GEO_OS_APPLE
100 "#version 150 core \n"
101 #else
102 "#version 130 \n"
103 #endif
104 "#define GLUP_VERTEX_SHADER \n"
105 );
106 }
107 }
108
109
110 void FullScreenEffectImpl::get_fragment_shader_preamble_pseudo_file(
111 std::vector<GLSL::Source>& sources
112 ) {
113 if(ES_profile_) {
114 sources.push_back(
115 "#version 100 \n"
116 "#define GLUP_FRAGMENT_SHADER \n"
117 "precision mediump float; \n"
118 "#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
119 " precision highp int; \n"
120 "#endif \n"
121 );
122 } else {
123 sources.push_back(
124 #ifdef GEO_OS_APPLE
125 "#version 150 core \n"
126 #else
127 "#version 130 \n"
128 #endif
129 "#define GLUP_FRAGMENT_SHADER \n"
130 );
131 }
132 }
133
134 void FullScreenEffectImpl::pre_render(index_t w, index_t h) {
135 main_framebuffer_id_ = FrameBufferObject::bound_framebuffer_id();
136 if(!initialized_) {
137 initialize(w,h) ;
138 }
139 if(!OK_) {
140 return;
141 }
142 if(w != width() || h != height()) {
143 resize(w,h) ;
144 }
145 if(draw_FBO_.initialized()) {
146 draw_FBO_.bind_as_framebuffer();
147 GEO_CHECK_GL();
148 }
149 }
150
151 void FullScreenEffectImpl::post_render() {
152 glBindFramebuffer(GL_FRAMEBUFFER, main_framebuffer_id_);
153 if(draw_FBO_.initialized()) {
154 glDisable(GL_DEPTH_TEST);
155 draw_FBO_.unbind();
156
157 glActiveTexture(GL_TEXTURE0);
158 draw_FBO_.bind_as_texture();
159
160 glViewport(0, 0, GLsizei(width()), GLsizei(height()));
161
162 draw_unit_textured_quad();
163 glEnable(GL_DEPTH_TEST);
164 draw_FBO_.unbind();
165 reset_alpha();
166
167 }
168 GEO_CHECK_GL();
169 }
170
171 void FullScreenEffectImpl::update() {
172 }
173
174 void FullScreenEffectImpl::initialize(index_t width, index_t height) {
175 width_ = width;
176 height_ = height;
177 initialized_ = true ;
178 #if defined(GEO_OS_EMSCRIPTEN) || defined(GEO_OS_ANDROID)
179 ES_profile_ = true;
180 #endif
181
182 static bool first_time = true;
183
184 if(first_time) {
185 GLSL::register_GLSL_include_file(
186 "fullscreen/current_profile/vertex_shader_preamble.h",
187 vertex_shader_preamble_pseudo_file
188 );
189
190 GLSL::register_GLSL_include_file(
191 "fullscreen/current_profile/fragment_shader_preamble.h",
192 fragment_shader_preamble_pseudo_file
193 );
194
195 GLUP::register_embedded_shaders_fullscreen();
196
197 first_time = false;
198 }
199
200 double supp_ver = GLSL::supported_language_version();
201 double req_ver = required_GLSL_version();
202 OK_ = (supp_ver >= req_ver);
203 if(!OK_) {
204 Logger::err("Renderer")
205 << "This FullScreenEffect requires GLSL ver. >= "
206 << req_ver
207 << std::endl;
208 Logger::err("Renderer")
209 << "This GPU has GLSL ver. " << supp_ver
210 << std::endl;
211 return;
212 }
213 GEO_CHECK_GL();
214 draw_FBO_.initialize(width, height, true, GL_RGBA, false);
215 GEO_CHECK_GL();
216 }
217
218 void FullScreenEffectImpl::resize(index_t width, index_t height) {
219 width_ = width;
220 height_ = height;
221 if(draw_FBO_.initialized()) {
222 GEO_CHECK_GL();
223 draw_FBO_.resize(width, height);
224 GEO_CHECK_GL();
225 }
226 }
227
228 void FullScreenEffectImpl::reset_alpha() {
229 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
230 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
231 glClear(GL_COLOR_BUFFER_BIT);
232 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
233 }
234 }
235