annotate Framework/Scene2D/OpenGLCompositor.cpp @ 819:a68cd7ae8838

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 29 May 2019 13:39:31 +0200
parents 7efa2543699d
children 266e2b0b9abc
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"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "Internals/OpenGLTextRenderer.h"
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 class OpenGLCompositor::Font : public boost::noncopyable
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 private:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 std::auto_ptr<GlyphTextureAlphabet> alphabet_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 std::auto_ptr<OpenGL::OpenGLTexture> texture_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 public:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 Font(const GlyphBitmapAlphabet& dict)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 alphabet_.reset(new GlyphTextureAlphabet(dict));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 texture_.reset(new OpenGL::OpenGLTexture);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 std::auto_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture());
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 texture_->Load(*bitmap, true /* enable linear interpolation */);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 OpenGL::OpenGLTexture& GetTexture() const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 assert(texture_.get() != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return *texture_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const GlyphTextureAlphabet& GetAlphabet() const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 assert(alphabet_.get() != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return *alphabet_;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
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 const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 Fonts::const_iterator found = fonts_.find(fontIndex);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (found == fonts_.end())
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 return NULL; // Unknown font, nothing should be drawn
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 assert(found->second != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return found->second;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
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 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 switch (layer.GetType())
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 case ISceneLayer::Type_InfoPanel:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 return new Internals::OpenGLInfoPanelRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 case ISceneLayer::Type_ColorTexture:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 return new Internals::OpenGLColorTextureRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 case ISceneLayer::Type_FloatTexture:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 return new Internals::OpenGLFloatTextureRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 case ISceneLayer::Type_Polyline:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 return new Internals::OpenGLAdvancedPolylineRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 case ISceneLayer::Type_Text:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 const Font* font = GetFont(l.GetFontIndex());
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 if (font == NULL)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return NULL;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 return new Internals::OpenGLTextRenderer
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 default:
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return NULL;
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context,
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 598
diff changeset
122 const Scene2D& scene) :
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 context_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 helper_(scene, *this),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 colorTextureProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 floatTextureProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 linesProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 textProgram_(context),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 canvasWidth_(0),
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 canvasHeight_(0)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 UpdateSize();
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
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 OpenGLCompositor::~OpenGLCompositor()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 assert(it->second != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 delete it->second;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 void OpenGLCompositor::UpdateSize()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 canvasWidth_ = context_.GetCanvasWidth();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 canvasHeight_ = context_.GetCanvasHeight();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 context_.MakeCurrent();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 glViewport(0, 0, canvasWidth_, canvasHeight_);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 void OpenGLCompositor::Refresh()
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 context_.MakeCurrent();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 glClearColor(0, 0, 0, 1);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 glClear(GL_COLOR_BUFFER_BIT);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 helper_.Refresh(canvasWidth_, canvasHeight_);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 context_.SwapBuffer();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 void OpenGLCompositor::SetFont(size_t index,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 const GlyphBitmapAlphabet& dict)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 std::auto_ptr<Font> font(new Font(dict));
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 Fonts::iterator found = fonts_.find(index);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (found == fonts_.end())
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 fonts_[index] = font.release();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 else
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 assert(found->second != NULL);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 delete found->second;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 found->second = font.release();
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 #if ORTHANC_ENABLE_LOCALE == 1
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 void OpenGLCompositor::SetFont(size_t index,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 Orthanc::EmbeddedResources::FileResourceId resource,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 unsigned int fontSize,
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 Orthanc::Encoding codepage)
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 FontRenderer renderer;
598
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 594
diff changeset
197 renderer.LoadFont(resource, fontSize);
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 GlyphBitmapAlphabet dict;
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 dict.LoadCodepage(renderer, codepage);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 SetFont(index, dict);
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 #endif
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
205
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
206
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
207 ScenePoint2D OpenGLCompositor::GetPixelCenterCoordinates(int x, int y) const
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
208 {
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
209 return ScenePoint2D(
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
210 static_cast<double>(x) + 0.5 - static_cast<double>(canvasWidth_) / 2.0,
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
211 static_cast<double>(y) + 0.5 - static_cast<double>(canvasHeight_) / 2.0);
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
212 }
594
9807ed3d3e03 OpenGLCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }