Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Texture; add load_from_bytearray, and remove unnecessary width/height…
Browse files Browse the repository at this point in the history
… params from load_from_resource and load_from_bytearray
  • Loading branch information
ruby0x1 committed Oct 13, 2014
1 parent fed5325 commit a4c2241
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
4 changes: 2 additions & 2 deletions luxe/debug/Inspector.hx
Expand Up @@ -41,8 +41,8 @@ typedef DebugInspectorOptions = {
pos = new Vector((Luxe.screen.w/2) - (size.x/2), (Luxe.screen.h/2) - (size.y/2));

//load the images
uitexture = Texture.load_from_resource('tiny.ui.png', 128, 128);
uibutton = Texture.load_from_resource('tiny.button.png', 32, 16);
uitexture = Texture.load_from_resource('tiny.ui.png');
uibutton = Texture.load_from_resource('tiny.button.png');

//default to the internal batcher
_batcher = Luxe.renderer.batcher;
Expand Down
2 changes: 1 addition & 1 deletion phoenix/Renderer.hx
Expand Up @@ -324,7 +324,7 @@ function get_target() : RenderTexture {
font = new BitmapFont( resource_manager );

//create the font texture
var _font_texture = Texture.load_from_resource('cabin.png', 512, 256);
var _font_texture = Texture.load_from_resource('cabin.png');
_font_texture.filter_min = FilterType.linear;

//load the font string data
Expand Down
59 changes: 21 additions & 38 deletions phoenix/Texture.hx
Expand Up @@ -2,6 +2,7 @@ package phoenix;

import snow.assets.AssetImage;
import snow.render.opengl.GL;
import snow.utils.ByteArray;
import snow.utils.UInt8Array;
import snow.utils.Libs;
import snow.utils.ArrayBuffer;
Expand Down Expand Up @@ -107,38 +108,6 @@ class Texture extends Resource {

} //estimated_memory

public function create_from_bytes_html(_asset_name:String, _asset_bytes, _width, _height ) {

var max_size = GL.getParameter(GL.MAX_TEXTURE_SIZE);

texture = GL.createTexture();

//if no problems
id = _asset_name;
width = Std.int(_width);
height = Std.int(_height);

width_actual = width;
height_actual = height;

if(_width > max_size) throw "texture bigger than MAX_TEXTURE_SIZE (" + max_size + ") " + _asset_name;
if(_height > max_size) throw "texture bigger than MAX_TEXTURE_SIZE (" + max_size + ") " + _asset_name;

//Now we can bind it
bind();

//And send GL the data
GL.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, width, height, 0, GL.RGBA, GL.UNSIGNED_BYTE, cast _asset_bytes );

//Set the properties
_set_filter( FilterType.linear );
_set_clamp( ClampType.edge );

// image_bytes = null;
// data = null; //:todo : - sven use lock/unlock

} //create_from_bytes_html

public static function load( _id:String, ?_onloaded:Texture->Void, ?_silent:Bool=false ) {

//:todo:which resources
Expand Down Expand Up @@ -203,25 +172,39 @@ class Texture extends Resource {
} //load


public static function load_from_resource( _name:String, _width:Int, _height:Int, ?_cache:Bool = true ) {
public static function load_from_resource( _name:String, ?_cache:Bool = true ) {

var texture_bytes : haxe.io.Bytes = haxe.Resource.getBytes(_name);

if(texture_bytes != null) {

var texture = load_from_bytearray( _name, ByteArray.fromBytes(texture_bytes), _cache );

texture_bytes = null;

return texture;

} //texture_bytes != null

return null;

} //load_texture_from_resource_bytes


public static function load_from_bytearray( _name:String, _bytes:ByteArray, ?_cache:Bool = true ) {

if(_bytes != null) {

//:todo: which resource manager...
var resources = Luxe.renderer.resource_manager;
var texture = new Texture(resources);

var _asset = Luxe.core.app.assets.image(_name, {
bytes:snow.utils.ByteArray.fromBytes(texture_bytes)
});
var _asset = Luxe.core.app.assets.image(_name, { bytes:_bytes });

if(_asset != null) {

texture.from_asset(_asset);

texture_bytes = null;
texture.reset();
texture.do_onload();

Expand All @@ -237,7 +220,7 @@ class Texture extends Resource {

return null;

} //load_texture_from_resource_bytes
} //load_from_bytearray

function check_size() {

Expand Down

0 comments on commit a4c2241

Please sign in to comment.