console: added texture support and others
Misc. changes to support OpenFL's BunnyMark.
This commit is contained in:
@@ -10,7 +10,10 @@ import lime.ConsoleIncludePaths;
|
||||
import lime.graphics.console.Shader;
|
||||
import lime.graphics.console.Primitive;
|
||||
import lime.graphics.console.IndexBuffer;
|
||||
import lime.graphics.console.Texture;
|
||||
import lime.graphics.console.TextureFormat;
|
||||
import lime.graphics.console.VertexBuffer;
|
||||
import lime.graphics.console.VertexDecl;
|
||||
import lime.math.Matrix4;
|
||||
import lime.utils.Float32Array;
|
||||
|
||||
@@ -30,19 +33,27 @@ extern class ConsoleRenderContext {
|
||||
|
||||
public function createIndexBuffer (indices:Pointer<UInt16>, count:Int):IndexBuffer;
|
||||
public function createVertexBuffer (decl:VertexDecl, count:Int):VertexBuffer;
|
||||
public function createTexture (format:TextureFormat, width:Int, height:Int, data:Pointer<UInt8>):Texture;
|
||||
|
||||
public function destroyIndexBuffer (ib:IndexBuffer):Void;
|
||||
public function destroyVertexBuffer (vb:VertexBuffer):Void;
|
||||
public function destroyTexture (tex:Texture):Void;
|
||||
|
||||
public function lookupShader (name:String):Shader;
|
||||
|
||||
public function clear (r:UInt8, g:UInt8, b:UInt8, a:UInt8, depth:Float32 = 1.0, stencil:UInt8 = 0):Void;
|
||||
|
||||
public function bindShader (shader:Shader):Void;
|
||||
|
||||
//public function setViewport (x:UInt16, y:UInt16, width:UInt16, height:UInt16, nearPlane:Float32 = 0.0, farPlane:Float32 = 1.0):Void;
|
||||
public function setViewport (x:UInt16, y:UInt16, width:UInt16, height:UInt16, nearPlane:Float32 = 0.0, farPlane:Float32 = 1.0):Void;
|
||||
|
||||
public function setVertexShaderConstantF (startRegister:Int, vec4:Pointer<Float32>, vec4count:Int):Void;
|
||||
|
||||
public function setVertexSource (vb:VertexBuffer):Void;
|
||||
public function setIndexSource (ib:IndexBuffer):Void;
|
||||
|
||||
public function setTexture (sampler:Int, texture:Texture):Void;
|
||||
|
||||
public function draw (primitive:Primitive, startVertex:UInt32, primitiveCount:UInt32):Void;
|
||||
public function drawIndexed (primitive:Primitive, vertexCount:UInt32, startIndex:UInt32, primitiveCount:UInt32):Void;
|
||||
|
||||
@@ -88,6 +99,47 @@ class ConsoleRenderContext {
|
||||
}
|
||||
|
||||
|
||||
public function createTexture (format:TextureFormat, width:Int, height:Int, data:Pointer<UInt8>):Texture {
|
||||
|
||||
return untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->createTexture ({0}, {1}, {2}, {3})",
|
||||
format, width, height, data
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function destroyIndexBuffer (ib:IndexBuffer):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->destroyIndexBuffer ({0})",
|
||||
ib
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function destroyVertexBuffer (vb:VertexBuffer):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->destroyVertexBuffer ({0})",
|
||||
vb
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function destroyTexture (tex:Texture):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->destroyTexture ({0})",
|
||||
tex
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function lookupShader (name:String):Shader {
|
||||
|
||||
return untyped __cpp__ (
|
||||
@@ -118,6 +170,16 @@ class ConsoleRenderContext {
|
||||
}
|
||||
|
||||
|
||||
public function setViewport (x:UInt16, y:UInt16, width:UInt16, height:UInt16, nearPlane:Float32 = 0.0, farPlane:Float32 = 1.0):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->setViewport ({0}, {1}, {2}, {3}, {4}, {5})",
|
||||
x, y, width, height, nearPlane, farPlane
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public inline function setVertexShaderConstantF (startRegister:Int, vec4:cpp.Pointer<Float32>, vec4count:Int):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
@@ -130,18 +192,6 @@ class ConsoleRenderContext {
|
||||
}
|
||||
|
||||
|
||||
public inline function setVertexShaderConstantMatrix (startRegister:Int, matrix:Matrix4):Void {
|
||||
|
||||
var array:Float32Array = matrix;
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->setVertexShaderConstantF ({0}, (float *){1}, 4)",
|
||||
startRegister,
|
||||
Pointer.arrayElem (array.buffer.getData (), 0).raw
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public inline function setVertexSource (vb:VertexBuffer):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
@@ -162,6 +212,26 @@ class ConsoleRenderContext {
|
||||
}
|
||||
|
||||
|
||||
public inline function setTexture (sampler:Int, texture:Texture):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->setTexture ({0}, {1})",
|
||||
sampler, texture
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public inline function draw (primitive:Primitive, startVertex:UInt32, primitiveCount:UInt32):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::hxapi::ConsoleRenderContext()->draw ({0}, {1}, {2})",
|
||||
primitive, startVertex, primitiveCount
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public inline function drawIndexed (primitive:Primitive, vertexCount:UInt32, startIndex:UInt32, primitiveCount:UInt32):Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
@@ -195,6 +265,12 @@ class ConsoleRenderContext {
|
||||
#else
|
||||
|
||||
|
||||
import lime.graphics.console.Shader;
|
||||
import lime.graphics.console.Primitive;
|
||||
import lime.graphics.console.IndexBuffer;
|
||||
import lime.graphics.console.VertexBuffer;
|
||||
|
||||
|
||||
class ConsoleRenderContext {
|
||||
|
||||
|
||||
@@ -205,7 +281,29 @@ class ConsoleRenderContext {
|
||||
}
|
||||
|
||||
|
||||
public function clear (a:Int, r:Int, g:Int, b:Int, depth:Float = 1.0, stencil:Int = 0):Void {}
|
||||
public var width (get, never):Int;
|
||||
public var height (get, never):Int;
|
||||
|
||||
public function createIndexBuffer (indices, count:Int):IndexBuffer { return new IndexBuffer (); }
|
||||
public function createVertexBuffer (decl, count:Int):VertexBuffer { return new VertexBuffer (); }
|
||||
public function lookupShader (name:String):Shader { return new Shader (); }
|
||||
|
||||
public function clear (r:Int, g:Int, b:Int, a:Int, depth:Float = 1.0, stencil:Int = 0):Void {}
|
||||
|
||||
public function bindShader (shader:Shader):Void {}
|
||||
|
||||
public function setViewport (x, y, width, height, nearPlane = 0.0, farPlane = 1.0):Void {}
|
||||
|
||||
public function setVertexShaderConstantF (startRegister, vec4, vec4count):Void {}
|
||||
|
||||
public function setVertexSource (vb:VertexBuffer):Void {}
|
||||
public function setIndexSource (ib:IndexBuffer):Void {}
|
||||
|
||||
public function draw (primitive, startVertex, primitiveCount):Void {}
|
||||
public function drawIndexed (primitive, vertexCount, startIndex, primitiveCount):Void {}
|
||||
|
||||
private function get_width ():Int { return 0; }
|
||||
private function get_height ():Int { return 0; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ import sys.io.File;
|
||||
#end
|
||||
#end
|
||||
|
||||
#if lime_console
|
||||
import lime.graphics.console.TextureData;
|
||||
#end
|
||||
|
||||
@:allow(lime.graphics.util.ImageCanvasUtil)
|
||||
@:allow(lime.graphics.util.ImageDataUtil)
|
||||
@:access(lime.app.Application)
|
||||
@@ -811,6 +815,10 @@ class Image {
|
||||
}
|
||||
|
||||
__fromBase64 (__base64Encode (bytes), type, onload);
|
||||
|
||||
#elseif lime_console
|
||||
|
||||
throw "Image.fromBytes not implemented for console target";
|
||||
|
||||
#elseif (cpp || neko || nodejs)
|
||||
|
||||
@@ -878,6 +886,22 @@ class Image {
|
||||
#elseif (cpp || neko || nodejs || java)
|
||||
|
||||
var buffer = null;
|
||||
|
||||
#if lime_console
|
||||
|
||||
var texdata = TextureData.fromFile (path);
|
||||
|
||||
if (texdata.valid) {
|
||||
|
||||
buffer = new ImageBuffer (null, texdata.width, texdata.height);
|
||||
buffer.src = texdata;
|
||||
// TODO(james4k): call texdata.release() in a finalizer or
|
||||
// somewhere.. or don't manage texture resources this way.
|
||||
// we shall see.
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (#if (sys && (!disable_cffi || !format) && !java) true #else false #end && !System.disableCFFI) {
|
||||
|
||||
@@ -893,7 +917,7 @@ class Image {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if format
|
||||
|
||||
else {
|
||||
@@ -930,6 +954,8 @@ class Image {
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
#end
|
||||
|
||||
if (buffer != null) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package lime.graphics.console; #if lime_console
|
||||
|
||||
|
||||
import cpp.Pointer;
|
||||
import cpp.UInt16;
|
||||
import lime.ConsoleIncludePaths;
|
||||
|
||||
|
||||
@@ -8,7 +10,8 @@ import lime.ConsoleIncludePaths;
|
||||
@:native("lime::hxapi::ConsoleIndexBuffer")
|
||||
extern class IndexBuffer {
|
||||
|
||||
|
||||
public function lock ():Pointer<UInt16>;
|
||||
public function unlock ():Void;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,15 +19,9 @@ extern class IndexBuffer {
|
||||
#else
|
||||
|
||||
|
||||
abstract IndexBuffer(Int) {
|
||||
class IndexBuffer {
|
||||
|
||||
|
||||
public function new (indices:Array<Int>):Void {
|
||||
|
||||
this = 0;
|
||||
|
||||
}
|
||||
|
||||
public function new () {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
34
lime/graphics/console/PointerUtil.hx
Normal file
34
lime/graphics/console/PointerUtil.hx
Normal file
@@ -0,0 +1,34 @@
|
||||
package lime.graphics.console; #if lime_console
|
||||
|
||||
|
||||
import cpp.Float32;
|
||||
import cpp.Pointer;
|
||||
import lime.math.Matrix4;
|
||||
import lime.utils.Float32Array;
|
||||
|
||||
|
||||
class PointerUtil {
|
||||
|
||||
public static inline function fromMatrix (m:Matrix4):Pointer<Float32> {
|
||||
|
||||
var array:Float32Array = m;
|
||||
var bytePtr = Pointer.arrayElem (array.buffer.getData (), 0);
|
||||
return untyped __cpp__ ("(float *){0}", bytePtr.raw);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
class PointerUtil {
|
||||
|
||||
public static function fromMatrix (m:Matrix4):Int { return 0; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
#end
|
||||
|
||||
@@ -15,15 +15,9 @@ extern class Shader {
|
||||
#else
|
||||
|
||||
|
||||
abstract Shader(Int) {
|
||||
class Shader {
|
||||
|
||||
|
||||
public function new (name:String):Void {
|
||||
|
||||
this = 0;
|
||||
|
||||
}
|
||||
|
||||
public function new () {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
29
lime/graphics/console/Texture.hx
Normal file
29
lime/graphics/console/Texture.hx
Normal file
@@ -0,0 +1,29 @@
|
||||
package lime.graphics.console; #if lime_console
|
||||
|
||||
|
||||
import lime.ConsoleIncludePaths;
|
||||
|
||||
|
||||
@:include("ConsoleHaxeAPI.h")
|
||||
@:native("lime::hxapi::ConsoleTexture")
|
||||
extern class Texture {
|
||||
|
||||
// valid returns true if this represents a non-zero handle to a texture.
|
||||
public var valid (get, never):Bool;
|
||||
|
||||
private function get_valid ():Bool;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
class Texture {
|
||||
|
||||
public function new () {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#end
|
||||
43
lime/graphics/console/TextureData.hx
Normal file
43
lime/graphics/console/TextureData.hx
Normal file
@@ -0,0 +1,43 @@
|
||||
package lime.graphics.console; #if lime_console
|
||||
|
||||
|
||||
import cpp.Pointer;
|
||||
import cpp.UInt8;
|
||||
import lime.ConsoleIncludePaths;
|
||||
import lime.system.System;
|
||||
import lime.utils.ByteArray;
|
||||
|
||||
|
||||
@:include("ConsoleHaxeAPI.h")
|
||||
@:native("lime::hxapi::ConsoleTextureData")
|
||||
extern class TextureData {
|
||||
|
||||
|
||||
// valid returns true if this represents a non-zero handle to texture data.
|
||||
public var valid (get, never):Bool;
|
||||
|
||||
public var width (get, never):Int;
|
||||
public var height (get, never):Int;
|
||||
|
||||
public var pointer (get, never):Pointer<UInt8>;
|
||||
|
||||
|
||||
// fromFile loads texture data from the named file.
|
||||
@:native("lime::ConsoleTextureData::fromFile")
|
||||
public static function fromFile (name:String):TextureData;
|
||||
|
||||
|
||||
// release releases the texture data.
|
||||
public function release ():Void;
|
||||
|
||||
|
||||
private function get_valid ():Bool;
|
||||
private function get_width ():Int;
|
||||
private function get_height ():Int;
|
||||
private function get_pointer ():Pointer<UInt8>;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#end
|
||||
9
lime/graphics/console/TextureFormat.hx
Normal file
9
lime/graphics/console/TextureFormat.hx
Normal file
@@ -0,0 +1,9 @@
|
||||
package lime.graphics.console;
|
||||
|
||||
|
||||
@:enum abstract TextureFormat(Int) {
|
||||
|
||||
var ARGB = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,10 @@
|
||||
package lime.graphics.console; #if lime_console
|
||||
|
||||
|
||||
import cpp.Float32;
|
||||
import cpp.UInt8;
|
||||
import cpp.RawConstPointer;
|
||||
import haxe.io.Input;
|
||||
import lime.graphics.console.VertexOutput;
|
||||
import lime.ConsoleIncludePaths;
|
||||
|
||||
|
||||
@:enum abstract VertexDecl(Int) {
|
||||
|
||||
var PositionTexcoord = 5; // xyz [3]float32, uv [2]float32
|
||||
var PositionColor = 13; // xyz [3]float32, rgba [4]uint8
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:include("ConsoleHaxeAPI.h")
|
||||
@:native("lime::hxapi::ConsoleVertexOutput")
|
||||
extern class VertexOutput {
|
||||
|
||||
public function vec2 (x:Float32, y:Float32):Void;
|
||||
public function vec3 (x:Float32, y:Float32, z:Float32):Void;
|
||||
public function color (r:UInt8, g:UInt8, b:UInt8, a:UInt8):Void;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:include("ConsoleHaxeAPI.h")
|
||||
@:native("lime::hxapi::ConsoleVertexBuffer")
|
||||
extern class VertexBuffer {
|
||||
@@ -35,70 +13,21 @@ extern class VertexBuffer {
|
||||
public function unlock ():Void;
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
// TODO(james4k): use abstract type instead when @:headerCode is supported
|
||||
//@:unreflective
|
||||
@:headerCode("#include <ConsoleVertexBuffer.h>")
|
||||
class VertexBuffer {
|
||||
|
||||
|
||||
private var ptr:RawConstPointer<UInt8>;
|
||||
|
||||
|
||||
public function new (decl:VertexDecl, count:Int):Void {
|
||||
|
||||
this.ptr = untyped __cpp__ (
|
||||
"(uint8_t *)lime::console_vertexbuffer::New ({0}, {1})",
|
||||
decl,
|
||||
count
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function lock ():VertexOutput {
|
||||
|
||||
untyped __cpp__ (
|
||||
"uint8_t *dest = (uint8_t *)lime::console_vertexbuffer::Lock ((void *){0})",
|
||||
ptr
|
||||
);
|
||||
|
||||
// TODO(james4k): VertexOutput output should do bounds checking
|
||||
return untyped __cpp__ (
|
||||
"ConsoleVertexOutput (dest)",
|
||||
ptr
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function unlock ():Void {
|
||||
|
||||
untyped __cpp__ (
|
||||
"lime::console_vertexbuffer::Unlock ((void *){0})",
|
||||
ptr
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
abstract VertexBuffer(Int) {
|
||||
|
||||
|
||||
public function new ():Void {
|
||||
|
||||
this = 0;
|
||||
|
||||
}
|
||||
import lime.graphics.console.VertexOutput;
|
||||
|
||||
|
||||
class VertexBuffer {
|
||||
|
||||
public function new () {}
|
||||
|
||||
public function lock ():VertexOutput { return new VertexOutput (); }
|
||||
public function unlock ():Void {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
lime/graphics/console/VertexDecl.hx
Normal file
12
lime/graphics/console/VertexDecl.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package lime.graphics.console;
|
||||
|
||||
|
||||
@:enum abstract VertexDecl(Int) {
|
||||
|
||||
var Position = 0; // xyz [3]f32
|
||||
var PositionTexcoord = 5; // xyz [3]f32, uv [2]f32
|
||||
var PositionColor = 13; // xyz [3]f32, rgba [4]u8
|
||||
var PositionTexcoordColor = 4; // xyz [3]f32, uv [2]f32, rgba [4]u8
|
||||
|
||||
}
|
||||
|
||||
35
lime/graphics/console/VertexOutput.hx
Normal file
35
lime/graphics/console/VertexOutput.hx
Normal file
@@ -0,0 +1,35 @@
|
||||
package lime.graphics.console; #if lime_console
|
||||
|
||||
|
||||
import cpp.Float32;
|
||||
import cpp.UInt8;
|
||||
import lime.ConsoleIncludePaths;
|
||||
|
||||
|
||||
@:include("ConsoleHaxeAPI.h")
|
||||
@:native("lime::hxapi::ConsoleVertexOutput")
|
||||
extern class VertexOutput {
|
||||
|
||||
public function vec2 (x:Float32, y:Float32):Void;
|
||||
public function vec3 (x:Float32, y:Float32, z:Float32):Void;
|
||||
public function color (r:UInt8, g:UInt8, b:UInt8, a:UInt8):Void;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
class VertexOutput {
|
||||
|
||||
public function new () {}
|
||||
|
||||
public function vec2 (x, y):Void {}
|
||||
public function vec3 (x, y, z):Void {}
|
||||
public function color (r, g, b, a):Void {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#end
|
||||
|
||||
Reference in New Issue
Block a user