Commit 90c29701 authored by hybrid's avatar hybrid

Added zbuffer depth flag, not all drivers and devices honor it, yet. Adapted...

Added zbuffer depth flag, not all drivers and devices honor it, yet. Adapted OSX device to recent device creation changes.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1373 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 85d886a0
......@@ -16,6 +16,7 @@ namespace irr
DriverType(video::EDT_BURNINGSVIDEO),
WindowSize(core::dimension2d<s32>(800, 600)),
Bits(16),
ZBufferBits(16),
Fullscreen(false),
Stencilbuffer(false),
Vsync(false),
......@@ -38,8 +39,11 @@ namespace irr
//! Size of the window or the video mode in fullscreen mode. Default: 800x600
core::dimension2d<s32> WindowSize;
//! Bits per pixel in fullscreen mode. Ignored if windowed mode. Default: 16.
u32 Bits;
//! Minimum Bits per pixel of the color buffer in fullscreen mode. Ignored if windowed mode. Default: 16.
u8 Bits;
//! Minimum Bits per pixel of the depth buffer. Default: 16.
u8 ZBufferBits;
//! Should be set to true if the device should run in fullscreen.
/** Otherwise the device runs in windowed mode. Default: false. */
......
......@@ -283,7 +283,7 @@ bool CIrrDeviceLinux::createWindow()
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_ALPHA_SIZE, CreationParams.WithAlphaChannel?1:0,
GLX_DEPTH_SIZE, 16,
GLX_DEPTH_SIZE, CreationParams.ZBufferBits,
GLX_DOUBLEBUFFER, GL_TRUE,
GLX_STENCIL_SIZE, 1,
GLX_SAMPLE_BUFFERS_ARB, 1,
......@@ -412,7 +412,7 @@ bool CIrrDeviceLinux::createWindow()
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_ALPHA_SIZE, CreationParams.WithAlphaChannel?1:0,
GLX_DEPTH_SIZE, 16,
GLX_DEPTH_SIZE, CreationParams.ZBufferBits,
GLX_DOUBLEBUFFER, GL_TRUE,
GLX_STENCIL_SIZE, 1,
None
......@@ -584,8 +584,10 @@ bool CIrrDeviceLinux::createWindow()
Window tmp;
u32 borderWidth;
int x,y;
unsigned int bits;
XGetGeometry(display, window, &tmp, &x, &y, &Width, &Height, &borderWidth, &CreationParams.Bits);
XGetGeometry(display, window, &tmp, &x, &y, &Width, &Height, &borderWidth, &bits);
CreationParams.Bits = bits;
StdHints = XAllocSizeHints();
long num;
XGetWMNormalHints(display, window, StdHints, &num);
......
......@@ -101,7 +101,8 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
//! destructor
CIrrDeviceSDL::~CIrrDeviceSDL()
{
if (Screen)
// only free surfaces created by us
if (Screen && !param.WindowId)
SDL_FreeSurface(Screen);
SDL_Quit();
}
......@@ -128,7 +129,7 @@ bool CIrrDeviceSDL::createWindow()
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel?8:0 );
}
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, CreationParams.Bits);
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
}
......
......@@ -336,11 +336,11 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
AdjustWindowRect(&clientSize, style, FALSE);
s32 realWidth = clientSize.right - clientSize.left;
s32 realHeight = clientSize.bottom - clientSize.top;
const s32 realWidth = clientSize.right - clientSize.left;
const s32 realHeight = clientSize.bottom - clientSize.top;
s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2;
s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2;
const s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2;
const s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2;
if (CreationParams.Fullscreen)
{
......@@ -630,8 +630,8 @@ void CIrrDeviceWin32::present(video::IImage* image, void* windowId, core::rect<s
bi.bV4Width = image->getDimension().Width;
bi.bV4Height = -image->getDimension().Height;
bi.bV4V4Compression = BI_BITFIELDS;
bi.bV4AlphaMask = image->getAlphaMask ();
bi.bV4RedMask = image->getRedMask ();
bi.bV4AlphaMask = image->getAlphaMask();
bi.bV4RedMask = image->getRedMask();
bi.bV4GreenMask = image->getGreenMask();
bi.bV4BlueMask = image->getBlueMask();
......@@ -769,10 +769,10 @@ void CIrrDeviceWin32::getWindowsVersion(core::stringc& out)
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if(!(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO*) &osvi)))
if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi)))
{
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
if (! GetVersionEx((OSVERSIONINFO *) &osvi))
return;
}
......@@ -785,13 +785,13 @@ void CIrrDeviceWin32::getWindowsVersion(core::stringc& out)
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
out.append("Microsoft Windows 2000 ");
else
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
out.append("Microsoft Windows XP ");
else
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
out.append("Microsoft Windows Vista ");
if( bOsVersionInfoEx )
if (bOsVersionInfoEx)
{
#ifdef VER_SUITE_ENTERPRISE
if (osvi.wProductType == VER_NT_WORKSTATION)
......@@ -829,9 +829,9 @@ void CIrrDeviceWin32::getWindowsVersion(core::stringc& out)
if (lstrcmpi( "WINNT", szProductType) == 0 )
out.append("Professional ");
if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
out.append("Server " );
if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
if (lstrcmpi( "LANMANNT", szProductType) == 0)
out.append("Server ");
if (lstrcmpi( "SERVERNT", szProductType) == 0)
out.append("Advanced Server ");
}
......@@ -841,7 +841,7 @@ void CIrrDeviceWin32::getWindowsVersion(core::stringc& out)
if (osvi.dwMajorVersion <= 4 )
{
sprintf (tmp, "version %ld.%ld %s (Build %ld)",
sprintf(tmp, "version %ld.%ld %s (Build %ld)",
osvi.dwMajorVersion,
osvi.dwMinorVersion,
osvi.szCSDVersion,
......@@ -849,7 +849,7 @@ void CIrrDeviceWin32::getWindowsVersion(core::stringc& out)
}
else
{
sprintf (tmp, "%s (Build %ld)", osvi.szCSDVersion,
sprintf(tmp, "%s (Build %ld)", osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF);
}
......@@ -917,11 +917,11 @@ void CIrrDeviceWin32::setResizeAble(bool resize)
AdjustWindowRect(&clientSize, style, FALSE);
s32 realWidth = clientSize.right - clientSize.left;
s32 realHeight = clientSize.bottom - clientSize.top;
const s32 realWidth = clientSize.right - clientSize.left;
const s32 realHeight = clientSize.bottom - clientSize.top;
s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2;
s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2;
const s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2;
const s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2;
SetWindowPos(HWnd, HWND_TOP, windowLeft, windowTop, realWidth, realHeight,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_SHOWWINDOW);
......
......@@ -25,12 +25,7 @@ namespace irr
public:
//! constructor
CIrrDeviceMacOSX(video::E_DRIVER_TYPE driverType,
const core::dimension2d<s32>& windowSize,
u32 bits, bool fullscreen,
bool sbuffer, bool vsync,
bool antiAlias, IEventReceiver* receiver,
const char* version);
CIrrDeviceMacOSX(const SIrrlichtCreationParameters& params);
//! destructor
virtual ~CIrrDeviceMacOSX();
......@@ -62,7 +57,7 @@ namespace irr
//! \return Returns a pointer to a list with all video modes
//! supported by the gfx adapter.
video::IVideoModeList* getVideoModeList();
virtual video::IVideoModeList* getVideoModeList();
void flush();
void setMouseLocation(int x,int y);
......@@ -72,9 +67,7 @@ namespace irr
private:
//! create the driver
void createDriver(video::E_DRIVER_TYPE driverType,
const core::dimension2d<s32>& windowSize, u32 bits, bool fullscreen,
bool stencilbuffer, bool vsync, bool antiAlias);
void createDriver();
//! Implementation of the macos x cursor control
class CCursorControl : public gui::ICursorControl
......@@ -184,21 +177,18 @@ namespace irr
core::position2d<s32> CursorPos;
core::dimension2d<s32> WindowSize;
core::dimension2d<float> InvWindowSize;
core::rect<s32> ReferenceRect;
CIrrDeviceMacOSX *_device;
bool IsVisible;
bool UseReferenceRect;
core::rect<s32> ReferenceRect;
};
bool createWindow(const irr::core::dimension2d<irr::s32>& windowSize, irr::u32 bits, bool fullscreen, bool vsync, bool stencilBuffer, bool antiAlias);
bool createWindow();
void initKeycodes();
void storeMouseLocation();
void postMouseEvent(void *event,irr::SEvent &ievent);
void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed);
video::E_DRIVER_TYPE DriverType;
bool stencilbuffer;
void *_window;
CGLContextObj _cglcontext;
void *_oglcontext;
......
......@@ -70,13 +70,8 @@ static bool firstLaunch = true;
namespace irr
{
//! constructor
CIrrDeviceMacOSX::CIrrDeviceMacOSX(video::E_DRIVER_TYPE driverType,
const core::dimension2d<s32>& windowSize,
u32 bits, bool fullscreen,
bool sbuffer, bool vsync,
bool antiAlias, IEventReceiver* receiver,
const char* version)
: CIrrDeviceStub(version, receiver), DriverType(driverType), stencilbuffer(sbuffer), _window(NULL), _active(true), _oglcontext(NULL), _cglcontext(NULL)
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), _window(NULL), _active(true), _oglcontext(NULL), _cglcontext(NULL)
{
struct utsname name;
NSString *path;
......@@ -104,9 +99,10 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(video::E_DRIVER_TYPE driverType,
os::Printer::log(name.version,ELL_INFORMATION);
initKeycodes();
if (driverType != video::EDT_NULL) createWindow(windowSize,bits,fullscreen,vsync,stencilbuffer, antiAlias);
CursorControl = new CCursorControl(windowSize, this);
createDriver(driverType,windowSize,bits,fullscreen,stencilbuffer,vsync,antiAlias);
if (CreationParams.DriverType != video::EDT_NULL)
createWindow();
CursorControl = new CCursorControl(CreationParams.WindowSize, this);
createDriver();
createGUIAndScene();
}
......@@ -147,7 +143,7 @@ void CIrrDeviceMacOSX::closeDevice()
_cglcontext = NULL;
}
bool CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& windowSize, irr::u32 bits, bool fullscreen, bool vsync, bool stencilBuffer, bool antiAlias)
bool CIrrDeviceMacOSX::createWindow()
{
int index;
CGDisplayErr error;
......@@ -160,23 +156,21 @@ bool CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& wind
NSOpenGLPixelFormatAttribute windowattribs[32];
CFDictionaryRef displaymode,olddisplaymode;
long numPixelFormats,newSwapInterval;
int alphaSize = 4, depthSize = 16;
int alphaSize = CreationParams.WithAlphaChannel?4:0, depthSize = CreationParams.ZBufferBits;
if (bits == 32) {
if (CreationParams.WithAlphaChannel && (CreationParams.Bits == 32))
alphaSize = 8;
depthSize = 32;
}
result = false;
display = CGMainDisplayID();
_screenWidth = (int) CGDisplayPixelsWide(display);
_screenHeight = (int) CGDisplayPixelsHigh(display);
VideoModeList.setDesktop((s32)bits,core::dimension2d<s32>(_screenWidth, _screenHeight));
VideoModeList.setDesktop(CreationParams.Bits,core::dimension2d<s32>(_screenWidth, _screenHeight));
if (!fullscreen)
if (!CreationParams.Fullscreen)
{
_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,windowSize.Width,windowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
if (_window != NULL)
{
index = 0;
......@@ -186,18 +180,18 @@ bool CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& wind
windowattribs[index++] = NSOpenGLPFADepthSize;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)depthSize;
windowattribs[index++] = NSOpenGLPFAColorSize;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)bits;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)CreationParams.Bits;
windowattribs[index++] = NSOpenGLPFAAlphaSize;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)alphaSize;
if (antiAlias) {
if (CreationParams.AntiAlias) {
windowattribs[index++] = NSOpenGLPFASampleBuffers;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)1;
windowattribs[index++] = NSOpenGLPFASamples;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)2;
}
if (stencilBuffer)
if (CreationParams.StencilBuffer)
{
windowattribs[index++] = NSOpenGLPFAStencilSize;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)1;
......@@ -222,15 +216,15 @@ bool CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& wind
[(NSWindow *)_window makeKeyAndOrderFront:nil];
_cglcontext = (CGLContextObj) [(NSOpenGLContext *)_oglcontext CGLContextObj];
_width = windowSize.Width;
_height = windowSize.Height;
_width = CreationParams.WindowSize.Width;
_height = CreationParams.WindowSize.Height;
result = true;
}
}
}
else
{
displaymode = CGDisplayBestModeForParameters(display,bits,windowSize.Width,windowSize.Height,NULL);
displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
if (displaymode != NULL)
{
olddisplaymode = CGDisplayCurrentMode(display);
......@@ -252,18 +246,18 @@ bool CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& wind
fullattribs[index++] = kCGLPFADepthSize;
fullattribs[index++] = (CGLPixelFormatAttribute)depthSize;
fullattribs[index++] = kCGLPFAColorSize;
fullattribs[index++] = (CGLPixelFormatAttribute)bits;
fullattribs[index++] = (CGLPixelFormatAttribute)CreationParams.Bits;
fullattribs[index++] = kCGLPFAAlphaSize;
fullattribs[index++] = (CGLPixelFormatAttribute)alphaSize;
if (antiAlias) {
if (CreationParams.AntiAlias) {
fullattribs[index++] = kCGLPFASampleBuffers;
fullattribs[index++] = (CGLPixelFormatAttribute)1;
fullattribs[index++] = kCGLPFASamples;
fullattribs[index++] = (CGLPixelFormatAttribute)2;
}
if (stencilBuffer)
if (CreationParams.StencilBuffer)
{
fullattribs[index++] = kCGLPFAStencilSize;
fullattribs[index++] = (CGLPixelFormatAttribute)1;
......@@ -296,7 +290,7 @@ bool CIrrDeviceMacOSX::createWindow(const irr::core::dimension2d<irr::s32>& wind
if (_window == NULL)
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
CGLSetCurrentContext(_cglcontext);
newSwapInterval = (vsync) ? 1 : 0;
newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
CGLSetParameter(_cglcontext,kCGLCPSwapInterval,&newSwapInterval);
glViewport(0,0,_width,_height);
glMatrixMode(GL_PROJECTION);
......@@ -316,13 +310,13 @@ void CIrrDeviceMacOSX::setResize(int width,int height)
getVideoDriver()->OnResize(core::dimension2d<s32>(width, height));
}
void CIrrDeviceMacOSX::createDriver(video::E_DRIVER_TYPE driverType,const core::dimension2d<s32>& windowSize,u32 bits,bool fullscreen,bool stencilbuffer, bool vsync, bool antiAlias)
void CIrrDeviceMacOSX::createDriver()
{
switch (driverType)
switch (CreationParams.DriverType)
{
case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(windowSize, fullscreen, FileSystem, this);
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
#endif
......@@ -330,7 +324,7 @@ void CIrrDeviceMacOSX::createDriver(video::E_DRIVER_TYPE driverType,const core::
case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createSoftwareDriver2(windowSize, fullscreen, FileSystem, this);
VideoDriver = video::createSoftwareDriver2(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
#endif
......@@ -338,7 +332,7 @@ void CIrrDeviceMacOSX::createDriver(video::E_DRIVER_TYPE driverType,const core::
case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_
VideoDriver = video::createOpenGLDriver(windowSize, this, fullscreen, stencilbuffer, FileSystem, vsync, antiAlias);
VideoDriver = video::createOpenGLDriver(CreationParams.WindowSize, this, CreationParams.Fullscreen, CreationParams.Stencilbuffer, FileSystem, CreationParams.Vsync, creationParams.AntiAlias);
#else
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
#endif
......@@ -350,7 +344,7 @@ void CIrrDeviceMacOSX::createDriver(video::E_DRIVER_TYPE driverType,const core::
break;
case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, windowSize);
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
default:
......@@ -702,16 +696,7 @@ video::IVideoModeList* CIrrDeviceMacOSX::getVideoModeList()
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param)
{
CIrrDeviceMacOSX* dev = new CIrrDeviceMacOSX(
param.DriverType,
param.WindowSize,
param.Bits,
param.Fullscreen,
param.Stencilbuffer,
param.Vsync,
param.AntiAlias,
param.EventReceiver,
param.SDK_version_do_not_use);
CIrrDeviceMacOSX* dev = new CIrrDeviceMacOSX(param);
if (dev && !dev->getVideoDriver() && param.DriverType != video::EDT_NULL)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment