Skip to content

Commit

Permalink
Enable WebGL by default!
Browse files Browse the repository at this point in the history
With canvas fallback of course.

Closes #8.
  • Loading branch information
aduros committed Jun 12, 2013
1 parent 96149ea commit 4677950
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/flambe/platform/Renderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ interface Renderer
* Notifies the renderer that drawing the frame is complete.
*/
function didRender () :Void;

/**
* Get the name of the renderer, for debug logging.
*/
function getName () :String;
}
4 changes: 2 additions & 2 deletions src/flambe/platform/flash/FlashPlatform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class FlashPlatform

public function init ()
{
Log.info("Initializing Flash platform");

var stage = Lib.current.stage;

_stage = new FlashStage(stage);
Expand Down Expand Up @@ -84,6 +82,8 @@ class FlashPlatform
_lastUpdate = Lib.getTimer();
_skipFrame = false;
_timeOffset = Date.now().getTime() - Lib.getTimer();

Log.info("Initialized Flash platform", ["renderer", _renderer.getName()]);
}

public function loadAssetPack (manifest :Manifest) :Promise<AssetPack>
Expand Down
5 changes: 5 additions & 0 deletions src/flambe/platform/flash/Stage3DRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ class Stage3DRenderer
#end
}

public function getName () :String
{
return "Stage3D";
}

private function onContext3DCreate (event :Event)
{
var stage3D :Stage3D = event.target;
Expand Down
5 changes: 5 additions & 0 deletions src/flambe/platform/html/CanvasRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class CanvasRenderer
{
}

public function getName () :String
{
return "Canvas";
}

/** If true, blit loaded images to a canvas and use that as the texture. */
private static var CANVAS_TEXTURES :Bool = (function () {
// On iOS, canvas textures are way faster
Expand Down
8 changes: 3 additions & 5 deletions src/flambe/platform/html/HtmlPlatform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class HtmlPlatform

public function init ()
{
Log.info("Initializing HTML platform");

var canvas :CanvasElement = null;
try {
// Use the canvas assigned to us by the flambe.js embedder
Expand Down Expand Up @@ -243,6 +241,8 @@ class HtmlPlatform
update(HtmlUtil.now());
}, 16); // ~60 FPS
}

Log.info("Initialized HTML platform", ["renderer", _renderer.getName()]);
}

public function loadAssetPack (manifest :Manifest) :Promise<AssetPack>
Expand Down Expand Up @@ -391,13 +391,11 @@ class HtmlPlatform

private function createRenderer (canvas :CanvasElement) :Renderer
{
#if flambe_enable_webgl
var gl = canvas.getContextWebGL({alpha: false, depth: false});
if (gl != null) {
return new WebGLRenderer(_stage, gl);
}
Log.info("WebGL not available, falling back to canvas");
#end
// No WebGL, fall back to canvas
return new CanvasRenderer(canvas);
}

Expand Down
7 changes: 5 additions & 2 deletions src/flambe/platform/html/WebGLRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class WebGLRenderer

public function new (stage :HtmlStage, gl :RenderingContext)
{
Log.info("Using experimental WebGL renderer", ["version", gl.getParameter(GL.VERSION)]);

this.gl = gl;

// Handle GL context loss
Expand Down Expand Up @@ -86,6 +84,11 @@ class WebGLRenderer
batcher.didRender();
}

public function getName () :String
{
return "WebGL";
}

private function onResize ()
{
var width = gl.canvas.width;
Expand Down

0 comments on commit 4677950

Please sign in to comment.