annotate OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp @ 1611:787db80a5a1b

new class MacroLayerRenderer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Oct 2020 18:02:03 +0100
parents 8563ea5d8ae4
children ad9b425f27ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "OpenGLCompositor.h"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "Internals/OpenGLAdvancedPolylineRenderer.h"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "Internals/OpenGLBasicPolylineRenderer.h"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "Internals/OpenGLColorTextureRenderer.h"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "Internals/OpenGLFloatTextureRenderer.h"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "Internals/OpenGLInfoPanelRenderer.h"
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
29 #include "Internals/OpenGLLookupTableTextureRenderer.h"
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "Internals/OpenGLTextRenderer.h"
1611
787db80a5a1b new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
31 #include "Internals/MacroLayerRenderer.h"
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 class OpenGLCompositor::Font : public boost::noncopyable
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 private:
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
38 std::unique_ptr<GlyphTextureAlphabet> alphabet_;
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
39 std::unique_ptr<OpenGL::OpenGLTexture> texture_;
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 public:
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
42 Font(OpenGL::IOpenGLContext& context, const GlyphBitmapAlphabet& dict)
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 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
45 texture_.reset(new OpenGL::OpenGLTexture(context));
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
47 std::unique_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture());
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 texture_->Load(*bitmap, true /* enable linear interpolation */);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 OpenGL::OpenGLTexture& GetTexture() const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 assert(texture_.get() != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 return *texture_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const GlyphTextureAlphabet& GetAlphabet() const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 assert(alphabet_.get() != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 return *alphabet_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 };
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Fonts::const_iterator found = fonts_.find(fontIndex);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 if (found == fonts_.end())
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 return NULL; // Unknown font, nothing should be drawn
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 assert(found->second != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 return found->second;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
81 if (!context_.IsContextLost())
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
83 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
84 {
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 case ISceneLayer::Type_InfoPanel:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 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
87 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer));
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 case ISceneLayer::Type_ColorTexture:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 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
91 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer));
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 case ISceneLayer::Type_FloatTexture:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 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
95 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer));
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
97 case ISceneLayer::Type_LookupTableTexture:
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
98 return new Internals::OpenGLLookupTableTextureRenderer
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
99 (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
100
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 case ISceneLayer::Type_Polyline:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return new Internals::OpenGLAdvancedPolylineRenderer
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
103 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer));
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 case ISceneLayer::Type_Text:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 const Font* font = GetFont(l.GetFontIndex());
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 if (font == NULL)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
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
112 LOG(WARNING) << "There is no font at index " << l.GetFontIndex();
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return NULL;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 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
118 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
1611
787db80a5a1b new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
122 case ISceneLayer::Type_Macro:
787db80a5a1b new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
123 return new Internals::MacroLayerRenderer(*this, layer);
787db80a5a1b new class MacroLayerRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
124
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 default:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 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
127 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
128 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
129 else
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
130 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
131 // 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
132 return NULL;
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
1211
d10d2acb8a02 compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
136 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context) :
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 context_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 colorTextureProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 floatTextureProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 linesProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 textProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 canvasWidth_(0),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 canvasHeight_(0)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
1211
d10d2acb8a02 compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
145 ResetScene();
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 OpenGLCompositor::~OpenGLCompositor()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
150 if (!context_.IsContextLost())
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
1327
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
152 try
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
153 {
1327
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
154 try
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
155 {
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
156 context_.MakeCurrent(); // this can throw if context lost!
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
157 }
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
158 catch (...)
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
159 {
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
160 LOG(ERROR) << "context_.MakeCurrent() failed in OpenGLCompositor::~OpenGLCompositor()!";
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
161 }
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 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
164 {
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
165 try
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
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
168 assert(it->second != NULL);
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
169 delete it->second;
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 catch (...)
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 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
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 }
4f8db2d202c8 OrthancSeriesProgressiveLoader now has two modes that
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
177 catch (...)
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 // 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
180 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
1211
d10d2acb8a02 compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
184 void OpenGLCompositor::Refresh(const Scene2D& scene)
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
186 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
187 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
188 context_.MakeCurrent(); // this can throw if context lost!
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
190 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
191 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
192 glClear(GL_COLOR_BUFFER_BIT);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
1211
d10d2acb8a02 compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
194 helper_->Refresh(scene, canvasWidth_, canvasHeight_);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
196 context_.SwapBuffer();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
197 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 void OpenGLCompositor::SetFont(size_t index,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 const GlyphBitmapAlphabet& dict)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 if (!context_.IsContextLost())
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
205 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
206
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
207 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
208
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
209 Fonts::iterator found = fonts_.find(index);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 (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
212 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
213 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
214 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
215 else
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 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
218 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
219
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
220 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
221 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 #if ORTHANC_ENABLE_LOCALE == 1
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 void OpenGLCompositor::SetFont(size_t index,
1471
28c64c246312 working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1327
diff changeset
227 const std::string& ttf,
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 unsigned int fontSize,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 Orthanc::Encoding codepage)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
231 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
232 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
233 FontRenderer renderer;
1471
28c64c246312 working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1327
diff changeset
234 renderer.LoadFont(ttf, fontSize);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
236 GlyphBitmapAlphabet dict;
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
237 dict.LoadCodepage(renderer, codepage);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 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
240 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 #endif
1482
5c96bf3f1d32 IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1471
diff changeset
243
5c96bf3f1d32 IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1471
diff changeset
244
1576
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
245 void OpenGLCompositor::SetCanvasSize(unsigned int canvasWidth,
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
246 unsigned int canvasHeight)
1482
5c96bf3f1d32 IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1471
diff changeset
247 {
1576
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
248 canvasWidth_ = canvasWidth;
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
249 canvasHeight_ = canvasHeight;
1482
5c96bf3f1d32 IOpenGL::RefreshCanvasSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1471
diff changeset
250 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }