annotate Framework/Scene2D/OpenGLCompositor.cpp @ 867:fe96057e97b9 toa2019062502

Added tag toa2019062501 for changeset c71ef52602a0
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 25 Jun 2019 17:55:50 +0200
parents 266e2b0b9abc
children 80829436ce0c 77c96ba899f9
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
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"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace OrthancStone
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 class OpenGLCompositor::Font : public boost::noncopyable
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 private:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 std::auto_ptr<GlyphTextureAlphabet> alphabet_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 std::auto_ptr<OpenGL::OpenGLTexture> texture_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 public:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 Font(const GlyphBitmapAlphabet& dict)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 alphabet_.reset(new GlyphTextureAlphabet(dict));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 texture_.reset(new OpenGL::OpenGLTexture);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 std::auto_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture());
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 texture_->Load(*bitmap, true /* enable linear interpolation */);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 OpenGL::OpenGLTexture& GetTexture() const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 assert(texture_.get() != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 return *texture_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const GlyphTextureAlphabet& GetAlphabet() const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 assert(alphabet_.get() != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 return *alphabet_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 switch (layer.GetType())
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 case ISceneLayer::Type_InfoPanel:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return new Internals::OpenGLInfoPanelRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 case ISceneLayer::Type_ColorTexture:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 return new Internals::OpenGLColorTextureRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 case ISceneLayer::Type_FloatTexture:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 return new Internals::OpenGLFloatTextureRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
96 case ISceneLayer::Type_LookupTableTexture:
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
97 return new Internals::OpenGLLookupTableTextureRenderer
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 617
diff changeset
98 (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
99
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 case ISceneLayer::Type_Polyline:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return new Internals::OpenGLAdvancedPolylineRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 case ISceneLayer::Type_Text:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const Font* font = GetFont(l.GetFontIndex());
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 if (font == NULL)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return NULL;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return new Internals::OpenGLTextRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 default:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 return NULL;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context,
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 598
diff changeset
127 const Scene2D& scene) :
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 context_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 helper_(scene, *this),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 colorTextureProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 floatTextureProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 linesProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 textProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 canvasWidth_(0),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 canvasHeight_(0)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 UpdateSize();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 OpenGLCompositor::~OpenGLCompositor()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 assert(it->second != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 delete it->second;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 void OpenGLCompositor::UpdateSize()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 canvasWidth_ = context_.GetCanvasWidth();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 canvasHeight_ = context_.GetCanvasHeight();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 context_.MakeCurrent();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 glViewport(0, 0, canvasWidth_, canvasHeight_);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 void OpenGLCompositor::Refresh()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 context_.MakeCurrent();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 glClearColor(0, 0, 0, 1);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 glClear(GL_COLOR_BUFFER_BIT);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 helper_.Refresh(canvasWidth_, canvasHeight_);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 context_.SwapBuffer();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 void OpenGLCompositor::SetFont(size_t index,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 const GlyphBitmapAlphabet& dict)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 std::auto_ptr<Font> font(new Font(dict));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 Fonts::iterator found = fonts_.find(index);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 if (found == fonts_.end())
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 fonts_[index] = font.release();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 assert(found->second != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 delete found->second;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 found->second = font.release();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 #if ORTHANC_ENABLE_LOCALE == 1
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 void OpenGLCompositor::SetFont(size_t index,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 Orthanc::EmbeddedResources::FileResourceId resource,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 unsigned int fontSize,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 Orthanc::Encoding codepage)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 FontRenderer renderer;
598
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 594
diff changeset
202 renderer.LoadFont(resource, fontSize);
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 GlyphBitmapAlphabet dict;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 dict.LoadCodepage(renderer, codepage);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 SetFont(index, dict);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 #endif
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
210
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
211
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
212 ScenePoint2D OpenGLCompositor::GetPixelCenterCoordinates(int x, int y) const
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
213 {
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
214 return ScenePoint2D(
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
215 static_cast<double>(x) + 0.5 - static_cast<double>(canvasWidth_) / 2.0,
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
216 static_cast<double>(y) + 0.5 - static_cast<double>(canvasHeight_) / 2.0);
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
217 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }