Skip to content

Commit

Permalink
Main: RenderWindow - provide default resize impl
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Sep 10, 2024
1 parent a87f815 commit 7c07de2
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 110 deletions.
2 changes: 1 addition & 1 deletion OgreMain/include/OgreRenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace Ogre

/** Alter the size of the window.
*/
virtual void resize(unsigned int widthPt, unsigned int heightPt) = 0;
virtual void resize(unsigned int widthPt, unsigned int heightPt);

/** Query the current size and position from an external window handle.
@note most of the time you already know the size and should call @ref resize instead.
Expand Down
11 changes: 11 additions & 0 deletions OgreMain/src/OgreRenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ THE SOFTWARE.
*/
#include "OgreStableHeaders.h"
#include "OgreRenderWindow.h"
#include "OgreViewport.h"

namespace Ogre {

Expand All @@ -36,6 +37,16 @@ namespace Ogre {
mAutoDeactivatedOnFocusChange = true;
}

void RenderWindow::resize(unsigned int widthPt, unsigned int heightPt)
{
mWidth = widthPt;
mHeight = heightPt;

// Notify viewports of resize
for (auto it : mViewportList)
it.second->_updateDimensions();
}

//-----------------------------------------------------------------------
void RenderWindow::getMetrics(unsigned int& width, unsigned int& height,
int& left, int& top) const
Expand Down
2 changes: 0 additions & 2 deletions RenderSystems/Direct3D11/include/OgreD3D11RenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ namespace Ogre
ComPtr<IDXGIDeviceN> _queryDxgiDevice() { ComPtr<IDXGIDeviceN> res; _queryDxgiDeviceImpl(res.GetAddressOf()); return res; }
void _queryDxgiDeviceImpl(IDXGIDeviceN** dxgiDevice); // release after use

void _updateViewportsDimensions();

protected:
D3D11Device & mDevice; // D3D11 driver
bool mIsExternal; // window not created by Ogre
Expand Down
23 changes: 4 additions & 19 deletions RenderSystems/Direct3D11/src/OgreD3D11RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ THE SOFTWARE.
#include "OgreRoot.h"
#include "OgreD3D11DepthBuffer.h"
#include "OgreD3D11Texture.h"
#include "OgreViewport.h"
#include "OgreLogManager.h"
#include "OgreHardwarePixelBuffer.h"
#if OGRE_NO_QUAD_BUFFER_STEREO == 0
Expand Down Expand Up @@ -222,14 +221,6 @@ namespace Ogre
RenderWindow::updateImpl();
}
//---------------------------------------------------------------------
void D3D11RenderWindowBase::_updateViewportsDimensions()
{
// Notify viewports of resize
ViewportList::iterator it = mViewportList.begin();
while( it != mViewportList.end() )
(*it++).second->_updateDimensions();
}
//---------------------------------------------------------------------
void D3D11RenderWindowBase::_queryDxgiDeviceImpl(IDXGIDeviceN** dxgiDevice)
{
if (mDevice.isNull())
Expand Down Expand Up @@ -478,9 +469,7 @@ namespace Ogre
}

_createSizeDependedD3DResources();

// Notify viewports of resize
_updateViewportsDimensions();
RenderWindow::resize(mWidth, mHeight);
rsys->fireDeviceEvent(&mDevice,"RenderWindowResized",this);
}
//---------------------------------------------------------------------
Expand Down Expand Up @@ -522,7 +511,7 @@ namespace Ogre
_createSizeDependedD3DResources();

// Notify viewports of resize
_updateViewportsDimensions();
RenderWindow::resize(mWidth, mHeight);
rsys->fireDeviceEvent(&mDevice,"RenderWindowResized",this);
}

Expand Down Expand Up @@ -1063,7 +1052,7 @@ namespace Ogre
if ((oldFullscreen && fullScreen) || mIsExternal)
{
// Notify viewports of resize
_updateViewportsDimensions();
RenderWindow::resize(mWidth, mHeight);
}
}
}
Expand Down Expand Up @@ -1716,13 +1705,9 @@ namespace Ogre

_destroySizeDependedD3DResources();

mWidth = width;
mHeight = height;
RenderWindow::resize(width, height);

_createSizeDependedD3DResources();

// Notify viewports of resize
_updateViewportsDimensions();
}
//---------------------------------------------------------------------
void D3D11RenderWindowImageSource::getCustomAttribute( const String& name, void* pData )
Expand Down
13 changes: 4 additions & 9 deletions RenderSystems/GLES2/src/EAGL/OgreEAGL2Window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ of this software and associated documentation files (the "Software"), to deal
#include "OgreEAGL2Support.h"
#include "OgreEAGLES2Context.h"

