Merge changes from OpenGL driver into OpenGL3 driver

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 10 years ago
parent 3db0105185
commit 161086bd56

@ -28,8 +28,6 @@
#include "nel/3d/light.h"
#include "nel/3d/index_buffer.h"
#include "nel/misc/rect.h"
#include "nel/misc/di_event_emitter.h"
#include "nel/misc/mouse_device.h"
#include "nel/misc/hierarchical_timer.h"
#include "nel/misc/dynloadlib.h"
#include "driver_opengl_vertex_buffer.h"
@ -87,6 +85,11 @@ IDriver* createGl3DriverInstance ()
#ifdef NL_OS_WINDOWS
#ifdef NL_COMP_MINGW
extern "C"
{
#endif
__declspec(dllexport) IDriver* NL3D_createIDriverInstance ()
{
return new CDriverGL3;
@ -97,6 +100,10 @@ __declspec(dllexport) uint32 NL3D_interfaceVersion ()
return IDriver::InterfaceVersion;
}
#ifdef NL_COMP_MINGW
}
#endif
#elif defined (NL_OS_UNIX)
extern "C"
@ -568,14 +575,6 @@ bool CDriverGL3::swapBuffers()
++ _SwapBufferCounter;
#ifdef NL_OS_WINDOWS
if (_EventEmitter.getNumEmitters() > 1) // is direct input running ?
{
// flush direct input messages if any
NLMISC::safe_cast<NLMISC::CDIEventEmitter *>(_EventEmitter.getEmitter(1))->poll();
}
#endif
if (!_WndActive)
{
updateLostBuffers();
@ -674,6 +673,8 @@ bool CDriverGL3::release()
// Call IDriver::release() before, to destroy textures, shaders and VBs...
IDriver::release();
nlassert(_DepthStencilFBOs.empty());
_SwapBufferCounter = 0;
// delete querries
@ -709,7 +710,7 @@ void CDriverGL3::setupViewport (const class CViewport& viewport)
// Setup gl viewport
uint32 clientWidth, clientHeight;
getWindowSize(clientWidth, clientHeight);
getRenderTargetSize(clientWidth, clientHeight);
// Backup the viewport
_CurrViewport = viewport;
@ -764,7 +765,7 @@ void CDriverGL3::setupScissor (const class CScissor& scissor)
// Setup gl viewport
uint32 clientWidth, clientHeight;
getWindowSize(clientWidth, clientHeight);
getRenderTargetSize(clientWidth, clientHeight);
// Backup the scissor
_CurrScissor= scissor;
@ -1658,9 +1659,13 @@ IOcclusionQuery::TOcclusionType COcclusionQueryGL3::getOcclusionType()
if (OcclusionType == NotAvailable)
{
GLuint result;
nglGetQueryObjectuiv(ID, GL_QUERY_RESULT, &result);
OcclusionType = result != 0 ? NotOccluded : Occluded;
VisibleCount = (uint) result;
nglGetQueryObjectuiv(ID, GL_QUERY_RESULT_AVAILABLE, &result);
if (result != GL_FALSE)
{
nglGetQueryObjectuiv(ID, GL_QUERY_RESULT, &result);
OcclusionType = result != 0 ? NotOccluded : Occluded;
VisibleCount = (uint)result;
}
}
return OcclusionType;

@ -130,6 +130,24 @@ public:
virtual uint getVisibleCount();
};
// ***************************************************************************
class CDepthStencilFBO : public NLMISC::CRefCount
{
public:
CDepthStencilFBO(CDriverGL3 *driver, uint width, uint height);
~CDepthStencilFBO();
uint Width;
uint Height;
GLuint DepthFBOId;
GLuint StencilFBOId;
private:
CDriverGL3 *m_Driver;
};
// ***************************************************************************
class CTextureDrvInfosGL3 : public ITextureDrvInfos
{
@ -157,12 +175,10 @@ public:
GLuint FBOId;
// depth stencil FBO id
GLuint DepthFBOId;
GLuint StencilFBOId;
bool AttachDepthStencil;
NLMISC::CSmartPtr<CDepthStencilFBO> DepthStencilFBO;
bool InitFBO;
bool AttachDepthStencil;
bool UsePackedDepthStencil;
// The current wrap modes assigned to the texture.
ITexture::TWrapMode WrapS;
@ -282,7 +298,7 @@ public:
virtual bool isLost() const { return false; } // there's no notion of 'lost device" in OpenGL
virtual bool init (uint windowIcon = 0, emptyProc exitFunc = 0);
virtual bool init(uintptr_t windowIcon = 0, emptyProc exitFunc = 0);
virtual void disableHardwareVertexProgram() {}
virtual void disableHardwarePixelProgram() {}
@ -524,14 +540,6 @@ public:
// Change default scale for all cursors
virtual void setCursorScale(float scale);
virtual NLMISC::IMouseDevice *enableLowLevelMouse(bool enable, bool exclusive);
virtual NLMISC::IKeyboardDevice *enableLowLevelKeyboard(bool enable);
virtual NLMISC::IInputDeviceManager *getLowLevelInputDeviceManager();
virtual uint getDoubleClickDelay(bool hardwareMouse);
virtual void getWindowSize (uint32 &width, uint32 &height);
virtual void getWindowPos (sint32 &x, sint32 &y);
@ -562,6 +570,8 @@ public:
virtual bool copyTargetToTexture (ITexture *tex, uint32 offsetx, uint32 offsety, uint32 x, uint32 y,
uint32 width, uint32 height, uint32 mipmapLevel);
virtual bool textureCoordinateAlternativeMode() const { return false; };
virtual bool getRenderTargetSize (uint32 &width, uint32 &height);
@ -632,7 +642,7 @@ public:
virtual void swapTextureHandle(ITexture &tex0, ITexture &tex1);
virtual uint getTextureHandle(const ITexture&tex);
virtual uintptr_t getTextureHandle(const ITexture&tex);
/// \name Material multipass.
/** NB: setupMaterial() must be called before thoses methods.
@ -692,6 +702,7 @@ private:
virtual class IVertexBufferGL3 *createVertexBufferGL(uint size, uint numVertices, CVertexBuffer::TPreferredMemory preferred, CVertexBuffer *vb);
friend class CTextureDrvInfosGL3;
friend class CVertexProgamDrvInfosGL3;
friend class CDepthStencilFBO;
private:
@ -872,7 +883,11 @@ private:
// viewport before call to setRenderTarget, if BFO extension is supported
CViewport _OldViewport;
bool _RenderTargetFBO;
// Current FBO render target
CSmartPtr<ITexture> _RenderTargetFBO;
// Share the same backbuffer for FBO render targets with window size
std::vector<CDepthStencilFBO *> _DepthStencilFBOs;
// real mirror of GL state
@ -1317,6 +1332,7 @@ private:
// @}
// misc
public:
friend class COcclusionQueryGL3;
static GLenum NLCubeFaceToGLCubeFace[6];
static CMaterial::CTexEnv _TexEnvReplace;
// occlusion query

@ -27,8 +27,6 @@
# endif // HAVE_XCURSOR
#endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
#include "nel/misc/mouse_device.h"
#include "nel/misc/di_event_emitter.h"
#include "nel/3d/u_driver.h"
#include "nel/misc/file.h"
@ -662,151 +660,6 @@ bool CDriverGL3::isSystemCursorCaptured()
#endif
}
// ***************************************************************************
NLMISC::IMouseDevice* CDriverGL3::enableLowLevelMouse(bool enable, bool exclusive)
{
H_AUTO_OGL(CDriverGL3_enableLowLevelMouse);
NLMISC::IMouseDevice *res = NULL;
#ifdef NL_OS_WINDOWS
NLMISC::CDIEventEmitter *diee = NULL;
if (_EventEmitter.getNumEmitters() > 1)
diee = NLMISC::safe_cast<CDIEventEmitter *>(_EventEmitter.getEmitter(1));
if (enable)
{
try
{
if (diee)
res = diee->getMouseDevice(exclusive);
}
catch (const EDirectInput &)
{
}
}
else
{
if (diee)
diee->releaseMouse();
}
#elif defined(NL_OS_MAC)
#elif defined (NL_OS_UNIX)
#endif
return res;
}
// ***************************************************************************
NLMISC::IKeyboardDevice* CDriverGL3::enableLowLevelKeyboard(bool enable)
{
H_AUTO_OGL(CDriverGL3_enableLowLevelKeyboard);
NLMISC::IKeyboardDevice *res = NULL;
#ifdef NL_OS_WINDOWS
NLMISC::CDIEventEmitter *diee = NULL;
if (_EventEmitter.getNumEmitters() > 1)
diee = NLMISC::safe_cast<NLMISC::CDIEventEmitter *>(_EventEmitter.getEmitter(1));
if (enable)
{
try
{
if (diee)
res = diee->getKeyboardDevice();
}
catch (const EDirectInput &)
{
}
}
else
{
if (diee)
diee->releaseKeyboard();
}
#elif defined(NL_OS_MAC)
#elif defined (NL_OS_UNIX)
#endif
return res;
}
// ***************************************************************************
NLMISC::IInputDeviceManager* CDriverGL3::getLowLevelInputDeviceManager()
{
H_AUTO_OGL(CDriverGL3_getLowLevelInputDeviceManager);
NLMISC::IInputDeviceManager *res = NULL;
#ifdef NL_OS_WINDOWS
if (_EventEmitter.getNumEmitters() > 1)
res = NLMISC::safe_cast<NLMISC::CDIEventEmitter *>(_EventEmitter.getEmitter(1));
#elif defined(NL_OS_MAC)
#elif defined (NL_OS_UNIX)
#endif
return res;
}
// ***************************************************************************
uint CDriverGL3::getDoubleClickDelay(bool hardwareMouse)
{
H_AUTO_OGL(CDriverGL3_getDoubleClickDelay);
uint res = 250;
#ifdef NL_OS_WINDOWS
NLMISC::IMouseDevice *md = NULL;
if (_EventEmitter.getNumEmitters() >= 2)
{
NLMISC::CDIEventEmitter *diee = NLMISC::safe_cast<CDIEventEmitter *>(_EventEmitter.getEmitter(1));
if (diee->isMouseCreated())
{
try
{
md = diee->getMouseDevice(hardwareMouse);
}
catch (const EDirectInput &)
{
// could not get device ..
}
}
}
if (md)
{
res = md->getDoubleClickDelay();
}
else
{
// try to read the good value from windows
res = ::GetDoubleClickTime();
}
#elif defined(NL_OS_MAC)
# warning "OpenGL Driver: Missing Mac Implementation for getDoubleClickDelay"
nlwarning("OpenGL Driver: Missing Mac Implementation for getDoubleClickDelay");
#elif defined (NL_OS_UNIX)
// TODO for Linux
#endif
return res;
}
bool CDriverGL3::getBestCursorSize(uint srcWidth, uint srcHeight, uint &dstWidth, uint &dstHeight)
{
#ifdef NL_OS_WINDOWS

@ -65,12 +65,9 @@ CTextureDrvInfosGL3::CTextureDrvInfosGL3(IDriver *drv, ItTexDrvInfoPtrMap it, CD
TextureMode = isRectangleTexture?GL_TEXTURE_RECTANGLE:GL_TEXTURE_2D;
FBOId = 0;
DepthFBOId = 0;
StencilFBOId = 0;
InitFBO = false;
AttachDepthStencil = true;
UsePackedDepthStencil = drvGl->supportPackedDepthStencil();
}
// ***************************************************************************
CTextureDrvInfosGL3::~CTextureDrvInfosGL3()
@ -97,6 +94,65 @@ CTextureDrvInfosGL3::~CTextureDrvInfosGL3()
}*/
}
CDepthStencilFBO::CDepthStencilFBO(CDriverGL3 *driver, uint width, uint height)
{
nldebug("3D: Init shared FBO");
m_Driver = driver;
Width = width;
Height = height;
bool packedDepthStencil = driver->supportPackedDepthStencil();
/*nglGenRenderbuffersEXT(1, &DepthFBOId);
if (packedDepthStencil)
StencilFBOId = DepthFBOId;
else
nglGenRenderbuffersEXT(1, &StencilFBOId);
if (packedDepthStencil)
{
//nldebug("3D: using packed depth stencil");
nglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilFBOId);
nglRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, width, height);
}
else
{
nglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthFBOId);
nglRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
*//*
nglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilFBOId);
nglRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX8_EXT, width, height);
*/
/*}*/
/*nlassert(DepthFBOId);
nlassert(StencilFBOId);*/
driver->_DepthStencilFBOs.push_back(this);
}
CDepthStencilFBO::~CDepthStencilFBO()
{
// driver remove
m_Driver->_DepthStencilFBOs.erase(std::find(m_Driver->_DepthStencilFBOs.begin(), m_Driver->_DepthStencilFBOs.end(), this));
/*if (DepthFBOId)
{
nldebug("3D: Release shared FBO");
nglDeleteRenderbuffersEXT(1, &DepthFBOId);
if (StencilFBOId == DepthFBOId)
StencilFBOId = 0;
DepthFBOId = 0;
}
if (StencilFBOId)
{
nglDeleteRenderbuffersEXT(1, &StencilFBOId);
StencilFBOId = 0;
}*/
}
// ***************************************************************************
bool CTextureDrvInfosGL3::initFrameBufferObject(ITexture * tex)
{
@ -112,14 +168,6 @@ bool CTextureDrvInfosGL3::initFrameBufferObject(ITexture * tex)
// generate IDs
nglGenFramebuffers(1, &FBOId);
if (AttachDepthStencil)
{
nglGenRenderbuffers(1, &DepthFBOId);
if (UsePackedDepthStencil)
StencilFBOId = DepthFBOId;
else
nglGenRenderbuffers(1, &StencilFBOId);
}
//nldebug("3D: using depth %d and stencil %d", DepthFBOId, StencilFBOId);
@ -136,26 +184,24 @@ bool CTextureDrvInfosGL3::initFrameBufferObject(ITexture * tex)
// FIXME GL3
if (AttachDepthStencil)
{
if (UsePackedDepthStencil)
for (std::vector<CDepthStencilFBO *>::iterator it(_Driver->_DepthStencilFBOs.begin()), end(_Driver->_DepthStencilFBOs.end()); it != end; ++it)
{
//nldebug("3D: using packed depth stencil");
nglBindRenderbuffer(GL_RENDERBUFFER, StencilFBOId);
nglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, tex->getWidth(), tex->getHeight());
if ((*it)->Width == tex->getWidth() && (*it)->Height == tex->getHeight())
{
DepthStencilFBO = (*it);
break;
}
}
else
if (!DepthStencilFBO)
{
nglBindRenderbuffer(GL_RENDERBUFFER, DepthFBOId);
nglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, tex->getWidth(), tex->getHeight());
/*
nglBindRenderbuffer(GL_RENDERBUFFER, StencilFBOId);
nglRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, tex->getWidth(), tex->getHeight());
*/
DepthStencilFBO = new CDepthStencilFBO(_Driver, tex->getWidth(), tex->getHeight());
}
nglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, DepthFBOId);
GL_RENDERBUFFER, DepthStencilFBO->DepthFBOId);
nldebug("3D: glFramebufferRenderbufferExt(depth:24) = %X", nglCheckFramebufferStatus(GL_FRAMEBUFFER));
nglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, StencilFBOId);
GL_RENDERBUFFER, DepthStencilFBO->StencilFBOId);
nldebug("3D: glFramebufferRenderbufferExt(stencil:8) = %X", nglCheckFramebufferStatus(GL_FRAMEBUFFER));
}
@ -226,10 +272,7 @@ bool CTextureDrvInfosGL3::initFrameBufferObject(ITexture * tex)
if (AttachDepthStencil)
{
nglDeleteRenderbuffers(1, &DepthFBOId);
if (!UsePackedDepthStencil)
nglDeleteRenderbuffers(1, &StencilFBOId);
DepthStencilFBO = NULL;
}
}
@ -1490,16 +1533,14 @@ void CDriverGL3::swapTextureHandle(ITexture &tex0, ITexture &tex1)
swap(t0->MinFilter, t1->MinFilter);
swap(t0->TextureMode, t1->TextureMode);
swap(t0->FBOId, t1->FBOId);
swap(t0->DepthFBOId, t1->DepthFBOId);
swap(t0->StencilFBOId, t1->StencilFBOId);
swap(t0->DepthStencilFBO, t1->DepthStencilFBO);
swap(t0->InitFBO, t1->InitFBO);
swap(t0->AttachDepthStencil, t1->AttachDepthStencil);
swap(t0->UsePackedDepthStencil, t1->UsePackedDepthStencil);
// swap(t0->AttachDepthStencil, t1->AttachDepthStencil); ?
}
// ***************************************************************************
uint CDriverGL3::getTextureHandle(const ITexture &tex)
uintptr_t CDriverGL3::getTextureHandle(const ITexture &tex)
{
H_AUTO_OGL(CDriverGL3_getTextureHandle)
// If DrvShare not setuped
@ -1549,11 +1590,14 @@ bool CDriverGL3::setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 widt
getViewport(_OldViewport);
if (!width) width = tex->getWidth();
if (!height) height = tex->getHeight();
CViewport newVP;
newVP.init(0, 0, ((float)width/(float)w), ((float)height/(float)h));
setupViewport(newVP);
_RenderTargetFBO = true;
_RenderTargetFBO = tex;
return activeFrameBufferObject(tex);
}
@ -1626,10 +1670,11 @@ bool CDriverGL3::copyTargetToTexture (ITexture *tex,
bool CDriverGL3::getRenderTargetSize (uint32 &width, uint32 &height)
{
H_AUTO_OGL(CDriverGL3_getRenderTargetSize)
if (_TextureTarget)
NLMISC::CSmartPtr<ITexture> tex = _RenderTargetFBO ? _RenderTargetFBO : (_TextureTarget ? _TextureTarget : NULL);
if (tex)
{
width = _TextureTarget->getWidth();
height = _TextureTarget->getHeight();
width = tex->getWidth();
height = tex->getHeight();
}
else
{

@ -38,8 +38,6 @@
# define _NET_WM_STATE_ADD 1
#endif // NL_OS_UNIX
#include "nel/misc/mouse_device.h"
#include "nel/misc/di_event_emitter.h"
#include "nel/3d/u_driver.h"
#include "nel/misc/file.h"
@ -292,7 +290,7 @@ bool GlWndProc(CDriverGL3 *driver, XEvent &e)
#endif // NL_OS_UNIX
// ***************************************************************************
bool CDriverGL3::init (uint windowIcon, emptyProc exitFunc)
bool CDriverGL3::init(uintptr_t windowIcon, emptyProc exitFunc)
{
H_AUTO_OGL(CDriverGL3_init)
@ -457,6 +455,7 @@ bool CDriverGL3::unInit()
{
nlwarning("Can't unregister NLClass");
}
_Registered = 0;
// Restaure monitor color parameters
if (_NeedToRestaureGammaRamp)
@ -596,6 +595,9 @@ bool CDriverGL3::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool r
{
H_AUTO_OGL(CDriverGL3_setDisplay)
if (!mode.OffScreen)
NLMISC::INelContext::getInstance().setWindowedApplication(true);
_win = EmptyWindow;
_CurrentMode = mode;
@ -622,6 +624,10 @@ bool CDriverGL3::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool r
if (!createWindow(mode))
return false;
HWND tmpHWND = _win;
int width = mode.Width;
int height = mode.Height;
// resize the window
RECT rc;
SetRect (&rc, 0, 0, width, height);
@ -914,20 +920,6 @@ bool CDriverGL3::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool r
// setup the event emitter, and try to retrieve a direct input interface
_EventEmitter.addEmitter(we, true /*must delete*/); // the main emitter
/// try to get direct input
try
{
NLMISC::CDIEventEmitter *diee = NLMISC::CDIEventEmitter::create(GetModuleHandle(NULL), _win, we);
if (diee)
{
_EventEmitter.addEmitter(diee, true);
}
}
catch(const EDirectInput &e)
{
nlinfo(e.what());
}
#elif defined(NL_OS_MAC)
if (wnd == EmptyWindow)
@ -1426,8 +1418,17 @@ bool CDriverGL3::createWindow(const GfxMode &mode)
#ifdef NL_OS_WINDOWS
// create the OpenGL window
window = CreateWindowW(L"NLClass", L"NeL Window", WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
CW_USEDEFAULT, CW_USEDEFAULT, mode.Width, mode.Height, HWND_DESKTOP, NULL, GetModuleHandle(NULL), NULL);
DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
int pos = CW_USEDEFAULT;
HWND hwndParent = HWND_DESKTOP;
if (mode.OffScreen)
{
dwStyle &= ~WS_VISIBLE;
pos = 0;
hwndParent = NULL;
}
window = CreateWindowW(L"NLClass", L"NeL Window", dwStyle,
pos, pos, mode.Width, mode.Height, hwndParent, NULL, GetModuleHandle(NULL), NULL);
if (window == EmptyWindow)
{
@ -1458,7 +1459,7 @@ bool CDriverGL3::createWindow(const GfxMode &mode)
[[CocoaApplicationDelegate alloc] initWithDriver:this];
// set the application delegate, this will handle window/app close events
[NSApp setDelegate:appDelegate];
[NSApp setDelegate:(id<NSFileManagerDelegate>)appDelegate];
// bind the close button of the window to applicationShouldTerminate
id closeButton = [cocoa_window standardWindowButton:NSWindowCloseButton];
@ -1826,6 +1827,19 @@ bool CDriverGL3::setMode(const GfxMode& mode)
if (!_DestroyWindow)
return true;
#if defined(NL_OS_WINDOWS)
// save relative cursor
POINT cursorPos;
cursorPos.x = 0;
cursorPos.y = 0;
BOOL cursorPosOk = isSystemCursorInClientArea()
&& GetCursorPos(&cursorPos)
&& ScreenToClient(_win, &cursorPos);
sint curX = (sint)cursorPos.x * (sint)mode.Width;
sint curY = (sint)cursorPos.y * (sint)mode.Height;
#endif
if (!setScreenMode(mode))
return false;
@ -1845,6 +1859,17 @@ bool CDriverGL3::setMode(const GfxMode& mode)
case 32: _ColorDepth = ColorDepth32; break;
}
#if defined(NL_OS_WINDOWS)
// restore relative cursor
if (cursorPosOk)
{
cursorPos.x = curX / (sint)mode.Width;
cursorPos.y = curY / (sint)mode.Height;
ClientToScreen(_win, &cursorPos);
SetCursorPos(cursorPos.x, cursorPos.y);
}
#endif
// set color depth for custom cursor
updateCursor(true);
@ -2260,7 +2285,19 @@ void CDriverGL3::setWindowPos(sint32 x, sint32 y)
#ifdef NL_OS_WINDOWS
SetWindowPos(_win, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
// save relative cursor
POINT cursorPos;
BOOL cursorPosOk = isSystemCursorInClientArea()
&& GetCursorPos(&cursorPos)
&& ScreenToClient(_win, &cursorPos);
SetWindowPos(_win, NULL, x, y, 0, 0, /*SWP_NOZORDER | SWP_NOACTIVATE |*/ SWP_NOSIZE);
if (cursorPosOk)
{
ClientToScreen(_win, &cursorPos);
SetCursorPos(cursorPos.x, cursorPos.y);
}
#elif defined(NL_OS_MAC)
// get the rect (position, size) of the screen with menu bar

@ -34,7 +34,9 @@
#ifdef NL_OS_WINDOWS
# define WIN32_LEAN_AND_MEAN
# define NOMINMAX
# ifndef NL_COMP_MINGW
# define NOMINMAX
# endif
# include <windows.h>
# include <windowsx.h>
#endif

@ -36,7 +36,7 @@ static Atom XA_WM_DELETE_WINDOW = 0;
namespace NLMISC {
CUnixEventEmitter::CUnixEventEmitter ():_dpy(NULL), _win(0), _emulateRawMode(false), _driver(NULL)
CUnixEventEmitter::CUnixEventEmitter ():_dpy(NULL), _win(0), _driver(NULL)
{
_im = 0;
_ic = 0;
@ -157,25 +157,6 @@ static Bool isMouseMoveEvent(Display *display, XEvent *event, XPointer arg)
return (event->type == MotionNotify);
}
void CUnixEventEmitter::emulateMouseRawMode(bool enable)
{
_emulateRawMode = enable;
if (_emulateRawMode)
{
XWindowAttributes xwa;
XGetWindowAttributes(_dpy, _win, &xwa);
XWarpPointer(_dpy, None, _win, None, None, None, None,
(xwa.width / 2), (xwa.height / 2));
// remove all outstanding mouse move events, they happened before the mouse
// was pulled back to 0.5 / 0.5, so a wrong movement delta would be
// reported otherwise
XEvent event;
while (XCheckIfEvent(_dpy, &event, &isMouseMoveEvent, NULL)) { };
}
}
#ifndef AltMask
# ifdef NL_OS_MAC
# define AltMask (8192)
@ -511,33 +492,12 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
{
TMouseButton button=getMouseButton (event.xbutton.state);
// if raw mode should be emulated
if (_emulateRawMode)
{
// when we just wrapped back the pointer to 0.5 / 0.5, ignore event
if (event.xbutton.x == xwa.width / 2 && event.xbutton.y == xwa.height / 2)
break;
// post a CGDMouseMove with the movement delta to the event server
server->postEvent(
new CGDMouseMove(this, NULL /* no mouse device */,
event.xbutton.x - (xwa.width / 2),
(xwa.height / 2) - event.xbutton.y));
// move the pointer back to the center of the window
XWarpPointer(_dpy, None, _win, None, None, None, None,
(xwa.width / 2), (xwa.height / 2));
}
// if in normal mouse mode
else
{
// get the relative mouse position
float fX = (float) event.xbutton.x / (float) xwa.width;
float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height;
// get the relative mouse position
float fX = (float) event.xbutton.x / (float) xwa.width;
float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height;
// post a normal mouse move event to the event server
server->postEvent (new CEventMouseMove (fX, fY, button, this));
}
// post a normal mouse move event to the event server
server->postEvent (new CEventMouseMove (fX, fY, button, this));
break;
}
case KeyPress:

@ -20,7 +20,6 @@
#include "nel/misc/types_nl.h"
#include "nel/misc/event_emitter.h"
#include "nel/misc/events.h"
#include "nel/misc/game_device_events.h"
#include "nel/3d/driver.h"
@ -56,11 +55,6 @@ public:
*/
virtual void submitEvents(CEventServer & server, bool allWindows);
/**
* enable or disable mouse raw mode
*/
virtual void emulateMouseRawMode(bool emulate);
/**
* process input-related events (mouse and keyboard)
*/
@ -106,7 +100,6 @@ private:
std::map<TKey, bool> _PressedKeys;
XIM _im;
XIC _ic;
bool _emulateRawMode;
NL3D::IDriver* _driver;
CUnixEventServer _InternalServer;
ucstring _CopiedString;

Loading…
Cancel
Save