فهرست منبع

Merge branch 'master' of https://github.com/okamstudio/godot into add_sprintf

Bil Bas (Spooner) 10 سال پیش
والد
کامیت
2c1a3dfed6
100فایلهای تغییر یافته به همراه1971 افزوده شده و 7678 حذف شده
  1. 1 0
      .gitignore
  2. 4 0
      SConstruct
  3. 1 1
      core/bind/core_bind.cpp
  4. 1 1
      core/color.cpp
  5. 1 1
      core/int_types.h
  6. 9 2
      core/object_type_db.cpp
  7. 2 0
      core/os/input.cpp
  8. 24 0
      core/variant_op.cpp
  9. BIN
      demos/2d/kinematic_char/colworld.scn
  10. 3 2
      demos/2d/kinematic_char/player.gd
  11. BIN
      demos/2d/kinematic_char/player.scn
  12. 35 17
      demos/2d/platformer/stage.xml
  13. 4 0
      demos/2d/polygon_path_finder_demo/.fscache
  14. 5 0
      demos/2d/polygon_path_finder_demo/engine.cfg
  15. BIN
      demos/2d/polygon_path_finder_demo/icon.png
  16. 1 0
      demos/2d/polygon_path_finder_demo/icon.png.flags
  17. BIN
      demos/2d/polygon_path_finder_demo/new_scene_poly_with_holes.scn
  18. 80 0
      demos/2d/polygon_path_finder_demo/polygonpathfinder.gd
  19. 1 1
      drivers/gl_context/context_gl.cpp
  20. 1 1
      drivers/gl_context/context_gl.h
  21. 0 5
      drivers/gles1/SCsub
  22. 0 5986
      drivers/gles1/rasterizer_gles1.cpp
  23. 0 1256
      drivers/gles1/rasterizer_gles1.h
  24. 471 37
      drivers/gles2/rasterizer_gles2.cpp
  25. 17 2
      drivers/gles2/rasterizer_gles2.h
  26. 104 5
      drivers/gles2/shader_compiler_gles2.cpp
  27. 10 1
      drivers/gles2/shader_compiler_gles2.h
  28. 140 5
      drivers/gles2/shaders/canvas.glsl
  29. 1 0
      drivers/gles2/shaders/material.glsl
  30. 2 2
      drivers/png/resource_saver_png.cpp
  31. 1 1
      drivers/theoraplayer/SCsub
  32. 36 0
      methods.py
  33. 53 69
      modules/gdscript/gd_compiler.h
  34. 1 1
      modules/gdscript/gd_editor.cpp
  35. 3 3
      platform/android/detect.py
  36. 1 1
      platform/android/globals/global_defaults.cpp
  37. 2 4
      platform/android/java_glue.cpp
  38. 5 5
      platform/android/os_android.cpp
  39. 0 2
      platform/iphone/SCsub
  40. 1 2
      platform/iphone/detect.py
  41. 0 4
      platform/iphone/gl_view.mm
  42. 2 6
      platform/iphone/os_iphone.cpp
  43. 1 1
      platform/iphone/platform_config.h
  44. 0 2
      platform/isim/SCsub
  45. 1 1
      platform/nacl/os_nacl.cpp
  46. 4 1
      platform/osx/detect.py
  47. 2 0
      platform/osx/os_osx.h
  48. 94 0
      platform/osx/os_osx.mm
  49. 3 0
      platform/server/detect.py
  50. 2 2
      platform/windows/detect.py
  51. 10 3
      platform/windows/os_windows.cpp
  52. 1 1
      platform/windows/platform_config.h
  53. 12 7
      platform/x11/detect.py
  54. 1 1
      platform/x11/export/export.cpp
  55. 4 5
      platform/x11/os_x11.cpp
  56. 1 1
      platform/x11/platform_config.h
  57. 101 2
      scene/2d/canvas_item.cpp
  58. 17 2
      scene/2d/canvas_item.h
  59. 40 2
      scene/2d/node_2d.cpp
  60. 7 0
      scene/2d/node_2d.h
  61. 36 1
      scene/2d/physics_body_2d.cpp
  62. 8 0
      scene/2d/physics_body_2d.h
  63. 1 0
      scene/3d/physics_body.cpp
  64. 2 0
      scene/3d/physics_body.h
  65. 103 8
      scene/animation/tween.cpp
  66. 11 3
      scene/animation/tween.h
  67. 9 2
      scene/gui/file_dialog.cpp
  68. 73 4
      scene/gui/graph_edit.cpp
  69. 8 1
      scene/gui/graph_edit.h
  70. 27 4
      scene/gui/graph_node.cpp
  71. 1 0
      scene/gui/grid_container.cpp
  72. 1 1
      scene/gui/text_edit.cpp
  73. 4 0
      scene/gui/tree.cpp
  74. 6 5
      scene/register_scene_types.cpp
  75. 2 16
      scene/resources/curve.cpp
  76. BIN
      scene/resources/default_theme/arrow_down.png
  77. BIN
      scene/resources/default_theme/arrow_right.png
  78. BIN
      scene/resources/default_theme/button_disabled.png
  79. BIN
      scene/resources/default_theme/button_hover.png
  80. BIN
      scene/resources/default_theme/button_normal.png
  81. BIN
      scene/resources/default_theme/button_pressed.png
  82. BIN
      scene/resources/default_theme/checked.png
  83. BIN
      scene/resources/default_theme/close_hl.png
  84. 355 179
      scene/resources/default_theme/default_theme.cpp
  85. BIN
      scene/resources/default_theme/dropdown.png
  86. BIN
      scene/resources/default_theme/focus.png
  87. BIN
      scene/resources/default_theme/full_panel_bg.png
  88. BIN
      scene/resources/default_theme/hscroll_bg.png
  89. BIN
      scene/resources/default_theme/hscroll_bg_focus.png
  90. BIN
      scene/resources/default_theme/hscroll_grabber.png
  91. BIN
      scene/resources/default_theme/hscroll_grabber_hl.png
  92. BIN
      scene/resources/default_theme/hslider_bg.png
  93. BIN
      scene/resources/default_theme/hslider_grabber.png
  94. BIN
      scene/resources/default_theme/hslider_grabber_hl.png
  95. BIN
      scene/resources/default_theme/hslider_tick.png
  96. BIN
      scene/resources/default_theme/hsplit_bg.png
  97. BIN
      scene/resources/default_theme/hsplitter.png
  98. BIN
      scene/resources/default_theme/icon_folder.png
  99. BIN
      scene/resources/default_theme/icon_play.png
  100. BIN
      scene/resources/default_theme/icon_stop.png

+ 1 - 0
.gitignore

@@ -259,3 +259,4 @@ Desktop.ini
 # Recycle Bin used on file shares
 $RECYCLE.BIN/
 logo.h
+*.autosave

+ 4 - 0
SConstruct

@@ -116,6 +116,7 @@ opts.Add("CFLAGS", "Custom flags for the C compiler");
 opts.Add("LINKFLAGS", "Custom flags for the linker");
 opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no")
 opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no")
+opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no')
 
 # add platform specific options
 
@@ -299,6 +300,9 @@ if selected_platform in platform_list:
 	if (env['xml']=='yes'):
 		env.Append(CPPFLAGS=['-DXML_ENABLED'])
 
+	if (env['colored']=='yes'):
+		methods.colored(sys,env)
+		
 
 	Export('env')
 

+ 1 - 1
core/bind/core_bind.cpp

@@ -642,7 +642,7 @@ void _OS::_bind_methods() {
 
 	ObjectTypeDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
 
-
+	ObjectTypeDB::bind_method(_MD("set_window_title","title"),&_OS::set_window_title);
 
 	ObjectTypeDB::bind_method(_MD("set_low_processor_usage_mode","enable"),&_OS::set_low_processor_usage_mode);
 	ObjectTypeDB::bind_method(_MD("is_in_low_processor_usage_mode"),&_OS::is_in_low_processor_usage_mode);

+ 1 - 1
core/color.cpp

@@ -225,7 +225,7 @@ Color Color::inverted() const {
 Color Color::contrasted() const {
 
 	Color c=*this;
-	c.contrasted();
+	c.contrast();
 	return c;
 }
 

+ 1 - 1
core/int_types.h

@@ -48,7 +48,7 @@ typedef signed short    int16_t;
 typedef unsigned int    uint32_t;
 typedef signed int      int32_t;
 typedef long long	int64_t;
-typedef unsigned long long int64_t;
+typedef unsigned long long uint64_t;
 #else
 #include <stdint.h>
 #endif

+ 9 - 2
core/object_type_db.cpp

@@ -847,8 +847,15 @@ void ObjectTypeDB::set_type_enabled(StringName p_type,bool p_enable) {
 
 bool ObjectTypeDB::is_type_enabled(StringName p_type) {
 
-	ERR_FAIL_COND_V(!types.has(p_type),false);
-	return !types[p_type].disabled;
+	TypeInfo *ti=types.getptr(p_type);
+	if (!ti || !ti->creation_func) {
+		if (compat_types.has(p_type)) {
+			ti=types.getptr(compat_types[p_type]);
+		}
+	}
+
+	ERR_FAIL_COND_V(!ti,false);
+	return !ti->disabled;
 }
 
 StringName ObjectTypeDB::get_category(const StringName& p_node) {

+ 2 - 0
core/os/input.cpp

@@ -62,6 +62,8 @@ void Input::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("set_mouse_mode","mode"),&Input::set_mouse_mode);
 	ObjectTypeDB::bind_method(_MD("get_mouse_mode"),&Input::get_mouse_mode);
 	ObjectTypeDB::bind_method(_MD("warp_mouse_pos","to"),&Input::warp_mouse_pos);
+	ObjectTypeDB::bind_method(_MD("action_press"),&Input::action_press);
+	ObjectTypeDB::bind_method(_MD("action_release"),&Input::action_release);
 
 	BIND_CONSTANT( MOUSE_MODE_VISIBLE );
 	BIND_CONSTANT( MOUSE_MODE_HIDDEN );

+ 24 - 0
core/variant_op.cpp

@@ -1701,6 +1701,19 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
 					return;
 				}
 			}
+			if (ie.type == InputEvent::ACTION) {
+
+				if (str =="action") {
+					valid=true;
+					ie.action.action=p_value;
+					return;
+				}
+				else if (str == "pressed") {
+					valid=true;
+					ie.action.pressed=p_value;
+					return;
+				}
+			}
 
 		} break;
 		case DICTIONARY: {
@@ -2379,6 +2392,17 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
 					return Vector2(ie.screen_drag.speed_x,ie.screen_drag.speed_y);
 				}
 			}
+			if (ie.type == InputEvent::ACTION) {
+
+				if (str =="action") {
+					valid=true;
+					return ie.action.action;
+				}
+				else if (str == "pressed") {
+					valid=true;
+					ie.action.pressed;
+				}
+			}
 
 		} break;
 		case DICTIONARY: {

BIN
demos/2d/kinematic_char/colworld.scn


+ 3 - 2
demos/2d/kinematic_char/player.gd

@@ -15,6 +15,7 @@ const GRAVITY = 500.0
 #consider "floor".
 const FLOOR_ANGLE_TOLERANCE = 40
 const WALK_FORCE = 600
+const WALK_MIN_SPEED=10
 const WALK_MAX_SPEED = 200
 const STOP_FORCE = 1300
 const JUMP_SPEED = 200
@@ -40,12 +41,12 @@ func _fixed_process(delta):
 	var stop=true
 	
 	if (walk_left):
-		if (velocity.x<=0 and velocity.x > -WALK_MAX_SPEED):
+		if (velocity.x<=WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
 			force.x-=WALK_FORCE			
 			stop=false
 		
 	elif (walk_right):
-		if (velocity.x>=0 and velocity.x < WALK_MAX_SPEED):
+		if (velocity.x>=-WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
 			force.x+=WALK_FORCE
 			stop=false
 	

BIN
demos/2d/kinematic_char/player.scn


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 35 - 17
demos/2d/platformer/stage.xml


+ 4 - 0
demos/2d/polygon_path_finder_demo/.fscache

@@ -0,0 +1,4 @@
+::res://::1421147952
+icon.png::ImageTexture::1420046079::
+new_scene_poly_with_holes.scn::PackedScene::1421147952::
+polygonpathfinder.gd::GDScript::1421146502::

+ 5 - 0
demos/2d/polygon_path_finder_demo/engine.cfg

@@ -0,0 +1,5 @@
+[application]
+
+name="polygon_path_finder_demo"
+main_scene="res://new_scene_poly_with_holes.scn"
+icon="icon.png"

BIN
demos/2d/polygon_path_finder_demo/icon.png


+ 1 - 0
demos/2d/polygon_path_finder_demo/icon.png.flags

@@ -0,0 +1 @@
+gen_mipmaps=true

BIN
demos/2d/polygon_path_finder_demo/new_scene_poly_with_holes.scn


+ 80 - 0
demos/2d/polygon_path_finder_demo/polygonpathfinder.gd

@@ -0,0 +1,80 @@
+
+extends Spatial
+
+func _ready():
+	var pf = PolygonPathFinder.new()
+	
+	var points = Vector2Array()
+	var connections = IntArray()
+	
+	# poly 1
+	points.push_back(Vector2(0, 0))		#0
+	points.push_back(Vector2(10, 0))	#1
+	points.push_back(Vector2(10, 10))	#2
+	points.push_back(Vector2(0, 10))	#3
+
+	connections.push_back(0) # connect vertex 0 ...
+	connections.push_back(1) # ... to 1
+	drawLine(points[0], points[1], get_node("/root/Spatial/Polys"))
+	connections.push_back(1) # connect vertex 1 ...
+	connections.push_back(2) # ... to 2
+	drawLine(points[1], points[2], get_node("/root/Spatial/Polys"))
+	connections.push_back(2) # etc.
+	connections.push_back(3)
+	drawLine(points[2], points[3], get_node("/root/Spatial/Polys"))
+	connections.push_back(3) # connect vertex 3 ...
+	connections.push_back(0) # back to vertex 0, to close the polygon
+	drawLine(points[3], points[0], get_node("/root/Spatial/Polys"))
+
+	# poly 2, as obstacle inside poly 1
+	points.push_back(Vector2(2, 0.5))	#4
+	points.push_back(Vector2(4, 0.5))	#5
+	points.push_back(Vector2(4, 9.5))	#6
+	points.push_back(Vector2(2, 9.5))	#7
+
+	connections.push_back(4)
+	connections.push_back(5)
+	drawLine(points[4], points[5], get_node("/root/Spatial/Polys"))
+	connections.push_back(5)
+	connections.push_back(6)
+	drawLine(points[5], points[6], get_node("/root/Spatial/Polys"))
+	connections.push_back(6)
+	connections.push_back(7)
+	drawLine(points[6], points[7], get_node("/root/Spatial/Polys"))
+	connections.push_back(7)
+	connections.push_back(4)
+	drawLine(points[7], points[4], get_node("/root/Spatial/Polys"))
+
+	
+	print("points: ",points)
+	print("connections: ",connections)
+	
+	pf.setup(points, connections)
+	
+	var path = pf.find_path(Vector2(1, 5), Vector2(8, 5))
+	
+	var lastStep = null
+	print("path: ",path)
+	for step in path:
+		print("step: ",step)
+		if (lastStep != null):
+			var currPathSegment = Vector2Array()
+			drawLine(lastStep, step, get_node("/root/Spatial/Path"))
+		lastStep = step
+		
+
+
+func drawLine(pointA, pointB, immediateGeo):
+	var drawPosY = 0.1
+	var im = immediateGeo
+	
+	im.begin(Mesh.PRIMITIVE_POINTS, null)
+	im.add_vertex(Vector3(pointA.x, drawPosY, pointA.y))
+	im.add_vertex(Vector3(pointB.x, drawPosY, pointB.y))
+	im.end()
+	im.begin(Mesh.PRIMITIVE_LINE_STRIP, null)
+	im.add_vertex(Vector3(pointA.x, drawPosY, pointA.y))
+	im.add_vertex(Vector3(pointB.x, drawPosY, pointB.y))
+	im.end()
+	
+	

+ 1 - 1
drivers/gl_context/context_gl.cpp

@@ -12,7 +12,7 @@
 #include "context_gl.h"
 
 
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED) || defined(GLES1_ENABLED)
+#if defined(OPENGL_ENABLED)  || defined(GLES2_ENABLED)
 
 
 

+ 1 - 1
drivers/gl_context/context_gl.h

@@ -29,7 +29,7 @@
 #ifndef CONTEXT_GL_H
 #define CONTEXT_GL_H
 
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED) || defined(GLES1_ENABLED)
+#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)
 
 #include "typedefs.h"
 

+ 0 - 5
drivers/gles1/SCsub

@@ -1,5 +0,0 @@
-Import('env')
-Export('env');
-
-env.add_source_files(env.drivers_sources,"*.cpp")
-

+ 0 - 5986
drivers/gles1/rasterizer_gles1.cpp

@@ -1,5986 +0,0 @@
-/*************************************************************************/
-/*  rasterizer_gles1.cpp                                                 */
-/*************************************************************************/
-/*                       This file is part of:                           */
-/*                           GODOT ENGINE                                */
-/*                    http://www.godotengine.org                         */
-/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                 */
-/*                                                                       */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the       */
-/* "Software"), to deal in the Software without restriction, including   */
-/* without limitation the rights to use, copy, modify, merge, publish,   */
-/* distribute, sublicense, and/or sell copies of the Software, and to    */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions:                                             */
-/*                                                                       */
-/* The above copyright notice and this permission notice shall be        */
-/* included in all copies or substantial portions of the Software.       */
-/*                                                                       */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
-/*************************************************************************/
-#ifdef GLES1_ENABLED
-
-#include "rasterizer_gles1.h"
-#include "os/os.h"
-#include "globals.h"
-#include <stdio.h>
-#include "drivers/gl_context/context_gl.h"
-#include "servers/visual/shader_language.h"
-#include "servers/visual/particle_system_sw.h"
-#include "gl_context/context_gl.h"
-#include <string.h>
-
-_FORCE_INLINE_ static void _gl_load_transform(const Transform& tr) {
-
-	GLfloat matrix[16]={ /* build a 16x16 matrix */
-		tr.basis.elements[0][0],
-		tr.basis.elements[1][0],
-		tr.basis.elements[2][0],
-		0,
-		tr.basis.elements[0][1],
-		tr.basis.elements[1][1],
-		tr.basis.elements[2][1],
-		0,
-		tr.basis.elements[0][2],
-		tr.basis.elements[1][2],
-		tr.basis.elements[2][2],
-		0,
-		tr.origin.x,
-		tr.origin.y,
-		tr.origin.z,
-		1
-	};
-
-	glLoadMatrixf(matrix);
-};
-
-
-_FORCE_INLINE_ static void _gl_mult_transform(const Transform& tr) {
-
-	GLfloat matrix[16]={ /* build a 16x16 matrix */
-		tr.basis.elements[0][0],
-		tr.basis.elements[1][0],
-		tr.basis.elements[2][0],
-		0,
-		tr.basis.elements[0][1],
-		tr.basis.elements[1][1],
-		tr.basis.elements[2][1],
-		0,
-		tr.basis.elements[0][2],
-		tr.basis.elements[1][2],
-		tr.basis.elements[2][2],
-		0,
-		tr.origin.x,
-		tr.origin.y,
-		tr.origin.z,
-		1
-	};
-
-	glMultMatrixf(matrix);
-};
-
-_FORCE_INLINE_ static void _gl_mult_transform(const Matrix32& tr) {
-
-	GLfloat matrix[16]={ /* build a 16x16 matrix */
-		tr.elements[0][0],
-		tr.elements[0][1],
-		0,
-		0,
-		tr.elements[1][0],
-		tr.elements[1][1],
-		0,
-		0,
-		0,
-		0,
-		1,
-		0,
-		tr.elements[2][0],
-		tr.elements[2][1],
-		0,
-		1
-	};
-
-	glMultMatrixf(matrix);
-};
-
-
-RasterizerGLES1::FX::FX() {
-
-	bgcolor_active=false;
-	bgcolor=Color(0,1,0,1);
-
-	skybox_active=false;
-
-	glow_active=false;
-	glow_passes=4;
-	glow_attenuation=0.7;
-	glow_bloom=0.0;
-
-	antialias_active=true;
-	antialias_tolerance=15;
-
-	ssao_active=true;
-	ssao_attenuation=0.7;
-	ssao_radius=0.18;
-	ssao_max_distance=1.0;
-	ssao_range_min=0.25;
-	ssao_range_max=0.48;
-	ssao_only=false;
-
-
-	fog_active=false;
-	fog_near=5;
-	fog_far=100;
-	fog_attenuation=1.0;
-	fog_color_near=Color(1,1,1,1);
-	fog_color_far=Color(1,1,1,1);
-	fog_bg=false;
-
-	toon_active=false;
-	toon_treshold=0.4;
-	toon_soft=0.001;
-
-	edge_active=false;
-	edge_color=Color(0,0,0,1);
-	edge_size=1.0;
-
-}
-
-static const GLenum prim_type[]={GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN};
-
-static void _draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color* p_colors, const Vector3 *p_uvs,const Plane *p_tangents=NULL,int p_instanced=1) {
-
-	ERR_FAIL_COND(!p_vertices);
-	ERR_FAIL_COND(p_points <1 || p_points>4);
-
-	GLenum type = prim_type[p_points - 1];
-
-
-	//if (!p_colors) {
-	//	glColor4f(1, 1, 1, 1);
-	//};
-
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)p_vertices);
-
-	if (p_normals) {
-
-			glEnableClientState(GL_NORMAL_ARRAY);
-			glNormalPointer(GL_FLOAT, 0, (GLvoid*)p_normals);
-	};
-
-	if (p_colors) {
-			glEnableClientState(GL_COLOR_ARRAY);
-			glColorPointer(4,GL_FLOAT, 0, p_colors);
-	};
-
-	if (p_uvs) {
-
-			glClientActiveTexture(GL_TEXTURE0);
-			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-			glTexCoordPointer(3, GL_FLOAT, 0, p_uvs);
-	};
-
-	glDrawArrays( type, 0, p_points);
-
-	glDisableClientState(GL_VERTEX_ARRAY);
-	glDisableClientState(GL_NORMAL_ARRAY);
-	glDisableClientState(GL_COLOR_ARRAY);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-};
-
-/* TEXTURE API */
-#define _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG                   0x8C00
-#define _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG                   0x8C01
-#define _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG                  0x8C02
-#define _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG                  0x8C03
-#define _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
-#define _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
-#define _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
-#define _EXT_COMPRESSED_RED_RGTC1_EXT 0x8DBB
-#define _EXT_COMPRESSED_RED_RGTC1 0x8DBB
-#define _EXT_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC
-#define _EXT_COMPRESSED_RG_RGTC2 0x8DBD
-#define _EXT_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE
-#define _EXT_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
-#define _EXT_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
-#define _EXT_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
-#define _EXT_ETC1_RGB8_OES           0x8D64
-
-/* TEXTURE API */
-
-Image RasterizerGLES1::_get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,int &r_gl_components,bool &r_has_alpha_cache,bool &r_compressed) {
-
-	r_has_alpha_cache=false;
-	r_compressed=false;
-	Image image=p_image;
-
-	switch(p_format) {
-
-		case Image::FORMAT_GRAYSCALE: {
-			r_gl_components=1;
-			r_gl_format=GL_LUMINANCE;
-
-		} break;
-		case Image::FORMAT_INTENSITY: {
-
-			if (!image.empty())
-				image.convert(Image::FORMAT_RGBA);
-			r_gl_components=4;
-			r_gl_format=GL_RGBA;
-			r_has_alpha_cache=true;
-		} break;
-		case Image::FORMAT_GRAYSCALE_ALPHA: {
-
-			//image.convert(Image::FORMAT_RGBA);
-			r_gl_components=2;
-			r_gl_format=GL_LUMINANCE_ALPHA;
-			r_has_alpha_cache=true;
-		} break;
-
-		case Image::FORMAT_INDEXED: {
-
-			if (!image.empty())
-				image.convert(Image::FORMAT_RGB);
-			r_gl_components=3;
-			r_gl_format=GL_RGB;
-
-		} break;
-
-		case Image::FORMAT_INDEXED_ALPHA: {
-
-			if (!image.empty())
-				image.convert(Image::FORMAT_RGBA);
-			r_gl_components=4;
-			r_gl_format=GL_RGBA;
-			r_has_alpha_cache=true;
-
-		} break;
-		case Image::FORMAT_RGB: {
-
-			r_gl_components=3;
-			r_gl_format=GL_RGB;
-		} break;
-		case Image::FORMAT_RGBA: {
-
-			r_gl_components=4;
-			r_gl_format=GL_RGBA;
-			r_has_alpha_cache=true;
-		} break;
-		case Image::FORMAT_BC1: {
-
-			r_gl_components=1; //doesn't matter much
-			r_gl_format=_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
-			r_compressed=true;
-
-		} break;
-		case Image::FORMAT_BC2: {
-			r_gl_components=1; //doesn't matter much
-			r_gl_format=_EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT;
-			r_has_alpha_cache=true;
-			r_compressed=true;
-
-		} break;
-		case Image::FORMAT_BC3: {
-
-			r_gl_components=1; //doesn't matter much
-			r_gl_format=_EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT;
-			r_has_alpha_cache=true;
-			r_compressed=true;
-
-		} break;
-		case Image::FORMAT_BC4: {
-
-			r_gl_format=_EXT_COMPRESSED_RED_RGTC1;
-			r_gl_components=1; //doesn't matter much
-			r_compressed=true;
-
-		} break;
-		case Image::FORMAT_BC5: {
-
-			r_gl_format=_EXT_COMPRESSED_RG_RGTC2;
-			r_gl_components=1; //doesn't matter much
-			r_compressed=true;
-		} break;
-		case Image::FORMAT_PVRTC2: {
-
-			if (!pvr_supported) {
-
-				if (!image.empty())
-					image.decompress();
-				r_gl_components=4;
-				r_gl_format=GL_RGBA;
-				r_has_alpha_cache=true;
-				print_line("Load Compat PVRTC2");
-
-			} else {
-
-				r_gl_format=_EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
-				r_gl_components=1; //doesn't matter much
-				r_compressed=true;
-				print_line("Load Normal PVRTC2");
-			}
-
-		} break;
-		case Image::FORMAT_PVRTC2_ALPHA: {
-
-			if (!pvr_supported) {
-
-				if (!image.empty())
-					image.decompress();
-				r_gl_components=4;
-				r_gl_format=GL_RGBA;
-				r_has_alpha_cache=true;
-				print_line("Load Compat PVRTC2A");
-
-			} else {
-
-				r_gl_format=_EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
-				r_gl_components=1; //doesn't matter much
-				r_compressed=true;
-				print_line("Load Normal PVRTC2A");
-			}
-
-		} break;
-		case Image::FORMAT_PVRTC4: {
-
-			if (!pvr_supported) {
-
-				if (!image.empty())
-					image.decompress();
-				r_gl_components=4;
-				r_gl_format=GL_RGBA;
-				r_has_alpha_cache=true;
-				print_line("Load Compat PVRTC4");
-			} else {
-
-				r_gl_format=_EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
-				r_gl_components=1; //doesn't matter much
-				r_compressed=true;
-				print_line("Load Normal PVRTC4");
-			}
-
-		} break;
-		case Image::FORMAT_PVRTC4_ALPHA: {
-
-			if (!pvr_supported) {
-
-				if (!image.empty())
-					image.decompress();
-				r_gl_components=4;
-				r_gl_format=GL_RGBA;
-				r_has_alpha_cache=true;
-				print_line("Load Compat PVRTC4A");
-
-			} else {
-
-				r_gl_format=_EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
-				r_gl_components=1; //doesn't matter much
-				r_compressed=true;
-				print_line("Load Normal PVRTC4A");
-			}
-
-		} break;
-		case Image::FORMAT_ETC: {
-
-			if (!pvr_supported) {
-
-				if (!image.empty())
-					image.decompress();
-			} else {
-
-				r_gl_format=_EXT_ETC1_RGB8_OES;
-				r_gl_components=1; //doesn't matter much
-				r_compressed=true;
-			}
-
-		} break;
-		case Image::FORMAT_YUV_422:
-		case Image::FORMAT_YUV_444: {
-
-			if (!image.empty())
-				image.convert(Image::FORMAT_RGB);
-			r_gl_format=GL_RGB;
-			r_gl_components=3;
-
-		} break;
-
-		default: {
-
-			ERR_FAIL_V(Image());
-		}
-	}
-
-	return image;
-}
-
-
-RID RasterizerGLES1::texture_create() {
-
-	Texture *texture = memnew(Texture);
-	ERR_FAIL_COND_V(!texture,RID());
-	glGenTextures(1, &texture->tex_id);
-	texture->active=false;
-	texture->total_data_size=0;
-
-	return texture_owner.make_rid( texture );
-
-}
-
-void RasterizerGLES1::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags) {
-
-	bool has_alpha_cache;
-	int components;
-	GLenum format;
-	bool compressed;
-
-	int po2_width =  nearest_power_of_2(p_width);
-	int po2_height =  nearest_power_of_2(p_height);
-
-	Texture *texture = texture_owner.get( p_texture );
-	ERR_FAIL_COND(!texture);
-	texture->width=p_width;
-	texture->height=p_height;
-	texture->format=p_format;
-	texture->flags=p_flags;
-	texture->target = /*(p_flags & VS::TEXTURE_FLAG_CUBEMAP) ? GL_TEXTURE_CUBE_MAP :*/ GL_TEXTURE_2D;
-
-	bool scale_textures = (!npo2_textures_available || p_format&VS::TEXTURE_FLAG_MIPMAPS);
-
-
-	if (scale_textures) {
-		texture->alloc_width = po2_width;
-		texture->alloc_height = po2_height;
-	} else {
-
-		texture->alloc_width = texture->width;
-		texture->alloc_height = texture->height;
-	};
-
-	_get_gl_image_and_format(Image(),texture->format,texture->flags,format,components,has_alpha_cache,compressed);
-
-	texture->gl_components_cache=components;
-	texture->gl_format_cache=format;
-	texture->format_has_alpha=has_alpha_cache;
-	texture->compressed=compressed;
-	texture->data_size=0;
-
-
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(texture->target, texture->tex_id);
-
-
-
-
-	if (compressed) {
-
-		glTexParameteri( texture->target, GL_GENERATE_MIPMAP, GL_FALSE );
-	} else {
-		if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS) {
-			glTexParameteri( texture->target, GL_GENERATE_MIPMAP, GL_TRUE );
-		} else {
-			glTexParameteri( texture->target, GL_GENERATE_MIPMAP, GL_FALSE );
-		}
-
-	}
-
-
-	if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS)
-		glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
-	else
-		glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-	if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
-
-		glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering
-
-	} else {
-
-		glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	// raw Filtering
-
-	}
-	bool force_clamp_to_edge = !(p_flags&VS::TEXTURE_FLAG_MIPMAPS) && (nearest_power_of_2(texture->alloc_height)!=texture->alloc_height || nearest_power_of_2(texture->alloc_width)!=texture->alloc_width);
-
-	if (!force_clamp_to_edge && texture->flags&VS::TEXTURE_FLAG_REPEAT) {
-
-		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
-		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
-	} else {
-
-		//glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
-		glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
-		glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
-	}
-
-	texture->active=true;
-}
-
-void RasterizerGLES1::texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side) {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND(!texture);
-	ERR_FAIL_COND(!texture->active);
-	ERR_FAIL_COND(texture->format != p_image.get_format() );
-
-	int components;
-	GLenum format;
-	bool alpha;
-	bool compressed;
-
-	if (keep_copies && !(texture->flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) && !(use_reload_hooks && texture->reloader)) {
-		texture->image[p_cube_side]=p_image;
-	}
-
-
-	Image img = _get_gl_image_and_format(p_image, p_image.get_format(),texture->flags,format,components,alpha,compressed);
-	if (texture->alloc_width != img.get_width() || texture->alloc_height != img.get_height()) {
-
-		img.resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR);
-	};
-
-
-	GLenum blit_target = /*(texture->target == GL_TEXTURE_CUBE_MAP)?_cube_side_enum[p_cube_side]:*/GL_TEXTURE_2D;
-
-	texture->data_size=img.get_data().size();
-	DVector<uint8_t>::Read read = img.get_data().read();
-
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(texture->target, texture->tex_id);
-
-	int mipmaps=(texture->flags&VS::TEXTURE_FLAG_MIPMAPS && img.get_mipmaps()>0) ? img.get_mipmaps() +1 : 1;
-
-	int w=img.get_width();
-	int h=img.get_height();
-
-	int tsize=0;
-	for(int i=0;i<mipmaps;i++) {
-
-		int size,ofs;
-		img.get_mipmap_offset_and_size(i,ofs,size);
-
-		if (texture->compressed) {
-			glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-			glCompressedTexImage2D( blit_target, i, format,w,h,0,size,&read[ofs] );
-
-		} else {
-			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-//			glTexImage2D(blit_target, i, format==GL_RGB?GL_RGB8:format, w, h, 0, format, GL_UNSIGNED_BYTE,&read[ofs]);
-			glTexImage2D(blit_target, i, format, w, h, 0, format, GL_UNSIGNED_BYTE,&read[ofs]);
-			//glTexSubImage2D( blit_target, i, 0,0,w,h,format,GL_UNSIGNED_BYTE,&read[ofs] );
-		}
-		tsize+=size;
-
-		w = MAX(1,w>>1);
-		h = MAX(1,h>>1);
-
-	}
-
-	_rinfo.texture_mem-=texture->total_data_size;
-	texture->total_data_size=tsize;
-	_rinfo.texture_mem+=texture->total_data_size;
-
-	printf("texture: %i x %i - size: %i - total: %i\n",texture->width,texture->height,tsize,_rinfo.texture_mem);
-
-
-	if (mipmaps==1 && texture->flags&VS::TEXTURE_FLAG_MIPMAPS) {
-		glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
-
-	} else {
-		glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE );
-
-	}
-
-	if (mipmaps>1) {
-
-		//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmaps-1 ); - assumed to have all, always
-	}
-
-	//texture_set_flags(p_texture,texture->flags);
-
-
-}
-
-Image RasterizerGLES1::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,Image());
-	ERR_FAIL_COND_V(!texture->active,Image());
-
-	return texture->image[p_cube_side];
-#if 0
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,Image());
-	ERR_FAIL_COND_V(!texture->active,Image());
-	ERR_FAIL_COND_V(texture->data_size==0,Image());
-
-	DVector<uint8_t> data;
-	GLenum format,type=GL_UNSIGNED_BYTE;
-	Image::Format fmt;
-	int pixelsize=0;
-	int pixelshift=0;
-	int minw=1,minh=1;
-	bool compressed=false;
-
-	fmt=texture->format;
-
-	switch(texture->format) {
-
-		case Image::FORMAT_GRAYSCALE: {
-
-			format=GL_LUMINANCE;
-			type=GL_UNSIGNED_BYTE;
-			data.resize(texture->alloc_width*texture->alloc_height);
-			pixelsize=1;
-
-		} break;
-		case Image::FORMAT_INTENSITY: {
-			return Image();
-		} break;
-		case Image::FORMAT_GRAYSCALE_ALPHA: {
-
-			format=GL_LUMINANCE_ALPHA;
-			type=GL_UNSIGNED_BYTE;
-			pixelsize=2;
-
-		} break;
-		case Image::FORMAT_RGB: {
-			format=GL_RGB;
-			type=GL_UNSIGNED_BYTE;
-			pixelsize=3;
-		} break;
-		case Image::FORMAT_RGBA: {
-
-			format=GL_RGBA;
-			type=GL_UNSIGNED_BYTE;
-			pixelsize=4;
-		} break;
-		case Image::FORMAT_INDEXED: {
-
-			format=GL_RGB;
-			type=GL_UNSIGNED_BYTE;
-			fmt=Image::FORMAT_RGB;
-			pixelsize=3;
-		} break;
-		case Image::FORMAT_INDEXED_ALPHA: {
-
-			format=GL_RGBA;
-			type=GL_UNSIGNED_BYTE;
-			fmt=Image::FORMAT_RGBA;
-			pixelsize=4;
-
-		} break;
-		case Image::FORMAT_BC1: {
-
-			pixelsize=1; //doesn't matter much
-			format=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
-			compressed=true;
-			pixelshift=1;
-			minw=minh=4;
-
-		} break;
-		case Image::FORMAT_BC2: {
-			pixelsize=1; //doesn't matter much
-			format=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
-			compressed=true;
-			minw=minh=4;
-
-		} break;
-		case Image::FORMAT_BC3: {
-
-			pixelsize=1; //doesn't matter much
-			format=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
-			compressed=true;
-			minw=minh=4;
-
-		} break;
-		case Image::FORMAT_BC4: {
-
-			format=GL_COMPRESSED_RED_RGTC1;
-			pixelsize=1; //doesn't matter much
-			compressed=true;
-			pixelshift=1;
-			minw=minh=4;
-
-		} break;
-		case Image::FORMAT_BC5: {
-
-			format=GL_COMPRESSED_RG_RGTC2;
-			pixelsize=1; //doesn't matter much
-			compressed=true;
-			minw=minh=4;
-
-		} break;
-
-		default:{}
-	}
-
-	data.resize(texture->data_size);
-	DVector<uint8_t>::Write wb = data.write();
-
-	glActiveTexture(GL_TEXTURE0);
-	int ofs=0;
-	glBindTexture(texture->target,texture->tex_id);
-
-	int w=texture->alloc_width;
-	int h=texture->alloc_height;
-	for(int i=0;i<texture->mipmaps+1;i++) {
-
-		if (compressed) {
-
-			glPixelStorei(GL_PACK_ALIGNMENT, 4);
-			glGetCompressedTexImage(texture->target,i,&wb[ofs]);
-
-		} else {
-			glPixelStorei(GL_PACK_ALIGNMENT, 1);
-			glGetTexImage(texture->target,i,format,type,&wb[ofs]);
-		}
-
-		int size = (w*h*pixelsize)>>pixelshift;
-		ofs+=size;
-
-		w=MAX(minw,w>>1);
-		h=MAX(minh,h>>1);
-
-	}
-
-
-	wb=DVector<uint8_t>::Write();
-
-	Image img(texture->alloc_width,texture->alloc_height,texture->mipmaps,fmt,data);
-
-	if (texture->format<Image::FORMAT_INDEXED && (texture->alloc_width!=texture->width || texture->alloc_height!=texture->height))
-		img.resize(texture->width,texture->height);
-
-	return img;
-#endif
-}
-
-void RasterizerGLES1::texture_set_flags(RID p_texture,uint32_t p_flags) {
-
-	Texture *texture = texture_owner.get( p_texture );
-	ERR_FAIL_COND(!texture);
-
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(texture->target, texture->tex_id);
-	uint32_t cube = texture->flags & VS::TEXTURE_FLAG_CUBEMAP;
-	texture->flags=p_flags|cube; // can't remove a cube from being a cube
-
-	bool force_clamp_to_edge = !(p_flags&VS::TEXTURE_FLAG_MIPMAPS) && (nearest_power_of_2(texture->alloc_height)!=texture->alloc_height || nearest_power_of_2(texture->alloc_width)!=texture->alloc_width);
-
-	if (!force_clamp_to_edge && texture->flags&VS::TEXTURE_FLAG_REPEAT) {
-
-		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
-		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
-	} else {
-		//glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
-		glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
-		glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
-
-	}
-
-
-	if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
-
-		glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering
-		if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS)
-			glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
-		else
-			glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering
-
-	} else {
-
-		glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	// nearest
-	}
-}
-uint32_t RasterizerGLES1::texture_get_flags(RID p_texture) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,0);
-
-	return texture->flags;
-
-}
-Image::Format RasterizerGLES1::texture_get_format(RID p_texture) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,Image::FORMAT_GRAYSCALE);
-
-	return texture->format;
-}
-uint32_t RasterizerGLES1::texture_get_width(RID p_texture) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,0);
-
-	return texture->width;
-}
-uint32_t RasterizerGLES1::texture_get_height(RID p_texture) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,0);
-
-	return texture->height;
-}
-
-bool RasterizerGLES1::texture_has_alpha(RID p_texture) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND_V(!texture,0);
-
-	return false;
-
-}
-
-void RasterizerGLES1::texture_set_size_override(RID p_texture,int p_width, int p_height) {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND(!texture);
-
-	ERR_FAIL_COND(p_width<=0 || p_width>4096);
-	ERR_FAIL_COND(p_height<=0 || p_height>4096);
-	//real texture size is in alloc width and height
-	texture->width=p_width;
-	texture->height=p_height;
-
-}
-
-void RasterizerGLES1::texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const {
-
-	Texture * texture = texture_owner.get(p_texture);
-
-	ERR_FAIL_COND(!texture);
-
-	texture->reloader=p_owner;
-	texture->reloader_func=p_function;
-	if (use_reload_hooks && p_owner && keep_copies) {
-
-		for(int i=0;i<6;i++)
-			texture->image[i]=Image();
-	}
-
-
-}
-
-/* SHADER API */
-
-/* SHADER API */
-
-RID RasterizerGLES1::shader_create(VS::ShaderMode p_mode) {
-
-	Shader *shader = memnew( Shader );
-	shader->mode=p_mode;
-	shader->valid=false;
-	shader->has_alpha=false;
-	shader->fragment_line=0;
-	shader->vertex_line=0;
-	shader->light_line=0;
-	RID rid = shader_owner.make_rid(shader);
-	shader_set_mode(rid,p_mode);
-//	_shader_make_dirty(shader);
-
-	return rid;
-
-}
-
-
-
-void RasterizerGLES1::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
-
-	ERR_FAIL_INDEX(p_mode,3);
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND(!shader);
-//	if (shader->custom_code_id && p_mode==shader->mode)
-//		return;
-
-	shader->mode=p_mode;
-
-}
-VS::ShaderMode RasterizerGLES1::shader_get_mode(RID p_shader) const {
-
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND_V(!shader,VS::SHADER_MATERIAL);
-	return shader->mode;
-}
-
-
-
-void RasterizerGLES1::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs,int p_fragment_ofs,int p_light_ofs) {
-
-
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND(!shader);
-
-#ifdef DEBUG_ENABLED
-	if (shader->vertex_code==p_vertex && shader->fragment_code==p_fragment && shader->light_code==p_light)
-		return;
-#endif
-	shader->fragment_code=p_fragment;
-	shader->vertex_code=p_vertex;
-	shader->light_code=p_light;
-	shader->fragment_line=p_fragment_ofs;
-	shader->vertex_line=p_vertex_ofs;
-	shader->light_line=p_light_ofs;
-
-}
-
-String RasterizerGLES1::shader_get_vertex_code(RID p_shader) const {
-
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND_V(!shader,String());
-	return shader->vertex_code;
-
-}
-
-String RasterizerGLES1::shader_get_fragment_code(RID p_shader) const {
-
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND_V(!shader,String());
-	return shader->fragment_code;
-
-}
-
-String RasterizerGLES1::shader_get_light_code(RID p_shader) const {
-
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND_V(!shader,String());
-	return shader->light_code;
-
-}
-
-void RasterizerGLES1::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
-
-	Shader *shader=shader_owner.get(p_shader);
-	ERR_FAIL_COND(!shader);
-#if 0
-
-	if (shader->dirty_list.in_list())
-		_update_shader(shader); // ok should be not anymore dirty
-
-
-	Map<int,StringName> order;
-
-
-	for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
-
-
-		order[E->get().order]=E->key();
-	}
-
-
-	for(Map<int,StringName>::Element *E=order.front();E;E=E->next()) {
-
-		PropertyInfo pi;
-		ShaderLanguage::Uniform &u=shader->uniforms[E->get()];
-		pi.name=E->get();
-		switch(u.type) {
-
-			case ShaderLanguage::TYPE_VOID:
-			case ShaderLanguage::TYPE_BOOL:
-			case ShaderLanguage::TYPE_FLOAT:
-			case ShaderLanguage::TYPE_VEC2:
-			case ShaderLanguage::TYPE_VEC3:
-			case ShaderLanguage::TYPE_MAT3:
-			case ShaderLanguage::TYPE_MAT4:
-			case ShaderLanguage::TYPE_VEC4:
-				pi.type=u.default_value.get_type();
-				break;
-			case ShaderLanguage::TYPE_TEXTURE:
-				pi.type=Variant::_RID;
-				pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
-				pi.hint_string="Texture";
-				break;
-			case ShaderLanguage::TYPE_CUBEMAP:
-				pi.type=Variant::_RID;
-				pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
-				pi.hint_string="Texture";
-				break;
-		};
-
-		p_param_list->push_back(pi);
-
-	}
-#endif
-
-}
-
-
-void RasterizerGLES1::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
-
-}
-
-RID RasterizerGLES1::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const {
-
-	return RID();
-}
-
-/* COMMON MATERIAL API */
-
-
-RID RasterizerGLES1::material_create() {
-
-	return material_owner.make_rid( memnew( Material ) );
-}
-
-void RasterizerGLES1::material_set_shader(RID p_material, RID p_shader) {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND(!material);
-	material->shader=p_shader;
-
-}
-
-RID RasterizerGLES1::material_get_shader(RID p_material) const {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND_V(!material,RID());
-	return material->shader;
-}
-
-#if 0
-
-void RasterizerGLES1::_material_check_alpha(Material *p_material) {
-
-	p_material->has_alpha=false;
-	Color diffuse=p_material->parameters[VS::FIXED_MATERIAL_PARAM_DIFFUSE];
-	if (diffuse.a<0.98) {
-
-		p_material->has_alpha=true;
-		return;
-	}
-
-	if (p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE].is_valid()) {
-
-		Texture *tex = texture_owner.get(p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE]);
-		if (!tex)
-			return;
-		if (tex->has_alpha) {
-
-			p_material->has_alpha=true;
-			return;
-		}
-	}
-}
-
-#endif
-void RasterizerGLES1::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value) {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND(!material);
-
-	if (p_value.get_type()==Variant::NIL)
-		material->shader_params.erase(p_param);
-	else
-		material->shader_params[p_param]=p_value;
-}
-Variant RasterizerGLES1::material_get_param(RID p_material, const StringName& p_param) const {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND_V(!material,Variant());
-
-	if (material->shader_params.has(p_param))
-		return material->shader_params[p_param];
-	else
-		return Variant();
-}
-
-
-void RasterizerGLES1::material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled) {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND(!material);
-	ERR_FAIL_INDEX(p_flag,VS::MATERIAL_FLAG_MAX);
-	material->flags[p_flag]=p_enabled;
-
-}
-bool RasterizerGLES1::material_get_flag(RID p_material,VS::MaterialFlag p_flag) const {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND_V(!material,false);
-	ERR_FAIL_INDEX_V(p_flag,VS::MATERIAL_FLAG_MAX,false);
-	return material->flags[p_flag];
-
-
-}
-
-void RasterizerGLES1::material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode) {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND(!material);
-	material->depth_draw_mode=p_mode;
-}
-
-VS::MaterialDepthDrawMode RasterizerGLES1::material_get_depth_draw_mode(RID p_material) const{
-
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND_V(!material,VS::MATERIAL_DEPTH_DRAW_ALWAYS);
-	return material->depth_draw_mode;
-}
-
-
-void RasterizerGLES1::material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND(!material);
-	material->blend_mode=p_mode;
-
-}
-VS::MaterialBlendMode RasterizerGLES1::material_get_blend_mode(RID p_material) const {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND_V(!material,VS::MATERIAL_BLEND_MODE_ADD);
-	return material->blend_mode;
-}
-
-void RasterizerGLES1::material_set_line_width(RID p_material,float p_line_width) {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND(!material);
-	material->line_width=p_line_width;
-
-}
-float RasterizerGLES1::material_get_line_width(RID p_material) const {
-
-	Material *material = material_owner.get(p_material);
-	ERR_FAIL_COND_V(!material,0);
-
-	return material->line_width;
-}
-
-/* FIXED MATERIAL */
-
-
-RID RasterizerGLES1::fixed_material_create() {
-
-	return material_create();
-}
-
-void RasterizerGLES1::fixed_material_set_flag(RID p_material, VS::FixedMaterialFlags p_flag, bool p_enabled) {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND(!m);
-	ERR_FAIL_INDEX(p_flag, 3);
-	m->fixed_flags[p_flag]=p_enabled;
-}
-
-bool RasterizerGLES1::fixed_material_get_flag(RID p_material, VS::FixedMaterialFlags p_flag) const {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND_V(!m,false);
-	ERR_FAIL_INDEX_V(p_flag,VS::FIXED_MATERIAL_FLAG_MAX, false);
-	return m->fixed_flags[p_flag];
-}
-
-void RasterizerGLES1::fixed_material_set_parameter(RID p_material, VS::FixedMaterialParam p_parameter, const Variant& p_value) {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND(!m);
-	ERR_FAIL_INDEX(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX);
-
-	m->parameters[p_parameter] = p_value;
-
-}
-
-Variant RasterizerGLES1::fixed_material_get_parameter(RID p_material,VS::FixedMaterialParam p_parameter) const {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND_V(!m, Variant());
-	ERR_FAIL_INDEX_V(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX, Variant());
-
-	return m->parameters[p_parameter];
-}
-
-void RasterizerGLES1::fixed_material_set_texture(RID p_material,VS::FixedMaterialParam p_parameter, RID p_texture) {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND(!m);
-	ERR_FAIL_INDEX(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX);
-
-	m->textures[p_parameter] = p_texture;
-
-}
-RID RasterizerGLES1::fixed_material_get_texture(RID p_material,VS::FixedMaterialParam p_parameter) const {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND_V(!m, RID());
-	ERR_FAIL_INDEX_V(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX, Variant());
-
-	return m->textures[p_parameter];
-}
-
-
-void RasterizerGLES1::fixed_material_set_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter, VS::FixedMaterialTexCoordMode p_mode) {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND(!m);
-	ERR_FAIL_INDEX(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX);
-	ERR_FAIL_INDEX(p_mode,4);
-
-	m->texcoord_mode[p_parameter] = p_mode;
-}
-
-VS::FixedMaterialTexCoordMode RasterizerGLES1::fixed_material_get_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter) const {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND_V(!m, VS::FIXED_MATERIAL_TEXCOORD_UV);
-	ERR_FAIL_INDEX_V(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX, VS::FIXED_MATERIAL_TEXCOORD_UV);
-
-	return m->texcoord_mode[p_parameter]; // for now
-}
-
-void RasterizerGLES1::fixed_material_set_uv_transform(RID p_material,const Transform& p_transform) {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND(!m);
-
-	m->uv_transform = p_transform;
-}
-
-Transform RasterizerGLES1::fixed_material_get_uv_transform(RID p_material) const {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND_V(!m, Transform());
-
-	return m->uv_transform;
-}
-
-void RasterizerGLES1::fixed_material_set_point_size(RID p_material,float p_size) {
-
-	Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND(!m);
-	m->point_size=p_size;
-
-}
-float RasterizerGLES1::fixed_material_get_point_size(RID p_material) const {
-
-	const Material *m=material_owner.get( p_material );
-	ERR_FAIL_COND_V(!m, 0);
-	return m->point_size;
-}
-
-
-/* MESH API */
-
-
-RID RasterizerGLES1::mesh_create() {
-
-
-	return mesh_owner.make_rid( memnew( Mesh ) );
-}
-
-
-
-void RasterizerGLES1::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,bool p_alpha_sort) {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND(!mesh);
-
-	ERR_FAIL_INDEX( p_primitive, VS::PRIMITIVE_MAX );
-	ERR_FAIL_COND(p_arrays.size()!=VS::ARRAY_MAX);
-
-	uint32_t format=0;
-
-	// validation
-	int index_array_len=0;
-	int array_len=0;
-
-	for(int i=0;i<p_arrays.size();i++) {
-
-		if (p_arrays[i].get_type()==Variant::NIL)
-			continue;
-
-		format|=(1<<i);
-
-		if (i==VS::ARRAY_VERTEX) {
-
-			array_len=Vector3Array(p_arrays[i]).size();
-			ERR_FAIL_COND(array_len==0);
-		} else if (i==VS::ARRAY_INDEX) {
-
-			index_array_len=IntArray(p_arrays[i]).size();
-		}
-	}
-
-	ERR_FAIL_COND((format&VS::ARRAY_FORMAT_VERTEX)==0); // mandatory
-
-
-	Surface *surface = memnew( Surface );
-	ERR_FAIL_COND( !surface );
-
-	bool use_VBO=true; //glGenBuffersARB!=NULL; // TODO detect if it's in there
-	if (format&VS::ARRAY_FORMAT_WEIGHTS || mesh->morph_target_count>0) {
-
-		use_VBO=false;
-	}
-
-	surface->packed=pack_arrays && use_VBO;
-
-	int total_elem_size=0;
-
-	for (int i=0;i<VS::ARRAY_MAX;i++) {
-
-
-		Surface::ArrayData&ad=surface->array[i];
-		ad.size=0;
-		ad.ofs=0;
-		int elem_size=0;
-		int elem_count=0;
-		bool valid_local=true;
-		GLenum datatype;
-		bool normalize=false;
-		bool bind=false;
-
-		if (!(format&(1<<i))) // no array
-			continue;
-
-
-		switch(i) {
-
-			case VS::ARRAY_VERTEX: {
-
-				if (surface->packed) {
-					elem_size=3*sizeof(int16_t); // vertex
-					datatype=GL_SHORT;
-					normalize=true;
-
-				} else {
-					elem_size=3*sizeof(GLfloat); // vertex
-					datatype=GL_FLOAT;
-				}
-				bind=true;
-				elem_count=3;
-
-			} break;
-			case VS::ARRAY_NORMAL: {
-
-				if (surface->packed) {
-					elem_size=3*sizeof(int8_t); // vertex
-					datatype=GL_BYTE;
-					normalize=true;
-				} else {
-					elem_size=3*sizeof(GLfloat); // vertex
-					datatype=GL_FLOAT;
-				}
-				bind=true;
-				elem_count=3;
-			} break;
-			case VS::ARRAY_TANGENT: {
-				if (surface->packed) {
-					elem_size=4*sizeof(int8_t); // vertex
-					datatype=GL_BYTE;
-					normalize=true;
-				} else {
-					elem_size=4*sizeof(GLfloat); // vertex
-					datatype=GL_FLOAT;
-				}
-				bind=true;
-				elem_count=4;
-
-			} break;
-			case VS::ARRAY_COLOR: {
-
-				elem_size=4*sizeof(uint8_t); /* RGBA */
-				datatype=GL_UNSIGNED_BYTE;
-				elem_count=4;
-				bind=true;
-				normalize=true;
-			} break;
-			case VS::ARRAY_TEX_UV:
-			case VS::ARRAY_TEX_UV2: {
-				if (surface->packed) {
-					elem_size=2*sizeof(int16_t); // vertex
-					datatype=GL_SHORT;
-					normalize=true;
-				} else {
-					elem_size=2*sizeof(GLfloat); // vertex
-					datatype=GL_FLOAT;
-				}
-				bind=true;
-				elem_count=2;
-
-			} break;
-			case VS::ARRAY_WEIGHTS: {
-
-				elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLfloat);
-				elem_count=VS::ARRAY_WEIGHTS_SIZE;
-				valid_local=false;
-				datatype=GL_FLOAT;
-
-			} break;
-			case VS::ARRAY_BONES: {
-
-				elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLuint);
-				elem_count=VS::ARRAY_WEIGHTS_SIZE;
-				valid_local=false;
-				datatype=GL_FLOAT;
-
-
-			} break;
-			case VS::ARRAY_INDEX: {
-
-				if (index_array_len<=0) {
-					ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
-					break;
-				}
-				/* determine wether using 16 or 32 bits indices */
-				elem_size=2;
-				datatype=GL_UNSIGNED_SHORT;
-
-/*
-				if (use_VBO) {
-
-					glGenBuffers(1,&surface->index_id);
-					ERR_FAIL_COND(surface->index_id==0);
-					glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id);
-					glBufferData(GL_ELEMENT_ARRAY_BUFFER,index_array_len*elem_size,NULL,GL_STATIC_DRAW);
-					glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-				} else {
-					surface->index_array_local = (uint8_t*)memalloc(index_array_len*elem_size);
-				};
-*/
-				surface->index_array_len=index_array_len; // only way it can exist
-				ad.ofs=0;
-				ad.size=elem_size;
-
-
-				continue;
-			} break;
-			default: {
-				ERR_FAIL( );
-			}
-		}
-
-		ad.ofs=total_elem_size;
-		ad.size=elem_size;
-		ad.datatype=datatype;
-		ad.normalize=normalize;
-		ad.bind=bind;
-		ad.count=elem_count;
-		total_elem_size+=elem_size;
-		if (valid_local) {
-			surface->local_stride+=elem_size;
-			surface->morph_format|=(1<<i);
-		}
-
-
-	}
-
-	surface->stride=total_elem_size;
-	surface->array_len=array_len;
-	surface->format=format;
-	surface->primitive=p_primitive;
-	surface->configured_format=0;
-	if (keep_copies) {
-		surface->data=p_arrays;
-		surface->morph_data=p_blend_shapes;
-	}
-
-	uint8_t *array_ptr=NULL;
-	uint8_t *index_array_ptr=NULL;
-	DVector<uint8_t> array_pre_vbo;
-	DVector<uint8_t>::Write vaw;
-	DVector<uint8_t> index_array_pre_vbo;
-	DVector<uint8_t>::Write iaw;
-
-	/* create pointers */
-	if (use_VBO) {
-
-		array_pre_vbo.resize(surface->array_len*surface->stride);
-		vaw = array_pre_vbo.write();
-		array_ptr=vaw.ptr();
-
-		if (surface->index_array_len) {
-
-			index_array_pre_vbo.resize(surface->index_array_len*surface->array[VS::ARRAY_INDEX].size);
-			iaw = index_array_pre_vbo.write();
-			index_array_ptr=iaw.ptr();
-		}
-	} else {
-
-		surface->array_local = (uint8_t*)memalloc(surface->array_len*surface->stride);
-		array_ptr=(uint8_t*)surface->array_local;
-		if (surface->index_array_len) {
-			surface->index_array_local = (uint8_t*)memalloc(index_array_len*surface->array[VS::ARRAY_INDEX].size);
-			index_array_ptr=(uint8_t*)surface->index_array_local;
-		}
-	}
-
-
-
-	_surface_set_arrays(surface,array_ptr,index_array_ptr,p_arrays,true);
-
-
-	/* create buffers!! */
-	if (use_VBO) {
-		glGenBuffers(1,&surface->vertex_id);
-		ERR_FAIL_COND(surface->vertex_id==0);
-		glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id);
-		glBufferData(GL_ARRAY_BUFFER,surface->array_len*surface->stride,array_ptr,GL_STATIC_DRAW);
-		glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
-		if (surface->index_array_len) {
-
-			glGenBuffers(1,&surface->index_id);
-			ERR_FAIL_COND(surface->index_id==0);
-			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id);
-			glBufferData(GL_ELEMENT_ARRAY_BUFFER,index_array_len*surface->array[VS::ARRAY_INDEX].size,index_array_ptr,GL_STATIC_DRAW);
-			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-
-		}
-	}
-
-	mesh->surfaces.push_back(surface);
-
-}
-
-Error RasterizerGLES1::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,uint8_t *p_index_mem,const Array& p_arrays,bool p_main) {
-
-	uint32_t stride = p_main ? p_surface->stride : p_surface->local_stride;
-
-	for(int ai=0;ai<VS::ARRAY_MAX;ai++) {
-		if (ai>=p_arrays.size())
-			break;
-		if (p_arrays[ai].get_type()==Variant::NIL)
-			continue;
-		Surface::ArrayData &a=p_surface->array[ai];
-
-		switch(ai) {
-
-
-			case VS::ARRAY_VERTEX: {
-
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER );
-
-				DVector<Vector3> array = p_arrays[ai];
-				ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER );
-
-
-				DVector<Vector3>::Read read = array.read();
-				const Vector3* src=read.ptr();
-
-				// setting vertices means regenerating the AABB
-				AABB aabb;
-
-				float scale=1;
-				float max=0;
-
-
-				for (int i=0;i<p_surface->array_len;i++) {
-
-
-					GLfloat vector[3]={ src[i].x, src[i].y, src[i].z };
-
-					copymem(&p_mem[a.ofs+i*stride], vector, a.size);
-
-					if (i==0) {
-
-						aabb=AABB(src[i],Vector3());
-					} else {
-
-						aabb.expand_to( src[i] );
-					}
-				}
-
-				if (p_main) {
-					p_surface->aabb=aabb;
-					p_surface->vertex_scale=scale;
-				}
-
-
-			} break;
-			case VS::ARRAY_NORMAL: {
-
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER );
-
-				DVector<Vector3> array = p_arrays[ai];
-				ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER );
-
-
-				DVector<Vector3>::Read read = array.read();
-				const Vector3* src=read.ptr();
-
-				// setting vertices means regenerating the AABB
-
-				for (int i=0;i<p_surface->array_len;i++) {
-
-
-					GLfloat vector[3]={ src[i].x, src[i].y, src[i].z };
-					copymem(&p_mem[a.ofs+i*stride], vector, a.size);
-
-				}
-
-
-			} break;
-			case VS::ARRAY_TANGENT: {
-
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
-
-				DVector<real_t> array = p_arrays[ai];
-
-				ERR_FAIL_COND_V( array.size() != p_surface->array_len*4, ERR_INVALID_PARAMETER );
-
-
-				DVector<real_t>::Read read = array.read();
-				const real_t* src = read.ptr();
-
-				for (int i=0;i<p_surface->array_len;i++) {
-
-					GLfloat xyzw[4]={
-						src[i*4+0],
-						src[i*4+1],
-						src[i*4+2],
-						src[i*4+3]
-					};
-
-					copymem(&p_mem[a.ofs+i*stride], xyzw, a.size);
-
-				}
-
-			} break;
-			case VS::ARRAY_COLOR: {
-
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER );
-
-
-				DVector<Color> array = p_arrays[ai];
-
-				ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER );
-
-
-				DVector<Color>::Read read = array.read();
-				const Color* src = read.ptr();
-				bool alpha=false;
-
-				for (int i=0;i<p_surface->array_len;i++) {
-
-					if (src[i].a<0.98) // tolerate alpha a bit, for crappy exporters
-						alpha=true;
-
-					uint8_t colors[4];
-
-					for(int j=0;j<4;j++) {
-
-						colors[j]=CLAMP( int((src[i][j])*255.0), 0,255 );
-					}
-
-						copymem(&p_mem[a.ofs+i*stride], colors, a.size);
-
-				}
-
-				if (p_main)
-					p_surface->has_alpha=alpha;
-
-			} break;
-			case VS::ARRAY_TEX_UV:
-			case VS::ARRAY_TEX_UV2: {
-
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::VECTOR2_ARRAY, ERR_INVALID_PARAMETER );
-
-				DVector<Vector2> array = p_arrays[ai];
-
-				ERR_FAIL_COND_V( array.size() != p_surface->array_len , ERR_INVALID_PARAMETER);
-
-				DVector<Vector2>::Read read = array.read();
-
-				const Vector2 * src=read.ptr();
-				float scale=1.0;
-
-
-				for (int i=0;i<p_surface->array_len;i++) {
-
-					GLfloat uv[2]={ src[i].x , src[i].y };
-
-					copymem(&p_mem[a.ofs+i*stride], uv, a.size);
-
-				}
-
-				if (p_main) {
-
-					if  (ai==VS::ARRAY_TEX_UV) {
-
-						p_surface->uv_scale=scale;
-					}
-					if  (ai==VS::ARRAY_TEX_UV2) {
-
-						p_surface->uv2_scale=scale;
-					}
-				}
-
-			} break;
-			case VS::ARRAY_BONES:
-			case VS::ARRAY_WEIGHTS: {
-
-
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
-
-				DVector<real_t> array = p_arrays[ai];
-
-				ERR_FAIL_COND_V( array.size() != p_surface->array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER );
-
-
-				DVector<real_t>::Read read = array.read();
-
-				const real_t * src = read.ptr();
-
-				p_surface->max_bone=0;
-
-				for (int i=0;i<p_surface->array_len;i++) {
-
-					GLfloat data[VS::ARRAY_WEIGHTS_SIZE];
-					for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
-						data[j]=src[i*VS::ARRAY_WEIGHTS_SIZE+j];
-						if (ai==VS::ARRAY_BONES) {
-
-							p_surface->max_bone=MAX(data[j],p_surface->max_bone);
-						}
-					}
-
-					copymem(&p_mem[a.ofs+i*stride], data, a.size);
-
-
-				}
-
-			} break;
-			case VS::ARRAY_INDEX: {
-
-				ERR_FAIL_COND_V( p_surface->index_array_len<=0, ERR_INVALID_DATA );
-				ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER );
-
-				DVector<int> indices = p_arrays[ai];
-				ERR_FAIL_COND_V( indices.size() == 0, ERR_INVALID_PARAMETER );
-				ERR_FAIL_COND_V( indices.size() != p_surface->index_array_len, ERR_INVALID_PARAMETER );
-
-				/* determine wether using 16 or 32 bits indices */
-
-				DVector<int>::Read read = indices.read();
-				const int *src=read.ptr();
-
-				for (int i=0;i<p_surface->index_array_len;i++) {
-
-
-					if (a.size==2) {
-						uint16_t v=src[i];
-
-						copymem(&p_index_mem[i*a.size], &v, a.size);
-					} else {
-						uint32_t v=src[i];
-
-						copymem(&p_index_mem[i*a.size], &v, a.size);
-					}
-				}
-
-
-			} break;
-
-
-			default: { ERR_FAIL_V(ERR_INVALID_PARAMETER);}
-		}
-
-		p_surface->configured_format|=(1<<ai);
-	}
-
-	return OK;
-}
-
-
-
-void RasterizerGLES1::mesh_add_custom_surface(RID p_mesh,const Variant& p_dat) {
-
-	ERR_EXPLAIN("OpenGL Rasterizer does not support custom surfaces. Running on wrong platform?");
-	ERR_FAIL_V();
-}
-
-Array RasterizerGLES1::mesh_get_surface_arrays(RID p_mesh,int p_surface) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,Array());
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array() );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, Array() );
-
-	return surface->data;
-
-
-}
-Array RasterizerGLES1::mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const{
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,Array());
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array() );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, Array() );
-
-	return surface->morph_data;
-
-}
-
-
-void RasterizerGLES1::mesh_set_morph_target_count(RID p_mesh,int p_amount) {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND(!mesh);
-	ERR_FAIL_COND( mesh->surfaces.size()!=0 );
-
-	mesh->morph_target_count=p_amount;
-
-}
-
-int RasterizerGLES1::mesh_get_morph_target_count(RID p_mesh) const{
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,-1);
-
-	return mesh->morph_target_count;
-
-}
-
-void RasterizerGLES1::mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode) {
-
-	ERR_FAIL_INDEX(p_mode,2);
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND(!mesh);
-
-	mesh->morph_target_mode=p_mode;
-
-}
-
-VS::MorphTargetMode RasterizerGLES1::mesh_get_morph_target_mode(RID p_mesh) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,VS::MORPH_MODE_NORMALIZED);
-
-	return mesh->morph_target_mode;
-
-}
-
-
-
-void RasterizerGLES1::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned) {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND(!mesh);
-	ERR_FAIL_INDEX(p_surface, mesh->surfaces.size() );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND( !surface);
-
-	if (surface->material_owned && surface->material.is_valid())
-		free(surface->material);
-
-	surface->material_owned=p_owned;
-
-	surface->material=p_material;
-}
-
-RID RasterizerGLES1::mesh_surface_get_material(RID p_mesh, int p_surface) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,RID());
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID() );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, RID() );
-
-	return surface->material;
-}
-
-int RasterizerGLES1::mesh_surface_get_array_len(RID p_mesh, int p_surface) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,-1);
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, -1 );
-
-	return surface->array_len;
-}
-int RasterizerGLES1::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,-1);
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, -1 );
-
-	return surface->index_array_len;
-}
-uint32_t RasterizerGLES1::mesh_surface_get_format(RID p_mesh, int p_surface) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,0);
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0 );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, 0 );
-
-	return surface->format;
-}
-VS::PrimitiveType RasterizerGLES1::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,VS::PRIMITIVE_POINTS);
-	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS );
-	Surface *surface = mesh->surfaces[p_surface];
-	ERR_FAIL_COND_V( !surface, VS::PRIMITIVE_POINTS );
-
-	return surface->primitive;
-}
-
-void RasterizerGLES1::mesh_remove_surface(RID p_mesh,int p_index) {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND(!mesh);
-	ERR_FAIL_INDEX(p_index, mesh->surfaces.size() );
-	Surface *surface = mesh->surfaces[p_index];
-	ERR_FAIL_COND( !surface);
-
-	if (mesh->morph_target_count) {
-		for(int i=0;i<mesh->morph_target_count;i++)
-			memfree(surface->morph_targets_local[i].array);
-		memfree( surface->morph_targets_local );
-	}
-
-	memdelete( mesh->surfaces[p_index] );
-	mesh->surfaces.remove(p_index);
-
-}
-int RasterizerGLES1::mesh_get_surface_count(RID p_mesh) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,-1);
-
-	return mesh->surfaces.size();
-}
-
-AABB RasterizerGLES1::mesh_get_aabb(RID p_mesh,RID p_skeleton) const {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,AABB());
-
-	if (mesh->custom_aabb!=AABB())
-		return mesh->custom_aabb;
-
-	AABB aabb;
-
-	for (int i=0;i<mesh->surfaces.size();i++) {
-
-		if (i==0)
-			aabb=mesh->surfaces[i]->aabb;
-		else
-			aabb.merge_with(mesh->surfaces[i]->aabb);
-	}
-
-	return aabb;
-}
-
-void RasterizerGLES1::mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb) {
-
-	Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND(!mesh);
-
-	mesh->custom_aabb=p_aabb;
-
-}
-
-AABB RasterizerGLES1::mesh_get_custom_aabb(RID p_mesh) const {
-
-	const Mesh *mesh = mesh_owner.get( p_mesh );
-	ERR_FAIL_COND_V(!mesh,AABB());
-
-	return mesh->custom_aabb;
-}
-
-
-/* MULTIMESH API */
-
-RID RasterizerGLES1::multimesh_create() {
-
-	return multimesh_owner.make_rid( memnew( MultiMesh ));
-}
-
-void RasterizerGLES1::multimesh_set_instance_count(RID p_multimesh,int p_count) {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh);
-
-	multimesh->elements.clear(); // make sure to delete everything, so it "fails" in all implementations
-	multimesh->elements.resize(p_count);
-
-}
-int RasterizerGLES1::multimesh_get_instance_count(RID p_multimesh) const {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND_V(!multimesh,-1);
-
-	return multimesh->elements.size();
-}
-
-void RasterizerGLES1::multimesh_set_mesh(RID p_multimesh,RID p_mesh) {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh);
-
-	multimesh->mesh=p_mesh;
-
-}
-void RasterizerGLES1::multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb) {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh);
-	multimesh->aabb=p_aabb;
-}
-void RasterizerGLES1::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform) {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh);
-	ERR_FAIL_INDEX(p_index,multimesh->elements.size());
-	MultiMesh::Element &e=multimesh->elements[p_index];
-
-	e.matrix[0]=p_transform.basis.elements[0][0];
-	e.matrix[1]=p_transform.basis.elements[1][0];
-	e.matrix[2]=p_transform.basis.elements[2][0];
-	e.matrix[3]=0;
-	e.matrix[4]=p_transform.basis.elements[0][1];
-	e.matrix[5]=p_transform.basis.elements[1][1];
-	e.matrix[6]=p_transform.basis.elements[2][1];
-	e.matrix[7]=0;
-	e.matrix[8]=p_transform.basis.elements[0][2];
-	e.matrix[9]=p_transform.basis.elements[1][2];
-	e.matrix[10]=p_transform.basis.elements[2][2];
-	e.matrix[11]=0;
-	e.matrix[12]=p_transform.origin.x;
-	e.matrix[13]=p_transform.origin.y;
-	e.matrix[14]=p_transform.origin.z;
-	e.matrix[15]=1;
-
-}
-void RasterizerGLES1::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color) {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh)
-	ERR_FAIL_INDEX(p_index,multimesh->elements.size());
-	MultiMesh::Element &e=multimesh->elements[p_index];
-	e.color[0]=CLAMP(p_color.r*255,0,255);
-	e.color[1]=CLAMP(p_color.g*255,0,255);
-	e.color[2]=CLAMP(p_color.b*255,0,255);
-	e.color[3]=CLAMP(p_color.a*255,0,255);
-
-
-}
-
-RID RasterizerGLES1::multimesh_get_mesh(RID p_multimesh) const {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND_V(!multimesh,RID());
-
-	return multimesh->mesh;
-}
-AABB RasterizerGLES1::multimesh_get_aabb(RID p_multimesh) const {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND_V(!multimesh,AABB());
-
-	return multimesh->aabb;
-}
-
-Transform RasterizerGLES1::multimesh_instance_get_transform(RID p_multimesh,int p_index) const {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND_V(!multimesh,Transform());
-
-	ERR_FAIL_INDEX_V(p_index,multimesh->elements.size(),Transform());
-	MultiMesh::Element &e=multimesh->elements[p_index];
-
-	Transform tr;
-
-	tr.basis.elements[0][0]=e.matrix[0];
-	tr.basis.elements[1][0]=e.matrix[1];
-	tr.basis.elements[2][0]=e.matrix[2];
-	tr.basis.elements[0][1]=e.matrix[4];
-	tr.basis.elements[1][1]=e.matrix[5];
-	tr.basis.elements[2][1]=e.matrix[6];
-	tr.basis.elements[0][2]=e.matrix[8];
-	tr.basis.elements[1][2]=e.matrix[9];
-	tr.basis.elements[2][2]=e.matrix[10];
-	tr.origin.x=e.matrix[12];
-	tr.origin.y=e.matrix[13];
-	tr.origin.z=e.matrix[14];
-
-	return tr;
-}
-Color RasterizerGLES1::multimesh_instance_get_color(RID p_multimesh,int p_index) const {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND_V(!multimesh,Color());
-	ERR_FAIL_INDEX_V(p_index,multimesh->elements.size(),Color());
-	MultiMesh::Element &e=multimesh->elements[p_index];
-	Color c;
-	c.r=e.color[0]/255.0;
-	c.g=e.color[1]/255.0;
-	c.b=e.color[2]/255.0;
-	c.a=e.color[3]/255.0;
-
-	return c;
-
-}
-
-void RasterizerGLES1::multimesh_set_visible_instances(RID p_multimesh,int p_visible) {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh);
-	multimesh->visible=p_visible;
-
-}
-
-int RasterizerGLES1::multimesh_get_visible_instances(RID p_multimesh) const {
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND_V(!multimesh,-1);
-	return multimesh->visible;
-
-}
-
-/* IMMEDIATE API */
-
-
-RID RasterizerGLES1::immediate_create() {
-
-	Immediate *im = memnew( Immediate );
-	return immediate_owner.make_rid(im);
-
-}
-
-void RasterizerGLES1::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture){
-
-
-}
-void RasterizerGLES1::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
-
-
-}
-void RasterizerGLES1::immediate_normal(RID p_immediate,const Vector3& p_normal){
-
-
-}
-void RasterizerGLES1::immediate_tangent(RID p_immediate,const Plane& p_tangent){
-
-
-}
-void RasterizerGLES1::immediate_color(RID p_immediate,const Color& p_color){
-
-
-}
-void RasterizerGLES1::immediate_uv(RID p_immediate,const Vector2& tex_uv){
-
-
-}
-void RasterizerGLES1::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
-
-
-}
-
-void RasterizerGLES1::immediate_end(RID p_immediate){
-
-
-}
-void RasterizerGLES1::immediate_clear(RID p_immediate) {
-
-
-}
-
-AABB RasterizerGLES1::immediate_get_aabb(RID p_immediate) const {
-
-	return AABB(Vector3(-1,-1,-1),Vector3(2,2,2));
-}
-
-void RasterizerGLES1::immediate_set_material(RID p_immediate,RID p_material) {
-
-	Immediate *im = immediate_owner.get(p_immediate);
-	ERR_FAIL_COND(!im);
-	im->material=p_material;
-}
-
-RID RasterizerGLES1::immediate_get_material(RID p_immediate) const {
-
-	const Immediate *im = immediate_owner.get(p_immediate);
-	ERR_FAIL_COND_V(!im,RID());
-	return im->material;
-
-}
-
-
-/* PARTICLES API */
-
-RID RasterizerGLES1::particles_create() {
-
-	Particles *particles = memnew( Particles );
-	ERR_FAIL_COND_V(!particles,RID());
-	return particles_owner.make_rid(particles);
-}
-
-void RasterizerGLES1::particles_set_amount(RID p_particles, int p_amount) {
-
-	ERR_FAIL_COND(p_amount<1);
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.amount=p_amount;
-
-}
-
-int RasterizerGLES1::particles_get_amount(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,-1);
-	return particles->data.amount;
-
-}
-
-void RasterizerGLES1::particles_set_emitting(RID p_particles, bool p_emitting) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.emitting=p_emitting;;
-
-}
-bool RasterizerGLES1::particles_is_emitting(RID p_particles) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,false);
-	return particles->data.emitting;
-
-}
-
-void RasterizerGLES1::particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.visibility_aabb=p_visibility;
-
-}
-
-void RasterizerGLES1::particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-
-	particles->data.emission_half_extents=p_half_extents;
-}
-Vector3 RasterizerGLES1::particles_get_emission_half_extents(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,Vector3());
-
-	return particles->data.emission_half_extents;
-}
-
-void RasterizerGLES1::particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-
-	particles->data.emission_base_velocity=p_base_velocity;
-}
-
-Vector3 RasterizerGLES1::particles_get_emission_base_velocity(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,Vector3());
-
-	return particles->data.emission_base_velocity;
-}
-
-
-void RasterizerGLES1::particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-
-	particles->data.emission_points=p_points;
-}
-
-DVector<Vector3> RasterizerGLES1::particles_get_emission_points(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,DVector<Vector3>());
-
-	return particles->data.emission_points;
-
-}
-
-void RasterizerGLES1::particles_set_gravity_normal(RID p_particles, const Vector3& p_normal) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-
-	particles->data.gravity_normal=p_normal;
-
-}
-Vector3 RasterizerGLES1::particles_get_gravity_normal(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,Vector3());
-
-	return particles->data.gravity_normal;
-}
-
-
-AABB RasterizerGLES1::particles_get_visibility_aabb(RID p_particles) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,AABB());
-	return particles->data.visibility_aabb;
-
-}
-
-void RasterizerGLES1::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value) {
-
-	ERR_FAIL_INDEX(p_variable,VS::PARTICLE_VAR_MAX);
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.particle_vars[p_variable]=p_value;
-
-}
-float RasterizerGLES1::particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,-1);
-	return particles->data.particle_vars[p_variable];
-}
-
-void RasterizerGLES1::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.particle_randomness[p_variable]=p_randomness;
-
-}
-float RasterizerGLES1::particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,-1);
-	return particles->data.particle_randomness[p_variable];
-
-}
-
-void RasterizerGLES1::particles_set_color_phases(RID p_particles, int p_phases) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	ERR_FAIL_COND( p_phases<0 || p_phases>VS::MAX_PARTICLE_COLOR_PHASES );
-	particles->data.color_phase_count=p_phases;
-
-}
-int RasterizerGLES1::particles_get_color_phases(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,-1);
-	return particles->data.color_phase_count;
-}
-
-
-void RasterizerGLES1::particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos) {
-
-	ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
-	if (p_pos<0.0)
-		p_pos=0.0;
-	if (p_pos>1.0)
-		p_pos=1.0;
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.color_phases[p_phase].pos=p_pos;
-
-}
-float RasterizerGLES1::particles_get_color_phase_pos(RID p_particles, int p_phase) const {
-
-	ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, -1.0);
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,-1);
-	return particles->data.color_phases[p_phase].pos;
-
-}
-
-void RasterizerGLES1::particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color) {
-
-	ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.color_phases[p_phase].color=p_color;
-
-	//update alpha
-	particles->has_alpha=false;
-	for(int i=0;i<VS::MAX_PARTICLE_COLOR_PHASES;i++) {
-		if (particles->data.color_phases[i].color.a<0.99)
-			particles->has_alpha=true;
-	}
-
-}
-
-Color RasterizerGLES1::particles_get_color_phase_color(RID p_particles, int p_phase) const {
-
-	ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, Color());
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,Color());
-	return particles->data.color_phases[p_phase].color;
-
-}
-
-void RasterizerGLES1::particles_set_attractors(RID p_particles, int p_attractors) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	ERR_FAIL_COND( p_attractors<0 || p_attractors>VisualServer::MAX_PARTICLE_ATTRACTORS );
-	particles->data.attractor_count=p_attractors;
-
-}
-int RasterizerGLES1::particles_get_attractors(RID p_particles) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,-1);
-	return particles->data.attractor_count;
-}
-
-void RasterizerGLES1::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count);
-	particles->data.attractors[p_attractor].pos=p_pos;;
-}
-Vector3 RasterizerGLES1::particles_get_attractor_pos(RID p_particles,int p_attractor) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,Vector3());
-	ERR_FAIL_INDEX_V(p_attractor,particles->data.attractor_count,Vector3());
-	return particles->data.attractors[p_attractor].pos;
-}
-
-void RasterizerGLES1::particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count);
-	particles->data.attractors[p_attractor].force=p_force;
-}
-
-float RasterizerGLES1::particles_get_attractor_strength(RID p_particles,int p_attractor) const {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,0);
-	ERR_FAIL_INDEX_V(p_attractor,particles->data.attractor_count,0);
-	return particles->data.attractors[p_attractor].force;
-}
-
-void RasterizerGLES1::particles_set_material(RID p_particles, RID p_material,bool p_owned) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	if (particles->material_owned && particles->material.is_valid())
-		free(particles->material);
-
-	particles->material_owned=p_owned;
-
-	particles->material=p_material;
-
-}
-RID RasterizerGLES1::particles_get_material(RID p_particles) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,RID());
-	return particles->material;
-
-}
-
-void RasterizerGLES1::particles_set_use_local_coordinates(RID p_particles, bool p_enable) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.local_coordinates=p_enable;
-
-}
-
-bool RasterizerGLES1::particles_is_using_local_coordinates(RID p_particles) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,false);
-	return particles->data.local_coordinates;
-}
-bool RasterizerGLES1::particles_has_height_from_velocity(RID p_particles) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,false);
-	return particles->data.height_from_velocity;
-}
-
-void RasterizerGLES1::particles_set_height_from_velocity(RID p_particles, bool p_enable) {
-
-	Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND(!particles);
-	particles->data.height_from_velocity=p_enable;
-
-}
-
-AABB RasterizerGLES1::particles_get_aabb(RID p_particles) const {
-
-	const Particles* particles = particles_owner.get( p_particles );
-	ERR_FAIL_COND_V(!particles,AABB());
-	return particles->data.visibility_aabb;
-}
-
-/* SKELETON API */
-
-RID RasterizerGLES1::skeleton_create() {
-
-	Skeleton *skeleton = memnew( Skeleton );
-	ERR_FAIL_COND_V(!skeleton,RID());
-	return skeleton_owner.make_rid( skeleton );
-}
-void RasterizerGLES1::skeleton_resize(RID p_skeleton,int p_bones) {
-
-	Skeleton *skeleton = skeleton_owner.get( p_skeleton );
-	ERR_FAIL_COND(!skeleton);
-	if (p_bones == skeleton->bones.size()) {
-		return;
-	};
-
-	skeleton->bones.resize(p_bones);
-
-}
-int RasterizerGLES1::skeleton_get_bone_count(RID p_skeleton) const {
-
-	Skeleton *skeleton = skeleton_owner.get( p_skeleton );
-	ERR_FAIL_COND_V(!skeleton, -1);
-	return skeleton->bones.size();
-}
-void RasterizerGLES1::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform) {
-
-	Skeleton *skeleton = skeleton_owner.get( p_skeleton );
-	ERR_FAIL_COND(!skeleton);
-	ERR_FAIL_INDEX( p_bone, skeleton->bones.size() );
-
-	skeleton->bones[p_bone] = p_transform;
-}
-
-Transform RasterizerGLES1::skeleton_bone_get_transform(RID p_skeleton,int p_bone) {
-
-	Skeleton *skeleton = skeleton_owner.get( p_skeleton );
-	ERR_FAIL_COND_V(!skeleton, Transform());
-	ERR_FAIL_INDEX_V( p_bone, skeleton->bones.size(), Transform() );
-
-	// something
-	return skeleton->bones[p_bone];
-}
-
-
-/* LIGHT API */
-
-RID RasterizerGLES1::light_create(VS::LightType p_type) {
-
-	Light *light = memnew( Light );
-	light->type=p_type;
-	return light_owner.make_rid(light);
-}
-
-VS::LightType RasterizerGLES1::light_get_type(RID p_light) const {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND_V(!light,VS::LIGHT_OMNI);
-	return light->type;
-}
-
-void RasterizerGLES1::light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color) {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND(!light);
-	ERR_FAIL_INDEX( p_type, 3 );
-	light->colors[p_type]=p_color;
-}
-Color RasterizerGLES1::light_get_color(RID p_light,VS::LightColor p_type) const {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND_V(!light, Color());
-	ERR_FAIL_INDEX_V( p_type, 3, Color() );
-	return light->colors[p_type];
-}
-
-void RasterizerGLES1::light_set_shadow(RID p_light,bool p_enabled) {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND(!light);
-	light->shadow_enabled=p_enabled;
-}
-
-bool RasterizerGLES1::light_has_shadow(RID p_light) const {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND_V(!light,false);
-	return light->shadow_enabled;
-}
-
-void RasterizerGLES1::light_set_volumetric(RID p_light,bool p_enabled) {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND(!light);
-	light->volumetric_enabled=p_enabled;
-
-}
-bool RasterizerGLES1::light_is_volumetric(RID p_light) const {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND_V(!light,false);
-	return light->volumetric_enabled;
-}
-
-void RasterizerGLES1::light_set_projector(RID p_light,RID p_texture) {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND(!light);
-	light->projector=p_texture;
-}
-RID RasterizerGLES1::light_get_projector(RID p_light) const {
-
-	Light *light = light_owner.get(p_light);
-	ERR_FAIL_COND_V(!light,RID());
-	return light->projector;
-}
-
-void RasterizerGLES1::light_set_var(RID p_light, VS::LightParam p_var, float p_value) {
-
-	Light * light = light_owner.get( p_light );
-	ERR_FAIL_COND(!light);
-	ERR_FAIL_INDEX( p_var, VS::LIGHT_PARAM_MAX );
-
-	light->vars[p_var]=p_value;
-}
-float RasterizerGLES1::light_get_var(RID p_light, VS::LightParam p_var) const {
-
-	Light * light = light_owner.get( p_light );
-	ERR_FAIL_COND_V(!light,0);
-
-	ERR_FAIL_INDEX_V( p_var, VS::LIGHT_PARAM_MAX,0 );
-
-	return light->vars[p_var];
-}
-
-void RasterizerGLES1::light_set_operator(RID p_light,VS::LightOp p_op) {
-
-	Light * light = light_owner.get( p_light );
-	ERR_FAIL_COND(!light);
-
-
-};
-
-VS::LightOp RasterizerGLES1::light_get_operator(RID p_light) const {
-
-	return VS::LightOp(0);
-};
-
-void RasterizerGLES1::light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode) {
-
-
-}
-
-VS::LightOmniShadowMode RasterizerGLES1::light_omni_get_shadow_mode(RID p_light) const{
-
-	return VS::LightOmniShadowMode(0);
-}
-
-void RasterizerGLES1::light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode) {
-
-
-}
-
-VS::LightDirectionalShadowMode RasterizerGLES1::light_directional_get_shadow_mode(RID p_light) const {
-
-	return VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
-}
-
-void RasterizerGLES1::light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value) {
-
-
-}
-
-float RasterizerGLES1::light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const {
-
-	return 0;
-}
-
-
-AABB RasterizerGLES1::light_get_aabb(RID p_light) const {
-
-	Light *light = light_owner.get( p_light );
-	ERR_FAIL_COND_V(!light,AABB());
-
-	switch( light->type ) {
-
-		case VS::LIGHT_SPOT: {
-
-			float len=light->vars[VS::LIGHT_PARAM_RADIUS];
-			float size=Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE]))*len;
-			return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) );
-		} break;
-		case VS::LIGHT_OMNI: {
-
-			float r = light->vars[VS::LIGHT_PARAM_RADIUS];
-			return AABB( -Vector3(r,r,r), Vector3(r,r,r)*2 );
-		} break;
-		case VS::LIGHT_DIRECTIONAL: {
-
-			return AABB();
-		} break;
-		default: {}
-	}
-
-	ERR_FAIL_V( AABB() );
-}
-
-
-RID RasterizerGLES1::light_instance_create(RID p_light) {
-
-	Light *light = light_owner.get( p_light );
-	ERR_FAIL_COND_V(!light, RID());
-
-	LightInstance *light_instance = memnew( LightInstance );
-
-	light_instance->light=p_light;
-	light_instance->base=light;
-	light_instance->last_pass=0;
-
-	return light_instance_owner.make_rid( light_instance );
-}
-void RasterizerGLES1::light_instance_set_transform(RID p_light_instance,const Transform& p_transform) {
-
-	LightInstance *lighti = light_instance_owner.get( p_light_instance );
-	ERR_FAIL_COND(!lighti);
-	lighti->transform=p_transform;
-
-}
-
-bool RasterizerGLES1::light_instance_has_shadow(RID p_light_instance) const {
-
-	return false;
-
-	/*
-	LightInstance *lighti = light_instance_owner.get( p_light_instance );
-	ERR_FAIL_COND_V(!lighti, false);
-
-	if (!lighti->base->shadow_enabled)
-		return false;
-
-	if (lighti->base->type==VS::LIGHT_DIRECTIONAL) {
-		if (lighti->shadow_pass!=scene_pass)
-			return false;
-
-	} else {
-		if (lighti->shadow_pass!=frame)
-			return false;
-	}*/
-
-
-
-	//return !lighti->shadow_buffers.empty();
-
-}
-
-
-bool RasterizerGLES1::light_instance_assign_shadow(RID p_light_instance) {
-
-	return false;
-
-}
-
-
-Rasterizer::ShadowType RasterizerGLES1::light_instance_get_shadow_type(RID p_light_instance) const {
-
-	LightInstance *lighti = light_instance_owner.get( p_light_instance );
-	ERR_FAIL_COND_V(!lighti,Rasterizer::SHADOW_NONE);
-
-	switch(lighti->base->type) {
-
-		case VS::LIGHT_DIRECTIONAL: return SHADOW_PSM; break;
-		case VS::LIGHT_OMNI: return SHADOW_DUAL_PARABOLOID; break;
-		case VS::LIGHT_SPOT: return SHADOW_SIMPLE; break;
-	}
-
-	return Rasterizer::SHADOW_NONE;
-}
-
-Rasterizer::ShadowType RasterizerGLES1::light_instance_get_shadow_type(RID p_light_instance,bool p_far) const {
-
-	return SHADOW_NONE;
-}
-void RasterizerGLES1::light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near,float p_split_far) {
-
-
-}
-
-int RasterizerGLES1::light_instance_get_shadow_passes(RID p_light_instance) const {
-
-	return 0;
-}
-
-bool RasterizerGLES1::light_instance_get_pssm_shadow_overlap(RID p_light_instance) const {
-
-	return false;
-}
-
-void RasterizerGLES1::light_instance_set_custom_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near,float p_split_far) {
-
-	LightInstance *lighti = light_instance_owner.get( p_light_instance );
-	ERR_FAIL_COND(!lighti);
-
-	ERR_FAIL_COND(lighti->base->type!=VS::LIGHT_DIRECTIONAL);
-	ERR_FAIL_INDEX(p_index,1);
-
-	lighti->custom_projection=p_camera;
-	lighti->custom_transform=p_transform;
-
-}
-void RasterizerGLES1::shadow_clear_near() {
-
-
-}
-
-bool RasterizerGLES1::shadow_allocate_near(RID p_light) {
-
-	return false;
-}
-
-bool RasterizerGLES1::shadow_allocate_far(RID p_light) {
-
-	return false;
-}
-
-/* PARTICLES INSTANCE */
-
-RID RasterizerGLES1::particles_instance_create(RID p_particles) {
-
-	ERR_FAIL_COND_V(!particles_owner.owns(p_particles),RID());
-	ParticlesInstance *particles_instance = memnew( ParticlesInstance );
-	ERR_FAIL_COND_V(!particles_instance, RID() );
-	particles_instance->particles=p_particles;
-	return particles_instance_owner.make_rid(particles_instance);
-}
-
-void RasterizerGLES1::particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform) {
-
-	ParticlesInstance *particles_instance=particles_instance_owner.get(p_particles_instance);
-	ERR_FAIL_COND(!particles_instance);
-	particles_instance->transform=p_transform;
-}
-
-
-/* RENDER API */
-/* all calls (inside begin/end shadow) are always warranted to be in the following order: */
-
-
-RID RasterizerGLES1::viewport_data_create() {
-
-	return RID();
-}
-
-RID RasterizerGLES1::render_target_create(){
-
-	return RID();
-
-}
-void RasterizerGLES1::render_target_set_size(RID p_render_target, int p_width, int p_height){
-
-
-}
-RID RasterizerGLES1::render_target_get_texture(RID p_render_target) const{
-
-	return RID();
-
-}
-bool RasterizerGLES1::render_target_renedered_in_frame(RID p_render_target){
-
-	return false;
-}
-
-
-void RasterizerGLES1::begin_frame() {
-
-
-	window_size = Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height );
-	//print_line("begin frame - winsize: "+window_size);
-
-	double time = (OS::get_singleton()->get_ticks_usec()/1000); // get msec
-	time/=1000.0; // make secs
-	time_delta=time-last_time;
-	last_time=time;
-	frame++;
-	clear_viewport(Color(1,0,0.5));
-
-	_rinfo.vertex_count=0;
-	_rinfo.object_count=0;
-	_rinfo.mat_change_count=0;
-	_rinfo.shader_change_count=0;
-
-
-//	material_shader.set_uniform_default(MaterialShaderGLES1::SCREENZ_SCALE, Math::fmod(time, 3600.0));
-	/* nehe ?*/
-
-//	glClearColor(0,0,1,1);
-//	glClear(GL_COLOR_BUFFER_BIT); //should not clear if anything else cleared..
-}
-
-void RasterizerGLES1::capture_viewport(Image* r_capture) {
-
-
-}
-
-
-void RasterizerGLES1::clear_viewport(const Color& p_color) {
-
-	glScissor( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
-	glEnable(GL_SCISSOR_TEST);
-	glClearColor(p_color.r,p_color.g,p_color.b,p_color.a);
-	glClear(GL_COLOR_BUFFER_BIT); //should not clear if anything else cleared..
-	glDisable(GL_SCISSOR_TEST);
-
-};
-
-void RasterizerGLES1::set_viewport(const VS::ViewportRect& p_viewport) {
-
-
-
-	viewport=p_viewport;
-	//print_line("viewport: "+itos(p_viewport.x)+","+itos(p_viewport.y)+","+itos(p_viewport.width)+","+itos(p_viewport.height));
-
-	glViewport( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
-}
-
-void RasterizerGLES1::set_render_target(RID p_render_target, bool p_transparent_bg, bool p_vflip) {
-
-
-}
-
-
-void RasterizerGLES1::begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug) {
-
-
-	opaque_render_list.clear();
-	alpha_render_list.clear();
-	light_instance_count=0;
-	scene_fx = NULL; // p_env.is_valid() ? fx_owner.get(p_env) : NULL;
-	scene_pass++;
-	last_light_id=0;
-	directional_light_count=0;
-
-
-	//set state
-
-	glCullFace(GL_FRONT);
-	cull_front=true;
-};
-
-void RasterizerGLES1::begin_shadow_map( RID p_light_instance, int p_shadow_pass ) {
-
-}
-
-void RasterizerGLES1::set_camera(const Transform& p_world,const CameraMatrix& p_projection) {
-
-	camera_transform=p_world;
-	camera_transform_inverse=camera_transform.inverse();
-	camera_projection=p_projection;
-	camera_plane = Plane( camera_transform.origin, camera_transform.basis.get_axis(2) );
-	camera_z_near=camera_projection.get_z_near();
-	camera_z_far=camera_projection.get_z_far();
-	camera_projection.get_viewport_size(camera_vp_size.x,camera_vp_size.y);
-}
-
-void RasterizerGLES1::add_light( RID p_light_instance ) {
-
-#define LIGHT_FADE_TRESHOLD 0.05
-
-	ERR_FAIL_COND( light_instance_count >= MAX_SCENE_LIGHTS );
-
-	LightInstance *li = light_instance_owner.get(p_light_instance);
-	ERR_FAIL_COND(!li);
-
-
-	/* make light hash */
-
-	// actually, not really a hash, but helps to sort the lights
-	// and avoid recompiling redudant shader versions
-
-
-	li->last_pass=scene_pass;
-	li->sort_key=light_instance_count;
-
-	 switch(li->base->type) {
-
-		case VisualServer::LIGHT_DIRECTIONAL: {
-
-			li->light_vector = camera_transform_inverse.basis.xform(li->transform.basis.get_axis(2)).normalized();
-			if (directional_light_count<MAX_HW_LIGHTS) {
-
-				directional_lights[directional_light_count++]=li;
-			}
-
-		} break;
-		case VisualServer::LIGHT_OMNI: {
-
-			  float radius = li->base->vars[VisualServer::LIGHT_PARAM_RADIUS];
-			  if (radius==0)
-				  radius=0.0001;
-			  li->linear_att=(1/LIGHT_FADE_TRESHOLD)/radius;
-			  li->light_vector = camera_transform_inverse.xform(li->transform.origin);
-
-		} break;
-		case VisualServer::LIGHT_SPOT: {
-
-			float radius = li->base->vars[VisualServer::LIGHT_PARAM_RADIUS];
-			if (radius==0)
-				radius=0.0001;
-			li->linear_att=(1/LIGHT_FADE_TRESHOLD)/radius;
-			li->light_vector = camera_transform_inverse.xform(li->transform.origin);
-			li->spot_vector = -camera_transform_inverse.basis.xform(li->transform.basis.get_axis(2)).normalized();
-			//li->sort_key|=LIGHT_SPOT_BIT; // this way, omnis go first, spots go last and less shader versions are generated
-
-			/*
-			if (li->base->projector.is_valid()) {
-
-				float far = li->base->vars[ VS::LIGHT_VAR_RADIUS ];
-				ERR_FAIL_COND( far<=0 );
-				float near= far/200.0;
-				if (near<0.05)
-					near=0.05;
-
-				float angle = li->base->vars[ VS::LIGHT_VAR_SPOT_ANGLE ];
-
-				//CameraMatrix proj;
-				//proj.set_perspective( angle*2.0, 1.0, near, far );
-
-				//Transform modelview=Transform(camera_transform_inverse * li->transform).inverse();
-				//li->projector_mtx= proj * modelview;
-
-			}*/
-		} break;
-	 }
-
-	light_instances[light_instance_count++]=li;
-
-}
-
-void RasterizerGLES1::_add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner) {
-
-	Material *m=NULL;
-	RID m_src=p_instance->material_override.is_valid() ? p_instance->material_override : p_geometry->material;
-
-	if (m_src)
-		m=material_owner.get( m_src );
-
-	if (!m) {
-		m=material_owner.get( default_material );
-	}
-
-	ERR_FAIL_COND(!m);
-
-
-	if (m->last_pass!=frame) {
-
-		m->last_pass=frame;
-	}
-
-
-	LightInstance *lights[RenderList::MAX_LIGHTS];
-	int light_count=0;
-
-	RenderList *render_list=&opaque_render_list;
-	if (m->fixed_flags[VS::FIXED_MATERIAL_FLAG_USE_ALPHA] || m->blend_mode!=VS::MATERIAL_BLEND_MODE_MIX) {
-		render_list = &alpha_render_list;
-	};
-
-	if (!m->flags[VS::MATERIAL_FLAG_UNSHADED]) {
-
-		int lis = p_instance->light_instances.size();
-
-		for(int i=0;i<lis;i++) {
-			if (light_count>=RenderList::MAX_LIGHTS)
-				break;
-
-			LightInstance *li=light_instance_owner.get( p_instance->light_instances[i] );
-
-			if (!li || li->last_pass!=scene_pass) //lit by light not in visible scene
-				continue;
-			lights[light_count++]=li;
-		}
-	}
-
-	RenderList::Element *e = render_list->add_element();
-
-	e->geometry=p_geometry;
-//	e->geometry_cmp=p_geometry_cmp;
-	e->material=m;
-	e->instance=p_instance;
-	//e->depth=camera_plane.distance_to(p_world->origin);
-	e->depth=camera_transform.origin.distance_to(p_instance->transform.origin);
-	e->owner=p_owner;
-	if (p_instance->skeleton.is_valid())
-		e->skeleton=skeleton_owner.get(p_instance->skeleton);
-	else
-		e->skeleton=NULL;
-	e->mirror=p_instance->mirror;
-	if (m->flags[VS::MATERIAL_FLAG_INVERT_FACES])
-		e->mirror=!e->mirror;
-
-	e->light_key=0;
-	e->light_count=0;
-
-
-	if (!shadow) {
-
-
-		if (m->flags[VS::MATERIAL_FLAG_UNSHADED]) {
-
-
-			e->light_key--; //special key for all the shadeless people
-		} else if (light_count) {
-
-			for(int i=0;i<light_count;i++) {
-
-				e->lights[i]=lights[i]->sort_key;			
-			}
-
-			e->light_count=light_count;
-			int poslight_count=light_count;
-			if (poslight_count>1) {
-				SortArray<uint16_t> light_sort;
-				light_sort.sort(&e->lights[0],poslight_count); //generate an equal sort key
-			}
-		}
-
-	}
-
-}
-
-
-void RasterizerGLES1::add_mesh( const RID& p_mesh, const InstanceData *p_data) {
-
-	Mesh *mesh = mesh_owner.get(p_mesh);
-	ERR_FAIL_COND(!mesh);
-
-	int ssize = mesh->surfaces.size();
-
-	for (int i=0;i<ssize;i++) {
-
-		Surface *s = mesh->surfaces[i];
-		_add_geometry(s,p_data,s,NULL);
-	}
-
-	mesh->last_pass=frame;
-
-}
-
-void RasterizerGLES1::add_multimesh( const RID& p_multimesh, const InstanceData *p_data){
-
-	MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
-	ERR_FAIL_COND(!multimesh);
-
-	if (!multimesh->mesh.is_valid())
-		return;
-	if (multimesh->elements.empty())
-		return;
-
-	Mesh *mesh = mesh_owner.get(multimesh->mesh);
-	ERR_FAIL_COND(!mesh);
-
-	int surf_count = mesh->surfaces.size();
-	if (multimesh->last_pass!=scene_pass) {
-
-		multimesh->cache_surfaces.resize(surf_count);
-		for(int i=0;i<surf_count;i++) {
-
-			multimesh->cache_surfaces[i].material=mesh->surfaces[i]->material;
-			multimesh->cache_surfaces[i].has_alpha=mesh->surfaces[i]->has_alpha;
-			multimesh->cache_surfaces[i].surface=mesh->surfaces[i];
-		}
-
-		multimesh->last_pass=scene_pass;
-	}
-
-	for(int i=0;i<surf_count;i++) {
-
-		_add_geometry(&multimesh->cache_surfaces[i],p_data,multimesh->cache_surfaces[i].surface,multimesh);
-	}
-
-
-}
-
-void RasterizerGLES1::add_particles( const RID& p_particle_instance, const InstanceData *p_data){
-
-	//print_line("adding particles");
-	ParticlesInstance *particles_instance = particles_instance_owner.get(p_particle_instance);
-	ERR_FAIL_COND(!particles_instance);
-	Particles *p=particles_owner.get( particles_instance->particles );
-	ERR_FAIL_COND(!p);
-
-	_add_geometry(p,p_data,p,particles_instance);
-
-}
-
-
-void RasterizerGLES1::_set_cull(bool p_front,bool p_reverse_cull) {
-
-	bool front = p_front;
-	if (p_reverse_cull)
-		front=!front;
-
-	if (front!=cull_front) {
-
-		glCullFace(front?GL_FRONT:GL_BACK);
-		cull_front=front;
-	}
-}
-
-
-void RasterizerGLES1::_setup_fixed_material(const Geometry *p_geometry,const Material *p_material) {
-
-	if (!shadow) {
-
-		///ambient @TODO offer global ambient group option
-
-		//GLenum side = use_shaders?GL_FRONT:GL_FRONT_AND_BACK;
-		GLenum side = GL_FRONT_AND_BACK;
-
-
-		///diffuse
-		Color diffuse_color=p_material->parameters[VS::FIXED_MATERIAL_PARAM_DIFFUSE];
-		float diffuse_rgba[4]={
-			diffuse_color.r,
-			 diffuse_color.g,
-			  diffuse_color.b,
-			   diffuse_color.a
-		};
-
-		//color array overrides this
-		glColor4f( diffuse_rgba[0],diffuse_rgba[1],diffuse_rgba[2],diffuse_rgba[3]);
-		last_color=diffuse_color;
-		glMaterialfv(side,GL_AMBIENT,diffuse_rgba);
-		glMaterialfv(side,GL_DIFFUSE,diffuse_rgba);
-		//specular
-
-		const Color specular_color=p_material->parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR];
-		float specular_rgba[4]={
-			specular_color.r,
-			specular_color.g,
-			specular_color.b,
-			1.0
-		};
-
-		glMaterialfv(side,GL_SPECULAR,specular_rgba);
-
-		const Color emission=p_material->parameters[VS::FIXED_MATERIAL_PARAM_EMISSION];
-
-
-		float emission_rgba[4]={
-			emission.r,
-			emission.g,
-			emission.b,
-			1.0 //p_material->parameters[VS::FIXED_MATERIAL_PARAM_DETAIL_MIX]
-		};
-
-		glMaterialfv(side,GL_EMISSION,emission_rgba);
-
-		glMaterialf(side,GL_SHININESS,p_material->parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR_EXP]);
-
-		Plane sparams=p_material->parameters[VS::FIXED_MATERIAL_PARAM_SHADE_PARAM];
-		//depth test?
-
-
-	}
-
-
-	if (p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE].is_valid()) {
-
-		Texture *texture = texture_owner.get( p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE] );
-		ERR_FAIL_COND(!texture);
-		glEnable(GL_TEXTURE_2D);
-		glActiveTexture(GL_TEXTURE0);
-		glBindTexture( GL_TEXTURE_2D,texture->tex_id );
-	} else {
-
-		glDisable(GL_TEXTURE_2D);
-	}
-
-}
-
-void RasterizerGLES1::_setup_material(const Geometry *p_geometry,const Material *p_material) {
-
-	if (p_material->flags[VS::MATERIAL_FLAG_DOUBLE_SIDED])
-		glDisable(GL_CULL_FACE);
-	else {
-		glEnable(GL_CULL_FACE);
-	}
-
-/*	if (p_material->flags[VS::MATERIAL_FLAG_WIREFRAME])
-		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
-	else
-		glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);*/
-
-	if (p_material->line_width > 0)
-		glLineWidth(p_material->line_width);
-
-	if (!shadow) {
-
-
-		if (blend_mode!=p_material->blend_mode) {
-			switch(p_material->blend_mode) {
-
-
-				 case VS::MATERIAL_BLEND_MODE_MIX: {
-					//glBlendEquation(GL_FUNC_ADD);
-					glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
-				 } break;
-				 case VS::MATERIAL_BLEND_MODE_ADD: {
-
-					//glBlendEquation(GL_FUNC_ADD);
-					glBlendFunc(GL_SRC_ALPHA,GL_ONE);
-
-				 } break;
-				 case VS::MATERIAL_BLEND_MODE_SUB: {
-
-					//glBlendEquation(GL_FUNC_SUBTRACT);
-					glBlendFunc(GL_SRC_ALPHA,GL_ONE);
-				 } break;
-				case VS::MATERIAL_BLEND_MODE_MUL: {
-					//glBlendEquation(GL_FUNC_ADD);
-					glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
-				} break;
-
-			}
-			blend_mode=p_material->blend_mode;
-		}
-
-		if (lighting!=!p_material->flags[VS::MATERIAL_FLAG_UNSHADED]) {
-			if (p_material->flags[VS::MATERIAL_FLAG_UNSHADED]) {
-				glDisable(GL_LIGHTING);
-			} else {
-				glEnable(GL_LIGHTING);
-			}
-			lighting=!p_material->flags[VS::MATERIAL_FLAG_UNSHADED];
-		}
-
-	}
-
-	bool current_depth_write=p_material->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_ALWAYS; //broken
-	bool current_depth_test=!p_material->flags[VS::MATERIAL_FLAG_ONTOP];
-
-
-	_setup_fixed_material(p_geometry,p_material);
-
-	if (current_depth_write!=depth_write) {
-
-		depth_write=current_depth_write;
-		glDepthMask(depth_write);
-	}
-
-	if (current_depth_test!=depth_test) {
-
-		depth_test=current_depth_test;
-		if (depth_test)
-			glEnable(GL_DEPTH_TEST);
-		else
-			glDisable(GL_DEPTH_TEST);
-	}
-}
-/*
-static const MaterialShaderGLES1::Conditionals _gl_light_version[4][3]={
-	{MaterialShaderGLES1::LIGHT_0_DIRECTIONAL,MaterialShaderGLES1::LIGHT_0_OMNI,MaterialShaderGLES1::LIGHT_0_SPOT},
-	{MaterialShaderGLES1::LIGHT_1_DIRECTIONAL,MaterialShaderGLES1::LIGHT_1_OMNI,MaterialShaderGLES1::LIGHT_1_SPOT},
-	{MaterialShaderGLES1::LIGHT_2_DIRECTIONAL,MaterialShaderGLES1::LIGHT_2_OMNI,MaterialShaderGLES1::LIGHT_2_SPOT},
-	{MaterialShaderGLES1::LIGHT_3_DIRECTIONAL,MaterialShaderGLES1::LIGHT_3_OMNI,MaterialShaderGLES1::LIGHT_3_SPOT}
-};
-
-static const MaterialShaderGLES1::Conditionals _gl_light_shadow[4]={
-	MaterialShaderGLES1::LIGHT_0_SHADOW,
-	MaterialShaderGLES1::LIGHT_1_SHADOW,
-	MaterialShaderGLES1::LIGHT_2_SHADOW,
-	MaterialShaderGLES1::LIGHT_3_SHADOW
-};
-*/
-
-
-void RasterizerGLES1::_setup_light(LightInstance* p_instance, int p_idx) {
-
-	Light* ld = p_instance->base;
-
-//	material_shader.set_conditional(MaterialShaderGLES1::LIGHT_0_DIRECTIONAL, true);
-
-	//material_shader.set_uniform_default(MaterialShaderGLES1::LIGHT_0_DIFFUSE, ld->colors[VS::LIGHT_COLOR_DIFFUSE]);
-	//material_shader.set_uniform_default(MaterialShaderGLES1::LIGHT_0_SPECULAR, ld->colors[VS::LIGHT_COLOR_SPECULAR]);
-	//material_shader.set_uniform_default(MaterialShaderGLES1::LIGHT_0_AMBIENT, ld->colors[VS::LIGHT_COLOR_AMBIENT]);
-
-	GLenum glid = GL_LIGHT0+p_idx;
-
-	Color diff_color = ld->colors[VS::LIGHT_COLOR_DIFFUSE];
-	float emult = ld->vars[VS::LIGHT_PARAM_ENERGY];
-
-	if (ld->type!=VS::LIGHT_DIRECTIONAL)
-		emult*=4.0;
-
-	GLfloat diffuse_sdark[4]={
-		diff_color.r*emult,
-		diff_color.g*emult,
-		diff_color.b*emult,
-		1.0
-	};
-
-	glLightfv(glid , GL_DIFFUSE, diffuse_sdark);
-
-	Color amb_color = Color(0,0,0);
-	GLfloat amb_stexsize[4]={
-		amb_color.r,
-		amb_color.g,
-		amb_color.b,
-		1.0
-	};
-
-	glLightfv(glid , GL_AMBIENT, amb_stexsize );
-
-	Color spec_color = ld->colors[VS::LIGHT_COLOR_SPECULAR];
-	GLfloat spec_op[4]={
-		spec_color.r,
-		spec_color.g,
-		spec_color.b,
-		1.0
-	};
-
-	glLightfv(glid , GL_SPECULAR, spec_op );
-
-	switch(ld->type) {
-
-		case VS::LIGHT_DIRECTIONAL: {
-
-			glMatrixMode(GL_MODELVIEW);
-			glPushMatrix();
-			glLoadIdentity();
-
-			glLightf(glid,GL_CONSTANT_ATTENUATION, 1);
-			glLightf(glid,GL_LINEAR_ATTENUATION, 0);
-			glLightf(glid,GL_QUADRATIC_ATTENUATION,0); // energy
-
-			float lightdir[4]={
-				p_instance->light_vector.x,
-				p_instance->light_vector.y,
-				p_instance->light_vector.z,
-				0.0
-			};
-
-			glLightfv(glid,GL_POSITION,lightdir); //at modelview
-			glLightf(glid,GL_SPOT_CUTOFF,180.0);
-			glLightf(glid,GL_SPOT_EXPONENT, 0);
-
-			float sdir[4]={
-				0,
-				0,
-				-1,
-				0
-			};
-
-			glLightfv(glid,GL_SPOT_DIRECTION,sdir); //at modelview
-
-//			material_shader.set_uniform_default(MaterialShaderGLES1::LIGHT_0_DIRECTION, p_instance->light_vector);
-			glPopMatrix();
-
-		} break;
-
-		case VS::LIGHT_OMNI: {
-
-
-			glLightf(glid,GL_SPOT_CUTOFF,180.0);
-			glLightf(glid,GL_SPOT_EXPONENT, 0);
-
-
-			glLightf(glid,GL_CONSTANT_ATTENUATION, 0);
-			glLightf(glid,GL_LINEAR_ATTENUATION, p_instance->linear_att);
-			glLightf(glid,GL_QUADRATIC_ATTENUATION, 0); // wut?
-
-			glMatrixMode(GL_MODELVIEW);
-			glPushMatrix();
-			glLoadIdentity();
-			float lightpos[4]={
-				p_instance->light_vector.x,
-				p_instance->light_vector.y,
-				p_instance->light_vector.z,
-				1.0
-			};
-
-			glLightfv(glid,GL_POSITION,lightpos); //at modelview
-
-			glPopMatrix();
-
-
-		} break;
-		case VS::LIGHT_SPOT: {
-
-			glLightf(glid,GL_SPOT_CUTOFF, ld->vars[VS::LIGHT_PARAM_SPOT_ANGLE]);
-			glLightf(glid,GL_SPOT_EXPONENT, ld->vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]);
-
-
-			glLightf(glid,GL_CONSTANT_ATTENUATION, 0);
-			glLightf(glid,GL_LINEAR_ATTENUATION, p_instance->linear_att);
-			glLightf(glid,GL_QUADRATIC_ATTENUATION, 0); // wut?
-
-
-			glMatrixMode(GL_MODELVIEW);
-			glPushMatrix();
-			glLoadIdentity();
-			float lightpos[4]={
-				p_instance->light_vector.x,
-				p_instance->light_vector.y,
-				p_instance->light_vector.z,
-				1.0
-			};
-
-			glLightfv(glid,GL_POSITION,lightpos); //at modelview
-
-			float lightdir[4]={
-				p_instance->spot_vector.x,
-				p_instance->spot_vector.y,
-				p_instance->spot_vector.z,
-				1.0
-			};
-
-			glLightfv(glid,GL_SPOT_DIRECTION,lightdir); //at modelview
-
-			glPopMatrix();
-
-
-
-		} break;
-
-		default: break;
-	}
-};
-
-
-
-
-
-void RasterizerGLES1::_setup_lights(const uint16_t * p_lights,int p_light_count) {
-
-	if (shadow)
-		return;
-
-
-
-	for (int i=directional_light_count; i<MAX_HW_LIGHTS; i++) {
-
-		if (i<(directional_light_count+p_light_count)) {
-
-
-			glEnable(GL_LIGHT0 + i);
-			_setup_light(light_instances[p_lights[i]], i);
-
-		} else {
-			glDisable(GL_LIGHT0 + i);
-
-		}
-	}
-
-}
-
-
-
-static const GLenum gl_client_states[] = {
-
-	GL_VERTEX_ARRAY,
-	GL_NORMAL_ARRAY,
-	0, // ARRAY_TANGENT
-	0,//GL_COLOR_ARRAY,
-	GL_TEXTURE_COORD_ARRAY, // ARRAY_TEX_UV
-	0,//GL_TEXTURE_COORD_ARRAY, // ARRAY_TEX_UV2
-	0, // ARRAY_BONES
-	0, // ARRAY_WEIGHTS
-};
-
-static const int gl_texcoord_index[VS::ARRAY_MAX-1] = {
-
-	-1,
-	-1,
-	-1, // ARRAY_TANGENT
-	-1,
-	0, // ARRAY_TEX_UV
-	-1,//1, // ARRAY_TEX_UV2
-	-1, // ARRAY_BONES
-	-1, // ARRAY_WEIGHTS
-};
-
-
-Error RasterizerGLES1::_setup_geometry(const Geometry *p_geometry, const Material* p_material, const Skeleton *p_skeleton,const float *p_morphs) {
-
-
-	switch(p_geometry->type) {
-
-		case Geometry::GEOMETRY_MULTISURFACE:
-		case Geometry::GEOMETRY_SURFACE: {
-
-
-
-			const Surface *surf=NULL;
-			if (p_geometry->type==Geometry::GEOMETRY_SURFACE)
-				surf=static_cast<const Surface*>(p_geometry);
-			else if (p_geometry->type==Geometry::GEOMETRY_MULTISURFACE)
-				surf=static_cast<const MultiMeshSurface*>(p_geometry)->surface;
-
-
-			if (surf->format != surf->configured_format) {
-				if (OS::get_singleton()->is_stdout_verbose()) {
-
-					print_line("has format: "+itos(surf->format));
-					print_line("configured format: "+itos(surf->configured_format));
-				}
-				ERR_EXPLAIN("Missing arrays (not set) in surface");
-			}
-			ERR_FAIL_COND_V( surf->format != surf->configured_format, ERR_UNCONFIGURED );
-			uint8_t *base=0;
-			int stride=surf->stride;
-			bool use_VBO = (surf->array_local==0);
-			_setup_geometry_vinfo=surf->array_len;
-
-			bool skeleton_valid = p_skeleton && (surf->format&VS::ARRAY_FORMAT_BONES) && (surf->format&VS::ARRAY_FORMAT_WEIGHTS) && !p_skeleton->bones.empty() && p_skeleton->bones.size() > surf->max_bone;
-
-
-
-			if (!use_VBO) {
-
-				base = surf->array_local;
-				glBindBuffer(GL_ARRAY_BUFFER, 0);
-				bool can_copy_to_local=surf->local_stride * surf->array_len <= skinned_buffer_size;
-				if (!can_copy_to_local)
-					skeleton_valid=false;
-
-				/* compute morphs */
-
-				if (p_morphs && surf->morph_target_count && can_copy_to_local) {
-
-					base = skinned_buffer;
-					stride=surf->local_stride;
-
-					//copy all first
-					float coef=1.0;
-
-					for(int i=0;i<surf->morph_target_count;i++) {
-						if (surf->mesh->morph_target_mode==VS::MORPH_MODE_NORMALIZED)
-							coef-=p_morphs[i];
-						ERR_FAIL_COND_V( surf->morph_format != surf->morph_targets_local[i].configured_format, ERR_INVALID_DATA );
-
-					}
-
-
-					for(int i=0;i<VS::ARRAY_MAX-1;i++) {
-
-						const Surface::ArrayData& ad=surf->array[i];
-						if (ad.size==0)
-							continue;
-
-						int ofs = ad.ofs;
-						int src_stride=surf->stride;
-						int dst_stride=surf->local_stride;
-						int count = surf->array_len;
-
-						switch(i) {
-
-							case VS::ARRAY_VERTEX:
-							case VS::ARRAY_NORMAL:
-							case VS::ARRAY_TANGENT:
-								{
-
-								for(int k=0;k<count;k++) {
-
-									const float *src = (const float*)&surf->array_local[ofs+k*src_stride];
-									float *dst = (float*)&base[ofs+k*dst_stride];
-
-									dst[0]= src[0]*coef;
-									dst[1]= src[1]*coef;
-									dst[2]= src[2]*coef;
-								} break;
-
-							} break;
-							case VS::ARRAY_TEX_UV:
-							case VS::ARRAY_TEX_UV2: {
-
-								for(int k=0;k<count;k++) {
-
-									const float *src = (const float*)&surf->array_local[ofs+k*src_stride];
-									float *dst = (float*)&base[ofs+k*dst_stride];
-
-									dst[0]= src[0]*coef;
-									dst[1]= src[1]*coef;
-								} break;
-
-							} break;
-						}
-					}
-
-
-					for(int j=0;j<surf->morph_target_count;j++) {
-
-						for(int i=0;i<VS::ARRAY_MAX-1;i++) {
-
-							const Surface::ArrayData& ad=surf->array[i];
-							if (ad.size==0)
-								continue;
-
-
-							int ofs = ad.ofs;
-							int dst_stride=surf->local_stride;
-							int count = surf->array_len;
-							const uint8_t *morph=surf->morph_targets_local[j].array;
-							float w = p_morphs[j];
-
-							switch(i) {
-
-								case VS::ARRAY_VERTEX:
-								case VS::ARRAY_NORMAL:
-								case VS::ARRAY_TANGENT:
-									{
-
-									for(int k=0;k<count;k++) {
-
-										const float *src_morph = (const float*)&morph[ofs+k*dst_stride];
-										float *dst = (float*)&base[ofs+k*dst_stride];
-
-										dst[0]+= src_morph[0]*w;
-										dst[1]+= src_morph[1]*w;
-										dst[2]+= src_morph[2]*w;
-									} break;
-
-								} break;
-								case VS::ARRAY_TEX_UV:
-								case VS::ARRAY_TEX_UV2: {
-
-									for(int k=0;k<count;k++) {
-
-										const float *src_morph = (const float*)&morph[ofs+k*dst_stride];
-										float *dst = (float*)&base[ofs+k*dst_stride];
-
-										dst[0]+= src_morph[0]*w;
-										dst[1]+= src_morph[1]*w;
-									} break;
-
-								} break;
-							}
-						}
-					}
-
-				} else if (skeleton_valid) {
-
-					base = skinned_buffer;
-					//copy stuff and get it ready for the skeleton
-
-					int len = surf->array_len;
-					int src_stride = surf->stride;
-					int dst_stride = surf->stride - ( surf->array[VS::ARRAY_BONES].size + surf->array[VS::ARRAY_WEIGHTS].size );
-
-					for(int i=0;i<len;i++) {
-						const uint8_t *src = &surf->array_local[i*src_stride];
-						uint8_t *dst = &base[i*dst_stride];
-						memcpy(dst,src,dst_stride);
-					}
-
-
-					stride=dst_stride;
-				}
-
-
-				if (skeleton_valid) {
-					//transform stuff
-
-					const uint8_t *src_weights=&surf->array_local[surf->array[VS::ARRAY_WEIGHTS].ofs];
-					const uint8_t *src_bones=&surf->array_local[surf->array[VS::ARRAY_BONES].ofs];
-					int src_stride = surf->stride;
-					int count = surf->array_len;
-					const Transform *skeleton = &p_skeleton->bones[0];
-
-					for(int i=0;i<VS::ARRAY_MAX-1;i++) {
-
-						const Surface::ArrayData& ad=surf->array[i];
-						if (ad.size==0)
-							continue;
-
-						int ofs = ad.ofs;
-
-
-						switch(i) {
-
-							case VS::ARRAY_VERTEX: {
-								for(int k=0;k<count;k++) {
-
-									float *ptr=  (float*)&base[ofs+k*stride];
-									const GLfloat* weights = reinterpret_cast<const GLfloat*>(&src_weights[k*src_stride]);
-									const GLfloat *bones = reinterpret_cast<const GLfloat*>(&src_bones[k*src_stride]);
-
-									Vector3 src( ptr[0], ptr[1], ptr[2] );
-									Vector3 dst;
-									for(int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
-
-										float w = weights[j];
-										if (w==0)
-											break;
-
-										//print_line("accum "+itos(i)+" += "+rtos(Math::ftoi(bones[j]))+" * "+skeleton[ Math::ftoi(bones[j]) ]+" * "+rtos(w));
-										dst+=skeleton[ Math::fast_ftoi(bones[j]) ].xform(src) * w;
-									}
-
-									ptr[0]=dst.x;
-									ptr[1]=dst.y;
-									ptr[2]=dst.z;
-
-								} break;
-
-							} break;
-							case VS::ARRAY_NORMAL:
-							case VS::ARRAY_TANGENT: {
-								for(int k=0;k<count;k++) {
-
-									float *ptr=  (float*)&base[ofs+k*stride];
-									const GLfloat* weights = reinterpret_cast<const GLfloat*>(&src_weights[k*src_stride]);
-									const GLfloat *bones = reinterpret_cast<const GLfloat*>(&src_bones[k*src_stride]);
-
-									Vector3 src( ptr[0], ptr[1], ptr[2] );
-									Vector3 dst;
-									for(int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
-
-										float w = weights[j];
-										if (w==0)
-											break;
-
-										//print_line("accum "+itos(i)+" += "+rtos(Math::ftoi(bones[j]))+" * "+skeleton[ Math::ftoi(bones[j]) ]+" * "+rtos(w));
-										dst+=skeleton[ Math::fast_ftoi(bones[j]) ].basis.xform(src) * w;
-									}
-
-									ptr[0]=dst.x;
-									ptr[1]=dst.y;
-									ptr[2]=dst.z;
-
-								} break;
-
-							} break;
-						}
-					}
-
-				}
-
-			} else {
-
-				glBindBuffer(GL_ARRAY_BUFFER, surf->vertex_id);
-			};
-
-
-			for (int i=0;i<(VS::ARRAY_MAX-1);i++) {
-
-				const Surface::ArrayData& ad=surf->array[i];
-
-//				if (!gl_texcoord_shader[i])
-//					continue;
-
-				if (ad.size==0 || i==VS::ARRAY_BONES || i==VS::ARRAY_WEIGHTS || gl_client_states[i]==0 ) {
-
-					if (gl_texcoord_index[i] != -1) {
-						glClientActiveTexture(GL_TEXTURE0+gl_texcoord_index[i]);
-					}
-
-					if (gl_client_states[i] != 0)
-						glDisableClientState(gl_client_states[i]);
-
-					if (i == VS::ARRAY_COLOR) {
-						glColor4f(last_color.r,last_color.g,last_color.b,last_color.a);
-					};
-					continue; // this one is disabled.
-				}
-
-				if (gl_texcoord_index[i] != -1) {
-					glClientActiveTexture(GL_TEXTURE0+gl_texcoord_index[i]);
-				}
-
-				glEnableClientState(gl_client_states[i]);
-
-				switch (i) {
-
-				case VS::ARRAY_VERTEX: {
-
-					glVertexPointer(3,ad.datatype,stride,&base[ad.ofs]);
-
-				} break; /* fallthrough to normal */
-				case VS::ARRAY_NORMAL: {
-
-					glNormalPointer(ad.datatype,stride,&base[ad.ofs]);
-				} break;
-				case VS::ARRAY_COLOR: {
-					glColorPointer(4,ad.datatype,stride,&base[ad.ofs]);
-				} break;
-				case VS::ARRAY_TEX_UV:
-				case VS::ARRAY_TEX_UV2: {
-
-					glTexCoordPointer(2,ad.datatype,stride,&base[ad.ofs]);
-				} break;
-				case VS::ARRAY_TANGENT: {
-
-					//glVertexAttribPointer(i, 4, use_VBO?GL_BYTE:GL_FLOAT, use_VBO?GL_TRUE:GL_FALSE, stride, &base[ad.ofs]);
-
-				} break;
-				case VS::ARRAY_BONES:
-				case VS::ARRAY_WEIGHTS: {
-
-					//do none
-					//glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, surf->stride, &base[ad.ofs]);
-
-				} break;
-				case VS::ARRAY_INDEX:
-					ERR_PRINT("Bug");
-					break;
-				};
-			}
-
-
-		} break;
-
-		default: break;
-
-	};
-
-	return OK;
-};
-
-static const GLenum gl_primitive[]={
-	GL_POINTS,
-	GL_LINES,
-	GL_LINE_STRIP,
-	GL_LINE_LOOP,
-	GL_TRIANGLES,
-	GL_TRIANGLE_STRIP,
-	GL_TRIANGLE_FAN
-};
-
-static const GLenum gl_poly_primitive[4]={
-	GL_POINTS,
-	GL_LINES,
-	GL_TRIANGLES,
-	//GL_QUADS
-
-};
-
-
-void RasterizerGLES1::_render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton, const GeometryOwner *p_owner) {
-
-
-	_rinfo.object_count++;
-
-	switch(p_geometry->type) {
-
-		case Geometry::GEOMETRY_SURFACE: {
-
-			Surface *s = (Surface*)p_geometry;
-
-			_rinfo.vertex_count+=s->array_len;
-
-			if (s->packed && s->array_local==0) {
-
-				float sc = (1.0/32767.0)*s->vertex_scale;
-
-				glMatrixMode(GL_MODELVIEW);
-				glPushMatrix();
-				glScalef(sc,sc,sc);
-				if (s->format&VS::ARRAY_FORMAT_TEX_UV) {
-					float uvs=(1.0/32767.0)*s->uv_scale;
-					//glActiveTexture(GL_TEXTURE0);
-					glClientActiveTexture(GL_TEXTURE0);
-					glMatrixMode(GL_TEXTURE);
-					glPushMatrix();
-					glScalef(uvs,uvs,uvs);
-				}
-
-
-			}
-
-
-			if (s->index_array_len>0) {
-
-				if (s->index_array_local) {
-
-					glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
-					glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_SHORT:GL_UNSIGNED_SHORT, s->index_array_local);
-
-				} else {
-				//	print_line("indices: "+itos(s->index_array_local) );
-
-					glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
-					glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_SHORT:GL_UNSIGNED_SHORT,0);
-				}
-
-
-			} else {
-
-				glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
-
-			};
-
-			if (s->packed && s->array_local==0) {
-				if (s->format&VS::ARRAY_FORMAT_TEX_UV) {
-					glPopMatrix();
-					glMatrixMode(GL_MODELVIEW);
-				}
-				glPopMatrix();
-			};
-		} break;
-
-		case Geometry::GEOMETRY_MULTISURFACE: {
-
-			Surface *s = static_cast<const MultiMeshSurface*>(p_geometry)->surface;
-			const MultiMesh *mm = static_cast<const MultiMesh*>(p_owner);
-			int element_count=mm->elements.size();
-
-			if (element_count==0)
-				return;
-
-			const MultiMesh::Element *elements=&mm->elements[0];
-
-			_rinfo.vertex_count+=s->array_len*element_count;
-
-
-			if (s->index_array_len>0) {
-
-
-				glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id);
-				for(int i=0;i<element_count;i++) {
-					//glUniformMatrix4fv(material_shader.get_uniform_location(MaterialShaderGLES1::INSTANCE_TRANSFORM), 1, false, elements[i].matrix);
-					glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>(1<<16))?GL_UNSIGNED_SHORT:GL_UNSIGNED_SHORT,0);
-				}
-
-
-			} else {
-
-				for(int i=0;i<element_count;i++) {
-//					glUniformMatrix4fv(material_shader.get_uniform_location(MaterialShaderGLES1::INSTANCE_TRANSFORM), 1, false, elements[i].matrix);
-					glDrawArrays(gl_primitive[s->primitive],0,s->array_len);
-				}
-
-
-			 };
-		 } break;
-		case Geometry::GEOMETRY_PARTICLES: {
-
-
-			//print_line("particulinas");
-			const Particles *particles = static_cast<const Particles*>( p_geometry );
-			ERR_FAIL_COND(!p_owner);
-			ParticlesInstance *particles_instance = (ParticlesInstance*)p_owner;
-
-			ParticleSystemProcessSW &pp = particles_instance->particles_process;
-			float td = time_delta; //MIN(time_delta,1.0/10.0);
-			pp.process(&particles->data,particles_instance->transform,td);
-			ERR_EXPLAIN("A parameter in the particle system is not correct.");
-			ERR_FAIL_COND(!pp.valid);
-			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-			glBindBuffer(GL_ARRAY_BUFFER,0);
-
-
-			Transform camera;
-			if (shadow)
-				camera=shadow->transform;
-			else
-				camera=camera_transform;
-
-			particle_draw_info.prepare(&particles->data,&pp,particles_instance->transform,camera);
-
-			_rinfo.vertex_count+=4*particles->data.amount;
-
-			{
-				static const Vector3 points[4]={
-					Vector3(-1.0,1.0,0),
-					Vector3(1.0,1.0,0),
-					Vector3(1.0,-1.0,0),
-					Vector3(-1.0,-1.0,0)
-				};
-				static const Vector3 uvs[4]={
-					Vector3(0.0,0.0,0.0),
-					Vector3(1.0,0.0,0.0),
-					Vector3(1.0,1.0,0.0),
-					Vector3(0,1.0,0.0)
-				};
-				static const Vector3 normals[4]={
-					Vector3(0,0,1),
-					Vector3(0,0,1),
-					Vector3(0,0,1),
-					Vector3(0,0,1)
-				};
-
-				static const Plane tangents[4]={
-					Plane(Vector3(1,0,0),0),
-					Plane(Vector3(1,0,0),0),
-					Plane(Vector3(1,0,0),0),
-					Plane(Vector3(1,0,0),0)
-				};
-
-
-				glMatrixMode(GL_MODELVIEW);
-				glPushMatrix();
-				_gl_load_transform(camera_transform_inverse);
-				for(int i=0;i<particles->data.amount;i++) {
-
-					ParticleSystemDrawInfoSW::ParticleDrawInfo &pinfo=*particle_draw_info.draw_info_order[i];
-					if (!pinfo.data->active)
-						continue;
-					glPushMatrix();
-					_gl_mult_transform(pinfo.transform);
-
-					glColor4f(pinfo.color.r*last_color.r,pinfo.color.g*last_color.g,pinfo.color.b*last_color.b,pinfo.color.a*last_color.a);
-					_draw_primitive(4,points,normals,NULL,uvs,tangents);
-					glPopMatrix();
-
-				}
-				glPopMatrix();
-
-			}
-
-		} break;
-		 default: break;
-	};
-
-};
-
-void RasterizerGLES1::_setup_shader_params(const Material *p_material) {
-#if 0
-	int idx=0;
-	int tex_idx=0;
-
-	for(Map<StringName,Variant>::Element *E=p_material->shader_cache->params.front();E;E=E->next(),idx++) {
-
-		Variant v; //
-		v = E->get();
-		const Map<StringName,Variant>::Element *F=p_material->shader_params.find(E->key());
-		if (F)
-			v=F->get();
-
-		switch(v.get_type() ) {
-			case Variant::OBJECT:
-			case Variant::_RID: {
-
-				RID tex=v;
-				if (!tex.is_valid())
-					break;
-
-				Texture *texture = texture_owner.get(tex);
-				if (!texture)
-					break;
-				glUniform1i( material_shader.get_custom_uniform_location(idx), tex_idx);
-				glActiveTexture(tex_idx);
-				glBindTexture(texture->target,texture->tex_id);
-
-			} break;
-			case Variant::COLOR: {
-
-				Color c=v;
-				material_shader.set_custom_uniform(idx,Vector3(c.r,c.g,c.b));
-			} break;
-			default: {
-
-				material_shader.set_custom_uniform(idx,v);
-			} break;
-		}
-
-	}
-#endif
-
-}
-
-void RasterizerGLES1::_render_list_forward(RenderList *p_render_list,bool p_reverse_cull) {
-
-	const Material *prev_material=NULL;
-	uint64_t prev_light_key=0;
-	const Skeleton *prev_skeleton=NULL;
-	const Geometry *prev_geometry=NULL;
-
-	Geometry::Type prev_geometry_type=Geometry::GEOMETRY_INVALID;
-
-	for (int i=0;i<p_render_list->element_count;i++) {
-
-		RenderList::Element *e = p_render_list->elements[i];
-		const Material *material = e->material;
-		uint64_t light_key = e->light_key;
-		const Skeleton *skeleton = e->skeleton;
-		const Geometry *geometry = e->geometry;
-
-		if (material!=prev_material || geometry->type!=prev_geometry_type) {
-			_setup_material(e->geometry,material);
-			_rinfo.mat_change_count++;
-			//_setup_material_overrides(e->material,NULL,material_overrides);
-			//_setup_material_skeleton(material,skeleton);
-		} else {
-
-			if (prev_skeleton!=skeleton) {
-				//_setup_material_skeleton(material,skeleton);
-			};
-		}
-
-
-		if (geometry!=prev_geometry || geometry->type!=prev_geometry_type  || prev_skeleton!=skeleton) {
-
-			_setup_geometry(geometry, material,e->skeleton,e->instance->morph_values.ptr());
-		};
-
-		if (i==0 || light_key!=prev_light_key)
-			_setup_lights(e->lights,e->light_count);
-
-		_set_cull(e->mirror,p_reverse_cull);
-
-		glMatrixMode(GL_MODELVIEW);
-		glPopMatrix();
-		glPushMatrix();
-
-
-		if (e->instance->billboard || e->instance->depth_scale) {
-
-			Transform xf=e->instance->transform;
-			if (e->instance->depth_scale) {
-
-				if (camera_projection.matrix[3][3]) {
-					//orthogonal matrix, try to do about the same
-					//with viewport size
-					//real_t w = Math::abs( 1.0/(2.0*(p_projection.matrix[0][0])) );
-					real_t h = Math::abs( 1.0/(2.0*camera_projection.matrix[1][1]) );
-					float sc = (h*2.0); //consistent with Y-fov
-					xf.basis.scale( Vector3(sc,sc,sc));
-				} else {
-					//just scale by depth
-					real_t sc = -camera_plane.distance_to(xf.origin);
-					xf.basis.scale( Vector3(sc,sc,sc));
-				}
-			}
-
-			if (e->instance->billboard) {
-
-				Vector3 scale = xf.basis.get_scale();
-				xf.set_look_at(xf.origin,xf.origin+camera_transform.get_basis().get_axis(2),camera_transform.get_basis().get_axis(1));
-				xf.basis.scale(scale);
-			}
-			_gl_mult_transform(xf); // for fixed pipeline
-
-		} else {
-			_gl_mult_transform(e->instance->transform); // for fixed pipeline
-		}
-
-
-
-		//bool changed_shader = material_shader.bind();
-		//if ( changed_shader && material->shader_cache && !material->shader_cache->params.empty())
-		//	_setup_shader_params(material);
-
-		_render(geometry, material, skeleton,e->owner);
-
-
-
-		prev_material=material;
-		prev_skeleton=skeleton;
-		prev_geometry=geometry;
-		prev_light_key=e->light_key;
-		prev_geometry_type=geometry->type;
-	}
-
-
-
-};
-
-
-
-void RasterizerGLES1::end_scene() {
-
-	glEnable(GL_BLEND);
-	glDepthMask(GL_TRUE);
-	glEnable(GL_DEPTH_TEST);
-	glDisable(GL_SCISSOR_TEST);
-	depth_write=true;
-	depth_test=true;
-
-	if (scene_fx && scene_fx->skybox_active) {
-
-		//skybox
-	} else if (scene_fx && scene_fx->bgcolor_active) {
-
-		glClearColor(scene_fx->bgcolor.r,scene_fx->bgcolor.g,scene_fx->bgcolor.b,1.0);
-
-	} else {
-
-		glClearColor(0.3,0.3,0.3,1.0);
-	}
-#ifdef GLES_OVER_GL
-	//glClearDepth(1.0);
-#else
-	//glClearDepthf(1.0);
-#endif
-
-	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-
-	if (scene_fx && scene_fx->fog_active) {
-
-		/*
-		glEnable(GL_FOG);
-		glFogf(GL_FOG_MODE,GL_LINEAR);
-		glFogf(GL_FOG_DENSITY,scene_fx->fog_attenuation);
-		glFogf(GL_FOG_START,scene_fx->fog_near);
-		glFogf(GL_FOG_END,scene_fx->fog_far);
-		glFogfv(GL_FOG_COLOR,scene_fx->fog_color_far.components);
-		glLightfv(GL_LIGHT5,GL_DIFFUSE,scene_fx->fog_color_near.components);
-
-		material_shader.set_conditional( MaterialShaderGLES1::USE_FOG,true);
-		*/
-	}
-
-
-
-	for(int i=0;i<directional_light_count;i++) {
-
-		glEnable(GL_LIGHT0+i);
-		_setup_light(directional_lights[i],i);
-	}
-
-	opaque_render_list.sort_mat_light();
-
-	//material_shader.set_uniform_camera(MaterialShaderGLES1::PROJECTION_MATRIX, camera_projection);
-
-	/*
-	printf("setting projection to ");
-	for (int i=0; i<16; i++) {
-		printf("%f, ", ((float*)camera_projection.matrix)[i]);
-	};
-	printf("\n");
-
-	print_line(String("setting camera to ")+camera_transform_inverse);
-	*/
-//	material_shader.set_uniform_default(MaterialShaderGLES1::CAMERA_INVERSE, camera_transform_inverse);
-
-	//projection
-	//glEnable(GL_RESCALE_NORMAL);
-	glEnable(GL_NORMALIZE);
-
-	glMatrixMode(GL_PROJECTION);
-	glLoadMatrixf(&camera_projection.matrix[0][0]);
-	//modelview (fixedpipie)
-	glMatrixMode(GL_MODELVIEW);
-	_gl_load_transform(camera_transform_inverse);
-	glPushMatrix();
-
-	glDisable(GL_BLEND);
-
-	blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
-	lighting=true;
-	glEnable(GL_LIGHTING);
-	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
-	_render_list_forward(&opaque_render_list);
-
-
-	alpha_render_list.sort_z();
-	glEnable(GL_BLEND);
-
-	_render_list_forward(&alpha_render_list);
-
-	glPopMatrix();
-
-
-//	material_shader.set_conditional( MaterialShaderGLES1::USE_FOG,false);
-
-	_debug_shadows();
-}
-void RasterizerGLES1::end_shadow_map() {
-#if 0
-	ERR_FAIL_COND(!shadow);
-	ERR_FAIL_INDEX(shadow_pass,shadow->shadow_buffers.size());
-
-	glDisable(GL_BLEND);
-	glDisable(GL_SCISSOR_TEST);
-	glEnable(GL_DEPTH_TEST);
-	glDepthMask(true);
-
-
-	ShadowBuffer *sb = shadow->shadow_buffers[shadow_pass];
-
-	ERR_FAIL_COND(!sb);
-
-	glBindFramebuffer(GL_FRAMEBUFFER, sb->fbo);
-	glViewport(0, 0, sb->size, sb->size);
-
-	glColorMask(0, 0, 0, 0);
-
-	glEnable(GL_POLYGON_OFFSET_FILL);
-	//glPolygonOffset(4,8);
-	glPolygonOffset( 4.0f, 4096.0f);
-	glPolygonOffset( 8.0f, 16.0f);
-
-	glClearDepth(1.0f);
-	glClear(GL_DEPTH_BUFFER_BIT);
-	CameraMatrix cm;
-	float z_near,z_far;
-	Transform light_transform;
-
-	float dp_direction=0.0;
-	bool flip_facing=false;
-
-	switch(shadow->base->type) {
-
-		case VS::LIGHT_DIRECTIONAL: {
-
-			cm = shadow->custom_projection;
-			light_transform=shadow->custom_transform;
-			z_near=cm.get_z_near();
-			z_far=cm.get_z_far();
-
-		} break;
-		case VS::LIGHT_OMNI: {
-
-			material_shader.set_conditional(MaterialShaderGLES1::USE_DUAL_PARABOLOID,true);
-			dp_direction = shadow_pass?1.0:0.0;
-			flip_facing = (shadow_pass == 1);
-			light_transform=shadow->transform;
-			z_near=0;
-			z_far=shadow->base->vars[ VS::LIGHT_VAR_RADIUS ];
-		} break;
-		case VS::LIGHT_SPOT: {
-
-			float far = shadow->base->vars[ VS::LIGHT_VAR_RADIUS ];
-			ERR_FAIL_COND( far<=0 );
-			float near= far/200.0;
-			if (near<0.05)
-			 near=0.05;
-
-			float angle = shadow->base->vars[ VS::LIGHT_VAR_SPOT_ANGLE ];
-
-			cm.set_perspective( angle*2.0, 1.0, near, far );
-			shadow->projection=cm; // cache
-			light_transform=shadow->transform;
-			z_near=cm.get_z_near();
-			z_far=cm.get_z_far();
-
-		} break;
-	}
-
-	Transform light_transform_inverse = light_transform.inverse();
-
-	opaque_render_list.sort_mat();
-
-	glLightf(GL_LIGHT5,GL_LINEAR_ATTENUATION,z_near);
-	glLightf(GL_LIGHT5,GL_QUADRATIC_ATTENUATION,z_far);
-	glLightf(GL_LIGHT5,GL_CONSTANT_ATTENUATION,dp_direction);
-
-	glMatrixMode(GL_PROJECTION);
-	glLoadMatrixf(&cm.matrix[0][0]);
-	glMatrixMode(GL_MODELVIEW);
-	_gl_load_transform(light_transform_inverse);
-	glPushMatrix();
-
-	for(int i=0;i<4;i++) {
-		for(int j=0;j<3;j++) {
-
-			material_shader.set_conditional(_gl_light_version[i][j],false); //start false by default
-		}
-		material_shader.set_conditional(_gl_light_shadow[i],false);
-	}
-
-	_render_list_forward(&opaque_render_list,flip_facing);
-
-	material_shader.set_conditional(MaterialShaderGLES1::USE_DUAL_PARABOLOID,false);
-	glViewport( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height );
-	if (framebuffer.active)
-		glBindFramebufferEXT(GL_FRAMEBUFFER,framebuffer.fbo);
-	else
-		glBindFramebufferEXT(GL_FRAMEBUFFER,0);
-
-	glDisable(GL_POLYGON_OFFSET_FILL);
-
-	glColorMask(1, 1, 1, 1);
-	shadow=NULL;
-#endif
-}
-
-void RasterizerGLES1::_debug_draw_shadow(ShadowBuffer *p_buffer, const Rect2& p_rect) {
-
-/*
-
-	Transform modelview;
-	modelview.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
-	modelview.scale( Vector3( 2.0f / viewport.width, -2.0f / viewport.height, 1.0f ) );
-	modelview.translate(p_rect.pos.x, p_rect.pos.y, 0);
-	material_shader.set_uniform_default(MaterialShaderGLES1::MODELVIEW_TRANSFORM, *e->transform);
-	glBindTexture(GL_TEXTURE_2D,p_buffer->depth);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
-
-	Vector3 coords[4]= {
-		Vector3(p_rect.pos.x, p_rect.pos.y, 0 ),
-		Vector3(p_rect.pos.x+p_rect.size.width,
-		p_rect.pos.y, 0 ),
-		Vector3(p_rect.pos.x+p_rect.size.width,
-		p_rect.pos.y+p_rect.size.height, 0 ),
-		Vector3(p_rect.pos.x,
-		p_rect.pos.y+p_rect.size.height, 0 )
-	};
-
-	Vector3 texcoords[4]={
-		Vector3( 0.0f,0.0f, 0),
-		Vector3( 1.0f,0.0f, 0),
-		Vector3( 1.0f, 1.0f, 0),
-		Vector3( 0.0f, 1.0f, 0),
-	};
-
-	_draw_primitive(4,coords,0,0,texcoords);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
-*/
-}
-
-void RasterizerGLES1::_debug_draw_shadows_type(Vector<ShadowBuffer>& p_shadows,Point2& ofs) {
-
-
-//	Size2 debug_size(128,128);
-	Size2 debug_size(512,512);
-
-	for (int i=0;i<p_shadows.size();i++) {
-
-		ShadowBuffer *sb=&p_shadows[i];
-
-		if (!sb->owner)
-			continue;
-
-		if (sb->owner->base->type==VS::LIGHT_DIRECTIONAL) {
-
-			if (sb->owner->shadow_pass!=scene_pass-1)
-				continue;
-		} else {
-
-			if (sb->owner->shadow_pass!=frame)
-				continue;
-		}
-		_debug_draw_shadow(sb, Rect2( ofs, debug_size ));
-		ofs.x+=debug_size.x;
-		if ( (ofs.x+debug_size.x) > viewport.width ) {
-
-			ofs.x=0;
-			ofs.y+=debug_size.y;
-		}
-	}
-
-}
-
-
-void RasterizerGLES1::_debug_shadows() {
-
-	return;
-#if 0
-	canvas_begin();
-	glUseProgram(0);
-	glDisable(GL_BLEND);
-	Size2 ofs;
-
-	/*
-	for(int i=0;i<16;i++) {
-		glActiveTexture(GL_TEXTURE0+i);
-		//glDisable(GL_TEXTURE_2D);
-	}
-	glActiveTexture(GL_TEXTURE0);
-	//glEnable(GL_TEXTURE_2D);
-	*/
-
-
-	_debug_draw_shadows_type(near_shadow_buffers,ofs);
-	_debug_draw_shadows_type(far_shadow_buffers,ofs);
-#endif
-}
-
-void RasterizerGLES1::end_frame() {
-
-	/*
-	if (framebuffer.active) {
-
-		canvas_begin(); //resets stuff and goes back to fixedpipe
-		glBindFramebuffer(GL_FRAMEBUFFER,0);
-
-		//copy to main bufferz
-		glEnable(GL_TEXTURE_2D);
-		
-		glBindTexture(GL_TEXTURE_2D,framebuffer.color);		
-		glBegin(GL_QUADS);
-		glTexCoord2f(0,0);
-		glVertex2f(-1,-1);
-		glTexCoord2f(0,1);
-		glVertex2f(-1,+1);
-		glTexCoord2f(1,1);
-		glVertex2f(+1,+1);
-		glTexCoord2f(1,0);
-		glVertex2f(+1,-1);
-		glEnd();
-
-
-	}
-	*/
-
-	//print_line("VTX: "+itos(_rinfo.vertex_count)+" OBJ: "+itos(_rinfo.object_count)+" MAT: "+itos(_rinfo.mat_change_count)+" SHD: "+itos(_rinfo.shader_change_count));
-
-	OS::get_singleton()->swap_buffers();
-}
-
-/* CANVAS API */
-
-
-void RasterizerGLES1::reset_state() {
-
-
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
-	glBindBuffer(GL_ARRAY_BUFFER,0);
-
-	glActiveTexture(GL_TEXTURE0);
-	glClientActiveTexture(GL_TEXTURE0);
-	glMatrixMode(GL_TEXTURE);
-	glLoadIdentity();
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-	glColor4f(1,1,1,1);
-
-	glDisable(GL_CULL_FACE);
-	glDisable(GL_DEPTH_TEST);
-	glEnable(GL_BLEND);	
-//	glBlendEquation(GL_FUNC_ADD);
-	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-//	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
-	canvas_blend=VS::MATERIAL_BLEND_MODE_MIX;
-	glLineWidth(1.0);
-	glDisable(GL_LIGHTING);
-
-}
-
-_FORCE_INLINE_ static void _set_glcoloro(const Color& p_color,const float p_opac) {
-
-	glColor4f(p_color.r, p_color.g, p_color.b, p_color.a*p_opac);
-}
-
-
-void RasterizerGLES1::canvas_begin() {
-
-
-	reset_state();
-	canvas_opacity=1.0;
-	glEnable(GL_BLEND);
-
-
-}
-
-void RasterizerGLES1::canvas_disable_blending() {
-
-	glDisable(GL_BLEND);
-}
-
-void RasterizerGLES1::canvas_set_opacity(float p_opacity) {
-
-	canvas_opacity = p_opacity;
-}
-
-void RasterizerGLES1::canvas_set_blend_mode(VS::MaterialBlendMode p_mode) {
-
-	switch(p_mode) {
-
-		 case VS::MATERIAL_BLEND_MODE_MIX: {
-			//glBlendEquation(GL_FUNC_ADD);
-			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
-		 } break;
-		 case VS::MATERIAL_BLEND_MODE_ADD: {
-
-			//glBlendEquation(GL_FUNC_ADD);
-			glBlendFunc(GL_SRC_ALPHA,GL_ONE);
-
-		 } break;
-		 case VS::MATERIAL_BLEND_MODE_SUB: {
-
-			//glBlendEquation(GL_FUNC_SUBTRACT);
-			glBlendFunc(GL_SRC_ALPHA,GL_ONE);
-		 } break;
-		case VS::MATERIAL_BLEND_MODE_MUL: {
-			//glBlendEquation(GL_FUNC_ADD);
-			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
-		} break;
-
-	}
-
-}
-
-
-void RasterizerGLES1::canvas_begin_rect(const Matrix32& p_transform) {
-
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-	glScalef(2.0 / viewport.width, -2.0 / viewport.height, 0);
-	glTranslatef((-(viewport.width / 2.0)), (-(viewport.height / 2.0)), 0);
-	_gl_mult_transform(p_transform);
-
-	glPushMatrix();
-
-}
-
-void RasterizerGLES1::canvas_set_clip(bool p_clip, const Rect2& p_rect) {
-
-	if (p_clip) {
-
-		glEnable(GL_SCISSOR_TEST);
-	//	glScissor(viewport.x+p_rect.pos.x,viewport.y+ (viewport.height-(p_rect.pos.y+p_rect.size.height)),
-		//p_rect.size.width,p_rect.size.height);
-		//glScissor(p_rect.pos.x,(viewport.height-(p_rect.pos.y+p_rect.size.height)),p_rect.size.width,p_rect.size.height);
-		glScissor(viewport.x+p_rect.pos.x,viewport.y+ (window_size.y-(p_rect.pos.y+p_rect.size.height)),
-		p_rect.size.width,p_rect.size.height);
-	} else {
-
-		glDisable(GL_SCISSOR_TEST);
-	}
-
-
-}
-
-void RasterizerGLES1::canvas_end_rect() {
-
-	glPopMatrix();
-}
-
-void RasterizerGLES1::canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width) {
-
-	glDisable(GL_TEXTURE_2D);
-	_set_glcoloro( p_color,canvas_opacity );
-
-	Vector3 verts[2]={
-		Vector3(p_from.x,p_from.y,0),
-		Vector3(p_to.x,p_to.y,0)
-	};
-	Color colors[2]={
-		p_color,
-		p_color
-	};
-	colors[0].a*=canvas_opacity;
-	colors[1].a*=canvas_opacity;
-	glLineWidth(p_width);
-	_draw_primitive(2,verts,0,colors,0);
-
-}
-
-static void _draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size,bool p_flip_h=false,bool p_flip_v=false ) {
-
-
-	Vector3 texcoords[4]= {
-		Vector3( p_src_region.pos.x/p_tex_size.width,
-		p_src_region.pos.y/p_tex_size.height, 0),
-
-		Vector3((p_src_region.pos.x+p_src_region.size.width)/p_tex_size.width,
-		p_src_region.pos.y/p_tex_size.height, 0),
-
-		Vector3( (p_src_region.pos.x+p_src_region.size.width)/p_tex_size.width,
-		(p_src_region.pos.y+p_src_region.size.height)/p_tex_size.height, 0),
-
-		Vector3( p_src_region.pos.x/p_tex_size.width,
-		(p_src_region.pos.y+p_src_region.size.height)/p_tex_size.height, 0)
-	};
-
-
-	if (p_flip_h) {
-		SWAP( texcoords[0], texcoords[1] );
-		SWAP( texcoords[2], texcoords[3] );
-	}
-	if (p_flip_v) {
-		SWAP( texcoords[1], texcoords[2] );
-		SWAP( texcoords[0], texcoords[3] );
-	}
-
-	Vector3 coords[4]= {
-		Vector3( p_rect.pos.x, p_rect.pos.y, 0 ),
-		Vector3( p_rect.pos.x+p_rect.size.width, p_rect.pos.y, 0 ),
-		Vector3( p_rect.pos.x+p_rect.size.width, p_rect.pos.y+p_rect.size.height, 0 ),
-		Vector3( p_rect.pos.x,p_rect.pos.y+p_rect.size.height, 0 )
-	};
-
-	_draw_primitive(4,coords,0,0,texcoords);
-}
-
-static void _draw_quad(const Rect2& p_rect) {
-
-	Vector3 coords[4]= {
-		Vector3( p_rect.pos.x,p_rect.pos.y, 0 ),
-		Vector3( p_rect.pos.x+p_rect.size.width,p_rect.pos.y, 0 ),
-		Vector3( p_rect.pos.x+p_rect.size.width,p_rect.pos.y+p_rect.size.height, 0 ),
-		Vector3( p_rect.pos.x,p_rect.pos.y+p_rect.size.height, 0 )
-	};
-
-	_draw_primitive(4,coords,0,0,0);
-
-}
-
-
-void RasterizerGLES1::canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate) {
-
-	_set_glcoloro( p_modulate,canvas_opacity );
-
-	if ( p_texture.is_valid() ) {
-
-		glEnable(GL_TEXTURE_2D);
-		Texture *texture = texture_owner.get( p_texture );
-		ERR_FAIL_COND(!texture);
-		glActiveTexture(GL_TEXTURE0);
-		glBindTexture( GL_TEXTURE_2D,texture->tex_id );
-
-		if (!(p_flags&CANVAS_RECT_REGION)) {
-
-			Rect2 region = Rect2(0,0,texture->width,texture->height);
-			_draw_textured_quad(p_rect,region,region.size,p_flags&CANVAS_RECT_FLIP_H,p_flags&CANVAS_RECT_FLIP_V);
-
-		} else {
-
-
-			_draw_textured_quad(p_rect, p_source, Size2(texture->width,texture->height),p_flags&CANVAS_RECT_FLIP_H,p_flags&CANVAS_RECT_FLIP_V );
-
-		}
-	} else {
-
-		glDisable(GL_TEXTURE_2D);
-		_draw_quad( p_rect );
-
-	}
-
-
-}
-void RasterizerGLES1::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) {
-
-	_set_glcoloro( p_modulate,canvas_opacity );
-
-
-	Texture *texture = texture_owner.get( p_texture );
-	ERR_FAIL_COND(!texture);
-
-	glEnable(GL_TEXTURE_2D);
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture( GL_TEXTURE_2D,texture->tex_id );
-
-
-	/* CORNERS */
-
-	_draw_textured_quad( // top left
-		Rect2( p_rect.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])),
-		Rect2( Point2(), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])),
-		Size2( texture->width, texture->height ) );
-
-	_draw_textured_quad( // top right
-		Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])),
-		Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],0), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])),
-		Size2( texture->width, texture->height ) );
-
-
-	_draw_textured_quad( // bottom left
-		Rect2( Point2(p_rect.pos.x,p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])),
-		Rect2( Point2(0,texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])),
-		Size2( texture->width, texture->height ) );
-
-	_draw_textured_quad( // bottom right
-		Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])),
-		Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])),
-		Size2( texture->width, texture->height ) );
-
-	Rect2 rect_center( p_rect.pos+Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] ));
-
-	Rect2 src_center( Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( texture->width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], texture->height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] ));
-
-
-	_draw_textured_quad( // top
-		Rect2( Point2(rect_center.pos.x,p_rect.pos.y),Size2(rect_center.size.width,p_margin[MARGIN_TOP])),
-		Rect2( Point2(p_margin[MARGIN_LEFT],0), Size2(src_center.size.width,p_margin[MARGIN_TOP])),
-		Size2( texture->width, texture->height ) );
-
-	_draw_textured_quad( // bottom
-		Rect2( Point2(rect_center.pos.x,rect_center.pos.y+rect_center.size.height),Size2(rect_center.size.width,p_margin[MARGIN_BOTTOM])),
-		Rect2( Point2(p_margin[MARGIN_LEFT],src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])),
-		Size2( texture->width, texture->height ) );
-
-	_draw_textured_quad( // left
-		Rect2( Point2(p_rect.pos.x,rect_center.pos.y),Size2(p_margin[MARGIN_LEFT],rect_center.size.height)),
-		Rect2( Point2(0,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)),
-		Size2( texture->width, texture->height ) );
-
-	_draw_textured_quad( // right
-		Rect2( Point2(rect_center.pos.x+rect_center.size.width,rect_center.pos.y),Size2(p_margin[MARGIN_RIGHT],rect_center.size.height)),
-		Rect2( Point2(src_center.pos.x+src_center.size.width,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)),
-		Size2( texture->width, texture->height ) );
-
-	if (p_draw_center) {
-
-		_draw_textured_quad(
-			rect_center,
-			src_center,
-			Size2( texture->width, texture->height ));
-	}
-
-}
-void RasterizerGLES1::canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) {
-
-	ERR_FAIL_COND(p_points.size()<1);
-	Vector3 verts[4];
-	Vector3 uvs[4];
-
-	_set_glcoloro( Color(1,1,1),canvas_opacity );
-
-	for(int i=0;i<p_points.size();i++) {
-
-		verts[i]=Vector3(p_points[i].x,p_points[i].y,0);
-	}
-
-	for(int i=0;i<p_uvs.size();i++) {
-
-		uvs[i]=Vector3(p_uvs[i].x,p_uvs[i].y,0);
-	}
-
-	if (p_texture.is_valid()) {
-		glEnable(GL_TEXTURE_2D);
-		Texture *texture = texture_owner.get( p_texture );
-		if (texture) {
-			glActiveTexture(GL_TEXTURE0);
-			glBindTexture( GL_TEXTURE_2D,texture->tex_id );
-		}
-	}
-
-	glLineWidth(p_width);
-	_draw_primitive(p_points.size(),&verts[0],NULL,p_colors.size()?&p_colors[0]:NULL,p_uvs.size()?uvs:NULL);
-
-}
-
-static const int _max_draw_poly_indices = 8*1024;
-static uint16_t _draw_poly_indices[_max_draw_poly_indices];
-static float _verts3[_max_draw_poly_indices];
-
-void RasterizerGLES1::canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor) {
-
-	bool do_colors=false;
-
-	//reset_state();
-	if (p_singlecolor) {
-		Color m = *p_colors;
-		m.a*=canvas_opacity;
-		glColor4f(m.r, m.g, m.b, m.a);
-	} else if (!p_colors) {
-		glColor4f(1, 1, 1, canvas_opacity);
-	} else
-		do_colors=true;
-
-	glColor4f(1, 1, 1, 1);
-
-	Texture* texture = NULL;
-	if (p_texture.is_valid()) {
-		glEnable(GL_TEXTURE_2D);
-		texture = texture_owner.get( p_texture );
-		if (texture) {
-			glActiveTexture(GL_TEXTURE0);
-			glBindTexture( GL_TEXTURE_2D,texture->tex_id );
-		}
-	}
-
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)p_vertices);
-	if (do_colors) {
-
-		glEnableClientState(GL_COLOR_ARRAY);
-		glColorPointer(4,GL_FLOAT, 0, p_colors);
-
-	} else {
-		glDisableClientState(GL_COLOR_ARRAY);
-	}
-
-	if (texture && p_uvs) {
-
-		glClientActiveTexture(GL_TEXTURE0);
-		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-		glTexCoordPointer(2, GL_FLOAT, 0, p_uvs);
-
-	} else {
-		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-	}
-
-	if (p_indices) {
-
-		for (int i=0; i<p_vertex_count; i++) {
-			_draw_poly_indices[i] = p_indices[i];
-		};
-		glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, _draw_poly_indices );
-	} else {
-
-		glDrawArrays(GL_TRIANGLES,0,p_vertex_count);
-	}
-
-	glDisableClientState(GL_VERTEX_ARRAY);
-	glDisableClientState(GL_COLOR_ARRAY);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
-}
-
-void RasterizerGLES1::canvas_set_transform(const Matrix32& p_transform) {
-
-	//restore
-	glPopMatrix();
-	glPushMatrix();
-	//set
-	_gl_mult_transform(p_transform);
-}
-
-/* FX */
-
-RID RasterizerGLES1::fx_create() {
-
-	FX *fx = memnew( FX );
-	ERR_FAIL_COND_V(!fx,RID());
-	return fx_owner.make_rid(fx);
-
-}
-void RasterizerGLES1::fx_get_effects(RID p_fx,List<String> *p_effects) const {
-
-	FX *fx = fx_owner.get(p_fx);
-	ERR_FAIL_COND(!fx);
-
-	p_effects->clear();
-	p_effects->push_back("bgcolor");
-	p_effects->push_back("skybox");
-	p_effects->push_back("antialias");
-	//p_effects->push_back("hdr");
-	p_effects->push_back("glow");	// glow has a bloom parameter, too
-	p_effects->push_back("ssao");
-	p_effects->push_back("fog");
-	p_effects->push_back("dof_blur");
-	p_effects->push_back("toon");
-	p_effects->push_back("edge");
-
-}
-void RasterizerGLES1::fx_set_active(RID p_fx,const String& p_effect, bool p_active) {
-
-	FX *fx = fx_owner.get(p_fx);
-	ERR_FAIL_COND(!fx);
-
-	if (p_effect=="bgcolor")
-		fx->bgcolor_active=p_active;
-	else if (p_effect=="skybox")
-		fx->skybox_active=p_active;
-	else if (p_effect=="antialias")
-		fx->antialias_active=p_active;
-	else if (p_effect=="glow")
-		fx->glow_active=p_active;
-	else if (p_effect=="ssao")
-		fx->ssao_active=p_active;
-	else if (p_effect=="fog")
-		fx->fog_active=p_active;
-//	else if (p_effect=="dof_blur")
-//		fx->dof_blur_active=p_active;
-	else if (p_effect=="toon")
-		fx->toon_active=p_active;
-	else if (p_effect=="edge")
-		fx->edge_active=p_active;
-}
-bool RasterizerGLES1::fx_is_active(RID p_fx,const String& p_effect) const {
-
-	FX *fx = fx_owner.get(p_fx);
-	ERR_FAIL_COND_V(!fx,false);
-
-	if (p_effect=="bgcolor")
-		return fx->bgcolor_active;
-	else if (p_effect=="skybox")
-		return fx->skybox_active;
-	else if (p_effect=="antialias")
-		return fx->antialias_active;
-	else if (p_effect=="glow")
-		return fx->glow_active;
-	else if (p_effect=="ssao")
-		return fx->ssao_active;
-	else if (p_effect=="fog")
-		return fx->fog_active;
-	//else if (p_effect=="dof_blur")
-	//	return fx->dof_blur_active;
-	else if (p_effect=="toon")
-		return fx->toon_active;
-	else if (p_effect=="edge")
-		return fx->edge_active;
-
-	return false;
-}
-void RasterizerGLES1::fx_get_effect_params(RID p_fx,const String& p_effect,List<PropertyInfo> *p_params) const {
-
-	FX *fx = fx_owner.get(p_fx);
-	ERR_FAIL_COND(!fx);
-
-
-	if (p_effect=="bgcolor") {
-
-		p_params->push_back( PropertyInfo( Variant::COLOR, "color" ) );
-	} else if (p_effect=="skybox") {
-		p_params->push_back( PropertyInfo( Variant::_RID, "cubemap" ) );
-	} else if (p_effect=="antialias") {
-
-		p_params->push_back( PropertyInfo( Variant::REAL, "tolerance", PROPERTY_HINT_RANGE,"1,128,1" ) );
-
-	} else if (p_effect=="glow") {
-
-		p_params->push_back( PropertyInfo( Variant::INT, "passes", PROPERTY_HINT_RANGE,"1,4,1" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "attenuation", PROPERTY_HINT_RANGE,"0.01,8.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "bloom", PROPERTY_HINT_RANGE,"-1.0,1.0,0.01" ) );
-
-	} else if (p_effect=="ssao") {
-
-		p_params->push_back( PropertyInfo( Variant::REAL, "radius", PROPERTY_HINT_RANGE,"0.0,16.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "max_distance", PROPERTY_HINT_RANGE,"0.0,256.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "range_max", PROPERTY_HINT_RANGE,"0.0,1.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "range_min", PROPERTY_HINT_RANGE,"0.0,1.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "attenuation", PROPERTY_HINT_RANGE,"0.0,8.0,0.01" ) );
-
-	} else if (p_effect=="fog") {
-
-		p_params->push_back( PropertyInfo( Variant::REAL, "begin", PROPERTY_HINT_RANGE,"0.0,8192,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "end", PROPERTY_HINT_RANGE,"0.0,8192,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "attenuation", PROPERTY_HINT_RANGE,"0.0,8.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::COLOR, "color_begin" ) );
-		p_params->push_back( PropertyInfo( Variant::COLOR, "color_end" ) );
-		p_params->push_back( PropertyInfo( Variant::BOOL, "fog_bg" ) );
-
-//	} else if (p_effect=="dof_blur") {
-//		return fx->dof_blur_active;
-	} else if (p_effect=="toon") {
-		p_params->push_back( PropertyInfo( Variant::REAL, "treshold", PROPERTY_HINT_RANGE,"0.0,1.0,0.01" ) );
-		p_params->push_back( PropertyInfo( Variant::REAL, "soft", PROPERTY_HINT_RANGE,"0.001,1.0,0.001" ) );
-	} else if (p_effect=="edge") {
-
-	}
-}
-Variant RasterizerGLES1::fx_get_effect_param(RID p_fx,const String& p_effect,const String& p_param) const {
-
-	FX *fx = fx_owner.get(p_fx);
-	ERR_FAIL_COND_V(!fx,Variant());
-
-	if (p_effect=="bgcolor") {
-
-		if (p_param=="color")
-			return fx->bgcolor;
-	} else if (p_effect=="skybox") {
-		if (p_param=="cubemap")
-			return fx->skybox_cubemap;
-	} else if (p_effect=="antialias") {
-
-		if (p_param=="tolerance")
-			return fx->antialias_tolerance;
-
-	} else if (p_effect=="glow") {
-
-		if (p_param=="passes")
-			return fx->glow_passes;
-		if (p_param=="attenuation")
-			return fx->glow_attenuation;
-		if (p_param=="bloom")
-			return fx->glow_bloom;
-
-	} else if (p_effect=="ssao") {
-
-		if (p_param=="attenuation")
-			return fx->ssao_attenuation;
-		if (p_param=="max_distance")
-			return fx->ssao_max_distance;
-		if (p_param=="range_max")
-			return fx->ssao_range_max;
-		if (p_param=="range_min")
-			return fx->ssao_range_min;
-		if (p_param=="radius")
-			return fx->ssao_radius;
-
-	} else if (p_effect=="fog") {
-
-		if (p_param=="begin")
-			return fx->fog_near;
-		if (p_param=="end")
-			return fx->fog_far;
-		if (p_param=="attenuation")
-			return fx->fog_attenuation;
-		if (p_param=="color_begin")
-			return fx->fog_color_near;
-		if (p_param=="color_end")
-			return fx->fog_color_far;
-		if (p_param=="fog_bg")
-			return fx->fog_bg;
-//	} else if (p_effect=="dof_blur") {
-//		return fx->dof_blur_active;
-	} else if (p_effect=="toon") {
-		if (p_param=="treshold")
-			return fx->toon_treshold;
-		if (p_param=="soft")
-			return fx->toon_soft;
-
-	} else if (p_effect=="edge") {
-
-	}
-	return Variant();
-}
-void RasterizerGLES1::fx_set_effect_param(RID p_fx,const String& p_effect, const String& p_param, const Variant& p_value) {
-
-	FX *fx = fx_owner.get(p_fx);
-	ERR_FAIL_COND(!fx);
-
-	if (p_effect=="bgcolor") {
-
-		if (p_param=="color")
-			fx->bgcolor=p_value;
-	} else if (p_effect=="skybox") {
-		if (p_param=="cubemap")
-			fx->skybox_cubemap=p_value;
-
-	} else if (p_effect=="antialias") {
-
-		if (p_param=="tolerance")
-			fx->antialias_tolerance=p_value;
-
-	} else if (p_effect=="glow") {
-
-		if (p_param=="passes")
-			fx->glow_passes=p_value;
-		if (p_param=="attenuation")
-			fx->glow_attenuation=p_value;
-		if (p_param=="bloom")
-			fx->glow_bloom=p_value;
-
-	} else if (p_effect=="ssao") {
-
-		if (p_param=="attenuation")
-			fx->ssao_attenuation=p_value;
-		if (p_param=="radius")
-			fx->ssao_radius=p_value;
-		if (p_param=="max_distance")
-			fx->ssao_max_distance=p_value;
-		if (p_param=="range_max")
-			fx->ssao_range_max=p_value;
-		if (p_param=="range_min")
-			fx->ssao_range_min=p_value;
-
-	} else if (p_effect=="fog") {
-
-		if (p_param=="begin")
-			fx->fog_near=p_value;
-		if (p_param=="end")
-			fx->fog_far=p_value;
-		if (p_param=="attenuation")
-			fx->fog_attenuation=p_value;
-		if (p_param=="color_begin")
-			fx->fog_color_near=p_value;
-		if (p_param=="color_end")
-			fx->fog_color_far=p_value;
-		if (p_param=="fog_bg")
-			fx->fog_bg=p_value;
-//	} else if (p_effect=="dof_blur") {
-//		fx->dof_blur_active=p_value;
-	} else if (p_effect=="toon") {
-
-		if (p_param=="treshold")
-			fx->toon_treshold=p_value;
-		if (p_param=="soft")
-			fx->toon_soft=p_value;
-
-	} else if (p_effect=="edge") {
-
-	}
-
-}
-
-/* ENVIRONMENT */
-
-RID RasterizerGLES1::environment_create() {
-
-	Environment * env = memnew( Environment );
-	return environment_owner.make_rid(env);
-}
-
-void RasterizerGLES1::environment_set_background(RID p_env,VS::EnvironmentBG p_bg) {
-
-	ERR_FAIL_INDEX(p_bg,VS::ENV_BG_MAX);
-	Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND(!env);
-	env->bg_mode=p_bg;
-}
-
-VS::EnvironmentBG RasterizerGLES1::environment_get_background(RID p_env) const{
-
-	const Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND_V(!env,VS::ENV_BG_MAX);
-	return env->bg_mode;
-}
-
-void RasterizerGLES1::environment_set_background_param(RID p_env,VS::EnvironmentBGParam p_param, const Variant& p_value){
-
-	ERR_FAIL_INDEX(p_param,VS::ENV_BG_PARAM_MAX);
-	Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND(!env);
-	env->bg_param[p_param]=p_value;
-
-}
-Variant RasterizerGLES1::environment_get_background_param(RID p_env,VS::EnvironmentBGParam p_param) const{
-
-	ERR_FAIL_INDEX_V(p_param,VS::ENV_BG_PARAM_MAX,Variant());
-	const Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND_V(!env,Variant());
-	return env->bg_param[p_param];
-
-}
-
-void RasterizerGLES1::environment_set_enable_fx(RID p_env,VS::EnvironmentFx p_effect,bool p_enabled){
-
-	ERR_FAIL_INDEX(p_effect,VS::ENV_FX_MAX);
-	Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND(!env);
-	env->fx_enabled[p_effect]=p_enabled;
-}
-bool RasterizerGLES1::environment_is_fx_enabled(RID p_env,VS::EnvironmentFx p_effect) const{
-
-	ERR_FAIL_INDEX_V(p_effect,VS::ENV_FX_MAX,false);
-	const Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND_V(!env,false);
-	return env->fx_enabled[p_effect];
-
-}
-
-void RasterizerGLES1::environment_fx_set_param(RID p_env,VS::EnvironmentFxParam p_param,const Variant& p_value){
-
-	ERR_FAIL_INDEX(p_param,VS::ENV_FX_PARAM_MAX);
-	Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND(!env);
-	env->fx_param[p_param]=p_value;
-}
-Variant RasterizerGLES1::environment_fx_get_param(RID p_env,VS::EnvironmentFxParam p_param) const{
-
-	ERR_FAIL_INDEX_V(p_param,VS::ENV_FX_PARAM_MAX,Variant());
-	const Environment * env = environment_owner.get(p_env);
-	ERR_FAIL_COND_V(!env,Variant());
-	return env->fx_param[p_param];
-
-}
-
-/* SAMPLED LIGHT */
-
-RID RasterizerGLES1::sampled_light_dp_create(int p_width,int p_height) {
-
-	return sampled_light_owner.make_rid(memnew(SampledLight));
-}
-
-void RasterizerGLES1::sampled_light_dp_update(RID p_sampled_light, const Color *p_data, float p_multiplier) {
-
-
-}
-
-/*MISC*/
-
-bool RasterizerGLES1::is_texture(const RID& p_rid) const {
-
-	return texture_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_material(const RID& p_rid) const {
-
-	return material_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_mesh(const RID& p_rid) const {
-
-	return mesh_owner.owns(p_rid);
-}
-
-bool RasterizerGLES1::is_immediate(const RID& p_rid) const {
-
-	return immediate_owner.owns(p_rid);
-}
-
-bool RasterizerGLES1::is_multimesh(const RID& p_rid) const {
-
-	return multimesh_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_particles(const RID &p_beam) const {
-
-	return particles_owner.owns(p_beam);
-}
-
-bool RasterizerGLES1::is_light(const RID& p_rid) const {
-
-	return light_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_light_instance(const RID& p_rid) const {
-
-	return light_instance_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_particles_instance(const RID& p_rid) const {
-
-	return particles_instance_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_skeleton(const RID& p_rid) const {
-
-	return skeleton_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_environment(const RID& p_rid) const {
-
-	return environment_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_fx(const RID& p_rid) const {
-
-	return fx_owner.owns(p_rid);
-}
-bool RasterizerGLES1::is_shader(const RID& p_rid) const {
-
-	return false;
-}
-
-void RasterizerGLES1::free(const RID& p_rid) {
-
-	if (texture_owner.owns(p_rid)) {
-
-		// delete the texture
-		Texture *texture = texture_owner.get(p_rid);
-
-		glDeleteTextures( 1,&texture->tex_id );
-		_rinfo.texture_mem-=texture->total_data_size;
-		texture_owner.free(p_rid);
-		memdelete(texture);
-
-	} else if (shader_owner.owns(p_rid)) {
-
-		// delete the texture
-		Shader *shader = shader_owner.get(p_rid);
-
-
-
-		shader_owner.free(p_rid);
-		memdelete(shader);
-
-	} else if (material_owner.owns(p_rid)) {
-
-		Material *material = material_owner.get( p_rid );
-		ERR_FAIL_COND(!material);
-
-		material_owner.free(p_rid);
-		memdelete(material);
-
-	} else if (mesh_owner.owns(p_rid)) {
-
-		Mesh *mesh = mesh_owner.get(p_rid);
-		ERR_FAIL_COND(!mesh);
-		for (int i=0;i<mesh->surfaces.size();i++) {
-
-			Surface *surface = mesh->surfaces[i];
-			if (surface->array_local != 0) {
-				memfree(surface->array_local);
-			};
-			if (surface->index_array_local != 0) {
-				memfree(surface->index_array_local);
-			};
-
-			if (mesh->morph_target_count>0) {
-
-				for(int i=0;i<mesh->morph_target_count;i++) {
-
-					memfree(surface->morph_targets_local[i].array);
-				}
-				memfree(surface->morph_targets_local);
-				surface->morph_targets_local=NULL;
-			}
-
-			if (surface->vertex_id)
-				glDeleteBuffers(1,&surface->vertex_id);
-			if (surface->index_id)
-				glDeleteBuffers(1,&surface->index_id);
-
-			memdelete( surface );
-		};
-
-		mesh->surfaces.clear();
-
-		mesh_owner.free(p_rid);
-		memdelete(mesh);
-
-	} else if (multimesh_owner.owns(p_rid)) {
-
-	       MultiMesh *multimesh = multimesh_owner.get(p_rid);
-	       ERR_FAIL_COND(!multimesh);
-
-	       multimesh_owner.free(p_rid);
-	       memdelete(multimesh);
-
-	} else if (particles_owner.owns(p_rid)) {
-
-		Particles *particles = particles_owner.get(p_rid);
-		ERR_FAIL_COND(!particles);
-
-		particles_owner.free(p_rid);
-		memdelete(particles);
-	} else if (immediate_owner.owns(p_rid)) {
-
-		Immediate *immediate = immediate_owner.get(p_rid);
-		ERR_FAIL_COND(!immediate);
-
-		immediate_owner.free(p_rid);
-		memdelete(immediate);
-	} else if (particles_instance_owner.owns(p_rid)) {
-
-		ParticlesInstance *particles_isntance = particles_instance_owner.get(p_rid);
-		ERR_FAIL_COND(!particles_isntance);
-
-		particles_instance_owner.free(p_rid);
-		memdelete(particles_isntance);
-
-	} else if (skeleton_owner.owns(p_rid)) {
-
-		Skeleton *skeleton = skeleton_owner.get( p_rid );
-		ERR_FAIL_COND(!skeleton)
-
-		skeleton_owner.free(p_rid);
-		memdelete(skeleton);
-
-	} else if (light_owner.owns(p_rid)) {
-
-		Light *light = light_owner.get( p_rid );
-		ERR_FAIL_COND(!light)
-
-		light_owner.free(p_rid);
-		memdelete(light);
-
-	} else if (light_instance_owner.owns(p_rid)) {
-
-		LightInstance *light_instance = light_instance_owner.get( p_rid );
-		ERR_FAIL_COND(!light_instance);
-		light_instance->clear_shadow_buffers();
-		light_instance_owner.free(p_rid);
-		memdelete( light_instance );
-
-	} else if (fx_owner.owns(p_rid)) {
-
-		FX *fx = fx_owner.get( p_rid );
-		ERR_FAIL_COND(!fx);
-
-		fx_owner.free(p_rid);
-		memdelete( fx );
-
-	} else if (environment_owner.owns(p_rid)) {
-
-		Environment *env = environment_owner.get( p_rid );
-		ERR_FAIL_COND(!env);
-
-		environment_owner.free(p_rid);
-		memdelete( env );
-	} else if (sampled_light_owner.owns(p_rid)) {
-
-		SampledLight *sampled_light = sampled_light_owner.get( p_rid );
-		ERR_FAIL_COND(!sampled_light);
-
-		sampled_light_owner.free(p_rid);
-		memdelete( sampled_light );
-	};
-}
-
-
-void RasterizerGLES1::custom_shade_model_set_shader(int p_model, RID p_shader) {
-
-
-};
-
-RID RasterizerGLES1::custom_shade_model_get_shader(int p_model) const {
-
-	return RID();
-};
-
-void RasterizerGLES1::custom_shade_model_set_name(int p_model, const String& p_name) {
-
-};
-
-String RasterizerGLES1::custom_shade_model_get_name(int p_model) const {
-
-	return String();
-};
-
-void RasterizerGLES1::custom_shade_model_set_param_info(int p_model, const List<PropertyInfo>& p_info) {
-
-};
-
-void RasterizerGLES1::custom_shade_model_get_param_info(int p_model, List<PropertyInfo>* p_info) const {
-
-};
-
-
-void RasterizerGLES1::ShadowBuffer::init(int p_size) {
-
-
-#if 0
-	size=p_size;
-
-	glActiveTexture(GL_TEXTURE0);
-	glGenTextures(1, &depth);
-	ERR_FAIL_COND(depth==0);
-
-	/* Setup Depth Texture */
-	glBindTexture(GL_TEXTURE_2D, depth);
-	glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, p_size, p_size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
-
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-	float border_color[]={1.0f, 1.0f, 1.0f, 1.0f};
-	glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color);
-
-	/* Create FBO */
-	glGenFramebuffers(1, &fbo);
-
-	ERR_FAIL_COND( fbo==0 );
-
-	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth, 0);
-	glDrawBuffer(GL_FALSE);
-	glReadBuffer(GL_FALSE);
-
-	/* Check FBO creation */
-	GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
-
-	ERR_FAIL_COND( status==GL_FRAMEBUFFER_UNSUPPORTED );
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
-#endif
-
-}
-
-void RasterizerGLES1::_init_shadow_buffers() {
-
-	int near_shadow_size=GLOBAL_DEF("rasterizer/near_shadow_size",512);
-	int far_shadow_size=GLOBAL_DEF("rasterizer/far_shadow_size",64);
-
-	near_shadow_buffers.resize( GLOBAL_DEF("rasterizer/near_shadow_count",4) );
-	far_shadow_buffers.resize( GLOBAL_DEF("rasterizer/far_shadow_count",16) );
-
-	shadow_near_far_split_size_ratio = GLOBAL_DEF("rasterizer/shadow_near_far_split_size_ratio",0.3);
-
-	for (int i=0;i<near_shadow_buffers.size();i++) {
-
-		near_shadow_buffers[i].init(near_shadow_size );
-	}
-
-	for (int i=0;i<far_shadow_buffers.size();i++) {
-
-		far_shadow_buffers[i].init(far_shadow_size);
-	}
-
-}
-
-
-void RasterizerGLES1::_update_framebuffer() {
-
-	return;
-
-#if 0
-	bool want_16 = GLOBAL_DEF("rasterizer/support_hdr",true);
-	int blur_buffer_div=GLOBAL_DEF("rasterizer/blur_buffer_div",4);
-	bool use_fbo = GLOBAL_DEF("rasterizer/use_fbo",true);
-
-
-	if (blur_buffer_div<1)
-		blur_buffer_div=2;
-
-
-	if (use_fbo==framebuffer.active && framebuffer.width==window_size.width && framebuffer.height==window_size.height && framebuffer.buff16==want_16)
-		return; //nuthin to change
-
-	if (framebuffer.fbo!=0) {
-
-		WARN_PRINT("Resizing the screen multiple times while using to FBOs may decrease performance on some hardware.");
-		//free the framebuffarz
-		glDeleteRenderbuffers(1,&framebuffer.fbo);
-		glDeleteTextures(1,&framebuffer.depth);
-		glDeleteTextures(1,&framebuffer.color);
-		for(int i=0;i<2;i++) {
-			glDeleteRenderbuffers(1,&framebuffer.blur[i].fbo);
-			glDeleteTextures(1,&framebuffer.blur[i].color);
-
-		}
-
-		framebuffer.fbo=0;
-	}
-
-	framebuffer.active=use_fbo;
-	framebuffer.width=window_size.width;
-	framebuffer.height=window_size.height;
-	framebuffer.buff16=want_16;
-
-
-	if (!use_fbo)
-		return;
-
-
-	glGenFramebuffers(1, &framebuffer.fbo);
-	glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo);
-
-	print_line("generating fbo, id: "+itos(framebuffer.fbo));
-	//depth
-	glGenTextures(1, &framebuffer.depth);
-
-	glBindTexture(GL_TEXTURE_2D, framebuffer.depth);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,  framebuffer.width, framebuffer.height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE );
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, framebuffer.depth, 0);
-	//color
-	glGenTextures(1, &framebuffer.color);
-	glBindTexture(GL_TEXTURE_2D, framebuffer.color);
-	glTexImage2D(GL_TEXTURE_2D, 0, want_16?GL_RGB16F:GL_RGBA8,  framebuffer.width, framebuffer.height, 0, GL_RGBA, want_16?GL_HALF_FLOAT:GL_UNSIGNED_BYTE, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer.color, 0);
-	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-	ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
-
-	for(int i=0;i<2;i++) {
-
-		glGenFramebuffers(1, &framebuffer.blur[i].fbo);
-		glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.blur[i].fbo);
-
-		glGenTextures(1, &framebuffer.blur[i].color);
-		glBindTexture(GL_TEXTURE_2D, framebuffer.blur[i].color);
-		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  framebuffer.width/blur_buffer_div, framebuffer.height/blur_buffer_div, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer.blur[i].color, 0);
-
-		status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-		ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
-	}
-
-	glBindFramebuffer(GL_FRAMEBUFFER, 0);
-#endif
-}
-
-void RasterizerGLES1::init() {
-
-#ifdef GLES_OVER_GL
-	glewInit();
-#endif
-
-
-
-
-	scene_pass=1;
-	if (ContextGL::get_singleton())
-		ContextGL::get_singleton()->make_current();
-
-
-
-	Set<String> extensions;
-	Vector<String> strings = String((const char*)glGetString( GL_EXTENSIONS )).split(" ",false);
-	for(int i=0;i<strings.size();i++) {
-
-		extensions.insert(strings[i]);
-//		print_line(strings[i]);
-	}
-
-
-
-	GLint tmp = 0;
-//	glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &tmp);
-//	print_line("GL_MAX_VERTEX_ATTRIBS "+itos(tmp));
-
-	glEnable(GL_DEPTH_TEST);
-	glDepthFunc(GL_LEQUAL);
-	glFrontFace(GL_CW);
-	//glEnable(GL_TEXTURE_2D);
-
-	default_material=create_default_material();
-
-	_init_shadow_buffers();
-
-	shadow=NULL;
-	shadow_pass=0;
-
-	framebuffer.fbo=0;
-	framebuffer.width=0;
-	framebuffer.height=0;
-	framebuffer.buff16=false;
-	framebuffer.blur[0].fbo=false;
-	framebuffer.blur[1].fbo=false;
-	framebuffer.active=false;
-
-	//do a single initial clear
-	glClearColor(0,0,0,1);
-	//glClearDepth(1.0);
-	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-
-	skinned_buffer_size = GLOBAL_DEF("rasterizer/skinned_buffer_size",DEFAULT_SKINNED_BUFFER_SIZE);
-	skinned_buffer = memnew_arr( uint8_t, skinned_buffer_size );
-
-	glGenTextures(1, &white_tex);
-	unsigned char whitetexdata[8*8*3];
-	for(int i=0;i<8*8*3;i++) {
-		whitetexdata[i]=255;
-	}
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(GL_TEXTURE_2D,white_tex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,whitetexdata);
-
-	npo2_textures_available=false;
-	pvr_supported=extensions.has("GL_IMG_texture_compression_pvrtc");
-	etc_supported=true;
-	s3tc_supported=false;
-	_rinfo.texture_mem=0;
-
-
-}
-
-void RasterizerGLES1::finish() {
-
-	memdelete(skinned_buffer);
-}
-
-int RasterizerGLES1::get_render_info(VS::RenderInfo p_info) {
-
-	switch(p_info) {
-
-		case VS::INFO_OBJECTS_IN_FRAME: {
-
-			return _rinfo.object_count;
-		} break;
-		case VS::INFO_VERTICES_IN_FRAME: {
-
-			return _rinfo.vertex_count;
-		} break;
-		case VS::INFO_MATERIAL_CHANGES_IN_FRAME: {
-
-			return _rinfo.mat_change_count;
-		} break;
-		case VS::INFO_SHADER_CHANGES_IN_FRAME: {
-
-			return _rinfo.shader_change_count;
-		} break;
-		case VS::INFO_USAGE_VIDEO_MEM_TOTAL: {
-
-			return 0;
-		} break;
-		case VS::INFO_VIDEO_MEM_USED: {
-
-			return get_render_info(VS::INFO_TEXTURE_MEM_USED)+get_render_info(VS::INFO_VERTEX_MEM_USED);
-		} break;
-		case VS::INFO_TEXTURE_MEM_USED: {
-
-			_rinfo.texture_mem;
-		} break;
-		case VS::INFO_VERTEX_MEM_USED: {
-
-			return 0;
-		} break;
-	}
-
-	return false;
-}
-
-bool RasterizerGLES1::needs_to_draw_next_frame() const {
-
-	return false;
-}
-
-void RasterizerGLES1::reload_vram() {
-
-	glEnable(GL_DEPTH_TEST);
-	glDepthFunc(GL_LEQUAL);
-	glFrontFace(GL_CW);
-
-	//do a single initial clear
-	glClearColor(0,0,0,1);
-	//glClearDepth(1.0);
-	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-
-/*
-	glGenTextures(1, &white_tex);
-	unsigned char whitetexdata[8*8*3];
-	for(int i=0;i<8*8*3;i++) {
-		whitetexdata[i]=255;
-	}
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(GL_TEXTURE_2D,white_tex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,whitetexdata);
-	glGenerateMipmap(GL_TEXTURE_2D);
-	glBindTexture(GL_TEXTURE_2D,0);
-
-*/
-	glEnable(GL_TEXTURE_2D);
-	glActiveTexture(GL_TEXTURE0);
-
-	List<RID> textures;
-	texture_owner.get_owned_list(&textures);
-	keep_copies=false;
-	for(List<RID>::Element *E=textures.front();E;E=E->next()) {
-
-		RID tid = E->get();
-		Texture *t=texture_owner.get(tid);
-		ERR_CONTINUE(!t);
-		t->tex_id=0;
-		t->data_size=0;
-		glGenTextures(1, &t->tex_id);
-		t->active=false;
-		texture_allocate(tid,t->width,t->height,t->format,t->flags);
-		bool had_image=false;
-		for(int i=0;i<6;i++) {
-			if (!t->image[i].empty()) {
-				texture_set_data(tid,t->image[i],VS::CubeMapSide(i));
-				had_image=true;
-			}
-		}
-
-		if (!had_image && t->reloader) {
-			Object *rl = ObjectDB::get_instance(t->reloader);
-			if (rl)
-				rl->call(t->reloader_func,tid);
-		}
-	}
-
-	keep_copies=true;
-
-
-}
-
-bool RasterizerGLES1::has_feature(VS::Features p_feature) const {
-
-	switch( p_feature) {
-		case VS::FEATURE_SHADERS: return false;
-		case VS::FEATURE_NEEDS_RELOAD_HOOK: return use_reload_hooks;
-		default: return false;
-
-	}
-
-}
-
-
-RasterizerGLES1::RasterizerGLES1(bool p_keep_copies,bool p_use_reload_hooks) {
-	keep_copies=p_keep_copies;
-	pack_arrays=false;
-	use_reload_hooks=p_use_reload_hooks;
-
-	frame = 0;
-};
-
-RasterizerGLES1::~RasterizerGLES1() {
-
-};
-
-
-#endif

+ 0 - 1256
drivers/gles1/rasterizer_gles1.h

@@ -1,1256 +0,0 @@
-/*************************************************************************/
-/*  rasterizer_gles1.h                                                   */
-/*************************************************************************/
-/*                       This file is part of:                           */
-/*                           GODOT ENGINE                                */
-/*                    http://www.godotengine.org                         */
-/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                 */
-/*                                                                       */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the       */
-/* "Software"), to deal in the Software without restriction, including   */
-/* without limitation the rights to use, copy, modify, merge, publish,   */
-/* distribute, sublicense, and/or sell copies of the Software, and to    */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions:                                             */
-/*                                                                       */
-/* The above copyright notice and this permission notice shall be        */
-/* included in all copies or substantial portions of the Software.       */
-/*                                                                       */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
-/*************************************************************************/
-#ifndef RASTERIZER_GLES1_H
-#define RASTERIZER_GLES1_H
-
-#include "servers/visual/rasterizer.h"
-
-#ifdef GLES1_ENABLED
-
-#include "image.h"
-#include "rid.h"
-#include "servers/visual_server.h"
-#include "list.h"
-#include "map.h"
-#include "camera_matrix.h"
-#include "sort.h"
-
-#include "platform_config.h"
-#ifndef GLES1_INCLUDE_H
-#include <GLES/gl.h>
-#else
-#include GLES1_INCLUDE_H
-#endif
-
-
-
-#include "servers/visual/particle_system_sw.h"
-
-/**
-        @author Juan Linietsky <[email protected]>
-*/
-class RasterizerGLES1 : public Rasterizer {
-
-	enum {
-
-		MAX_SCENE_LIGHTS=2048,
-		LIGHT_SPOT_BIT=0x80,
-		DEFAULT_SKINNED_BUFFER_SIZE = 1024 * 1024, // 10k vertices
-		MAX_HW_LIGHTS = 1,
-	};
-
-
-	uint8_t *skinned_buffer;
-	int skinned_buffer_size;
-	bool pvr_supported;
-	bool s3tc_supported;
-	bool etc_supported;
-	bool npo2_textures_available;
-	bool pack_arrays;
-	bool use_reload_hooks;
-
-	Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,int &r_gl_components,bool &r_has_alpha_cache,bool &r_compressed);
-
-
-	struct Texture {
-
-		uint32_t flags;
-		int width,height;
-		int alloc_width, alloc_height;
-		Image::Format format;
-
-		GLenum target;
-		GLenum gl_format_cache;
-		int gl_components_cache;
-		int data_size; //original data size, useful for retrieving back
-		bool format_has_alpha;
-		bool compressed;
-		bool disallow_mipmaps;
-		int total_data_size;
-
-		Image image[6];
-
-		bool active;
-		GLuint tex_id;
-
-		ObjectID reloader;
-		StringName reloader_func;
-
-		Texture() {
-
-			flags=width=height=0;
-			tex_id=0;
-			data_size=0;
-			format=Image::FORMAT_GRAYSCALE;
-			gl_components_cache=0;
-			format_has_alpha=false;
-			active=false;
-			disallow_mipmaps=false;
-//			gen_mipmap=true;
-			compressed=false;
-			total_data_size=0;
-		}
-
-		~Texture() {
-
-			if (tex_id!=0) {
-
-				glDeleteTextures(1,&tex_id);
-			}
-		}
-	};
-
-	mutable RID_Owner<Texture> texture_owner;
-
-	struct Shader {
-
-		String vertex_code;
-		String fragment_code;
-		String light_code;
-		VS::ShaderMode mode;
-		Map<StringName,Variant> params;
-		int fragment_line;
-		int vertex_line;
-		int light_line;
-		bool valid;
-		bool has_alpha;
-		bool use_world_transform;
-
-	};
-
-	mutable RID_Owner<Shader> shader_owner;
-
-
-	struct Material {
-
-		bool fixed_flags[VS::FIXED_MATERIAL_FLAG_MAX];
-		bool flags[VS::MATERIAL_FLAG_MAX];
-		Variant parameters[VisualServer::FIXED_MATERIAL_PARAM_MAX];
-		RID textures[VisualServer::FIXED_MATERIAL_PARAM_MAX];
-
-		VS::MaterialDepthDrawMode depth_draw_mode;
-
-		Transform uv_transform;
-		VS::FixedMaterialTexCoordMode texcoord_mode[VisualServer::FIXED_MATERIAL_PARAM_MAX];
-
-		VS::MaterialBlendMode blend_mode;
-
-		float line_width;
-		float point_size;
-		bool has_alpha;
-
-		RID shader; // shader material
-		uint64_t last_pass;
-
-		Map<StringName,Variant> shader_params;
-
-
-		Material() {
-
-
-			for(int i=0;i<VS::FIXED_MATERIAL_FLAG_MAX;i++)
-				flags[i]=false;
-
-			for(int i=0;i<VS::MATERIAL_FLAG_MAX;i++)
-				flags[i]=false;
-			flags[VS::MATERIAL_FLAG_VISIBLE]=true;
-
-			parameters[VS::FIXED_MATERIAL_PARAM_DIFFUSE] = Color(0.8, 0.8, 0.8);
-			parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR_EXP] = 12;
-
-			for (int i=0; i<VisualServer::FIXED_MATERIAL_PARAM_MAX; i++) {
-				texcoord_mode[i] = VS::FIXED_MATERIAL_TEXCOORD_UV;
-			};
-			depth_draw_mode=VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY;
-			line_width=1;
-			has_alpha=false;
-			blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
-			last_pass = 0;
-			point_size = 1.0;
-
-		}
-	};
-	mutable RID_Owner<Material> material_owner;
-
-	void _material_check_alpha(Material *p_material);
-
-
-	struct Geometry {
-
-		enum Type {
-			GEOMETRY_INVALID,
-			GEOMETRY_SURFACE,
-			GEOMETRY_POLY,
-			GEOMETRY_PARTICLES,
-			GEOMETRY_MULTISURFACE,
-		};
-
-		Type type;
-		RID material;
-		bool has_alpha;
-		bool material_owned;
-
-		Geometry() { has_alpha=false; material_owned = false; }
-		virtual ~Geometry() {};
-	};
-
-	struct GeometryOwner {
-
-		virtual ~GeometryOwner() {}
-	};
-
-	class Mesh;
-
-	struct Surface : public Geometry {
-
-		struct ArrayData {
-
-			uint32_t ofs,size,datatype,count;
-			bool normalize;
-			bool bind;
-
-			ArrayData() { ofs=0; size=0; count=0; datatype=0; normalize=0; bind=false;}
-		};
-
-		Mesh *mesh;
-
-		Array data;
-		Array morph_data;
-		ArrayData array[VS::ARRAY_MAX];
-		// support for vertex array objects
-		GLuint array_object_id;
-		// support for vertex buffer object
-		GLuint vertex_id; // 0 means, unconfigured
-		GLuint index_id; // 0 means, unconfigured
-		// no support for the above, array in localmem.
-		uint8_t *array_local;
-		uint8_t *index_array_local;
-
-		bool packed;
-
-		struct MorphTarget {
-			uint32_t configured_format;
-			uint8_t *array;
-		};
-
-		MorphTarget* morph_targets_local;
-		int morph_target_count;
-		AABB aabb;
-
-		int array_len;
-		int index_array_len;
-		int max_bone;
-
-		float vertex_scale;
-		float uv_scale;
-		float uv2_scale;
-
-		VS::PrimitiveType primitive;
-
-		uint32_t format;
-		uint32_t configured_format;
-
-		int stride;
-		int local_stride;
-		uint32_t morph_format;
-
-		bool active;
-
-		Point2 uv_min;
-		Point2 uv_max;
-
-		Surface() {
-
-
-			array_len=0;
-			local_stride=0;
-			morph_format=0;
-			type=GEOMETRY_SURFACE;
-			primitive=VS::PRIMITIVE_POINTS;
-			index_array_len=0;
-			vertex_scale=1.0;
-			uv_scale=1.0;
-			uv2_scale=1.0;
-
-			format=0;
-			stride=0;
-			morph_targets_local=0;
-			morph_target_count=0;
-
-			array_local = index_array_local = 0;
-			vertex_id = index_id = 0;
-
-			active=false;
-			packed=false;
-		}
-
-		~Surface() {
-
-		}
-	};
-
-
-	struct Mesh {
-
-		bool active;
-		Vector<Surface*> surfaces;
-		int morph_target_count;
-		VS::MorphTargetMode morph_target_mode;
-		AABB custom_aabb;
-
-		mutable uint64_t last_pass;
-		Mesh() {
-			morph_target_mode=VS::MORPH_MODE_NORMALIZED;
-			morph_target_count=0;
-			last_pass=0;
-			active=false;
-		}
-	};
-	mutable RID_Owner<Mesh> mesh_owner;
-
-	Error _surface_set_arrays(Surface *p_surface, uint8_t *p_mem,uint8_t *p_index_mem,const Array& p_arrays,bool p_main);
-
-	struct MultiMesh;
-
-	struct MultiMeshSurface : public Geometry {
-
-		Surface *surface;
-		MultiMeshSurface() { type=GEOMETRY_MULTISURFACE; }
-	};
-
-	struct MultiMesh : public GeometryOwner {
-
-		struct Element {
-
-			float matrix[16];
-			uint8_t color[4];
-		};
-
-		AABB aabb;
-		RID mesh;
-		int visible;
-
-		//IDirect3DVertexBuffer9* instance_buffer;
-		Vector<Element> elements;
-		Vector<MultiMeshSurface> cache_surfaces;
-		mutable uint64_t last_pass;
-
-		MultiMesh() {
-
-			last_pass=0;
-			visible = -1;
-		}
-	};
-
-	mutable RID_Owner<MultiMesh> multimesh_owner;
-
-
-	struct Immediate {
-
-		RID material;
-		int empty;
-	};
-
-	mutable RID_Owner<Immediate> immediate_owner;
-
-	struct Particles : public Geometry {
-
-		ParticleSystemSW data; // software particle system
-
-		Particles() {
-			type=GEOMETRY_PARTICLES;
-
-		}
-	};
-
-	mutable RID_Owner<Particles> particles_owner;
-
-	struct ParticlesInstance : public GeometryOwner {
-
-		RID particles;
-
-		ParticleSystemProcessSW particles_process;
-		Transform transform;
-
-		ParticlesInstance() {  }
-	};
-
-	mutable RID_Owner<ParticlesInstance> particles_instance_owner;
-	ParticleSystemDrawInfoSW particle_draw_info;
-
-	struct Skeleton {
-
-		Vector<Transform> bones;
-
-	};
-
-	mutable RID_Owner<Skeleton> skeleton_owner;
-
-
-	struct Light {
-
-		VS::LightType type;
-		float vars[VS::LIGHT_PARAM_MAX];
-		Color colors[3];
-		bool shadow_enabled;
-		RID projector;
-		bool volumetric_enabled;
-		Color volumetric_color;
-
-
-		Light() {
-
-			vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]=1;
-			vars[VS::LIGHT_PARAM_SPOT_ANGLE]=45;
-			vars[VS::LIGHT_PARAM_ATTENUATION]=1.0;
-			vars[VS::LIGHT_PARAM_ENERGY]=1.0;
-			vars[VS::LIGHT_PARAM_RADIUS]=1.0;
-			vars[VS::LIGHT_PARAM_SHADOW_Z_OFFSET]=0.05;
-
-			colors[VS::LIGHT_COLOR_DIFFUSE]=Color(1,1,1);
-			colors[VS::LIGHT_COLOR_SPECULAR]=Color(1,1,1);
-			shadow_enabled=false;
-			volumetric_enabled=false;
-		}
-	};
-
-
-	struct Environment {
-
-
-		VS::EnvironmentBG bg_mode;
-		Variant bg_param[VS::ENV_BG_PARAM_MAX];
-		bool fx_enabled[VS::ENV_FX_MAX];
-		Variant fx_param[VS::ENV_FX_PARAM_MAX];
-
-		Environment() {
-
-			bg_mode=VS::ENV_BG_DEFAULT_COLOR;
-			bg_param[VS::ENV_BG_PARAM_COLOR]=Color(0,0,0);
-			bg_param[VS::ENV_BG_PARAM_TEXTURE]=RID();
-			bg_param[VS::ENV_BG_PARAM_CUBEMAP]=RID();
-			bg_param[VS::ENV_BG_PARAM_ENERGY]=1.0;
-
-			for(int i=0;i<VS::ENV_FX_MAX;i++)
-				fx_enabled[i]=false;
-
-			fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES]=1;
-			fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM]=0.0;
-			fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD]=0.5;
-			fx_param[VS::ENV_FX_PARAM_DOF_BLUR_PASSES]=1;
-			fx_param[VS::ENV_FX_PARAM_DOF_BLUR_BEGIN]=100.0;
-			fx_param[VS::ENV_FX_PARAM_DOF_BLUR_RANGE]=10.0;
-			fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]=0.4;
-			fx_param[VS::ENV_FX_PARAM_HDR_WHITE]=1.0;
-			fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD]=0.95;
-			fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE]=0.2;
-			fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE]=0.4;
-			fx_param[VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE]=8.0;
-			fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED]=0.5;
-			fx_param[VS::ENV_FX_PARAM_FOG_BEGIN]=100.0;
-			fx_param[VS::ENV_FX_PARAM_FOG_ATTENUATION]=1.0;
-			fx_param[VS::ENV_FX_PARAM_FOG_BEGIN_COLOR]=Color(0,0,0);
-			fx_param[VS::ENV_FX_PARAM_FOG_END_COLOR]=Color(0,0,0);
-			fx_param[VS::ENV_FX_PARAM_FOG_BG]=true;
-			fx_param[VS::ENV_FX_PARAM_BCS_BRIGHTNESS]=1.0;
-			fx_param[VS::ENV_FX_PARAM_BCS_CONTRAST]=1.0;
-			fx_param[VS::ENV_FX_PARAM_BCS_SATURATION]=1.0;
-
-		}
-
-	};
-
-	mutable RID_Owner<Environment> environment_owner;
-
-	struct SampledLight {
-
-		int w,h;
-	};
-
-	mutable RID_Owner<SampledLight> sampled_light_owner;
-
-	struct ShadowBuffer;
-
-	struct LightInstance {
-
-		struct SplitInfo {
-
-			CameraMatrix camera;
-			Transform transform;
-			float near;
-			float far;
-		};
-
-		RID light;
-		Light *base;
-		Transform transform;
-		CameraMatrix projection;
-
-		Transform custom_transform;
-		CameraMatrix custom_projection;
-
-		Vector3 light_vector;
-		Vector3 spot_vector;
-		float linear_att;
-
-		uint64_t shadow_pass;
-		uint64_t last_pass;
-		uint16_t sort_key;
-
-		Vector<ShadowBuffer*> shadow_buffers;
-
-		void clear_shadow_buffers() {
-
-			for (int i=0;i<shadow_buffers.size();i++) {
-
-				ShadowBuffer *sb=shadow_buffers[i];
-				ERR_CONTINUE( sb->owner != this );
-
-				sb->owner=NULL;
-			}
-
-			shadow_buffers.clear();
-		}
-
-		LightInstance() { shadow_pass=0; last_pass=0; sort_key=0; }
-
-	};
-	mutable RID_Owner<Light> light_owner;
-	mutable RID_Owner<LightInstance> light_instance_owner;
-
-	LightInstance *light_instances[MAX_SCENE_LIGHTS];
-	LightInstance *directional_lights[4];
-//	LightInstance *directional_light_instances[MAX_SCENE_LIGHTS];
-	int light_instance_count;
-	int directional_light_count;
-	int last_light_id;
-
-
-	struct RenderList {
-
-		enum {
-			MAX_ELEMENTS=4096,
-			MAX_LIGHTS=4
-		};
-
-		struct Element {
-
-
-			float depth;
-			const InstanceData *instance;
-			const Skeleton *skeleton;
-			union {
-				uint16_t lights[MAX_HW_LIGHTS];
-				uint64_t light_key;
-			};
-
-			const Geometry *geometry;
-			const Material *material;
-			const GeometryOwner *owner;
-			uint16_t light_count;
-			bool mirror;
-
-
-		};
-
-
-		Element _elements[MAX_ELEMENTS];
-		Element *elements[MAX_ELEMENTS];
-		int element_count;
-
-		void clear() {
-
-			element_count=0;
-		}
-
-		struct SortZ {
-
-			_FORCE_INLINE_ bool operator()(const Element* A,  const Element* B ) const {
-
-				return A->depth > B->depth;
-			}
-		};
-
-		void sort_z() {
-
-			SortArray<Element*,SortZ> sorter;
-			sorter.sort(elements,element_count);
-		}
-
-
-		struct SortMat {
-
-			_FORCE_INLINE_ bool operator()(const Element* A,  const Element* B ) const {
-				// TODO move to a single uint64 (one comparison)
-				if (A->material == B->material) {
-
-					return A->light_key < B->light_key;
-				} else {
-
-					return (A->material < B->material);
-				}
-			}
-		};
-
-		void sort_mat() {
-
-			SortArray<Element*,SortMat> sorter;
-			sorter.sort(elements,element_count);
-		}
-
-		struct SortMatLight {
-
-			_FORCE_INLINE_ bool operator()(const Element* A,  const Element* B ) const {
-
-				if (A->material->flags[VS::MATERIAL_FLAG_UNSHADED] == B->material->flags[VS::MATERIAL_FLAG_UNSHADED]) {
-
-					if (A->material == B->material) {
-
-						if (A->geometry == B->geometry) {
-
-							return A->light_key<B->light_key;
-						} else
-							return (A->geometry < B->geometry);
-					} else {
-
-						return (A->material < B->material);
-					}
-				} else {
-
-					return (int(A->material->flags[VS::MATERIAL_FLAG_UNSHADED]) < int(B->material->flags[VS::MATERIAL_FLAG_UNSHADED]));
-				}
-			}
-		};
-
-		void sort_mat_light() {
-
-			SortArray<Element*,SortMatLight> sorter;
-			sorter.sort(elements,element_count);
-		}
-
-		_FORCE_INLINE_ Element* add_element() {
-
-			if (element_count>MAX_ELEMENTS)
-				return NULL;
-			elements[element_count]=&_elements[element_count];
-			return elements[element_count++];
-		}
-
-		RenderList() {
-
-			element_count = 0;
-			for (int i=0;i<MAX_ELEMENTS;i++)
-				elements[i]=&_elements[i]; // assign elements
-		}
-	};
-
-	RenderList opaque_render_list;
-	RenderList alpha_render_list;
-
-	RID default_material;
-
-	struct FX {
-
-		bool bgcolor_active;
-		Color bgcolor;
-
-		bool skybox_active;
-		RID skybox_cubemap;
-
-		bool antialias_active;
-		float antialias_tolerance;
-
-		bool glow_active;
-		int glow_passes;
-		float glow_attenuation;
-		float glow_bloom;
-
-		bool ssao_active;
-		float ssao_attenuation;
-		float ssao_radius;
-		float ssao_max_distance;
-		float ssao_range_max;
-		float ssao_range_min;
-		bool ssao_only;
-
-		bool fog_active;
-		float fog_near;
-		float fog_far;
-		float fog_attenuation;
-		Color fog_color_near;
-		Color fog_color_far;
-		bool fog_bg;
-
-		bool toon_active;
-		float toon_treshold;
-		float toon_soft;
-
-		bool edge_active;
-		Color edge_color;
-		float edge_size;
-
-		FX();
-
-	};
-	mutable RID_Owner<FX> fx_owner;
-
-
-	FX *scene_fx;
-	CameraMatrix camera_projection;
-	Transform camera_transform;
-	Transform camera_transform_inverse;
-	float camera_z_near;
-	float camera_z_far;
-	Size2 camera_vp_size;
-	Color last_color;
-
-	Plane camera_plane;
-
-	bool keep_copies;
-
-	bool depth_write;
-	bool depth_test;
-	int blend_mode;
-	bool lighting;
-
-	_FORCE_INLINE_ void _add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner);
-
-	void _render_list_forward(RenderList *p_render_list,bool p_reverse_cull=false);
-
-	void _setup_light(LightInstance* p_instance, int p_idx);
-	void _setup_lights(const uint16_t * p_lights,int p_light_count);
-
-	_FORCE_INLINE_ void _setup_shader_params(const Material *p_material);
-	void _setup_fixed_material(const Geometry *p_geometry,const Material *p_material);
-	void _setup_material(const Geometry *p_geometry,const Material *p_material);
-
-	Error _setup_geometry(const Geometry *p_geometry, const Material* p_material,const Skeleton *p_skeleton, const float *p_morphs);
-	void _render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton, const GeometryOwner *p_owner);
-
-
-	/***********/
-	/* SHADOWS */
-	/***********/
-
-	struct ShadowBuffer {
-
-		int size;
-		GLuint fbo;
-		GLuint depth;
-		LightInstance *owner;
-		void init(int p_size);
-		ShadowBuffer() { size=0; depth=0; owner=NULL; }
-	};
-
-	Vector<ShadowBuffer> near_shadow_buffers;
-	Vector<ShadowBuffer> far_shadow_buffers;
-
-	LightInstance *shadow;
-	int shadow_pass;
-	void _init_shadow_buffers();
-
-	float shadow_near_far_split_size_ratio;
-	bool _allocate_shadow_buffers(LightInstance *p_instance, Vector<ShadowBuffer>& p_buffers);
-	void _debug_draw_shadow(ShadowBuffer *p_buffer, const Rect2& p_rect);
-	void _debug_draw_shadows_type(Vector<ShadowBuffer>& p_shadows,Point2& ofs);
-	void _debug_shadows();
-	void reset_state();
-
-	/***********/
-	/*  FBOs   */
-	/***********/
-
-
-	struct FrameBuffer {
-
-		GLuint fbo;
-		GLuint color;
-		GLuint depth;
-		int width,height;
-		bool buff16;
-		bool active;
-
-		struct Blur {
-
-			GLuint fbo;
-			GLuint color;
-		} blur[2];
-
-	} framebuffer;
-
-	void _update_framebuffer();
-	void _process_glow_and_bloom();
-
-	/*********/
-	/* FRAME */
-	/*********/
-
-	struct _Rinfo {
-
-		int texture_mem;
-		int vertex_count;
-		int object_count;
-		int mat_change_count;
-		int shader_change_count;
-
-	} _rinfo;
-
-	GLuint white_tex;
-	RID canvas_tex;
-	float canvas_opacity;
-	VS::MaterialBlendMode canvas_blend;
-	_FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture);
-
-
-	int _setup_geometry_vinfo;
-
-	bool cull_front;
-	_FORCE_INLINE_ void _set_cull(bool p_front,bool p_reverse_cull=false);
-
-	Size2 window_size;
-	VS::ViewportRect viewport;
-	double last_time;
-	double time_delta;
-	uint64_t frame;
-	uint64_t scene_pass;
-
-	//void _draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color* p_colors, const Vector3 *p_uvs,const Plane *p_tangents=NULL,int p_instanced=1);
-	//void _draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size,bool p_h_flip=false, bool p_v_flip=false );
-	//void _draw_quad(const Rect2& p_rect);
-
-public:
-
-	/* TEXTURE API */
-
-	virtual RID texture_create();
-	virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT);
-	virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT);
-	virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const;
-	virtual void texture_set_flags(RID p_texture,uint32_t p_flags);
-	virtual uint32_t texture_get_flags(RID p_texture) const;
-	virtual Image::Format texture_get_format(RID p_texture) const;
-	virtual uint32_t texture_get_width(RID p_texture) const;
-	virtual uint32_t texture_get_height(RID p_texture) const;
-	virtual bool texture_has_alpha(RID p_texture) const;
-	virtual void texture_set_size_override(RID p_texture,int p_width, int p_height);
-	virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const;
-
-	/* SHADER API */
-
-	virtual RID shader_create(VS::ShaderMode p_mode=VS::SHADER_MATERIAL);
-
-	virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode);
-	virtual VS::ShaderMode shader_get_mode(RID p_shader) const;
-
-	virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs=0,int p_fragment_ofs=0,int p_light_ofs=0);
-	virtual String shader_get_fragment_code(RID p_shader) const;
-	virtual String shader_get_vertex_code(RID p_shader) const;
-	virtual String shader_get_light_code(RID p_shader) const;
-
-	virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
-
-	virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
-	virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
-
-	/* COMMON MATERIAL API */
-
-	virtual RID material_create();
-
-	virtual void material_set_shader(RID p_shader_material, RID p_shader);
-	virtual RID material_get_shader(RID p_shader_material) const;
-
-	virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value);
-	virtual Variant material_get_param(RID p_material, const StringName& p_param) const;
-
-	virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled);
-	virtual bool material_get_flag(RID p_material,VS::MaterialFlag p_flag) const;
-
-	virtual void material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode);
-	virtual VS::MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const;
-
-	virtual void material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode);
-	virtual VS::MaterialBlendMode material_get_blend_mode(RID p_material) const;
-
-	virtual void material_set_line_width(RID p_material,float p_line_width);
-	virtual float material_get_line_width(RID p_material) const;
-
-	/* FIXED MATERIAL */
-
-	virtual RID fixed_material_create();
-
-	virtual void fixed_material_set_flag(RID p_material, VS::FixedMaterialFlags p_flag, bool p_enabled);
-	virtual bool fixed_material_get_flag(RID p_material, VS::FixedMaterialFlags p_flag) const;
-
-	virtual void fixed_material_set_parameter(RID p_material, VS::FixedMaterialParam p_parameter, const Variant& p_value);
-	virtual Variant fixed_material_get_parameter(RID p_material,VS::FixedMaterialParam p_parameter) const;
-
-	virtual void fixed_material_set_texture(RID p_material,VS::FixedMaterialParam p_parameter, RID p_texture);
-	virtual RID fixed_material_get_texture(RID p_material,VS::FixedMaterialParam p_parameter) const;
-
-	virtual void fixed_material_set_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter, VS::FixedMaterialTexCoordMode p_mode);
-	virtual VS::FixedMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter) const;
-
-	virtual void fixed_material_set_uv_transform(RID p_material,const Transform& p_transform);
-	virtual Transform fixed_material_get_uv_transform(RID p_material) const;
-
-	virtual void fixed_material_set_point_size(RID p_material,float p_size);
-	virtual float fixed_material_get_point_size(RID p_material) const;
-
-	/* MESH API */
-
-
-	virtual RID mesh_create();
-
-	virtual void mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false);
-	virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const;
-	virtual Array mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const;
-	virtual void mesh_add_custom_surface(RID p_mesh,const Variant& p_dat);
-
-	virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount);
-	virtual int mesh_get_morph_target_count(RID p_mesh) const;
-
-	virtual void mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode);
-	virtual VS::MorphTargetMode mesh_get_morph_target_mode(RID p_mesh) const;
-
-	virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned=false);
-	virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
-
-	virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const;
-	virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const;
-	virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const;
-	virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const;
-
-	virtual void mesh_remove_surface(RID p_mesh,int p_index);
-	virtual int mesh_get_surface_count(RID p_mesh) const;
-
-	virtual AABB mesh_get_aabb(RID p_mesh,RID p_skeleton=RID()) const;
-
-	virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb);
-	virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
-
-	/* MULTIMESH API */
-
-	virtual RID multimesh_create();
-
-	virtual void multimesh_set_instance_count(RID p_multimesh,int p_count);
-	virtual int multimesh_get_instance_count(RID p_multimesh) const;
-
-	virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh);
-	virtual void multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb);
-	virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform);
-	virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color);
-
-	virtual RID multimesh_get_mesh(RID p_multimesh) const;
-	virtual AABB multimesh_get_aabb(RID p_multimesh) const;;
-
-	virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const;
-	virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const;
-
-	virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible);
-	virtual int multimesh_get_visible_instances(RID p_multimesh) const;
-
-	/* IMMEDIATE API */
-
-	virtual RID immediate_create();
-	virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID());
-	virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex);
-	virtual void immediate_normal(RID p_immediate,const Vector3& p_normal);
-	virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent);
-	virtual void immediate_color(RID p_immediate,const Color& p_color);
-	virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv);
-	virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv);
-	virtual void immediate_end(RID p_immediate);
-	virtual void immediate_clear(RID p_immediate);
-	virtual AABB immediate_get_aabb(RID p_immediate) const;
-	virtual void immediate_set_material(RID p_immediate,RID p_material);
-	virtual RID immediate_get_material(RID p_immediate) const;
-
-
-	/* PARTICLES API */
-
-	virtual RID particles_create();
-
-	virtual void particles_set_amount(RID p_particles, int p_amount);
-	virtual int particles_get_amount(RID p_particles) const;
-
-	virtual void particles_set_emitting(RID p_particles, bool p_emitting);
-	virtual bool particles_is_emitting(RID p_particles) const;
-
-	virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility);
-	virtual AABB particles_get_visibility_aabb(RID p_particles) const;
-
-	virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents);
-	virtual Vector3 particles_get_emission_half_extents(RID p_particles) const;
-
-	virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity);
-	virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const;
-
-	virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points);
-	virtual DVector<Vector3> particles_get_emission_points(RID p_particles) const;
-
-	virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal);
-	virtual Vector3 particles_get_gravity_normal(RID p_particles) const;
-
-	virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value);
-	virtual float particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const;
-
-	virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness);
-	virtual float particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const;
-
-	virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos);
-	virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const;
-
-	virtual void particles_set_color_phases(RID p_particles, int p_phases);
-	virtual int particles_get_color_phases(RID p_particles) const;
-
-	virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color);
-	virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const;
-
-	virtual void particles_set_attractors(RID p_particles, int p_attractors);
-	virtual int particles_get_attractors(RID p_particles) const;
-
-	virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos);
-	virtual Vector3 particles_get_attractor_pos(RID p_particles,int p_attractor) const;
-
-	virtual void particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force);
-	virtual float particles_get_attractor_strength(RID p_particles,int p_attractor) const;
-
-	virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false);
-	virtual RID particles_get_material(RID p_particles) const;
-
-	virtual AABB particles_get_aabb(RID p_particles) const;
-
-	virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable);
-	virtual bool particles_has_height_from_velocity(RID p_particles) const;
-
-	virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
-	virtual bool particles_is_using_local_coordinates(RID p_particles) const;
-
-	/* SKELETON API */
-
-	virtual RID skeleton_create();
-	virtual void skeleton_resize(RID p_skeleton,int p_bones);
-	virtual int skeleton_get_bone_count(RID p_skeleton) const;
-	virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform);
-	virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone);
-
-
-	/* LIGHT API */
-
-	virtual RID light_create(VS::LightType p_type);
-	virtual VS::LightType light_get_type(RID p_light) const;
-
-	virtual void light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color);
-	virtual Color light_get_color(RID p_light,VS::LightColor p_type) const;
-
-	virtual void light_set_shadow(RID p_light,bool p_enabled);
-	virtual bool light_has_shadow(RID p_light) const;
-
-	virtual void light_set_volumetric(RID p_light,bool p_enabled);
-	virtual bool light_is_volumetric(RID p_light) const;
-
-	virtual void light_set_projector(RID p_light,RID p_texture);
-	virtual RID light_get_projector(RID p_light) const;
-
-	virtual void light_set_var(RID p_light, VS::LightParam p_var, float p_value);
-	virtual float light_get_var(RID p_light, VS::LightParam p_var) const;
-
-	virtual void light_set_operator(RID p_light,VS::LightOp p_op);
-	virtual VS::LightOp light_get_operator(RID p_light) const;
-
-	virtual void light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode);
-	virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) const;
-
-
-	virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode);
-	virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) const;
-	virtual void light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value);
-	virtual float light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const;
-
-	virtual AABB light_get_aabb(RID p_poly) const;
-
-
-	virtual RID light_instance_create(RID p_light);
-	virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform);
-
-	virtual bool light_instance_has_shadow(RID p_light_instance) const;
-	virtual bool light_instance_assign_shadow(RID p_light_instance);
-	virtual ShadowType light_instance_get_shadow_type(RID p_light_instance) const;
-	virtual int light_instance_get_shadow_passes(RID p_light_instance) const;
-	virtual bool light_instance_get_pssm_shadow_overlap(RID p_light_instance) const;
-	virtual void light_instance_set_custom_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near=0,float p_split_far=0);
-	virtual int light_instance_get_shadow_size(RID p_light_instance, int p_index=0) const { return 1; }
-
-	virtual ShadowType light_instance_get_shadow_type(RID p_light_instance,bool p_far=false) const;
-	virtual void light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near=0,float p_split_far=0);
-
-	virtual void shadow_clear_near();
-	virtual bool shadow_allocate_near(RID p_light);
-	virtual bool shadow_allocate_far(RID p_light);
-
-
-	/* PARTICLES INSTANCE */
-
-	virtual RID particles_instance_create(RID p_particles);
-	virtual void particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform);
-
-	/* VIEWPORT */
-
-	virtual RID viewport_data_create();
-
-	virtual RID render_target_create();
-	virtual void render_target_set_size(RID p_render_target, int p_width, int p_height);
-	virtual RID render_target_get_texture(RID p_render_target) const;
-	virtual bool render_target_renedered_in_frame(RID p_render_target);
-
-	/* RENDER API */
-	/* all calls (inside begin/end shadow) are always warranted to be in the following order: */
-
-	virtual void begin_frame();
-
-	virtual void set_viewport(const VS::ViewportRect& p_viewport);
-	virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false);
-	virtual void clear_viewport(const Color& p_color);
-	virtual void capture_viewport(Image* r_capture);
-
-
-	virtual void begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug);
-	virtual void begin_shadow_map( RID p_light_instance, int p_shadow_pass );
-
-	virtual void set_camera(const Transform& p_world,const CameraMatrix& p_projection);
-
-	virtual void add_light( RID p_light_instance ); ///< all "add_light" calls happen before add_geometry calls
-
-
-	virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data);
-	virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data);
-	virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data) {}
-	virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data);
-
-	virtual void end_scene();
-	virtual void end_shadow_map();
-
-	virtual void end_frame();
-
-	/* CANVAS API */
-
-	virtual void canvas_begin();
-	virtual void canvas_disable_blending();
-	virtual void canvas_set_opacity(float p_opacity);
-	virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode);
-	virtual void canvas_begin_rect(const Matrix32& p_transform);
-	virtual void canvas_set_clip(bool p_clip, const Rect2& p_rect);
-	virtual void canvas_end_rect();
-	virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width);
-	virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate);
-	virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1));
-	virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width);
-	virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
-	virtual void canvas_set_transform(const Matrix32& p_transform);
-
-	/* FX */
-
-	virtual RID fx_create();
-	virtual void fx_get_effects(RID p_fx,List<String> *p_effects) const;
-	virtual void fx_set_active(RID p_fx,const String& p_effect, bool p_active);
-	virtual bool fx_is_active(RID p_fx,const String& p_effect) const;
-	virtual void fx_get_effect_params(RID p_fx,const String& p_effect,List<PropertyInfo> *p_params) const;
-	virtual Variant fx_get_effect_param(RID p_fx,const String& p_effect,const String& p_param) const;
-	virtual void fx_set_effect_param(RID p_fx,const String& p_effect, const String& p_param, const Variant& p_pvalue);
-
-	/* ENVIRONMENT */
-
-	virtual RID environment_create();
-
-	virtual void environment_set_background(RID p_env,VS::EnvironmentBG p_bg);
-	virtual VS::EnvironmentBG environment_get_background(RID p_env) const;
-
-	virtual void environment_set_background_param(RID p_env,VS::EnvironmentBGParam p_param, const Variant& p_value);
-	virtual Variant environment_get_background_param(RID p_env,VS::EnvironmentBGParam p_param) const;
-
-	virtual void environment_set_enable_fx(RID p_env,VS::EnvironmentFx p_effect,bool p_enabled);
-	virtual bool environment_is_fx_enabled(RID p_env,VS::EnvironmentFx p_effect) const;
-
-	virtual void environment_fx_set_param(RID p_env,VS::EnvironmentFxParam p_param,const Variant& p_value);
-	virtual Variant environment_fx_get_param(RID p_env,VS::EnvironmentFxParam p_param) const;
-
-	/* SAMPLED LIGHT */
-	virtual RID sampled_light_dp_create(int p_width,int p_height);
-	virtual void sampled_light_dp_update(RID p_sampled_light,const Color *p_data,float p_multiplier);
-
-
-	/*MISC*/
-
-	virtual bool is_texture(const RID& p_rid) const;
-	virtual bool is_material(const RID& p_rid) const;
-	virtual bool is_mesh(const RID& p_rid) const;
-	virtual bool is_multimesh(const RID& p_rid) const;
-	virtual bool is_immediate(const RID& p_rid) const;
-	virtual bool is_particles(const RID &p_beam) const;
-
-	virtual bool is_light(const RID& p_rid) const;
-	virtual bool is_light_instance(const RID& p_rid) const;
-	virtual bool is_particles_instance(const RID& p_rid) const;
-	virtual bool is_skeleton(const RID& p_rid) const;
-	virtual bool is_environment(const RID& p_rid) const;
-	virtual bool is_fx(const RID& p_rid) const;
-	virtual bool is_shader(const RID& p_rid) const;
-
-	virtual void free(const RID& p_rid);
-
-	virtual void custom_shade_model_set_shader(int p_model, RID p_shader);
-	virtual RID custom_shade_model_get_shader(int p_model) const;
-	virtual void custom_shade_model_set_name(int p_model, const String& p_name);
-	virtual String custom_shade_model_get_name(int p_model) const;
-	virtual void custom_shade_model_set_param_info(int p_model, const List<PropertyInfo>& p_info);
-	virtual void custom_shade_model_get_param_info(int p_model, List<PropertyInfo>* p_info) const;
-
-
-	virtual void init();
-	virtual void finish();
-
-	virtual int get_render_info(VS::RenderInfo p_info);
-
-	void reload_vram();
-
-	virtual bool needs_to_draw_next_frame() const;
-
-	virtual bool has_feature(VS::Features p_feature) const;
-
-
-#ifdef TOOLS_ENABLED
-	RasterizerGLES1(bool p_keep_copies=true,bool p_use_reload_hooks=false);
-#else
-	RasterizerGLES1(bool p_keep_copies=false,bool p_use_reload_hooks=false);
-#endif
-	virtual ~RasterizerGLES1();
-};
-
-#endif
-#endif

+ 471 - 37
drivers/gles2/rasterizer_gles2.cpp

@@ -1411,6 +1411,9 @@ void RasterizerGLES2::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
 			case VS::SHADER_MATERIAL: {
 				material_shader.free_custom_shader(shader->custom_code_id);
 			} break;
+			case VS::SHADER_CANVAS_ITEM: {
+				canvas_shader.free_custom_shader(shader->custom_code_id);
+			} break;
 		}
 
 		shader->custom_code_id=0;
@@ -1422,6 +1425,9 @@ void RasterizerGLES2::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
 		case VS::SHADER_MATERIAL: {
 			shader->custom_code_id=material_shader.create_custom_shader();
 		} break;
+		case VS::SHADER_CANVAS_ITEM: {
+			shader->custom_code_id=canvas_shader.create_custom_shader();
+		} break;
 	}
 	_shader_make_dirty(shader);
 
@@ -1545,17 +1551,20 @@ void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const Strin
 
 	Shader *shader=shader_owner.get(p_shader);
 	ERR_FAIL_COND(!shader);
-	ERR_FAIL_COND(!texture_owner.owns(p_texture));
+	ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
 
 	if (p_texture.is_valid())
 		shader->default_textures[p_name]=p_texture;
 	else
 		shader->default_textures.erase(p_name);
 
+	_shader_make_dirty(shader);
+
 }
 
 RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
 	const Shader *shader=shader_owner.get(p_shader);
+	ERR_FAIL_COND_V(!shader,RID());
 
 	const Map<StringName,RID>::Element *E=shader->default_textures.find(p_name);
 	if (!E)
@@ -1563,6 +1572,22 @@ RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const String
 	return E->get();
 }
 
+Variant RasterizerGLES2::shader_get_default_param(RID p_shader, const StringName& p_name) {
+
+	Shader *shader=shader_owner.get(p_shader);
+	ERR_FAIL_COND_V(!shader,Variant());
+
+	//update shader params if necesary
+	//make sure the shader is compiled and everything
+	//so the actual parameters can be properly retrieved!
+	if (shader->dirty_list.in_list()) {
+		_update_shader(shader);
+	}
+	if (shader->valid && shader->uniforms.has(p_name))
+		return shader->uniforms[p_name].default_value;
+
+	return Variant();
+}
 
 
 /* COMMON MATERIAL API */
@@ -1606,6 +1631,7 @@ void RasterizerGLES2::material_set_param(RID p_material, const StringName& p_par
 			material->shader_version=0; //get default!
 		} else {
 			E->get().value=p_value;
+			E->get().inuse=true;
 		}
 	} else {
 
@@ -1613,6 +1639,7 @@ void RasterizerGLES2::material_set_param(RID p_material, const StringName& p_par
 		ud.index=-1;
 		ud.value=p_value;
 		ud.istexture=p_value.get_type()==Variant::_RID; /// cache it being texture
+		ud.inuse=true;
 		material->shader_params[p_param]=ud; //may be got at some point, or erased
 
 	}
@@ -1644,7 +1671,7 @@ Variant RasterizerGLES2::material_get_param(RID p_material, const StringName& p_
 	}
 
 
-	if (material->shader_params.has(p_param))
+	if (material->shader_params.has(p_param) && material->shader_params[p_param].inuse)
 		return material->shader_params[p_param].value;
 	else
 		return Variant();
@@ -4430,6 +4457,13 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
 		if (err) {
 			return; //invalid
 		}
+	} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
+
+		Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX,vertex_code,vertex_globals,vertex_flags,&p_shader->uniforms);
+		if (err) {
+			return; //invalid
+		}
+
 	}
 
 	//print_line("compiled vertex: "+vertex_code);
@@ -4439,9 +4473,16 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
 	String fragment_code;
 	String fragment_globals;
 
-	Error err = shader_precompiler.compile(p_shader->fragment_code,(p_shader->mode==VS::SHADER_MATERIAL?ShaderLanguage::SHADER_MATERIAL_FRAGMENT:ShaderLanguage::SHADER_POST_PROCESS),fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
-	if (err) {
-		return; //invalid
+	if (p_shader->mode==VS::SHADER_MATERIAL) {
+		Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
+		if (err) {
+			return; //invalid
+		}
+	} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
+		Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
+		if (err) {
+			return; //invalid
+		}
 	}
 
 
@@ -4454,6 +4495,11 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
 		if (err) {
 			return; //invalid
 		}
+	} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
+		Error err = shader_precompiler.compile(p_shader->light_code,(ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT),light_code,light_globals,light_flags,&p_shader->uniforms);
+		if (err) {
+			return; //invalid
+		}
 	}
 
 	fragment_globals+=light_globals; //both fragment anyway
@@ -4514,7 +4560,39 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
 		}
 
 		material_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
-	} else {
+	} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
+
+		Vector<const char*> enablers;
+
+		if (light_flags.uses_time || fragment_flags.uses_time || vertex_flags.uses_time) {
+			enablers.push_back("#define USE_TIME\n");
+			uses_time=true;
+		}
+		if (fragment_flags.uses_normal) {
+			enablers.push_back("#define NORMAL_USED\n");
+		}
+		if (light_flags.uses_light) {
+			enablers.push_back("#define USE_LIGHT_SHADER_CODE\n");
+		}
+		if (fragment_flags.use_var1_interp || vertex_flags.use_var1_interp)
+			enablers.push_back("#define ENABLE_VAR1_INTERP\n");
+		if (fragment_flags.use_var2_interp || vertex_flags.use_var2_interp)
+			enablers.push_back("#define ENABLE_VAR2_INTERP\n");
+		if (fragment_flags.uses_texscreen) {
+			enablers.push_back("#define ENABLE_TEXSCREEN\n");
+		}
+		if (fragment_flags.uses_screen_uv) {
+			enablers.push_back("#define ENABLE_SCREEN_UV\n");
+		}
+		if (fragment_flags.uses_texpixel_size) {
+			enablers.push_back("#define USE_TEXPIXEL_SIZE\n");
+		}
+
+		if (vertex_flags.uses_worldvec) {
+			enablers.push_back("#define USE_WORLD_VEC\n");
+		}
+		canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
+
 		//postprocess_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names);
 	}
 
@@ -4525,7 +4603,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
 	p_shader->has_texscreen=fragment_flags.uses_texscreen;
 	p_shader->has_screen_uv=fragment_flags.uses_screen_uv;
 	p_shader->can_zpass=!fragment_flags.uses_discard && !vertex_flags.vertex_code_writes_vertex;
+	p_shader->uses_normal=fragment_flags.uses_normal || light_flags.uses_normal;
 	p_shader->uses_time=uses_time;
+	p_shader->uses_texpixel_size=fragment_flags.uses_texpixel_size;
 	p_shader->version++;
 
 }
@@ -4876,31 +4956,58 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
 
 		Material::UniformData ud;
 
-		bool keep=true;
+		bool keep=true; //keep material value
 
-		if (!old_mparams.has(E->key()))
+		Map<StringName,Material::UniformData>::Element *OLD=old_mparams.find(E->key());
+		bool has_old = OLD;
+		bool old_inuse=has_old && old_mparams[E->key()].inuse;
+
+		ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
+
+		if (!has_old || !old_inuse) {
 			keep=false;
-		else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) {
+		}
+		else if (OLD->get().value.get_type()!=E->value().default_value.get_type()) {
 
-			if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
+			if (OLD->get().value.get_type()==Variant::INT && E->get().type==ShaderLanguage::TYPE_FLOAT) {
+				//handle common mistake using shaders (feeding ints instead of float)
+				OLD->get().value=float(OLD->get().value);
+				keep=true;
+			} else if (!ud.istexture && E->value().default_value.get_type()!=Variant::NIL) {
+
+				keep=false;
+			}
+			//type changed between old and new
+			/*	if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
 				if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures
 					keep=false;
 			} else if (!old_mparams[E->key()].value.is_num() || !E->value().default_value.get_type())
-				keep=false;
+				keep=false;*/
+
+			//value is invalid because type differs and default is not null
+			;
 		}
 
+
 		if (keep) {
 			ud.value=old_mparams[E->key()].value;
+
 			//print_line("KEEP: "+String(E->key()));
 		} else {
-			ud.value=E->value().default_value;
+			if (ud.istexture && p_material->shader_cache->default_textures.has(E->key()))
+				ud.value=p_material->shader_cache->default_textures[E->key()];
+			else
+				ud.value=E->value().default_value;
+			old_inuse=false; //if reverted to default, obviously did not work
+
 			//print_line("NEW: "+String(E->key())+" because: hasold-"+itos(old_mparams.has(E->key())));
 			//if (old_mparams.has(E->key()))
 			//	print_line(" told "+Variant::get_type_name(old_mparams[E->key()].value.get_type())+" tnew "+Variant::get_type_name(E->value().default_value.get_type()));
 		}
 
-		ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
+
 		ud.index=idx++;
+		ud.inuse=old_inuse;
 		mparams[E->key()]=ud;
 	}
 
@@ -5004,8 +5111,10 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
 		int texcoord=0;
 		for (Map<StringName,Material::UniformData>::Element *E=p_material->shader_params.front();E;E=E->next()) {
 
+
 			if (E->get().index<0)
 				continue;
+//			print_line(String(E->key())+": "+E->get().value);
 			if (E->get().istexture) {
 				//clearly a texture..
 				RID rid = E->get().value;
@@ -5021,23 +5130,8 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
 						E->get().value=RID(); //nullify, invalid texture
 						rid=RID();
 					}
-				} else {
-
-
 				}
 
-				if (!rid.is_valid()) {
-					//use from default textures
-					Map<StringName,RID>::Element *F=p_material->shader_cache->default_textures.find(E->key());
-					if (F) {
-						t=texture_owner.get(F->get());
-						if (!t) {
-							p_material->shader_cache->default_textures.erase(E->key());
-						}
-					}
-				}
-
-
 				glActiveTexture(GL_TEXTURE0+texcoord);
 				glUniform1i(loc,texcoord); //TODO - this could happen automatically on compile...
 				if (t) {
@@ -5061,15 +5155,10 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
 
 		}
 
-		for (Map<StringName,RID>::Element *E=p_material->shader_cache->default_textures.front();E;E=E->next()) {
-			if (p_material->shader_params.has(E->key()))
-				continue;
-
-
-		}
 
 		if (p_material->shader_cache->has_texscreen && framebuffer.active) {
 			material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
+			material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(0,0,float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
 			material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_TEX,texcoord);
 			glActiveTexture(GL_TEXTURE0+texcoord);
 			glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
@@ -7724,10 +7813,11 @@ void RasterizerGLES2::canvas_begin() {
 	canvas_tex=RID();
 	//material_shader.unbind();
 	canvas_shader.unbind();
+	canvas_shader.set_custom_shader(0);
 	canvas_shader.bind();
 	canvas_shader.set_uniform(CanvasShaderGLES2::TEXTURE, 0);
 	_set_color_attrib(Color(1,1,1));
-	Transform canvas_transform;
+	canvas_transform=Transform();
 	canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f);
 	float csy = 1.0;
 	if (current_rt && current_rt_vflip)
@@ -7741,6 +7831,9 @@ void RasterizerGLES2::canvas_begin() {
 	canvas_opacity=1.0;
 	canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
 
+	canvas_texscreen_used=false;
+	uses_texpixel_size=false;
+	canvas_last_shader=RID();
 
 }
 
@@ -7823,7 +7916,7 @@ void RasterizerGLES2::canvas_end_rect() {
 
 RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_texture) {
 
-	if (p_texture==canvas_tex) {
+	if (p_texture==canvas_tex && !rebind_texpixel_size) {
 		if (canvas_tex.is_valid()) {
 			Texture*texture=texture_owner.get(p_texture);
 			return texture;
@@ -7831,14 +7924,16 @@ RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_tex
 		return NULL;
 	}
 
-
+	rebind_texpixel_size=false;
 
 	if (p_texture.is_valid()) {
 
+
 		Texture*texture=texture_owner.get(p_texture);
 		if (!texture) {
 			canvas_tex=RID();
 			glBindTexture(GL_TEXTURE_2D,white_tex);
+
 			return NULL;
 		}
 
@@ -7847,6 +7942,9 @@ RasterizerGLES2::Texture* RasterizerGLES2::_bind_canvas_texture(const RID& p_tex
 
 		glBindTexture(GL_TEXTURE_2D,texture->tex_id);
 		canvas_tex=p_texture;
+		if (uses_texpixel_size) {
+			canvas_shader.set_uniform(CanvasShaderGLES2::TEXPIXEL_SIZE,Size2(1.0/texture->width,1.0/texture->height));
+		}
 		return texture;
 
 
@@ -8217,6 +8315,342 @@ void RasterizerGLES2::canvas_set_transform(const Matrix32& p_transform) {
 	//canvas_transform = Variant(p_transform);
 }
 
+
+void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
+
+
+	CanvasItem *current_clip=NULL;
+
+	canvas_opacity=1.0;
+	while(p_item_list) {
+
+		CanvasItem *ci=p_item_list;
+
+		if (ci->vp_render) {
+			if (draw_viewport_func) {
+				draw_viewport_func(ci->vp_render->owner,ci->vp_render->udata,ci->vp_render->rect);
+			}
+			memdelete(ci->vp_render);
+			ci->vp_render=NULL;
+			canvas_last_shader=RID();
+		}
+
+		if (current_clip!=ci->final_clip_owner) {
+
+			current_clip=ci->final_clip_owner;
+
+			//setup clip
+			if (current_clip) {
+
+				glEnable(GL_SCISSOR_TEST);
+				glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
+				current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
+			} else {
+
+				glDisable(GL_SCISSOR_TEST);
+			}
+		}
+
+
+		//begin rect
+		CanvasItem *shader_owner = ci->shader_owner?ci->shader_owner:ci;
+
+		if (shader_owner->shader!=canvas_last_shader) {
+
+			Shader *shader = NULL;
+			if (shader_owner->shader.is_valid()) {
+				shader = this->shader_owner.get(shader_owner->shader);
+				if (shader && !shader->valid) {
+					shader=NULL;
+				}
+			}
+
+			if (shader) {
+				canvas_shader.set_custom_shader(shader->custom_code_id);
+				if (canvas_shader.bind())
+					rebind_texpixel_size=true;
+
+				if (shader_owner->shader_version!=shader->version) {
+					//todo optimize uniforms
+					shader_owner->shader_version=shader->version;
+				}
+				//this can be optimized..
+				int tex_id=1;
+				int idx=0;
+				for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
+
+					Map<StringName,Variant>::Element *F=shader_owner->shader_param.find(E->key());
+
+					if ((E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP)) {
+
+						RID rid;
+						if (F) {
+							rid=F->get();
+						}
+
+						if (!rid.is_valid()) {
+
+							Map<StringName,RID>::Element *DT=shader->default_textures.find(E->key());
+							if (DT) {
+								rid=DT->get();
+							}
+						}
+
+						if (rid.is_valid()) {
+
+							int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic..
+
+							glActiveTexture(GL_TEXTURE0+tex_id);
+							Texture *t=texture_owner.get(rid);
+							if (!t)
+								glBindTexture(GL_TEXTURE_2D,white_tex);
+							else
+								glBindTexture(t->target,t->tex_id);
+
+							glUniform1i(loc,tex_id);
+							tex_id++;
+						}
+					} else {
+						Variant &v=F?F->get():E->get().default_value;
+						canvas_shader.set_custom_uniform(idx,v);
+					}
+
+					idx++;
+				}
+
+
+				if (shader->has_texscreen && framebuffer.active) {
+
+					int x = viewport.x;
+					int y = window_size.height-(viewport.height+viewport.y);
+
+					canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
+					canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(float(x)/framebuffer.width,float(y)/framebuffer.height,float(x+viewport.width)/framebuffer.width,float(y+viewport.height)/framebuffer.height));
+					canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_TEX,tex_id);
+					glActiveTexture(GL_TEXTURE0+tex_id);
+					glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
+					if (framebuffer.scale==1 && !canvas_texscreen_used) {
+#ifdef GLEW_ENABLED
+						glReadBuffer(GL_COLOR_ATTACHMENT0);
+#endif
+						glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
+						if (current_clip) {
+						//	print_line(" a clip ");
+						}
+
+						canvas_texscreen_used=true;
+					}
+					tex_id++;
+
+				}
+
+				if (tex_id>1) {
+					glActiveTexture(GL_TEXTURE0);
+				}
+				if (shader->has_screen_uv) {
+					canvas_shader.set_uniform(CanvasShaderGLES2::SCREEN_UV_MULT,Vector2(1.0/viewport.width,1.0/viewport.height));
+				}
+
+				if (shader->uses_time) {
+					canvas_shader.set_uniform(CanvasShaderGLES2::TIME,Math::fmod(last_time,300.0));
+					draw_next_frame=true;
+				}
+					//if uses TIME - draw_next_frame=true
+
+				uses_texpixel_size=shader->uses_texpixel_size;
+
+			} else {
+				canvas_shader.set_custom_shader(0);
+				canvas_shader.bind();
+				uses_texpixel_size=false;
+
+			}
+
+
+			canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
+			canvas_last_shader=shader_owner->shader;
+		}
+
+		canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
+		canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32());
+
+
+		bool reclip=false;
+
+		if (ci==p_item_list || ci->blend_mode!=canvas_blend_mode) {
+
+			switch(ci->blend_mode) {
+
+				 case VS::MATERIAL_BLEND_MODE_MIX: {
+					glBlendEquation(GL_FUNC_ADD);
+					glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+
+				 } break;
+				 case VS::MATERIAL_BLEND_MODE_ADD: {
+
+					glBlendEquation(GL_FUNC_ADD);
+					glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+
+				 } break;
+				 case VS::MATERIAL_BLEND_MODE_SUB: {
+
+					glBlendEquation(GL_FUNC_SUBTRACT);
+					glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+				 } break;
+				case VS::MATERIAL_BLEND_MODE_MUL: {
+					glBlendEquation(GL_FUNC_ADD);
+					glBlendFunc(GL_DST_COLOR,GL_ZERO);
+				} break;
+				case VS::MATERIAL_BLEND_MODE_PREMULT_ALPHA: {
+					glBlendEquation(GL_FUNC_ADD);
+					glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
+				} break;
+
+			}
+
+			canvas_blend_mode=ci->blend_mode;
+		}
+
+		int cc=ci->commands.size();
+		CanvasItem::Command **commands = ci->commands.ptr();
+
+		canvas_opacity = ci->final_opacity;
+
+		for(int i=0;i<cc;i++) {
+
+			CanvasItem::Command *c=commands[i];
+
+			switch(c->type) {
+				case CanvasItem::Command::TYPE_LINE: {
+
+					CanvasItem::CommandLine* line = static_cast<CanvasItem::CommandLine*>(c);
+					canvas_draw_line(line->from,line->to,line->color,line->width);
+				} break;
+				case CanvasItem::Command::TYPE_RECT: {
+
+					CanvasItem::CommandRect* rect = static_cast<CanvasItem::CommandRect*>(c);
+//						canvas_draw_rect(rect->rect,rect->region,rect->source,rect->flags&CanvasItem::CommandRect::FLAG_TILE,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H,rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V,rect->texture,rect->modulate);
+#if 0
+					int flags=0;
+
+					if (rect->flags&CanvasItem::CommandRect::FLAG_REGION) {
+						flags|=Rasterizer::CANVAS_RECT_REGION;
+					}
+					if (rect->flags&CanvasItem::CommandRect::FLAG_TILE) {
+						flags|=Rasterizer::CANVAS_RECT_TILE;
+					}
+					if (rect->flags&CanvasItem::CommandRect::FLAG_FLIP_H) {
+
+						flags|=Rasterizer::CANVAS_RECT_FLIP_H;
+					}
+					if (rect->flags&CanvasItem::CommandRect::FLAG_FLIP_V) {
+
+						flags|=Rasterizer::CANVAS_RECT_FLIP_V;
+					}
+#else
+
+					int flags=rect->flags;
+#endif
+					canvas_draw_rect(rect->rect,flags,rect->source,rect->texture,rect->modulate);
+
+				} break;
+				case CanvasItem::Command::TYPE_STYLE: {
+
+					CanvasItem::CommandStyle* style = static_cast<CanvasItem::CommandStyle*>(c);
+					canvas_draw_style_box(style->rect,style->texture,style->margin,style->draw_center,style->color);
+
+				} break;
+				case CanvasItem::Command::TYPE_PRIMITIVE: {
+
+					CanvasItem::CommandPrimitive* primitive = static_cast<CanvasItem::CommandPrimitive*>(c);
+					canvas_draw_primitive(primitive->points,primitive->colors,primitive->uvs,primitive->texture,primitive->width);
+				} break;
+				case CanvasItem::Command::TYPE_POLYGON: {
+
+					CanvasItem::CommandPolygon* polygon = static_cast<CanvasItem::CommandPolygon*>(c);
+					canvas_draw_polygon(polygon->count,polygon->indices.ptr(),polygon->points.ptr(),polygon->uvs.ptr(),polygon->colors.ptr(),polygon->texture,polygon->colors.size()==1);
+
+				} break;
+
+				case CanvasItem::Command::TYPE_POLYGON_PTR: {
+
+					CanvasItem::CommandPolygonPtr* polygon = static_cast<CanvasItem::CommandPolygonPtr*>(c);
+					canvas_draw_polygon(polygon->count,polygon->indices,polygon->points,polygon->uvs,polygon->colors,polygon->texture,false);
+				} break;
+				case CanvasItem::Command::TYPE_CIRCLE: {
+
+					CanvasItem::CommandCircle* circle = static_cast<CanvasItem::CommandCircle*>(c);
+					static const int numpoints=32;
+					Vector2 points[numpoints+1];
+					points[numpoints]=circle->pos;
+					int indices[numpoints*3];
+
+					for(int i=0;i<numpoints;i++) {
+
+						points[i]=circle->pos+Vector2( Math::sin(i*Math_PI*2.0/numpoints),Math::cos(i*Math_PI*2.0/numpoints) )*circle->radius;
+						indices[i*3+0]=i;
+						indices[i*3+1]=(i+1)%numpoints;
+						indices[i*3+2]=numpoints;
+					}
+					canvas_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
+					//canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
+				} break;
+				case CanvasItem::Command::TYPE_TRANSFORM: {
+
+					CanvasItem::CommandTransform* transform = static_cast<CanvasItem::CommandTransform*>(c);
+					canvas_set_transform(transform->xform);
+				} break;
+				case CanvasItem::Command::TYPE_BLEND_MODE: {
+
+					CanvasItem::CommandBlendMode* bm = static_cast<CanvasItem::CommandBlendMode*>(c);
+					canvas_set_blend_mode(bm->blend_mode);
+
+				} break;
+				case CanvasItem::Command::TYPE_CLIP_IGNORE: {
+
+					CanvasItem::CommandClipIgnore* ci = static_cast<CanvasItem::CommandClipIgnore*>(c);
+					if (current_clip) {
+
+						if (ci->ignore!=reclip) {
+							if (ci->ignore) {
+
+								glDisable(GL_SCISSOR_TEST);
+								reclip=true;
+							} else  {
+
+								glEnable(GL_SCISSOR_TEST);
+								glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
+								current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
+								reclip=false;
+							}
+						}
+					}
+
+
+
+				} break;
+			}
+		}
+
+
+		if (reclip) {
+
+			glEnable(GL_SCISSOR_TEST);
+			glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
+			current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
+		}
+
+
+
+		p_item_list=p_item_list->next;
+	}
+
+	if (current_clip) {
+		glDisable(GL_SCISSOR_TEST);
+	}
+
+}
+
 /* ENVIRONMENT */
 
 RID RasterizerGLES2::environment_create() {

+ 17 - 2
drivers/gles2/rasterizer_gles2.h

@@ -191,6 +191,8 @@ class RasterizerGLES2 : public Rasterizer {
 		bool writes_vertex;
 		bool uses_discard;
 		bool uses_time;
+		bool uses_normal;
+		bool uses_texpixel_size;
 
 		Map<StringName,ShaderLanguage::Uniform> uniforms;
 		StringName first_texture;
@@ -214,6 +216,7 @@ class RasterizerGLES2 : public Rasterizer {
 			writes_vertex=false;
 			uses_discard=false;
 			uses_time=false;
+			uses_normal=false;
 		}
 
 
@@ -241,8 +244,9 @@ class RasterizerGLES2 : public Rasterizer {
 
 		struct UniformData {
 
+			bool inuse;
 			bool istexture;
-			Variant value;
+			Variant value;			
 			int index;
 		};
 
@@ -1168,6 +1172,13 @@ class RasterizerGLES2 : public Rasterizer {
 	GLuint white_tex;
 	RID canvas_tex;
 	float canvas_opacity;
+	bool uses_texpixel_size;
+	bool rebind_texpixel_size;
+	Transform canvas_transform;
+	RID canvas_last_shader;
+	bool canvas_texscreen_used;
+
+
 	_FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture);
 	VS::MaterialBlendMode canvas_blend_mode;
 
@@ -1198,7 +1209,7 @@ class RasterizerGLES2 : public Rasterizer {
 	RID overdraw_material;
 
 	mutable MaterialShaderGLES2 material_shader;
-	CanvasShaderGLES2 canvas_shader;
+	mutable CanvasShaderGLES2 canvas_shader;
 	BlurShaderGLES2 blur_shader;
 	CopyShaderGLES2 copy_shader;
 
@@ -1259,6 +1270,8 @@ public:
 	virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
 	virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
 
+	virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name);
+
 	/* COMMON MATERIAL API */
 
 	virtual RID material_create();
@@ -1535,6 +1548,8 @@ public:
 	virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
 	virtual void canvas_set_transform(const Matrix32& p_transform);
 
+	virtual void canvas_render_items(CanvasItem *p_item_list);
+
 	/* ENVIRONMENT */
 
 

+ 104 - 5
drivers/gles2/shader_compiler_gles2.cpp

@@ -131,6 +131,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 			SL::BlockNode *bnode=(SL::BlockNode*)p_node;
 
 			//variables
+			code+="{"ENDL;
 			for(Map<StringName,SL::DataType>::Element *E=bnode->variables.front();E;E=E->next()) {
 
 				code+=_mktab(p_level)+_typestr(E->value())+" "+replace_string(E->key())+";"ENDL;
@@ -141,10 +142,12 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 				code+=_mktab(p_level)+dump_node_code(bnode->statements[i],p_level)+";"ENDL;
 			}
 
+			code+="}"ENDL;
 
 		} break;
 		case SL::Node::TYPE_VARIABLE: {
 			SL::VariableNode *vnode=(SL::VariableNode*)p_node;
+
 			if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX) {
 
 				if (vnode->name==vname_vertex && p_assign_left) {
@@ -171,6 +174,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 
 
 			}
+
+
+
 			if (type==ShaderLanguage::SHADER_MATERIAL_FRAGMENT) {
 
 				if (vnode->name==vname_discard) {
@@ -211,6 +217,50 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 					uses_light=true;
 				}
 
+			}
+			if (type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
+
+				if (vnode->name==vname_var1_interp) {
+					flags->use_var1_interp=true;
+				}
+				if (vnode->name==vname_var2_interp) {
+					flags->use_var2_interp=true;
+				}
+				if (vnode->name==vname_world_vec) {
+					uses_worldvec=true;
+				}
+
+			}
+
+
+			if (type==ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT) {
+
+
+				if (vnode->name==vname_texpixel_size) {
+					uses_texpixel_size=true;
+				}
+				if (vnode->name==vname_normal) {
+					uses_normal=true;
+				}
+
+				if (vnode->name==vname_screen_uv) {
+					uses_screen_uv=true;
+				}
+
+				if (vnode->name==vname_var1_interp) {
+					flags->use_var1_interp=true;
+				}
+				if (vnode->name==vname_var2_interp) {
+					flags->use_var2_interp=true;
+				}
+			}
+
+			if (type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) {
+
+				if (vnode->name==vname_light) {
+					uses_light=true;
+				}
+
 			}
 
 			if (vnode->name==vname_time) {
@@ -260,13 +310,13 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 
 						String mul_l=dump_node_code(onode->arguments[0],p_level,true);
 						String mul_r=dump_node_code(onode->arguments[1],p_level);
-						code=mul_l+"=(vec4("+mul_l+",1.0,1.0)*("+mul_r+")).xy";
+						code=mul_l+"=(vec4("+mul_l+",0.0,1.0)*("+mul_r+")).xy";
 						break;
 					} else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
 
 						String mul_l=dump_node_code(onode->arguments[0],p_level,true);
 						String mul_r=dump_node_code(onode->arguments[1],p_level);
-						code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",1.0,1.0)).xy";
+						code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",0.0,1.0)).xy";
 						break;
 					} else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT3) {
 						String mul_l=dump_node_code(onode->arguments[0],p_level,true);
@@ -296,11 +346,11 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 						break;
 					} else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
 
-						code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",1.0,1.0)).xyz";
+						code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",0.0,1.0)).xy";
 						break;
 					} else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) {
 
-						code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",1.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xyz";
+						code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",0.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xy";
 						break;
 					} else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT3 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
 
@@ -357,7 +407,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
 					} else if (callfunc=="texscreen") {
 						//create the call to sample the screen, and clamp it
 						uses_texscreen=true;
-						code="(texture2D( texscreen_tex, min(("+dump_node_code(onode->arguments[1],p_level)+").xy*texscreen_screen_mult,texscreen_screen_mult))).rgb";
+						code="(texture2D( texscreen_tex, clamp(("+dump_node_code(onode->arguments[1],p_level)+").xy*texscreen_screen_mult,texscreen_screen_clamp.xy,texscreen_screen_clamp.zw))).rgb";
 						//code="(texture2D( screen_texture, ("+dump_node_code(onode->arguments[1],p_level)+").xy).rgb";
 						break;
 					} else if (callfunc=="texpos") {
@@ -550,6 +600,9 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
 	uses_light=false;
 	uses_time=false;
 	uses_normalmap=false;
+	uses_normal=false;
+	uses_texpixel_size=false;
+	uses_worldvec=false;
 	vertex_code_writes_vertex=false;
 	uniforms=r_uniforms;
 	flags=&r_flags;
@@ -560,6 +613,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
 	r_flags.use_var1_interp=false;
 	r_flags.use_var2_interp=false;
 	r_flags.uses_normalmap=false;
+	r_flags.uses_normal=false;
 
 	String error;
 	int errline,errcol;
@@ -582,6 +636,9 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
 	r_flags.uses_light=uses_light;
 	r_flags.uses_time=uses_time;
 	r_flags.uses_normalmap=uses_normalmap;
+	r_flags.uses_normal=uses_normalmap;
+	r_flags.uses_texpixel_size=uses_texpixel_size;
+	r_flags.uses_worldvec=uses_worldvec;
 	r_code_line=code;
 	r_globals_line=global_code;
 
@@ -638,6 +695,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
 	replace_table["cross" ]="cross";
 	replace_table["normalize"]= "normalize";
 	replace_table["reflect"]= "reflect";
+	replace_table["refract"]= "refract";
 	replace_table["tex"]= "tex";
 	replace_table["texa"]= "texa";
 	replace_table["tex2"]= "tex2";
@@ -676,6 +734,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
 	//mode_replace_table[1]["POSITION"]="IN_POSITION";
 	mode_replace_table[1]["NORMAL"]="normal";
 	mode_replace_table[1]["TANGENT"]="tangent";
+	mode_replace_table[1]["POSITION"]="gl_Position";
 	mode_replace_table[1]["BINORMAL"]="binormal";
 	mode_replace_table[1]["NORMALMAP"]="normalmap";
 	mode_replace_table[1]["NORMALMAP_DEPTH"]="normaldepth";
@@ -718,6 +777,43 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
 	mode_replace_table[2]["POINT_COORD"]="gl_PointCoord";
 	mode_replace_table[2]["TIME"]="time";
 
+	mode_replace_table[3]["SRC_VERTEX"]="src_vtx";
+	mode_replace_table[3]["VERTEX"]="outvec.xy";
+	mode_replace_table[3]["WORLD_VERTEX"]="outvec.xy";
+	mode_replace_table[3]["UV"]="uv_interp";
+	mode_replace_table[3]["COLOR"]="color_interp";
+	mode_replace_table[3]["VAR1"]="var1_interp";
+	mode_replace_table[3]["VAR2"]="var2_interp";
+	mode_replace_table[3]["POINT_SIZE"]="gl_PointSize";
+	mode_replace_table[3]["WORLD_MATRIX"]="modelview_matrix";
+	mode_replace_table[3]["PROJECTION_MATRIX"]="projection_matrix";
+	mode_replace_table[3]["EXTRA_MATRIX"]="extra_matrix";
+	mode_replace_table[3]["TIME"]="time";
+
+	mode_replace_table[4]["POSITION"]="gl_Position";
+	mode_replace_table[4]["NORMAL"]="normal";
+	mode_replace_table[4]["UV"]="uv_interp";
+	mode_replace_table[4]["SRC_COLOR"]="color_interp";
+	mode_replace_table[4]["COLOR"]="color";
+	mode_replace_table[4]["TEXTURE"]="texture";
+	mode_replace_table[4]["TEXTURE_PIXEL_SIZE"]="texpixel_size";
+	mode_replace_table[4]["VAR1"]="var1_interp";
+	mode_replace_table[4]["VAR2"]="var2_interp";
+	mode_replace_table[4]["SCREEN_UV"]="screen_uv";
+	mode_replace_table[4]["POINT_COORD"]="gl_PointCoord";
+	mode_replace_table[4]["TIME"]="time";
+
+	mode_replace_table[5]["SRC_COLOR"]="color";
+	mode_replace_table[5]["COLOR"]="color";
+	mode_replace_table[5]["NORMAL"]="normal";
+	mode_replace_table[5]["LIGHT_DIR"]="light_dir";
+	mode_replace_table[5]["LIGHT_DISTANCE"]="light_distance";
+	mode_replace_table[5]["LIGHT"]="light";
+	mode_replace_table[5]["POINT_COORD"]="gl_PointCoord";
+	mode_replace_table[5]["TIME"]="time";
+
+
+
 	//mode_replace_table[2]["SCREEN_POS"]="SCREEN_POS";
 	//mode_replace_table[2]["SCREEN_TEXEL_SIZE"]="SCREEN_TEXEL_SIZE";
 
@@ -738,5 +834,8 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
 	vname_light="LIGHT";
 	vname_time="TIME";
 	vname_normalmap="NORMALMAP";
+	vname_normal="NORMAL";
+	vname_texpixel_size="TEXTURE_PIXEL_SIZE";
+	vname_world_vec="WORLD_VERTEX";
 
 }

+ 10 - 1
drivers/gles2/shader_compiler_gles2.h

@@ -51,6 +51,9 @@ private:
 	bool uses_time;
 	bool uses_screen_uv;
 	bool uses_normalmap;
+	bool uses_normal;
+	bool uses_texpixel_size;
+	bool uses_worldvec;
 	bool vertex_code_writes_vertex;
 	Flags *flags;
 
@@ -68,6 +71,9 @@ private:
 	StringName vname_light;
 	StringName vname_time;
 	StringName vname_normalmap;
+	StringName vname_normal;
+	StringName vname_texpixel_size;
+	StringName vname_world_vec;
 
 	Map<StringName,ShaderLanguage::Uniform> *uniforms;
 
@@ -79,7 +85,7 @@ private:
 
 	String replace_string(const StringName& p_string);
 
-	Map<StringName,StringName> mode_replace_table[3];
+	Map<StringName,StringName> mode_replace_table[9];
 	Map<StringName,StringName> replace_table;
 
 public:
@@ -101,6 +107,9 @@ public:
 		bool use_var2_interp;
 		bool uses_light;
 		bool uses_time;
+		bool uses_normal;
+		bool uses_texpixel_size;
+		bool uses_worldvec;
 	};
 
 	Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map<StringName,ShaderLanguage::Uniform> *r_uniforms=NULL);

+ 140 - 5
drivers/gles2/shaders/canvas.glsl

@@ -18,20 +18,60 @@ attribute highp vec2 uv_attrib; // attrib:4
 varying vec2 uv_interp;
 varying vec4 color_interp;
 
+#if defined(USE_TIME)
+uniform float time;
+#endif
+
+
+#ifdef USE_LIGHTING
+
+uniform highp mat4 light_matrix;
+varying vec4 light_tex_pos;
+
+#endif
+
+#if defined(ENABLE_VAR1_INTERP)
+varying vec4 var1_interp;
+#endif
+
+#if defined(ENABLE_VAR2_INTERP)
+varying vec4 var2_interp;
+#endif
+
 //uniform bool snap_pixels;
 
+VERTEX_SHADER_GLOBALS
+
 void main() {
 
 	color_interp = color_attrib;
 	uv_interp = uv_attrib;		
-	highp vec4 outvec = vec4(vertex, 1.0);
-	outvec = extra_matrix * outvec;
-	outvec = modelview_matrix * outvec;
+        highp vec4 outvec = vec4(vertex, 1.0);
+{
+        vec2 src_vtx=outvec.xy;
+VERTEX_SHADER_CODE
+
+}
+#if !defined(USE_WORLD_VEC)
+        outvec = extra_matrix * outvec;
+        outvec = modelview_matrix * outvec;
+#endif
+
 #ifdef USE_PIXEL_SNAP
 
-		outvec.xy=floor(outvec.xy+0.5);
+	outvec.xy=floor(outvec.xy+0.5);
 #endif
+
+
 	gl_Position = projection_matrix * outvec;
+
+#ifdef USE_LIGHTING
+
+	light_tex_pos.xy = light_matrix * gl_Position;
+	light_tex_pos.zw=outvec.xy - light_matrix[4].xy; //likely wrong
+
+#endif
+
 }
 
 [fragment]
@@ -54,17 +94,112 @@ varying vec4 color_interp;
 
 #endif
 
+#if defined(ENABLE_SCREEN_UV)
+
+uniform vec2 screen_uv_mult;
+
+#endif
+
+#if defined(ENABLE_TEXSCREEN)
+
+uniform vec2 texscreen_screen_mult;
+uniform vec4 texscreen_screen_clamp;
+uniform sampler2D texscreen_tex;
+
+#endif
+
+
+#if defined(ENABLE_VAR1_INTERP)
+varying vec4 var1_interp;
+#endif
+
+#if defined(ENABLE_VAR2_INTERP)
+varying vec4 var2_interp;
+#endif
+
+#if defined(USE_TIME)
+uniform float time;
+#endif
+
+
+#ifdef USE_LIGHTING
+
+uniform sampler2D light_texture;
+varying vec4 light_tex_pos;
+
+#ifdef USE_SHADOWS
+
+uniform sampler2D shadow_texture;
+uniform float shadow_attenuation;
+
+#endif
+
+#endif
+
+#if defined(USE_TEXPIXEL_SIZE)
+uniform vec2 texpixel_size;
+#endif
+
+
+FRAGMENT_SHADER_GLOBALS
+
+
 void main() {
 
 	vec4 color = color_interp;
-	
+#if defined(NORMAL_USED)
+	vec3 normal = vec3(0,0,1);
+#endif
+
 	color *= texture2D( texture,  uv_interp );
+#if defined(ENABLE_SCREEN_UV)
+	vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult;
+#endif
 
+{
+FRAGMENT_SHADER_CODE
+}
 #ifdef DEBUG_ENCODED_32
 	highp float enc32 = dot( color,highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1)  );
 	color = vec4(vec3(enc32),1.0);
 #endif
 
+#ifdef USE_LIGHTING
+
+	float att=1.0;
+
+	vec3 light = texture2D(light_texture,light_tex_pos).rgb;
+#ifdef USE_SHADOWS
+	//this might not be that great on mobile?
+	float light_dist = length(light_texture.zw);
+	float light_angle = atan2(light_texture.x,light_texture.z) + 1.0 * 0.5;
+	float shadow_dist = texture2D(shadow_texture,vec2(light_angle,0));
+	if (light_dist>shadow_dist) {
+		light*=shadow_attenuation;
+	}
+//use shadows
+#endif
+
+#if defined(USE_LIGHT_SHADER_CODE)
+//light is written by the light shader
+{
+	vec2 light_dir = normalize(light_tex_pos.zw);
+	float light_distance = length(light_tex_pos.zw);
+LIGHT_SHADER_CODE
+}
+#else
+
+#if defined(NORMAL_USED)
+	vec2 light_normal = normalize(light_tex_pos.zw);
+	light = color.rgb * light * max(dot(light_normal,normal),0);
+#endif
+
+	color.rgb=light;
+//light shader code
+#endif
+
+//use lighting
+#endif
 //	color.rgb*=color.a;
 	gl_FragColor = color;
 

+ 1 - 0
drivers/gles2/shaders/material.glsl

@@ -779,6 +779,7 @@ uniform highp mat4 camera_inverse_transform;
 #if defined(ENABLE_TEXSCREEN)
 
 uniform vec2 texscreen_screen_mult;
+uniform vec4 texscreen_screen_clamp;
 uniform sampler2D texscreen_tex;
 
 #endif

+ 2 - 2
drivers/png/resource_saver_png.cpp

@@ -64,10 +64,10 @@ Error ResourceSaverPNG::save(const String &p_path,const RES& p_resource,uint32_t
 			text+=bool(texture->get_flags()&Texture::FLAG_FILTER)?"filter=true\n":"filter=false\n";
 		}
 		if (global_mipmaps!=bool(texture->get_flags()&Texture::FLAG_MIPMAPS)) {
-			text+=bool(texture->get_flags()&Texture::FLAG_FILTER)?"gen_mipmaps=true\n":"gen_mipmaps=false\n";
+			text+=bool(texture->get_flags()&Texture::FLAG_MIPMAPS)?"gen_mipmaps=true\n":"gen_mipmaps=false\n";
 		}
 		if (global_repeat!=bool(texture->get_flags()&Texture::FLAG_REPEAT)) {
-			text+=bool(texture->get_flags()&Texture::FLAG_FILTER)?"repeat=true\n":"repeat=false\n";
+			text+=bool(texture->get_flags()&Texture::FLAG_REPEAT)?"repeat=true\n":"repeat=false\n";
 		}
 		if (bool(texture->get_flags()&Texture::FLAG_ANISOTROPIC_FILTER)) {
 			text+="anisotropic=true\n";

+ 1 - 1
drivers/theoraplayer/SCsub

@@ -70,7 +70,7 @@ if env["platform"] == "iphone":
 		env_theora.Append(CPPFLAGS=["-D_IOS", "-D__ARM_NEON__", "-fstrict-aliasing", "-fmessage-length=210", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fcolor-diagnostics", "-Wno-trigraphs", "-fpascal-strings", "-fvisibility=hidden", "-fvisibility-inlines-hidden"])
 
 env_theora.Append(CPPFLAGS=["-D_LIB", "-D__THEORA"]) # removed -D_YUV_C
-env_theora.Append(CPPFLAGS=["-D_YUV_LIBYUV", "-DLIBYUV_NEON"])
+env_theora.Append(CPPFLAGS=["-D_YUV_LIBYUV"])
 #env_theora.Append(CPPFLAGS=["-D_YUV_C"])
 
 if env["platform"] == "iphone":

+ 36 - 0
methods.py

@@ -1316,3 +1316,39 @@ def save_active_platforms(apnames,ap):
 		logow = open(wf,"wb")
 		logow.write(str)
 
+
+def colored(sys,env):
+
+	#If the output is not a terminal, do nothing
+	if not sys.stdout.isatty():
+		return
+
+	colors = {}
+	colors['cyan']   = '\033[96m'
+	colors['purple'] = '\033[95m'
+	colors['blue']   = '\033[94m'
+	colors['green']  = '\033[92m'
+	colors['yellow'] = '\033[93m'
+	colors['red']    = '\033[91m'
+	colors['end']    = '\033[0m'
+
+	compile_source_message        = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
+	java_compile_source_message   = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
+	compile_shared_source_message = '%sCompiling shared %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
+	link_program_message          = '%sLinking Program        %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
+	link_library_message          = '%sLinking Static Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
+	ranlib_library_message        = '%sRanlib Library         %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
+	link_shared_library_message   = '%sLinking Shared Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
+	java_library_message          = '%sCreating Java Archive  %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
+
+	env.Append( CXXCOMSTR=[compile_source_message] )
+	env.Append( CCCOMSTR=[compile_source_message] )
+	env.Append( SHCCCOMSTR=[compile_shared_source_message] )
+	env.Append( SHCXXCOMSTR=[compile_shared_source_message] )
+	env.Append( ARCOMSTR=[link_library_message] )
+	env.Append( RANLIBCOMSTR=[ranlib_library_message] )
+	env.Append( SHLINKCOMSTR=[link_shared_library_message] )
+	env.Append( LINKCOMSTR=[link_program_message] )
+	env.Append( JARCOMSTR=[java_library_message] )
+	env.Append( JAVACCOMSTR=[java_compile_source_message] )
+

+ 53 - 69
modules/gdscript/gd_compiler.h

@@ -37,77 +37,65 @@ class GDCompiler {
 
 	const GDParser *parser;
 	struct CodeGen {
-
-
 		GDScript *script;
 		const GDParser::ClassNode *class_node;
 		const GDParser::FunctionNode *function_node;
-
-
-        bool debug_stack;
-
-
-        List< Map<StringName,int> > stack_id_stack;
-		Map<StringName,int> stack_identifiers;
-
-        List<GDFunction::StackDebug> stack_debug;
-        List< Map<StringName,int> > block_identifier_stack;
-        Map<StringName,int> block_identifiers;
-
-
-        void add_stack_identifier(const StringName& p_id,int p_stackpos) {
-
-            stack_identifiers[p_id]=p_stackpos;
-            if (debug_stack) {
-
-                block_identifiers[p_id]=p_stackpos;
-                GDFunction::StackDebug sd;
-                sd.added=true;
-                sd.line=current_line;
-                sd.identifier=p_id;
-                sd.pos=p_stackpos;
-                stack_debug.push_back(sd);
-            }
-        }
-
-        void push_stack_identifiers() {
-
-            stack_id_stack.push_back( stack_identifiers );
-            if (debug_stack) {
-
-                block_identifier_stack.push_back(block_identifiers);
-                block_identifiers.clear();
-            }
-        }
-
-        void pop_stack_identifiers() {
-
-            stack_identifiers = stack_id_stack.back()->get();
-            stack_id_stack.pop_back();
-
-            if (debug_stack) {
-                for (Map<StringName,int>::Element *E=block_identifiers.front();E;E=E->next()) {
-
-                    GDFunction::StackDebug sd;
-                    sd.added=false;
-                    sd.identifier=E->key();
-                    sd.line=current_line;
-                    sd.pos=E->get();
-                    stack_debug.push_back(sd);
-                }
-                block_identifiers=block_identifier_stack.back()->get();
-                block_identifier_stack.pop_back();
-            }
-
-        }
-
-
-	//	int get_identifier_pos(const StringName& p_dentifier) const;
+		bool debug_stack;
+
+	        List< Map<StringName,int> > stack_id_stack;
+			Map<StringName,int> stack_identifiers;
+	
+	        List<GDFunction::StackDebug> stack_debug;
+	        List< Map<StringName,int> > block_identifier_stack;
+	        Map<StringName,int> block_identifiers;
+
+	        void add_stack_identifier(const StringName& p_id,int p_stackpos) {
+	            stack_identifiers[p_id]=p_stackpos;
+	            if (debug_stack) {
+	                block_identifiers[p_id]=p_stackpos;
+	                GDFunction::StackDebug sd;
+	                sd.added=true;
+	                sd.line=current_line;
+	                sd.identifier=p_id;
+	                sd.pos=p_stackpos;
+	                stack_debug.push_back(sd);
+	            }
+	        }
+
+	        void push_stack_identifiers() {
+	            stack_id_stack.push_back( stack_identifiers );
+	            if (debug_stack) {
+	
+	                block_identifier_stack.push_back(block_identifiers);
+	                block_identifiers.clear();
+	            }
+	        }
+
+	        void pop_stack_identifiers() {
+	            stack_identifiers = stack_id_stack.back()->get();
+	            stack_id_stack.pop_back();
+	
+	            if (debug_stack) {
+	                for (Map<StringName,int>::Element *E=block_identifiers.front();E;E=E->next()) {
+	
+	                    GDFunction::StackDebug sd;
+	                    sd.added=false;
+	                    sd.identifier=E->key();
+	                    sd.line=current_line;
+	                    sd.pos=E->get();
+	                    stack_debug.push_back(sd);
+	                }
+	                block_identifiers=block_identifier_stack.back()->get();
+	                block_identifier_stack.pop_back();
+	            }
+	        }
+
+
+		//int get_identifier_pos(const StringName& p_dentifier) const;
 		HashMap<Variant,int,VariantHasher> constant_map;
 		Map<StringName,int> name_map;
 
 		int get_name_map_pos(const StringName& p_identifier) {
-
 			int ret;
 			if (!name_map.has(p_identifier)) {
 				ret=name_map.size();
@@ -118,11 +106,7 @@ class GDCompiler {
 			return ret;
 		}
 
-
-
 		int get_constant_pos(const Variant& p_constant) {
-
-
 			if (constant_map.has(p_constant))
 				return constant_map[p_constant];
 			int pos = constant_map.size();
@@ -134,7 +118,7 @@ class GDCompiler {
 		void alloc_stack(int p_level) { if (p_level >= stack_max) stack_max=p_level+1; }
 		void alloc_call(int p_params) { if (p_params >= call_max) call_max=p_params; }
 
-        int current_line;
+        	int current_line;
 		int stack_max;
 		int call_max;
 	};

+ 1 - 1
modules/gdscript/gd_editor.cpp

@@ -1661,7 +1661,7 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
 	//print_line( p_code.replace(String::chr(0xFFFF),"<cursor>"));
 
 	GDParser p;
-	Error err = p.parse(p_code,p_base_path);
+	Error err = p.parse(p_code,p_base_path,true);
 	bool isfunction=false;
 	Set<String> options;
 

+ 3 - 3
platform/android/detect.py

@@ -124,11 +124,11 @@ def configure(env):
 #	env['CCFLAGS'] = string.split('-DNO_THREADS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv5te -mtune=xscale -msoft-float  -fno-exceptions -mthumb -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED ')
 
 	if env['x86']=='yes':
-		env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__  -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
+		env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__  -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED')
 	elif env["armv6"]!="no":
-		env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__  -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
+		env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__  -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED')
 	else:
-		env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__GLIBC__  -Wno-psabi -march=armv6 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
+		env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__GLIBC__  -Wno-psabi -march=armv6 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED')
 
 	env.Append(LDPATH=[ld_path])
 	env.Append(LIBS=['OpenSLES'])

+ 1 - 1
platform/android/globals/global_defaults.cpp

@@ -10,5 +10,5 @@ void register_android_global_defaults() {
 	GLOBAL_DEF("display.Android/driver","GLES2");
 //	GLOBAL_DEF("rasterizer.Android/trilinear_mipmap_filter",false);
 
-	Globals::get_singleton()->set_custom_property_info("display.Android/driver",PropertyInfo(Variant::STRING,"display.Android/driver",PROPERTY_HINT_ENUM,"GLES1,GLES2"));
+	Globals::get_singleton()->set_custom_property_info("display.Android/driver",PropertyInfo(Variant::STRING,"display.Android/driver",PROPERTY_HINT_ENUM,"GLES2"));
 }

+ 2 - 4
platform/android/java_glue.cpp

@@ -205,6 +205,7 @@ Variant _jobject_to_variant(JNIEnv * env, jobject obj) {
 	String name = _get_class_name(env, c, &array);
 	//print_line("name is " + name + ", array "+Variant(array));
 
+	print_line("ARGNAME: "+name);
 	if (name == "java.lang.String") {
 
 		return String::utf8(env->GetStringUTFChars( (jstring)obj, NULL ));
@@ -821,10 +822,7 @@ JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_initialize(JNIEnv * env,
 	String vd = Globals::get_singleton()->get("display/driver");
 
 
-	if (vd.to_upper()=="GLES1")
-		env->CallVoidMethod(_godot_instance, _on_video_init, (jboolean)false);
-	else
-		env->CallVoidMethod(_godot_instance, _on_video_init, (jboolean)true);
+	env->CallVoidMethod(_godot_instance, _on_video_init, (jboolean)true);
 
 	__android_log_print(ANDROID_LOG_INFO,"godot","**START");
 

+ 5 - 5
platform/android/os_android.cpp

@@ -28,7 +28,7 @@
 /*************************************************************************/
 #include "os_android.h"
 #include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles1/rasterizer_gles1.h"
+
 #include "core/io/file_access_buffered_fa.h"
 #include "drivers/unix/file_access_unix.h"
 #include "drivers/unix/dir_access_unix.h"
@@ -49,11 +49,11 @@
 
 int OS_Android::get_video_driver_count() const {
 
-	return 2;
+	return 1;
 }
 const char * OS_Android::get_video_driver_name(int p_driver) const {
 
-	return p_driver==0?"GLES2":"GLES1";
+	return "GLES2";
 }
 
 OS::VideoMode OS_Android::get_default_video_mode() const {
@@ -123,13 +123,13 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_
 	AudioDriverManagerSW::add_driver(&audio_driver_android);
 
 
-	if (use_gl2) {
+	if (true) {
 		RasterizerGLES2 *rasterizer_gles22=memnew( RasterizerGLES2(false,use_reload_hooks,false,use_reload_hooks ) );
 		if (gl_extensions)
 			rasterizer_gles22->set_extensions(gl_extensions);
 		rasterizer = rasterizer_gles22;
 	} else {
-		rasterizer = memnew( RasterizerGLES1(use_reload_hooks, use_reload_hooks) );
+		//rasterizer = memnew( RasterizerGLES1(use_reload_hooks, use_reload_hooks) );
 
 	}
 

+ 0 - 2
platform/iphone/SCsub

@@ -25,8 +25,6 @@ env_ios = env.Clone();
 if env['ios_gles22_override'] == "yes":
 	env_ios.Append(CPPFLAGS=['-DGLES2_OVERRIDE'])
 
-if env['ios_GLES1_override'] == "yes":
-	env_ios.Append(CPPFLAGS=['-DGLES1_OVERRIDE'])
 
 if env['ios_appirater'] == "yes":
 	env_ios.Append(CPPFLAGS=['-DAPPIRATER_ENABLED'])

+ 1 - 2
platform/iphone/detect.py

@@ -26,7 +26,6 @@ def get_opts():
 		('game_center', 'Support for game center', 'yes'),
 		('store_kit', 'Support for in-app store', 'yes'),
 		('ios_gles22_override', 'Force GLES2.0 on iOS', 'yes'),
-		('ios_GLES1_override', 'Force legacy GLES (1.1) on iOS', 'no'),
 		('ios_appirater', 'Enable Appirater', 'no'),
 		('ios_exceptions', 'Use exceptions when compiling on playbook', 'yes'),
 	]
@@ -130,7 +129,7 @@ def configure(env):
 
 
 	env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
-	env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES1_ENABLED', '-DMPC_FIXED_POINT'])
+	env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DMPC_FIXED_POINT'])
 	if env['ios_exceptions'] == 'yes':
 		env.Append(CPPFLAGS=['-fexceptions'])
 	else:

+ 0 - 4
platform/iphone/gl_view.mm

@@ -307,11 +307,7 @@ static void clear_touches() {
 										nil];
 	
 	// Create our EAGLContext, and if successful make it current and create our framebuffer.
-#ifdef GLES1_OVERRIDE
-	context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
-#else
 	context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
-#endif
 
 	if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer])
 	{

+ 2 - 6
platform/iphone/os_iphone.cpp

@@ -31,7 +31,7 @@
 #include "os_iphone.h"
 
 #include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles1/rasterizer_gles1.h"
+
 
 #include "servers/visual/visual_server_raster.h"
 #include "servers/visual/visual_server_wrap_mt.h"
@@ -52,7 +52,7 @@ int OSIPhone::get_video_driver_count() const {
 
 const char * OSIPhone::get_video_driver_name(int p_driver) const {
 
-	return "openglES";
+	return "GLES2";
 };
 
 OSIPhone* OSIPhone::get_singleton() {
@@ -106,13 +106,9 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au
 	supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false)?1:0) << PortraitDown);
 	supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false)?1:0) << PortraitUp);
 
-#ifdef GLES1_OVERRIDE
-	rasterizer = memnew( RasterizerGLES1 );
-#else
 	rasterizer_gles22 = memnew( RasterizerGLES2(false, false, false) );
 	rasterizer = rasterizer_gles22;
 	rasterizer_gles22->set_base_framebuffer(gl_view_base_fb);
-#endif
 
 	visual_server = memnew( VisualServerRaster(rasterizer) );
 	if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {

+ 1 - 1
platform/iphone/platform_config.h

@@ -28,6 +28,6 @@
 /*************************************************************************/
 #include <alloca.h>
 #define GLES2_INCLUDE_H <ES2/gl.h>
-#define GLES1_INCLUDE_H <ES1/gl.h>
+
 
 #define PLATFORM_REFCOUNT

+ 0 - 2
platform/isim/SCsub

@@ -25,8 +25,6 @@ env_ios = env.Clone();
 if env['ios_gles22_override'] == "yes":
 	env_ios.Append(CPPFLAGS=['-DGLES2_OVERRIDE'])
 
-if env['ios_GLES1_override'] == "yes":
-	env_ios.Append(CPPFLAGS=['-DGLES1_OVERRIDE'])
 
 if env['ios_appirater'] == "yes":
 	env_ios.Append(CPPFLAGS=['-DAPPIRATER_ENABLED'])

+ 1 - 1
platform/nacl/os_nacl.cpp

@@ -64,7 +64,7 @@ int OSNacl::get_video_driver_count() const {
 };
 const char * OSNacl::get_video_driver_name(int p_driver) const {
 
-	return "gles2";
+	return "GLES2";
 };
 
 OS::VideoMode OSNacl::get_default_video_mode() const {

+ 4 - 1
platform/osx/detect.py

@@ -78,12 +78,15 @@ def configure(env):
 	env.Append(LIBS=['pthread'])
 	#env.Append(CPPFLAGS=['-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-mmacosx-version-min=10.4'])
 	#env.Append(LINKFLAGS=['-mmacosx-version-min=10.4', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk'])
-	env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit','-lz'])
+	env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit','-lz'])
 
 	if (env["CXX"]=="clang++"):
 		env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
 		env["CC"]="clang"
 		env["LD"]="clang++"
+		if (env["colored"]=="yes"):
+			if sys.stdout.isatty():
+				env.Append(CPPFLAGS=["-fcolor-diagnostics"])
 
 	import methods
 

+ 2 - 0
platform/osx/os_osx.h

@@ -156,6 +156,8 @@ public:
 
 	virtual String get_executable_path() const;
 
+	virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
+
 	virtual void move_window_to_foreground();
 
 	void run();

+ 94 - 0
platform/osx/os_osx.mm

@@ -27,6 +27,8 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 #import <Cocoa/Cocoa.h>
+
+#include <Carbon/Carbon.h>
 #include <IOKit/IOKitLib.h>
 #include <IOKit/IOCFPlugIn.h>
 #include <IOKit/hid/IOHIDLib.h>
@@ -835,11 +837,24 @@ void OS_OSX::initialize_core() {
 
 }
 
+static bool keyboard_layout_dirty = true;
+static void keyboardLayoutChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
+	keyboard_layout_dirty = true;
+}
+
 void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
 
 	/*** OSX INITIALIZATION ***/
 	/*** OSX INITIALIZATION ***/
 	/*** OSX INITIALIZATION ***/
+
+	keyboard_layout_dirty = true;
+
+	// Register to be notified on keyboard layout changes
+	CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
+									NULL, keyboardLayoutChanged,
+									kTISNotifySelectedKeyboardInputSourceChanged, NULL,
+									CFNotificationSuspensionBehaviorDeliverImmediately);
     
 	window_delegate = [[GodotWindowDelegate alloc] init];
 
@@ -1007,6 +1022,8 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
 }
 void OS_OSX::finalize() {
 
+	CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
+
 }
 
 void OS_OSX::set_main_loop( MainLoop * p_main_loop ) {
@@ -1241,6 +1258,83 @@ String OS_OSX::get_executable_path() const {
 
 }
 
+// Returns string representation of keys, if they are printable.
+//
+static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) {
+
+	TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
+	if (!currentKeyboard)
+		return nil;
+
+	CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
+	if (!layoutData)
+		return nil;
+
+	const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
+
+	OSStatus err;
+	CFMutableStringRef output = CFStringCreateMutable(NULL, 0);
+
+	for (int i=0; i<length; ++i) {
+
+		UInt32 keysDown = 0;
+		UniChar chars[4];
+		UniCharCount realLength;
+
+		err = UCKeyTranslate(keyboardLayout,
+					   keyCode[i],
+					   kUCKeyActionDisplay,
+					   0,
+					   LMGetKbdType(),
+					   kUCKeyTranslateNoDeadKeysBit,
+					   &keysDown,
+					   sizeof(chars) / sizeof(chars[0]),
+					   &realLength,
+					   chars);
+
+		if (err != noErr) {
+			CFRelease(output);
+			return nil;
+		}
+
+		CFStringAppendCharacters(output, chars, 1);
+	}
+
+	//CFStringUppercase(output, NULL);
+
+	return (NSString *)output;
+}
+OS::LatinKeyboardVariant OS_OSX::get_latin_keyboard_variant() const {
+
+	static LatinKeyboardVariant layout = LATIN_KEYBOARD_QWERTY;
+
+	if (keyboard_layout_dirty) {
+
+		layout = LATIN_KEYBOARD_QWERTY;
+
+		CGKeyCode keys[] = {kVK_ANSI_Q, kVK_ANSI_W, kVK_ANSI_E, kVK_ANSI_R, kVK_ANSI_T, kVK_ANSI_Y};
+		NSString *test = createStringForKeys(keys, 6);
+
+		if ([test isEqualToString:@"qwertz"]) {
+			layout = LATIN_KEYBOARD_QWERTZ;
+		} else if ([test isEqualToString:@"azerty"]) {
+			layout = LATIN_KEYBOARD_AZERTY;
+		} else if ([test isEqualToString:@"qzerty"]) {
+			layout = LATIN_KEYBOARD_QZERTY;
+		} else if ([test isEqualToString:@"',.pyf"]) {
+			layout = LATIN_KEYBOARD_DVORAK;
+		} else if ([test isEqualToString:@"xvlcwk"]) {
+			layout = LATIN_KEYBOARD_NEO;
+		}
+
+		[test release];
+
+		keyboard_layout_dirty = false;
+		return layout;
+	}
+
+	return layout;
+}
 
 void OS_OSX::process_events() {
 

+ 3 - 0
platform/server/detect.py

@@ -40,6 +40,9 @@ def configure(env):
 		env["CC"]="clang"
 		env["CXX"]="clang++"
 		env["LD"]="clang++"
+		if (env["colored"]=="yes"):
+			if sys.stdout.isatty():
+				env.Append(CXXFLAGS=["-fcolor-diagnostics"])
 
 	is64=sys.maxsize > 2**32
 

+ 2 - 2
platform/windows/detect.py

@@ -113,7 +113,7 @@ def configure(env):
 		env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
 
 		env.Append(CCFLAGS=['/DGLES2_ENABLED'])
-		env.Append(CCFLAGS=['/DGLES1_ENABLED'])
+
 		env.Append(CCFLAGS=['/DGLEW_ENABLED'])
 		LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI', 'wsock32', 'shell32','advapi32']
 		env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
@@ -228,7 +228,7 @@ def configure(env):
 
 		env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows'])
 		env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED'])
-		env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLEW_ENABLED'])
+		env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLEW_ENABLED'])
 		env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','wsock32','kernel32'])
 
 		if (env["bits"]=="32" and env["mingw64_for_32"]!="yes"):

+ 10 - 3
platform/windows/os_windows.cpp

@@ -27,7 +27,7 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 #include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles1/rasterizer_gles1.h"
+
 #include "os_windows.h"
 #include "drivers/nedmalloc/memory_pool_static_nedmalloc.h"
 #include "drivers/unix/memory_pool_static_malloc.h"
@@ -56,6 +56,13 @@
 #include "shlobj.h"
 static const WORD MAX_CONSOLE_LINES = 1500;
 
+extern "C" {
+#ifdef _MSC_VER
+	_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
+#else
+	__attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001;
+#endif
+}
 
 //#define STDOUT_FILE
 
@@ -130,11 +137,11 @@ void RedirectIOToConsole() {
 
 int OS_Windows::get_video_driver_count() const {
 
-	return 2;
+	return 1;
 }
 const char * OS_Windows::get_video_driver_name(int p_driver) const {
 
-	return p_driver==0?"GLES2":"GLES1";
+	return "GLES2";
 }
 
 OS::VideoMode OS_Windows::get_default_video_mode() const {

+ 1 - 1
platform/windows/platform_config.h

@@ -31,5 +31,5 @@
 //#include <alloca.h>
 //#endif
 #define GLES2_INCLUDE_H "gl_context/glew.h"
-#define GLES1_INCLUDE_H "gl_context/glew.h"
+
 

+ 12 - 7
platform/x11/detect.py

@@ -47,6 +47,7 @@ def get_opts():
 	return [
 	('use_llvm','Use llvm compiler','no'),
 	('use_sanitizer','Use llvm compiler sanitize address','no'),
+	('pulseaudio','Detect & Use pulseaudio','yes'),
 	]
   
 def get_flags():
@@ -81,6 +82,9 @@ def configure(env):
 			env.extra_suffix=".llvms"
 		else:
 			env.extra_suffix=".llvm"
+		if (env["colored"]=="yes"):
+			if sys.stdout.isatty():
+				env.Append(CXXFLAGS=["-fcolor-diagnostics"])
 
 
 
@@ -115,14 +119,15 @@ def configure(env):
 	env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED'])
 	env.Append(CPPFLAGS=["-DALSA_ENABLED"])
 
-        if not os.system("pkg-config --exists libpulse-simple"):
-            print("Enabling PulseAudio")
-            env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
-            env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
-        else:
-            print("PulseAudio development libraries not found, disabling driver")
+	if (env["pulseaudio"]=="yes"):
+		if not os.system("pkg-config --exists libpulse-simple"):
+			print("Enabling PulseAudio")
+			env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
+			env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
+		else:
+			print("PulseAudio development libraries not found, disabling driver")
 
-	env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLES_OVER_GL'])
+	env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES_OVER_GL'])
 	env.Append(LIBS=['GL', 'GLU', 'pthread','asound','z']) #TODO detect linux/BSD!
 	#env.Append(CPPFLAGS=['-DMPC_FIXED_POINT'])
 

+ 1 - 1
platform/x11/export/export.cpp

@@ -11,7 +11,7 @@ void register_x11_exporter() {
 
 	{
 		Ref<EditorExportPlatformPC> exporter = Ref<EditorExportPlatformPC>( memnew(EditorExportPlatformPC) );
-		exporter->set_binary_extension("bin");
+		exporter->set_binary_extension("");
 		exporter->set_release_binary32("linux_x11_32_release");
 		exporter->set_debug_binary32("linux_x11_32_debug");
 		exporter->set_release_binary64("linux_x11_64_release");

+ 4 - 5
platform/x11/os_x11.cpp

@@ -28,7 +28,6 @@
 /*************************************************************************/
 #include "servers/visual/visual_server_raster.h"
 #include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles1/rasterizer_gles1.h"
 #include "os_x11.h"
 #include "key_mapping_x11.h"
 #include <stdio.h>
@@ -63,11 +62,11 @@
 
 int OS_X11::get_video_driver_count() const {
 
-	return 2;
+	return 1;
 }
 const char * OS_X11::get_video_driver_name(int p_driver) const {
 
-	return p_driver==0?"GLES2":"GLES1";
+	return "GLES2";
 }
 OS::VideoMode OS_X11::get_default_video_mode() const {
 
@@ -166,10 +165,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
 	context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) );
 	context_gl->initialize();
 
-	if (p_video_driver == 0) {
+	if (true) {
 		rasterizer = memnew( RasterizerGLES2 );
 	} else {
-		rasterizer = memnew( RasterizerGLES1 );
+		//rasterizer = memnew( RasterizerGLES1 );
 	};
 
 #endif

+ 1 - 1
platform/x11/platform_config.h

@@ -34,5 +34,5 @@
 #endif
 
 #define GLES2_INCLUDE_H "gl_context/glew.h"
-#define GLES1_INCLUDE_H "gl_context/glew.h"
+
 

+ 101 - 2
scene/2d/canvas_item.cpp

@@ -720,6 +720,95 @@ bool CanvasItem::is_draw_behind_parent_enabled() const{
 	return behind;
 }
 
+void CanvasItem::set_shader(const Ref<Shader>& p_shader) {
+
+	ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_CANVAS_ITEM);
+
+#ifdef TOOLS_ENABLED
+
+	if (shader.is_valid()) {
+		shader->disconnect("changed",this,"_shader_changed");
+	}
+#endif
+	shader=p_shader;
+
+#ifdef TOOLS_ENABLED
+
+	if (shader.is_valid()) {
+		shader->connect("changed",this,"_shader_changed");
+	}
+#endif
+
+	RID rid;
+	if (shader.is_valid())
+		rid=shader->get_rid();
+	VS::get_singleton()->canvas_item_set_shader(canvas_item,rid);
+	_change_notify(); //properties for shader exposed
+}
+
+void CanvasItem::set_use_parent_shader(bool p_use_parent_shader) {
+
+	use_parent_shader=p_use_parent_shader;
+	VS::get_singleton()->canvas_item_set_use_parent_shader(canvas_item,p_use_parent_shader);
+}
+
+bool CanvasItem::get_use_parent_shader() const{
+
+	return use_parent_shader;
+}
+
+Ref<Shader> CanvasItem::get_shader() const{
+
+	return shader;
+}
+
+void CanvasItem::set_shader_param(const StringName& p_param,const Variant& p_value) {
+
+	VS::get_singleton()->canvas_item_set_shader_param(canvas_item,p_param,p_value);
+}
+
+Variant CanvasItem::get_shader_param(const StringName& p_param) const {
+
+	return VS::get_singleton()->canvas_item_get_shader_param(canvas_item,p_param);
+}
+
+bool CanvasItem::_set(const StringName& p_name, const Variant& p_value) {
+
+	if (shader.is_valid()) {
+		StringName pr = shader->remap_param(p_name);
+		if (pr) {
+			set_shader_param(pr,p_value);
+			return true;
+		}
+	}
+	return false;
+}
+
+bool CanvasItem::_get(const StringName& p_name,Variant &r_ret) const{
+
+	if (shader.is_valid()) {
+		StringName pr = shader->remap_param(p_name);
+		if (pr) {
+			r_ret=get_shader_param(pr);
+			return true;
+		}
+	}
+	return false;
+
+}
+void CanvasItem::_get_property_list( List<PropertyInfo> *p_list) const{
+
+	if (shader.is_valid()) {
+		shader->get_param_list(p_list);
+	}
+}
+
+#ifdef TOOLS_ENABLED
+void CanvasItem::_shader_changed() {
+
+	_change_notify();
+}
+#endif
 
 void CanvasItem::_bind_methods() {
 
@@ -761,7 +850,9 @@ void CanvasItem::_bind_methods() {
 
 	ObjectTypeDB::bind_method(_MD("_set_on_top","on_top"),&CanvasItem::_set_on_top);
 	ObjectTypeDB::bind_method(_MD("_is_on_top"),&CanvasItem::_is_on_top);
-
+#ifdef TOOLS_ENABLED
+	ObjectTypeDB::bind_method(_MD("_shader_changed"),&CanvasItem::_shader_changed);
+#endif
 	//ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
 
 	ObjectTypeDB::bind_method(_MD("draw_line","from","to","color","width"),&CanvasItem::draw_line,DEFVAL(1.0));
@@ -786,15 +877,22 @@ void CanvasItem::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("get_world_2d"),&CanvasItem::get_world_2d);
 	//ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasItem::get_viewport);
 
+	ObjectTypeDB::bind_method(_MD("set_shader","shader"),&CanvasItem::set_shader);
+	ObjectTypeDB::bind_method(_MD("get_shader"),&CanvasItem::get_shader);
+	ObjectTypeDB::bind_method(_MD("set_use_parent_shader","enable"),&CanvasItem::set_use_parent_shader);
+	ObjectTypeDB::bind_method(_MD("get_use_parent_shader"),&CanvasItem::get_use_parent_shader);
+
 	BIND_VMETHOD(MethodInfo("_draw"));
 
 	ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
 	ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
 	ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
-	ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
+	ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
 	ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility
 
 	ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") );
+	ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"shader/shader",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"), _SCS("set_shader"),_SCS("get_shader") );
+	ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"shader/use_parent"), _SCS("set_use_parent_shader"),_SCS("get_use_parent_shader") );
 	//exporting these two things doesn't really make much sense i think
 	//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), _SCS("set_as_toplevel"),_SCS("is_set_as_toplevel") );
 	//ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),_SCS("set_transform_notify"),_SCS("is_transform_notify_enabled"));
@@ -871,6 +969,7 @@ CanvasItem::CanvasItem() : xform_change(this) {
 	block_transform_notify=false;
 //	viewport=NULL;
 	canvas_layer=NULL;
+	use_parent_shader=false;
 	global_invalid=true;
 
 	C=NULL;

+ 17 - 2
scene/2d/canvas_item.h

@@ -32,6 +32,7 @@
 #include "scene/main/node.h"
 #include "scene/resources/texture.h"
 #include "scene/main/scene_main_loop.h"
+#include "scene/resources/shader.h"
 
 class CanvasLayer;
 class Viewport;
@@ -80,6 +81,9 @@ private:
 	bool block_transform_notify;
 	bool behind;
 
+	bool use_parent_shader;
+	Ref<Shader> shader;
+
 	mutable Matrix32 global_transform;
 	mutable bool global_invalid;
 
@@ -99,8 +103,9 @@ private:
 	void _queue_sort_children();
 	void _sort_children();
 
-
-
+#ifdef TOOLS_ENABLED
+	void _shader_changed();
+#endif
 	void _notify_transform(CanvasItem *p_node);
 
 	void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); }
@@ -108,6 +113,9 @@ private:
 
 protected:
 
+	bool _set(const StringName& p_name, const Variant& p_value);
+	bool _get(const StringName& p_name,Variant &r_ret) const;
+	void _get_property_list( List<PropertyInfo> *p_list) const;
 
 
 	_FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); }
@@ -204,7 +212,14 @@ public:
 	RID get_canvas() const;
 	Ref<World2D> get_world_2d() const;
 
+	void set_shader(const Ref<Shader>& p_shader);
+	Ref<Shader> get_shader() const;
+
+	void set_use_parent_shader(bool p_use_parent_shader);
+	bool get_use_parent_shader() const;
 
+	void set_shader_param(const StringName& p_param,const Variant& p_value);
+	Variant get_shader_param(const StringName& p_param) const;
 
 	CanvasItem();
 	~CanvasItem();

+ 40 - 2
scene/2d/node_2d.cpp

@@ -289,6 +289,35 @@ void Node2D::set_global_transform(const Matrix32& p_transform) {
 
 }
 
+void Node2D::set_z(int p_z) {
+
+	ERR_FAIL_COND(p_z<VS::CANVAS_ITEM_Z_MIN);
+	ERR_FAIL_COND(p_z>VS::CANVAS_ITEM_Z_MAX);
+	z=p_z;
+	VS::get_singleton()->canvas_item_set_z(get_canvas_item(),z);
+
+}
+
+void Node2D::set_z_as_relative(bool p_enabled) {
+
+	if (z_relative==p_enabled)
+		return;
+	z_relative=p_enabled;
+	VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(),p_enabled);
+}
+
+bool Node2D::is_z_relative() const {
+
+	return z_relative;
+}
+
+
+int Node2D::get_z() const{
+
+	return z;
+}
+
+
 void Node2D::_bind_methods() {
 
 
@@ -308,18 +337,25 @@ void Node2D::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false));
 	ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false));
 
+	ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Node2D::set_global_pos);
 	ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos);
-	ObjectTypeDB::bind_method(_MD("set_global_pos"),&Node2D::set_global_pos);
 
 	ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform);
 	ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform);
 
+	ObjectTypeDB::bind_method(_MD("set_z","z"),&Node2D::set_z);
+	ObjectTypeDB::bind_method(_MD("get_z"),&Node2D::get_z);
+
+	ObjectTypeDB::bind_method(_MD("set_z_as_relative","enable"),&Node2D::set_z_as_relative);
+	ObjectTypeDB::bind_method(_MD("is_z_relative"),&Node2D::is_z_relative);
+
 	ObjectTypeDB::bind_method(_MD("edit_set_pivot"),&Node2D::edit_set_pivot);
 
 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/pos"),_SCS("set_pos"),_SCS("get_pos"));
 	ADD_PROPERTY(PropertyInfo(Variant::REAL,"transform/rot",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),_SCS("_set_rotd"),_SCS("_get_rotd"));
 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/scale"),_SCS("set_scale"),_SCS("get_scale"));
-
+	ADD_PROPERTY(PropertyInfo(Variant::INT,"z/z",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z"),_SCS("get_z"));
+	ADD_PROPERTY(PropertyInfo(Variant::BOOL,"z/relative"),_SCS("set_z_as_relative"),_SCS("is_z_relative"));
 
 
 }
@@ -331,6 +367,8 @@ Node2D::Node2D() {
 	angle=0;
 	scale=Vector2(1,1);
 	_xform_dirty=false;
+	z=0;
+	z_relative=true;
 
 }
 

+ 7 - 0
scene/2d/node_2d.h

@@ -38,6 +38,8 @@ class Node2D : public CanvasItem {
 	Point2 pos;
 	float angle;
 	Size2 scale;
+	int z;
+	bool z_relative;
 
 	Matrix32 _mat;
 
@@ -85,6 +87,11 @@ public:
 	void set_global_transform(const Matrix32& p_transform);
 	void set_global_pos(const Point2& p_pos);
 
+	void set_z(int p_z);
+	int get_z() const;
+
+	void set_z_as_relative(bool p_enabled);
+	bool is_z_relative() const;
 
 	Matrix32 get_transform() const;
 

+ 36 - 1
scene/2d/physics_body_2d.cpp

@@ -43,13 +43,44 @@ void PhysicsBody2D::_notification(int p_what) {
 	*/
 }
 
+void PhysicsBody2D::set_one_way_collision_direction(const Vector2& p_dir) {
+
+	one_way_collision_direction=p_dir;
+	Physics2DServer::get_singleton()->body_set_one_way_collision_direction(get_rid(),p_dir);
+}
+
+Vector2 PhysicsBody2D::get_one_way_collision_direction() const{
+
+	return one_way_collision_direction;
+}
+
+
+void PhysicsBody2D::set_one_way_collision_max_depth(float p_depth) {
+
+	one_way_collision_max_depth=p_depth;
+	Physics2DServer::get_singleton()->body_set_one_way_collision_max_depth(get_rid(),p_depth);
+
+}
+
+float PhysicsBody2D::get_one_way_collision_max_depth() const{
+
+	return one_way_collision_max_depth;
+}
+
+
 void PhysicsBody2D::_bind_methods() {
 
 	ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody2D::set_layer_mask);
 	ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask);
+	ObjectTypeDB::bind_method(_MD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction);
+	ObjectTypeDB::bind_method(_MD("get_one_way_collision_direction"),&PhysicsBody2D::get_one_way_collision_direction);
+	ObjectTypeDB::bind_method(_MD("set_one_way_collision_max_depth","depth"),&PhysicsBody2D::set_one_way_collision_max_depth);
+	ObjectTypeDB::bind_method(_MD("get_one_way_collision_max_depth"),&PhysicsBody2D::get_one_way_collision_max_depth);
 	ObjectTypeDB::bind_method(_MD("add_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::add_collision_exception_with);
 	ObjectTypeDB::bind_method(_MD("remove_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::remove_collision_exception_with);
 	ADD_PROPERTY(PropertyInfo(Variant::INT,"layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
+	ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"one_way_collision/direction"),_SCS("set_one_way_collision_direction"),_SCS("get_one_way_collision_direction"));
+	ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"one_way_collision/max_depth"),_SCS("set_one_way_collision_max_depth"),_SCS("get_one_way_collision_max_depth"));
 }
 
 void PhysicsBody2D::set_layer_mask(uint32_t p_mask) {
@@ -66,6 +97,7 @@ uint32_t PhysicsBody2D::get_layer_mask() const {
 PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) {
 
 	mask=1;
+	set_one_way_collision_max_depth(0);
 
 }
 
@@ -932,7 +964,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
 
 			//if (d<margin)
 			///	continue;
-			recover_motion+=(b-a)*0.2;
+			recover_motion+=(b-a)*0.4;
 		}
 
 		if (recover_motion==Vector2()) {
@@ -963,6 +995,7 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
 		bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0,lsafe,lunsafe,exclude,get_layer_mask(),mask);
 		//print_line("shape: "+itos(i)+" travel:"+rtos(ltravel));
 		if (!valid) {
+
 			safe=0;
 			unsafe=0;
 			best_shape=i; //sadly it's the best
@@ -994,9 +1027,11 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
 		bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), Vector2(), margin,&rest_info,exclude,get_layer_mask(),mask);
 		if (!c2) {
 			//should not happen, but floating point precision is so weird..
+
 			colliding=false;
 		} else {
 
+
 			//print_line("Travel: "+rtos(travel));
 			colliding=true;
 			collision=rest_info.point;

+ 8 - 0
scene/2d/physics_body_2d.h

@@ -39,6 +39,8 @@ class PhysicsBody2D : public CollisionObject2D {
 	OBJ_TYPE(PhysicsBody2D,CollisionObject2D);
 
 	uint32_t mask;
+	Vector2 one_way_collision_direction;
+	float one_way_collision_max_depth;
 protected:
 
 	void _notification(int p_what);
@@ -53,6 +55,12 @@ public:
 	void add_collision_exception_with(Node* p_node); //must be physicsbody
 	void remove_collision_exception_with(Node* p_node);
 
+	void set_one_way_collision_direction(const Vector2& p_dir);
+	Vector2 get_one_way_collision_direction() const;
+
+	void set_one_way_collision_max_depth(float p_dir);
+	float get_one_way_collision_max_depth() const;
+
 	PhysicsBody2D();
 
 };

+ 1 - 0
scene/3d/physics_body.cpp

@@ -92,6 +92,7 @@ void PhysicsBody::remove_collision_exception_with(Node* p_node) {
 	PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(),physics_body->get_rid());
 }
 
+
 void PhysicsBody::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody::set_layer_mask);
 	ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody::get_layer_mask);

+ 2 - 0
scene/3d/physics_body.h

@@ -56,6 +56,8 @@ public:
 	void add_collision_exception_with(Node* p_node); //must be physicsbody
 	void remove_collision_exception_with(Node* p_node);
 
+
+
 	PhysicsBody();
 
 };

+ 103 - 8
scene/animation/tween.cpp

@@ -138,7 +138,8 @@ void Tween::_bind_methods() {
 
 	ObjectTypeDB::bind_method(_MD("interpolate_property","object","property","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_property, DEFVAL(0) );
 	ObjectTypeDB::bind_method(_MD("interpolate_method","object","method","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_method, DEFVAL(0) );
-	ObjectTypeDB::bind_method(_MD("interpolate_callback","object","times_in_sec","callback","args"),&Tween::interpolate_callback, DEFVAL(Variant()) );
+	ObjectTypeDB::bind_method(_MD("interpolate_callback","object","times_in_sec","callback","arg1", "arg2","arg3","arg4","arg5"),&Tween::interpolate_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()) );
+	ObjectTypeDB::bind_method(_MD("interpolate_deferred_callback","object","times_in_sec","callback","arg1","arg2","arg3","arg4","arg5"),&Tween::interpolate_deferred_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()) );
 	ObjectTypeDB::bind_method(_MD("follow_property","object","property","initial_val","target","target_property","times_in_sec","trans_type","ease_type","delay"),&Tween::follow_property, DEFVAL(0) );
 	ObjectTypeDB::bind_method(_MD("follow_method","object","method","initial_val","target","target_method","times_in_sec","trans_type","ease_type","delay"),&Tween::follow_method, DEFVAL(0) );
 	ObjectTypeDB::bind_method(_MD("targeting_property","object","property","initial","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::targeting_property, DEFVAL(0) );
@@ -513,11 +514,33 @@ void Tween::_tween_process(float p_delta) {
 			if(data.finish) {
 
 				Variant::CallError error;
-				if (data.arg.get_type() != Variant::NIL) {
-					Variant *arg[1] = { &data.arg };
-					object->call(data.key, (const Variant **) arg, 1, error);
-				} else {
-					object->call(data.key, NULL, 0, error);
+				if (data.call_deferred) {
+
+					switch (data.args) {
+					case 0:
+						object->call_deferred(data.key); break;
+					case 1:
+						object->call_deferred(data.key, data.arg[0]); break;
+					case 2:
+						object->call_deferred(data.key, data.arg[0], data.arg[1]); break;
+					case 3:
+						object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2]); break;
+					case 4:
+						object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3]); break;
+					case 5:
+						object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); break;
+					}
+
+				}
+				else {
+					Variant *arg[5] = {
+						&data.arg[0],
+						&data.arg[1],
+						&data.arg[2],
+						&data.arg[3],
+						&data.arg[4],
+					};
+					object->call(data.key, (const Variant **) arg, data.args, error);
 				}
 			}
 			continue;
@@ -1003,7 +1026,58 @@ bool Tween::interpolate_method(Object *p_object
 bool Tween::interpolate_callback(Object *p_object
 	, real_t p_times_in_sec
 	, String p_callback
-	, Variant p_arg
+	, VARIANT_ARG_DECLARE
+) {
+
+	ERR_FAIL_COND_V(pending_update != 0, false);
+	ERR_FAIL_COND_V(p_object == NULL, false);
+	ERR_FAIL_COND_V(p_times_in_sec < 0, false);
+
+	ERR_FAIL_COND_V(!p_object->has_method(p_callback), false);
+
+	InterpolateData data;
+	data.active = true;
+	data.type = INTER_CALLBACK;
+	data.finish = false;
+	data.call_deferred = false;
+	data.elapsed = 0;
+
+	data.id = p_object->get_instance_ID();
+	data.key = p_callback;
+	data.times_in_sec = p_times_in_sec;
+	data.delay = 0;
+
+	int args=0;
+	if (p_arg5.get_type()!=Variant::NIL)
+		args=5;
+	else if (p_arg4.get_type()!=Variant::NIL)
+		args=4;
+	else if (p_arg3.get_type()!=Variant::NIL)
+		args=3;
+	else if (p_arg2.get_type()!=Variant::NIL)
+		args=2;
+	else if (p_arg1.get_type()!=Variant::NIL)
+		args=1;
+	else 
+		args=0;
+
+	data.args = args;
+	data.arg[0] = p_arg1;
+	data.arg[1] = p_arg2;
+	data.arg[2] = p_arg3;
+	data.arg[3] = p_arg4;
+	data.arg[4] = p_arg5;
+
+	pending_update ++;
+	interpolates.push_back(data);
+	pending_update --;
+	return true;
+}
+
+bool Tween::interpolate_deferred_callback(Object *p_object
+	, real_t p_times_in_sec
+	, String p_callback
+	, VARIANT_ARG_DECLARE
 ) {
 
 	ERR_FAIL_COND_V(pending_update != 0, false);
@@ -1016,13 +1090,34 @@ bool Tween::interpolate_callback(Object *p_object
 	data.active = true;
 	data.type = INTER_CALLBACK;
 	data.finish = false;
+	data.call_deferred = true;
 	data.elapsed = 0;
 
 	data.id = p_object->get_instance_ID();
 	data.key = p_callback;
 	data.times_in_sec = p_times_in_sec;
 	data.delay = 0;
-	data.arg = p_arg;
+
+	int args=0;
+	if (p_arg5.get_type()!=Variant::NIL)
+		args=5;
+	else if (p_arg4.get_type()!=Variant::NIL)
+		args=4;
+	else if (p_arg3.get_type()!=Variant::NIL)
+		args=3;
+	else if (p_arg2.get_type()!=Variant::NIL)
+		args=2;
+	else if (p_arg1.get_type()!=Variant::NIL)
+		args=1;
+	else 
+		args=0;
+
+	data.args = args;
+	data.arg[0] = p_arg1;
+	data.arg[1] = p_arg2;
+	data.arg[2] = p_arg3;
+	data.arg[3] = p_arg4;
+	data.arg[4] = p_arg5;
 
 	pending_update ++;
 	interpolates.push_back(data);

+ 11 - 3
scene/animation/tween.h

@@ -83,6 +83,7 @@ private:
 		bool active;
 		InterpolateType type;
 		bool finish;
+		bool call_deferred;
 		real_t elapsed;
 		ObjectID id;
 		StringName key;
@@ -95,7 +96,8 @@ private:
 		TransitionType trans_type;
 		EaseType ease_type;
 		real_t delay;
-		Variant arg;
+		int args;
+		Variant arg[5];
 	};
 
 	String autoplay;
@@ -178,10 +180,16 @@ public:
 		, real_t p_delay = 0
 	);
 
-	bool interpolate_callback(Object *p_node
+	bool interpolate_callback(Object *p_object
 		, real_t p_times_in_sec
 		, String p_callback
-		, Variant p_arg = Variant()
+		, VARIANT_ARG_DECLARE
+	);
+	
+	bool interpolate_deferred_callback(Object *p_object
+		, real_t p_times_in_sec
+		, String p_callback
+		, VARIANT_ARG_DECLARE
 	);
 
 	bool follow_property(Object *p_node

+ 9 - 2
scene/gui/file_dialog.cpp

@@ -156,7 +156,6 @@ void FileDialog::_action_pressed() {
 
 	if (mode==MODE_SAVE_FILE) {
 		
-		String ext = f.extension();
 		bool valid=false;
 
 		if (filter->get_selected()==filter->get_item_count()-1) {
@@ -184,7 +183,8 @@ void FileDialog::_action_pressed() {
 			if (idx>=0 && idx<filters.size()) {
 
 				String flt=filters[idx].get_slice(";",0);
-				for (int j=0;j<flt.get_slice_count(",");j++) {
+				int filterSliceCount=flt.get_slice_count(",");
+				for (int j=0;j<filterSliceCount;j++) {
 
 					String str = (flt.get_slice(",",j).strip_edges());
 					if (f.match(str)) {
@@ -192,6 +192,13 @@ void FileDialog::_action_pressed() {
 						break;
 					}
 				}
+
+				if (!valid && filterSliceCount>0) {
+					String str = (flt.get_slice(",",0).strip_edges());
+					f+=str.substr(1, str.length()-1);
+					file->set_text(f.get_file());
+					valid=true;
+				}
 			} else {
 				valid=true;
 			}

+ 73 - 4
scene/gui/graph_edit.cpp

@@ -1,5 +1,6 @@
 #include "graph_edit.h"
-
+#include "os/input.h"
+#include "os/keyboard.h"
 bool GraphEditFilter::has_point(const Point2& p_point) const {
 
 	return ge->_filter_input(p_point);
@@ -53,7 +54,7 @@ void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const
 	}
 }
 
-void GraphEdit::get_connection_list(List<Connection> *r_connections) {
+void GraphEdit::get_connection_list(List<Connection> *r_connections) const {
 
 	*r_connections=connections;
 }
@@ -88,7 +89,6 @@ void GraphEdit::_update_scroll() {
 
 	updating=true;
 	Rect2 screen;
-	screen.size=get_size();
 	for(int i=0;i<get_child_count();i++) {
 
 		GraphNode *gn=get_child(i)->cast_to<GraphNode>();
@@ -101,6 +101,10 @@ void GraphEdit::_update_scroll() {
 		screen = screen.merge(r);
 	}
 
+	screen.pos-=get_size();
+	screen.size+=get_size()*2.0;
+
+
 	h_scroll->set_min(screen.pos.x);
 	h_scroll->set_max(screen.pos.x+screen.size.x);
 	h_scroll->set_page(get_size().x);
@@ -265,6 +269,37 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
 				Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
 
 				if (pos.distance_to(mpos)<grab_r) {
+
+					if (right_disconnects) {
+						//check disconnect
+						for (List<Connection>::Element*E=connections.front();E;E=E->next()) {
+
+							if (E->get().to==gn->get_name() && E->get().to_port==j) {
+
+								Node*fr = get_node(String(E->get().from));
+								if (fr && fr->cast_to<GraphNode>()) {
+
+									connecting_from=E->get().from;
+									connecting_index=E->get().from_port;
+									connecting_out=true;
+									connecting_type=fr->cast_to<GraphNode>()->get_connection_output_type(E->get().from_port);
+									connecting_color=fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port);
+									connecting_target=false;
+									connecting_to=pos;
+
+									emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
+									fr = get_node(String(connecting_from)); //maybe it was erased
+									if (fr && fr->cast_to<GraphNode>()) {
+										connecting=true;
+									}
+									return;
+								}
+
+							}
+						}
+					}
+
+
 					connecting=true;
 					connecting_from=gn->get_name();
 					connecting_index=j;
@@ -461,7 +496,7 @@ void GraphEdit::_top_layer_draw() {
 
 void GraphEdit::_input_event(const InputEvent& p_ev) {
 
-	if (p_ev.type==InputEvent::MOUSE_MOTION && p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE) {
+	if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
 		h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x );
 		v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y );
 	}
@@ -474,11 +509,41 @@ void GraphEdit::clear_connections() {
 }
 
 
+void GraphEdit::set_right_disconnects(bool p_enable) {
+
+	right_disconnects=p_enable;
+}
+
+bool GraphEdit::is_right_disconnects_enabled() const{
+
+	return right_disconnects;
+}
+
+Array GraphEdit::_get_connection_list() const {
+
+	List<Connection> conns;
+	get_connection_list(&conns);
+	Array arr;
+	for(List<Connection>::Element *E=conns.front();E;E=E->next()) {
+		Dictionary d;
+		d["from"]=E->get().from;
+		d["from_port"]=E->get().from_port;
+		d["to"]=E->get().to;
+		d["to_port"]=E->get().to_port;
+		arr.push_back(d);
+	}
+	return arr;
+}
 void GraphEdit::_bind_methods() {
 
 	ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node);
 	ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected);
 	ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node);
+	ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list);
+
+	ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects);
+	ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled);
+
 	ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved);
 	ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised);
 
@@ -489,9 +554,12 @@ void GraphEdit::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event);
 
 	ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
+	ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
 
 }
 
+
+
 GraphEdit::GraphEdit() {
 	top_layer=NULL;
 	top_layer=memnew(GraphEditFilter(this));
@@ -511,6 +579,7 @@ GraphEdit::GraphEdit() {
 	top_layer->add_child(v_scroll);
 	updating=false;
 	connecting=false;
+	right_disconnects=false;
 
 	h_scroll->connect("value_changed", this,"_scroll_moved");
 	v_scroll->connect("value_changed", this,"_scroll_moved");

+ 8 - 1
scene/gui/graph_edit.h

@@ -51,6 +51,7 @@ private:
 
 
 
+	bool right_disconnects;
 	bool updating;
 	List<Connection> connections;
 
@@ -68,6 +69,8 @@ private:
 	void _top_layer_draw();
 	void _update_scroll_offset();
 
+	Array _get_connection_list() const;
+
 friend class GraphEditFilter;
 	bool _filter_input(const Point2& p_point);
 protected:
@@ -84,7 +87,11 @@ public:
 	void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
 	void clear_connections();
 
-	void get_connection_list(List<Connection> *r_connections);
+	GraphEditFilter *get_top_layer() const { return top_layer; }
+	void get_connection_list(List<Connection> *r_connections) const;
+
+	void set_right_disconnects(bool p_enable);
+	bool is_right_disconnects_enabled() const;
 
 
 	GraphEdit();

+ 27 - 4
scene/gui/graph_node.cpp

@@ -1,4 +1,5 @@
 #include "graph_node.h"
+#include "method_bind_ext.inc"
 
 
 bool GraphNode::_set(const StringName& p_name, const Variant& p_value) {
@@ -38,9 +39,8 @@ bool GraphNode::_set(const StringName& p_name, const Variant& p_value) {
 bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{
 
 
-	print_line("get "+p_name.operator String());
-	if (!p_name.operator String().begins_with("slot/")) {
-		print_line("no begins");
+
+	if (!p_name.operator String().begins_with("slot/")) {		
 		return false;
 	}
 
@@ -68,7 +68,6 @@ bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{
 	else
 		return false;
 
-	print_line("ask for: "+p_name.operator String()+" get: "+String(r_ret));
 	return true;
 }
 void GraphNode::_get_property_list( List<PropertyInfo> *p_list) const{
@@ -540,6 +539,30 @@ void GraphNode::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title);
 	ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event);
 
+	ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot);
+	ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot);
+	ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots);
+	ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left);
+	ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left);
+	ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left);
+	ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right);
+	ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right);
+	ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right);
+
+	ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset);
+	ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset);
+
+	ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count);
+	ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count);
+
+	ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos);
+	ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type);
+	ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color);
+	ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos);
+	ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type);
+	ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color);
+
+
 	ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button);
 	ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible);
 

+ 1 - 0
scene/gui/grid_container.cpp

@@ -226,5 +226,6 @@ Size2 GridContainer::get_minimum_size() const {
 
 GridContainer::GridContainer() {
 
+	set_stop_mouse(false);
 	columns=1;
 }

+ 1 - 1
scene/gui/text_edit.cpp

@@ -298,7 +298,7 @@ void TextEdit::_update_scrollbars() {
 	
 	int hscroll_rows = ((hmin.height-1)/get_row_height())+1;
 	int visible_rows = get_visible_rows();
-	int total_rows = text.size() * cache.line_spacing;
+	int total_rows = text.size();
 	
 	int vscroll_pixels = v_scroll->get_combined_minimum_size().width;
 	int visible_width = size.width - cache.style_normal->get_minimum_size().width;

+ 4 - 0
scene/gui/tree.cpp

@@ -2472,6 +2472,10 @@ void Tree::_notification(int p_what) {
 		}
 	}
 
+	if (p_what==NOTIFICATION_THEME_CHANGED) {
+		update_cache();
+	}
+
 }
 
 

+ 6 - 5
scene/register_scene_types.cpp

@@ -272,7 +272,7 @@ void register_scene_types() {
 
 	ObjectTypeDB::register_type<Control>();
 //	ObjectTypeDB::register_type<EmptyControl>();
-	ObjectTypeDB::add_compatibility_type("EmptyControl","control");
+	ObjectTypeDB::add_compatibility_type("EmptyControl","Control");
 	ObjectTypeDB::register_type<Button>();
 	ObjectTypeDB::register_type<Label>();
 	ObjectTypeDB::register_type<HScrollBar>();
@@ -496,16 +496,17 @@ void register_scene_types() {
 
 	/* REGISTER RESOURCES */
 
+	ObjectTypeDB::register_virtual_type<Shader>();
+	ObjectTypeDB::register_virtual_type<ShaderGraph>();
+	ObjectTypeDB::register_type<CanvasItemShader>();
+	ObjectTypeDB::register_type<CanvasItemShaderGraph>();
+
 #ifndef _3D_DISABLED
 	ObjectTypeDB::register_type<Mesh>();
 	ObjectTypeDB::register_virtual_type<Material>();
 	ObjectTypeDB::register_type<FixedMaterial>();
-	//ObjectTypeDB::register_type<ParticleSystemMaterial>();
-	//ObjectTypeDB::register_type<UnshadedMaterial>();
 	ObjectTypeDB::register_type<ShaderMaterial>();
 	ObjectTypeDB::register_type<RoomBounds>();
-	ObjectTypeDB::register_virtual_type<Shader>();
-	ObjectTypeDB::register_virtual_type<ShaderGraph>();
 	ObjectTypeDB::register_type<MaterialShaderGraph>();
 	ObjectTypeDB::register_type<MaterialShader>();
 	ObjectTypeDB::add_compatibility_type("Shader","MaterialShader");

+ 2 - 16
scene/resources/curve.cpp

@@ -541,19 +541,12 @@ void Curve2D::_bake() const {
 
 
 	Vector2 pos=points[0].pos;
-	int point=0;
-	float ofs=0;
 	List<Vector2> pointlist;
 
 
 	for(int i=0;i<points.size()-1;i++) {
 
-		float slen=points[i].pos.distance_to(points[i+1].pos);
-		float divs = slen / bake_interval;
-		if (divs>1)
-			divs=1;
-
-		float step = divs*0.1; // 10 substeps ought to be enough?
+		float step = 0.1; // at least 10 substeps ought to be enough?
 		float p = 0;
 
 		while(p<1.0) {
@@ -1014,19 +1007,12 @@ void Curve3D::_bake() const {
 
 
 	Vector3 pos=points[0].pos;
-	int point=0;
-	float ofs=0;
 	List<Plane> pointlist;
 	pointlist.push_back(Plane(pos,points[0].tilt));
 
 	for(int i=0;i<points.size()-1;i++) {
 
-		float slen=points[i].pos.distance_to(points[i+1].pos);
-		float divs = slen / bake_interval;
-		if (divs>1)
-			divs=1;
-
-		float step = divs*0.1; // 10 substeps ought to be enough?
+		float step = 0.1; // at least 10 substeps ought to be enough?
 		float p = 0;
 
 		while(p<1.0) {

BIN
scene/resources/default_theme/arrow_down.png


BIN
scene/resources/default_theme/arrow_right.png


BIN
scene/resources/default_theme/button_disabled.png


BIN
scene/resources/default_theme/button_hover.png


BIN
scene/resources/default_theme/button_normal.png


BIN
scene/resources/default_theme/button_pressed.png


BIN
scene/resources/default_theme/checked.png


BIN
scene/resources/default_theme/close_hl.png


+ 355 - 179
scene/resources/default_theme/default_theme.cpp

@@ -168,8 +168,6 @@ void make_default_theme() {
 
 	tex_cache = memnew( TexCacheMap );
 
-	uint32_t last=OS::get_singleton()->get_ticks_msec();
-
 	Ref<Theme> t( memnew( Theme ) );
 
 	//Ref<Font> default_font = make_font(_bi_font_normal_height,_bi_font_normal_ascent,_bi_font_normal_valign,_bi_font_normal_charcount,_bi_font_normal_characters,make_icon(font_normal_png));
@@ -177,167 +175,240 @@ void make_default_theme() {
 	Ref<Font> source_font=make_font2(_builtin_source_font_height,_builtin_source_font_ascent,_builtin_source_font_charcount,&_builtin_source_font_charrects[0][0],_builtin_source_font_kerning_pair_count,&_builtin_source_font_kerning_pairs[0][0],_builtin_source_font_img_width,_builtin_source_font_img_height,_builtin_source_font_img_data);
 	Ref<Font> large_font=make_font2(_builtin_large_font_height,_builtin_large_font_ascent,_builtin_large_font_charcount,&_builtin_large_font_charrects[0][0],_builtin_large_font_kerning_pair_count,&_builtin_large_font_kerning_pairs[0][0],_builtin_large_font_img_width,_builtin_large_font_img_height,_builtin_large_font_img_data);
 
+	// Font Colors
+
+	Color control_font_color = Color::html("e0e0e0");
+	Color control_font_color_low = Color::html("b0b0b0");
+	Color control_font_color_hover = Color::html("f0f0f0");
+	Color control_font_color_disabled = Color(0.9,0.9,0.9,0.2);
+	Color control_font_color_pressed = Color::html("ffffff");
+	Color font_color_selection = Color::html("7d7d7d");
+
+
+	// Panel
+
 	t->set_stylebox("panel","Panel", make_stylebox( panel_bg_png,0,0,0,0) );
 
-	Color control_font_color = Color::html("cfc9d5");
-	Color control_font_color_low = Color::html("bab4c1");
-	Color control_font_color_hover = Color::html("ffffff");
-	Color control_font_color_disabled = Color(0.9,0.9,0.9,0.6);
-	Color control_font_color_pressed = Color::html("bfb9c5");
-	Color font_color_selection = Color::html("715e7d");
-	Ref<Texture> empty_icon = memnew( ImageTexture );
 
-	t->set_stylebox("normal","Button", make_stylebox( button_normal_png,5,5,5,5,8,3,8,4) );
-	t->set_stylebox("pressed","Button", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("hover","Button", make_stylebox( button_hover_png,5,5,5,5,3,0,3,0) );
-	t->set_stylebox("disabled","Button", make_stylebox( button_disabled_png,5,5,5,5,3,3,3,3) );
-	Ref<StyleBoxTexture> focus = make_stylebox( focus_png,6,6,6,6,3,3,3,3);
+
+	// Focus
+
+	Ref<StyleBoxTexture> focus = make_stylebox( focus_png,5,5,5,5);
 	for(int i=0;i<4;i++) {
 		focus->set_expand_margin_size(Margin(i),2);
 	}
+
+
+
+	// Button
+
+	t->set_stylebox("normal","Button", make_stylebox( button_normal_png,4,4,4,4,8,4,8,4) );
+	t->set_stylebox("pressed","Button", make_stylebox( button_pressed_png,4,4,4,4) );
+	t->set_stylebox("hover","Button", make_stylebox( button_hover_png,4,4,4,4) );
+	t->set_stylebox("disabled","Button", make_stylebox( button_disabled_png,4,4,4,4) );
 	t->set_stylebox("focus","Button", focus );
+
 	t->set_font("font","Button", default_font );
+
 	t->set_color("font_color","Button", control_font_color );
 	t->set_color("font_color_pressed","Button", control_font_color_pressed );
 	t->set_color("font_color_hover","Button", control_font_color_hover );
 	t->set_color("font_color_disabled","Button", control_font_color_disabled );
-	t->set_constant("hseparation","Button", 2 );
 
+	t->set_constant("hseparation","Button", 2);
+
+
+
+	// ColorPickerButton
+
+	t->set_stylebox("normal","ColorPickerButton", make_stylebox( button_normal_png,4,4,4,4) );
+	t->set_stylebox("pressed","ColorPickerButton", make_stylebox( button_pressed_png,4,4,4,4) );
+	t->set_stylebox("hover","ColorPickerButton", make_stylebox( button_hover_png,4,4,4,4) );
+	t->set_stylebox("disabled","ColorPickerButton", make_stylebox( button_disabled_png,4,4,4,4) );
+	t->set_stylebox("focus","ColorPickerButton", focus );
 
-	t->set_stylebox("normal","ColorPickerButton", make_stylebox( button_normal_png,7,7,7,7,8,3,8,3) );
-	t->set_stylebox("pressed","ColorPickerButton", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("hover","ColorPickerButton", make_stylebox( button_hover_png,4,4,4,4,3,3,3,3) );
-	t->set_stylebox("disabled","ColorPickerButton", make_stylebox( button_disabled_png,4,4,4,4,3,3,3,3) );
-	t->set_stylebox("focus","ColorPickerButton", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
 	t->set_font("font","ColorPickerButton", default_font );
+
 	t->set_color("font_color","ColorPickerButton", Color(1,1,1,1) );
 	t->set_color("font_color_pressed","ColorPickerButton", Color(0.8,0.8,0.8,1) );
 	t->set_color("font_color_hover","ColorPickerButton", Color(1,1,1,1) );
-	t->set_color("font_color_disabled","ColorPickerButton", Color(0.9,0.9,0.9,0.6) );
+	t->set_color("font_color_disabled","ColorPickerButton", Color(0.9,0.9,0.9,0.3) );
+
 	t->set_constant("hseparation","ColorPickerButton", 2 );
 
-	t->set_stylebox("normal","ToolButton", make_empty_stylebox(5,3,5,3) );
-	t->set_stylebox("pressed","ToolButton", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
 
-	t->set_stylebox("hover","ToolButton", make_stylebox( button_normal_png,5,5,5,5,3,3,3,3) );
-	//t->set_stylebox("disabled","ToolButton", make_stylebox( button_disabled_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("disabled","ToolButton", make_empty_stylebox(3,3,3,3) );
-	t->set_stylebox("focus","ToolButton", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
+	// ToolButton
+
+	Ref<StyleBox> tb_empty = memnew( StyleBoxEmpty );
+	tb_empty->set_default_margin(MARGIN_LEFT,8);
+	tb_empty->set_default_margin(MARGIN_RIGHT,8);
+	tb_empty->set_default_margin(MARGIN_TOP,4);
+	tb_empty->set_default_margin(MARGIN_BOTTOM,4);
+
+	t->set_stylebox("normal","ToolButton", tb_empty);
+	t->set_stylebox("pressed","ToolButton", make_stylebox( button_pressed_png,4,4,4,4) );
+	t->set_stylebox("hover","ToolButton", make_stylebox( button_normal_png,4,4,4,4) );
+	t->set_stylebox("disabled","ToolButton", make_empty_stylebox(4,4,4,4) );
+	t->set_stylebox("focus","ToolButton", focus );
+
 	t->set_font("font","ToolButton", default_font );
+
 	t->set_color("font_color","ToolButton", control_font_color );
 	t->set_color("font_color_pressed","ToolButton", control_font_color_pressed );
 	t->set_color("font_color_hover","ToolButton", control_font_color_hover );
-	t->set_color("font_color_disabled","ToolButton", Color(0.9,0.95,1,0.6) );
-	t->set_constant("hseparation","ToolButton", 2 );
+	t->set_color("font_color_disabled","ToolButton", Color(0.9,0.95,1,0.3) );
+
+	t->set_constant("hseparation","ToolButton", 0 );
+
+
+
+	// OptionButton
 
-	t->set_stylebox("normal","OptionButton", make_stylebox( option_button_normal_png,4,4,20,5,8,3,20,4) );
-	t->set_stylebox("pressed","OptionButton", make_stylebox( option_button_pressed_png,4,4,20,5,3,3,3,3) );
-	t->set_stylebox("hover","OptionButton", make_stylebox( option_button_hover_png,4,4,20,5,3,3,3,3) );
-	t->set_stylebox("disabled","OptionButton", make_stylebox( option_button_disabled_png,4,4,20,5,3,3,3,3) );
+	t->set_stylebox("normal","OptionButton", make_stylebox( option_button_normal_png,5,5,21,5,8,4,8,4) );
+	t->set_stylebox("pressed","OptionButton", make_stylebox( option_button_pressed_png,5,5,21,5) );
+	t->set_stylebox("hover","OptionButton", make_stylebox( option_button_hover_png,5,5,21,5) );
+	t->set_stylebox("disabled","OptionButton", make_stylebox( option_button_disabled_png,5,5,21,5) );
 	t->set_stylebox("focus","OptionButton", focus );
-	t->set_constant("arrow_margin","OptionButton", 1 );
+
 	t->set_icon("arrow","OptionButton", make_icon( option_arrow_png ) );
 
 	t->set_font("font","OptionButton", default_font );
+
 	t->set_color("font_color","OptionButton", control_font_color );
 	t->set_color("font_color_pressed","OptionButton", control_font_color_pressed );
 	t->set_color("font_color_hover","OptionButton", control_font_color_hover );
 	t->set_color("font_color_disabled","OptionButton", control_font_color_disabled );
 
 	t->set_constant("hseparation","OptionButton", 2 );
+	t->set_constant("arrow_margin","OptionButton", 2 );
+
+
 
-	t->set_stylebox("normal","MenuButton", make_stylebox( button_normal_png,6,6,6,6,3,3,3,3) );
-	t->set_stylebox("pressed","MenuButton", make_stylebox( tool_button_pressed_png ,6,6,6,6,3,3,3,3) );
-	t->set_stylebox("hover","MenuButton", make_stylebox( button_normal_png,6,6,6,6,3,3,3,3) );
+	// MenuButton
+
+	t->set_stylebox("normal","MenuButton", make_stylebox( button_normal_png,4,4,4,4,8,4,8,4) );
+	t->set_stylebox("pressed","MenuButton", make_stylebox( tool_button_pressed_png ,4,4,4,4) );
+	t->set_stylebox("hover","MenuButton", make_stylebox( button_normal_png,4,4,4,4) );
 	t->set_stylebox("disabled","MenuButton", make_empty_stylebox(0,0,0,0) );
+
 	t->set_font("font","MenuButton", default_font );
+
 	t->set_color("font_color","MenuButton", control_font_color );
 	t->set_color("font_color_pressed","MenuButton", control_font_color_pressed );
 	t->set_color("font_color_hover","MenuButton", control_font_color_hover );
 	t->set_color("font_color_disabled","MenuButton", Color(1,1,1,0.3) );
-	t->set_stylebox("focus","OptionButton", Ref<StyleBox>( memnew( StyleBoxEmpty )) );
 
-	t->set_constant("hseparation","MenuButton", 2 );
+	t->set_constant("hseparation","MenuButton", 0 );
+
+
+
+	// CheckButton
 	
 	Ref<StyleBox> cb_empty = memnew( StyleBoxEmpty );
+	cb_empty->set_default_margin(MARGIN_LEFT,6);
 	cb_empty->set_default_margin(MARGIN_RIGHT,70);
 	cb_empty->set_default_margin(MARGIN_TOP,4);
 	cb_empty->set_default_margin(MARGIN_BOTTOM,4);
+
 	t->set_stylebox("normal","CheckButton", cb_empty );
 	t->set_stylebox("pressed","CheckButton", cb_empty );
 	t->set_stylebox("disabled","CheckButton", cb_empty );
 	t->set_stylebox("hover","CheckButton", cb_empty );
-	//t->set_stylebox("hover","CheckButton", make_stylebox( button_hover_png,5,5,5,5,3,3,3,3) );
+	t->set_stylebox("focus","CheckButton", focus );
+
+	t->set_icon("on","CheckButton", make_icon(toggle_on_png) );
+	t->set_icon("off","CheckButton", make_icon(toggle_off_png));
+
 	t->set_font("font","CheckButton", default_font );
+
 	t->set_color("font_color","CheckButton", control_font_color );
 	t->set_color("font_color_pressed","CheckButton", control_font_color_pressed );
 	t->set_color("font_color_hover","CheckButton", control_font_color_hover );
 	t->set_color("font_color_disabled","CheckButton", control_font_color_disabled );
-	t->set_icon("on","CheckButton", make_icon(toggle_on_png) );
-	t->set_icon("off","CheckButton", make_icon(toggle_off_png));
-	t->set_stylebox("focus","CheckButton", focus );
+
 	t->set_constant("hseparation","CheckButton",4);
 	t->set_constant("check_vadjust","CheckButton",0);
 
+
+
+	// Label
 	            
 	t->set_font("font","Label", default_font );
+
 	t->set_color("font_color","Label", Color(1,1,1) );
 	t->set_color("font_color_shadow","Label", Color(0,0,0,0) );
+
 	t->set_constant("shadow_offset_x","Label", 1 );
 	t->set_constant("shadow_offset_y","Label", 1 );
 	t->set_constant("shadow_as_outline","Label", 0 );
 
-	t->set_stylebox("normal","LineEdit", make_stylebox( line_edit_png,4,4,4,4,3,4,3,4) );
-	t->set_stylebox("focus","LineEdit", focus );
-	t->set_stylebox("read_only","LineEdit", make_stylebox( line_edit_disabled_png,6,6,6,6,4,4,4,4) );
-	Image n(line_edit_png);
-	Image nf(line_edit_focus_png);
 
 
+	// LineEdit
+
+	t->set_stylebox("normal","LineEdit", make_stylebox( line_edit_png,5,5,5,5) );
+	t->set_stylebox("focus","LineEdit", focus );
+	t->set_stylebox("read_only","LineEdit", make_stylebox( line_edit_disabled_png,6,6,6,6) );
 
 	t->set_font("font","LineEdit", default_font );
+
 	t->set_color("font_color","LineEdit", control_font_color );
 	t->set_color("font_color_selected","LineEdit", Color(0,0,0) );
 	t->set_color("cursor_color","LineEdit", control_font_color_hover );
 	t->set_color("selection_color","LineEdit", font_color_selection );
-	t->set_constant("minimum_spaces","LineEdit", 8 );
 
-	t->set_stylebox("bg","ProgressBar", make_stylebox( progress_bar_png,5,5,5,5,0,0,0,0) );
-	t->set_stylebox("fg","ProgressBar", make_stylebox( progress_fill_png,5,5,5,5,2,2,2,2) );
+	t->set_constant("minimum_spaces","LineEdit", 12 );
+
+
+
+	// ProgressBar
+
+	t->set_stylebox("bg","ProgressBar", make_stylebox( progress_bar_png,4,4,4,4,0,0,0,0) );
+	t->set_stylebox("fg","ProgressBar", make_stylebox( progress_fill_png,6,6,6,6,2,1,2,1) );
+
 	t->set_font("font","ProgressBar", default_font );
-	t->set_color("font_color","ProgressBar", control_font_color );
+
+	t->set_color("font_color","ProgressBar", control_font_color_hover );
 	t->set_color("font_color_shadow","ProgressBar", Color(0,0,0) );
 
-	t->set_icon("tab","TextEdit", make_icon( tab_png) );
 
-	t->set_stylebox("normal","TextEdit", make_stylebox( tree_bg_png,12,12,12,12,3,3,3,3) );
-	t->set_stylebox("focus","TextEdit", focus );
 
-	t->set_stylebox("completion","TextEdit", make_stylebox( tree_bg_png,4,4,4,5,3,3,3,3) );
-	t->set_constant("completion_lines","TextEdit", 7 );
-	t->set_constant("completion_max_width","TextEdit", 50 );
-	t->set_constant("completion_scroll_width","TextEdit", 3 );
-	t->set_color("completion_scroll_color","TextEdit", control_font_color_pressed );
-	t->set_color("completion_existing","TextEdit", control_font_color );
+	// TextEdit
 
-	//t->set_font("font","TextEdit", mono_font );
+	t->set_stylebox("normal","TextEdit", make_stylebox( tree_bg_png,3,3,3,3) );
+	t->set_stylebox("focus","TextEdit", focus );
+	t->set_stylebox("completion","TextEdit", make_stylebox( tree_bg_png,3,3,3,3) );
+
+	t->set_icon("tab","TextEdit", make_icon( tab_png) );
 
 	t->set_font("font","TextEdit", default_font );
+
+	t->set_color("completion_scroll_color","TextEdit", control_font_color_pressed );
+	t->set_color("completion_existing","TextEdit", control_font_color );
 	t->set_color("font_color","TextEdit", control_font_color );
 	t->set_color("font_color_selected","TextEdit", Color(0,0,0) );
 	t->set_color("selection_color","TextEdit", font_color_selection );
 	t->set_color("mark_color","TextEdit", Color(1.0,0.4,0.4,0.4) );
-	t->set_color("breakpoint_color","TextEdit", Color(0.8,0.8,0.4,0.4) );
-	t->set_color("current_line_color","TextEdit", Color(0.3,0.5,0.8,0.15) );
+	t->set_color("breakpoint_color","TextEdit", Color(0.8,0.8,0.4,0.2) );
+	t->set_color("current_line_color","TextEdit", Color(0.25,0.25,0.26,0.8) );
 	t->set_color("cursor_color","TextEdit", control_font_color );
 	t->set_color("symbol_color","TextEdit", control_font_color_hover );
 	t->set_color("brace_mismatch_color","TextEdit", Color(1,0.2,0.2) );
-	t->set_constant("line_spacing","TextEdit",1 );
 
-	t->set_stylebox("scroll","HScrollBar", make_stylebox( hscroll_bg_png,3,3,3,3,0,0,0,0) );
-	t->set_stylebox("scroll_focus","HScrollBar", make_stylebox( hscroll_bg_png,3,3,3,3,0,0,0,0) );
-	t->set_stylebox("grabber","HScrollBar", make_stylebox( hscroll_grabber_png,3,3,3,3,2,2,2,2) );
-	t->set_stylebox("grabber_hilite","HScrollBar", make_stylebox( hscroll_grabber_hl_png,3,3,3,3,2,2,2,2) );
+	t->set_constant("completion_lines","TextEdit", 7 );
+	t->set_constant("completion_max_width","TextEdit", 50 );
+	t->set_constant("completion_scroll_width","TextEdit", 3 );
+	t->set_constant("line_spacing","TextEdit",4 );
+
+
+	Ref<Texture> empty_icon = memnew( ImageTexture );
+
+	// HScrollBar
+
+	t->set_stylebox("scroll","HScrollBar", make_stylebox( scroll_bg_png,3,3,3,3,0,0,0,0) );
+	t->set_stylebox("scroll_focus","HScrollBar", make_stylebox( scroll_bg_png,3,3,3,3,0,0,0,0) );
+	t->set_stylebox("grabber","HScrollBar", make_stylebox( scroll_grabber_png,3,3,3,3,2,2,2,2) );
+	t->set_stylebox("grabber_hilite","HScrollBar", make_stylebox( scroll_grabber_hl_png,3,3,3,3,2,2,2,2) );
 
 	t->set_icon("increment","HScrollBar",empty_icon);
 	t->set_icon("increment_hilite","HScrollBar",empty_icon);
@@ -345,77 +416,112 @@ void make_default_theme() {
 	t->set_icon("decrement_hilite","HScrollBar",empty_icon);
 
 
-	t->set_stylebox("scroll","VScrollBar", make_stylebox( vscroll_bg_png,3,3,3,3,0,0,0,0) );
-	t->set_stylebox("scroll_focus","VScrollBar", make_stylebox( vscroll_bg_png,3,3,3,3,0,0,0,0) );
-	t->set_stylebox("grabber","VScrollBar", make_stylebox( vscroll_grabber_png,3,3,3,3,2,2,2,2) );
-	t->set_stylebox("grabber_hilite","VScrollBar", make_stylebox( vscroll_grabber_hl_png,3,3,3,3,2,2,2,2) );
+
+	// VScrollBar
+
+	t->set_stylebox("scroll","VScrollBar", make_stylebox( scroll_bg_png,3,3,3,3,0,0,0,0) );
+	t->set_stylebox("scroll_focus","VScrollBar", make_stylebox( scroll_bg_png,3,3,3,3,0,0,0,0) );
+	t->set_stylebox("grabber","VScrollBar", make_stylebox( scroll_grabber_png,3,3,3,3,2,2,2,2) );
+	t->set_stylebox("grabber_hilite","VScrollBar", make_stylebox( scroll_grabber_hl_png,3,3,3,3,2,2,2,2) );
+
 	t->set_icon("increment","VScrollBar",empty_icon);
 	t->set_icon("increment_hilite","VScrollBar",empty_icon);
 	t->set_icon("decrement","VScrollBar",empty_icon);
 	t->set_icon("decrement_hilite","VScrollBar",empty_icon);
 
-	t->set_stylebox("slider","HSlider", make_stylebox( hslider_bg_png,5,5,5,5,1,1,1,1) );
-	t->set_stylebox("focus","HSlider", make_stylebox( focus_png,3,3,3,3,1,1,1,1) );
-	//t->set_stylebox("slider_focus","HSlider", make_stylebox( hslider_bg_focus_png,6,6,6,6,2,2,2,2) );
+
+
+	// HSlider
+
+	t->set_stylebox("slider","HSlider", make_stylebox( hslider_bg_png,4,4,4,4) );
+	t->set_stylebox("grabber_hilite","HSlider", make_stylebox( hslider_grabber_hl_png,6,6,6,6) );
+	t->set_stylebox("focus","HSlider", focus );
+
 	t->set_icon("grabber","HSlider", make_icon( hslider_grabber_png ) );
 	t->set_icon("grabber_hilite","HSlider", make_icon( hslider_grabber_hl_png ) );
 	t->set_icon("tick","HSlider", make_icon( hslider_tick_png ) );
-	t->set_stylebox("grabber_hilite","HSlider", make_stylebox( hslider_grabber_hl_png,6,6,6,6,2,2,2,2) );
 
-	t->set_stylebox("slider","VSlider", make_stylebox( vslider_bg_png,5,5,5,5,1,1,1,1) );
-	t->set_stylebox("focus","HSlider", make_stylebox( focus_png,3,3,3,3,1,1,1,1) );
-	//t->set_stylebox("slider_focus","VSlider", make_stylebox( vslider_bg_focus_png,6,6,6,6,2,2,2,2) );
+
+
+
+	// VSlider
+
+	t->set_stylebox("slider","VSlider", make_stylebox( vslider_bg_png,4,4,4,4) );
+	t->set_stylebox("grabber_hilite","VSlider", make_stylebox( vslider_grabber_hl_png,6,6,6,6) );
+	t->set_stylebox("focus","HSlider", focus );
+
 	t->set_icon("grabber","VSlider", make_icon( vslider_grabber_png)  );
 	t->set_icon("grabber_hilite","VSlider", make_icon( vslider_grabber_hl_png ) );
 	t->set_icon("tick","VSlider", make_icon( vslider_tick_png ) );
-	t->set_stylebox("grabber_hilite","VSlider", make_stylebox( vslider_grabber_hl_png,6,6,6,6,2,2,2,2) );
+
+
+
+	// SpinBox
 
 	t->set_icon("updown","SpinBox",make_icon(spinbox_updown_png));
 
 
-	Ref<StyleBoxTexture> style_pp_win = make_stylebox( popup_window_png,6,28,6,7,8,8,8,8);
+
+	// WindowDialog
+
+	Ref<StyleBoxTexture> style_pp_win = make_stylebox( popup_window_png,6,28,6,7);
 	for(int i=0;i<4;i++)
 		style_pp_win->set_expand_margin_size((Margin)i,3);
 	style_pp_win->set_expand_margin_size(MARGIN_TOP,26);
+
 	t->set_stylebox("panel","WindowDialog", style_pp_win );
-	t->set_constant("titlebar_height","WindowDialog", 18 );
-	t->set_constant("title_height","WindowDialog", 20 );
-	t->set_font("title_font","WindowDialog", large_font );
-	t->set_color("title_color","WindowDialog", Color(0,0,0) );
+
 	t->set_icon("close","WindowDialog", make_icon( close_png ) );
 	t->set_icon("close_hilite","WindowDialog", make_icon( close_hl_png ) );
+
+	t->set_font("title_font","WindowDialog", large_font );
+
+	t->set_color("title_color","WindowDialog", Color(0,0,0) );
+
 	t->set_constant("close_h_ofs","WindowDialog", 22 );
 	t->set_constant("close_v_ofs","WindowDialog", 20 );
+	t->set_constant("titlebar_height","WindowDialog", 18 );
+	t->set_constant("title_height","WindowDialog", 20 );
 
 
-	Ref<StyleBoxTexture> style_pp = make_stylebox( popup_bg_png,6,19,6,7,8,8,8,8);
-	style_pp->set_expand_margin_size(MARGIN_LEFT,2);
-	style_pp->set_expand_margin_size(MARGIN_TOP,3);
-	style_pp->set_expand_margin_size(MARGIN_RIGHT,2);
-	style_pp->set_expand_margin_size(MARGIN_BOTTOM,3);
 
+	// Popup
 
-	t->set_stylebox("panel","PopupMenu", style_pp );
-	t->set_stylebox("panel","PopupPanel", style_pp );
+	Ref<StyleBoxTexture> style_pp = make_stylebox( popup_bg_png,4,4,4,4,8,8,8,8);
 
 	Ref<StyleBoxTexture> selected = make_stylebox( selection_png,6,6,6,6);
 	for(int i=0;i<4;i++) {
 		selected->set_expand_margin_size(Margin(i),2);
 	}
 
-	t->set_stylebox("panel_disabled","PopupMenu", make_stylebox( popup_bg_disabled_png,5,5,5,5) );
+	t->set_stylebox("panel","PopupPanel", style_pp );
+
+
+
+
+	// PopupMenu
+
+	t->set_stylebox("panel","PopupMenu", make_stylebox( popup_bg_png,4,4,4,4,10,10,10,10) );
+	t->set_stylebox("panel_disabled","PopupMenu", make_stylebox( popup_bg_disabled_png,4,4,4,4) );
 	t->set_stylebox("hover","PopupMenu", selected );
 	t->set_stylebox("separator","PopupMenu", make_stylebox( vseparator_png,3,3,3,3) );
-	t->set_icon("checked","PopupMenu", make_icon(popup_checked_png) );
-	t->set_icon("unchecked","PopupMenu", make_icon(popup_unchecked_png) );
+
+	t->set_icon("checked","PopupMenu", make_icon(checked_png) );
+	t->set_icon("unchecked","PopupMenu", make_icon(unchecked_png) );
 	t->set_icon("submenu","PopupMenu", make_icon(submenu_png) );
+
 	t->set_font("font","PopupMenu", default_font );
+
 	t->set_color("font_color","PopupMenu", control_font_color );
 	t->set_color("font_color_accel","PopupMenu", Color(0.7,0.7,0.7,0.8) );
 	t->set_color("font_color_disabled","PopupMenu", Color(0.4,0.4,0.4,0.8) );
 	t->set_color("font_color_hover","PopupMenu", control_font_color );
-	t->set_constant("hseparation","PopupMenu",2);
-	t->set_constant("vseparation","PopupMenu",1);
+
+	t->set_constant("hseparation","PopupMenu",4);
+	t->set_constant("vseparation","PopupMenu",4);
+
+
+	// GraphNode
 
 	Ref<StyleBoxTexture> graphsb = make_stylebox(graph_node_png,6,24,6,5,16,24,16,5);
 	//graphsb->set_expand_margin_size(MARGIN_LEFT,10);
@@ -431,57 +537,65 @@ void make_default_theme() {
 	t->set_constant("port_offset","GraphNode", 3);
 
 
-	t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5,3,3,3,3) );
+	// Tree
+
+	Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0);
+	Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0);
+
+	t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) );
 	t->set_stylebox("bg_focus","Tree", focus );
-	Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4);
-	Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4);
-	for(int i=0;i<4;i++) {
-		tree_selected->set_expand_margin_size(Margin(i),2);
-		tree_selected_oof->set_expand_margin_size(Margin(i),2);
-	}
 	t->set_stylebox("selected","Tree", tree_selected_oof );
 	t->set_stylebox("selected_focus","Tree", tree_selected );
-	t->set_stylebox("completion_selected","TextEdit", tree_selected );
-
-
 	t->set_stylebox("cursor","Tree", focus );
 	t->set_stylebox("cursor_unfocused","Tree", focus );
-	t->set_stylebox("button_pressed","Tree",make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3));
+	t->set_stylebox("button_pressed","Tree",make_stylebox( button_pressed_png,4,4,4,4));
+	t->set_stylebox("title_button_normal","Tree", make_stylebox( tree_title_png,4,4,4,4) );
+	t->set_stylebox("title_button_pressed","Tree", make_stylebox( tree_title_pressed_png,4,4,4,4) );
+	t->set_stylebox("title_button_hover","Tree", make_stylebox( tree_title_png,4,4,4,4) );
+
+	t->set_icon("checked","Tree",make_icon(checked_png));
+	t->set_icon("unchecked","Tree",make_icon(unchecked_png));
+	t->set_icon("updown","Tree",make_icon(updown_png));
+	t->set_icon("select_arrow","Tree",make_icon(dropdown_png));
+	t->set_icon("arrow","Tree",make_icon(arrow_down_png));
+	t->set_icon("arrow_collapsed","Tree",make_icon(arrow_right_png));
+
+	t->set_font("title_button_font","Tree", default_font );
 	t->set_font("font","Tree", default_font );
+
+	t->set_color("title_button_color","Tree", control_font_color );
 	t->set_color("font_color","Tree", control_font_color_low );
-	t->set_color("font_color_selected","Tree", control_font_color );
+	t->set_color("font_color_selected","Tree", control_font_color_pressed );
 	t->set_color("selection_color","Tree", Color(0.1,0.1,1,0.8) );
 	t->set_color("cursor_color","Tree", Color(0,0,0) );
 	t->set_color("guide_color","Tree", Color(0,0,0,0.1) );
-	t->set_constant("hseparation","Tree",2);
-	t->set_constant("vseparation","Tree",1);
-	t->set_constant("guide_width","Tree",1);
+
+	t->set_constant("hseparation","Tree",4);
+	t->set_constant("vseparation","Tree",2);
+	t->set_constant("guide_width","Tree",2);
 	t->set_constant("item_margin","Tree",12);
-	t->set_constant("button_margin","Tree",2);
+	t->set_constant("button_margin","Tree",4);
 
-	t->set_stylebox("title_button_normal","Tree", make_stylebox( tree_title_png,4,4,4,4,3,3,3,3) );
-	t->set_stylebox("title_button_pressed","Tree", make_stylebox( tree_title_pressed_png,4,4,4,4,3,3,3,3) );
-	t->set_stylebox("title_button_hover","Tree", make_stylebox( tree_title_png,4,4,4,4,3,3,3,3) );
-	t->set_color("title_button_color","Tree", control_font_color );
-	t->set_font("title_button_font","Tree", default_font );
 
 
-	t->set_icon("checked","Tree",make_icon(checked_png));
-	t->set_icon("unchecked","Tree",make_icon(unchecked_png));
-	t->set_icon("updown","Tree",make_icon(updown_png));
-	t->set_icon("select_arrow","Tree",make_icon(dropdown_png));
-	t->set_icon("arrow","Tree",make_icon(arrow_down_png));
-	t->set_icon("arrow_collapsed","Tree",make_icon(arrow_right_png));
+	// TextEdit
 
-	t->set_stylebox("tab_fg","TabContainer", make_stylebox( tab_current_png,5,5,5,5,8,3,8,3) );
-	t->set_stylebox("tab_bg","TabContainer", make_stylebox( tab_behind_png,5,5,5,5,8,4,8,3) );
-	Ref<StyleBoxTexture> tc_sb = make_stylebox( tab_container_bg_png,6,19,6,7);
+	t->set_stylebox("completion_selected","TextEdit", tree_selected );
+
+
+
+	// TabContainer
+
+	Ref<StyleBoxTexture> tc_sb = make_stylebox( tab_container_bg_png,4,4,4,4);
 	for(int i=0;i<4;i++) {
-		tc_sb->set_default_margin(Margin(i),7);
+		tc_sb->set_default_margin(Margin(i),4);
 		tc_sb->set_expand_margin_size(Margin(i),2);
 	}
-	//tc_sb->set_expand_margin_size(MARGIN_TOP,2);
-	//tc_sb->set_default_margin(MARGIN_TOP,6);
+	tc_sb->set_expand_margin_size(MARGIN_TOP,2);
+	tc_sb->set_default_margin(MARGIN_TOP,8);
+
+	t->set_stylebox("tab_fg","TabContainer", make_stylebox( tab_current_png,4,4,4,4,16,4,16,4) );
+	t->set_stylebox("tab_bg","TabContainer", make_stylebox( tab_behind_png,4,4,4,4,16,6,16,4) );
 	t->set_stylebox("panel","TabContainer", tc_sb );
 
 	t->set_icon("increment","TabContainer",make_icon( scroll_button_right_png));
@@ -490,116 +604,178 @@ void make_default_theme() {
 	t->set_icon("decrement_hilite","TabContainer",make_icon( scroll_button_left_hl_png));
 
 	t->set_font("font","TabContainer", default_font );
+
 	t->set_color("font_color_fg","TabContainer", control_font_color_hover );
-	t->set_color("font_color_bg","TabContainer", control_font_color );
-	t->set_constant("side_margin","TabContainer", 5 );
+	t->set_color("font_color_bg","TabContainer", control_font_color_low );
+
+	t->set_constant("side_margin","TabContainer", 8 );
 	t->set_constant("top_margin","TabContainer", 24);
-	t->set_constant("label_valign_fg","TabContainer", 4);
-	t->set_constant("label_valign_bg","TabContainer", 5);
-	t->set_constant("hseparation","TabContainer", 2);
+	t->set_constant("label_valign_fg","TabContainer", 0);
+	t->set_constant("label_valign_bg","TabContainer", 2);
+	t->set_constant("hseparation","TabContainer", 4);
+
+
+
+	// Tabs
+
+	t->set_stylebox("tab_fg","Tabs", make_stylebox( tab_current_png,4,4,4,4,16,4,16,4) );
+	t->set_stylebox("tab_bg","Tabs", make_stylebox( tab_behind_png,4,4,4,4,16,6,16,4) );
+	t->set_stylebox("panel","Tabs", make_stylebox( tab_container_bg_png,4,4,4,4) );
 
-	t->set_stylebox("tab_fg","Tabs", make_stylebox( tab_current_png,5,5,5,5,8,3,8,3) );
-	t->set_stylebox("tab_bg","Tabs", make_stylebox( tab_behind_png,5,5,5,5,8,4,8,3) );
-	t->set_stylebox("panel","Tabs", make_stylebox( tab_container_bg_png,3,3,3,3) );
 	t->set_font("font","Tabs", default_font );
+
 	t->set_color("font_color_fg","Tabs", control_font_color_hover );
-	t->set_color("font_color_bg","Tabs", control_font_color );
+	t->set_color("font_color_bg","Tabs", control_font_color_low );
+
 	t->set_constant("top_margin","Tabs", 24);
-	t->set_constant("label_valign_fg","Tabs", 4);
-	t->set_constant("label_valign_bg","Tabs", 5);
-	t->set_constant("hseparation","Tabs", 2);
+	t->set_constant("label_valign_fg","Tabs", 0);
+	t->set_constant("label_valign_bg","Tabs", 2);
+	t->set_constant("hseparation","Tabs", 4);
+
+
+
+	// Separators
 
 	t->set_stylebox("separator","HSeparator", make_stylebox( vseparator_png,3,3,3,3) );
-	t->set_constant("separation","HSeparator", 7);
 	t->set_stylebox("separator","VSeparator", make_stylebox( hseparator_png,3,3,3,3) );
-	t->set_constant("separation","VSeparator", 7);
 
 	t->set_icon("close","Icons", make_icon(icon_close_png));
 	t->set_font("source","Fonts", source_font);
 	t->set_font("normal","Fonts", default_font );
 	t->set_font("large","Fonts", large_font );
 
+	t->set_constant("separation","HSeparator", 4);
+	t->set_constant("separation","VSeparator", 4);
+
 
+	// Dialogs
 
-	t->set_constant("margin","Dialogs",10);
+	t->set_constant("margin","Dialogs",8);
 	t->set_constant("button_margin","Dialogs",32);
+
+
+
+	// FileDialog
 	
 	t->set_icon("folder","FileDialog",make_icon(icon_folder_png));
+
 	t->set_color("files_disabled","FileDialog",Color(0,0,0,0.7));
 
+
+
+	// colorPicker
+
 	t->set_constant("value_height","ColorPicker", 23 );
 	t->set_constant("value_width","ColorPicker", 50);
 	t->set_constant("color_width","ColorPicker", 100);
-	t->set_constant("label_width","ColorPicker", 15);
+	t->set_constant("label_width","ColorPicker", 20);
 	t->set_constant("hseparator","ColorPicker", 4);
 
-	Ref<StyleBoxTexture> style_tt = make_stylebox( tooltip_bg_png,9,9,9,9,8,8,8,8);
+
+
+	// TooltipPanel
+
+	Ref<StyleBoxTexture> style_tt = make_stylebox( tooltip_bg_png,4,4,4,4);
 	for(int i=0;i<4;i++)
 		style_tt->set_expand_margin_size((Margin)i,4);
+
 	t->set_stylebox("panel","TooltipPanel", style_tt );
+
 	t->set_font("font","TooltipLabel", default_font );
+
 	t->set_color("font_color","TooltipLabel", Color(0,0,0) );
 	t->set_color("font_color_shadow","TooltipLabel", Color(0,0,0,0.1) );
+
 	t->set_constant("shadow_offset_x","TooltipLabel", 1 );
 	t->set_constant("shadow_offset_y","TooltipLabel", 1 );
 
+
+
+	// RichTextLabel
+
+	t->set_stylebox("focus","RichTextLabel", focus );
+
 	t->set_font("default_font","RichTextLabel", default_font );
+
 	t->set_color("default_color","RichTextLabel", control_font_color );
 	t->set_color("font_color_selected","RichTextLabel", font_color_selection );
 	t->set_color("selection_color","RichTextLabel", Color(0.1,0.1,1,0.8) );
+
 	t->set_constant("line_separation","RichTextLabel", 1 );
-	t->set_stylebox("focus","RichTextLabel", focus );
 
 
+
+	// Containers
+
+	t->set_stylebox("bg","VSplitContainer", make_stylebox( vsplit_bg_png,1,1,1,1) );
+	t->set_stylebox("bg","HSplitContainer", make_stylebox( hsplit_bg_png,1,1,1,1) );
+
+	t->set_icon("grabber","VSplitContainer",make_icon(vsplitter_png));
+	t->set_icon("grabber","HSplitContainer",make_icon(hsplitter_png));
+
 	t->set_constant("separation","HBoxContainer",4);
 	t->set_constant("separation","VBoxContainer",4);
-	t->set_constant("margin","MarginContainer",15);
-
+	t->set_constant("margin","MarginContainer",8);
 	t->set_constant("separation","GridContainer",4);
-
-	t->set_constant("separation","HSplitContainer",8);
-	t->set_constant("separation","VSplitContainer",8);
+	t->set_constant("separation","HSplitContainer",12);
+	t->set_constant("separation","VSplitContainer",12);
 	t->set_constant("autohide","HSplitContainer",1);
 	t->set_constant("autohide","VSplitContainer",1);
-	t->set_icon("grabber","VSplitContainer",make_icon(vsplitter_png));
-	t->set_icon("grabber","HSplitContainer",make_icon(hsplitter_png));
 
-	t->set_stylebox("bg","VSplitContainer", make_stylebox( vsplit_bg_png,1,1,1,1,1,1,1,1) );
-	t->set_stylebox("bg","HSplitContainer", make_stylebox( hsplit_bg_png,1,1,1,1,1,1,1,1) );
 
-	t->set_stylebox("normal","HButtonArray", make_stylebox( button_normal_png,2,2,2,2,3,3,3,3) );
-	t->set_stylebox("selected","HButtonArray", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("hover","HButtonArray", make_stylebox( button_hover_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("focus","HButtonArray", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
+
+	// HButtonArray
+
+	t->set_stylebox("normal","HButtonArray", make_stylebox( button_normal_png,4,4,4,4,0,4,22,4) );
+	t->set_stylebox("selected","HButtonArray", make_stylebox( button_pressed_png,4,4,4,4,0,4,22,4) );
+	t->set_stylebox("hover","HButtonArray", make_stylebox( button_hover_png,4,4,4,4) );
+
 	t->set_font("font","HButtonArray", default_font);
 	t->set_font("font_selected","HButtonArray", default_font);
-	t->set_color("font_color","HButtonArray", Color(1,1,1,1) );
-	t->set_color("font_color_selected","HButtonArray", Color(0.7,0.7,0.7,1) );
-	t->set_constant("icon_separator","HButtonArray", 2 );
-	t->set_constant("button_separator","HButtonArray", 3 );
-
-	t->set_stylebox("normal","VButtonArray", make_stylebox( button_normal_png,2,2,2,2,3,3,3,3) );
-	t->set_stylebox("selected","VButtonArray", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("hover","VButtonArray", make_stylebox( button_hover_png,5,5,5,5,3,3,3,3) );
-	t->set_stylebox("focus","VButtonArray", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
+
+	t->set_color("font_color","HButtonArray", control_font_color_low );
+	t->set_color("font_color_selected","HButtonArray", control_font_color_hover );
+
+	t->set_constant("icon_separator","HButtonArray", 4 );
+	t->set_constant("button_separator","HButtonArray", 8 );
+
+	t->set_stylebox("focus","HButtonArray", focus );
+
+
+	// VButtonArray
+
+	t->set_stylebox("normal","VButtonArray", make_stylebox( button_normal_png,4,4,4,4,0,4,22,4) );
+	t->set_stylebox("selected","VButtonArray", make_stylebox( button_pressed_png,4,4,4,4,0,4,22,4) );
+	t->set_stylebox("hover","VButtonArray", make_stylebox( button_hover_png,4,4,4,4) );
+
 	t->set_font("font","VButtonArray", default_font);
 	t->set_font("font_selected","VButtonArray", default_font);
-	t->set_color("font_color","VButtonArray", Color(1,1,1,1) );
-	t->set_color("font_color_selected","VButtonArray", Color(0.7,0.7,0.7,1) );
-	t->set_constant("icon_separator","VButtonArray", 2 );
-	t->set_constant("button_separator","VButtonArray", 3 );
 
-	t->set_stylebox("border","ReferenceFrame", make_stylebox( reference_border_png,5,5,5,5,3,3,3,3) );
+	t->set_color("font_color","VButtonArray", control_font_color_low );
+	t->set_color("font_color_selected","VButtonArray", control_font_color_hover );
+
+	t->set_constant("icon_separator","VButtonArray", 4);
+	t->set_constant("button_separator","VButtonArray", 8);
+
+	t->set_stylebox("focus","VButtonArray", focus );
+
+
+	// ReferenceFrame
 
 	Ref<StyleBoxTexture> ttnc = make_stylebox( full_panel_bg_png,8,8,8,8);
 	ttnc->set_draw_center(false);
+
+	t->set_stylebox("border","ReferenceFrame", make_stylebox( reference_border_png,4,4,4,4) );
 	t->set_stylebox("panelnc","Panel", ttnc );
 	t->set_stylebox("panelf","Panel", tc_sb );
-
 	t->set_stylebox("panel","PanelContainer", tc_sb );
 
 	t->set_icon( "logo","Icons", make_icon(logo_png) );
 
+
+
+	// Theme
+
 	Theme::set_default( t );
 	Theme::set_default_icon( make_icon(error_icon_png) );
 	Theme::set_default_style( make_stylebox( error_icon_png,2,2,2,2) );
@@ -626,8 +802,8 @@ void make_default_theme() {
 	style->set_texture(texture);
 
 	for(int i=0;i<4;i++) {
-		style->set_margin_size(  Margin(),2);
-		style->set_default_margin(  Margin(),2);
+		style->set_margin_size(  Margin(),8);
+		style->set_default_margin(  Margin(),8);
 	}
 
 	Ref<Font> f = make_default_font();

BIN
scene/resources/default_theme/dropdown.png


BIN
scene/resources/default_theme/focus.png


BIN
scene/resources/default_theme/full_panel_bg.png


BIN
scene/resources/default_theme/hscroll_bg.png


BIN
scene/resources/default_theme/hscroll_bg_focus.png


BIN
scene/resources/default_theme/hscroll_grabber.png


BIN
scene/resources/default_theme/hscroll_grabber_hl.png


BIN
scene/resources/default_theme/hslider_bg.png


BIN
scene/resources/default_theme/hslider_grabber.png


BIN
scene/resources/default_theme/hslider_grabber_hl.png


BIN
scene/resources/default_theme/hslider_tick.png


BIN
scene/resources/default_theme/hsplit_bg.png


BIN
scene/resources/default_theme/hsplitter.png


BIN
scene/resources/default_theme/icon_folder.png


BIN
scene/resources/default_theme/icon_play.png


BIN
scene/resources/default_theme/icon_stop.png


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است