GCC Code Coverage Report


./
File: libs/viz/scene3d/texture.hpp
Date: 2025-01-21 16:21:04
Lines:
10/10
100.0%
Functions:
4/4
100.0%
Branches:
9/18
50.0%

Line Branch Exec Source
1 /************************************************************************
2 *
3 * Copyright (C) 2015-2024 IRCAD France
4 * Copyright (C) 2015-2019 IHU Strasbourg
5 *
6 * This file is part of Sight.
7 *
8 * Sight is free software: you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Sight is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
20 *
21 ***********************************************************************/
22
23 #pragma once
24
25 #include <sight/viz/scene3d/config.hpp>
26
27 #include <data/image.hpp>
28
29 #include <viz/scene3d/resource.hpp>
30
31 #include <OGRE/OgrePass.h>
32 #include <OGRE/OgreTexture.h>
33
34 #include <optional>
35 namespace sight::viz::scene3d
36 {
37
38 /**
39 * @brief This binds a sight::data::image to a shared Ogre texture. It allows to share the GPU memory from multiple
40 * callers that use the same image, and only update the GPU buffer when necessary.
41 */
42 class SIGHT_VIZ_SCENE3D_CLASS_API texture : public resource<data::image,
43 Ogre::Texture,
44 texture>
45 {
46 public:
47
48 /// Instantiates a texture. If a texture matching the image name does not exist, it creates a new one, otherwise
49 /// it wraps the existing one.
50 /// @param _image input image
51 /// @param _suffix_id optional suffix to the object identifier, this allows to create different copies of the object
52 SIGHT_VIZ_SCENE3D_API texture(const data::image::csptr& _image, const std::string& _suffix_id = "");
53 SIGHT_VIZ_SCENE3D_API ~texture() override;
54
55 /// Updates the TF texture according to the source image content, if any modification occurred since the last
56 /// update.
57 SIGHT_VIZ_SCENE3D_API void update() override;
58
59 SIGHT_VIZ_SCENE3D_API void set_dirty();
60
61 /// Binds the texture in the given texture unit state
62 SIGHT_VIZ_SCENE3D_API void bind(
63 Ogre::TextureUnitState* _tex_unit,
64 Ogre::TextureType _type,
65 Ogre::TextureFilterOptions _filter_type,
66 Ogre::TextureAddressingMode _address_mode
67 ) const;
68
69 /// Binds the texture in the given pass
70 SIGHT_VIZ_SCENE3D_API void bind(
71 Ogre::Pass* _pass,
72 const std::string& _sampler_name,
73 std::optional<Ogre::TextureFilterOptions> _filter_type = std::nullopt,
74 std::optional<Ogre::TextureAddressingMode> _address_mode = std::nullopt,
75 bool _upload_window_uniform = true
76 ) const;
77
78 /// Binds the texture in the given pass and the given uniform
79 SIGHT_VIZ_SCENE3D_API void bind(
80 Ogre::Pass* _pass,
81 const std::string& _sampler_name,
82 const std::string& _uniform_name,
83 std::optional<Ogre::TextureFilterOptions> _filter_type = std::nullopt,
84 std::optional<Ogre::TextureAddressingMode> _address_mode = std::nullopt
85 ) const;
86
87 /// Gets the width of this texture
88 70 [[nodiscard]] std::uint32_t width() const
89 {
90
2/4
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
140 return this->get()->getWidth();
91 }
92
93 /// Gets the height of this texture
94 70 [[nodiscard]] std::uint32_t height() const
95 {
96
2/4
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
140 return this->get()->getHeight();
97 }
98
99 /// Gets the depth of this texture
100 70 [[nodiscard]] std::uint32_t depth() const
101 {
102
2/4
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
140 return this->get()->getDepth();
103 }
104
105 /// Gets the name of this texture
106 7 [[nodiscard]] std::string name() const
107 {
108
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
21 return this->get()->getName();
109 }
110
111 /// Gets the name of this texture
112 63 [[nodiscard]] Ogre::Vector2 window() const
113 {
114
1/2
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
63 return m_window;
115 }
116
117 private:
118
119 /// Stores the texture window to upload it when necessary as a fragment shader uniform
120 Ogre::Vector2 m_window;
121 };
122
123 //-----------------------------------------------------------------------------
124
125 } // namespace sight::viz::scene3d
126