aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/CIrrDeviceSDL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Irrlicht/CIrrDeviceSDL.cpp')
-rw-r--r--source/Irrlicht/CIrrDeviceSDL.cpp263
1 files changed, 123 insertions, 140 deletions
diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp
index 26683a7..c1e7527 100644
--- a/source/Irrlicht/CIrrDeviceSDL.cpp
+++ b/source/Irrlicht/CIrrDeviceSDL.cpp
@@ -20,15 +20,10 @@
#include <SDL_video.h>
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
-#ifdef _IRR_COMPILE_WITH_OGLES2_
-#include "CEGLManager.h"
-#endif
#include <emscripten.h>
#endif
-#ifdef _IRR_COMPILE_WITH_OPENGL_
#include "CSDLManager.h"
-#endif
static int SDLDeviceInstances = 0;
@@ -38,14 +33,42 @@ namespace irr
{
#ifdef _IRR_COMPILE_WITH_OPENGL_
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
+ #else
+ static IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
+ {
+ os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
+ return nullptr;
+ }
+ #endif
+
+ #ifdef ENABLE_OPENGL3
+ IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
+ #else
+ static IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
+ {
+ os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR);
+ return nullptr;
+ }
#endif
#ifdef _IRR_COMPILE_WITH_OGLES2_
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
+ #else
+ static IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
+ {
+ os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR);
+ return nullptr;
+ }
#endif
#ifdef _IRR_COMPILE_WITH_WEBGL1_
IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
+ #else
+ static IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
+ {
+ os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR);
+ return nullptr;
+ }
#endif
} // end namespace video
@@ -232,28 +255,6 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
// create keymap
createKeyMap();
- if (CreationParams.Fullscreen) {
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_
- SDL_Flags |= SDL_WINDOW_FULLSCREEN;
-#else
- SDL_Flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
-#endif
- }
- if (Resizable)
- SDL_Flags |= SDL_WINDOW_RESIZABLE;
- if (CreationParams.WindowMaximized)
- SDL_Flags |= SDL_WINDOW_MAXIMIZED;
-
- if (CreationParams.DriverType == video::EDT_OPENGL)
- {
- SDL_Flags |= SDL_WINDOW_OPENGL;
- if (!CreationParams.Doublebuffer)
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
- }
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_
- SDL_Flags |= SDL_WINDOW_OPENGL;
-#endif //_IRR_EMSCRIPTEN_PLATFORM_
-
// create window
if (CreationParams.DriverType != video::EDT_NULL)
{
@@ -343,6 +344,19 @@ void CIrrDeviceSDL::logAttributes()
bool CIrrDeviceSDL::createWindow()
{
+ if (CreationParams.Fullscreen) {
+#ifdef _IRR_EMSCRIPTEN_PLATFORM_
+ SDL_Flags |= SDL_WINDOW_FULLSCREEN;
+#else
+ SDL_Flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+#endif
+ }
+ if (Resizable)
+ SDL_Flags |= SDL_WINDOW_RESIZABLE;
+ if (CreationParams.WindowMaximized)
+ SDL_Flags |= SDL_WINDOW_MAXIMIZED;
+ SDL_Flags |= SDL_WINDOW_OPENGL;
+
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
if ( Width != 0 || Height != 0 )
emscripten_set_canvas_size( Width, Height);
@@ -389,54 +403,73 @@ bool CIrrDeviceSDL::createWindow()
if ( Close )
return false;
- if (CreationParams.DriverType == video::EDT_OPENGL) {
- if (CreationParams.Bits == 16) {
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4);
- SDL_GL_SetAttribute(
- SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0);
- } else {
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- 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.ZBufferBits);
- if (CreationParams.Doublebuffer)
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0);
- if (CreationParams.Stereobuffer)
- SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
- if (CreationParams.AntiAlias > 1) {
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+ switch (CreationParams.DriverType) {
+ case video::EDT_OPENGL:
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ break;
+ case video::EDT_OPENGL3:
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
+ break;
+ case video::EDT_OGLES1:
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ break;
+ case video::EDT_OGLES2:
+ case video::EDT_WEBGL1:
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ break;
+ default:;
+ }
+
+#ifdef _DEBUG
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG);
+#endif
+
+ if (CreationParams.Bits == 16) {
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0);
+ } else {
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ 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.ZBufferBits);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0);
+ SDL_GL_SetAttribute(SDL_GL_STEREO, CreationParams.Stereobuffer);
+ if (CreationParams.AntiAlias > 1) {
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);
+ }
+ if (!Window)
+ Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
+ if (!Window) {
+ os::Printer::log("Could not create window...", SDL_GetError(), ELL_WARNING);
+ }
+ if (!Window && CreationParams.AntiAlias > 1) {
+ while (--CreationParams.AntiAlias > 1) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);
- }
- if (!Window)
Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
- if (!Window && CreationParams.AntiAlias > 1) {
- while (--CreationParams.AntiAlias > 1) {
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);
- Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
- if (Window)
- break;
- }
- if (!Window) {
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
- Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
- if (Window)
- os::Printer::log("AntiAliasing disabled due to lack of support!");
- }
+ if (Window)
+ break;
}
-
- if (Window)
- {
- Context = SDL_GL_CreateContext(Window);
+ if (!Window) {
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
+ Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
+ if (Window)
+ os::Printer::log("AntiAliasing disabled due to lack of support!", ELL_WARNING);
}
- } else if (!Window)
- Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
+ }
if ( !Window && CreationParams.Doublebuffer)
{
@@ -447,7 +480,14 @@ bool CIrrDeviceSDL::createWindow()
}
if ( !Window )
{
- os::Printer::log("Could not initialize display!" );
+ os::Printer::log("Could not initialize display", SDL_GetError(), ELL_ERROR);
+ return false;
+ }
+
+ Context = SDL_GL_CreateContext(Window);
+ if (!Context) {
+ os::Printer::log("Could not initialize context", SDL_GetError(), ELL_ERROR);
+ SDL_DestroyWindow(Window);
return false;
}
@@ -459,79 +499,22 @@ bool CIrrDeviceSDL::createWindow()
//! create the driver
void CIrrDeviceSDL::createDriver()
{
- switch(CreationParams.DriverType)
- {
- case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS:
- os::Printer::log("DIRECT3D8 Driver is no longer supported in Irrlicht. Try another one.", ELL_ERROR);
- break;
-
- case video::EDT_DIRECT3D9:
- #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
- os::Printer::log("SDL device does not support DIRECT3D9 driver. Try another one.", ELL_ERROR);
- #else
- os::Printer::log("DIRECT3D9 Driver was not compiled into this dll. Try another one.", ELL_ERROR);
- #endif // _IRR_COMPILE_WITH_DIRECT3D_9_
-
- break;
-
- case video::EDT_OPENGL:
- #ifdef _IRR_COMPILE_WITH_OPENGL_
- ContextManager = new video::CSDLManager(this);
- VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);
- #else
- os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
- #endif
- break;
-
- case video::EDT_OGLES2:
-#if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)
- {
- video::SExposedVideoData data;
-
- ContextManager = new video::CEGLManager();
- ContextManager->initialize(CreationParams, data);
-
- VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);
- }
-#else
- os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR);
-#endif
- break;
-
- case video::EDT_WEBGL1:
-#if defined(_IRR_COMPILE_WITH_WEBGL1_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)
- {
- video::SExposedVideoData data;
-
- ContextManager = new video::CEGLManager();
- ContextManager->initialize(CreationParams, data);
-
- VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager);
- }
-#else
- os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR);
-#endif
- break;
-
- case video::EDT_NULL:
+ if (CreationParams.DriverType == video::EDT_NULL) {
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
- break;
-
- default:
- os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);
- break;
+ return;
}
- // In case we got the size from the canvas
- if ( VideoDriver && CreationParams.WindowSize.Width == 0 && CreationParams.WindowSize.Height == 0 && Width > 0 && Height > 0 )
+ ContextManager = new video::CSDLManager(this);
+ switch(CreationParams.DriverType)
{
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_
- SDL_CreateWindowAndRenderer(Width, Height, SDL_Flags, &Window, &Renderer);
-#else //_IRR_EMSCRIPTEN_PLATFORM_
- Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);
-#endif //_IRR_EMSCRIPTEN_PLATFOR
- VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
+ case video::EDT_OPENGL: VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); break;
+ case video::EDT_OPENGL3: VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); break;
+ case video::EDT_OGLES2: VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); break;
+ case video::EDT_WEBGL1: VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); break;
+ default:;
}
+ if (!VideoDriver)
+ os::Printer::log("Could not create video driver", ELL_ERROR);
}