Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp @ 1801:64dad1d7aca4
renamed subclass
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 13:23:59 +0200 |
parents | c5e6379b9cd0 |
children | 3889ae96d2e9 |
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 | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1614
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
594 | 6 * |
7 * 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
|
8 * modify it under the terms of the GNU Lesser General Public License |
594 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * 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
|
14 * 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
|
15 * Lesser General Public License for more details. |
1327
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
594 | 20 **/ |
21 | |
22 #include "OpenGLCompositor.h" | |
23 | |
24 #include "Internals/OpenGLAdvancedPolylineRenderer.h" | |
1614
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
25 #include "Internals/OpenGLArrowRenderer.h" |
594 | 26 #include "Internals/OpenGLBasicPolylineRenderer.h" |
27 #include "Internals/OpenGLColorTextureRenderer.h" | |
28 #include "Internals/OpenGLFloatTextureRenderer.h" | |
29 #include "Internals/OpenGLInfoPanelRenderer.h" | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
30 #include "Internals/OpenGLLookupTableTextureRenderer.h" |
594 | 31 #include "Internals/OpenGLTextRenderer.h" |
1611
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
32 #include "Internals/MacroLayerRenderer.h" |
594 | 33 |
1793 | 34 #include <OrthancException.h> |
35 | |
594 | 36 namespace OrthancStone |
37 { | |
38 class OpenGLCompositor::Font : public boost::noncopyable | |
39 { | |
40 private: | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
41 std::unique_ptr<GlyphTextureAlphabet> alphabet_; |
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
42 std::unique_ptr<OpenGL::OpenGLTexture> texture_; |
594 | 43 |
44 public: | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
45 Font(OpenGL::IOpenGLContext& context, const GlyphBitmapAlphabet& dict) |
594 | 46 { |
47 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
|
48 texture_.reset(new OpenGL::OpenGLTexture(context)); |
594 | 49 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
50 std::unique_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture()); |
594 | 51 texture_->Load(*bitmap, true /* enable linear interpolation */); |
52 } | |
53 | |
54 OpenGL::OpenGLTexture& GetTexture() const | |
55 { | |
56 assert(texture_.get() != NULL); | |
57 return *texture_; | |
58 } | |
59 | |
60 const GlyphTextureAlphabet& GetAlphabet() const | |
61 { | |
62 assert(alphabet_.get() != NULL); | |
63 return *alphabet_; | |
64 } | |
65 }; | |
66 | |
67 const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const | |
68 { | |
69 Fonts::const_iterator found = fonts_.find(fontIndex); | |
70 | |
71 if (found == fonts_.end()) | |
72 { | |
73 return NULL; // Unknown font, nothing should be drawn | |
74 } | |
75 else | |
76 { | |
77 assert(found->second != NULL); | |
78 return found->second; | |
79 } | |
80 } | |
81 | |
82 Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer) | |
83 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
84 if (!context_.IsContextLost()) |
594 | 85 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
86 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
|
87 { |
594 | 88 case ISceneLayer::Type_InfoPanel: |
89 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
|
90 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer)); |
594 | 91 |
92 case ISceneLayer::Type_ColorTexture: | |
93 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
|
94 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer)); |
594 | 95 |
96 case ISceneLayer::Type_FloatTexture: | |
97 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
|
98 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer)); |
594 | 99 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
100 case ISceneLayer::Type_LookupTableTexture: |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
101 return new Internals::OpenGLLookupTableTextureRenderer |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
102 (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
|
103 |
594 | 104 case ISceneLayer::Type_Polyline: |
105 return new Internals::OpenGLAdvancedPolylineRenderer | |
1571 | 106 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer)); |
594 | 107 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer)); |
108 | |
109 case ISceneLayer::Type_Text: | |
110 { | |
111 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer); | |
112 const Font* font = GetFont(l.GetFontIndex()); | |
113 if (font == NULL) | |
114 { | |
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
|
115 LOG(WARNING) << "There is no font at index " << l.GetFontIndex(); |
594 | 116 return NULL; |
117 } | |
118 else | |
119 { | |
120 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
|
121 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l); |
594 | 122 } |
123 } | |
124 | |
1611
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
125 case ISceneLayer::Type_Macro: |
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
126 return new Internals::MacroLayerRenderer(*this, layer); |
787db80a5a1b
new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
127 |
1614
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
128 case ISceneLayer::Type_Arrow: |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
129 return new Internals::OpenGLArrowRenderer |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
130 (context_, linesProgram_, dynamic_cast<const ArrowSceneLayer&>(layer)); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1611
diff
changeset
|
131 |
594 | 132 default: |
133 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
|
134 } |
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 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
137 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
138 // 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
|
139 return NULL; |
594 | 140 } |
141 } | |
142 | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
143 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context) : |
594 | 144 context_(context), |
145 colorTextureProgram_(context), | |
146 floatTextureProgram_(context), | |
147 linesProgram_(context), | |
148 textProgram_(context), | |
149 canvasWidth_(0), | |
150 canvasHeight_(0) | |
151 { | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
152 ResetScene(); |
594 | 153 } |
154 | |
155 OpenGLCompositor::~OpenGLCompositor() | |
156 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
157 if (!context_.IsContextLost()) |
594 | 158 { |
1327
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
159 try |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
160 { |
1327
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
161 try |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
162 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
163 context_.MakeCurrent(); // this can throw if context lost! |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
164 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
165 catch (...) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
166 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
167 LOG(ERROR) << "context_.MakeCurrent() failed in OpenGLCompositor::~OpenGLCompositor()!"; |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
168 } |
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 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
|
171 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
172 try |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
173 { |
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 assert(it->second != NULL); |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
176 delete it->second; |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
177 } |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
178 catch (...) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
179 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
180 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
|
181 } |
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 catch (...) |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
185 { |
4f8db2d202c8
OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents:
1300
diff
changeset
|
186 // 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
|
187 } |
594 | 188 } |
189 } | |
190 | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
191 void OpenGLCompositor::Refresh(const Scene2D& scene) |
594 | 192 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
193 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
|
194 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
195 context_.MakeCurrent(); // this can throw if context lost! |
594 | 196 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
197 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
|
198 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
|
199 glClear(GL_COLOR_BUFFER_BIT); |
594 | 200 |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
201 helper_->Refresh(scene, canvasWidth_, canvasHeight_); |
594 | 202 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
203 context_.SwapBuffer(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
204 } |
594 | 205 } |
206 | |
207 void OpenGLCompositor::SetFont(size_t index, | |
208 const GlyphBitmapAlphabet& dict) | |
209 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
210 if (!context_.IsContextLost()) |
594 | 211 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
212 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
|
213 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
214 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
|
215 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
216 Fonts::iterator found = fonts_.find(index); |
594 | 217 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
218 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
|
219 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
220 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
|
221 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
222 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
223 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
224 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
|
225 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
|
226 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
227 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
|
228 } |
594 | 229 } |
230 } | |
231 | |
232 #if ORTHANC_ENABLE_LOCALE == 1 | |
233 void OpenGLCompositor::SetFont(size_t index, | |
1471
28c64c246312
working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1327
diff
changeset
|
234 const std::string& ttf, |
594 | 235 unsigned int fontSize, |
236 Orthanc::Encoding codepage) | |
237 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
238 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
|
239 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
240 FontRenderer renderer; |
1471
28c64c246312
working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1327
diff
changeset
|
241 renderer.LoadFont(ttf, fontSize); |
594 | 242 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
243 GlyphBitmapAlphabet dict; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
244 dict.LoadCodepage(renderer, codepage); |
594 | 245 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
246 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
|
247 } |
594 | 248 } |
249 #endif | |
1482
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
250 |
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
251 |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
252 void OpenGLCompositor::SetCanvasSize(unsigned int canvasWidth, |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
253 unsigned int canvasHeight) |
1482
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
254 { |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
255 canvasWidth_ = canvasWidth; |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
256 canvasHeight_ = canvasHeight; |
1482
5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1471
diff
changeset
|
257 } |
1792
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
258 |
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 #if ORTHANC_ENABLE_LOCALE == 1 |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
261 TextBoundingBox* OpenGLCompositor::ComputeTextBoundingBox(size_t fontIndex, |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
262 const std::string& utf8) |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
263 { |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
264 Fonts::const_iterator found = fonts_.find(fontIndex); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
265 |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
266 if (found == fonts_.end()) |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
267 { |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
268 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
269 "No such font: " + boost::lexical_cast<std::string>(fontIndex)); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
270 } |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
271 else |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
272 { |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
273 assert(found->second != NULL); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
274 return new TextBoundingBox(found->second->GetAlphabet().GetAlphabet(), utf8); |
373d7f7e796e
ICompositor::ComputeTextBoundingBox()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
275 } |
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 #endif |
594 | 278 } |