Help getting kha to work with Awe6

85 views
Skip to first unread message

Sidar Talei

unread,
Jul 12, 2015, 7:50:58 PM7/12/15
to aw...@googlegroups.com
Hey guys,

I'm working on bringing Kha to Awe6. For those that don't know what Kha is here is the github page: https://github.com/KTXSoftware/Kha.
But simply put it's a toolkit that allows you to create games and applications for different targets under one haxe api ( think Lime, SDL, etc).

I'm not assuming any of you have a lot of Kha experience so I'll try to keep it as abstract as possible.

At this point I'm trying to define the Context and View for Kha. From all the other drivers I've seen they all work with existing containers from each backend. Kha however doesn't have concepts such as graphs/containers , it's rather more to the bone. I need to define these myself.
Kha has an interface Canvas, Image derives from this.
An Image type is either created from assets; static, you can not use this as a render target, you use these to render onto a render target.
Or an Image type that is created with Image Image.createRenderTarget(...), as the name suggest, allows you to draw onto them.

So I came up with this:


typedef Context = KhaContext;

class KhaContext {

public var canvas:Canvas;
public function new () { }
}

In my entry point class I then define a new RenderTarget :

var khaContext:Context = new Context();
khaContext.canvas = Image.createRenderTarget(800, 600);
new Factory(khaContext, false, null);

What I completely fail to understand is how this will work for Views?
Each view holds its own Context. But creating a render target for each view (/entity?) would be abysmal. I can however assign loaded images ( non render targets )  to Context.canvas as well, but I have no clue where and when this would be possible?
To be honest I do not know yet how graphics for entities ( how to add them, apply shaders etc) will work eventually.

Any help would be appreciated.

Canvas holds drawing functionality for both 2D and 3D, but I'm focussing on 2D views first.


Sidar

Rob Fell

unread,
Jul 13, 2015, 11:41:11 AM7/13/15
to aw...@googlegroups.com, sidar...@gmail.com
Sounds very exciting Sidar, thanks for posting to the forum.

To get the discussion going my early investigation on Kha graphics looks very similar to raw CanvasRenderingContext2D in HTML5 (?).  So I'm wondering if we use awe6 View to act similar to EaselJS' Container.  And mirror some of the functionality written there - e.g. the draw() method:


I note it uses a traversal / visitor pattern to render each branch in turn, passing the rendering context to each.  CanvasRenderingContext2D has the ability to save and restore the transformation matrix, does Kha have similar?  If not then some local matrix per View might be needed.

Any additional insight from other forum members would be great to hear.  Thanks.

Sidar Talei

unread,
Jul 13, 2015, 2:51:46 PM7/13/15
to aw...@googlegroups.com, sidar...@gmail.com
The draw functionality for 2D requires an image and a x and y position. These properties need to be added to either context or view ( although I assume view considering Kha.Canvas also has access to 3d rendering functionality ). For Khapunk I wrote this  :
 I think I need to do something similar then.

I could add a function to khas 2d rendering that takes a matrix instead of an x and y parameter.

Sidar Talei

unread,
Jul 19, 2015, 2:08:04 PM7/19/15
to aw...@googlegroups.com
Been a busy week so had little time for awe6. 

What I've done now :

package awe6.core.drivers.kha;
import awe6.core.drivers.AView;
import kha.math.Matrix3;


/**
 * ...
 * @author Sidar Talei
 */

class View extends AView
{
 
private var container:Context;
 
public var matrix:Matrix3;


 
 
 
override private function _init():Void {
 
if (!context) {
 context
= new Context();
 
}
 
super._init();
 
}
 
 
 
override private function _driverDisposer():Void
 
{
 
 
}
 
 
override private function _driverDraw():Void
 
{
 
if (!isVisible) return;
 
 
var children:Array<View> = cast _children;
 
 
if (parent != null) {
 matrix
.multmat((cast parent).matrix);
 
}
 
for ( c in children )
 
{
 
if (c.isVisible) children[i]._driverDraw();
 
}
 
 
}


 
override private function set_x( p_value:Float ):Float
 
{
 matrix
._20 = p_value;
 
//context.x = p_value;
 
return super.set_x( p_value );
 
}
 
 
override private function set_y( p_value:Float ):Float
 
{
 matrix
._21 = p_value;
 
//context.y = p_value;
 
return super.set_y( p_value );
 
}
}


The thing is, what if I want rotation? If I add any extra public functionality to View wouldn't that break awe6 on other targets?

Rob Fell

unread,
Jul 21, 2015, 2:13:21 PM7/21/15
to aw...@googlegroups.com, sidar...@gmail.com

Looks like a good start.  I see a few issues here: matrix will need resetting, each view will need a render method (with RenderTarget passed) to do the actual drawing.

Regarding rotation, typically Context is platform specific and injected into the View from the owning Entity.  Then Context can have platform specific methods, all accessible by it's related Entity.  I generally favor this approach for expediency, however it fuses view functionality into entity.

If you wish to make an extended View that's probably better for separation of concerns, however you'll likely need to inject a specific type of Entity into it so that the internal rendering can access the data model.  With proper interface design this can prevent bloated fusion.
Reply all
Reply to author
Forward
0 new messages