From c45b5f52e49a971c5a39d06e5f74412d2635ce77 Mon Sep 17 00:00:00 2001 From: Michael Bickel Date: Tue, 17 Jun 2014 04:56:52 +0200 Subject: [PATCH] first pass of adding flags for sdl (stencil and depthbuffer) --- lime/app/Application.hx | 5 ++--- lime/graphics/Renderer.hx | 2 ++ lime/ui/Window.hx | 19 ++++++++++++++++--- project/include/ui/Window.h | 2 +- project/src/ExternalInterface.cpp | 6 +++--- project/src/backend/sdl/SDLWindow.cpp | 17 +++++++++++++---- project/src/backend/sdl/SDLWindow.h | 7 ++++++- 7 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 2859fcd19..29b1d489b 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -7,8 +7,7 @@ import lime.ui.*; class Application implements IKeyEventListener implements IMouseEventListener implements ITouchEventListener implements IWindowEventListener { - - + public var handle:Dynamic; private var config:Config; @@ -52,7 +51,7 @@ class Application implements IKeyEventListener implements IMouseEventListener im TouchEventManager.addEventListener (this); WindowEventManager.addEventListener (this); - var window = new Window (this); + var window = new Window (this, config); var renderer = new Renderer (window); window.width = config.width; diff --git a/lime/graphics/Renderer.hx b/lime/graphics/Renderer.hx index e3f5179c5..5011be8a3 100644 --- a/lime/graphics/Renderer.hx +++ b/lime/graphics/Renderer.hx @@ -16,6 +16,8 @@ import flash.Lib; @:access(lime.graphics.opengl.GL) class Renderer { + public inline static var DEPTH_BUFFER = 0x0200; + public inline static var STENCIL_BUFFER = 0x0400; public var context:RenderContext; public var handle:Dynamic; diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index 7160818db..de0805e2f 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -19,8 +19,11 @@ import js.Browser; class Window { + public inline static var DEPTH_BUFFER = 0x0200; + public inline static var STENCIL_BUFFER = 0x0400; public var currentRenderer:Renderer; + public var config:Config; public var fullscreen:Bool; public var height:Int; public var width:Int; @@ -39,9 +42,10 @@ class Window { #end - public function new (application:Application) { + public function new (application:Application, config:Config) { this.application = application; + this.config = config; } @@ -151,7 +155,16 @@ class Window { #end #elseif (cpp || neko) - handle = lime_window_create (application.handle); + // forward flags + var flags:Int = 0; + + if (config.depthBuffer) + flags |= DEPTH_BUFFER; + + if (config.stencilBuffer) + flags |= STENCIL_BUFFER; + + handle = lime_window_create (application.handle, flags); #end KeyEventManager.registerWindow (this); @@ -171,7 +184,7 @@ class Window { #if (cpp || neko) - private static var lime_window_create = System.load ("lime", "lime_window_create", 1); + private static var lime_window_create = System.load ("lime", "lime_window_create", 2); #end diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index a3b9544fa..0a36df2b1 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -23,7 +23,7 @@ namespace lime { }; - Window* CreateWindow (Application* application); + Window* CreateWindow (Application* application, int flags); } diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index bc5d3921e..fe0726cd1 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -159,9 +159,9 @@ namespace lime { } - value lime_window_create (value application) { + value lime_window_create (value application, value flags) { - Window* window = CreateWindow ((Application*)(intptr_t)val_float (application)); + Window* window = CreateWindow ((Application*)(intptr_t)val_float (application), val_int(flags)); return alloc_float ((intptr_t)window); } @@ -191,7 +191,7 @@ namespace lime { DEFINE_PRIM (lime_system_get_timestamp, 0); DEFINE_PRIM (lime_touch_event_manager_register, 2); DEFINE_PRIM (lime_update_event_manager_register, 2); - DEFINE_PRIM (lime_window_create, 1); + DEFINE_PRIM (lime_window_create, 2); DEFINE_PRIM (lime_window_event_manager_register, 2); diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 10e2ba71c..de36411bd 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -4,9 +4,18 @@ namespace lime { - SDLWindow::SDLWindow (Application* application) { - + SDLWindow::SDLWindow (Application* application, int flags) { + currentApplication = application; + + // config the window + if (flags & DEPTH_BUFFER) + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32 - (flags & STENCIL_BUFFER) ? 8 : 0); + + if (flags & STENCIL_BUFFER) + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + + sdlWindow = SDL_CreateWindow ("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_OPENGL); } @@ -19,9 +28,9 @@ namespace lime { } - Window* CreateWindow (Application* application) { + Window* CreateWindow (Application* application, int flags) { - return new SDLWindow (application); + return new SDLWindow (application, flags); } diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index d55df2c3a..eb9c1b729 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -8,12 +8,17 @@ namespace lime { + enum SDLWindowFlags + { + DEPTH_BUFFER = 0x00000200, + STENCIL_BUFFER = 0x00000400, + }; class SDLWindow : public Window { public: - SDLWindow (Application* application); + SDLWindow (Application* application, int flags); ~SDLWindow (); SDL_Window* sdlWindow;