Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 977 vs 978 for /trunk/Source Code/Platform/Video/GFXDevice.cpp

Diff revisions: vs.
  @@ -332,42 +332,49 @@
332 332 }
333 333
334 334 void GFXDevice::increaseResolution() {
335 - WindowManager& winManager = _parent.platformContext().app().windowManager();
336 - const vec2<U16>& resolution = winManager.getActiveWindow().getDimensions();
337 - const vectorImpl<GPUState::GPUVideoMode>& displayModes = _state.getDisplayModes(winManager.targetDisplay());
338 -
339 - vectorImpl<GPUState::GPUVideoMode>::const_reverse_iterator it;
340 - for (it = std::rbegin(displayModes); it != std::rend(displayModes); ++it) {
341 - const vec2<U16>& tempResolution = it->_resolution;
342 -
343 - if (resolution.width < tempResolution.width &&
344 - resolution.height < tempResolution.height) {
345 - winManager.handleWindowEvent(WindowEvent::RESOLUTION_CHANGED,
346 - winManager.getActiveWindow().getGUID(),
347 - to_I32(tempResolution.width),
348 - to_I32(tempResolution.height));
349 - return;
350 - }
351 - }
335 + stepResolution(true);
352 336 }
353 337
354 338 void GFXDevice::decreaseResolution() {
339 + stepResolution(false);
340 + }
341 +
342 + void GFXDevice::stepResolution(bool increment) {
343 + auto compare = [](const vec2<U16>& a, const vec2<U16>& b) -> bool {
344 + return a.x > b.x || a.y > b.y;
345 + };
346 +
355 347 WindowManager& winManager = _parent.platformContext().app().windowManager();
356 - const vec2<U16>& resolution = winManager.getActiveWindow().getDimensions();
357 - const vectorImpl<GPUState::GPUVideoMode>& displayModes = _state.getDisplayModes(winManager.targetDisplay());
358 -
348 +
359 349 vectorImpl<GPUState::GPUVideoMode>::const_iterator it;
360 - for (it = std::begin(displayModes); it != std::end(displayModes); ++it) {
361 - const vec2<U16>& tempResolution = it->_resolution;
362 - if (resolution.width > tempResolution.width &&
363 - resolution.height > tempResolution.height) {
364 - winManager.handleWindowEvent(WindowEvent::RESOLUTION_CHANGED,
365 - winManager.getActiveWindow().getGUID(),
366 - to_I32(tempResolution.width),
367 - to_I32(tempResolution.height));
368 - return;
350 + const vectorImpl<GPUState::GPUVideoMode>& displayModes = _state.getDisplayModes(winManager.targetDisplay());
351 +
352 + bool found = false;
353 + vec2<U16> foundRes;
354 + if (increment) {
355 + for (const GPUState::GPUVideoMode& mode : reverse(displayModes)) {
356 + const vec2<U16>& res = mode._resolution;
357 + if (compare(res, _renderingResolution)) {
358 + found = true;
359 + foundRes.set(res);
360 + break;
361 + }
362 + }
363 + } else {
364 + for (const GPUState::GPUVideoMode& mode : displayModes) {
365 + const vec2<U16>& res = mode._resolution;
366 + if (compare(_renderingResolution, res)) {
367 + found = true;
368 + foundRes.set(res);
369 + break;
370 + }
369 371 }
370 372 }
373 +
374 + if (found) {
375 + _resolutionChangeQueued.first.set(foundRes);
376 + _resolutionChangeQueued.second = true;
377 + }
371 378 }
372 379
373 380 void GFXDevice::toggleFullScreen() {
  @@ -388,42 +395,51 @@
388 395 }
389 396
390 397 /// The main entry point for any resolution change request
391 - void GFXDevice::onChangeResolution(U16 w, U16 h) {
392 - RenderTarget& screenRT = _rtPool->renderTarget(RenderTargetID(RenderTargetUsage::SCREEN));
393 - // Update resolution only if it's different from the current one.
394 - // Avoid resolution change on minimize so we don't thrash render targets
395 - if ((w == screenRT.getWidth() &&
396 - h == screenRT.getHeight()) ||
397 - !(w > 1 && h > 1)) {
398 - return;
399 - }
398 + void GFXDevice::onSizeChange(const SizeChangeParams& params) {
399 + U16 w = params.width;
400 + U16 h = params.height;
401 +
402 + if (!params.window) {
403 + // Update resolution only if it's different from the current one.
404 + // Avoid resolution change on minimize so we don't thrash render targets
405 + if (w < 1 || h < 1 || _renderingResolution == vec2<U16>(w, h)) {
406 + return;
407 + }
400 408
401 - // Update render targets with the new resolution
402 - _rtPool->resizeTargets(RenderTargetUsage::SCREEN, w, h);
403 - _rtPool->resizeTargets(RenderTargetUsage::OIT, w, h);
404 - if (Config::Build::ENABLE_EDITOR) {
405 - _rtPool->resizeTargets(RenderTargetUsage::EDITOR, w, h);
406 - }
409 + _renderingResolution.set(w, h);
407 410
408 - U16 reflectRes = std::max(w, h) / Config::REFLECTION_TARGET_RESOLUTION_DOWNSCALE_FACTOR;
411 + // Update render targets with the new resolution
412 + _rtPool->resizeTargets(RenderTargetUsage::SCREEN, w, h);
413 + _rtPool->resizeTargets(RenderTargetUsage::OIT, w, h);
414 + if (Config::Build::ENABLE_EDITOR) {
415 + _rtPool->resizeTargets(RenderTargetUsage::EDITOR, w, h);
416 + }
409 417
410 - _rtPool->resizeTargets(RenderTargetUsage::REFLECTION_PLANAR, reflectRes, reflectRes);
411 - _rtPool->resizeTargets(RenderTargetUsage::REFRACTION_PLANAR, reflectRes, reflectRes);
412 - _rtPool->resizeTargets(RenderTargetUsage::REFLECTION_CUBE, reflectRes, reflectRes);
413 - _rtPool->resizeTargets(RenderTargetUsage::REFRACTION_CUBE, reflectRes, reflectRes);
418 + U16 reflectRes = std::max(w, h) / Config::REFLECTION_TARGET_RESOLUTION_DOWNSCALE_FACTOR;
414 419
415 - for (Texture_ptr& tex : _prevDepthBuffers) {
416 - tex->resize(NULL, vec2<U16>(w, h));
417 - }
420 + _rtPool->resizeTargets(RenderTargetUsage::REFLECTION_PLANAR, reflectRes, reflectRes);
421 + _rtPool->resizeTargets(RenderTargetUsage::REFRACTION_PLANAR, reflectRes, reflectRes);
422 + _rtPool->resizeTargets(RenderTargetUsage::REFLECTION_CUBE, reflectRes, reflectRes);
423 + _rtPool->resizeTargets(RenderTargetUsage::REFRACTION_CUBE, reflectRes, reflectRes);
418 424
419 - // Update post-processing render targets and buffers
420 - PostFX::instance().updateResolution(w, h);
425 + for (Texture_ptr& tex : _prevDepthBuffers) {
426 + tex->resize(NULL, vec2<U16>(w, h));
427 + }
421 428
422 - // Update the 2D camera so it matches our new rendering viewport
423 - Camera::utilityCamera(Camera::UtilityCamera::_2D)->setProjection(vec4<F32>(0, to_F32(w), 0, to_F32(h)), vec2<F32>(-1, 1));
424 - Camera::utilityCamera(Camera::UtilityCamera::_2D_FLIP_Y)->setProjection(vec4<F32>(0, to_F32(w), to_F32(h), 0), vec2<F32>(-1, 1));
425 -
426 - setBaseViewport(vec4<I32>(0, 0, to_I32(w), to_I32(h)));
429 + // Update post-processing render targets and buffers
430 + PostFX::instance().updateResolution(w, h);
431 +
432 + // Update the 2D camera so it matches our new rendering viewport
433 + Camera::utilityCamera(Camera::UtilityCamera::_2D)->setProjection(vec4<F32>(0, to_F32(w), 0, to_F32(h)), vec2<F32>(-1, 1));
434 + Camera::utilityCamera(Camera::UtilityCamera::_2D_FLIP_Y)->setProjection(vec4<F32>(0, to_F32(w), to_F32(h), 0), vec2<F32>(-1, 1));
435 + }
436 +
437 + F32 currentAspectRatio = to_F32(_renderingResolution.width) / _renderingResolution.height;
438 + I32 newWidth = to_I32(std::round(h * currentAspectRatio));
439 + I32 newHeight = to_I32(std::round(w / currentAspectRatio));
440 + I32 left = to_I32(std::round((w - newWidth) * 0.5f));
441 + I32 bottom = to_I32(std::round((h - newHeight) * 0.5f));
442 + setBaseViewport(vec4<I32>(left, bottom, newWidth, newHeight));
427 443 }
428 444
429 445 /// Return a GFXDevice specific matrix or a derivative of it