#include "OgreRenderSystem.h"
#include "OgreRenderWindow.h"
#include "OgreRoot.h"
#include "OgreGLES2RenderSystem.h"
#include "OgreGLES2PixelFormat.h"
#include "OgreViewport.h"
#include "OgreLogManager.h"
#include <iomanip>

Expand Down Expand Up @@ -129,16 +130,10 @@ of this software and associated documentation files (the "Software"), to deal
EAGLContextGuard ctx_guard(mContext->getContext());

mContext->destroyFramebuffer();

mWidth = widthPx;
mHeight = heightPx;

RenderWindow::resize(widthPx, heightPx);

mContext->createFramebuffer();

for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
{
(*it).second->_updateDimensions();
}
}

void EAGL2Window::windowMovedOrResized()
Expand Down
2 changes: 0 additions & 2 deletions RenderSystems/GLSupport/include/EGL/OgreEGLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ namespace Ogre {
void create(const String& name, unsigned int width, unsigned int height, bool fullScreen,
const NameValuePairList* miscParams) override;

void resize(unsigned int width, unsigned int height) override {}

void setFullscreen (bool fullscreen, uint width, uint height) override;
void destroy(void) override;
void swapBuffers() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ THE SOFTWARE.

#include "OgreAndroidEGLSupport.h"
#include "OgreAndroidEGLWindow.h"
#include "OgreViewport.h"

#include <android/native_window.h>

Expand Down Expand Up @@ -65,13 +64,7 @@ namespace Ogre {
if (!mActive || (mWidth == width && mHeight == height))
return;

mWidth = width;
mHeight = height;

// Notify viewports of resize
ViewportList::iterator it = mViewportList.begin();
while (it != mViewportList.end())
(*it++).second->_updateDimensions();
RenderWindow::resize(width, height);

EGLint format;
eglGetConfigAttrib(mEglDisplay, mEglConfig, EGL_NATIVE_VISUAL_ID, &format);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ THE SOFTWARE.

#include "OgreEmscriptenEGLSupport.h"
#include "OgreEmscriptenEGLWindow.h"
#include "OgreViewport.h"

#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -68,9 +67,7 @@ namespace Ogre {

void EmscriptenEGLWindow::resize(uint width, uint height)
{
mWidth = width;
mHeight = height;

RenderWindow::resize(width, height);

EMSCRIPTEN_RESULT result = emscripten_set_canvas_element_size(mCanvasSelector.c_str(), width, height);
// This is a workaroud for issue: https://github.com/emscripten-core/emscripten/issues/3283.
Expand All @@ -86,11 +83,6 @@ namespace Ogre {


LogManager::getSingleton().logMessage("EmscriptenEGLWindow::resize "+mCanvasSelector+" w:" + Ogre::StringConverter::toString(mWidth) + " h:" + Ogre::StringConverter::toString(mHeight));

// Notify viewports of resize
ViewportList::iterator it = mViewportList.begin();
while( it != mViewportList.end() )
(*it++).second->_updateDimensions();
}

void EmscriptenEGLWindow::windowMovedOrResized()
Expand Down
10 changes: 1 addition & 9 deletions RenderSystems/GLSupport/src/EGL/WIN32/OgreWin32EGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ THE SOFTWARE.
#include "OgreLogManager.h"
#include "OgreStringConverter.h"

#include "OgreViewport.h"

#include "OgreWin32EGLSupport.h"
#include "OgreWin32EGLWindow.h"

Expand Down Expand Up @@ -265,13 +263,7 @@ namespace Ogre {
// Case window resized.
if (width != mWidth || height != mHeight)
{
mWidth = rc.right - rc.left;
mHeight = rc.bottom - rc.top;

// Notify viewports of resize
ViewportList::iterator it = mViewportList.begin();
while( it != mViewportList.end() )
(*it++).second->_updateDimensions();
RenderWindow::resize(width, height);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "OgreLogManager.h"
#include "OgreRoot.h"
#include "OgreStringConverter.h"
#include "OgreViewport.h"

#include "OgreWaylandEGLSupport.h"
#include "OgreWaylandEGLWindow.h"
Expand Down Expand Up @@ -92,11 +91,8 @@ void WaylandEGLWindow::resize(uint width, uint height)
if (mWindow)
{
wl_egl_window_resize(mWindow, width, height, 0, 0);
mWidth = width;
mHeight = height;

for (auto& it : mViewportList)
it.second->_updateDimensions();
RenderWindow::resize(width, height);

wl_surface_damage(mWlSurface, 0, 0, mWidth, mHeight);
wl_surface_commit(mWlSurface);
Expand Down
7 changes: 1 addition & 6 deletions RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ THE SOFTWARE.
#include "OgreException.h"
#include "OgreLogManager.h"
#include "OgreStringConverter.h"
#include "OgreViewport.h"

#include "OgreX11EGLSupport.h"
#include "OgreX11EGLWindow.h"
Expand Down Expand Up @@ -187,11 +186,7 @@ namespace Ogre {
XFlush(mGLSupport->getNativeDisplay());
}

mWidth = width;
mHeight = height;

for (auto & it : mViewportList)
it.second->_updateDimensions();
RenderWindow::resize(width, height);
}
}

Expand Down
7 changes: 1 addition & 6 deletions RenderSystems/GLSupport/src/GLX/OgreGLXWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "OgreException.h"
#include "OgreLogManager.h"
#include "OgreStringConverter.h"
#include "OgreViewport.h"

#include "OgreGLXContext.h"
#include "OgreGLXGLSupport.h"
Expand Down Expand Up @@ -465,11 +464,7 @@ namespace Ogre
XFlush(mGLSupport->getXDisplay());
}

mWidth = width;
mHeight = height;

for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
(*it).second->_updateDimensions();
RenderWindow::resize(width, height);
}
}

Expand Down
8 changes: 1 addition & 7 deletions RenderSystems/GLSupport/src/OSX/OgreOSXCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ of this software and associated documentation files (the "Software"), to deal
#import <AppKit/NSScreen.h>
#import <AppKit/NSOpenGLView.h>
#import <QuartzCore/CVDisplayLink.h>
#import "OgreViewport.h"
#import <iomanip>

@implementation OgreGLWindow
Expand Down Expand Up @@ -531,8 +530,7 @@ - (BOOL)acceptsFirstResponder
if(mWidth == widthPx && mHeight == heightPx)
return;

mWidth = widthPx;
mHeight = heightPx;
RenderWindow::resize(widthPx, heightPx);

if(mIsExternal)
{
Expand Down Expand Up @@ -563,10 +561,6 @@ - (BOOL)acceptsFirstResponder
}
//make sure the context is current
NSOpenGLContextGuard ctx_guard(mGLContext);
for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
{
(*it).second->_updateDimensions();
}
[mGLContext update];
}

