Use onWindowCreate() instead of init(), fix support for multiple GL windows, use window.renderer instead of currentRenderer
This commit is contained in:
@@ -101,6 +101,8 @@ class NativeRenderer {
|
|||||||
|
|
||||||
public function render ():Void {
|
public function render ():Void {
|
||||||
|
|
||||||
|
lime_renderer_make_current (handle);
|
||||||
|
|
||||||
if (!useHardware) {
|
if (!useHardware) {
|
||||||
|
|
||||||
#if lime_cairo
|
#if lime_cairo
|
||||||
@@ -147,8 +149,10 @@ class NativeRenderer {
|
|||||||
|
|
||||||
private static var lime_renderer_create = System.load ("lime", "lime_renderer_create", 1);
|
private static var lime_renderer_create = System.load ("lime", "lime_renderer_create", 1);
|
||||||
private static var lime_renderer_flip = System.load ("lime", "lime_renderer_flip", 1);
|
private static var lime_renderer_flip = System.load ("lime", "lime_renderer_flip", 1);
|
||||||
|
private static var lime_renderer_get_context = System.load ("lime", "lime_renderer_get_context", 1);
|
||||||
private static var lime_renderer_get_type = System.load ("lime", "lime_renderer_get_type", 1);
|
private static var lime_renderer_get_type = System.load ("lime", "lime_renderer_get_type", 1);
|
||||||
private static var lime_renderer_lock = System.load ("lime", "lime_renderer_lock", 1);
|
private static var lime_renderer_lock = System.load ("lime", "lime_renderer_lock", 1);
|
||||||
|
private static var lime_renderer_make_current = System.load ("lime", "lime_renderer_make_current", 1);
|
||||||
private static var lime_renderer_unlock = System.load ("lime", "lime_renderer_unlock", 1);
|
private static var lime_renderer_unlock = System.load ("lime", "lime_renderer_unlock", 1);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ class Application extends Module {
|
|||||||
public var windows (default, null):Array<Window>;
|
public var windows (default, null):Array<Window>;
|
||||||
|
|
||||||
@:noCompletion private var backend:ApplicationBackend;
|
@:noCompletion private var backend:ApplicationBackend;
|
||||||
@:noCompletion private var initialized:Bool;
|
|
||||||
@:noCompletion private var windowByID:Map<Int, Window>;
|
@:noCompletion private var windowByID:Map<Int, Window>;
|
||||||
|
|
||||||
|
|
||||||
@@ -79,11 +78,11 @@ class Application extends Module {
|
|||||||
|
|
||||||
modules.push (module);
|
modules.push (module);
|
||||||
|
|
||||||
if (initialized) {
|
if (windows.length > 0) {
|
||||||
|
|
||||||
if (renderer != null) {
|
for (window in windows) {
|
||||||
|
|
||||||
module.init (this);
|
module.onWindowCreate (window);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +149,11 @@ class Application extends Module {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init (this);
|
if (preloader == null || preloader.complete) {
|
||||||
|
|
||||||
|
onPreloadComplete ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +171,7 @@ class Application extends Module {
|
|||||||
|
|
||||||
window.onActivate.add (onWindowActivate.bind (window));
|
window.onActivate.add (onWindowActivate.bind (window));
|
||||||
window.onClose.add (onWindowClose.bind (window));
|
window.onClose.add (onWindowClose.bind (window));
|
||||||
|
window.onCreate.add (onWindowCreate.bind (window));
|
||||||
window.onDeactivate.add (onWindowDeactivate.bind (window));
|
window.onDeactivate.add (onWindowDeactivate.bind (window));
|
||||||
window.onEnter.add (onWindowEnter.bind (window));
|
window.onEnter.add (onWindowEnter.bind (window));
|
||||||
window.onFocusIn.add (onWindowFocusIn.bind (window));
|
window.onFocusIn.add (onWindowFocusIn.bind (window));
|
||||||
@@ -188,7 +192,7 @@ class Application extends Module {
|
|||||||
window.onTextEdit.add (onTextEdit.bind (window));
|
window.onTextEdit.add (onTextEdit.bind (window));
|
||||||
window.onTextInput.add (onTextInput.bind (window));
|
window.onTextInput.add (onTextInput.bind (window));
|
||||||
|
|
||||||
if (window.currentRenderer == null) {
|
if (window.renderer == null) {
|
||||||
|
|
||||||
var renderer = new Renderer (window);
|
var renderer = new Renderer (window);
|
||||||
addRenderer (renderer);
|
addRenderer (renderer);
|
||||||
@@ -199,6 +203,8 @@ class Application extends Module {
|
|||||||
windows.push (window);
|
windows.push (window);
|
||||||
windowByID.set (window.id, window);
|
windowByID.set (window.id, window);
|
||||||
|
|
||||||
|
window.onCreate.dispatch ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -217,25 +223,6 @@ class Application extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function init (application:Application):Void {
|
|
||||||
|
|
||||||
for (module in modules) {
|
|
||||||
|
|
||||||
module.init (application);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
if (preloader == null || preloader.complete) {
|
|
||||||
|
|
||||||
onPreloadComplete ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void {
|
public override function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void {
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
@@ -507,6 +494,17 @@ class Application extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override function onWindowCreate (window:Window):Void {
|
||||||
|
|
||||||
|
for (module in modules) {
|
||||||
|
|
||||||
|
module.onWindowCreate (window);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function onWindowDeactivate (window:Window):Void {
|
public override function onWindowDeactivate (window:Window):Void {
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
|
|||||||
@@ -15,13 +15,6 @@ import lime.ui.Window;
|
|||||||
interface IModule {
|
interface IModule {
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the module is initialized
|
|
||||||
* @param application The parent application
|
|
||||||
*/
|
|
||||||
public function init (application:Application):Void;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a gamepad axis move event is fired
|
* Called when a gamepad axis move event is fired
|
||||||
* @param gamepad The current gamepad
|
* @param gamepad The current gamepad
|
||||||
@@ -216,6 +209,13 @@ interface IModule {
|
|||||||
public function onWindowClose (window:Window):Void;
|
public function onWindowClose (window:Window):Void;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a window create event is fired
|
||||||
|
* @param window The window dispatching the event
|
||||||
|
*/
|
||||||
|
public function onWindowCreate (window:Window):Void;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a window deactivate event is fired
|
* Called when a window deactivate event is fired
|
||||||
* @param window The window dispatching the event
|
* @param window The window dispatching the event
|
||||||
|
|||||||
@@ -28,13 +28,6 @@ class Module implements IModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the module is initialized
|
|
||||||
* @param application The parent application
|
|
||||||
*/
|
|
||||||
public function init (application:Application):Void { }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a gamepad axis move event is fired
|
* Called when a gamepad axis move event is fired
|
||||||
* @param gamepad The current gamepad
|
* @param gamepad The current gamepad
|
||||||
@@ -229,6 +222,13 @@ class Module implements IModule {
|
|||||||
public function onWindowClose (window:Window):Void { }
|
public function onWindowClose (window:Window):Void { }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a window create event is fired
|
||||||
|
* @param window The window dispatching the event
|
||||||
|
*/
|
||||||
|
public function onWindowCreate (window:Window):Void { }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a window deactivate event is fired
|
* Called when a window deactivate event is fired
|
||||||
* @param window The window dispatching the event
|
* @param window The window dispatching the event
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Renderer {
|
|||||||
|
|
||||||
backend = new RendererBackend (this);
|
backend = new RendererBackend (this);
|
||||||
|
|
||||||
this.window.currentRenderer = this;
|
this.window.renderer = this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class Window {
|
|||||||
|
|
||||||
|
|
||||||
public var application (default, null):Application;
|
public var application (default, null):Application;
|
||||||
public var currentRenderer:Renderer;
|
|
||||||
public var config:WindowConfig;
|
public var config:WindowConfig;
|
||||||
public var display (get, null):Display;
|
public var display (get, null):Display;
|
||||||
public var enableTextEvents (get, set):Bool;
|
public var enableTextEvents (get, set):Bool;
|
||||||
@@ -29,6 +28,7 @@ class Window {
|
|||||||
public var minimized (get, set):Bool;
|
public var minimized (get, set):Bool;
|
||||||
public var onActivate = new Event<Void->Void> ();
|
public var onActivate = new Event<Void->Void> ();
|
||||||
public var onClose = new Event<Void->Void> ();
|
public var onClose = new Event<Void->Void> ();
|
||||||
|
public var onCreate = new Event<Void->Void> ();
|
||||||
public var onDeactivate = new Event<Void->Void> ();
|
public var onDeactivate = new Event<Void->Void> ();
|
||||||
public var onEnter = new Event<Void->Void> ();
|
public var onEnter = new Event<Void->Void> ();
|
||||||
public var onFocusIn = new Event<Void->Void> ();
|
public var onFocusIn = new Event<Void->Void> ();
|
||||||
@@ -48,6 +48,7 @@ class Window {
|
|||||||
public var onRestore = new Event<Void->Void> ();
|
public var onRestore = new Event<Void->Void> ();
|
||||||
public var onTextEdit = new Event<String->Int->Int->Void> ();
|
public var onTextEdit = new Event<String->Int->Int->Void> ();
|
||||||
public var onTextInput = new Event<String->Void> ();
|
public var onTextInput = new Event<String->Void> ();
|
||||||
|
public var renderer:Renderer;
|
||||||
public var stage:Stage;
|
public var stage:Stage;
|
||||||
public var title (get, set):String;
|
public var title (get, set):String;
|
||||||
public var width (get, set):Int;
|
public var width (get, set):Int;
|
||||||
@@ -220,9 +221,9 @@ class Window {
|
|||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
if (currentRenderer != null) {
|
if (renderer != null) {
|
||||||
|
|
||||||
currentRenderer.create ();
|
renderer.create ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ namespace lime {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void Flip () = 0;
|
virtual void Flip () = 0;
|
||||||
|
virtual void* GetContext () = 0;
|
||||||
virtual value Lock () = 0;
|
virtual value Lock () = 0;
|
||||||
|
virtual void MakeCurrent () = 0;
|
||||||
virtual const char* Type () = 0;
|
virtual const char* Type () = 0;
|
||||||
virtual void Unlock () = 0;
|
virtual void Unlock () = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -910,6 +910,14 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_renderer_get_context (value renderer) {
|
||||||
|
|
||||||
|
Renderer* targetRenderer = (Renderer*)(intptr_t)val_float (renderer);
|
||||||
|
return alloc_float ((intptr_t)targetRenderer->GetContext ());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
value lime_renderer_get_type (value renderer) {
|
value lime_renderer_get_type (value renderer) {
|
||||||
|
|
||||||
Renderer* targetRenderer = (Renderer*)(intptr_t)val_float (renderer);
|
Renderer* targetRenderer = (Renderer*)(intptr_t)val_float (renderer);
|
||||||
@@ -925,6 +933,14 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_renderer_make_current (value renderer) {
|
||||||
|
|
||||||
|
((Renderer*)(intptr_t)val_float (renderer))->MakeCurrent ();
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
value lime_renderer_unlock (value renderer) {
|
value lime_renderer_unlock (value renderer) {
|
||||||
|
|
||||||
((Renderer*)(intptr_t)val_float (renderer))->Unlock ();
|
((Renderer*)(intptr_t)val_float (renderer))->Unlock ();
|
||||||
@@ -1273,8 +1289,10 @@ namespace lime {
|
|||||||
DEFINE_PRIM (lime_png_decode_file, 2);
|
DEFINE_PRIM (lime_png_decode_file, 2);
|
||||||
DEFINE_PRIM (lime_renderer_create, 1);
|
DEFINE_PRIM (lime_renderer_create, 1);
|
||||||
DEFINE_PRIM (lime_renderer_flip, 1);
|
DEFINE_PRIM (lime_renderer_flip, 1);
|
||||||
|
DEFINE_PRIM (lime_renderer_get_context, 1);
|
||||||
DEFINE_PRIM (lime_renderer_get_type, 1);
|
DEFINE_PRIM (lime_renderer_get_type, 1);
|
||||||
DEFINE_PRIM (lime_renderer_lock, 1);
|
DEFINE_PRIM (lime_renderer_lock, 1);
|
||||||
|
DEFINE_PRIM (lime_renderer_make_current, 1);
|
||||||
DEFINE_PRIM (lime_renderer_unlock, 1);
|
DEFINE_PRIM (lime_renderer_unlock, 1);
|
||||||
DEFINE_PRIM (lime_render_event_manager_register, 2);
|
DEFINE_PRIM (lime_render_event_manager_register, 2);
|
||||||
DEFINE_PRIM (lime_system_get_directory, 3);
|
DEFINE_PRIM (lime_system_get_directory, 3);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace lime {
|
|||||||
currentWindow = window;
|
currentWindow = window;
|
||||||
sdlWindow = ((SDLWindow*)window)->sdlWindow;
|
sdlWindow = ((SDLWindow*)window)->sdlWindow;
|
||||||
sdlTexture = 0;
|
sdlTexture = 0;
|
||||||
|
context = 0;
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
@@ -46,6 +47,8 @@ namespace lime {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context = SDL_GL_GetCurrentContext ();
|
||||||
|
|
||||||
OpenGLBindings::Init ();
|
OpenGLBindings::Init ();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -69,6 +72,13 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* SDLRenderer::GetContext () {
|
||||||
|
|
||||||
|
return context;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
value SDLRenderer::Lock () {
|
value SDLRenderer::Lock () {
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
@@ -76,10 +86,13 @@ namespace lime {
|
|||||||
|
|
||||||
SDL_GetRendererOutputSize (sdlRenderer, &width, &height);
|
SDL_GetRendererOutputSize (sdlRenderer, &width, &height);
|
||||||
|
|
||||||
if ( width != this->width || height != this->height) {
|
if (width != this->width || height != this->height) {
|
||||||
|
|
||||||
if( sdlTexture )
|
if (sdlTexture) {
|
||||||
SDL_DestroyTexture( sdlTexture );
|
|
||||||
|
SDL_DestroyTexture (sdlTexture);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
sdlTexture = SDL_CreateTexture (sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
sdlTexture = SDL_CreateTexture (sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||||
|
|
||||||
@@ -104,6 +117,17 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SDLRenderer::MakeCurrent () {
|
||||||
|
|
||||||
|
if (sdlWindow && context) {
|
||||||
|
|
||||||
|
SDL_GL_MakeCurrent (sdlWindow, context);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* SDLRenderer::Type () {
|
const char* SDLRenderer::Type () {
|
||||||
|
|
||||||
if (sdlRenderer) {
|
if (sdlRenderer) {
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ namespace lime {
|
|||||||
~SDLRenderer ();
|
~SDLRenderer ();
|
||||||
|
|
||||||
virtual void Flip ();
|
virtual void Flip ();
|
||||||
|
virtual void* GetContext ();
|
||||||
virtual value Lock ();
|
virtual value Lock ();
|
||||||
|
virtual void MakeCurrent ();
|
||||||
virtual const char* Type ();
|
virtual const char* Type ();
|
||||||
virtual void Unlock ();
|
virtual void Unlock ();
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ namespace lime {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
SDL_GLContext context;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class WindowTest {
|
|||||||
|
|
||||||
var window = new Window ();
|
var window = new Window ();
|
||||||
|
|
||||||
Assert.isNull (window.currentRenderer);
|
Assert.isNull (window.renderer);
|
||||||
Assert.isNull (window.config);
|
Assert.isNull (window.config);
|
||||||
Assert.isFalse (window.fullscreen);
|
Assert.isFalse (window.fullscreen);
|
||||||
Assert.areEqual (0, window.height);
|
Assert.areEqual (0, window.height);
|
||||||
@@ -37,7 +37,7 @@ class WindowTest {
|
|||||||
|
|
||||||
app.createWindow (window);
|
app.createWindow (window);
|
||||||
|
|
||||||
Assert.isNotNull (window.currentRenderer);
|
Assert.isNotNull (window.renderer);
|
||||||
Assert.isNull (window.config);
|
Assert.isNull (window.config);
|
||||||
|
|
||||||
#if !html5
|
#if !html5
|
||||||
@@ -70,7 +70,7 @@ class WindowTest {
|
|||||||
window.width = 400;
|
window.width = 400;
|
||||||
window.height = 300;
|
window.height = 300;
|
||||||
|
|
||||||
Assert.isNull (window.currentRenderer);
|
Assert.isNull (window.renderer);
|
||||||
Assert.isNull (window.config);
|
Assert.isNull (window.config);
|
||||||
Assert.isFalse (window.fullscreen);
|
Assert.isFalse (window.fullscreen);
|
||||||
Assert.areEqual (300, window.height);
|
Assert.areEqual (300, window.height);
|
||||||
@@ -80,7 +80,7 @@ class WindowTest {
|
|||||||
|
|
||||||
app.createWindow (window);
|
app.createWindow (window);
|
||||||
|
|
||||||
Assert.isNotNull (window.currentRenderer);
|
Assert.isNotNull (window.renderer);
|
||||||
Assert.isNull (window.config);
|
Assert.isNull (window.config);
|
||||||
Assert.isFalse (window.fullscreen);
|
Assert.isFalse (window.fullscreen);
|
||||||
Assert.areEqual (300, window.height);
|
Assert.areEqual (300, window.height);
|
||||||
@@ -104,7 +104,7 @@ class WindowTest {
|
|||||||
var config = {};
|
var config = {};
|
||||||
var window = new Window (config);
|
var window = new Window (config);
|
||||||
|
|
||||||
Assert.isNull (window.currentRenderer);
|
Assert.isNull (window.renderer);
|
||||||
Assert.areEqual (config, window.config);
|
Assert.areEqual (config, window.config);
|
||||||
Assert.isFalse (window.fullscreen);
|
Assert.isFalse (window.fullscreen);
|
||||||
Assert.areEqual (0, window.height);
|
Assert.areEqual (0, window.height);
|
||||||
@@ -114,7 +114,7 @@ class WindowTest {
|
|||||||
|
|
||||||
app.createWindow (window);
|
app.createWindow (window);
|
||||||
|
|
||||||
Assert.isNotNull (window.currentRenderer);
|
Assert.isNotNull (window.renderer);
|
||||||
Assert.areEqual (config, window.config);
|
Assert.areEqual (config, window.config);
|
||||||
|
|
||||||
#if !html5
|
#if !html5
|
||||||
@@ -143,7 +143,7 @@ class WindowTest {
|
|||||||
var config = { width: 400, height: 300 };
|
var config = { width: 400, height: 300 };
|
||||||
var window = new Window (config);
|
var window = new Window (config);
|
||||||
|
|
||||||
Assert.isNull (window.currentRenderer);
|
Assert.isNull (window.renderer);
|
||||||
Assert.areEqual (config, window.config);
|
Assert.areEqual (config, window.config);
|
||||||
Assert.isFalse (window.fullscreen);
|
Assert.isFalse (window.fullscreen);
|
||||||
Assert.areEqual (300, window.height);
|
Assert.areEqual (300, window.height);
|
||||||
@@ -153,7 +153,7 @@ class WindowTest {
|
|||||||
|
|
||||||
app.createWindow (window);
|
app.createWindow (window);
|
||||||
|
|
||||||
Assert.isNotNull (window.currentRenderer);
|
Assert.isNotNull (window.renderer);
|
||||||
Assert.areEqual (config, window.config);
|
Assert.areEqual (config, window.config);
|
||||||
Assert.isFalse (window.fullscreen);
|
Assert.isFalse (window.fullscreen);
|
||||||
Assert.areEqual (300, window.height);
|
Assert.areEqual (300, window.height);
|
||||||
|
|||||||
Reference in New Issue
Block a user