support SDL build w/o OpenGL

This commit is contained in:
Vadim Lopatin 2014-04-30 11:48:15 +04:00
parent a2dc1d7c6e
commit 85aca6f039
3 changed files with 67 additions and 62 deletions

View File

@ -66,7 +66,7 @@
<debuglevel>0</debuglevel> <debuglevel>0</debuglevel>
<debugids /> <debugids />
<versionlevel>0</versionlevel> <versionlevel>0</versionlevel>
<versionids>Unicode USE_OPENGL USE_SDL</versionids> <versionids>Unicode USE_SDL</versionids>
<dump_source>0</dump_source> <dump_source>0</dump_source>
<mapverbosity>0</mapverbosity> <mapverbosity>0</mapverbosity>
<createImplib>1</createImplib> <createImplib>1</createImplib>
@ -217,14 +217,6 @@
<File path="..\DerelictGL3\source\derelict\opengl3\wgl.d" /> <File path="..\DerelictGL3\source\derelict\opengl3\wgl.d" />
<File path="..\DerelictGL3\source\derelict\opengl3\wglext.d" /> <File path="..\DerelictGL3\source\derelict\opengl3\wglext.d" />
</Folder> </Folder>
<Folder name="DerelictUtil">
<File path="..\DerelictUtil\source\derelict\util\exception.d" />
<File path="..\DerelictUtil\source\derelict\util\loader.d" />
<File path="..\DerelictUtil\source\derelict\util\sharedlib.d" />
<File path="..\DerelictUtil\source\derelict\util\system.d" />
<File path="..\DerelictUtil\source\derelict\util\wintypes.d" />
<File path="..\DerelictUtil\source\derelict\util\xtypes.d" />
</Folder>
<Folder name="DerelictSDL2"> <Folder name="DerelictSDL2">
<File path="..\DerelictSDL2\source\derelict\sdl2\functions.d" /> <File path="..\DerelictSDL2\source\derelict\sdl2\functions.d" />
<File path="..\DerelictSDL2\source\derelict\sdl2\image.d" /> <File path="..\DerelictSDL2\source\derelict\sdl2\image.d" />
@ -234,6 +226,14 @@
<File path="..\DerelictSDL2\source\derelict\sdl2\ttf.d" /> <File path="..\DerelictSDL2\source\derelict\sdl2\ttf.d" />
<File path="..\DerelictSDL2\source\derelict\sdl2\types.d" /> <File path="..\DerelictSDL2\source\derelict\sdl2\types.d" />
</Folder> </Folder>
<Folder name="DerelictUtil">
<File path="..\DerelictUtil\source\derelict\util\exception.d" />
<File path="..\DerelictUtil\source\derelict\util\loader.d" />
<File path="..\DerelictUtil\source\derelict\util\sharedlib.d" />
<File path="..\DerelictUtil\source\derelict\util\system.d" />
<File path="..\DerelictUtil\source\derelict\util\wintypes.d" />
<File path="..\DerelictUtil\source\derelict\util\xtypes.d" />
</Folder>
<Folder name="gl3n"> <Folder name="gl3n">
<File path="..\gl3n\gl3n\aabb.d" /> <File path="..\gl3n\gl3n\aabb.d" />
<File path="..\gl3n\gl3n\frustum.d" /> <File path="..\gl3n\gl3n\frustum.d" />

View File

@ -66,7 +66,7 @@
<debuglevel>0</debuglevel> <debuglevel>0</debuglevel>
<debugids /> <debugids />
<versionlevel>0</versionlevel> <versionlevel>0</versionlevel>
<versionids>Unicode USE_OPENGL USE_SDL</versionids> <versionids>Unicode USE_SDL</versionids>
<dump_source>0</dump_source> <dump_source>0</dump_source>
<mapverbosity>3</mapverbosity> <mapverbosity>3</mapverbosity>
<createImplib>0</createImplib> <createImplib>0</createImplib>

View File

