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 102c5d5
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 146 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
20 changes: 4 additions & 16 deletions RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ THE SOFTWARE.
*/
#include "OgreD3D9RenderWindow.h"
#include "OgreLogManager.h"
#include "OgreViewport.h"
#include "OgreException.h"
#include "OgreD3D9RenderSystem.h"
#include "OgreRenderSystem.h"
#include "OgreBitwise.h"
#include "OgreImageCodec.h"
#include "OgreStringConverter.h"
#include "OgreRoot.h"
#include "OgreD3D9DeviceManager.h"
Expand Down Expand Up @@ -434,10 +432,8 @@ namespace Ogre
// NB don't use windowMovedOrResized since Win32 doesn't know
// about the size change yet
mDevice->invalidate(this);
// Notify viewports of resize
ViewportList::iterator it = mViewportList.begin();
while( it != mViewportList.end() )
(*it++).second->_updateDimensions();

RenderWindow::resize(mWidth, mHeight);
}
}

Expand Down Expand Up @@ -918,18 +914,10 @@ namespace Ogre
unsigned int width = rc.right - rc.left;
unsigned int height = rc.bottom - rc.top;

// 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);
}
}
//-----------------------------------------------------------------------------
void D3D9RenderWindow::updateStats( void )
Expand Down
20 changes: 4 additions & 16 deletions RenderSystems/GLES2/src/EAGL/OgreEAGL2Window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ of this software and associated documentation files (the "Software"), to deal
#include "OgreRoot.h"
#include "OgreGLES2RenderSystem.h"
#include "OgreGLES2PixelFormat.h"
#include "OgreViewport.h"
#include "OgreLogManager.h"
#include <iomanip>

Expand Down Expand Up @@ -129,16 +128,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 All @@ -155,17 +148,12 @@ of this software and associated documentation files (the "Software"), to deal
EAGLContextGuard ctx_guard(mContext->getContext());
mContext->destroyFramebuffer();

mWidth = width;
mHeight = height;
mLeft = left;
mTop = top;

mContext->createFramebuffer();
RenderWindow::resize(width, height);

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

void EAGL2Window::createNativeWindow(uint widthPt, uint heightPt, const NameValuePairList *miscParams)
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 All @@ -99,13 +91,8 @@ namespace Ogre {

int w, h;
emscripten_get_canvas_element_size(mCanvasSelector.c_str(), &w, &h);
mWidth = w;
mHeight = h;

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

void EmscriptenEGLWindow::switchFullScreen(bool fullscreen)
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
Loading

0 comments on commit 102c5d5

Please sign in to comment.