Use onWindowCreate() instead of init(), fix support for multiple GL windows, use window.renderer instead of currentRenderer

This commit is contained in:
Joshua Granick
2015-08-20 13:39:53 -07:00
parent f79a73fa47
commit 56c0872b8a
11 changed files with 104 additions and 54 deletions

View File

@@ -101,6 +101,8 @@ class NativeRenderer {
public function render ():Void {
lime_renderer_make_current (handle);
if (!useHardware) {
#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_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_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);

View File

@@ -39,7 +39,6 @@ class Application extends Module {
public var windows (default, null):Array<Window>;
@:noCompletion private var backend:ApplicationBackend;
@:noCompletion private var initialized:Bool;
@:noCompletion private var windowByID:Map<Int, Window>;
@@ -79,11 +78,11 @@ class Application extends 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.onClose.add (onWindowClose.bind (window));
window.onCreate.add (onWindowCreate.bind (window));
window.onDeactivate.add (onWindowDeactivate.bind (window));
window.onEnter.add (onWindowEnter.bind (window));
window.onFocusIn.add (onWindowFocusIn.bind (window));
@@ -188,7 +192,7 @@ class Application extends Module {
window.onTextEdit.add (onTextEdit.bind (window));
window.onTextInput.add (onTextInput.bind (window));
if (window.currentRenderer == null) {
if (window.renderer == null) {
var renderer = new Renderer (window);
addRenderer (renderer);
@@ -199,6 +203,8 @@ class Application extends Module {
windows.push (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 {
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 {
for (module in modules) {

View File

@@ -15,13 +15,6 @@ import lime.ui.Window;
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
* @param gamepad The current gamepad
@@ -216,6 +209,13 @@ interface IModule {
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
* @param window The window dispatching the event

View File

@@ -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
* @param gamepad The current gamepad
@@ -229,6 +222,13 @@ class Module implements IModule {
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
* @param window The window dispatching the event

View File

@@ -23,7 +23,7 @@ class Renderer {
backend = new RendererBackend (this);
this.window.currentRenderer = this;
this.window.renderer = this;
}

View File

@@ -19,7 +19,6 @@ class Window {
public var application (default, null):Application;
public var currentRenderer:Renderer;
public var config:WindowConfig;
public var display (get, null):Display;
public var enableTextEvents (get, set):Bool;
@@ -29,6 +28,7 @@ class Window {
public var minimized (get, set):Bool;
public var onActivate = 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 onEnter = 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 onTextEdit = new Event<String->Int->Int->Void> ();
public var onTextInput = new Event<String->Void> ();
public var renderer:Renderer;
public var stage:Stage;
public var title (get, set):String;
public var width (get, set):Int;
@@ -220,9 +221,9 @@ class Window {
#end
if (currentRenderer != null) {
if (renderer != null) {
currentRenderer.create ();
renderer.create ();
}

View File

@@ -15,7 +15,9 @@ namespace lime {
public:
virtual void Flip () = 0;
virtual void* GetContext () = 0;
virtual value Lock () = 0;
virtual void MakeCurrent () = 0;
virtual const char* Type () = 0;
virtual void Unlock () = 0;

View File

@@ -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) {
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) {
((Renderer*)(intptr_t)val_float (renderer))->Unlock ();
@@ -1273,8 +1289,10 @@ namespace lime {
DEFINE_PRIM (lime_png_decode_file, 2);
DEFINE_PRIM (lime_renderer_create, 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_lock, 1);
DEFINE_PRIM (lime_renderer_make_current, 1);
DEFINE_PRIM (lime_renderer_unlock, 1);
DEFINE_PRIM (lime_render_event_manager_register, 2);
DEFINE_PRIM (lime_system_get_directory, 3);

View File

@@ -11,6 +11,7 @@ namespace lime {
currentWindow = window;
sdlWindow = ((SDLWindow*)window)->sdlWindow;
sdlTexture = 0;
context = 0;
width = 0;
height = 0;
@@ -46,6 +47,8 @@ namespace lime {
}
context = SDL_GL_GetCurrentContext ();
OpenGLBindings::Init ();
}
@@ -69,6 +72,13 @@ namespace lime {
}
void* SDLRenderer::GetContext () {
return context;
}
value SDLRenderer::Lock () {
int width;
@@ -78,9 +88,12 @@ namespace lime {
if (width != this->width || height != this->height) {
if( sdlTexture )
if (sdlTexture) {
SDL_DestroyTexture (sdlTexture);
}
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 () {
if (sdlRenderer) {

View File

@@ -17,7 +17,9 @@ namespace lime {
~SDLRenderer ();
virtual void Flip ();
virtual void* GetContext ();
virtual value Lock ();
virtual void MakeCurrent ();
virtual const char* Type ();
virtual void Unlock ();
@@ -27,6 +29,7 @@ namespace lime {
private:
SDL_GLContext context;
int width;
int height;

View File

@@ -27,7 +27,7 @@ class WindowTest {
var window = new Window ();
Assert.isNull (window.currentRenderer);
Assert.isNull (window.renderer);
Assert.isNull (window.config);
Assert.isFalse (window.fullscreen);
Assert.areEqual (0, window.height);
@@ -37,7 +37,7 @@ class WindowTest {
app.createWindow (window);
Assert.isNotNull (window.currentRenderer);
Assert.isNotNull (window.renderer);
Assert.isNull (window.config);
#if !html5
@@ -70,7 +70,7 @@ class WindowTest {
window.width = 400;
window.height = 300;
Assert.isNull (window.currentRenderer);
Assert.isNull (window.renderer);
Assert.isNull (window.config);
Assert.isFalse (window.fullscreen);
Assert.areEqual (300, window.height);
@@ -80,7 +80,7 @@ class WindowTest {
app.createWindow (window);
Assert.isNotNull (window.currentRenderer);
Assert.isNotNull (window.renderer);
Assert.isNull (window.config);
Assert.isFalse (window.fullscreen);
Assert.areEqual (300, window.height);
@@ -104,7 +104,7 @@ class WindowTest {
var config = {};
var window = new Window (config);
Assert.isNull (window.currentRenderer);
Assert.isNull (window.renderer);
Assert.areEqual (config, window.config);
Assert.isFalse (window.fullscreen);
Assert.areEqual (0, window.height);
@@ -114,7 +114,7 @@ class WindowTest {
app.createWindow (window);
Assert.isNotNull (window.currentRenderer);
Assert.isNotNull (window.renderer);
Assert.areEqual (config, window.config);
#if !html5
@@ -143,7 +143,7 @@ class WindowTest {
var config = { width: 400, height: 300 };
var window = new Window (config);
Assert.isNull (window.currentRenderer);
Assert.isNull (window.renderer);
Assert.areEqual (config, window.config);
Assert.isFalse (window.fullscreen);
Assert.areEqual (300, window.height);
@@ -153,7 +153,7 @@ class WindowTest {
app.createWindow (window);
Assert.isNotNull (window.currentRenderer);
Assert.isNotNull (window.renderer);
Assert.areEqual (config, window.config);
Assert.isFalse (window.fullscreen);
Assert.areEqual (300, window.height);