comparison OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp @ 1576:92fca2b3ba3d

sanitizing the handling of canvas size
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Sep 2020 16:40:30 +0200
parents 85e117739eca
children 8563ea5d8ae4
comparison
equal deleted inserted replaced
1575:e4a52cbbdd70 1576:92fca2b3ba3d
135 linesProgram_(context), 135 linesProgram_(context),
136 textProgram_(context), 136 textProgram_(context),
137 canvasWidth_(0), 137 canvasWidth_(0),
138 canvasHeight_(0) 138 canvasHeight_(0)
139 { 139 {
140 if (!context_.IsContextLost())
141 {
142 canvasWidth_ = context_.GetCanvasWidth();
143 canvasHeight_ = context_.GetCanvasHeight();
144 }
145
146 ResetScene(); 140 ResetScene();
147 } 141 }
148 142
149 OpenGLCompositor::~OpenGLCompositor() 143 OpenGLCompositor::~OpenGLCompositor()
150 { 144 {
185 void OpenGLCompositor::Refresh(const Scene2D& scene) 179 void OpenGLCompositor::Refresh(const Scene2D& scene)
186 { 180 {
187 if (!context_.IsContextLost()) 181 if (!context_.IsContextLost())
188 { 182 {
189 context_.MakeCurrent(); // this can throw if context lost! 183 context_.MakeCurrent(); // this can throw if context lost!
190 canvasWidth_ = context_.GetCanvasWidth();
191 canvasHeight_ = context_.GetCanvasHeight();
192 184
193 glViewport(0, 0, canvasWidth_, canvasHeight_); 185 glViewport(0, 0, canvasWidth_, canvasHeight_);
194 glClearColor(0, 0, 0, 1); 186 glClearColor(0, 0, 0, 1);
195 glClear(GL_COLOR_BUFFER_BIT); 187 glClear(GL_COLOR_BUFFER_BIT);
196 188
243 } 235 }
244 } 236 }
245 #endif 237 #endif
246 238
247 239
248 void OpenGLCompositor::RefreshCanvasSize() 240 void OpenGLCompositor::SetCanvasSize(unsigned int canvasWidth,
249 { 241 unsigned int canvasHeight)
250 if (!context_.IsContextLost()) 242 {
251 { 243 canvasWidth_ = canvasWidth;
252 context_.MakeCurrent(); // this can throw if context lost! 244 canvasHeight_ = canvasHeight;
253 context_.RefreshCanvasSize(); // Difference with Refresh(scene)
254 canvasWidth_ = context_.GetCanvasWidth();
255 canvasHeight_ = context_.GetCanvasHeight();
256 }
257 } 245 }
258 } 246 }