| 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 H_GEOGRAM_GFX_BASIC_FBO_H | ||
| 41 | #define H_GEOGRAM_GFX_BASIC_FBO_H | ||
| 42 | |||
| 43 | #include <geogram_gfx/basic/common.h> | ||
| 44 | |||
| 45 | /** | ||
| 46 | * \file geogram_gfx/basic/frame_buffer_object.h | ||
| 47 | * \brief Helper class for manipulating OpenGL frame buffer objects. | ||
| 48 | */ | ||
| 49 | |||
| 50 | namespace GEO { | ||
| 51 | |||
| 52 | /** | ||
| 53 | * \brief An OpenGL frame buffer object. | ||
| 54 | */ | ||
| 55 | class GEOGRAM_GFX_API FrameBufferObject { | ||
| 56 | public: | ||
| 57 | /** | ||
| 58 | * \brief FrameBufferObject constructor. | ||
| 59 | * \details Creates an uninitialized FrameBufferObject. | ||
| 60 | */ | ||
| 61 | FrameBufferObject(); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * \brief FrameBufferObject destructor. | ||
| 65 | * \details Releases all the allocated OpenGL resources. | ||
| 66 | */ | ||
| 67 | ~FrameBufferObject(); | ||
| 68 | |||
| 69 | /** | ||
| 70 | * \brief Initializes the FrameBufferObject. | ||
| 71 | * \param[in] width_in the width (in pixels) | ||
| 72 | * \param[in] height_in the height (in picels) | ||
| 73 | * \param[in] with_depth_buffer if true, a depth buffer is also created | ||
| 74 | * \param[in] internal_storage the OpenGL internal storage | ||
| 75 | * \param[in] mipmaps if true, the created textures have mipmaps | ||
| 76 | */ | ||
| 77 | bool initialize( | ||
| 78 | index_t width_in, | ||
| 79 | index_t height_in, | ||
| 80 | bool with_depth_buffer, | ||
| 81 | GLint internal_storage, | ||
| 82 | bool mipmaps = false | ||
| 83 | ); | ||
| 84 | |||
| 85 | /** | ||
| 86 | * \brief Resizes the FrameBuferObject | ||
| 87 | * \param[in] new_width the new width, in pixels | ||
| 88 | * \param[in] new_height the new height, in pixels | ||
| 89 | */ | ||
| 90 | void resize(index_t new_width, index_t new_height); | ||
| 91 | |||
| 92 | /** | ||
| 93 | * \brief Binds this frame buffer as the input 2D texture. | ||
| 94 | */ | ||
| 95 | void bind_as_texture(); | ||
| 96 | |||
| 97 | /** | ||
| 98 | * \brief Binds the depth buffer of this frame buffer as the | ||
| 99 | * input 2D texture. | ||
| 100 | * \pre initialize() was called with with_depth_buffer=true | ||
| 101 | */ | ||
| 102 | void bind_depth_buffer_as_texture(); | ||
| 103 | |||
| 104 | /** | ||
| 105 | * \brief Binds this framebuffer as the output of OpenGL rendering. | ||
| 106 | * \details This memorizes the currently bound framebuffer. | ||
| 107 | */ | ||
| 108 | void bind_as_framebuffer(); | ||
| 109 | |||
| 110 | |||
| 111 | /** | ||
| 112 | * \brief Tests whether this framebuffer is bound as a framebuffer. | ||
| 113 | * \retval true if this framebuffer is bound, i.e. used for OpenGL | ||
| 114 | * output. | ||
| 115 | * \retval false otherwise | ||
| 116 | */ | ||
| 117 | bool is_bound_as_framebuffer() const; | ||
| 118 | |||
| 119 | /** | ||
| 120 | * \brief Unbind this framebuffer. | ||
| 121 | * \details This removes all the bindings (both as texture and | ||
| 122 | * as target of OpenGL rendering). If the framebuffer was bound | ||
| 123 | * as target of OpenGL rendering, then target of OpenGL rendering | ||
| 124 | * is reset to zero. | ||
| 125 | */ | ||
| 126 | void unbind(); | ||
| 127 | |||
| 128 | |||
| 129 | /** | ||
| 130 | * \brief Tests whether this FrameBufferObject is initialized. | ||
| 131 | * \retval true if this FrameBufferObject is initialized. | ||
| 132 | * \retval false otherwise. | ||
| 133 | */ | ||
| 134 | bool initialized() { | ||
| 135 | ✗ | return (frame_buffer_id != 0); | |
| 136 | } | ||
| 137 | |||
| 138 | /** | ||
| 139 | * \brief Gets the currently bound FrameBufferObject | ||
| 140 | * \return the OpenGL id of the currently bound FrameBufferObject | ||
| 141 | */ | ||
| 142 | static GLuint bound_framebuffer_id() { | ||
| 143 | GLuint result; | ||
| 144 | ✗ | glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)(&result)); | |
| 145 | ✗ | return result; | |
| 146 | } | ||
| 147 | |||
| 148 | /** | ||
| 149 | * \brief The id of the frame buffer. | ||
| 150 | */ | ||
| 151 | GLuint frame_buffer_id; | ||
| 152 | |||
| 153 | /** | ||
| 154 | * \brief The id of the texture used for the depth buffer. | ||
| 155 | */ | ||
| 156 | GLuint depth_buffer_id; | ||
| 157 | |||
| 158 | /** | ||
| 159 | * \brief The id of the texture used for the color buffer. | ||
| 160 | */ | ||
| 161 | GLuint offscreen_id; | ||
| 162 | |||
| 163 | /** | ||
| 164 | * \brief The width of this frame buffer, in pixels. | ||
| 165 | */ | ||
| 166 | index_t width; | ||
| 167 | |||
| 168 | /** | ||
| 169 | * \brief The height of this frame buffer, in pixels. | ||
| 170 | */ | ||
| 171 | index_t height; | ||
| 172 | |||
| 173 | /** | ||
| 174 | * \brief The OpenGL internal storage for the color buffer. | ||
| 175 | */ | ||
| 176 | GLint internal_storage; | ||
| 177 | }; | ||
| 178 | |||
| 179 | } | ||
| 180 | |||
| 181 | #endif | ||
| 182 |