Expand Down
9 changes: 1 addition & 8 deletions RenderSystems/GLSupport/src/win32/OgreWin32Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ THE SOFTWARE.
#endif
#include "OgreWin32Window.h"
#include "OgreRoot.h"
#include "OgreViewport.h"
#include "OgreLogManager.h"
#include "OgreRenderSystem.h"
#include "OgreImageCodec.h"
Expand Down Expand Up @@ -754,13 +753,7 @@ namespace Ogre {
// Case window resized.
if (width != mWidth || height != mHeight)
{
mWidth = rc.right - rc.left;
mHeight = rc.bottom - rc.top;

// Notify viewports of resize
ViewportList::iterator it = mViewportList.begin();
while( it != mViewportList.end() )
(*it++).second->_updateDimensions();
RenderWindow::resize(rc.right - rc.left, rc.bottom - rc.top);
}
}

Expand Down
12 changes: 1 addition & 11 deletions RenderSystems/Metal/src/OgreMetalRenderWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ of this software and associated documentation files (the "Software"), to deal
#include "OgreMetalRenderWindow.h"
#include "OgreMetalMappings.h"
#include "OgreMetalRenderSystem.h"
#include "OgreViewport.h"

namespace Ogre
{
Expand Down Expand Up @@ -113,8 +112,7 @@ of this software and associated documentation files (the "Software"), to deal
if( mWidth != mMetalLayer.drawableSize.width ||
mHeight != mMetalLayer.drawableSize.height )
{
mWidth = mMetalLayer.drawableSize.width;
mHeight = mMetalLayer.drawableSize.height;
RenderWindow::resize(mMetalLayer.drawableSize.width, mMetalLayer.drawableSize.height);

if( mFSAA > 1 && mWidth > 0 && mHeight > 0 )
{
Expand All @@ -133,14 +131,6 @@ of this software and associated documentation files (the "Software"), to deal
}

detachDepthBuffer();

ViewportList::iterator itor = mViewportList.begin();
ViewportList::iterator end = mViewportList.end();
while( itor != end )
{
(*itor).second->_updateDimensions();
++itor;
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/Tiny/src/OgreTinyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ void TinyWindow::create(const String& name, uint width, uint height,

void TinyWindow::resize(uint width, uint height)
{
mWidth = width;
mHeight = height;
mBuffer.create(PF_BYTE_RGB, width, height);
RenderWindow::resize(width, height);
}

void TinyWindow::swapBuffers()
Expand Down
Loading

0 comments on commit 7c07de2

Please sign in to comment.