Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp @ 2012:637d6373127a
width of the vertical slider has doubled to ease user interactions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Dec 2022 18:49:06 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
594 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
594 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
594 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
16 * Lesser General Public License for more details. |
1327
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
594 | 21 **/ |
22 | |
23 #include "OpenGLCompositor.h" | |
24 | |
25 #include "Internals/OpenGLAdvancedPolylineRenderer.h" | |
1614
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
26 #include "Internals/OpenGLArrowRenderer.h" |
594 | 27 #include "Internals/OpenGLBasicPolylineRenderer.h" |
28 #include "Internals/OpenGLColorTextureRenderer.h" | |
29 #include "Internals/OpenGLFloatTextureRenderer.h" | |
30 #include "Internals/OpenGLInfoPanelRenderer.h" | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
31 #include "Internals/OpenGLLookupTableTextureRenderer.h" |
594 | 32 #include "Internals/OpenGLTextRenderer.h" |
1611
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
33 #include "Internals/MacroLayerRenderer.h" |
594 | 34 |
1793 | 35 #include <OrthancException.h> |
36 | |
594 | 37 namespace OrthancStone |
38 { | |
39 class OpenGLCompositor::Font : public boost::noncopyable | |
40 { | |
41 private: | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
42 std::unique_ptr<GlyphTextureAlphabet> alphabet_; |
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
43 std::unique_ptr<OpenGL::OpenGLTexture> texture_; |
594 | 44 |
45 public: | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
46 Font(OpenGL::IOpenGLContext& context, const GlyphBitmapAlphabet& dict) |
594 | 47 { |
48 alphabet_.reset(new GlyphTextureAlphabet(dict)); | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
49 texture_.reset(new OpenGL::OpenGLTexture(context)); |
594 | 50 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
51 std::unique_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture()); |
594 | 52 texture_->Load(*bitmap, true /* enable linear interpolation */); |
53 } | |
54 | |
55 OpenGL::OpenGLTexture& GetTexture() const | |
56 { | |
57 assert(texture_.get() != NULL); | |
58 return *texture_; | |
59 } | |
60 | |
61 const GlyphTextureAlphabet& GetAlphabet() const | |
62 { | |
63 assert(alphabet_.get() != NULL); | |
64 return *alphabet_; | |
65 } | |
66 }; | |
67 | |
68 const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const | |
69 { | |
70 Fonts::const_iterator found = fonts_.find(fontIndex); | |
71 | |
72 if (found == fonts_.end()) | |
73 { | |
74 return NULL; // Unknown font, nothing should be drawn | |
75 } | |
76 else | |
77 { | |
78 assert(found->second != NULL); | |
79 return found->second; | |
80 } | |
81 } | |
82 | |
83 Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer) | |
84 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
85 if (!context_.IsContextLost()) |
594 | 86 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
87 switch (layer.GetType()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
88 { |
594 | 89 case ISceneLayer::Type_InfoPanel: |
90 return new Internals::OpenGLInfoPanelRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
91 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer)); |
594 | 92 |
93 case ISceneLayer::Type_ColorTexture: | |
94 return new Internals::OpenGLColorTextureRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
95 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer)); |
594 | 96 |
97 case ISceneLayer::Type_FloatTexture: | |
98 return new Internals::OpenGLFloatTextureRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
99 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer)); |
594 | 100 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
101 case ISceneLayer::Type_LookupTableTexture: |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
102 return new Internals::OpenGLLookupTableTextureRenderer |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
103 (context_, colorTextureProgram_, dynamic_cast<const LookupTableTextureSceneLayer&>(layer)); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
104 |
594 | 105 case ISceneLayer::Type_Polyline: |
106 return new Internals::OpenGLAdvancedPolylineRenderer | |
1571 | 107 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer)); |
594 | 108 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer)); |
109 | |
110 case ISceneLayer::Type_Text: | |
111 { | |
112 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer); | |
113 const Font* font = GetFont(l.GetFontIndex()); | |
114 if (font == NULL) | |
115 { | |
949
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
116 LOG(WARNING) << "There is no font at index " << l.GetFontIndex(); |
594 | 117 return NULL; |
118 } | |
119 else | |
120 { | |
121 return new Internals::OpenGLTextRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
122 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l); |
594 | 123 } |
124 } | |
125 | |
1611
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
126 case ISceneLayer::Type_Macro: |
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
127 return new Internals::MacroLayerRenderer(*this, layer); |
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
128 |
1614
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
129 case ISceneLayer::Type_Arrow: |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
130 return new Internals::OpenGLArrowRenderer |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
131 (context_, linesProgram_, dynamic_cast<const ArrowSceneLayer&>(layer)); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
132 |
594 | 133 default: |
134 return NULL; | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
135 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
136 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
137 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
138 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
139 // context is lost. returning null. |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
140 return NULL; |
594 | 141 } |
142 } | |
143 | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
144 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context) : |
594 | 145 context_(context), |
146 colorTextureProgram_(context), | |
147 floatTextureProgram_(context), | |
148 linesProgram_(context), | |
149 textProgram_(context), | |
150 canvasWidth_(0), | |
151 canvasHeight_(0) | |
152 { | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
153 ResetScene(); |
594 | 154 } |
155 | |
156 OpenGLCompositor::~OpenGLCompositor() | |
157 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
158 if (!context_.IsContextLost()) |
594 | 159 { |
1327
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
160 try |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
161 { |
1327
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
162 try |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
163 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
164 context_.MakeCurrent(); // this can throw if context lost! |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
165 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
166 catch (...) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
167 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
168 LOG(ERROR) << "context_.MakeCurrent() failed in OpenGLCompositor::~OpenGLCompositor()!"; |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
169 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
170 |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
171 for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
172 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
173 try |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
174 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
175 |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
176 assert(it->second != NULL); |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
177 delete it->second; |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
178 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
179 catch (...) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
180 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
181 LOG(ERROR) << "Exception thrown while deleting OpenGL-based font!"; |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
182 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
183 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
184 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
185 catch (...) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
186 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
187 // logging threw an exception! |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
188 } |
594 | 189 } |
190 } | |
191 | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
192 void OpenGLCompositor::Refresh(const Scene2D& scene) |
594 | 193 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
194 if (!context_.IsContextLost()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
195 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
196 context_.MakeCurrent(); // this can throw if context lost! |
594 | 197 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
198 glViewport(0, 0, canvasWidth_, canvasHeight_); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
199 glClearColor(0, 0, 0, 1); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
200 glClear(GL_COLOR_BUFFER_BIT); |
594 | 201 |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
202 helper_->Refresh(scene, canvasWidth_, canvasHeight_); |
594 | 203 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
204 context_.SwapBuffer(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
205 } |
594 | 206 } |
207 | |
208 void OpenGLCompositor::SetFont(size_t index, | |
209 const GlyphBitmapAlphabet& dict) | |
210 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
211 if (!context_.IsContextLost()) |
594 | 212 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
213 context_.MakeCurrent(); // this can throw if context lost |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
214 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
215 std::unique_ptr<Font> font(new Font(context_, dict)); |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
216 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
217 Fonts::iterator found = fonts_.find(index); |
594 | 218 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
219 if (found == fonts_.end()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
220 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
221 fonts_[index] = font.release(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
222 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
223 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
224 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
225 assert(found->second != NULL); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
226 delete found->second; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
227 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
228 found->second = font.release(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
229 } |
594 | 230 } |
231 } | |
232 | |
233 #if ORTHANC_ENABLE_LOCALE == 1 | |
234 void OpenGLCompositor::SetFont(size_t index, | |
1471
28c64c246312
working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1327
diff
changeset
|
235 const std::string& ttf, |
594 | 236 unsigned int fontSize, |
237 Orthanc::Encoding codepage) | |
238 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
239 if (!context_.IsContextLost()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
240 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
241 FontRenderer renderer; |
1471
28c64c246312
working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1327
diff
changeset
|
242 renderer.LoadFont(ttf, fontSize); |
594 | 243 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
244 GlyphBitmapAlphabet dict; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
245 dict.LoadCodepage(renderer, codepage); |
594 | 246 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
247 SetFont(index, dict); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
248 } |
594 | 249 } |
250 #endif | |
1482
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
251 |
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
252 |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
253 void OpenGLCompositor::SetCanvasSize(unsigned int canvasWidth, |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
254 unsigned int canvasHeight) |
1482
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
255 { |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
256 canvasWidth_ = canvasWidth; |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
257 canvasHeight_ = canvasHeight; |
1482
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
258 } |
1792
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
259 |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
260 |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
261 #if ORTHANC_ENABLE_LOCALE == 1 |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
262 TextBoundingBox* OpenGLCompositor::ComputeTextBoundingBox(size_t fontIndex, |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
263 const std::string& utf8) |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
264 { |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
265 Fonts::const_iterator found = fonts_.find(fontIndex); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
266 |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
267 if (found == fonts_.end()) |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
268 { |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
269 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
270 "No such font: " + boost::lexical_cast<std::string>(fontIndex)); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
271 } |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
272 else |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
273 { |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
274 assert(found->second != NULL); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
275 return new TextBoundingBox(found->second->GetAlphabet().GetAlphabet(), utf8); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
276 } |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
277 } |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
278 #endif |
594 | 279 } |