Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 173 forks source link

Different behaviour of drawing on rendertarget in HTML5 and Krom on macOS #1184

Closed BlackGoku36 closed 4 years ago

BlackGoku36 commented 4 years ago

When drawing on rendertarget in Krom, multiple pixels can be drawn. But on HTML5 rendertarget seems to get 'cleared' after drawing a single pixel.

Sample code:

Main.hx
```hx package; import kha.Image; import kha.input.Mouse; import kha.Assets; import kha.Color; import kha.Framebuffer; import kha.Scheduler; import kha.System; class Main { static var mouse: std.Mouse; static var img: kha.Image; static function update(): Void { img.g1.begin(); if(mouse.started(0)){ for(x in 0...100){ for (y in 0...100){ img.g1.setPixel(Std.int(mouse.x+y), Std.int(mouse.y+x), kha.Color.Red); } } } img.g1.end(); } static function render(frames: Array): Void { final fb = frames[0]; final g2 = fb.g2; g2.begin(); g2.drawImage(img, 0, 0); g2.end(); } public static function main() { System.start({title: "Project", width: 1024, height: 768}, function (_) { Assets.loadEverything(function () { mouse = new std.Mouse(); img = Image.createRenderTarget(1024, 768); Scheduler.addTimeTask(function () { update(); mouse.endFrame(); }, 0, 1 / 60); System.notifyOnFrames(function (frames) { render(frames); }); }); }); } } ```
Mouse.hx
```hx class Mouse { var buttons = ['left', 'right', 'middle']; var buttonDown = new Map(); var buttonStarted = new Map(); var buttonReleased = new Map(); public var x(default, null) = 0.0; public var y(default, null) = 0.0; public var moved(default, null) = false; public var movementX(default, null) = 0.0; public var movementY(default, null) = 0.0; public var wheelDelta(default, null) = 0; public var lastX = -1.0; public var lastY = -1.0; public function new() { reset(); kha.input.Mouse.get().notify(downListener, upListener, moveListner, wheelListener); } public function endFrame() { buttonStarted.set("left", false); buttonStarted.set("right", false); buttonStarted.set("middle", false); buttonReleased.set("left", false); buttonReleased.set("right", false); buttonReleased.set("middle", false); moved = false; movementX = 0; movementY = 0; wheelDelta = 0; } public function reset() { buttonDown.set("left", false); buttonDown.set("right", false); buttonDown.set("middle", false); endFrame(); } public function down(button: Int = 0){ return buttonDown.get(buttonCode(button)); } public function started(button: Int = 0){ return buttonStarted.get(buttonCode(button)); } public function released(button: Int = 0){ return buttonReleased.get(buttonCode(button)); } function buttonCode(button: Int): String{ switch(button){ case 0: return "left"; case 1: return "right"; case _: return "middle"; } } function downListener(button:Int, x: Int, y:Int):Void { var b = buttonCode(button); buttonDown.set(b, true); buttonStarted.set(b, true); this.x = x; this.y = y; } function upListener(button: Int, x: Int, y: Int):Void{ var b = buttonCode(button); buttonDown.set(b, false); buttonReleased.set(b, true); this.x = x; this.y = y; } function moveListner(x: Int, y: Int, movementX: Int, movementY: Int): Void{ if (lastX == -1.0 && lastY == -1.0){ lastX = x; lastY = y; } this.movementX += x-lastX; this.movementY += y-lastY; lastX = x; lastY = y; this.x = x; this.y = y; moved = true; } function wheelListener(delta: Int){ wheelDelta = delta; } } ```
RobDangerous commented 4 years ago

Clarified that with Goku, it's not about single pixels at all, this is just about the rendertarget being cleared in a begin call. Lots of pixels are drawn.