@ -48,22 +48,29 @@ version(USE_SDL) {
debug Log.d("Destroying SDL window"); debug Log.d("Destroying SDL window");
if (_renderer) if (_renderer)
SDL_DestroyRenderer(_renderer); SDL_DestroyRenderer(_renderer);
version(USE_OPENGL) {
if (_context) if (_context)
SDL_GL_DeleteContext(_context); SDL_GL_DeleteContext(_context);
}
if (_win) if (_win)
SDL_DestroyWindow(_win); SDL_DestroyWindow(_win);
} }
static private bool _sdlReloaded = false; version(USE_OPENGL) {
SDL_GLContext _context; static private bool _gl3Reloaded = false;
private SDL_GLContext _context;
}
bool create() { bool create() {
uint windowFlags = SDL_WINDOW_RESIZABLE; uint windowFlags = SDL_WINDOW_RESIZABLE;
version(USE_OPENGL) {
if (_enableOpengl) if (_enableOpengl)
windowFlags |= SDL_WINDOW_OPENGL; windowFlags |= SDL_WINDOW_OPENGL;
}
_win = SDL_CreateWindow(_caption.toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _win = SDL_CreateWindow(_caption.toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
700, 500, 700, 500,
windowFlags); windowFlags);
version(USE_OPENGL) {
if (!_win) { if (!_win) {
if (_enableOpengl) { if (_enableOpengl) {
Log.e("SDL_CreateWindow failed - cannot create OpenGL window: ", fromStringz(SDL_GetError())); Log.e("SDL_CreateWindow failed - cannot create OpenGL window: ", fromStringz(SDL_GetError()));
@ -74,30 +81,25 @@ version(USE_SDL) {
700, 500, 700, 500,
windowFlags); windowFlags);
} }
}
} }
if (!_win) { if (!_win) {
Log.e("SDL2: Failed to create window"); Log.e("SDL2: Failed to create window");
return false; return false;
} }
version(USE_OPENGL) {
if (_enableOpengl) { if (_enableOpengl) {
_context = SDL_GL_CreateContext(_win); // Create the actual context and make it current _context = SDL_GL_CreateContext(_win); // Create the actual context and make it current
if (!_context) { if (!_context) {
Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError())); Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError()));
_enableOpengl = false; _enableOpengl = false;
} else if (!_sdlReloaded) { } else if (!_gl3Reloaded) {
//if (SDL_GL_MakeCurrent(window, context)) { DerelictGL3.reload();
// Log.e("SDL_GL_MakeCurrent failed: ", fromStringz(SDL_GetError())); _gl3Reloaded = true;
// _enableOpengl = false;
//}
DerelictGL3.reload(); //<-- BOOM SIGSEGV
_sdlReloaded = true;
if (!initShaders()) if (!initShaders())
_enableOpengl = false; _enableOpengl = false;
} }
//if (context) }
// SDL_GL_DeleteContext(context);
//if (window)
// SDL_DestroyWindow(window);
} }
if (!_enableOpengl) { if (!_enableOpengl) {
_renderer = SDL_CreateRenderer(_win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); _renderer = SDL_CreateRenderer(_win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
@ -106,7 +108,7 @@ version(USE_SDL) {
return false; return false;
} }
} }
//windowCaption = _caption; windowCaption = _caption;
return true; return true;
} }
@ -117,7 +119,6 @@ version(USE_SDL) {
} }
bool _derelictgl3Reloaded;
override void show() { override void show() {
Log.d("SDLWindow.show()"); Log.d("SDLWindow.show()");
SDL_ShowWindow(_win); SDL_ShowWindow(_win);
@ -169,12 +170,9 @@ version(USE_SDL) {
//Log.e("Widget instance count in SDLWindow.redraw: ", Widget.instanceCount()); //Log.e("Widget instance count in SDLWindow.redraw: ", Widget.instanceCount());
// check if size has been changed // check if size has been changed
int w, h; int w, h;
SDL_GetWindowSize(_win, SDL_GetWindowSize(_win, &w, &h);
&w,
&h);
onResize(w, h); onResize(w, h);
if (_enableOpengl) { if (_enableOpengl) {
version(USE_OPENGL) { version(USE_OPENGL) {
SDL_GL_MakeCurrent(_win, _context); SDL_GL_MakeCurrent(_win, _context);
@ -194,10 +192,13 @@ version(USE_SDL) {
destroy(buf); destroy(buf);
} }
} else { } else {
// Select the color for drawing. It is set to red here. // Select the color for drawing.
//SDL_SetRenderDrawColor(_renderer, 255, 0, 0, 255); ubyte r = cast(ubyte)((_backgroundColor >> 16) & 255);
ubyte g = cast(ubyte)((_backgroundColor >> 8) & 255);
ubyte b = cast(ubyte)((_backgroundColor >> 0) & 255);
SDL_SetRenderDrawColor(_renderer, r, g, b, 255);
// Clear the entire screen to our selected color. // Clear the entire screen to our selected color.
//SDL_RenderClear(_renderer); SDL_RenderClear(_renderer);
if (!_drawbuf) if (!_drawbuf)
_drawbuf = new ColorDrawBuf(_dx, _dy); _drawbuf = new ColorDrawBuf(_dx, _dy);
@ -786,12 +787,14 @@ version(USE_SDL) {
return 1; return 1;
} }
version(USE_OPENGL) {
try { try {
DerelictGL3.load(); DerelictGL3.load();
_enableOpengl = true; _enableOpengl = true;
} catch (Exception e) { } catch (Exception e) {
Log.e("Cannot load opengl library", e); Log.e("Cannot load opengl library", e);
} }
}
SDL_DisplayMode displayMode; SDL_DisplayMode displayMode;
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS) != 0) { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS) != 0) {
@ -801,12 +804,14 @@ version(USE_SDL) {
scope(exit)SDL_Quit(); scope(exit)SDL_Quit();
int request = SDL_GetDesktopDisplayMode(0,&displayMode); int request = SDL_GetDesktopDisplayMode(0,&displayMode);
version(USE_OPENGL) {
// we want OpenGL 3.3 // we want OpenGL 3.3
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2);
// Set OpenGL attributes // Set OpenGL attributes
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
}
SDLPlatform sdl = new SDLPlatform(); SDLPlatform sdl = new SDLPlatform();
if (!sdl.connect()) { if (!sdl.connect()) {