summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-10-03 16:33:42 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-10-03 21:35:16 +0200
commit22d83bc9f655d5ae7a1b49709c4c1b663725daf5 (patch)
treea817195c08d4713a70ca014a3f63f5937934fe36
parent78d97b060a6873a454e710380cb9ef1bde5e4c65 (diff)
Begining of GLES3 renderer:
-Most 2D drawing is implemented -Missing shaders -Missing all 3D -Editor needs to be set on update always to be used, otherwise it does not refresh -Large parts of editor not working
-rw-r--r--SConstruct3
-rw-r--r--bin/tests/test_detailer.cpp217
-rw-r--r--bin/tests/test_detailer.h44
-rw-r--r--bin/tests/test_gui.cpp4
-rw-r--r--bin/tests/test_main.cpp34
-rw-r--r--bin/tests/test_misc.cpp499
-rw-r--r--bin/tests/test_misc.h40
-rw-r--r--bin/tests/test_particles.cpp121
-rw-r--r--bin/tests/test_particles.h43
-rw-r--r--bin/tests/test_physics.cpp28
-rw-r--r--bin/tests/test_physics_2d.cpp10
-rw-r--r--bin/tests/test_python.cpp56
-rw-r--r--bin/tests/test_python.h43
-rw-r--r--bin/tests/test_render.cpp8
-rw-r--r--bin/tests/test_shader_lang.cpp18
-rw-r--r--core/globals.cpp47
-rw-r--r--core/image.cpp1213
-rw-r--r--core/image.h200
-rw-r--r--core/image_quantize.cpp365
-rw-r--r--core/io/marshalls.cpp2
-rw-r--r--core/io/resource_format_binary.cpp94
-rw-r--r--core/io/resource_format_xml.cpp61
-rw-r--r--core/rid.cpp12
-rw-r--r--core/rid.h202
-rw-r--r--core/variant_call.cpp71
-rw-r--r--core/variant_parser.cpp80
-rw-r--r--doc/base/classes.xml22
-rw-r--r--drivers/SCsub2
-rw-r--r--drivers/dds/texture_loader_dds.cpp29
-rw-r--r--drivers/etc1/image_etc.cpp16
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp60
-rw-r--r--drivers/gles2/rasterizer_gles2.h2
-rw-r--r--drivers/gles2/shaders/canvas.glsl6
-rw-r--r--drivers/gles3/SCsub5
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp1461
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.h102
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp266
-rw-r--r--drivers/gles3/rasterizer_gles3.h38
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp2045
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.h445
-rw-r--r--drivers/gles3/shader_gles3.cpp754
-rw-r--r--drivers/gles3/shader_gles3.h377
-rw-r--r--drivers/gles3/shaders/SCsub7
-rw-r--r--drivers/gles3/shaders/canvas.glsl428
-rw-r--r--drivers/gles3/shaders/canvas_shadow.glsl49
-rw-r--r--drivers/gles3/shaders/copy.glsl52
-rw-r--r--drivers/jpegd/image_loader_jpegd.cpp4
-rw-r--r--drivers/png/image_loader_png.cpp91
-rw-r--r--drivers/png/resource_saver_png.cpp16
-rw-r--r--drivers/pvr/texture_loader_pvr.cpp38
-rw-r--r--drivers/squish/image_compress_squish.cpp18
-rw-r--r--drivers/theora/video_stream_theora.cpp10
-rw-r--r--drivers/webp/image_loader_webp.cpp10
-rwxr-xr-xmethods.py46
-rw-r--r--modules/gridmap/config.py2
-rw-r--r--platform/iphone/rasterizer_iphone.cpp18
-rw-r--r--platform/iphone/rasterizer_iphone.h2
-rw-r--r--platform/osx/export/export.cpp2
-rw-r--r--platform/osx/os_osx.mm2
-rw-r--r--platform/osx/platform_config.h2
-rw-r--r--platform/server/os_server.cpp10
-rw-r--r--platform/server/os_server.h2
-rw-r--r--platform/windows/os_windows.cpp4
-rw-r--r--platform/windows/platform_config.h1
-rw-r--r--platform/x11/context_gl_x11.cpp1
-rw-r--r--platform/x11/detect.py6
-rw-r--r--platform/x11/os_x11.cpp19
-rw-r--r--platform/x11/os_x11.h4
-rw-r--r--platform/x11/platform_config.h1
-rw-r--r--scene/2d/canvas_item.cpp151
-rw-r--r--scene/2d/canvas_item.h38
-rw-r--r--scene/2d/light_2d.cpp60
-rw-r--r--scene/2d/light_2d.h29
-rw-r--r--scene/2d/sprite.cpp3
-rw-r--r--scene/2d/sprite.h2
-rw-r--r--scene/2d/tile_map.cpp15
-rw-r--r--scene/3d/baked_light_instance.cpp2
-rw-r--r--scene/3d/baked_light_instance.h3
-rw-r--r--scene/3d/camera.cpp107
-rw-r--r--scene/3d/camera.h6
-rw-r--r--scene/3d/light.cpp509
-rw-r--r--scene/3d/light.h104
-rw-r--r--scene/3d/particles.cpp2
-rw-r--r--scene/3d/particles.h3
-rw-r--r--scene/3d/portal.cpp44
-rw-r--r--scene/3d/portal.h2
-rw-r--r--scene/3d/position_3d.cpp31
-rw-r--r--scene/3d/position_3d.h1
-rw-r--r--scene/3d/quad.cpp2
-rw-r--r--scene/3d/room_instance.cpp77
-rw-r--r--scene/3d/room_instance.h5
-rw-r--r--scene/3d/skeleton.cpp47
-rw-r--r--scene/3d/skeleton.h1
-rw-r--r--scene/3d/spatial_player.cpp140
-rw-r--r--scene/3d/spatial_player.h2
-rw-r--r--scene/3d/visual_instance.cpp108
-rw-r--r--scene/3d/visual_instance.h21
-rw-r--r--scene/gui/color_picker.cpp76
-rw-r--r--scene/gui/patch_9_frame.cpp2
-rw-r--r--scene/main/canvas_layer.cpp10
-rw-r--r--scene/main/canvas_layer.h5
-rw-r--r--scene/main/node.cpp10
-rw-r--r--scene/main/scene_main_loop.cpp35
-rw-r--r--scene/main/viewport.cpp260
-rw-r--r--scene/main/viewport.h74
-rw-r--r--scene/register_scene_types.cpp25
-rw-r--r--scene/resources/baked_light.cpp5
-rw-r--r--scene/resources/baked_light.h5
-rw-r--r--scene/resources/bit_mask.cpp7
-rw-r--r--scene/resources/default_theme/color_picker_hue.pngbin0 -> 132 bytes
-rw-r--r--scene/resources/default_theme/color_picker_main.pngbin0 -> 310 bytes
-rw-r--r--scene/resources/default_theme/color_picker_sample.pngbin0 -> 194 bytes
-rw-r--r--scene/resources/default_theme/default_theme.cpp18
-rw-r--r--scene/resources/default_theme/theme_data.h15
-rw-r--r--scene/resources/dynamic_font.cpp2
-rw-r--r--scene/resources/dynamic_font_stb.cpp2
-rw-r--r--scene/resources/environment.cpp245
-rw-r--r--scene/resources/environment.h97
-rw-r--r--scene/resources/material.cpp552
-rw-r--r--scene/resources/material.h188
-rw-r--r--scene/resources/mesh.cpp38
-rw-r--r--scene/resources/mesh.h5
-rw-r--r--scene/resources/multimesh.cpp42
-rw-r--r--scene/resources/multimesh.h29
-rw-r--r--scene/resources/room.cpp38
-rw-r--r--scene/resources/room.h8
-rw-r--r--scene/resources/shader.cpp334
-rw-r--r--scene/resources/shader.h19
-rw-r--r--scene/resources/shader_graph.cpp7
-rw-r--r--scene/resources/shader_graph.h4
-rw-r--r--scene/resources/style_box.cpp126
-rw-r--r--scene/resources/style_box.h30
-rw-r--r--scene/resources/texture.cpp18
-rw-r--r--scene/resources/texture.h2
-rw-r--r--servers/audio/audio_server_sw.h4
-rw-r--r--servers/audio/sample_manager_sw.h2
-rw-r--r--servers/physics/broad_phase_octree.cpp2
-rw-r--r--servers/physics/constraint_sw.h2
-rw-r--r--servers/physics/shape_sw.h4
-rw-r--r--servers/physics/space_sw.h2
-rw-r--r--servers/physics_2d/broad_phase_2d_basic.cpp2
-rw-r--r--servers/physics_2d/constraint_2d_sw.h2
-rw-r--r--servers/physics_2d/shape_2d_sw.h4
-rw-r--r--servers/physics_2d/space_2d_sw.h2
-rw-r--r--servers/spatial_sound/spatial_sound_server_sw.h8
-rw-r--r--servers/spatial_sound_2d/spatial_sound_2d_server_sw.h8
-rw-r--r--servers/visual/particle_system_sw.cpp412
-rw-r--r--servers/visual/particle_system_sw.h131
-rw-r--r--servers/visual/rasterizer.cpp19
-rw-r--r--servers/visual/rasterizer.h760
-rw-r--r--servers/visual/rasterizer_dummy.cpp1961
-rw-r--r--servers/visual/rasterizer_dummy.h791
-rw-r--r--servers/visual/shader_language.cpp3910
-rw-r--r--servers/visual/shader_language.h375
-rw-r--r--servers/visual/visual_server_canvas.cpp1268
-rw-r--r--servers/visual/visual_server_canvas.h214
-rw-r--r--servers/visual/visual_server_global.cpp10
-rw-r--r--servers/visual/visual_server_global.h26
-rw-r--r--servers/visual/visual_server_raster.cpp1329
-rw-r--r--servers/visual/visual_server_raster.h592
-rw-r--r--servers/visual/visual_server_viewport.cpp489
-rw-r--r--servers/visual/visual_server_viewport.h118
-rw-r--r--servers/visual/visual_server_wrap_mt.cpp212
-rw-r--r--servers/visual/visual_server_wrap_mt.h739
-rw-r--r--servers/visual_server.cpp439
-rw-r--r--servers/visual_server.h758
-rw-r--r--tools/editor/code_editor.cpp2
-rw-r--r--tools/editor/editor_autoload_settings.cpp2
-rw-r--r--tools/editor/editor_help.cpp2
-rw-r--r--tools/editor/editor_node.cpp35
-rw-r--r--tools/editor/editor_profiler.cpp2
-rw-r--r--tools/editor/icons/SCsub2
-rw-r--r--tools/editor/io_plugins/editor_font_import_plugin.cpp10
-rw-r--r--tools/editor/io_plugins/editor_import_collada.cpp50
-rw-r--r--tools/editor/io_plugins/editor_scene_import_plugin.cpp58
-rw-r--r--tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp3
-rw-r--r--tools/editor/io_plugins/editor_scene_importer_fbxconv.h2
-rw-r--r--tools/editor/io_plugins/editor_texture_import_plugin.cpp72
-rw-r--r--tools/editor/plugins/baked_light_baker.cpp11
-rw-r--r--tools/editor/plugins/baked_light_baker.h3
-rw-r--r--tools/editor/plugins/baked_light_editor_plugin.cpp5
-rw-r--r--tools/editor/plugins/baked_light_editor_plugin.h4
-rw-r--r--tools/editor/plugins/collision_polygon_editor_plugin.cpp3
-rw-r--r--tools/editor/plugins/collision_polygon_editor_plugin.h4
-rw-r--r--tools/editor/plugins/cube_grid_theme_editor_plugin.cpp3
-rw-r--r--tools/editor/plugins/cube_grid_theme_editor_plugin.h3
-rw-r--r--tools/editor/plugins/editor_preview_plugins.cpp17
-rw-r--r--tools/editor/plugins/editor_preview_plugins.h3
-rw-r--r--tools/editor/plugins/material_editor_plugin.cpp3
-rw-r--r--tools/editor/plugins/material_editor_plugin.h3
-rw-r--r--tools/editor/plugins/mesh_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/mesh_editor_plugin.h3
-rw-r--r--tools/editor/plugins/particles_2d_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/particles_editor_plugin.cpp3
-rw-r--r--tools/editor/plugins/particles_editor_plugin.h3
-rw-r--r--tools/editor/plugins/path_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/path_editor_plugin.h3
-rw-r--r--tools/editor/plugins/polygon_2d_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/sample_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/sample_library_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/shader_editor_plugin.cpp3
-rw-r--r--tools/editor/plugins/shader_editor_plugin.h4
-rw-r--r--tools/editor/plugins/shader_graph_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/shader_graph_editor_plugin.h4
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.cpp86
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.h2
-rw-r--r--tools/editor/project_manager.cpp4
-rw-r--r--tools/editor/pvrtc_compress.cpp2
-rw-r--r--tools/editor/scene_tree_editor.cpp2
-rw-r--r--tools/editor/spatial_editor_gizmos.cpp3
-rw-r--r--tools/editor/spatial_editor_gizmos.h4
211 files changed, 14937 insertions, 13944 deletions
diff --git a/SConstruct b/SConstruct
index 0652414088..4fd0330b92 100644
--- a/SConstruct
+++ b/SConstruct
@@ -386,6 +386,9 @@ if selected_platform in platform_list:
if (env['etc1']=='yes'):
env.Append(CPPFLAGS=['-DETC1_ENABLED'])
+ if (True): # detect GLES3
+ env.Append( BUILDERS = { 'GLES3_GLSL' : env.Builder(action = methods.build_gles3_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
+
Export('env')
#build subdirs, the build order is dependent on link order.
diff --git a/bin/tests/test_detailer.cpp b/bin/tests/test_detailer.cpp
deleted file mode 100644
index 5dba7c3f72..0000000000
--- a/bin/tests/test_detailer.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-/*************************************************************************/
-/* test_detailer.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "test_detailer.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
-#include "math_funcs.h"
-#include "print_string.h"
-#include "geometry.h"
-#include "quick_hull.h"
-namespace TestMultiMesh {
-
-
-class TestMainLoop : public MainLoop {
-
- RID instance;
- RID camera;
- RID viewport;
- RID light;
- RID mesh;
- RID scenario;
-
-#define MULTIMESH_COUNT 1500
-
- float ofs_x,ofs_y;
- bool quit;
-public:
-
-
- virtual void _update_qh() {
-
- VisualServer *vs=VisualServer::get_singleton();
- Vector<Vector3> vts;
-/*
-
- static const int s = 20;
- for(int i=0;i<s;i++) {
- Matrix3 rot(Vector3(0,1,0),i*Math_PI/s);
-
- for(int j=0;j<s;j++) {
- Vector3 v;
- v.x=Math::sin(j*Math_PI*2/s);
- v.y=Math::cos(j*Math_PI*2/s);
-
- vts.push_back( rot.xform(v*2 ) );
- }
- }*/
- /*
- Math::seed(0);
- for(int i=0;i<50;i++) {
-
- vts.push_back( Vector3(Math::randf()*2-1.0,Math::randf()*2-1.0,Math::randf()*2-1.0).normalized()*2);
- }*/
- /*
- vts.push_back(Vector3(0,0,1));
- vts.push_back(Vector3(0,0,-1));
- vts.push_back(Vector3(0,1,0));
- vts.push_back(Vector3(0,-1,0));
- vts.push_back(Vector3(1,0,0));
- vts.push_back(Vector3(-1,0,0));*/
-/*
- vts.push_back(Vector3(1,1,1));
- vts.push_back(Vector3(1,-1,1));
- vts.push_back(Vector3(-1,1,1));
- vts.push_back(Vector3(-1,-1,1));
- vts.push_back(Vector3(1,1,-1));
- vts.push_back(Vector3(1,-1,-1));
- vts.push_back(Vector3(-1,1,-1));
- vts.push_back(Vector3(-1,-1,-1));
-*/
-
-
- DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,4,Vector3::AXIS_Z);
- Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes);
- vts=convex_data.vertices;
-
- Geometry::MeshData md;
- Error err = QuickHull::build(vts,md);
- print_line("ERR: "+itos(err));
-
- vs->mesh_remove_surface(mesh,0);
- vs->mesh_add_surface_from_mesh_data(mesh,md);
-
-
-
- //vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME);
-
- /*
- RID sm = vs->shader_create();
- //vs->shader_set_fragment_code(sm,"OUT_ALPHA=mod(TIME,1);");
- //vs->shader_set_vertex_code(sm,"OUT_VERTEX=IN_VERTEX*mod(TIME,1);");
- vs->shader_set_fragment_code(sm,"OUT_DIFFUSE=vec3(1,0,1);OUT_GLOW=abs(sin(TIME));");
- RID tcmat = vs->mesh_surface_get_material(test_cube,0);
- vs->material_set_shader(tcmat,sm);
- */
-
- }
-
- virtual void input_event(const InputEvent& p_event) {
-
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) {
-
- ofs_x+=p_event.mouse_motion.relative_y/200.0;
- ofs_y+=p_event.mouse_motion.relative_x/200.0;
- }
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) {
-
- QuickHull::debug_stop_after++;
- _update_qh();
- }
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==2) {
-
- if (QuickHull::debug_stop_after>0)
- QuickHull::debug_stop_after--;
- _update_qh();
- }
-
-
- }
-
- virtual void request_quit() {
-
- quit=true;
- }
-
-
-
- virtual void init() {
-
- VisualServer *vs=VisualServer::get_singleton();
-
-
- mesh = vs->mesh_create();
-
- scenario = vs->scenario_create();
-
- QuickHull::debug_stop_after=0;
- _update_qh();
-
- instance = vs->instance_create2(mesh,scenario);
-
- camera = vs->camera_create();
-
-
- vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
- viewport = vs->viewport_create();
- vs->viewport_attach_camera( viewport, camera );
- vs->viewport_attach_to_screen(viewport);
- vs->viewport_set_scenario( viewport, scenario );
-
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,2 ) ) );
-
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
- //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.3,0.3,0.3) );
- light = vs->instance_create2( lightaux,scenario );
- vs->instance_set_transform(light,Transform(Matrix3(Vector3(0.1,0.4,0.7).normalized(),0.9)));
-
- ofs_x=0;
- ofs_y=0;
- quit=false;
- }
-
- virtual bool idle(float p_time) {
- return false;
- }
-
- virtual bool iteration(float p_time) {
-
- VisualServer *vs=VisualServer::get_singleton();
-
- Transform tr_camera;
- tr_camera.rotate( Vector3(0,1,0), ofs_y );
- tr_camera.rotate( Vector3(1,0,0),ofs_x );
- tr_camera.translate(0,0,10);
-
- vs->camera_set_transform( camera, tr_camera );
-
- return quit;
- }
- virtual void finish() {
-
- }
-
-};
-
-MainLoop* test() {
-
- return memnew(TestMainLoop);
-
-}
-
-}
diff --git a/bin/tests/test_detailer.h b/bin/tests/test_detailer.h
deleted file mode 100644
index 597e088caf..0000000000
--- a/bin/tests/test_detailer.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*************************************************************************/
-/* test_detailer.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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 TEST_MULTIMESH_H
-#define TEST_MULTIMESH_H
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-#include "os/main_loop.h"
-
-namespace TestMultiMesh {
-
-MainLoop* test();
-
-}
-
-
-#endif
diff --git a/bin/tests/test_gui.cpp b/bin/tests/test_gui.cpp
index f4341fd7b3..bfce03d663 100644
--- a/bin/tests/test_gui.cpp
+++ b/bin/tests/test_gui.cpp
@@ -370,7 +370,7 @@ public:
tabc->set_size( Point2( 180,250 ) );
- Ref<ImageTexture> text = memnew( ImageTexture );
+ /*Ref<ImageTexture> text = memnew( ImageTexture );
text->load("test_data/concave.png");
Sprite* sprite = memnew(Sprite);
@@ -383,7 +383,7 @@ public:
sprite->set_texture(text);
sprite->add_child(sprite2);
sprite2->set_pos(Point2(50, 50));
- sprite2->show();
+ sprite2->show();*/
}
diff --git a/bin/tests/test_main.cpp b/bin/tests/test_main.cpp
index 363aede96e..1f7f2d7dda 100644
--- a/bin/tests/test_main.cpp
+++ b/bin/tests/test_main.cpp
@@ -37,13 +37,10 @@
#include "test_gui.h"
#include "test_render.h"
#include "test_sound.h"
-#include "test_misc.h"
#include "test_physics.h"
#include "test_physics_2d.h"
-#include "test_python.h"
+
#include "test_io.h"
-#include "test_particles.h"
-#include "test_detailer.h"
#include "test_shader_lang.h"
#include "test_gdscript.h"
#include "test_image.h"
@@ -56,7 +53,6 @@ const char ** tests_get_names() {
"containers",
"math",
"render",
- "particles",
"multimesh",
"gui",
"io",
@@ -96,11 +92,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
return TestPhysics2D::test();
}
- if (p_test=="misc") {
-
- return TestMisc::test();
- }
-
if (p_test=="render") {
return TestRender::test();
@@ -123,16 +114,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
return TestIO::test();
}
- if (p_test=="particles") {
-
- return TestParticles::test();
- }
-
- if (p_test=="multimesh") {
-
- return TestMultiMesh::test();
- }
-
if (p_test=="shaderlang") {
return TestShaderLang::test();
@@ -163,19 +144,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
return TestImage::test();
}
- if (p_test=="detailer") {
-
- return TestMultiMesh::test();
- }
-
-#ifdef PYTHON_ENABLED
-
- if (p_test=="python") {
-
- return TestPython::test();
- }
-#endif
-
return NULL;
}
diff --git a/bin/tests/test_misc.cpp b/bin/tests/test_misc.cpp
deleted file mode 100644
index 9d7adc3573..0000000000
--- a/bin/tests/test_misc.cpp
+++ /dev/null
@@ -1,499 +0,0 @@
-/*************************************************************************/
-/* test_misc.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "test_misc.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
-#include "math_funcs.h"
-#include "print_string.h"
-
-
-namespace TestMisc {
-
-struct ConvexTestResult
-{
-
- Vector3 edgeA[2];
- Vector3 edgeB[2];
- bool valid;
- Vector3 contactA;
- Vector3 contactB;
- Vector3 contactNormal;
- float depth;
-
- /*
- Vector3 contactA;
- Vector3 contactB;
- Vector3 contactNormal;
- Vector3 contactX;
- Vector3 contactY;
- Vector3 edgeA[2];
- Vector3 edgeB[2];
- float depth;
- bool valid;
- bool isEdgeEdge;
- bool needTransform;
- neBool ComputerEdgeContactPoint(ConvexTestResult & res);
- neBool ComputerEdgeContactPoint2(float & au, float & bu);
- void Reverse()
- {
- neSwap(contactA, contactB);
- contactNormal *= -1.0f;
- }*/
- bool ComputerEdgeContactPoint2(float & au, float & bu);
-};
-
-
-
-bool ConvexTestResult::ComputerEdgeContactPoint2(float & au, float & bu)
-{
- float d1343, d4321, d1321, d4343, d2121;
- float numer, denom;
-
- Vector3 p13;
- Vector3 p43;
- Vector3 p21;
- Vector3 diff;
-
- p13 = (edgeA[0]) - (edgeB[0]);
- p43 = (edgeB[1]) - (edgeB[0]);
-
- if ( p43.length_squared() < CMP_EPSILON2 )
- {
- valid = false;
- goto ComputerEdgeContactPoint2_Exit;
- }
-
- p21 = (edgeA[1]) - (edgeA[0]);
-
- if ( p21.length_squared()<CMP_EPSILON2 )
- {
- valid = false;
- goto ComputerEdgeContactPoint2_Exit;
- }
-
- d1343 = p13.dot(p43);
- d4321 = p43.dot(p21);
- d1321 = p13.dot(p21);
- d4343 = p43.dot(p43);
- d2121 = p21.dot(p21);
-
- denom = d2121 * d4343 - d4321 * d4321;
-
- if (ABS(denom) < CMP_EPSILON)
- {
- valid = false;
-
- goto ComputerEdgeContactPoint2_Exit;
- }
-
- numer = d1343 * d4321 - d1321 * d4343;
- au = numer / denom;
- bu = (d1343 + d4321 * (au)) / d4343;
-
- if (au < 0.0f || au >= 1.0f)
- {
- valid = false;
- }
- else if (bu < 0.0f || bu >= 1.0f)
- {
- valid = false;
- }
- else
- {
- valid = true;
- }
- {
- Vector3 tmpv;
-
- tmpv = p21 * au;
- contactA = (edgeA[0]) + tmpv;
-
- tmpv = p43 * bu;
- contactB = (edgeB[0]) + tmpv;
- }
-
- diff = contactA - contactB;
-
- depth = Math::sqrt(diff.dot(diff));
-
- return true;
-
-ComputerEdgeContactPoint2_Exit:
-
- return false;
-}
-
-struct neCollisionResult {
-
- float depth;
- bool penetrate;
- Matrix3 collisionFrame;
- Vector3 contactA;
- Vector3 contactB;
-};
-
-
-struct TConvex {
-
- float radius;
- float half_height;
- float CylinderRadius() const { return radius; }
- float CylinderHalfHeight() const { return half_height; }
-};
-
-float GetDistanceFromLine2(Vector3 v, Vector3 & project, const Vector3 & pointA, const Vector3 & pointB)
-{
- Vector3 ba = pointB - pointA;
-
- float len = ba.length();
-
- if (len<CMP_EPSILON)
- ba=Vector3();
- else
- ba *= 1.0f / len;
-
- Vector3 pa = v - pointA;
-
- float k = pa.dot(ba);
-
- project = pointA + ba * k;
-
- Vector3 diff = v - project;
-
- return diff.length();
-}
-
-void TestCylinderVertEdge(neCollisionResult & result, Vector3 & edgeA1, Vector3 & edgeA2, Vector3 & vertB,
- TConvex & cA, TConvex & cB, Transform & transA, Transform & transB, bool flip)
-{
- Vector3 project;
-
- float dist = GetDistanceFromLine2(vertB,project, edgeA1, edgeA2);
-
- float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist;
-
- if (depth <= 0.0f)
- return;
-
- if (depth <= result.depth)
- return;
-
- result.penetrate = true;
-
- result.depth = depth;
-
- if (!flip)
- {
- result.collisionFrame.set_axis(2,(project - vertB).normalized());
-
- result.contactA = project - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
-
- result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
- }
- else
- {
-
- result.collisionFrame.set_axis(2,(vertB - project).normalized());
-
- result.contactA = vertB - result.collisionFrame.get_axis(2) * cB.CylinderRadius();
-
- result.contactB = project + result.collisionFrame.get_axis(2) * cA.CylinderRadius();
- }
-}
-
-void TestCylinderVertVert(neCollisionResult & result, Vector3 & vertA, Vector3 & vertB,
- TConvex & cA, TConvex & cB, Transform & transA, Transform & transB)
-{
- Vector3 diff = vertA - vertB;
-
- float dist = diff.length();
-
- float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist;
-
- if (depth <= 0.0f)
- return;
-
- if (depth <= result.depth)
- return;
-
- result.penetrate = true;
-
- result.depth = depth;
-
- result.collisionFrame.set_axis(2, diff * (1.0f / dist));
-
- result.contactA = vertA - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
-
- result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
-}
-
-void Cylinder2CylinderTest(neCollisionResult & result, TConvex & cA, Transform & transA, TConvex & cB, Transform & transB)
-{
- result.penetrate = false;
-
- Vector3 dir = transA.basis.get_axis(1).cross(transB.basis.get_axis(1));
-
- float len = dir.length();
-
-// bool isParallel = len<CMP_EPSILON;
-
-// int doVertCheck = 0;
-
- ConvexTestResult cr;
-
- cr.edgeA[0] = transA.origin + transA.basis.get_axis(1) * cA.CylinderHalfHeight();
- cr.edgeA[1] = transA.origin - transA.basis.get_axis(1) * cA.CylinderHalfHeight();
- cr.edgeB[0] = transB.origin + transB.basis.get_axis(1) * cB.CylinderHalfHeight();
- cr.edgeB[1] = transB.origin - transB.basis.get_axis(1) * cB.CylinderHalfHeight();
-
-// float dot = transA.basis.get_axis(1).dot(transB.basis.get_axis(1));
-
- if (len>CMP_EPSILON)
- {
- float au, bu;
-
- cr.ComputerEdgeContactPoint2(au, bu);
-
- if (cr.valid)
- {
- float depth = cA.CylinderRadius() + cB.CylinderRadius() - cr.depth;
-
- if (depth <= 0.0f)
- return;
-
- result.depth = depth;
-
- result.penetrate = true;
-
- result.collisionFrame.set_axis(2, (cr.contactA - cr.contactB)*(1.0f / cr.depth));
-
- result.contactA = cr.contactA - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
-
- result.contactB = cr.contactB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
-
- return;
- }
- }
- result.depth = -1.0e6f;
-
- int i;
-
- for (i = 0; i < 2; i++)
- {
- //project onto edge b
-
- Vector3 diff = cr.edgeA[i] - cr.edgeB[1];
-
- float dot = diff.dot(transB.basis.get_axis(1));
-
- if (dot < 0.0f)
- {
- TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[1], cA, cB, transA, transB);
- }
- else if (dot > (2.0f * cB.CylinderHalfHeight()))
- {
- TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[0], cA, cB, transA, transB);
- }
- else
- {
- TestCylinderVertEdge(result, cr.edgeB[0], cr.edgeB[1], cr.edgeA[i], cB, cA, transB, transA, true);
- }
- }
- for (i = 0; i < 2; i++)
- {
- //project onto edge b
-
- Vector3 diff = cr.edgeB[i] - cr.edgeA[1];
-
- float dot = diff.dot(transA.basis.get_axis(1));
-
- if (dot < 0.0f)
- {
- TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[1], cA, cB, transA, transB);
- }
- else if (dot > (2.0f * cB.CylinderHalfHeight()))
- {
- TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[0], cA, cB, transA, transB);
- }
- else
- {
- TestCylinderVertEdge(result, cr.edgeA[0], cr.edgeA[1], cr.edgeB[i], cA, cB, transA, transB, false);
- }
- }
-}
-
-
-class TestMainLoop : public MainLoop {
-
- RID meshA;
- RID meshB;
- RID poly;
- RID instance;
- RID camera;
- RID viewport;
- RID boxA;
- RID boxB;
- RID scenario;
-
- Transform rot_a;
- Transform rot_b;
-
- bool quit;
-public:
- virtual void input_event(const InputEvent& p_event) {
-
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) {
-
- rot_b.origin.y+=-p_event.mouse_motion.relative_y/100.0;
- rot_b.origin.x+=p_event.mouse_motion.relative_x/100.0;
- }
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_MIDDLE) {
-
- //rot_b.origin.x+=-p_event.mouse_motion.relative_y/100.0;
- rot_b.origin.z+=p_event.mouse_motion.relative_x/100.0;
- }
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_RIGHT) {
-
- float rot_x=-p_event.mouse_motion.relative_y/100.0;
- float rot_y=p_event.mouse_motion.relative_x/100.0;
- rot_b.basis = rot_b.basis * Matrix3(Vector3(1,0,0),rot_x) * Matrix3(Vector3(0,1,0),rot_y);
- }
-
- }
- virtual void request_quit() {
-
- quit=true;
- }
- virtual void init() {
-
- VisualServer *vs=VisualServer::get_singleton();
-
- camera = vs->camera_create();
-
- viewport = vs->viewport_create();
- vs->viewport_attach_to_screen(viewport);
- vs->viewport_attach_camera( viewport, camera );
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,3 ) ) );
-
- /* CONVEX SHAPE */
-
- DVector<Plane> cylinder_planes = Geometry::build_cylinder_planes(0.5,2,9,Vector3::AXIS_Y);
- RID cylinder_material = vs->fixed_material_create();
- vs->fixed_material_set_param( cylinder_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8,0.2,0.9));
- vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_ONTOP,true);
- //vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_WIREFRAME,true);
- vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_DOUBLE_SIDED,true);
- vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_UNSHADED,true);
-
- RID cylinder_mesh = vs->mesh_create();
- Geometry::MeshData cylinder_data = Geometry::build_convex_mesh(cylinder_planes);
- vs->mesh_add_surface_from_mesh_data(cylinder_mesh,cylinder_data);
- vs->mesh_surface_set_material( cylinder_mesh, 0, cylinder_material );
-
- meshA=vs->instance_create2(cylinder_mesh,scenario);
- meshB=vs->instance_create2(cylinder_mesh,scenario);
- boxA=vs->instance_create2(vs->get_test_cube(),scenario);
- boxB=vs->instance_create2(vs->get_test_cube(),scenario);
-
- /*
- RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
- vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 );
- vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ATTENUATION, 1 );
- vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 );
- light = vs->instance_create2( lightaux );
- */
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
- //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
- //vs->light_set_shadow( lightaux, true );
- vs->instance_create2( lightaux,scenario );
-
- //rot_a=Transform(Matrix3(Vector3(1,0,0),Math_PI/2.0),Vector3());
- rot_b=Transform(Matrix3(),Vector3(2,0,0));
-
- //rot_x=0;
- //rot_y=0;
- quit=false;
- }
- virtual bool idle(float p_time) {
-
- VisualServer *vs=VisualServer::get_singleton();
-
- vs->instance_set_transform(meshA,rot_a);
- vs->instance_set_transform(meshB,rot_b);
-
-
- neCollisionResult res;
- TConvex a;
- a.radius=0.5;
- a.half_height=1;
- Cylinder2CylinderTest(res,a,rot_a,a,rot_b);
- if (res.penetrate) {
-
- Matrix3 scale;
- scale.scale(Vector3(0.1,0.1,0.1));
- vs->instance_set_transform(boxA,Transform(scale,res.contactA));
- vs->instance_set_transform(boxB,Transform(scale,res.contactB));
- print_line("depth: "+rtos(res.depth));
- } else {
-
- Matrix3 scale;
- scale.scale(Vector3());
- vs->instance_set_transform(boxA,Transform(scale,res.contactA));
- vs->instance_set_transform(boxB,Transform(scale,res.contactB));
-
- }
- print_line("collided: "+itos(res.penetrate));
-
- return false;
- }
-
-
- virtual bool iteration(float p_time) {
-
-
-
- return quit;
- }
- virtual void finish() {
-
- }
-
-};
-
-
-MainLoop* test() {
-
- return memnew( TestMainLoop );
-
-}
-
-}
-
-
-
diff --git a/bin/tests/test_misc.h b/bin/tests/test_misc.h
deleted file mode 100644
index 55608f6a0e..0000000000
--- a/bin/tests/test_misc.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*************************************************************************/
-/* test_misc.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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 TEST_MISC_H
-#define TEST_MISC_H
-
-#include "os/main_loop.h"
-
-namespace TestMisc {
-
-MainLoop* test();
-
-}
-
-#endif
diff --git a/bin/tests/test_particles.cpp b/bin/tests/test_particles.cpp
deleted file mode 100644
index 23a4b9e635..0000000000
--- a/bin/tests/test_particles.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*************************************************************************/
-/* test_particles.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "test_particles.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
-#include "math_funcs.h"
-#include "print_string.h"
-
-namespace TestParticles {
-
-
-class TestMainLoop : public MainLoop {
-
- RID particles;
- RID instance;
- RID camera;
- RID viewport;
- RID light;
- RID scenario;
-
- struct InstanceInfo {
-
- RID instance;
- Transform base;
- Vector3 rot_axis;
- };
-
- List<InstanceInfo> instances;
-
- float ofs;
- bool quit;
-public:
- virtual void input_event(const InputEvent& p_event) {
-
-
- }
- virtual void request_quit() {
-
- quit=true;
- }
- virtual void init() {
-
- VisualServer *vs=VisualServer::get_singleton();
- particles = vs->particles_create();
- vs->particles_set_amount(particles,1000);
-
- instance = vs->instance_create2(particles,scenario);
-
-
- camera = vs->camera_create();
-
-// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
- viewport = vs->viewport_create();
- vs->viewport_attach_camera( viewport, camera );
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,20 ) ) );
- /*
- RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
- vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 );
- vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ATTENUATION, 1 );
- vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 );
- light = vs->instance_create2( lightaux );
- */
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
- // vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
- light = vs->instance_create2( lightaux, scenario );
-
- ofs=0;
- quit=false;
- }
- virtual bool idle(float p_time) {
- return false;
- }
-
-
- virtual bool iteration(float p_time) {
-
-// VisualServer *vs=VisualServer::get_singleton();
-
- ofs+=p_time;
- return quit;
- }
- virtual void finish() {
-
- }
-
-};
-
-
-MainLoop* test() {
-
- return memnew( TestMainLoop );
-
-}
-
-}
diff --git a/bin/tests/test_particles.h b/bin/tests/test_particles.h
deleted file mode 100644
index e95637a4e6..0000000000
--- a/bin/tests/test_particles.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*************************************************************************/
-/* test_particles.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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 TEST_PARTICLES_H
-#define TEST_PARTICLES_H
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-#include "os/main_loop.h"
-
-namespace TestParticles {
-
-MainLoop* test();
-
-}
-
-#endif
diff --git a/bin/tests/test_physics.cpp b/bin/tests/test_physics.cpp
index f202d0dda1..3a8ca65734 100644
--- a/bin/tests/test_physics.cpp
+++ b/bin/tests/test_physics.cpp
@@ -138,10 +138,6 @@ protected:
/* SPHERE SHAPE */
RID sphere_mesh = vs->make_sphere_mesh(10,20,0.5);
- RID sphere_material = vs->fixed_material_create();
- //vs->material_set_flag( sphere_material, VisualServer::MATERIAL_FLAG_WIREFRAME, true );
- vs->fixed_material_set_param( sphere_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.7,0.8,3.0) );
- vs->mesh_surface_set_material( sphere_mesh, 0, sphere_material );
type_mesh_map[PhysicsServer::SHAPE_SPHERE]=sphere_mesh;
RID sphere_shape=ps->shape_create(PhysicsServer::SHAPE_SPHERE);
@@ -151,12 +147,9 @@ protected:
/* BOX SHAPE */
DVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5,0.5,0.5));
- RID box_material = vs->fixed_material_create();
- vs->fixed_material_set_param( box_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0,0.2,0.2) );
RID box_mesh = vs->mesh_create();
Geometry::MeshData box_data = Geometry::build_convex_mesh(box_planes);
vs->mesh_add_surface_from_mesh_data(box_mesh,box_data);
- vs->mesh_surface_set_material( box_mesh, 0, box_material );
type_mesh_map[PhysicsServer::SHAPE_BOX]=box_mesh;
RID box_shape=ps->shape_create(PhysicsServer::SHAPE_BOX);
@@ -167,13 +160,11 @@ protected:
/* CAPSULE SHAPE */
DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,0.7,12,Vector3::AXIS_Z);
- RID capsule_material = vs->fixed_material_create();
- vs->fixed_material_set_param( capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.3,0.4,1.0) );
RID capsule_mesh = vs->mesh_create();
Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes);
vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data);
- vs->mesh_surface_set_material( capsule_mesh, 0, capsule_material );
+
type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh;
RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
@@ -186,14 +177,12 @@ protected:
/* CONVEX SHAPE */
DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,5,Vector3::AXIS_Z);
- RID convex_material = vs->fixed_material_create();
- vs->fixed_material_set_param( convex_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8,0.2,0.9));
RID convex_mesh = vs->mesh_create();
Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes);
QuickHull::build(convex_data.vertices,convex_data);
vs->mesh_add_surface_from_mesh_data(convex_mesh,convex_data);
- vs->mesh_surface_set_material( convex_mesh, 0, convex_material );
+
type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_mesh;
RID convex_shape=ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON);
@@ -223,11 +212,9 @@ protected:
d.resize(VS::ARRAY_MAX);
d[VS::ARRAY_VERTEX]=p_faces;
d[VS::ARRAY_NORMAL]=normals;
- vs->mesh_add_surface(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d );
- RID trimesh_mat = vs->fixed_material_create();
- vs->fixed_material_set_param( trimesh_mat, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0,0.5,0.8));
+ vs->mesh_add_surface_from_arrays(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d );
//vs->material_set_flag( trimesh_mat, VisualServer::MATERIAL_FLAG_UNSHADED,true);
- vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_mat );
+
RID triins = vs->instance_create2(trimesh_mesh,scenario);
@@ -464,7 +451,7 @@ public:
}
virtual bool iteration(float p_time) {
- if (mover) {
+ if (mover.is_valid()) {
static float joy_speed = 10;
PhysicsServer * ps = PhysicsServer::get_singleton();
Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM);
@@ -548,15 +535,10 @@ public:
DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,1,12,5,Vector3::AXIS_Y);
- RID capsule_material = vs->fixed_material_create();
-
- vs->fixed_material_set_param( capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1,1,1) );
-
RID capsule_mesh = vs->mesh_create();
Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes);
vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data);
- vs->mesh_surface_set_material( capsule_mesh, 0, capsule_material );
type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh;
RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
diff --git a/bin/tests/test_physics_2d.cpp b/bin/tests/test_physics_2d.cpp
index 845e20b6c3..f369c361d3 100644
--- a/bin/tests/test_physics_2d.cpp
+++ b/bin/tests/test_physics_2d.cpp
@@ -85,7 +85,7 @@ class TestPhysics2DMainLoop : public MainLoop {
}
}
- Image image(32,2,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32,2,0,Image::FORMAT_LA8,pixels);
body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image);
@@ -113,7 +113,7 @@ class TestPhysics2DMainLoop : public MainLoop {
}
}
- Image image(32,32,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32,32,0,Image::FORMAT_LA8,pixels);
body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image);
@@ -141,7 +141,7 @@ class TestPhysics2DMainLoop : public MainLoop {
}
}
- Image image(32,32,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32,32,0,Image::FORMAT_LA8,pixels);
body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image);
@@ -173,7 +173,7 @@ class TestPhysics2DMainLoop : public MainLoop {
}
}
- Image image(32,64,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32,64,0,Image::FORMAT_LA8,pixels);
body_shape_data[Physics2DServer::SHAPE_CAPSULE].image=vs->texture_create_from_image(image);
@@ -381,7 +381,7 @@ public:
RID vp = vs->viewport_create();
canvas = vs->canvas_create();
vs->viewport_attach_canvas(vp,canvas);
- vs->viewport_attach_to_screen(vp);
+ vs->viewport_attach_to_screen(vp,Rect2(Vector2(),OS::get_singleton()->get_window_size()));
Matrix32 smaller;
//smaller.scale(Vector2(0.6,0.6));
//smaller.elements[2]=Vector2(100,0);
diff --git a/bin/tests/test_python.cpp b/bin/tests/test_python.cpp
deleted file mode 100644
index f4a3d7a3a2..0000000000
--- a/bin/tests/test_python.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*************************************************************************/
-/* test_python.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "test_python.h"
-
-#ifdef PYTHON_ENABLED
-
-#include "Python.h"
-#include "print_string.h"
-
-namespace TestPython {
-
-void test() {
-
- print_line("testing python");
- PyRun_SimpleString("import engine\n");
- PyRun_SimpleString("def test(self):\n\tprint(\"noway\")\n");
- PyRun_SimpleString("a=engine.ObjectPtr()\n");
- PyRun_SimpleString("a.noway(22,'hello')\n");
- PyRun_SimpleString("a.normalize()\n");
- PyRun_SimpleString("class Moch(engine.ObjectPtr):\n\tdef mooch(self):\n\t\tprint('muchi')\n");
- PyRun_SimpleString("b=Moch();\n");
- PyRun_SimpleString("b.mooch();\n");
- PyRun_SimpleString("b.meis();\n");
-
-
-}
-
-}
-
-#endif
diff --git a/bin/tests/test_python.h b/bin/tests/test_python.h
deleted file mode 100644
index 77e9603fe2..0000000000
--- a/bin/tests/test_python.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*************************************************************************/
-/* test_python.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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 TEST_PYTHON_H
-#define TEST_PYTHON_H
-
-#ifdef PYTHON_ENABLED
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-namespace TestPython {
-
-void test();
-
-}
-
-#endif
-#endif
diff --git a/bin/tests/test_render.cpp b/bin/tests/test_render.cpp
index 9c3a287afa..7bf833c8a7 100644
--- a/bin/tests/test_render.cpp
+++ b/bin/tests/test_render.cpp
@@ -173,7 +173,7 @@ public:
// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
viewport = vs->viewport_create();
- vs->viewport_attach_to_screen(viewport);
+ vs->viewport_attach_to_screen(viewport,Rect2(Vector2(),OS::get_singleton()->get_window_size()));
vs->viewport_attach_camera( viewport, camera );
vs->viewport_set_scenario( viewport, scenario );
vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,3,30 ) ) );
@@ -192,7 +192,7 @@ public:
//*
lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
- vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0,1.0,1.0) );
+ vs->light_set_color( lightaux, Color(1.0,1.0,1.0) );
//vs->light_set_shadow( lightaux, true );
light = vs->instance_create2( lightaux, scenario );
Transform lla;
@@ -205,8 +205,8 @@ public:
//*
lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
// vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) );
- vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0,1.0,0.0) );
- vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RADIUS, 4 );
+ vs->light_set_color( lightaux, Color(1.0,1.0,0.0) );
+ vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RANGE, 4 );
vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8 );
//vs->light_set_shadow( lightaux, true );
//light = vs->instance_create( lightaux );
diff --git a/bin/tests/test_shader_lang.cpp b/bin/tests/test_shader_lang.cpp
index 9c0075c47d..6c8132122c 100644
--- a/bin/tests/test_shader_lang.cpp
+++ b/bin/tests/test_shader_lang.cpp
@@ -37,9 +37,9 @@
#include "scene/gui/text_edit.h"
#include "print_string.h"
#include "servers/visual/shader_language.h"
-#include "drivers/gles2/shader_compiler_gles2.h"
-
+//#include "drivers/gles2/shader_compiler_gles2.h"
+#if 0
typedef ShaderLanguage SL;
namespace TestShaderLang {
@@ -323,7 +323,7 @@ MainLoop* test() {
if (!err) {
print_line(rcode);
}
-
+#if 0
ShaderCompilerGLES2 comp;
String codeline,globalsline;
SL::VarInfo vi;
@@ -333,6 +333,18 @@ MainLoop* test() {
ShaderCompilerGLES2::Flags fl;
comp.compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,codeline,globalsline,fl);
+#endif
+ return NULL;
+}
+
+}
+#endif
+
+typedef ShaderLanguage SL;
+
+namespace TestShaderLang {
+
+MainLoop* test() {
return NULL;
}
diff --git a/core/globals.cpp b/core/globals.cpp
index b822f52f15..6fe53c7412 100644
--- a/core/globals.cpp
+++ b/core/globals.cpp
@@ -657,37 +657,37 @@ static Variant _decode_variant(const String& p_string) {
String format=params[0].strip_edges();
Image::Format imgformat;
-
+/*
if (format=="grayscale") {
- imgformat=Image::FORMAT_GRAYSCALE;
+ imgformat=Image::FORMAT_L8;
} else if (format=="intensity") {
imgformat=Image::FORMAT_INTENSITY;
} else if (format=="grayscale_alpha") {
- imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
+ imgformat=Image::FORMAT_LA8;
} else if (format=="rgb") {
- imgformat=Image::FORMAT_RGB;
+ imgformat=Image::FORMAT_RGB8;
} else if (format=="rgba") {
- imgformat=Image::FORMAT_RGBA;
+ imgformat=Image::FORMAT_RGBA8;
} else if (format=="indexed") {
imgformat=Image::FORMAT_INDEXED;
} else if (format=="indexed_alpha") {
imgformat=Image::FORMAT_INDEXED_ALPHA;
} else if (format=="bc1") {
- imgformat=Image::FORMAT_BC1;
+ imgformat=Image::FORMAT_DXT1;
} else if (format=="bc2") {
- imgformat=Image::FORMAT_BC2;
+ imgformat=Image::FORMAT_DXT3;
} else if (format=="bc3") {
- imgformat=Image::FORMAT_BC3;
+ imgformat=Image::FORMAT_DXT5;
} else if (format=="bc4") {
- imgformat=Image::FORMAT_BC4;
+ imgformat=Image::FORMAT_ATI1;
} else if (format=="bc5") {
- imgformat=Image::FORMAT_BC5;
+ imgformat=Image::FORMAT_ATI2;
} else if (format=="custom") {
imgformat=Image::FORMAT_CUSTOM;
} else {
ERR_FAIL_V( Image() );
- }
+ }*/
int mipmaps=params[1].to_int();
int w=params[2].to_int();
@@ -974,26 +974,30 @@ static String _encode_variant(const Variant& p_variant) {
if (!img.empty()) {
String format;
+
+ /*
switch(img.get_format()) {
- case Image::FORMAT_GRAYSCALE: format="grayscale"; break;
+ case Image::FORMAT_L8: format="grayscale"; break;
case Image::FORMAT_INTENSITY: format="intensity"; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: format="grayscale_alpha"; break;
- case Image::FORMAT_RGB: format="rgb"; break;
- case Image::FORMAT_RGBA: format="rgba"; break;
+ case Image::FORMAT_LA8: format="grayscale_alpha"; break;
+ case Image::FORMAT_RGB8: format="rgb"; break;
+ case Image::FORMAT_RGBA8: format="rgba"; break;
case Image::FORMAT_INDEXED : format="indexed"; break;
case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break;
- case Image::FORMAT_BC1: format="bc1"; break;
- case Image::FORMAT_BC2: format="bc2"; break;
- case Image::FORMAT_BC3: format="bc3"; break;
- case Image::FORMAT_BC4: format="bc4"; break;
- case Image::FORMAT_BC5: format="bc5"; break;
+ case Image::FORMAT_DXT1: format="bc1"; break;
+ case Image::FORMAT_DXT3: format="bc2"; break;
+ case Image::FORMAT_DXT5: format="bc3"; break;
+ case Image::FORMAT_ATI1: format="bc4"; break;
+ case Image::FORMAT_ATI2: format="bc5"; break;
case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break;
default: {}
}
+ */
+
str+=format+", ";
- str+=itos(img.get_mipmaps())+", ";
+ str+=itos(img.has_mipmaps())+", ";
str+=itos(img.get_width())+", ";
str+=itos(img.get_height())+", ";
DVector<uint8_t> data = img.get_data();
@@ -1399,6 +1403,7 @@ void Globals::set_custom_property_info(const String& p_prop,const PropertyInfo&
ERR_FAIL_COND(!props.has(p_prop));
custom_prop_info[p_prop]=p_info;
+ custom_prop_info[p_prop].name=p_prop;
}
diff --git a/core/image.cpp b/core/image.cpp
index 90051d7d0d..73a2ab8013 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -36,86 +36,186 @@
const char* Image::format_names[Image::FORMAT_MAX]={
- "Grayscale",
- "Intensity",
- "GrayscaleAlpha",
- "RGB",
- "RGBA",
- "Indexed",
- "IndexedAlpha",
- "YUV422",
- "YUV444",
- "BC1",
- "BC2",
- "BC3",
- "BC4",
- "BC5",
- "PVRTC2",
- "PVRTC2Alpha",
+ "Lum8", //luminance
+ "LumAlpha8", //luminance-alpha
+ "Red8",
+ "RedGreen",
+ "RGB8",
+ "RGBA8",
+ "RGB565", //16 bit
+ "RGBA4444",
+ "RGBA5551",
+ "RFloat", //float
+ "RGFloat",
+ "RGBFloat",
+ "RGBAFloat",
+ "RHalf", //half float
+ "RGHalf",
+ "RGBHalf",
+ "RGBAHalf",
+ "DXT1", //s3tc
+ "DXT3",
+ "DXT5",
+ "ATI1",
+ "ATI2",
+ "BPTC_RGBA",
+ "BPTC_RGBF",
+ "BPTC_RGBFU",
+ "PVRTC2", //pvrtc
+ "PVRTC2A",
"PVRTC4",
- "PVRTC4Alpha",
- "ETC",
- "ATC",
- "ATCAlphaExp",
- "ATCAlphaInterp",
+ "PVRTC4A",
+ "ETC", //etc1
+ "ETC2_R11", //etc2
+ "ETC2_R11S", //signed", NOT srgb.
+ "ETC2_RG11",
+ "ETC2_RG11S",
+ "ETC2_RGB8",
+ "ETC2_RGBA8",
+ "ETC2_RGB8A1",
};
SavePNGFunc Image::save_png_func = NULL;
-void Image::_put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data) {
- _put_pixelw(p_x,p_y,width,p_color,p_data);
+void Image::_put_pixelb(int p_x,int p_y, uint32_t p_pixelsize,uint8_t *p_dst,const uint8_t *p_src) {
+
+ uint32_t ofs=(p_y*width+p_x)*p_pixelsize;
+
+ for(uint32_t i=0;i<p_pixelsize;i++) {
+ p_dst[ofs+i]=p_src[i];
+ }
}
-void Image::_put_pixelw(int p_x,int p_y, int p_width, const BColor& p_color, unsigned char *p_data) {
+void Image::_get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_src,uint8_t *p_dst) {
+ uint32_t ofs=(p_y*width+p_x)*p_pixelsize;
- int ofs=p_y*p_width+p_x;
+ for(uint32_t i=0;i<p_pixelsize;i++) {
+ p_dst[ofs]=p_src[ofs+i];
+ }
- switch(format) {
- case FORMAT_GRAYSCALE: {
+}
- p_data[ofs]=p_color.gray();
- } break;
- case FORMAT_INTENSITY: {
- p_data[ofs]=p_color.a;
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
+int Image::get_format_pixel_size(Format p_format) {
+
+ switch(p_format) {
+ case FORMAT_L8: return 1; //luminance
+ case FORMAT_LA8: return 2; //luminance-alpha
+ case FORMAT_R8: return 1;
+ case FORMAT_RG8: return 2;
+ case FORMAT_RGB8: return 3;
+ case FORMAT_RGBA8: return 4;
+ case FORMAT_RGB565: return 2; //16 bit
+ case FORMAT_RGBA4444: return 2;
+ case FORMAT_RGBA5551: return 2;
+ case FORMAT_RF: return 4; //float
+ case FORMAT_RGF: return 8;
+ case FORMAT_RGBF: return 12;
+ case FORMAT_RGBAF: return 16;
+ case FORMAT_RH: return 2; //half float
+ case FORMAT_RGH: return 4;
+ case FORMAT_RGBH: return 8;
+ case FORMAT_RGBAH: return 12;
+ case FORMAT_DXT1: return 1; //s3tc bc1
+ case FORMAT_DXT3: return 1; //bc2
+ case FORMAT_DXT5: return 1; //bc3
+ case FORMAT_ATI1: return 1; //bc4
+ case FORMAT_ATI2: return 1; //bc5
+ case FORMAT_BPTC_RGBA: return 1; //btpc bc6h
+ case FORMAT_BPTC_RGBF: return 1; //float /
+ case FORMAT_BPTC_RGBFU: return 1; //unsigned float
+ case FORMAT_PVRTC2: return 1; //pvrtc
+ case FORMAT_PVRTC2A: return 1;
+ case FORMAT_PVRTC4: return 1;
+ case FORMAT_PVRTC4A: return 1;
+ case FORMAT_ETC: return 1; //etc1
+ case FORMAT_ETC2_R11: return 1; //etc2
+ case FORMAT_ETC2_R11S: return 1; //signed: return 1; NOT srgb.
+ case FORMAT_ETC2_RG11: return 1;
+ case FORMAT_ETC2_RG11S: return 1;
+ case FORMAT_ETC2_RGB8: return 1;
+ case FORMAT_ETC2_RGBA8: return 1;
+ case FORMAT_ETC2_RGB8A1: return 1;
+ case FORMAT_MAX: {}
- p_data[ofs*2]=p_color.gray();
- p_data[ofs*2+1]=p_color.a;
+ }
+ return 0;
+}
+
+void Image::get_format_min_pixel_size(Format p_format,int &r_w, int &r_h) {
+
+
+ switch(p_format) {
+ case FORMAT_DXT1: //s3tc bc1
+ case FORMAT_DXT3: //bc2
+ case FORMAT_DXT5: //bc3
+ case FORMAT_ATI1: //bc4
+ case FORMAT_ATI2: { //bc5 case case FORMAT_DXT1:
+
+ r_w=4;
+ r_h=4;
} break;
- case FORMAT_RGB: {
+ case FORMAT_PVRTC2:
+ case FORMAT_PVRTC2A: {
- p_data[ofs*3+0]=p_color.r;
- p_data[ofs*3+1]=p_color.g;
- p_data[ofs*3+2]=p_color.b;
+ r_w=16;
+ r_h=8;
+ } break;
+ case FORMAT_PVRTC4A:
+ case FORMAT_PVRTC4: {
+ r_w=8;
+ r_h=8;
} break;
- case FORMAT_RGBA: {
+ case FORMAT_ETC: {
- p_data[ofs*4+0]=p_color.r;
- p_data[ofs*4+1]=p_color.g;
- p_data[ofs*4+2]=p_color.b;
- p_data[ofs*4+3]=p_color.a;
+ r_w=4;
+ r_h=4;
+ } break;
+ case FORMAT_BPTC_RGBA:
+ case FORMAT_BPTC_RGBF:
+ case FORMAT_BPTC_RGBFU: {
+ r_w=4;
+ r_h=4;
} break;
- case FORMAT_INDEXED:
- case FORMAT_INDEXED_ALPHA: {
+ case FORMAT_ETC2_R11: //etc2
+ case FORMAT_ETC2_R11S: //signed: NOT srgb.
+ case FORMAT_ETC2_RG11:
+ case FORMAT_ETC2_RG11S:
+ case FORMAT_ETC2_RGB8:
+ case FORMAT_ETC2_RGBA8:
+ case FORMAT_ETC2_RGB8A1: {
+
+ r_w=4;
+ r_h=4;
- ERR_FAIL();
} break;
- default: {};
+ default: {
+ r_w=1;
+ r_h=1;
+ } break;
}
}
+int Image::get_format_pixel_rshift(Format p_format) {
+
+ if (p_format==FORMAT_DXT1 || p_format==FORMAT_ATI1 || p_format==FORMAT_PVRTC4 || p_format==FORMAT_PVRTC4A || p_format==FORMAT_ETC || p_format==FORMAT_ETC2_R11 || p_format==FORMAT_ETC2_R11S || p_format==FORMAT_ETC2_RGB8 || p_format==FORMAT_ETC2_RGB8A1)
+ return 1;
+ else if (p_format==FORMAT_PVRTC2 || p_format==FORMAT_PVRTC2A)
+ return 2;
+ else
+ return 0;
+}
+
void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width,int &r_height) const {
@@ -126,7 +226,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width
int pixel_size = get_format_pixel_size(format);
int pixel_rshift = get_format_pixel_rshift(format);
int minw,minh;
- _get_format_min_data_size(format,minw,minh);
+ get_format_min_pixel_size(format,minw,minh);
for(int i=0;i<p_mipmap;i++) {
int s = w*h;
@@ -173,191 +273,76 @@ void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap,int &r_ofs, int &
}
-void Image::put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap){
-
- ERR_FAIL_INDEX(p_mipmap,mipmaps+1);
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX(p_x,w);
- ERR_FAIL_INDEX(p_y,h);
-
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *data_ptr=wp.ptr();
-
- _put_pixelw(p_x,p_y,w,BColor(p_color.r*255,p_color.g*255,p_color.b*255,p_color.a*255),&data_ptr[ofs]);
+int Image::get_width() const {
+ return width;
}
+int Image::get_height() const{
-Image::BColor Image::_get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const{
-
- return _get_pixelw(p_x,p_y,width,p_data,p_data_size);
+ return height;
}
-Image::BColor Image::_get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const{
- int ofs=p_y*p_width+p_x;
- BColor result(0,0,0,0);
- switch(format) {
-
- case FORMAT_GRAYSCALE: {
-
- result=BColor(p_data[ofs],p_data[ofs],p_data[ofs],255.0);
- } break;
- case FORMAT_INTENSITY: {
-
- result=BColor(255,255,255,p_data[ofs]);
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
-
- result=BColor(p_data[ofs*2],p_data[ofs*2],p_data[ofs*2],p_data[ofs*2+1]);
-
- } break;
- case FORMAT_RGB: {
-
- result=BColor(p_data[ofs*3],p_data[ofs*3+1],p_data[ofs*3+2]);
-
- } break;
- case FORMAT_RGBA: {
-
- result=BColor(p_data[ofs*4],p_data[ofs*4+1],p_data[ofs*4+2],p_data[ofs*4+3]);
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- int pitch = 4;
- const uint8_t* pal = &p_data[ p_data_size - pitch * 256 ];
- int idx = p_data[ofs];
- result=BColor(pal[idx * pitch + 0] , pal[idx * pitch + 1] , pal[idx * pitch + 2] , pal[idx * pitch + 3] );
-
- } break;
- case FORMAT_INDEXED: {
-
- int pitch = 3;
- const uint8_t* pal = &p_data[ p_data_size - pitch * 256 ];
- int idx = p_data[ofs];
- result=BColor(pal[idx * pitch + 0] , pal[idx * pitch + 1] , pal[idx * pitch + 2] ,255);
- } break;
- case FORMAT_YUV_422: {
-
- int y, u, v;
- if (p_x % 2) {
- const uint8_t* yp = &p_data[p_width * 2 * p_y + p_x * 2];
- u = *(yp-1);
- y = yp[0];
- v = yp[1];
- } else {
-
- const uint8_t* yp = &p_data[p_width * 2 * p_y + p_x * 2];
- y = yp[0];
- u = yp[1];
- v = yp[3];
- };
-
- int32_t r = 1.164 * (y - 16) + 1.596 * (v - 128);
- int32_t g = 1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u - 128);
- int32_t b = 1.164 * (y - 16) + 2.018 * (u - 128);
- result = BColor(CLAMP(r, 0, 255), CLAMP(g, 0, 255), CLAMP(b, 0, 255));
- } break;
- case FORMAT_YUV_444: {
-
- uint8_t y, u, v;
- const uint8_t* yp = &p_data[p_width * 3 * p_y + p_x * 3];
- y = yp[0];
- u = yp[1];
- v = yp[2];
-
- int32_t r = 1.164 * (y - 16) + 1.596 * (v - 128);
- int32_t g = 1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u - 128);
- int32_t b = 1.164 * (y - 16) + 2.018 * (u - 128);
- result = BColor(CLAMP(r, 0, 255), CLAMP(g, 0, 255), CLAMP(b, 0, 255));
- } break;
- default:{}
-
- }
-
- return result;
+bool Image::has_mipmaps() const {
+ return mipmaps;
}
-void Image::put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap) {
-
- ERR_FAIL_COND(format != FORMAT_INDEXED && format != FORMAT_INDEXED_ALPHA);
- ERR_FAIL_INDEX(p_mipmap,mipmaps+1);
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX(p_x,w);
- ERR_FAIL_INDEX(p_y,h);
-
- data.set(ofs + p_y * w + p_x, p_idx);
-};
-
-uint8_t Image::get_indexed_pixel(int p_x, int p_y,int p_mipmap) const {
-
- ERR_FAIL_COND_V(format != FORMAT_INDEXED && format != FORMAT_INDEXED_ALPHA, 0);
-
- ERR_FAIL_INDEX_V(p_mipmap,mipmaps+1,0);
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX_V(p_x,w,0);
- ERR_FAIL_INDEX_V(p_y,h,0);
-
-
- return data[ofs + p_y * w + p_x];
-};
-
-void Image::set_pallete(const DVector<uint8_t>& p_data) {
+int Image::get_mipmap_count() const {
+ if (mipmaps)
+ return get_image_required_mipmaps(width,height,format);
+ else
+ return 0;
+}
- int len = p_data.size();
- ERR_FAIL_COND(format != FORMAT_INDEXED && format != FORMAT_INDEXED_ALPHA);
- ERR_FAIL_COND(format == FORMAT_INDEXED && len!=(256*3));
- ERR_FAIL_COND(format == FORMAT_INDEXED_ALPHA && len!=(256*4));
+//using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers
+template<uint32_t read_bytes,bool read_alpha,uint32_t write_bytes,bool write_alpha,bool read_gray,bool write_gray>
+static void _convert( int p_width,int p_height,const uint8_t* p_src,uint8_t* p_dst ){
- int ofs,w,h;
- _get_mipmap_offset_and_size(mipmaps+1,ofs,w,h);
- int pal_ofs = ofs;
- data.resize(pal_ofs + p_data.size());
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *dst=wp.ptr() + pal_ofs;
+ for(int y=0;y<p_height;y++) {
+ for(int x=0;x<p_width;x++) {
- DVector<uint8_t>::Read r = p_data.read();
- const unsigned char *src=r.ptr();
+ const uint8_t *rofs = &p_src[((y*p_width)+x)*(read_bytes+(read_alpha?1:0))];
+ uint8_t *wofs = &p_dst[((y*p_width)+x)*(write_bytes+(write_alpha?1:0))];
- copymem(dst, src, len);
-};
+ uint8_t rgba[4];
-int Image::get_width() const {
-
- return width;
-}
-int Image::get_height() const{
-
- return height;
-}
-
-int Image::get_mipmaps() const {
+ if (read_gray) {
+ rgba[0]=rofs[0];
+ rgba[1]=rofs[0];
+ rgba[2]=rofs[0];
+ } else {
+ for(uint32_t i=0;i<MAX(read_bytes,write_bytes);i++) {
+ rgba[i]=(i<read_bytes)?rofs[i]:0;
+ }
+ }
- return mipmaps;
-}
+ if (read_alpha || write_alpha) {
+ rgba[3]=read_alpha?rofs[read_bytes]:255;
+ }
-Color Image::get_pixel(int p_x,int p_y,int p_mipmap) const {
+ if (write_gray) {
+ //TODO: not correct grayscale, should use fixed point version of actual weights
+ wofs[0]=uint8_t((uint16_t(rofs[0])+uint16_t(rofs[1])+uint16_t(rofs[2]))/3);
+ } else {
+ for(uint32_t i=0;i<write_bytes;i++) {
+ wofs[i]=rgba[i];
+ }
+ }
- ERR_FAIL_INDEX_V(p_mipmap,mipmaps+1,Color());
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX_V(p_x,w,Color());
- ERR_FAIL_INDEX_V(p_y,h,Color());
+ if (write_alpha) {
+ wofs[write_bytes]=rgba[3];
+ }
+ }
+ }
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const unsigned char*data_ptr=r.ptr();
- BColor c = _get_pixelw(p_x,p_y,w,&data_ptr[ofs],len);
- return Color( c.r/255.0,c.g/255.0,c.b/255.0,c.a/255.0 );
}
void Image::convert( Format p_new_format ){
@@ -368,22 +353,17 @@ void Image::convert( Format p_new_format ){
if (p_new_format==format)
return;
- if (format>=FORMAT_BC1 || p_new_format>=FORMAT_BC1) {
- ERR_EXPLAIN("Cannot convert to <-> from compressed/custom image formats (for now).");
- ERR_FAIL();
- }
-
- if (p_new_format==FORMAT_INDEXED || p_new_format==FORMAT_INDEXED_ALPHA) {
+ if (format>=FORMAT_RGB565 || p_new_format>=FORMAT_RGB565) {
-
- return;
+ ERR_EXPLAIN("Cannot convert to <-> from non byte formats.");
+ ERR_FAIL();
}
Image new_img(width,height,0,p_new_format);
- int len=data.size();
+// int len=data.size();
DVector<uint8_t>::Read r = data.read();
DVector<uint8_t>::Write w = new_img.data.write();
@@ -391,35 +371,56 @@ void Image::convert( Format p_new_format ){
const uint8_t *rptr = r.ptr();
uint8_t *wptr = w.ptr();
- if (p_new_format==FORMAT_RGBA && format==FORMAT_INDEXED_ALPHA) {
+ int conversion_type = format | p_new_format<<8;
+
+ switch(conversion_type) {
+
+ case FORMAT_L8|(FORMAT_LA8<<8): _convert<1,false,1,true,true,true>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_R8<<8): _convert<1,false,1,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_RG8<<8): _convert<1,false,2,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_RGB8<<8): _convert<1,false,3,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_RGBA8<<8): _convert<1,false,3,true,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_L8<<8): _convert<1,true,1,false,true,true>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_R8<<8): _convert<1,true,1,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_RG8<<8): _convert<1,true,2,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_RGB8<<8): _convert<1,true,3,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_RGBA8<<8): _convert<1,true,3,true,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_L8<<8): _convert<1,false,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_LA8<<8): _convert<1,false,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_RG8<<8): _convert<1,false,2,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_RGB8<<8): _convert<1,false,3,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_RGBA8<<8): _convert<1,false,3,true,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_L8<<8): _convert<1,false,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_LA8<<8): _convert<1,false,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_R8<<8): _convert<1,false,1,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_RGB8<<8): _convert<1,false,3,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_RGBA8<<8): _convert<1,false,3,true,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_L8<<8): _convert<2,false,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_LA8<<8): _convert<2,false,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_R8<<8): _convert<2,false,1,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_RG8<<8): _convert<2,false,2,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_RGBA8<<8): _convert<2,false,3,true,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_L8<<8): _convert<3,true,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_LA8<<8): _convert<3,true,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_R8<<8): _convert<3,true,1,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_RG8<<8): _convert<3,true,2,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_RGB8<<8): _convert<3,true,3,true,false,false>( width, height,rptr, wptr ); break;
- //optimized unquantized form
- int dataend = len-256*4;
- const uint32_t *palpos = (const uint32_t*)&rptr[dataend];
- uint32_t *dst32 = (uint32_t *)wptr;
-
- for(int i=0;i<dataend;i++)
- dst32[i]=palpos[rptr[i]]; //since this is read/write, endianness is not a problem
-
- } else {
-
- //this is temporary, must find a faster way to do it.
- for(int i=0;i<width;i++)
- for(int j=0;j<height;j++)
- new_img._put_pixel(i,j,_get_pixel(i,j,rptr,len),wptr);
}
+
r = DVector<uint8_t>::Read();
w = DVector<uint8_t>::Write();
- bool gen_mipmaps=mipmaps>0;
+ bool gen_mipmaps=mipmaps;
+
+ mipmaps=false;
*this=new_img;
if (gen_mipmaps)
generate_mipmaps();
-
}
Image::Format Image::get_format() const{
@@ -460,13 +461,13 @@ static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_wi
int xmax = width - 1;
// temporary pointer
- for ( int y = 0; y < p_dst_height; y++ ) {
+ for ( uint32_t y = 0; y < p_dst_height; y++ ) {
// Y coordinates
oy = (double) y * yfac - 0.5f;
oy1 = (int) oy;
dy = oy - (double) oy1;
- for ( int x = 0; x < p_dst_width; x++ ) {
+ for ( uint32_t x = 0; x < p_dst_width; x++ ) {
// X coordinates
ox = (double) x * xfac - 0.5f;
ox1 = (int) ox;
@@ -650,10 +651,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
Image dst( p_width, p_height, 0, format );
- if (format==FORMAT_INDEXED)
- p_interpolation=INTERPOLATE_NEAREST;
-
-
DVector<uint8_t>::Read r = data.read();
const unsigned char*r_ptr=r.ptr();
@@ -722,18 +719,33 @@ void Image::crop( int p_width, int p_height ) {
if (p_width==width && p_height==height)
return;
+ uint8_t pdata[16]; //largest is 16
+ uint32_t pixel_size = get_format_pixel_size(format);
+
Image dst( p_width, p_height,0, format );
+ {
+ DVector<uint8_t>::Read r = data.read();
+ DVector<uint8_t>::Write w = dst.data.write();
- for (int y=0;y<p_height;y++) {
+ for (int y=0;y<p_height;y++) {
- for (int x=0;x<p_width;x++) {
+ for (int x=0;x<p_width;x++) {
- Color col = (x>=width || y>=height)? Color() : get_pixel(x,y);
- dst.put_pixel(x,y,col);
+ if ((x>=width || y>=height)) {
+ for(uint32_t i=0;i<pixel_size;i++)
+ pdata[i]=0;
+ } else {
+ _get_pixelb(x,y,pixel_size,r.ptr(),pdata);
+ }
+
+
+ dst._put_pixelb(x,y,pixel_size,w.ptr(),pdata);
+ }
}
}
+
if (mipmaps>0)
dst.generate_mipmaps();
*this=dst;
@@ -754,18 +766,28 @@ void Image::flip_y() {
+ {
+ DVector<uint8_t>::Write w = data.write();
+ uint8_t up[16];
+ uint8_t down[16];
+ uint32_t pixel_size = get_format_pixel_size(format);
- for (int y=0;y<(height/2);y++) {
+ for (int y=0;y<height;y++) {
- for (int x=0;x<width;x++) {
+ for (int x=0;x<width;x++) {
- Color up = get_pixel(x,y);
- Color down = get_pixel(x,height-y-1);
- put_pixel(x,y,down);
- put_pixel(x,height-y-1,up);
+ _get_pixelb(x,y,pixel_size,w.ptr(),up);
+ _get_pixelb(x,height-y-1,pixel_size,w.ptr(),down);
+
+ _put_pixelb(x,height-y-1,pixel_size,w.ptr(),up);
+ _put_pixelb(x,y,pixel_size,w.ptr(),down);
+
+ }
}
}
+
+
if (gm)
generate_mipmaps();;
@@ -782,15 +804,25 @@ void Image::flip_x() {
if (gm)
clear_mipmaps();;
- for (int y=0;y<(height/2);y++) {
- for (int x=0;x<width;x++) {
+ {
+ DVector<uint8_t>::Write w = data.write();
+ uint8_t up[16];
+ uint8_t down[16];
+ uint32_t pixel_size = get_format_pixel_size(format);
+
+ for (int y=0;y<height;y++) {
+
+ for (int x=0;x<width;x++) {
- Color up = get_pixel(x,y);
- Color down = get_pixel(width-x-1,y);
- put_pixel(x,y,down);
- put_pixel(width-x-1,y,up);
+ _get_pixelb(x,y,pixel_size,w.ptr(),up);
+ _get_pixelb(width-x-1,y,pixel_size,w.ptr(),down);
+
+ _put_pixelb(width-x-1,y,pixel_size,w.ptr(),up);
+ _put_pixelb(x,y,pixel_size,w.ptr(),down);
+
+ }
}
}
@@ -809,15 +841,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format,int &r
int pixsize=get_format_pixel_size(p_format);
int pixshift=get_format_pixel_rshift(p_format);
int minw,minh;
- _get_format_min_data_size(p_format,minw,minh);
-
-
- switch(p_format) {
-
- case FORMAT_INDEXED: pixsize=1; size=256*3; break;
- case FORMAT_INDEXED_ALPHA: pixsize=1; size=256*4;break;
- default: {}
- } ;
+ get_format_min_pixel_size(p_format,minw,minh);
while(true) {
@@ -849,20 +873,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format,int &r
bool Image::_can_modify(Format p_format) const {
- switch(p_format) {
-
- //these are OK
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY:
- case FORMAT_GRAYSCALE_ALPHA:
- case FORMAT_RGB:
- case FORMAT_RGBA:
- return true;
- default:
- return false;
- }
-
- return false;
+ return p_format<FORMAT_RGB565;
}
template<int CC>
@@ -903,16 +914,16 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
void Image::expand_x2_hq2x() {
- ERR_FAIL_COND(format>=FORMAT_INDEXED);
+ ERR_FAIL_COND(!_can_modify(format));
Format current = format;
- bool mipmaps=get_mipmaps();
- if (mipmaps) {
+ bool mm=has_mipmaps();
+ if (mm) {
clear_mipmaps();
}
- if (current!=FORMAT_RGBA)
- convert(FORMAT_RGBA);
+ if (current!=FORMAT_RGBA8)
+ convert(FORMAT_RGBA8);
DVector<uint8_t> dest;
dest.resize(width*2*height*2*4);
@@ -930,7 +941,7 @@ void Image::expand_x2_hq2x() {
data=dest;
- if (current!=FORMAT_RGBA)
+ if (current!=FORMAT_RGBA8)
convert(current);
if (mipmaps) {
@@ -941,7 +952,6 @@ void Image::expand_x2_hq2x() {
void Image::shrink_x2() {
- ERR_FAIL_COND(format==FORMAT_INDEXED || format==FORMAT_INDEXED_ALPHA);
ERR_FAIL_COND( data.size()==0 );
@@ -964,7 +974,6 @@ void Image::shrink_x2() {
copymem(w.ptr(),&r[ofs],new_size);
}
- mipmaps--;
width/=2;
height/=2;
data=new_img;
@@ -973,7 +982,7 @@ void Image::shrink_x2() {
DVector<uint8_t> new_img;
- ERR_FAIL_COND( format>=FORMAT_INDEXED );
+ ERR_FAIL_COND( !_can_modify(format) );
int ps = get_format_pixel_size(format);
new_img.resize((width/2)*(height/2)*ps);
@@ -983,11 +992,12 @@ void Image::shrink_x2() {
switch(format) {
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
- case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
- case FORMAT_RGB: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
- case FORMAT_RGBA: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_L8:
+ case FORMAT_R8: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_LA8: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RG8: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGB8: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGBA8: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
default: {}
}
}
@@ -999,7 +1009,7 @@ void Image::shrink_x2() {
}
}
-Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
+Error Image::generate_mipmaps(bool p_keep_existing) {
if (!_can_modify(format)) {
ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats.");
@@ -1007,11 +1017,13 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
}
+ int mmcount = get_mipmap_count();
+
int from_mm=1;
if (p_keep_existing) {
- from_mm=mipmaps+1;
+ from_mm=mmcount+1;
}
- int size = _get_dst_image_size(width,height,format,mipmaps,p_mipmaps);
+ int size = _get_dst_image_size(width,height,format,mmcount);
data.resize(size);
@@ -1023,7 +1035,7 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
int prev_h=height;
int prev_w=width;
- for(int i=1;i<mipmaps;i++) {
+ for(int i=1;i<mmcount;i++) {
int ofs,w,h;
@@ -1033,11 +1045,12 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
switch(format) {
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
- case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
- case FORMAT_RGB: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
- case FORMAT_RGBA: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_L8:
+ case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_LA8:
+ case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
default: {}
}
}
@@ -1056,7 +1069,7 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
int prev_h=height;
int prev_w=width;
- for(int i=1;i<mipmaps;i++) {
+ for(int i=1;i<mmcount;i++) {
int ofs,w,h;
@@ -1066,11 +1079,12 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
switch(format) {
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
- case FORMAT_GRAYSCALE_ALPHA: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
- case FORMAT_RGB: _scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
- case FORMAT_RGBA: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_L8:
+ case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_LA8:
+ case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_RGB8:_scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
default: {}
}
}
@@ -1083,85 +1097,25 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
}
-
-
return OK;
}
void Image::clear_mipmaps() {
- if (mipmaps==0)
+ if (!mipmaps)
return;
- if (format==FORMAT_CUSTOM) {
- ERR_EXPLAIN("Cannot clear mipmaps in indexed, compressed or custom image formats.");
- ERR_FAIL();
-
- }
-
if (empty())
return;
int ofs,w,h;
_get_mipmap_offset_and_size(1,ofs,w,h);
- int palsize = get_format_pallete_size(format);
- DVector<uint8_t> pallete;
- ERR_FAIL_COND(ofs+palsize > data.size()); //bug?
- if (palsize) {
-
- pallete.resize(palsize);
- DVector<uint8_t>::Read r = data.read();
- DVector<uint8_t>::Write w = pallete.write();
-
- copymem(&w[0],&r[data.size()-palsize],palsize);
- }
+ data.resize(ofs);
- data.resize(ofs+palsize);
-
- if (palsize) {
-
- DVector<uint8_t>::Read r = pallete.read();
- DVector<uint8_t>::Write w = data.write();
-
- copymem(&w[ofs],&r[0],palsize);
- }
-
- mipmaps=0;
+ mipmaps=false;
}
-void Image::make_normalmap(float p_height_scale) {
-
- if (!_can_modify(format)) {
- ERR_EXPLAIN("Cannot crop in indexed, compressed or custom image formats.");
- ERR_FAIL();
- }
-
- ERR_FAIL_COND( empty() );
-
- Image normalmap(width,height,0, FORMAT_RGB);
- /*
- for (int y=0;y<height;y++) {
- for (int x=0;x<width;x++) {
-
- float center=get_pixel(x,y).gray()/255.0;
- float up=(y>0)?get_pixel(x,y-1).gray()/255.0:center;
- float down=(y<(height-1))?get_pixel(x,y+1).gray()/255.0:center;
- float left=(x>0)?get_pixel(x-1,y).gray()/255.0:center;
- float right=(x<(width-1))?get_pixel(x+1,y).gray()/255.0:center;
-
-
- // uhm, how do i do this? ....
-
- Color result( (uint8_t)((normal.x+1.0)*127.0), (uint8_t)((normal.y+1.0)*127.0), (uint8_t)((normal.z+1.0)*127.0) );
-
- normalmap.put_pixel( x, y, result );
- }
-
- }
- */
- *this=normalmap;
-}
bool Image::empty() const {
@@ -1186,32 +1140,30 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format
width=p_width;
height=p_height;
- mipmaps=mm;
+ mipmaps=p_use_mipmaps;
format=p_format;
}
-void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
+void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
ERR_FAIL_INDEX(p_width-1,MAX_WIDTH);
ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT);
- if (p_format < FORMAT_CUSTOM) {
- int mm;
- int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_mipmaps);
+ int mm;
+ int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps);
- if (size!=p_data.size()) {
- ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()");
- ERR_FAIL_COND(p_data.size()!=size);
- }
- };
+ if (size!=p_data.size()) {
+ ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()");
+ ERR_FAIL_COND(p_data.size()!=size);
+ }
height=p_height;
width=p_width;
format=p_format;
data=p_data;
- mipmaps=p_mipmaps;
+ mipmaps=p_use_mipmaps;
}
@@ -1220,7 +1172,7 @@ void Image::create( const char ** p_xpm ) {
int size_width,size_height;
int pixelchars=0;
- mipmaps=0;
+ mipmaps=false;
bool has_alpha=false;
enum Status {
@@ -1235,6 +1187,8 @@ void Image::create( const char ** p_xpm ) {
HashMap<String,Color> colormap;
int colormap_size;
+ uint32_t pixel_size;
+ DVector<uint8_t>::Write w;
while (status!=DONE) {
@@ -1327,7 +1281,9 @@ void Image::create( const char ** p_xpm ) {
if (line==colormap_size) {
status=READING_PIXELS;
- create(size_width,size_height,0,has_alpha?FORMAT_RGBA:FORMAT_RGB);
+ create(size_width,size_height,0,has_alpha?FORMAT_RGBA8:FORMAT_RGB8);
+ w=data.write();
+ pixel_size=has_alpha?4:3;
}
} break;
case READING_PIXELS: {
@@ -1341,7 +1297,11 @@ void Image::create( const char ** p_xpm ) {
Color *colorptr = colormap.getptr(pixelstr);
ERR_FAIL_COND(!colorptr);
- put_pixel(x,y,*colorptr);
+ uint8_t pixel[4];
+ for(uint32_t i=0;i<pixel_size;i++) {
+ pixel[i]=CLAMP((*colorptr)[i]*255,0,255);
+ }
+ _put_pixelb(x,y,pixel_size,w.ptr(),pixel);
}
@@ -1382,9 +1342,8 @@ void Image::create( const char ** p_xpm ) {
bool Image::is_invisible() const {
- if (format==FORMAT_GRAYSCALE ||
- format==FORMAT_RGB ||
- format==FORMAT_INDEXED)
+ if (format==FORMAT_L8 ||
+ format==FORMAT_RGB8 || format==FORMAT_RG8)
return false;
int len = data.size();
@@ -1392,8 +1351,6 @@ bool Image::is_invisible() const {
if (len==0)
return true;
- if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444)
- return false;
int w,h;
_get_mipmap_offset_and_size(1,len,w,h);
@@ -1404,13 +1361,8 @@ bool Image::is_invisible() const {
bool detected=false;
switch(format) {
- case FORMAT_INTENSITY: {
- for(int i=0;i<len;i++) {
- DETECT_NON_ALPHA(data_ptr[i]);
- }
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
+ case FORMAT_LA8: {
for(int i=0;i<(len>>1);i++) {
@@ -1418,25 +1370,18 @@ bool Image::is_invisible() const {
}
} break;
- case FORMAT_RGBA: {
+ case FORMAT_RGBA8: {
for(int i=0;i<(len>>2);i++) {
DETECT_NON_ALPHA(data_ptr[(i<<2)+3])
}
} break;
- case FORMAT_INDEXED: {
- return false;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return false;
- } break;
- case FORMAT_PVRTC2_ALPHA:
- case FORMAT_PVRTC4_ALPHA:
- case FORMAT_BC2:
- case FORMAT_BC3: {
+ case FORMAT_PVRTC2A:
+ case FORMAT_PVRTC4A:
+ case FORMAT_DXT3:
+ case FORMAT_DXT5: {
detected=true;
} break;
default: {}
@@ -1447,19 +1392,12 @@ bool Image::is_invisible() const {
Image::AlphaMode Image::detect_alpha() const {
- if (format==FORMAT_GRAYSCALE ||
- format==FORMAT_RGB ||
- format==FORMAT_INDEXED)
- return ALPHA_NONE;
int len = data.size();
if (len==0)
return ALPHA_NONE;
- if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444)
- return ALPHA_NONE;
-
int w,h;
_get_mipmap_offset_and_size(1,len,w,h);
@@ -1470,13 +1408,8 @@ Image::AlphaMode Image::detect_alpha() const {
bool detected=false;
switch(format) {
- case FORMAT_INTENSITY: {
- for(int i=0;i<len;i++) {
- DETECT_ALPHA(data_ptr[i]);
- }
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
+ case FORMAT_LA8: {
for(int i=0;i<(len>>1);i++) {
@@ -1484,25 +1417,17 @@ Image::AlphaMode Image::detect_alpha() const {
}
} break;
- case FORMAT_RGBA: {
+ case FORMAT_RGBA8: {
for(int i=0;i<(len>>2);i++) {
DETECT_ALPHA(data_ptr[(i<<2)+3])
}
- } break;
- case FORMAT_INDEXED: {
-
- return ALPHA_NONE;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return ALPHA_BLEND;
- } break;
- case FORMAT_PVRTC2_ALPHA:
- case FORMAT_PVRTC4_ALPHA:
- case FORMAT_BC2:
- case FORMAT_BC3: {
+ } break;
+ case FORMAT_PVRTC2A:
+ case FORMAT_PVRTC4A:
+ case FORMAT_DXT3:
+ case FORMAT_DXT5: {
detected=true;
} break;
default: {}
@@ -1528,7 +1453,7 @@ Error Image::save_png(const String& p_path) {
return ERR_UNAVAILABLE;
return save_png_func(p_path, *this);
-};
+}
bool Image::operator==(const Image& p_image) const {
@@ -1541,84 +1466,7 @@ bool Image::operator==(const Image& p_image) const {
}
-int Image::get_format_pixel_size(Format p_format) {
-
- switch(p_format) {
- case FORMAT_GRAYSCALE: {
-
- return 1;
- } break;
- case FORMAT_INTENSITY: {
-
- return 1;
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
-
- return 2;
- } break;
- case FORMAT_RGB: {
-
- return 3;
- } break;
- case FORMAT_RGBA: {
-
- return 4;
- } break;
- case FORMAT_INDEXED: {
- return 1;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return 1;
- } break;
- case FORMAT_BC1:
- case FORMAT_BC2:
- case FORMAT_BC3:
- case FORMAT_BC4:
- case FORMAT_BC5: {
-
- return 1;
- } break;
- case FORMAT_PVRTC2:
- case FORMAT_PVRTC2_ALPHA: {
-
- return 1;
- } break;
- case FORMAT_PVRTC4:
- case FORMAT_PVRTC4_ALPHA: {
-
- return 1;
- } break;
- case FORMAT_ATC:
- case FORMAT_ATC_ALPHA_EXPLICIT:
- case FORMAT_ATC_ALPHA_INTERPOLATED: {
-
- return 1;
- } break;
- case FORMAT_ETC: {
-
- return 1;
- } break;
- case FORMAT_YUV_422: {
- return 2;
- };
- case FORMAT_YUV_444: {
- return 3;
- } break;
- case FORMAT_CUSTOM: {
-
- ERR_EXPLAIN("pixel size requested for custom image format, and it's unknown obviously");
- ERR_FAIL_V(1);
- } break;
- default:{
- ERR_EXPLAIN("Cannot obtain pixel size from this format");
- ERR_FAIL_V(1);
-
- }
- }
- return 0;
-}
int Image::get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps) {
@@ -1635,105 +1483,12 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
}
-void Image::_get_format_min_data_size(Format p_format,int &r_w, int &r_h) {
-
-
- switch(p_format) {
- case FORMAT_BC1:
- case FORMAT_BC2:
- case FORMAT_BC3:
- case FORMAT_BC4:
- case FORMAT_BC5: {
- r_w=4;
- r_h=4;
- } break;
- case FORMAT_PVRTC2:
- case FORMAT_PVRTC2_ALPHA: {
-
- r_w=16;
- r_h=8;
- } break;
- case FORMAT_PVRTC4_ALPHA:
- case FORMAT_PVRTC4: {
-
- r_w=8;
- r_h=8;
- } break;
- case FORMAT_ATC:
- case FORMAT_ATC_ALPHA_EXPLICIT:
- case FORMAT_ATC_ALPHA_INTERPOLATED: {
-
- r_w=8;
- r_h=8;
-
- } break;
-
- case FORMAT_ETC: {
-
- r_w=4;
- r_h=4;
- } break;
- default: {
- r_w=1;
- r_h=1;
- } break;
- }
-
-}
-
-
-int Image::get_format_pixel_rshift(Format p_format) {
-
- if (p_format==FORMAT_BC1 || p_format==FORMAT_BC4 || p_format==FORMAT_ATC || p_format==FORMAT_PVRTC4 || p_format==FORMAT_PVRTC4_ALPHA || p_format==FORMAT_ETC)
- return 1;
- else if (p_format==FORMAT_PVRTC2 || p_format==FORMAT_PVRTC2_ALPHA)
- return 2;
- else
- return 0;
-}
-
-int Image::get_format_pallete_size(Format p_format) {
-
- switch(p_format) {
- case FORMAT_GRAYSCALE: {
-
- return 0;
- } break;
- case FORMAT_INTENSITY: {
-
- return 0;
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
-
- return 0;
- } break;
- case FORMAT_RGB: {
-
- return 0;
- } break;
- case FORMAT_RGBA: {
-
- return 0;
- } break;
- case FORMAT_INDEXED: {
-
- return 3*256;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return 4*256;
- } break;
- default:{}
- }
- return 0;
-}
Error Image::_decompress_bc() {
- print_line("decompressing bc");
int wd=width,ht=height;
if (wd%4!=0) {
@@ -1745,7 +1500,7 @@ Error Image::_decompress_bc() {
int mm;
- int size = _get_dst_image_size(wd,ht,FORMAT_RGBA,mm,mipmaps);
+ int size = _get_dst_image_size(wd,ht,FORMAT_RGBA8,mm);
DVector<uint8_t> newdata;
newdata.resize(size);
@@ -1762,7 +1517,7 @@ Error Image::_decompress_bc() {
switch(format) {
- case FORMAT_BC1: {
+ case FORMAT_DXT1: {
int len = (wd*ht)/16;
uint8_t* dst=&w[wofs];
@@ -1788,8 +1543,8 @@ Error Image::_decompress_bc() {
col_b|=src[2];
uint8_t table[4][4]={
- { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 },
- { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 },
+ { uint8_t((col_a>>11)<<3), uint8_t(((col_a>>5)&0x3f)<<2),uint8_t(((col_a)&0x1f)<<3), 255 },
+ { uint8_t((col_b>>11)<<3), uint8_t(((col_b>>5)&0x3f)<<2),uint8_t(((col_b)&0x1f)<<3), 255 },
{0,0,0,255},
{0,0,0,255}
};
@@ -1841,7 +1596,7 @@ Error Image::_decompress_bc() {
ht/=2;
} break;
- case FORMAT_BC2: {
+ case FORMAT_DXT3: {
int len = (wd*ht)/16;
uint8_t* dst=&w[wofs];
@@ -1885,8 +1640,9 @@ Error Image::_decompress_bc() {
col_b|=src[8+2];
uint8_t table[4][4]={
- { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 },
- { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 },
+ { uint8_t((col_a>>11)<<3), uint8_t(((col_a>>5)&0x3f)<<2),uint8_t(((col_a)&0x1f)<<3), 255 },
+ { uint8_t((col_b>>11)<<3), uint8_t(((col_b>>5)&0x3f)<<2),uint8_t(((col_b)&0x1f)<<3), 255 },
+
{0,0,0,255},
{0,0,0,255}
};
@@ -1933,7 +1689,7 @@ Error Image::_decompress_bc() {
ht/=2;
} break;
- case FORMAT_BC3: {
+ case FORMAT_DXT5: {
int len = (wd*ht)/16;
uint8_t* dst=&w[wofs];
@@ -2001,9 +1757,10 @@ Error Image::_decompress_bc() {
col_b<<=8;
col_b|=src[8+2];
- uint8_t table[4][4]={
- { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 },
- { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 },
+ uint8_t table[4][4]={
+ { uint8_t((col_a>>11)<<3), uint8_t(((col_a>>5)&0x3f)<<2),uint8_t(((col_a)&0x1f)<<3), 255 },
+ { uint8_t((col_b>>11)<<3), uint8_t(((col_b>>5)&0x3f)<<2),uint8_t(((col_b)&0x1f)<<3), 255 },
+
{0,0,0,255},
{0,0,0,255}
};
@@ -2061,18 +1818,19 @@ Error Image::_decompress_bc() {
r=DVector<uint8_t>::Read();
data=newdata;
- format=FORMAT_RGBA;
+ format=FORMAT_RGBA8;
if (wd!=width || ht!=height) {
- //todo, crop
- width=wd;
- height=ht;
+
+ SWAP(width,wd);
+ SWAP(height,ht);
+ crop(wd,ht);
}
return OK;
}
bool Image::is_compressed() const {
- return format>=FORMAT_BC1;
+ return format>=FORMAT_RGB565;
}
@@ -2085,12 +1843,14 @@ Image Image::decompressed() const {
Error Image::decompress() {
- if (format>=FORMAT_BC1 && format<=FORMAT_BC5 )
+ if (format>=FORMAT_DXT1 && format<=FORMAT_ATI2 )
_decompress_bc();//_image_decompress_bc(this);
- else if (format>=FORMAT_PVRTC2 && format<=FORMAT_PVRTC4_ALPHA && _image_decompress_pvrtc)
+ else if (format>=FORMAT_PVRTC2 && format<=FORMAT_PVRTC4A&& _image_decompress_pvrtc)
_image_decompress_pvrtc(this);
else if (format==FORMAT_ETC && _image_decompress_etc)
_image_decompress_etc(this);
+ else if (format>=FORMAT_ETC2_R11 && format<=FORMAT_ETC2_RGB8A1 && _image_decompress_etc)
+ _image_decompress_etc2(this);
else
return ERR_UNAVAILABLE;
return OK;
@@ -2101,7 +1861,12 @@ Error Image::compress(CompressMode p_mode) {
switch(p_mode) {
- case COMPRESS_BC: {
+ case COMPRESS_16BIT: {
+
+ //ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
+ //_image_compress_bc_func(this);
+ } break;
+ case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
_image_compress_bc_func(this);
@@ -2121,6 +1886,11 @@ Error Image::compress(CompressMode p_mode) {
ERR_FAIL_COND_V(!_image_compress_etc_func, ERR_UNAVAILABLE);
_image_compress_etc_func(this);
} break;
+ case COMPRESS_ETC2: {
+
+ ERR_FAIL_COND_V(!_image_compress_etc_func, ERR_UNAVAILABLE);
+ _image_compress_etc_func(this);
+ } break;
}
@@ -2133,14 +1903,14 @@ Image Image::compressed(int p_mode) {
ret.compress((Image::CompressMode)p_mode);
return ret;
-};
+}
Image::Image(const char **p_xpm) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=false;
+ format=FORMAT_L8;
create(p_xpm);
}
@@ -2150,37 +1920,28 @@ Image::Image(int p_width, int p_height,bool p_use_mipmaps, Format p_format) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=p_use_mipmaps;
+ format=FORMAT_L8;
create(p_width,p_height,p_use_mipmaps,p_format);
}
-Image::Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
+Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=p_mipmaps;
+ format=FORMAT_L8;
create(p_width,p_height,p_mipmaps,p_format,p_data);
}
-Image Image::brushed(const Image& p_src, const Image& p_brush, const Point2& p_dest) const {
-
- Image img = *this;
- img.brush_transfer(p_src,p_brush,p_dest);
- return img;
-}
-
Rect2 Image::get_used_rect() const {
- if (format==FORMAT_GRAYSCALE ||
- format==FORMAT_RGB ||
- format==FORMAT_INDEXED || format>FORMAT_INDEXED_ALPHA)
+ if (format!=FORMAT_LA8 && format!=FORMAT_RGBA8)
return Rect2(Point2(),Size2(width,height));
int len = data.size();
@@ -2188,16 +1949,18 @@ Rect2 Image::get_used_rect() const {
if (len==0)
return Rect2();
- int data_size = len;
+ //int data_size = len;
DVector<uint8_t>::Read r = data.read();
const unsigned char *rptr=r.ptr();
+ int ps = format==FORMAT_LA8?2:4;
int minx=0xFFFFFF,miny=0xFFFFFFF;
int maxx=-1,maxy=-1;
- for(int i=0;i<width;i++) {
- for(int j=0;j<height;j++) {
+ for(int j=0;j<height;j++) {
+ for(int i=0;i<width;i++) {
+
- bool opaque = _get_pixel(i,j,rptr,data_size).a>2;
+ bool opaque = rptr[(j*width+i)*ps+(ps-1)]>2;
if (!opaque)
continue;
if (i>maxx)
@@ -2225,101 +1988,47 @@ Image Image::get_rect(const Rect2& p_area) const {
img.blit_rect(*this, p_area, Point2(0, 0));
return img;
-};
-
-void Image::brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest) {
-
-
- ERR_FAIL_COND( width != p_src.width || height !=p_src.height);
-
- int dst_data_size = data.size();
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *dst_data_ptr=wp.ptr();
-
-
- int src_data_size = p_src.data.size();
- DVector<uint8_t>::Read rp = p_src.data.read();
- const unsigned char *src_data_ptr=rp.ptr();
-
- int brush_data_size = p_brush.data.size();
- DVector<uint8_t>::Read bp = p_brush.data.read();
- const unsigned char *src_brush_ptr=bp.ptr();
-
- int bw = p_brush.get_width();
- int bh = p_brush.get_height();
- int dx=p_dest.x;
- int dy=p_dest.y;
-
- for(int i=dy;i<dy+bh;i++) {
-
- if (i<0 || i >= height)
- continue;
- for(int j=dx;j<dx+bw;j++) {
-
- if (j<0 || j>=width)
- continue;
-
- BColor src = p_src._get_pixel(j,i,src_data_ptr,src_data_size);
- BColor dst = _get_pixel(j,i,dst_data_ptr,dst_data_size);
- BColor brush = p_brush._get_pixel(j-dx,i-dy,src_brush_ptr,brush_data_size);
- uint32_t mult = brush.r;
- dst.r = dst.r + (((int32_t(src.r)-int32_t(dst.r))*mult)>>8);
- dst.g = dst.g + (((int32_t(src.g)-int32_t(dst.g))*mult)>>8);
- dst.b = dst.b + (((int32_t(src.b)-int32_t(dst.b))*mult)>>8);
- dst.a = dst.a + (((int32_t(src.a)-int32_t(dst.a))*mult)>>8);
- _put_pixel(j,i,dst,dst_data_ptr);
- }
- }
}
-
void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest) {
int dsize=data.size();
int srcdsize=p_src.data.size();
ERR_FAIL_COND( dsize==0 );
ERR_FAIL_COND( srcdsize==0 );
+ ERR_FAIL_COND( format!=p_src.format );
+ Rect2i local_src_rect = Rect2i(0,0,width,height).clip( Rect2i(p_dest+p_src_rect.pos,p_src_rect.size) );
- Rect2 rrect = Rect2(0,0,p_src.width,p_src.height).clip(p_src_rect);
+ if (local_src_rect.size.x<=0 || local_src_rect.size.y<=0)
+ return;
+ Rect2i src_rect( p_src_rect.pos + ( local_src_rect.pos - p_dest), local_src_rect.size );
DVector<uint8_t>::Write wp = data.write();
- unsigned char *dst_data_ptr=wp.ptr();
+ uint8_t *dst_data_ptr=wp.ptr();
DVector<uint8_t>::Read rp = p_src.data.read();
- const unsigned char *src_data_ptr=rp.ptr();
-
- if ((format==FORMAT_INDEXED || format == FORMAT_INDEXED_ALPHA) && (p_src.format==FORMAT_INDEXED || p_src.format == FORMAT_INDEXED_ALPHA)) {
-
- Point2i desti(p_dest.x, p_dest.y);
- Point2i srci(rrect.pos.x, rrect.pos.y);
+ const uint8_t *src_data_ptr=rp.ptr();
- for(int i=0;i<rrect.size.y;i++) {
+ int pixel_size=get_format_pixel_size(format);
- if (i<0 || i >= height)
- continue;
- for(int j=0;j<rrect.size.x;j++) {
-
- if (j<0 || j>=width)
- continue;
+ for(int i=0;i<src_rect.size.y;i++) {
- dst_data_ptr[width * (desti.y + i) + desti.x + j] = src_data_ptr[p_src.width * (srci.y+i) + srci.x+j];
- }
- }
- } else {
+ for(int j=0;j<src_rect.size.x;j++) {
- for(int i=0;i<rrect.size.y;i++) {
+ int src_x = src_rect.pos.x+j;
+ int src_y = src_rect.pos.y+i;
- if (i<0 || i >= height)
- continue;
- for(int j=0;j<rrect.size.x;j++) {
+ int dst_x = local_src_rect.pos.x+j;
+ int dst_y = local_src_rect.pos.y+i;
- if (j<0 || j>=width)
- continue;
+ const uint8_t *src = &src_data_ptr[ (src_y*p_src.width+src_x)*pixel_size];
+ uint8_t *dst = &dst_data_ptr[ (dst_y*width+dst_x)*pixel_size];
- _put_pixel(p_dest.x+j,p_dest.y+i,p_src._get_pixel(rrect.pos.x+j,rrect.pos.y+i,src_data_ptr,srcdsize),dst_data_ptr);
+ for(int k=0;k<pixel_size;k++) {
+ dst[k]=src[k];
}
}
}
@@ -2334,9 +2043,11 @@ void (*Image::_image_compress_bc_func)(Image *)=NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *)=NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *)=NULL;
void (*Image::_image_compress_etc_func)(Image *)=NULL;
+void (*Image::_image_compress_etc2_func)(Image *)=NULL;
void (*Image::_image_decompress_pvrtc)(Image *)=NULL;
void (*Image::_image_decompress_bc)(Image *)=NULL;
void (*Image::_image_decompress_etc)(Image *)=NULL;
+void (*Image::_image_decompress_etc2)(Image *)=NULL;
DVector<uint8_t> (*Image::lossy_packer)(const Image& ,float )=NULL;
Image (*Image::lossy_unpacker)(const DVector<uint8_t>& )=NULL;
@@ -2352,7 +2063,7 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
void Image::normalmap_to_xy() {
- convert(Image::FORMAT_RGBA);
+ convert(Image::FORMAT_RGBA8);
{
int len = data.size()/4;
@@ -2367,7 +2078,7 @@ void Image::normalmap_to_xy() {
}
}
- convert(Image::FORMAT_GRAYSCALE_ALPHA);
+ convert(Image::FORMAT_LA8);
}
void Image::srgb_to_linear() {
@@ -2378,9 +2089,9 @@ void Image::srgb_to_linear() {
static const uint8_t srgb2lin[256]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252};
- ERR_FAIL_COND( format!=FORMAT_RGB && format!=FORMAT_RGBA );
+ ERR_FAIL_COND( format!=FORMAT_RGB8 && format!=FORMAT_RGBA8 );
- if (format==FORMAT_RGBA) {
+ if (format==FORMAT_RGBA8) {
int len = data.size()/4;
DVector<uint8_t>::Write wp = data.write();
@@ -2393,7 +2104,7 @@ void Image::srgb_to_linear() {
data_ptr[(i<<2)+2]=srgb2lin[ data_ptr[(i<<2)+2] ];
}
- } else if (format==FORMAT_RGB) {
+ } else if (format==FORMAT_RGB8) {
int len = data.size()/3;
DVector<uint8_t>::Write wp = data.write();
@@ -2414,7 +2125,7 @@ void Image::premultiply_alpha() {
if (data.size()==0)
return;
- if (format!=FORMAT_RGBA)
+ if (format!=FORMAT_RGBA8)
return; //not needed
DVector<uint8_t>::Write wp = data.write();
@@ -2424,11 +2135,11 @@ void Image::premultiply_alpha() {
for(int i=0;i<height;i++) {
for(int j=0;j<width;j++) {
- BColor bc = _get_pixel(j,i,data_ptr,0);
- bc.r=(int(bc.r)*int(bc.a))>>8;
- bc.g=(int(bc.g)*int(bc.a))>>8;
- bc.b=(int(bc.b)*int(bc.a))>>8;
- _put_pixel(j,i,bc,data_ptr);
+ uint8_t *ptr = &data_ptr[(i*width+j)*4];
+
+ ptr[0]=(uint16_t(ptr[0])*uint16_t(ptr[3]))>>8;
+ ptr[1]=(uint16_t(ptr[1])*uint16_t(ptr[3]))>>8;
+ ptr[2]=(uint16_t(ptr[2])*uint16_t(ptr[3]))>>8;
}
}
}
@@ -2438,12 +2149,12 @@ void Image::fix_alpha_edges() {
if (data.size()==0)
return;
- if (format!=FORMAT_RGBA)
+ if (format!=FORMAT_RGBA8)
return; //not needed
DVector<uint8_t> dcopy = data;
DVector<uint8_t>::Read rp = data.read();
- const uint8_t *rptr=rp.ptr();
+ const uint8_t *srcptr=rp.ptr();
DVector<uint8_t>::Write wp = data.write();
unsigned char *data_ptr=wp.ptr();
@@ -2455,13 +2166,16 @@ void Image::fix_alpha_edges() {
for(int i=0;i<height;i++) {
for(int j=0;j<width;j++) {
- BColor bc = _get_pixel(j,i,rptr,0);
- if (bc.a>=alpha_treshold)
+ const uint8_t *rptr = &srcptr[(i*width+j)*4];
+ uint8_t *wptr = &data_ptr[(i*width+j)*4];
+
+ if (rptr[3]>=alpha_treshold)
continue;
int closest_dist=max_dist;
- BColor closest_color;
- closest_color.a=bc.a;
+ uint8_t closest_color[3];
+
+
int from_x = MAX(0,j-max_radius);
int to_x = MIN(width-1,j+max_radius);
int from_y = MAX(0,i-max_radius);
@@ -2476,22 +2190,25 @@ void Image::fix_alpha_edges() {
if (dist>=closest_dist)
continue;
- const uint8_t * rp = &rptr[(k*width+l)<<2];
+ const uint8_t * rp = &srcptr[(k*width+l)<<2];
if (rp[3]<alpha_treshold)
continue;
- closest_dist=dist;
- closest_color.r=rp[0];
- closest_color.g=rp[1];
- closest_color.b=rp[2];
+ closest_color[0]=rp[0];
+ closest_color[1]=rp[1];
+ closest_color[2]=rp[2];
}
}
- if (closest_dist!=max_dist)
- _put_pixel(j,i,closest_color,data_ptr);
+ if (closest_dist!=max_dist) {
+
+ wptr[0]=closest_color[0];
+ wptr[1]=closest_color[1];
+ wptr[2]=closest_color[2];
+ }
}
}
@@ -2508,8 +2225,8 @@ Image::Image(const uint8_t* p_mem_png_jpg, int p_len) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=false;
+ format=FORMAT_L8;
if (_png_mem_loader_func) {
*this = _png_mem_loader_func(p_mem_png_jpg,p_len);
@@ -2525,8 +2242,8 @@ Image::Image() {
width=0;
height=0;
- mipmaps=0;
- format = FORMAT_GRAYSCALE;
+ mipmaps=false;
+ format = FORMAT_L8;
}
Image::~Image() {
diff --git a/core/image.h b/core/image.h
index 0f0b345eb9..2b4da03516 100644
--- a/core/image.h
+++ b/core/image.h
@@ -55,35 +55,44 @@ public:
static SavePNGFunc save_png_func;
enum Format {
- FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255
- FORMAT_INTENSITY, ///< one byte per pixel, 0-255
- FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255
- FORMAT_RGB, ///< one byte R, one byte G, one byte B
- FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A
- FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette
- FORMAT_INDEXED_ALPHA, ///< index byte 0-256, and after image end, 256*4 bytes of palette (alpha)
- FORMAT_YUV_422,
- FORMAT_YUV_444,
- FORMAT_BC1, // DXT1
- FORMAT_BC2, // DXT3
- FORMAT_BC3, // DXT5
- FORMAT_BC4, // ATI1
- FORMAT_BC5, // ATI2
- FORMAT_PVRTC2,
- FORMAT_PVRTC2_ALPHA,
- FORMAT_PVRTC4,
- FORMAT_PVRTC4_ALPHA,
- FORMAT_ETC, // regular ETC, no transparency
- FORMAT_ATC,
- FORMAT_ATC_ALPHA_EXPLICIT,
- FORMAT_ATC_ALPHA_INTERPOLATED,
- /*FORMAT_ETC2_R, for the future..
- FORMAT_ETC2_RG,
- FORMAT_ETC2_RGB,
- FORMAT_ETC2_RGBA1,
- FORMAT_ETC2_RGBA,*/
- FORMAT_CUSTOM,
+ FORMAT_L8, //luminance
+ FORMAT_LA8, //luminance-alpha
+ FORMAT_R8,
+ FORMAT_RG8,
+ FORMAT_RGB8,
+ FORMAT_RGBA8,
+ FORMAT_RGB565, //16 bit
+ FORMAT_RGBA4444,
+ FORMAT_RGBA5551,
+ FORMAT_RF, //float
+ FORMAT_RGF,
+ FORMAT_RGBF,
+ FORMAT_RGBAF,
+ FORMAT_RH, //half float
+ FORMAT_RGH,
+ FORMAT_RGBH,
+ FORMAT_RGBAH,
+ FORMAT_DXT1, //s3tc bc1
+ FORMAT_DXT3, //bc2
+ FORMAT_DXT5, //bc3
+ FORMAT_ATI1, //bc4
+ FORMAT_ATI2, //bc5
+ FORMAT_BPTC_RGBA, //btpc bc6h
+ FORMAT_BPTC_RGBF, //float /
+ FORMAT_BPTC_RGBFU, //unsigned float
+ FORMAT_PVRTC2, //pvrtc
+ FORMAT_PVRTC2A,
+ FORMAT_PVRTC4,
+ FORMAT_PVRTC4A,
+ FORMAT_ETC, //etc1
+ FORMAT_ETC2_R11, //etc2
+ FORMAT_ETC2_R11S, //signed, NOT srgb.
+ FORMAT_ETC2_RG11,
+ FORMAT_ETC2_RG11S,
+ FORMAT_ETC2_RGB8,
+ FORMAT_ETC2_RGBA8,
+ FORMAT_ETC2_RGB8A1,
FORMAT_MAX
};
@@ -96,15 +105,21 @@ public:
/* INTERPOLATE GAUSS */
};
+ //some functions provided by something else
+
static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size);
static Image (*_jpg_mem_loader_func)(const uint8_t* p_png,int p_size);
+
static void (*_image_compress_bc_func)(Image *);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc_func)(Image *);
+ static void (*_image_compress_etc2_func)(Image *);
+
static void (*_image_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
static void (*_image_decompress_etc)(Image *);
+ static void (*_image_decompress_etc2)(Image *);
Error _decompress_bc();
@@ -114,92 +129,19 @@ public:
static Image (*lossless_unpacker)(const DVector<uint8_t>& p_buffer);
private:
- //internal byte based color
- struct BColor {
- union {
- uint8_t col[4];
- struct {
- uint8_t r,g,b,a;
- };
- };
-
- bool operator==(const BColor& p_color) const { for(int i=0;i<4;i++) {if (col[i]!=p_color.col[i]) return false; } return true; }
- _FORCE_INLINE_ uint8_t gray() const { return (uint16_t(col[0])+uint16_t(col[1])+uint16_t(col[2]))/3; }
- _FORCE_INLINE_ BColor() {}
- BColor(uint8_t p_r,uint8_t p_g,uint8_t p_b,uint8_t p_a=255) { col[0]=p_r; col[1]=p_g; col[2]=p_b; col[3]=p_a; }
- };
-
- //median cut classes
-
- struct BColorPos {
-
- uint32_t index;
- BColor color;
- struct SortR {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.r < cb.color.r; }
- };
-
- struct SortG {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.g < cb.color.g; }
- };
-
- struct SortB {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.b < cb.color.b; }
- };
-
- struct SortA {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.a < cb.color.a; }
- };
- };
-
- struct SPTree {
-
- bool leaf;
- uint8_t split_plane;
- uint8_t split_value;
- union {
- int left;
- int color;
- };
- int right;
- SPTree() { leaf=true; left=-1; right=-1;}
- };
-
- struct MCBlock {
-
- BColorPos min_color,max_color;
- BColorPos *colors;
- int sp_idx;
- int color_count;
- int get_longest_axis_index() const;
- int get_longest_axis_length() const;
- bool operator<(const MCBlock& p_block) const;
- void shrink();
- MCBlock();
- MCBlock(BColorPos *p_colors,int p_color_count);
- };
-
Format format;
DVector<uint8_t> data;
- int width,height,mipmaps;
-
-
+ int width,height;
+ bool mipmaps;
- _FORCE_INLINE_ BColor _get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const;
- _FORCE_INLINE_ BColor _get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const;
- _FORCE_INLINE_ void _put_pixelw(int p_x,int p_y, int p_width, const BColor& p_color, unsigned char *p_data);
- _FORCE_INLINE_ void _put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data);
_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
- _FORCE_INLINE_ static void _get_format_min_data_size(Format p_format,int &r_w, int &r_h);
static int _get_dst_image_size(int p_width, int p_height, Format p_format,int &r_mipmaps,int p_mipmaps=-1);
bool _can_modify(Format p_format) const;
+ _FORCE_INLINE_ void _put_pixelb(int p_x,int p_y, uint32_t p_pixelsize,uint8_t *p_dst,const uint8_t *p_src);
+ _FORCE_INLINE_ void _get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_src,uint8_t *p_dst);
public:
@@ -207,20 +149,11 @@ public:
int get_width() const; ///< Get image width
int get_height() const; ///< Get image height
- int get_mipmaps() const;
-
- /**
- * Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual
- * value.
- */
- Color get_pixel(int p_x,int p_y,int p_mipmap=0) const;
- /**
- * Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor.
- */
- void put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap=0); /* alpha and index are averaged */
+ bool has_mipmaps() const;
+ int get_mipmap_count() const;
/**
- * Convert the image to another format, as close as it can be done.
+ * Convert the image to another format, conversion only to raw byte format
*/
void convert( Format p_new_format );
@@ -259,25 +192,21 @@ public:
void flip_x();
void flip_y();
+
/**
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
*/
- Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false);
+ Error generate_mipmaps(bool p_keep_existing=false);
void clear_mipmaps();
- /**
- * Generate a normal map from a grayscale image
- */
-
- void make_normalmap(float p_height_scale=1.0);
/**
* Create a new image of a given size and format. Current image will be lost
*/
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
- void create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
+ void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
void create( const char ** p_xpm );
/**
@@ -301,7 +230,7 @@ public:
/**
* import an image of a specific size and format from a pointer
*/
- Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
+ Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
enum AlphaMode {
ALPHA_NONE,
@@ -312,32 +241,27 @@ public:
AlphaMode detect_alpha() const;
bool is_invisible() const;
- void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0);
- uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const;
- void set_pallete(const DVector<uint8_t>& p_data);
-
static int get_format_pixel_size(Format p_format);
static int get_format_pixel_rshift(Format p_format);
- static int get_format_pallete_size(Format p_format);
+ static void get_format_min_pixel_size(Format p_format,int &r_w, int &r_h);
+
static int get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps=0);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
-
-
bool operator==(const Image& p_image) const;
- void quantize();
-
enum CompressMode {
- COMPRESS_BC,
+ COMPRESS_16BIT,
+ COMPRESS_S3TC,
COMPRESS_PVRTC2,
COMPRESS_PVRTC4,
- COMPRESS_ETC
+ COMPRESS_ETC,
+ COMPRESS_ETC2
};
- Error compress(CompressMode p_mode=COMPRESS_BC);
+ Error compress(CompressMode p_mode=COMPRESS_S3TC);
Image compressed(int p_mode); /* from the Image::CompressMode enum */
Error decompress();
Image decompressed() const;
@@ -349,8 +273,6 @@ public:
void normalmap_to_xy();
void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest);
- void brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest);
- Image brushed(const Image& p_src, const Image& p_brush, const Point2& p_dest) const;
Rect2 get_used_rect() const;
Image get_rect(const Rect2& p_area) const;
diff --git a/core/image_quantize.cpp b/core/image_quantize.cpp
index f6fe7a88a0..e69de29bb2 100644
--- a/core/image_quantize.cpp
+++ b/core/image_quantize.cpp
@@ -1,365 +0,0 @@
-/*************************************************************************/
-/* image_quantize.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "image.h"
-#include <stdio.h>
-#include "print_string.h"
-#ifdef TOOLS_ENABLED
-#include "set.h"
-#include "sort.h"
-#include "os/os.h"
-
-//#define QUANTIZE_SPEED_OVER_QUALITY
-
-
-Image::MCBlock::MCBlock() {
-
-
-}
-
-Image::MCBlock::MCBlock(BColorPos *p_colors,int p_color_count) {
-
- colors=p_colors;
- color_count=p_color_count;
- min_color.color=BColor(255,255,255,255);
- max_color.color=BColor(0,0,0,0);
- shrink();
-}
-
-int Image::MCBlock::get_longest_axis_index() const {
-
- int max_dist=-1;
- int max_index=0;
-
- for(int i=0;i<4;i++) {
-
- int d = max_color.color.col[i]-min_color.color.col[i];
- if (d>max_dist) {
- max_index=i;
- max_dist=d;
- }
- }
-
- return max_index;
-}
-int Image::MCBlock::get_longest_axis_length() const {
-
- int max_dist=-1;
-
- for(int i=0;i<4;i++) {
-
- int d = max_color.color.col[i]-min_color.color.col[i];
- if (d>max_dist) {
- max_dist=d;
- }
- }
-
- return max_dist;
-}
-
-bool Image::MCBlock::operator<(const MCBlock& p_block) const {
-
- int alen = get_longest_axis_length();
- int blen = p_block.get_longest_axis_length();
- if (alen==blen) {
-
- return colors < p_block.colors;
- } else
- return alen < blen;
-
-}
-
-void Image::MCBlock::shrink() {
-
- min_color=colors[0];
- max_color=colors[0];
-
- for(int i=1;i<color_count;i++) {
-
- for(int j=0;j<4;j++) {
-
- min_color.color.col[j]=MIN(min_color.color.col[j],colors[i].color.col[j]);
- max_color.color.col[j]=MAX(max_color.color.col[j],colors[i].color.col[j]);
- }
- }
-}
-
-
-
-
-void Image::quantize() {
-
- bool has_alpha = detect_alpha()!=ALPHA_NONE;
-
- bool quantize_fast=OS::get_singleton()->has_environment("QUANTIZE_FAST");
-
- convert(FORMAT_RGBA);
-
- ERR_FAIL_COND( format!=FORMAT_RGBA );
-
- DVector<uint8_t> indexed_data;
-
-
- {
- int color_count = data.size()/4;
-
- ERR_FAIL_COND(color_count==0);
-
- Set<MCBlock> block_queue;
-
- DVector<BColorPos> data_colors;
- data_colors.resize(color_count);
-
- DVector<BColorPos>::Write dcw=data_colors.write();
-
- DVector<uint8_t>::Read dr = data.read();
- const BColor * drptr=(const BColor*)&dr[0];
- BColorPos *bcptr=&dcw[0];
-
-
-
- {
- for(int i=0;i<color_count;i++) {
-
- //uint32_t data_ofs=i<<2;
- bcptr[i].color=drptr[i];//BColor(drptr[data_ofs+0],drptr[data_ofs+1],drptr[data_ofs+2],drptr[data_ofs+3]);
- bcptr[i].index=i;
- }
-
- }
-
- //printf("color count: %i\n",color_count);
- /*
- for(int i=0;i<color_count;i++) {
-
- BColor bc = ((BColor*)&wb[0])[i];
- printf("%i - %i,%i,%i,%i\n",i,bc.r,bc.g,bc.b,bc.a);
- }*/
-
- MCBlock initial_block((BColorPos*)&dcw[0],color_count);
-
- block_queue.insert(initial_block);
-
- while( block_queue.size() < 256 && block_queue.back()->get().color_count > 1 ) {
-
- MCBlock longest = block_queue.back()->get();
- //printf("longest: %i (%i)\n",longest.get_longest_axis_index(),longest.get_longest_axis_length());
-
- block_queue.erase(block_queue.back());
-
- BColorPos *first = longest.colors;
- BColorPos *median = longest.colors + (longest.color_count+1)/2;
- BColorPos *end = longest.colors + longest.color_count;
-
-#if 0
- int lai =longest.get_longest_axis_index();
- switch(lai) {
-#if 0
- case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.sort(first,end-first); } break;
- case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.sort(first,end-first); } break;
- case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.sort(first,end-first); } break;
- case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.sort(first,end-first); } break;
-#else
- case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.nth_element(0,end-first,median-first,first); } break;
-#endif
-
- }
-
- //avoid same color from being split in 2
- //search forward and flip
- BColorPos *median_end=median;
- BColorPos *p=median_end+1;
-
- while(p!=end) {
- if (median_end->color==p->color) {
- SWAP(*(median_end+1),*p);
- median_end++;
- }
- p++;
- }
-
- //search backward and flip
- BColorPos *median_begin=median;
- p=median_begin-1;
-
- while(p!=(first-1)) {
- if (median_begin->color==p->color) {
- SWAP(*(median_begin-1),*p);
- median_begin--;
- }
- p--;
- }
-
-
- if (first < median_begin) {
- median=median_begin;
- } else if (median_end < end-1) {
- median=median_end+1;
- } else {
- break; //shouldn't have arrived here, since it means all pixels are equal, but wathever
- }
-
- MCBlock left(first,median-first);
- MCBlock right(median,end-median);
-
- block_queue.insert(left);
- block_queue.insert(right);
-
-#else
- switch(longest.get_longest_axis_index()) {
- case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.nth_element(0,end-first,median-first,first); } break;
-
- }
-
- MCBlock left(first,median-first);
- MCBlock right(median,end-median);
-
- block_queue.insert(left);
- block_queue.insert(right);
-
-
-#endif
-
-
- }
-
- while(block_queue.size() > 256) {
-
- block_queue.erase(block_queue.front());// erase least significant
- }
-
- int res_colors=0;
-
- int comp_size = (has_alpha?4:3);
- indexed_data.resize(color_count + 256*comp_size);
-
- DVector<uint8_t>::Write iw = indexed_data.write();
- uint8_t *iwptr=&iw[0];
- BColor pallete[256];
-
- // print_line("applying quantization - res colors "+itos(block_queue.size()));
-
- while(block_queue.size()) {
-
- const MCBlock &b = block_queue.back()->get();
-
- uint64_t sum[4]={0,0,0,0};
-
- for(int i=0;i<b.color_count;i++) {
-
- sum[0]+=b.colors[i].color.col[0];
- sum[1]+=b.colors[i].color.col[1];
- sum[2]+=b.colors[i].color.col[2];
- sum[3]+=b.colors[i].color.col[3];
- }
-
- BColor c( sum[0]/b.color_count, sum[1]/b.color_count, sum[2]/b.color_count, sum[3]/b.color_count );
-
-
-
- //printf(" %i: %i,%i,%i,%i out of %i\n",res_colors,c.r,c.g,c.b,c.a,b.color_count);
-
-
-
- for(int i=0;i<comp_size;i++) {
- iwptr[ color_count + res_colors * comp_size + i ] = c.col[i];
- }
-
- if (quantize_fast) {
- for(int i=0;i<b.color_count;i++) {
- iwptr[b.colors[i].index]=res_colors;
- }
- } else {
-
- pallete[res_colors]=c;
- }
-
-
- res_colors++;
-
- block_queue.erase(block_queue.back());
-
- }
-
-
- if (!quantize_fast) {
-
- for(int i=0;i<color_count;i++) {
-
- const BColor &c=drptr[i];
- uint8_t best_dist_idx=0;
- uint32_t dist=0xFFFFFFFF;
-
- for(int j=0;j<res_colors;j++) {
-
- const BColor &pc=pallete[j];
- uint32_t d = 0;
- { int16_t v = (int16_t)c.r-(int16_t)pc.r; d+=v*v; }
- { int16_t v = (int16_t)c.g-(int16_t)pc.g; d+=v*v; }
- { int16_t v = (int16_t)c.b-(int16_t)pc.b; d+=v*v; }
- { int16_t v = (int16_t)c.a-(int16_t)pc.a; d+=v*v; }
-
- if (d<=dist) {
- best_dist_idx=j;
- dist=d;
- }
- }
-
-
- iwptr[ i ] = best_dist_idx;
-
- }
- }
-
- //iw = DVector<uint8_t>::Write();
- //dr = DVector<uint8_t>::Read();
- //wb = DVector<uint8_t>::Write();
- }
-
- print_line(itos(indexed_data.size()));
- data=indexed_data;
- format=has_alpha?FORMAT_INDEXED_ALPHA:FORMAT_INDEXED;
-
-
-} //do none
-
-
-
-#else
-
-
-void Image::quantize() {} //do none
-
-
-#endif
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index c9bd38c654..13817b762d 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -1060,7 +1060,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
if (buf) {
encode_uint32(image.get_format(),&buf[0]);
- encode_uint32(image.get_mipmaps(),&buf[4]);
+ encode_uint32(image.has_mipmaps(),&buf[4]);
encode_uint32(image.get_width(),&buf[8]);
encode_uint32(image.get_height(),&buf[12]);
int ds=data.size();
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 0544fd6ba8..8db06bf3d9 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -74,29 +74,6 @@ enum {
IMAGE_ENCODING_LOSSLESS=2,
IMAGE_ENCODING_LOSSY=3,
- IMAGE_FORMAT_GRAYSCALE=0,
- IMAGE_FORMAT_INTENSITY=1,
- IMAGE_FORMAT_GRAYSCALE_ALPHA=2,
- IMAGE_FORMAT_RGB=3,
- IMAGE_FORMAT_RGBA=4,
- IMAGE_FORMAT_INDEXED=5,
- IMAGE_FORMAT_INDEXED_ALPHA=6,
- IMAGE_FORMAT_BC1=7,
- IMAGE_FORMAT_BC2=8,
- IMAGE_FORMAT_BC3=9,
- IMAGE_FORMAT_BC4=10,
- IMAGE_FORMAT_BC5=11,
- IMAGE_FORMAT_PVRTC2=12,
- IMAGE_FORMAT_PVRTC2_ALPHA=13,
- IMAGE_FORMAT_PVRTC4=14,
- IMAGE_FORMAT_PVRTC4_ALPHA=15,
- IMAGE_FORMAT_ETC=16,
- IMAGE_FORMAT_ATC=17,
- IMAGE_FORMAT_ATC_ALPHA_EXPLICIT=18,
- IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED=19,
- IMAGE_FORMAT_CUSTOM=30,
-
-
OBJECT_EMPTY=0,
OBJECT_EXTERNAL_RESOURCE=1,
OBJECT_INTERNAL_RESOURCE=2,
@@ -269,38 +246,22 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t height = f->get_32();
uint32_t mipmaps = f->get_32();
uint32_t format = f->get_32();
- Image::Format fmt;
- switch(format) {
-
- case IMAGE_FORMAT_GRAYSCALE: { fmt=Image::FORMAT_GRAYSCALE; } break;
- case IMAGE_FORMAT_INTENSITY: { fmt=Image::FORMAT_INTENSITY; } break;
- case IMAGE_FORMAT_GRAYSCALE_ALPHA: { fmt=Image::FORMAT_GRAYSCALE_ALPHA; } break;
- case IMAGE_FORMAT_RGB: { fmt=Image::FORMAT_RGB; } break;
- case IMAGE_FORMAT_RGBA: { fmt=Image::FORMAT_RGBA; } break;
- case IMAGE_FORMAT_INDEXED: { fmt=Image::FORMAT_INDEXED; } break;
- case IMAGE_FORMAT_INDEXED_ALPHA: { fmt=Image::FORMAT_INDEXED_ALPHA; } break;
- case IMAGE_FORMAT_BC1: { fmt=Image::FORMAT_BC1; } break;
- case IMAGE_FORMAT_BC2: { fmt=Image::FORMAT_BC2; } break;
- case IMAGE_FORMAT_BC3: { fmt=Image::FORMAT_BC3; } break;
- case IMAGE_FORMAT_BC4: { fmt=Image::FORMAT_BC4; } break;
- case IMAGE_FORMAT_BC5: { fmt=Image::FORMAT_BC5; } break;
- case IMAGE_FORMAT_PVRTC2: { fmt=Image::FORMAT_PVRTC2; } break;
- case IMAGE_FORMAT_PVRTC2_ALPHA: { fmt=Image::FORMAT_PVRTC2_ALPHA; } break;
- case IMAGE_FORMAT_PVRTC4: { fmt=Image::FORMAT_PVRTC4; } break;
- case IMAGE_FORMAT_PVRTC4_ALPHA: { fmt=Image::FORMAT_PVRTC4_ALPHA; } break;
- case IMAGE_FORMAT_ETC: { fmt=Image::FORMAT_ETC; } break;
- case IMAGE_FORMAT_ATC: { fmt=Image::FORMAT_ATC; } break;
- case IMAGE_FORMAT_ATC_ALPHA_EXPLICIT: { fmt=Image::FORMAT_ATC_ALPHA_EXPLICIT; } break;
- case IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED: { fmt=Image::FORMAT_ATC_ALPHA_INTERPOLATED; } break;
- case IMAGE_FORMAT_CUSTOM: { fmt=Image::FORMAT_CUSTOM; } break;
- default: {
-
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
+ const uint32_t format_version_shift=24;
+ const uint32_t format_version_mask=format_version_shift-1;
+
+ uint32_t format_version = format>>format_version_shift;
+
+ const uint32_t current_version = 0;
+ if (format_version>current_version) {
+ ERR_PRINT("Format version for encoded binary image is too new");
+ return ERR_PARSE_ERROR;
}
+ Image::Format fmt=Image::Format(format&format_version_mask); //if format changes, we can add a compatibility bit on top
+
+
uint32_t datalen = f->get_32();
DVector<uint8_t> imgdata;
@@ -1599,7 +1560,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
int encoding=IMAGE_ENCODING_RAW;
float quality=0.7;
- if (val.get_format() <= Image::FORMAT_INDEXED_ALPHA) {
+ if (!val.is_compressed()) {
//can only compress uncompressed stuff
if (p_hint.hint==PROPERTY_HINT_IMAGE_COMPRESS_LOSSY && Image::lossy_packer) {
@@ -1621,33 +1582,8 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_32(val.get_width());
f->store_32(val.get_height());
- f->store_32(val.get_mipmaps());
- switch(val.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: f->store_32(IMAGE_FORMAT_GRAYSCALE ); break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
- case Image::FORMAT_INTENSITY: f->store_32(IMAGE_FORMAT_INTENSITY ); break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
- case Image::FORMAT_GRAYSCALE_ALPHA: f->store_32(IMAGE_FORMAT_GRAYSCALE_ALPHA ); break; ///< two bytes per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255. alpha 0-255
- case Image::FORMAT_RGB: f->store_32(IMAGE_FORMAT_RGB ); break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B
- case Image::FORMAT_RGBA: f->store_32(IMAGE_FORMAT_RGBA ); break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B: f->store_32(IMAGE_FORMAT_ ); break; one byte A
- case Image::FORMAT_INDEXED: f->store_32(IMAGE_FORMAT_INDEXED ); break; ///< index byte 0-256: f->store_32(IMAGE_FORMAT_ ); break; and after image end: f->store_32(IMAGE_FORMAT_ ); break; 256*3 bytes of palette
- case Image::FORMAT_INDEXED_ALPHA: f->store_32(IMAGE_FORMAT_INDEXED_ALPHA ); break; ///< index byte 0-256: f->store_32(IMAGE_FORMAT_ ); break; and after image end: f->store_32(IMAGE_FORMAT_ ); break; 256*4 bytes of palette (alpha)
- case Image::FORMAT_BC1: f->store_32(IMAGE_FORMAT_BC1 ); break; // DXT1
- case Image::FORMAT_BC2: f->store_32(IMAGE_FORMAT_BC2 ); break; // DXT3
- case Image::FORMAT_BC3: f->store_32(IMAGE_FORMAT_BC3 ); break; // DXT5
- case Image::FORMAT_BC4: f->store_32(IMAGE_FORMAT_BC4 ); break; // ATI1
- case Image::FORMAT_BC5: f->store_32(IMAGE_FORMAT_BC5 ); break; // ATI2
- case Image::FORMAT_PVRTC2: f->store_32(IMAGE_FORMAT_PVRTC2 ); break;
- case Image::FORMAT_PVRTC2_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC2_ALPHA ); break;
- case Image::FORMAT_PVRTC4: f->store_32(IMAGE_FORMAT_PVRTC4 ); break;
- case Image::FORMAT_PVRTC4_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC4_ALPHA ); break;
- case Image::FORMAT_ETC: f->store_32(IMAGE_FORMAT_ETC); break;
- case Image::FORMAT_ATC: f->store_32(IMAGE_FORMAT_ATC); break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: f->store_32(IMAGE_FORMAT_ATC_ALPHA_EXPLICIT); break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: f->store_32(IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED); break;
- case Image::FORMAT_CUSTOM: f->store_32(IMAGE_FORMAT_CUSTOM ); break;
- default: {}
-
- }
+ f->store_32(val.has_mipmaps());
+ f->store_32(val.get_format()); //if format changes we can add a compatibility version bit
int dlen = val.get_data().size();
f->store_32(dlen);
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
index 44fbaf02ac..bbd395f21a 100644
--- a/core/io/resource_format_xml.cpp
+++ b/core/io/resource_format_xml.cpp
@@ -553,39 +553,39 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name)
Image::Format imgformat;
-
+/*
if (format=="grayscale") {
- imgformat=Image::FORMAT_GRAYSCALE;
+ imgformat=Image::FORMAT_L8;
} else if (format=="intensity") {
imgformat=Image::FORMAT_INTENSITY;
} else if (format=="grayscale_alpha") {
- imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
+ imgformat=Image::FORMAT_LA8;
} else if (format=="rgb") {
- imgformat=Image::FORMAT_RGB;
+ imgformat=Image::FORMAT_RGB8;
} else if (format=="rgba") {
- imgformat=Image::FORMAT_RGBA;
+ imgformat=Image::FORMAT_RGBA8;
} else if (format=="indexed") {
imgformat=Image::FORMAT_INDEXED;
} else if (format=="indexed_alpha") {
imgformat=Image::FORMAT_INDEXED_ALPHA;
} else if (format=="bc1") {
- imgformat=Image::FORMAT_BC1;
+ imgformat=Image::FORMAT_DXT1;
} else if (format=="bc2") {
- imgformat=Image::FORMAT_BC2;
+ imgformat=Image::FORMAT_DXT3;
} else if (format=="bc3") {
- imgformat=Image::FORMAT_BC3;
+ imgformat=Image::FORMAT_DXT5;
} else if (format=="bc4") {
- imgformat=Image::FORMAT_BC4;
+ imgformat=Image::FORMAT_ATI1;
} else if (format=="bc5") {
- imgformat=Image::FORMAT_BC5;
+ imgformat=Image::FORMAT_ATI2;
} else if (format=="pvrtc2") {
imgformat=Image::FORMAT_PVRTC2;
} else if (format=="pvrtc2a") {
- imgformat=Image::FORMAT_PVRTC2_ALPHA;
+ imgformat=Image::FORMAT_PVRTC2A;
} else if (format=="pvrtc4") {
imgformat=Image::FORMAT_PVRTC4;
} else if (format=="pvrtc4a") {
- imgformat=Image::FORMAT_PVRTC4_ALPHA;
+ imgformat=Image::FORMAT_PVRTC4A;
} else if (format=="etc") {
imgformat=Image::FORMAT_ETC;
} else if (format=="atc") {
@@ -599,7 +599,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name)
} else {
ERR_FAIL_V( ERR_FILE_CORRUPT );
- }
+ }*/
int datasize;
@@ -614,13 +614,6 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name)
return OK;
};
- if (imgformat==Image::FORMAT_CUSTOM) {
-
- datasize=custom_size;
- } else {
-
- datasize = Image::get_image_data_size(h,w,imgformat,mipmaps);
- }
if (datasize==0) {
//r_v = Image(w, h, imgformat);
@@ -2186,33 +2179,33 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V
params+="encoding=\"raw\"";
params+=" width=\""+itos(img.get_width())+"\"";
params+=" height=\""+itos(img.get_height())+"\"";
- params+=" mipmaps=\""+itos(img.get_mipmaps())+"\"";
-
+ params+=" mipmaps=\""+itos(img.has_mipmaps())+"\"";
+/*
switch(img.get_format()) {
- case Image::FORMAT_GRAYSCALE: params+=" format=\"grayscale\""; break;
+ case Image::FORMAT_L8: params+=" format=\"grayscale\""; break;
case Image::FORMAT_INTENSITY: params+=" format=\"intensity\""; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: params+=" format=\"grayscale_alpha\""; break;
- case Image::FORMAT_RGB: params+=" format=\"rgb\""; break;
- case Image::FORMAT_RGBA: params+=" format=\"rgba\""; break;
+ case Image::FORMAT_LA8: params+=" format=\"grayscale_alpha\""; break;
+ case Image::FORMAT_RGB8: params+=" format=\"rgb\""; break;
+ case Image::FORMAT_RGBA8: params+=" format=\"rgba\""; break;
case Image::FORMAT_INDEXED : params+=" format=\"indexed\""; break;
case Image::FORMAT_INDEXED_ALPHA: params+=" format=\"indexed_alpha\""; break;
- case Image::FORMAT_BC1: params+=" format=\"bc1\""; break;
- case Image::FORMAT_BC2: params+=" format=\"bc2\""; break;
- case Image::FORMAT_BC3: params+=" format=\"bc3\""; break;
- case Image::FORMAT_BC4: params+=" format=\"bc4\""; break;
- case Image::FORMAT_BC5: params+=" format=\"bc5\""; break;
+ case Image::FORMAT_DXT1: params+=" format=\"bc1\""; break;
+ case Image::FORMAT_DXT3: params+=" format=\"bc2\""; break;
+ case Image::FORMAT_DXT5: params+=" format=\"bc3\""; break;
+ case Image::FORMAT_ATI1: params+=" format=\"bc4\""; break;
+ case Image::FORMAT_ATI2: params+=" format=\"bc5\""; break;
case Image::FORMAT_PVRTC2: params+=" format=\"pvrtc2\""; break;
- case Image::FORMAT_PVRTC2_ALPHA: params+=" format=\"pvrtc2a\""; break;
+ case Image::FORMAT_PVRTC2A: params+=" format=\"pvrtc2a\""; break;
case Image::FORMAT_PVRTC4: params+=" format=\"pvrtc4\""; break;
- case Image::FORMAT_PVRTC4_ALPHA: params+=" format=\"pvrtc4a\""; break;
+ case Image::FORMAT_PVRTC4A: params+=" format=\"pvrtc4a\""; break;
case Image::FORMAT_ETC: params+=" format=\"etc\""; break;
case Image::FORMAT_ATC: params+=" format=\"atc\""; break;
case Image::FORMAT_ATC_ALPHA_EXPLICIT: params+=" format=\"atcae\""; break;
case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params+=" format=\"atcai\""; break;
case Image::FORMAT_CUSTOM: params+=" format=\"custom\" custom_size=\""+itos(img.get_data().size())+"\""; break;
default: {}
- }
+ }*/
} break;
case Variant::NODE_PATH: type="node_path"; break;
case Variant::OBJECT: {
diff --git a/core/rid.cpp b/core/rid.cpp
index 219c2f0e69..1b7a58313a 100644
--- a/core/rid.cpp
+++ b/core/rid.cpp
@@ -28,18 +28,16 @@
/*************************************************************************/
#include "rid.h"
-static SafeRefCount current_id;
-void RID_OwnerBase::init_rid() {
+RID_Data::~RID_Data() {
- current_id.init(1);
}
-ID RID_OwnerBase::new_ID() {
+SafeRefCount RID_OwnerBase::refcount;
- ID id = current_id.refval();
- return id;
-}
+void RID_OwnerBase::init_rid() {
+ refcount.init();
+}
diff --git a/core/rid.h b/core/rid.h
index 2de6956096..85a69ac0ef 100644
--- a/core/rid.h
+++ b/core/rid.h
@@ -33,183 +33,189 @@
#include "safe_refcount.h"
#include "typedefs.h"
#include "os/memory.h"
-#include "hash_map.h"
+#include "set.h"
#include "list.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class RID_OwnerBase;
-typedef uint32_t ID;
+class RID_Data {
+
+friend class RID_OwnerBase;
+
+#ifndef DEBUG_ENABLED
+ RID_OwnerBase *_owner;
+#endif
+ uint32_t _id;
+public:
+ _FORCE_INLINE_ uint32_t get_id() const { return _id; }
+
+ virtual ~RID_Data();
+};
+
class RID {
friend class RID_OwnerBase;
- ID _id;
- RID_OwnerBase *owner;
+
+ mutable RID_Data *_data;
+
public:
- _FORCE_INLINE_ ID get_id() const { return _id; }
- bool operator==(const RID& p_rid) const {
+ _FORCE_INLINE_ RID_Data *get_data() const { return _data; }
+
+ _FORCE_INLINE_ bool operator==(const RID& p_rid) const {
- return _id==p_rid._id;
+ return _data==p_rid._data;
}
_FORCE_INLINE_ bool operator<(const RID& p_rid) const {
- return _id < p_rid._id;
+ return _data < p_rid._data;
}
_FORCE_INLINE_ bool operator<=(const RID& p_rid) const {
- return _id <= p_rid._id;
+ return _data <= p_rid._data;
}
_FORCE_INLINE_ bool operator>(const RID& p_rid) const {
- return _id > p_rid._id;
+ return _data > p_rid._data;
}
- bool operator!=(const RID& p_rid) const {
+ _FORCE_INLINE_ bool operator!=(const RID& p_rid) const {
- return _id!=p_rid._id;
+ return _data!=p_rid._data;
}
- _FORCE_INLINE_ bool is_valid() const { return _id>0; }
+ _FORCE_INLINE_ bool is_valid() const { return _data!=NULL; }
- operator const void*() const {
- return is_valid() ? this : 0;
- };
+ _FORCE_INLINE_ uint32_t get_id() const { return _data?_data->get_id():0; }
_FORCE_INLINE_ RID() {
- _id = 0;
- owner=0;
+ _data=NULL;
}
+
};
class RID_OwnerBase {
protected:
-friend class RID;
- void set_id(RID& p_rid, ID p_id) const { p_rid._id=p_id; }
- void set_ownage(RID& p_rid) const { p_rid.owner=const_cast<RID_OwnerBase*>(this); }
- ID new_ID();
+
+ static SafeRefCount refcount;
+ _FORCE_INLINE_ void _set_data(RID& p_rid, RID_Data* p_data) {
+ p_rid._data=p_data;
+ refcount.ref();
+ p_data->_id=refcount.get();
+#ifndef DEBUG_ENABLED
+ p_data->_owner=this;
+#endif
+ }
+
+#ifndef DEBUG_ENABLED
+
+ _FORCE_INLINE_ bool _is_owner(RID& p_rid) const {
+
+ return this==p_rid._owner;
+
+ }
+
+ _FORCE_INLINE_ void _remove_owner(RID& p_rid) {
+
+ return p_rid._owner=NULL;
+
+ }
+#
+#endif
+
+
public:
- virtual bool owns(const RID& p_rid) const=0;
- virtual void get_owned_list(List<RID> *p_owned) const=0;
- static void init_rid();
+ virtual void get_owned_list(List<RID> *p_owned)=0;
+ static void init_rid();
virtual ~RID_OwnerBase() {}
};
-template<class T,bool thread_safe=false>
+template<class T>
class RID_Owner : public RID_OwnerBase {
public:
-
- typedef void (*ReleaseNotifyFunc)(void*user,T *p_data);
-private:
-
- Mutex *mutex;
- mutable HashMap<ID,T*> id_map;
-
+#ifdef DEBUG_ENABLED
+ mutable Set<RID_Data*> id_map;
+#endif
public:
- RID make_rid(T * p_data) {
+ _FORCE_INLINE_ RID make_rid(T * p_data) {
- if (thread_safe) {
- mutex->lock();
- }
- ID id = new_ID();
- id_map[id]=p_data;
RID rid;
- set_id(rid,id);
- set_ownage(rid);
+ _set_data(rid,p_data);
- if (thread_safe) {
- mutex->unlock();
- }
+#ifdef DEBUG_ENABLED
+ id_map.insert(p_data) ;
+#endif
return rid;
}
_FORCE_INLINE_ T * get(const RID& p_rid) {
- if (thread_safe) {
- mutex->lock();
- }
-
- T**elem = id_map.getptr(p_rid.get_id());
+#ifdef DEBUG_ENABLED
- if (thread_safe) {
- mutex->unlock();
- }
-
- ERR_FAIL_COND_V(!elem,NULL);
-
- return *elem;
+ ERR_FAIL_COND_V(!p_rid.is_valid(),NULL);
+ ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()),NULL);
+#endif
+ return static_cast<T*>(p_rid.get_data());
}
- virtual bool owns(const RID& p_rid) const {
+ _FORCE_INLINE_ T * getornull(const RID& p_rid) {
- if (thread_safe) {
- mutex->lock();
- }
-
- T**elem = id_map.getptr(p_rid.get_id());
+#ifdef DEBUG_ENABLED
- if (thread_safe) {
- mutex->lock();
+ if (p_rid.get_data()) {
+ ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()),NULL);
}
+#endif
+ return static_cast<T*>(p_rid.get_data());
- return elem!=NULL;
}
- virtual void free(RID p_rid) {
+ _FORCE_INLINE_ bool owns(const RID& p_rid) const {
- if (thread_safe) {
- mutex->lock();
- }
- ERR_FAIL_COND(!owns(p_rid));
- id_map.erase(p_rid.get_id());
+ if (p_rid.get_data()==NULL)
+ return false;
+#ifdef DEBUG_ENABLED
+ return id_map.has(p_rid.get_data());
+#else
+ return _is_owner(p_rid);
+#endif
}
- virtual void get_owned_list(List<RID> *p_owned) const {
- if (thread_safe) {
- mutex->lock();
- }
+ void free(RID p_rid) {
- const ID*id=NULL;
- while((id=id_map.next(id))) {
+#ifdef DEBUG_ENABLED
+ id_map.erase(p_rid.get_data());
+#else
+ _remove_owner(p_rid);
+#endif
+ }
- RID rid;
- set_id(rid,*id);
- set_ownage(rid);
- p_owned->push_back(rid);
+ void get_owned_list(List<RID> *p_owned) {
- }
- if (thread_safe) {
- mutex->lock();
- }
- }
- RID_Owner() {
+#ifdef DEBUG_ENABLED
- if (thread_safe) {
-
- mutex = Mutex::create();
+ for (typename Set<RID_Data*>::Element *E=id_map.front();E;E=E->next()) {
+ RID r;
+ _set_data(r,static_cast<T*>(E->get()));
+ p_owned->push_back(r);
}
+#endif
}
-
- ~RID_Owner() {
-
- if (thread_safe) {
-
- memdelete(mutex);
- }
- }
};
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 51cd4c2399..bfbb95085e 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -617,13 +617,9 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_PTR0R(Image,get_width);
VCALL_PTR0R(Image,get_height);
VCALL_PTR0R(Image,empty);
- VCALL_PTR3R(Image,get_pixel);
- VCALL_PTR4(Image, put_pixel);
VCALL_PTR0R(Image,get_used_rect);
- VCALL_PTR3R(Image,brushed);
VCALL_PTR1R(Image,load);
VCALL_PTR1R(Image,save_png);
- VCALL_PTR3(Image,brush_transfer);
VCALL_PTR1R(Image,get_rect);
VCALL_PTR1R(Image,compressed);
VCALL_PTR0R(Image,decompressed);
@@ -1526,12 +1522,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(IMAGE, INT, Image, get_width, varray());
ADDFUNC0(IMAGE, INT, Image, get_height, varray());
ADDFUNC0(IMAGE, BOOL, Image, empty, varray());
- ADDFUNC3(IMAGE, COLOR, Image, get_pixel, INT, "x", INT, "y", INT, "mipmap_level", varray(0));
- ADDFUNC4(IMAGE, NIL, Image, put_pixel, INT, "x", INT, "y", COLOR, "color", INT, "mipmap_level", varray(0));
- ADDFUNC3(IMAGE, IMAGE, Image, brushed, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
ADDFUNC1(IMAGE, INT, Image, load, STRING, "path", varray(0));
ADDFUNC1(IMAGE, INT, Image, save_png, STRING, "path", varray(0));
- ADDFUNC3(IMAGE, NIL, Image, brush_transfer, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
ADDFUNC0(IMAGE, RECT2, Image, get_used_rect, varray(0));
ADDFUNC1(IMAGE, IMAGE, Image, get_rect, RECT2, "area", varray(0));
ADDFUNC1(IMAGE, IMAGE, Image, compressed, INT, "format", varray(0));
@@ -1788,34 +1780,53 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
_VariantCall::add_constant(Variant::INPUT_EVENT,"ACTION",InputEvent::ACTION);
- _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_BC",Image::COMPRESS_BC);
+ _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_16BIT",Image::COMPRESS_16BIT);
+ _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_S3TC",Image::COMPRESS_S3TC);
_VariantCall::add_constant(Variant::IMAGE,"COMPRESS_PVRTC2",Image::COMPRESS_PVRTC2);
_VariantCall::add_constant(Variant::IMAGE,"COMPRESS_PVRTC4",Image::COMPRESS_PVRTC4);
_VariantCall::add_constant(Variant::IMAGE,"COMPRESS_ETC",Image::COMPRESS_ETC);
-
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_GRAYSCALE",Image::FORMAT_GRAYSCALE);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_INTENSITY",Image::FORMAT_INTENSITY);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_GRAYSCALE_ALPHA",Image::FORMAT_GRAYSCALE_ALPHA);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGB",Image::FORMAT_RGB);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA",Image::FORMAT_RGBA);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_INDEXED",Image::FORMAT_INDEXED);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_INDEXED_ALPHA",Image::FORMAT_INDEXED_ALPHA);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_YUV_422",Image::FORMAT_YUV_422);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_YUV_444",Image::FORMAT_YUV_444);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC1",Image::FORMAT_BC1);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC2",Image::FORMAT_BC2);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC3",Image::FORMAT_BC3);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC4",Image::FORMAT_BC4);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC5",Image::FORMAT_BC5);
+ _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_ETC2",Image::COMPRESS_ETC2);
+
+
+
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_L8",Image::FORMAT_L8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_LA8",Image::FORMAT_LA8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_R8",Image::FORMAT_R8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RG8",Image::FORMAT_RG8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGB8",Image::FORMAT_RGB8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA8",Image::FORMAT_RGBA8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGB565",Image::FORMAT_RGB565);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA4444",Image::FORMAT_RGBA4444);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA5551",Image::FORMAT_DXT1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RF",Image::FORMAT_RF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGF",Image::FORMAT_RGF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBF",Image::FORMAT_RGBF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBAF",Image::FORMAT_RGBAF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RH",Image::FORMAT_RH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGH",Image::FORMAT_RGH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBH",Image::FORMAT_RGBH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBAH",Image::FORMAT_RGBAH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_DXT1",Image::FORMAT_DXT1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_DXT3",Image::FORMAT_DXT3);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_DXT5",Image::FORMAT_DXT5);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATI1",Image::FORMAT_ATI1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATI2",Image::FORMAT_ATI2);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BPTC_RGBA",Image::FORMAT_BPTC_RGBA);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BPTC_RGBF",Image::FORMAT_BPTC_RGBF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BPTC_RGBFU",Image::FORMAT_BPTC_RGBFU);
_VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC2",Image::FORMAT_PVRTC2);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC2_ALPHA",Image::FORMAT_PVRTC2_ALPHA);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC2A",Image::FORMAT_PVRTC2A);
_VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC4",Image::FORMAT_PVRTC4);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC4_ALPHA",Image::FORMAT_PVRTC4_ALPHA);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC4A",Image::FORMAT_PVRTC4A);
_VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC",Image::FORMAT_ETC);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATC",Image::FORMAT_ATC);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATC_ALPHA_EXPLICIT",Image::FORMAT_ATC_ALPHA_EXPLICIT);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATC_ALPHA_INTERPOLATED",Image::FORMAT_ATC_ALPHA_INTERPOLATED);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_CUSTOM",Image::FORMAT_CUSTOM);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_R11",Image::FORMAT_ETC2_R11);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_R11S",Image::FORMAT_ETC2_R11S);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RG11",Image::FORMAT_ETC2_RG11);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RG11S",Image::FORMAT_ETC2_RG11S);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RGB8",Image::FORMAT_ETC2_RGB8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RGBA8",Image::FORMAT_ETC2_RGBA8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RGB8A1",Image::FORMAT_ETC2_RGB8A1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_MAX",Image::FORMAT_MAX);
_VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_NEAREST",Image::INTERPOLATE_NEAREST);
_VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_BILINEAR",Image::INTERPOLATE_BILINEAR);
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 6b3828a572..32358e1180 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -755,8 +755,17 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
}
get_token(p_stream,token,line,r_err_str);
- if (token.type!=TK_NUMBER) {
- r_err_str="Expected number (mipmaps)";
+
+ bool has_mipmaps=false;
+
+ if (token.type==TK_NUMBER) {
+ has_mipmaps=bool(token.value);
+ } else if (token.type==TK_IDENTIFIER && String(token.value)=="true") {
+ has_mipmaps=true;
+ } else if (token.type==TK_IDENTIFIER && String(token.value)=="false") {
+ has_mipmaps=false;
+ } else {
+ r_err_str="Expected number/true/false (mipmaps)";
return ERR_PARSE_ERROR;
}
@@ -778,32 +787,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
String sformat=token.value;
- Image::Format format;
-
- if (sformat=="GRAYSCALE") format=Image::FORMAT_GRAYSCALE;
- else if (sformat=="INTENSITY") format=Image::FORMAT_INTENSITY;
- else if (sformat=="GRAYSCALE_ALPHA") format=Image::FORMAT_GRAYSCALE_ALPHA;
- else if (sformat=="RGB") format=Image::FORMAT_RGB;
- else if (sformat=="RGBA") format=Image::FORMAT_RGBA;
- else if (sformat=="INDEXED") format=Image::FORMAT_INDEXED;
- else if (sformat=="INDEXED_ALPHA") format=Image::FORMAT_INDEXED_ALPHA;
- else if (sformat=="BC1") format=Image::FORMAT_BC1;
- else if (sformat=="BC2") format=Image::FORMAT_BC2;
- else if (sformat=="BC3") format=Image::FORMAT_BC3;
- else if (sformat=="BC4") format=Image::FORMAT_BC4;
- else if (sformat=="BC5") format=Image::FORMAT_BC5;
- else if (sformat=="PVRTC2") format=Image::FORMAT_PVRTC2;
- else if (sformat=="PVRTC2_ALPHA") format=Image::FORMAT_PVRTC2_ALPHA;
- else if (sformat=="PVRTC4") format=Image::FORMAT_PVRTC4;
- else if (sformat=="PVRTC4_ALPHA") format=Image::FORMAT_PVRTC4_ALPHA;
- else if (sformat=="ATC") format=Image::FORMAT_ATC;
- else if (sformat=="ATC_ALPHA_EXPLICIT") format=Image::FORMAT_ATC_ALPHA_EXPLICIT;
- else if (sformat=="ATC_ALPHA_INTERPOLATED") format=Image::FORMAT_ATC_ALPHA_INTERPOLATED;
- else if (sformat=="CUSTOM") format=Image::FORMAT_CUSTOM;
- else {
- r_err_str="Invalid image format: '"+sformat+"'";
+ Image::Format format=Image::FORMAT_MAX;
+
+ for(int i=0;i<Image::FORMAT_MAX;i++) {
+ if (Image::get_format_name(format)==sformat) {
+ format=Image::Format(i);
+ }
+ }
+
+ if (format==Image::FORMAT_MAX) {
+ r_err_str="Unknown image format: "+String(sformat);
return ERR_PARSE_ERROR;
- };
+ }
int len = Image::get_image_data_size(width,height,format,mipmaps);
@@ -1986,35 +1981,8 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
String imgstr="Image( ";
imgstr+=itos(img.get_width());
imgstr+=", "+itos(img.get_height());
- imgstr+=", "+itos(img.get_mipmaps());
- imgstr+=", ";
-
- switch(img.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: imgstr+="GRAYSCALE"; break;
- case Image::FORMAT_INTENSITY: imgstr+="INTENSITY"; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: imgstr+="GRAYSCALE_ALPHA"; break;
- case Image::FORMAT_RGB: imgstr+="RGB"; break;
- case Image::FORMAT_RGBA: imgstr+="RGBA"; break;
- case Image::FORMAT_INDEXED : imgstr+="INDEXED"; break;
- case Image::FORMAT_INDEXED_ALPHA: imgstr+="INDEXED_ALPHA"; break;
- case Image::FORMAT_BC1: imgstr+="BC1"; break;
- case Image::FORMAT_BC2: imgstr+="BC2"; break;
- case Image::FORMAT_BC3: imgstr+="BC3"; break;
- case Image::FORMAT_BC4: imgstr+="BC4"; break;
- case Image::FORMAT_BC5: imgstr+="BC5"; break;
- case Image::FORMAT_PVRTC2: imgstr+="PVRTC2"; break;
- case Image::FORMAT_PVRTC2_ALPHA: imgstr+="PVRTC2_ALPHA"; break;
- case Image::FORMAT_PVRTC4: imgstr+="PVRTC4"; break;
- case Image::FORMAT_PVRTC4_ALPHA: imgstr+="PVRTC4_ALPHA"; break;
- case Image::FORMAT_ETC: imgstr+="ETC"; break;
- case Image::FORMAT_ATC: imgstr+="ATC"; break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: imgstr+="ATC_ALPHA_EXPLICIT"; break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: imgstr+="ATC_ALPHA_INTERPOLATED"; break;
- case Image::FORMAT_CUSTOM: imgstr+="CUSTOM"; break;
- default: {}
- }
-
+ imgstr+=", "+String(img.has_mipmaps()?"true":"false");
+ imgstr+=", "+Image::get_format_name(img.get_format());
String s;
diff --git a/doc/base/classes.xml b/doc/base/classes.xml
index c18cba09a4..9453cdc77d 100644
--- a/doc/base/classes.xml
+++ b/doc/base/classes.xml
@@ -16324,15 +16324,15 @@
</constant>
<constant name="COMPRESS_ETC" value="3">
</constant>
- <constant name="FORMAT_GRAYSCALE" value="0">
+ <constant name="FORMAT_L8" value="0">
</constant>
<constant name="FORMAT_INTENSITY" value="1">
</constant>
- <constant name="FORMAT_GRAYSCALE_ALPHA" value="2">
+ <constant name="FORMAT_LA8" value="2">
</constant>
- <constant name="FORMAT_RGB" value="3">
+ <constant name="FORMAT_RGB8" value="3">
</constant>
- <constant name="FORMAT_RGBA" value="4">
+ <constant name="FORMAT_RGBA8" value="4">
</constant>
<constant name="FORMAT_INDEXED" value="5">
</constant>
@@ -16342,23 +16342,23 @@
</constant>
<constant name="FORMAT_YUV_444" value="8">
</constant>
- <constant name="FORMAT_BC1" value="9">
+ <constant name="FORMAT_DXT1" value="9">
</constant>
- <constant name="FORMAT_BC2" value="10">
+ <constant name="FORMAT_DXT3" value="10">
</constant>
- <constant name="FORMAT_BC3" value="11">
+ <constant name="FORMAT_DXT5" value="11">
</constant>
- <constant name="FORMAT_BC4" value="12">
+ <constant name="FORMAT_ATI1" value="12">
</constant>
- <constant name="FORMAT_BC5" value="13">
+ <constant name="FORMAT_ATI2" value="13">
</constant>
<constant name="FORMAT_PVRTC2" value="14">
</constant>
- <constant name="FORMAT_PVRTC2_ALPHA" value="15">
+ <constant name="FORMAT_PVRTC2A" value="15">
</constant>
<constant name="FORMAT_PVRTC4" value="16">
</constant>
- <constant name="FORMAT_PVRTC4_ALPHA" value="17">
+ <constant name="FORMAT_PVRTC4A" value="17">
</constant>
<constant name="FORMAT_ETC" value="18">
</constant>
diff --git a/drivers/SCsub b/drivers/SCsub
index 8243483e17..7420d57604 100644
--- a/drivers/SCsub
+++ b/drivers/SCsub
@@ -12,7 +12,7 @@ SConscript('unix/SCsub');
SConscript('alsa/SCsub');
SConscript('pulseaudio/SCsub');
SConscript('windows/SCsub');
-SConscript('gles2/SCsub');
+SConscript('gles3/SCsub');
SConscript('gl_context/SCsub');
SConscript('pnm/SCsub');
diff --git a/drivers/dds/texture_loader_dds.cpp b/drivers/dds/texture_loader_dds.cpp
index 0cc84f02f7..23fb9f48f7 100644
--- a/drivers/dds/texture_loader_dds.cpp
+++ b/drivers/dds/texture_loader_dds.cpp
@@ -74,21 +74,20 @@ struct DDSFormatInfo {
static const DDSFormatInfo dds_format_info[DDS_MAX]={
- {"DXT1",true,false,4,8,Image::FORMAT_BC1},
- {"DXT3",true,false,4,16,Image::FORMAT_BC2},
- {"DXT5",true,false,4,16,Image::FORMAT_BC3},
- {"ATI1",true,false,4,8,Image::FORMAT_BC4},
- {"ATI2",true,false,4,16,Image::FORMAT_BC5},
- {"BGRA8",false,false,1,4,Image::FORMAT_RGBA},
- {"BGR8",false,false,1,3,Image::FORMAT_RGB},
- {"RGBA8",false,false,1,4,Image::FORMAT_RGBA},
- {"RGB8",false,false,1,3,Image::FORMAT_RGB},
- {"BGR5A1",false,false,1,2,Image::FORMAT_RGBA},
- {"BGR565",false,false,1,2,Image::FORMAT_RGB},
- {"BGR10A2",false,false,1,4,Image::FORMAT_RGBA},
- {"INDEXED",false,true,1,1,Image::FORMAT_INDEXED},
- {"GRAYSCALE",false,false,1,1,Image::FORMAT_GRAYSCALE},
- {"GRAYSCALE_ALPHA",false,false,1,2,Image::FORMAT_GRAYSCALE_ALPHA}
+ {"DXT1",true,false,4,8,Image::FORMAT_DXT1},
+ {"DXT3",true,false,4,16,Image::FORMAT_DXT3},
+ {"DXT5",true,false,4,16,Image::FORMAT_DXT5},
+ {"ATI1",true,false,4,8,Image::FORMAT_ATI1},
+ {"ATI2",true,false,4,16,Image::FORMAT_ATI2},
+ {"BGRA8",false,false,1,4,Image::FORMAT_RGBA8},
+ {"BGR8",false,false,1,3,Image::FORMAT_RGB8},
+ {"RGBA8",false,false,1,4,Image::FORMAT_RGBA8},
+ {"RGB8",false,false,1,3,Image::FORMAT_RGB8},
+ {"BGR5A1",false,false,1,2,Image::FORMAT_RGBA8},
+ {"BGR565",false,false,1,2,Image::FORMAT_RGB8},
+ {"BGR10A2",false,false,1,4,Image::FORMAT_RGBA8},
+ {"GRAYSCALE",false,false,1,1,Image::FORMAT_L8},
+ {"GRAYSCALE_ALPHA",false,false,1,2,Image::FORMAT_LA8}
};
diff --git a/drivers/etc1/image_etc.cpp b/drivers/etc1/image_etc.cpp
index cf2384240b..176abc356c 100644
--- a/drivers/etc1/image_etc.cpp
+++ b/drivers/etc1/image_etc.cpp
@@ -42,7 +42,7 @@ static void _decompress_etc(Image *p_img) {
DVector<uint8_t>::Read r = src.read();
- int mmc=p_img->get_mipmaps();
+ int mmc=p_img->get_mipmap_count();
for(int i=0;i<=mmc;i++) {
@@ -93,9 +93,9 @@ static void _decompress_etc(Image *p_img) {
r=DVector<uint8_t>::Read();
//print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps()));
- *p_img=Image(p_img->get_width(),p_img->get_height(),p_img->get_mipmaps(),Image::FORMAT_RGB,dst);
- if (p_img->get_mipmaps())
- p_img->generate_mipmaps(-1,true);
+ *p_img=Image(p_img->get_width(),p_img->get_height(),p_img->has_mipmaps(),Image::FORMAT_RGB8,dst);
+ if (p_img->has_mipmaps())
+ p_img->generate_mipmaps(true);
}
@@ -108,11 +108,11 @@ static void _compress_etc(Image *p_img) {
ERR_FAIL_COND( nearest_power_of_2(imgw)!=imgw || nearest_power_of_2(imgh)!=imgh );
- if (img.get_format()!=Image::FORMAT_RGB)
- img.convert(Image::FORMAT_RGB);
+ if (img.get_format()!=Image::FORMAT_RGB8)
+ img.convert(Image::FORMAT_RGB8);
- int mmc=img.get_mipmaps();
+ int mmc=img.get_mipmap_count();
if (mmc==0)
img.generate_mipmaps(); // force mipmaps, so it works on most hardware
@@ -186,7 +186,7 @@ static void _compress_etc(Image *p_img) {
}
- *p_img=Image(p_img->get_width(),p_img->get_height(),mc-1,Image::FORMAT_ETC,dst_data);
+ *p_img=Image(p_img->get_width(),p_img->get_height(),(mc-1)?true:false,Image::FORMAT_ETC,dst_data);
}
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index a7edc8d935..db874d1287 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -376,7 +376,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
switch(p_format) {
- case Image::FORMAT_GRAYSCALE: {
+ case Image::FORMAT_L8: {
r_gl_components=1;
r_gl_format=GL_LUMINANCE;
r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_SLUMINANCE_NV:GL_LUMINANCE;
@@ -385,15 +385,15 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
case Image::FORMAT_INTENSITY: {
if (!image.empty())
- image.convert(Image::FORMAT_RGBA);
+ image.convert(Image::FORMAT_RGBA8);
r_gl_components=4;
r_gl_format=GL_RGBA;
r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_GL_SRGB_ALPHA_EXT:GL_RGBA;
r_has_alpha_cache=true;
} break;
- case Image::FORMAT_GRAYSCALE_ALPHA: {
+ case Image::FORMAT_LA8: {
- //image.convert(Image::FORMAT_RGBA);
+ //image.convert(Image::FORMAT_RGBA8);
r_gl_components=2;
r_gl_format=GL_LUMINANCE_ALPHA;
r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_SLUMINANCE_ALPHA_NV:GL_LUMINANCE_ALPHA;
@@ -403,7 +403,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
case Image::FORMAT_INDEXED: {
if (!image.empty())
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
r_gl_components=3;
r_gl_format=GL_RGB;
r_gl_internal_format=(srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_GL_SRGB_EXT:GL_RGB;
@@ -413,7 +413,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
case Image::FORMAT_INDEXED_ALPHA: {
if (!image.empty())
- image.convert(Image::FORMAT_RGBA);
+ image.convert(Image::FORMAT_RGBA8);
r_gl_components=4;
if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
@@ -432,7 +432,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
r_has_alpha_cache=true;
} break;
- case Image::FORMAT_RGB: {
+ case Image::FORMAT_RGB8: {
r_gl_components=3;
@@ -450,7 +450,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
r_gl_internal_format=GL_RGB;
}
} break;
- case Image::FORMAT_RGBA: {
+ case Image::FORMAT_RGBA8: {
r_gl_components=4;
if (p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
@@ -470,7 +470,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
r_has_alpha_cache=true;
} break;
- case Image::FORMAT_BC1: {
+ case Image::FORMAT_DXT1: {
if (!s3tc_supported || (!s3tc_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
@@ -501,7 +501,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
};
} break;
- case Image::FORMAT_BC2: {
+ case Image::FORMAT_DXT3: {
if (!s3tc_supported || (!s3tc_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
@@ -533,7 +533,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
};
} break;
- case Image::FORMAT_BC3: {
+ case Image::FORMAT_DXT5: {
if (!s3tc_supported || (!s3tc_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
@@ -564,7 +564,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
};
} break;
- case Image::FORMAT_BC4: {
+ case Image::FORMAT_ATI1: {
if (!latc_supported) {
@@ -595,7 +595,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
};
} break;
- case Image::FORMAT_BC5: {
+ case Image::FORMAT_ATI2: {
if (!latc_supported ) {
@@ -657,7 +657,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
}
} break;
- case Image::FORMAT_PVRTC2_ALPHA: {
+ case Image::FORMAT_PVRTC2A: {
if (!pvr_supported || (!pvr_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
@@ -719,7 +719,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
}
} break;
- case Image::FORMAT_PVRTC4_ALPHA: {
+ case Image::FORMAT_PVRTC4A: {
if (!pvr_supported || (!pvr_srgb_supported && p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) {
@@ -841,7 +841,7 @@ Image RasterizerGLES2::_get_gl_image_and_format(const Image& p_image, Image::For
case Image::FORMAT_YUV_444: {
if (!image.empty())
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
r_gl_internal_format=GL_RGB;
r_gl_components=3;
@@ -1145,7 +1145,7 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
switch(texture->format) {
- case Image::FORMAT_GRAYSCALE: {
+ case Image::FORMAT_L8: {
format=GL_LUMINANCE;
type=GL_UNSIGNED_BYTE;
@@ -1156,19 +1156,19 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
case Image::FORMAT_INTENSITY: {
return Image();
} break;
- case Image::FORMAT_GRAYSCALE_ALPHA: {
+ case Image::FORMAT_LA8: {
format=GL_LUMINANCE_ALPHA;
type=GL_UNSIGNED_BYTE;
pixelsize=2;
} break;
- case Image::FORMAT_RGB: {
+ case Image::FORMAT_RGB8: {
format=GL_RGB;
type=GL_UNSIGNED_BYTE;
pixelsize=3;
} break;
- case Image::FORMAT_RGBA: {
+ case Image::FORMAT_RGBA8: {
format=GL_RGBA;
type=GL_UNSIGNED_BYTE;
@@ -1178,18 +1178,18 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
format=GL_RGB;
type=GL_UNSIGNED_BYTE;
- fmt=Image::FORMAT_RGB;
+ fmt=Image::FORMAT_RGB8;
pixelsize=3;
} break;
case Image::FORMAT_INDEXED_ALPHA: {
format=GL_RGBA;
type=GL_UNSIGNED_BYTE;
- fmt=Image::FORMAT_RGBA;
+ fmt=Image::FORMAT_RGBA8;
pixelsize=4;
} break;
- case Image::FORMAT_BC1: {
+ case Image::FORMAT_DXT1: {
pixelsize=1; //doesn't matter much
format=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
@@ -1198,14 +1198,14 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
minw=minh=4;
} break;
- case Image::FORMAT_BC2: {
+ case Image::FORMAT_DXT3: {
pixelsize=1; //doesn't matter much
format=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
compressed=true;
minw=minh=4;
} break;
- case Image::FORMAT_BC3: {
+ case Image::FORMAT_DXT5: {
pixelsize=1; //doesn't matter much
format=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
@@ -1213,7 +1213,7 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
minw=minh=4;
} break;
- case Image::FORMAT_BC4: {
+ case Image::FORMAT_ATI1: {
format=GL_COMPRESSED_RED_RGTC1;
pixelsize=1; //doesn't matter much
@@ -1222,7 +1222,7 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid
minw=minh=4;
} break;
- case Image::FORMAT_BC5: {
+ case Image::FORMAT_ATI2: {
format=GL_COMPRESSED_RG_RGTC2;
pixelsize=1; //doesn't matter much
@@ -1359,7 +1359,7 @@ Image::Format RasterizerGLES2::texture_get_format(RID p_texture) const {
Texture * texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,Image::FORMAT_GRAYSCALE);
+ ERR_FAIL_COND_V(!texture,Image::FORMAT_L8);
return texture->format;
}
@@ -4320,7 +4320,7 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) {
w=DVector<uint8_t>::Write();
- r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGB,pixels);
+ r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGB8,pixels);
#else
@@ -4360,7 +4360,7 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) {
}
w=DVector<uint8_t>::Write();
- r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGBA,pixels);
+ r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGBA8,pixels);
//r_capture->flip_y();
diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h
index b18f89d8e7..23f7cb6a1f 100644
--- a/drivers/gles2/rasterizer_gles2.h
+++ b/drivers/gles2/rasterizer_gles2.h
@@ -154,7 +154,7 @@ class RasterizerGLES2 : public Rasterizer {
flags=width=height=0;
tex_id=0;
data_size=0;
- format=Image::FORMAT_GRAYSCALE;
+ format=Image::FORMAT_L8;
gl_components_cache=0;
format_has_alpha=false;
has_alpha=false;
diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl
index 5f4767940d..38c579c15c 100644
--- a/drivers/gles2/shaders/canvas.glsl
+++ b/drivers/gles2/shaders/canvas.glsl
@@ -105,8 +105,8 @@ precision mediump float;
precision mediump int;
#endif
- // texunit:0
-uniform sampler2D texture;
+
+uniform sampler2D texture; // texunit:0
varying vec2 uv_interp;
varying vec4 color_interp;
@@ -319,7 +319,7 @@ LIGHT_SHADER_CODE
#ifdef USE_DEPTH_SHADOWS
-#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).z)
+#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).r)
#else
diff --git a/drivers/gles3/SCsub b/drivers/gles3/SCsub
new file mode 100644
index 0000000000..a17335b41b
--- /dev/null
+++ b/drivers/gles3/SCsub
@@ -0,0 +1,5 @@
+Import('env')
+
+env.add_source_files(env.drivers_sources,"*.cpp")
+
+SConscript("shaders/SCsub")
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
new file mode 100644
index 0000000000..f24560763f
--- /dev/null
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -0,0 +1,1461 @@
+#include "rasterizer_canvas_gles3.h"
+#include "os/os.h"
+
+static _FORCE_INLINE_ void store_matrix32(const Matrix32& p_mtx, float* p_array) {
+
+ p_array[ 0]=p_mtx.elements[0][0];
+ p_array[ 1]=p_mtx.elements[0][1];
+ p_array[ 2]=0;
+ p_array[ 3]=0;
+ p_array[ 4]=p_mtx.elements[1][0];
+ p_array[ 5]=p_mtx.elements[1][1];
+ p_array[ 6]=0;
+ p_array[ 7]=0;
+ p_array[ 8]=0;
+ p_array[ 9]=0;
+ p_array[10]=1;
+ p_array[11]=0;
+ p_array[12]=p_mtx.elements[2][0];
+ p_array[13]=p_mtx.elements[2][1];
+ p_array[14]=0;
+ p_array[15]=1;
+}
+
+
+static _FORCE_INLINE_ void store_transform(const Transform& p_mtx, float* p_array) {
+ p_array[ 0]=p_mtx.basis.elements[0][0];
+ p_array[ 1]=p_mtx.basis.elements[1][0];
+ p_array[ 2]=p_mtx.basis.elements[2][0];
+ p_array[ 3]=0;
+ p_array[ 4]=p_mtx.basis.elements[0][1];
+ p_array[ 5]=p_mtx.basis.elements[1][1];
+ p_array[ 6]=p_mtx.basis.elements[2][1];
+ p_array[ 7]=0;
+ p_array[ 8]=p_mtx.basis.elements[0][2];
+ p_array[ 9]=p_mtx.basis.elements[1][2];
+ p_array[10]=p_mtx.basis.elements[2][2];
+ p_array[11]=0;
+ p_array[12]=p_mtx.origin.x;
+ p_array[13]=p_mtx.origin.y;
+ p_array[14]=p_mtx.origin.z;
+ p_array[15]=1;
+}
+
+static _FORCE_INLINE_ void store_camera(const CameraMatrix& p_mtx, float* p_array) {
+
+ for (int i=0;i<4;i++) {
+ for (int j=0;j<4;j++) {
+
+ p_array[i*4+j]=p_mtx.matrix[i][j];
+ }
+ }
+}
+
+
+RID RasterizerCanvasGLES3::light_internal_create() {
+
+ LightInternal * li = memnew( LightInternal );
+
+ glGenBuffers(1, &li->ubo);
+ glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(LightInternal::UBOData), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+
+ return light_internal_owner.make_rid(li);
+}
+
+void RasterizerCanvasGLES3::light_internal_update(RID p_rid, Light* p_light) {
+
+ LightInternal * li = light_internal_owner.getornull(p_rid);
+ ERR_FAIL_COND(!li);
+
+ store_matrix32(p_light->light_shader_xform,li->ubo_data.light_matrix);
+ store_matrix32(p_light->xform_cache.affine_inverse(),li->ubo_data.local_matrix);
+ store_camera(p_light->shadow_matrix_cache,li->ubo_data.shadow_matrix);
+
+ for(int i=0;i<4;i++) {
+
+ li->ubo_data.color[i]=p_light->color[i]*p_light->energy;
+ li->ubo_data.shadow_color[i]=p_light->shadow_color[i];
+ }
+
+ li->ubo_data.light_pos[0]=p_light->light_shader_pos.x;
+ li->ubo_data.light_pos[1]=p_light->light_shader_pos.y;
+ li->ubo_data.shadowpixel_size=1.0/p_light->shadow_buffer_size;
+ li->ubo_data.light_outside_alpha=p_light->mode==VS::CANVAS_LIGHT_MODE_MASK?1.0:0.0;
+ li->ubo_data.light_height=p_light->height;
+ if (p_light->radius_cache==0)
+ li->ubo_data.shadow_gradient=0;
+ else
+ li->ubo_data.shadow_gradient=p_light->shadow_gradient_length/(p_light->radius_cache*1.1);;
+
+ li->ubo_data.shadow_distance_mult=(p_light->radius_cache*1.1);
+
+
+ glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0,sizeof(LightInternal::UBOData), &li->ubo_data);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+
+}
+
+void RasterizerCanvasGLES3::light_internal_free(RID p_rid) {
+
+ LightInternal * li = light_internal_owner.getornull(p_rid);
+ ERR_FAIL_COND(!li);
+
+ glDeleteBuffers(1,&li->ubo);
+ light_internal_owner.free(p_rid);
+ memdelete(li);
+
+}
+
+void RasterizerCanvasGLES3::canvas_begin(){
+
+ /*canvas_shader.unbind();
+ canvas_shader.set_custom_shader(0);
+ canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,false);
+ canvas_shader.bind();
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXTURE, 0);
+ canvas_use_modulate=false;*/
+
+ reset_canvas();
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT,true);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD,false);
+
+
+ state.canvas_shader.bind();
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,Color(1,1,1,1));
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Matrix32());
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Matrix32());
+
+
+
+
+// state.canvas_shader.set_uniform(CanvasShaderGLES3::PROJECTION_MATRIX,state.vp);
+ //state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Transform());
+ //state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform());
+
+ glBindBufferBase(GL_UNIFORM_BUFFER,0,state.canvas_item_ubo);
+ glBindVertexArray(data.canvas_quad_array);
+ state.using_texture_rect=true;
+
+
+}
+
+
+void RasterizerCanvasGLES3::canvas_end(){
+
+
+ glBindVertexArray(0);
+ glBindBufferBase(GL_UNIFORM_BUFFER,0,0);
+
+ state.using_texture_rect=false;
+
+}
+
+
+
+RasterizerStorageGLES3::Texture* RasterizerCanvasGLES3::_bind_canvas_texture(const RID& p_texture) {
+
+ if (p_texture==state.current_tex) {
+ return state.current_tex_ptr;
+ }
+
+ if (p_texture.is_valid()) {
+
+
+ RasterizerStorageGLES3::Texture*texture=storage->texture_owner.getornull(p_texture);
+
+ if (!texture) {
+ state.current_tex=RID();
+ state.current_tex_ptr=NULL;
+ glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ return NULL;
+ }
+
+ if (texture->render_target)
+ texture->render_target->used_in_frame=true;
+
+ glBindTexture(GL_TEXTURE_2D,texture->tex_id);
+ state.current_tex=p_texture;
+ state.current_tex_ptr=texture;
+
+ return texture;
+
+
+ } else {
+
+
+ glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ state.current_tex=RID();
+ state.current_tex_ptr=NULL;
+ }
+
+
+ return NULL;
+}
+
+void RasterizerCanvasGLES3::_set_texture_rect_mode(bool p_enable) {
+
+ if (state.using_texture_rect==p_enable)
+ return;
+
+ if (p_enable) {
+ glBindVertexArray(data.canvas_quad_array);
+
+
+ } else {
+ glBindVertexArray(0);
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+
+
+ }
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT,p_enable);
+ state.canvas_shader.bind();
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,state.extra_matrix);
+
+
+ state.using_texture_rect=p_enable;
+}
+
+
+void RasterizerCanvasGLES3::_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;
+ Color m;
+ if (p_singlecolor) {
+ m = *p_colors;
+ glVertexAttrib4f(VS::ARRAY_COLOR,m.r,m.g,m.b,m.a);
+ } else if (!p_colors) {
+
+ glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ } else
+ do_colors=true;
+
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(p_texture);
+
+#ifndef GLES_NO_CLIENT_ARRAYS
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(Vector2), p_vertices );
+ if (do_colors) {
+
+ glEnableVertexAttribArray(VS::ARRAY_COLOR);
+ glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(Color), p_colors );
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
+ }
+
+ if (texture && p_uvs) {
+
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
+ glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs );
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
+ }
+
+ if (p_indices) {
+#ifdef GLEW_ENABLED
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices );
+#else
+ static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!!
+ ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
+ static uint16_t _draw_poly_indices[_max_draw_poly_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 );
+#endif
+ } else {
+ glDrawArrays(GL_TRIANGLES,0,p_vertex_count);
+ }
+
+
+#else //WebGL specific impl.
+ glBindBuffer(GL_ARRAY_BUFFER, gui_quad_buffer);
+ float *b = GlobalVertexBuffer;
+ int ofs = 0;
+ if(p_vertex_count > MAX_POLYGON_VERTICES){
+ print_line("Too many vertices to render");
+ return;
+ }
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
+ for(int i=0;i<p_vertex_count;i++) {
+ b[ofs++]=p_vertices[i].x;
+ b[ofs++]=p_vertices[i].y;
+ }
+
+ if (p_colors && do_colors) {
+
+ glEnableVertexAttribArray(VS::ARRAY_COLOR);
+ glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(float)*4, ((float*)0)+ofs );
+ for(int i=0;i<p_vertex_count;i++) {
+ b[ofs++]=p_colors[i].r;
+ b[ofs++]=p_colors[i].g;
+ b[ofs++]=p_colors[i].b;
+ b[ofs++]=p_colors[i].a;
+ }
+
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
+ }
+
+
+ if (p_uvs) {
+
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
+ glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
+ for(int i=0;i<p_vertex_count;i++) {
+ b[ofs++]=p_uvs[i].x;
+ b[ofs++]=p_uvs[i].y;
+ }
+
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
+ }
+
+ glBufferSubData(GL_ARRAY_BUFFER,0,ofs*4,&b[0]);
+
+ //bind the indices buffer.
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer);
+
+ static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!!
+ ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
+ static uint16_t _draw_poly_indices[_max_draw_poly_indices];
+ for (int i=0; i<p_vertex_count; i++) {
+ _draw_poly_indices[i] = p_indices[i];
+ //OS::get_singleton()->print("ind: %d ", p_indices[i]);
+ };
+
+ //copy the data to GPU.
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, p_vertex_count * sizeof(uint16_t), &_draw_poly_indices[0]);
+
+ //draw the triangles.
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, 0);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+#endif
+
+ storage->frame.canvas_draw_commands++;
+
+}
+
+void RasterizerCanvasGLES3::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs) {
+
+
+
+ static const GLenum prim[5]={GL_POINTS,GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN};
+
+
+ //#define GLES_USE_PRIMITIVE_BUFFER
+
+#ifndef GLES_NO_CLIENT_ARRAYS
+
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(Vector2), p_vertices );
+
+ if (p_colors) {
+
+ glEnableVertexAttribArray(VS::ARRAY_COLOR);
+ glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(Color), p_colors );
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
+ }
+
+ if (p_uvs) {
+
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
+ glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(Vector2), p_uvs );
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
+ }
+
+ glDrawArrays(prim[p_points],0,p_points);
+
+#else
+
+ glBindBuffer(GL_ARRAY_BUFFER,gui_quad_buffer);
+ float b[32];
+ int ofs=0;
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
+ for(int i=0;i<p_points;i++) {
+ b[ofs++]=p_vertices[i].x;
+ b[ofs++]=p_vertices[i].y;
+ }
+
+ if (p_colors) {
+
+ glEnableVertexAttribArray(VS::ARRAY_COLOR);
+ glVertexAttribPointer( VS::ARRAY_COLOR, 4 ,GL_FLOAT, false, sizeof(float)*4, ((float*)0)+ofs );
+ for(int i=0;i<p_points;i++) {
+ b[ofs++]=p_colors[i].r;
+ b[ofs++]=p_colors[i].g;
+ b[ofs++]=p_colors[i].b;
+ b[ofs++]=p_colors[i].a;
+ }
+
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
+ }
+
+
+ if (p_uvs) {
+
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
+ glVertexAttribPointer( VS::ARRAY_TEX_UV, 2 ,GL_FLOAT, false, sizeof(float)*2, ((float*)0)+ofs );
+ for(int i=0;i<p_points;i++) {
+ b[ofs++]=p_uvs[i].x;
+ b[ofs++]=p_uvs[i].y;
+ }
+
+ } else {
+ glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
+ }
+
+ glBufferSubData(GL_ARRAY_BUFFER,0,ofs*4,&b[0]);
+ glDrawArrays(prim[p_points],0,p_points);
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+
+
+#endif
+
+ storage->frame.canvas_draw_commands++;
+}
+
+void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *current_clip,bool &reclip) {
+
+ int cc=p_item->commands.size();
+ Item::Command **commands = p_item->commands.ptr();
+
+
+ for(int i=0;i<cc;i++) {
+
+ Item::Command *c=commands[i];
+
+ switch(c->type) {
+ case Item::Command::TYPE_LINE: {
+
+
+ Item::CommandLine* line = static_cast<Item::CommandLine*>(c);
+ _set_texture_rect_mode(false);
+
+
+ _bind_canvas_texture(RID());
+
+ glVertexAttrib4f(VS::ARRAY_COLOR,line->color.r,line->color.g,line->color.b,line->color.a);
+
+ Vector2 verts[2]={
+ Vector2(line->from.x,line->from.y),
+ Vector2(line->to.x,line->to.y)
+ };
+
+#ifdef GLEW_ENABLED
+ if (line->antialiased)
+ glEnable(GL_LINE_SMOOTH);
+#endif
+ glLineWidth(line->width);
+ _draw_gui_primitive(2,verts,NULL,NULL);
+
+#ifdef GLEW_ENABLED
+ if (line->antialiased)
+ glDisable(GL_LINE_SMOOTH);
+#endif
+
+
+ } break;
+ case Item::Command::TYPE_RECT: {
+
+ Item::CommandRect* rect = static_cast<Item::CommandRect*>(c);
+
+ _set_texture_rect_mode(true);
+
+ //set color
+ glVertexAttrib4f(VS::ARRAY_COLOR,rect->modulate.r,rect->modulate.g,rect->modulate.b,rect->modulate.a);
+
+ RasterizerStorageGLES3::Texture* texture = _bind_canvas_texture(rect->texture);
+
+ if ( texture ) {
+
+ bool untile=false;
+
+ if (rect->flags&CANVAS_RECT_TILE && !(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 );
+ untile=true;
+ }
+
+ Size2 texpixel_size( 1.0/texture->width, 1.0/texture->height );
+ Rect2 src_rect = (rect->flags&CANVAS_RECT_REGION) ? Rect2( rect->source.pos * texpixel_size, rect->source.size * texpixel_size ) : Rect2(0,0,1,1);
+
+ if (rect->flags&CANVAS_RECT_FLIP_H) {
+ src_rect.size.x*=-1;
+ }
+
+ if (rect->flags&CANVAS_RECT_FLIP_V) {
+ src_rect.size.x*=-1;
+ }
+
+ if (rect->flags&CANVAS_RECT_TRANSPOSE) {
+ //err..
+ }
+
+
+ glVertexAttrib4f(1,rect->rect.pos.x,rect->rect.pos.y,rect->rect.size.x,rect->rect.size.y);
+ glVertexAttrib4f(2,src_rect.pos.x,src_rect.pos.y,src_rect.size.x,src_rect.size.y);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+
+ if (untile) {
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+ }
+
+ } else {
+
+
+ glVertexAttrib4f(1,rect->rect.pos.x,rect->rect.pos.y,rect->rect.size.x,rect->rect.size.y);
+ glVertexAttrib4f(2,0,0,1,1);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+
+ }
+
+ storage->frame.canvas_draw_commands++;
+
+ } break;
+
+ case Item::Command::TYPE_NINEPATCH: {
+
+ Item::CommandNinePatch* np = static_cast<Item::CommandNinePatch*>(c);
+
+ _set_texture_rect_mode(true);
+
+ glVertexAttrib4f(VS::ARRAY_COLOR,np->color.r,np->color.g,np->color.b,np->color.a);
+
+
+ RasterizerStorageGLES3::Texture* texture = _bind_canvas_texture(np->texture);
+
+ if ( !texture ) {
+
+ glVertexAttrib4f(1,np->rect.pos.x,np->rect.pos.y,np->rect.size.x,np->rect.size.y);
+ glVertexAttrib4f(2,0,0,1,1);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ continue;
+ }
+
+
+ Size2 texpixel_size( 1.0/texture->width, 1.0/texture->height );
+
+#define DSTRECT(m_x,m_y,m_w,m_h) glVertexAttrib4f(1,m_x,m_y,m_w,m_h)
+#define SRCRECT(m_x,m_y,m_w,m_h) glVertexAttrib4f(2,(m_x)*texpixel_size.x,(m_y)*texpixel_size.y,(m_w)*texpixel_size.x,(m_h)*texpixel_size.y)
+
+ //top left
+ DSTRECT(np->rect.pos.x,np->rect.pos.y,np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP]);
+ SRCRECT(0,0,np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ //top right
+ DSTRECT(np->rect.pos.x+np->rect.size.x-np->margin[MARGIN_RIGHT],np->rect.pos.y,np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
+ SRCRECT(texture->width-np->margin[MARGIN_RIGHT],0,np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ //bottom right
+ DSTRECT(np->rect.pos.x+np->rect.size.x-np->margin[MARGIN_RIGHT],np->rect.pos.y+np->rect.size.y-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_RIGHT],np->margin[MARGIN_BOTTOM]);
+ SRCRECT(texture->width-np->margin[MARGIN_RIGHT],texture->height-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_RIGHT],np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ //bottom left
+ DSTRECT(np->rect.pos.x,np->rect.pos.y+np->rect.size.y-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_LEFT],np->margin[MARGIN_BOTTOM]);
+ SRCRECT(0,texture->height-np->margin[MARGIN_BOTTOM],np->margin[MARGIN_LEFT],np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+
+ //top
+ DSTRECT(np->rect.pos.x+np->margin[MARGIN_LEFT],np->rect.pos.y,np->rect.size.width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
+ SRCRECT(np->margin[MARGIN_LEFT],0,texture->width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ //bottom
+ DSTRECT(np->rect.pos.x+np->margin[MARGIN_LEFT],np->rect.pos.y+np->rect.size.y-np->margin[MARGIN_BOTTOM],np->rect.size.width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP]);
+ SRCRECT(np->margin[MARGIN_LEFT],texture->height-np->margin[MARGIN_BOTTOM],texture->width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+
+ //left
+ DSTRECT(np->rect.pos.x,np->rect.pos.y+np->margin[MARGIN_TOP],np->margin[MARGIN_LEFT],np->rect.size.height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
+ SRCRECT(0,np->margin[MARGIN_TOP],np->margin[MARGIN_LEFT],texture->height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ //right
+ DSTRECT(np->rect.pos.x+np->rect.size.width-np->margin[MARGIN_RIGHT],np->rect.pos.y+np->margin[MARGIN_TOP],np->margin[MARGIN_RIGHT],np->rect.size.height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
+ SRCRECT(texture->width-np->margin[MARGIN_RIGHT],np->margin[MARGIN_TOP],np->margin[MARGIN_RIGHT],texture->height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ if (np->draw_center) {
+
+ //center
+ DSTRECT(np->rect.pos.x+np->margin[MARGIN_LEFT],np->rect.pos.y+np->margin[MARGIN_TOP],np->rect.size.x-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],np->rect.size.height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
+ SRCRECT(np->margin[MARGIN_LEFT],np->margin[MARGIN_TOP],texture->width-np->margin[MARGIN_LEFT]-np->margin[MARGIN_RIGHT],texture->height-np->margin[MARGIN_TOP]-np->margin[MARGIN_BOTTOM]);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+
+ }
+
+#undef SRCRECT
+#undef DSTRECT
+
+ storage->frame.canvas_draw_commands++;
+ } break;
+
+ case Item::Command::TYPE_PRIMITIVE: {
+
+ Item::CommandPrimitive* primitive = static_cast<Item::CommandPrimitive*>(c);
+ _set_texture_rect_mode(false);
+
+ ERR_CONTINUE( primitive->points.size()<1);
+
+ _bind_canvas_texture(primitive->texture);
+
+ if (primitive->colors.size()==1 && primitive->points.size()>1) {
+
+ Color c = primitive->colors[0];
+ glVertexAttrib4f(VS::ARRAY_COLOR,c.r,c.g,c.b,c.a);
+
+ } else if (primitive->colors.empty()) {
+ glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ }
+
+ _draw_gui_primitive(primitive->points.size(),primitive->points.ptr(),primitive->colors.ptr(),primitive->uvs.ptr());
+
+ } break;
+ case Item::Command::TYPE_POLYGON: {
+
+ Item::CommandPolygon* polygon = static_cast<Item::CommandPolygon*>(c);
+ _set_texture_rect_mode(false);
+ _draw_polygon(polygon->count,polygon->indices.ptr(),polygon->points.ptr(),polygon->uvs.ptr(),polygon->colors.ptr(),polygon->texture,polygon->colors.size()==1);
+
+ } break;
+ case Item::Command::TYPE_CIRCLE: {
+
+ _set_texture_rect_mode(false);
+
+ Item::CommandCircle* circle = static_cast<Item::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;
+ }
+ _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 Item::Command::TYPE_TRANSFORM: {
+
+ Item::CommandTransform* transform = static_cast<Item::CommandTransform*>(c);
+ state.extra_matrix=transform->xform;
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,state.extra_matrix);
+
+ } break;
+ case Item::Command::TYPE_CLIP_IGNORE: {
+
+ Item::CommandClipIgnore* ci = static_cast<Item::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);
+
+ int x = current_clip->final_clip_rect.pos.x;
+ int y = storage->frame.current_rt->height - ( current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y );
+ int w = current_clip->final_clip_rect.size.x;
+ int h = current_clip->final_clip_rect.size.y;
+
+ glScissor(x,y,w,h);
+
+ reclip=false;
+ }
+ }
+ }
+
+
+
+ } break;
+ }
+ }
+}
+
+#if 0
+void RasterizerGLES2::_canvas_item_setup_shader_params(CanvasItemMaterial *material,Shader* shader) {
+
+ if (canvas_shader.bind())
+ rebind_texpixel_size=true;
+
+ if (material->shader_version!=shader->version) {
+ //todo optimize uniforms
+ material->shader_version=shader->version;
+ }
+
+ 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,max_texture_units-1);
+ glActiveTexture(GL_TEXTURE0+max_texture_units-1);
+ glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
+ if (framebuffer.scale==1 && !canvas_texscreen_used) {
+#ifdef GLEW_ENABLED
+ if (current_rt) {
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ } else {
+ glReadBuffer(GL_BACK);
+ }
+#endif
+ if (current_rt) {
+ glCopyTexSubImage2D(GL_TEXTURE_2D,0,viewport.x,viewport.y,viewport.x,viewport.y,viewport.width,viewport.height);
+ canvas_shader.set_uniform(CanvasShaderGLES2::TEXSCREEN_SCREEN_CLAMP,Color(float(x)/framebuffer.width,float(viewport.y)/framebuffer.height,float(x+viewport.width)/framebuffer.width,float(y+viewport.height)/framebuffer.height));
+ //window_size.height-(viewport.height+viewport.y)
+ } else {
+ glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
+ }
+// if (current_clip) {
+// // print_line(" a clip ");
+// }
+
+ canvas_texscreen_used=true;
+ }
+
+ 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));
+ }
+
+
+ uses_texpixel_size=shader->uses_texpixel_size;
+
+}
+
+#endif
+
+void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light) {
+
+
+ if (storage->frame.clear_request) {
+ // a clear request may be pending, so do it
+ glClearColor( storage->frame.clear_request_color.r, storage->frame.clear_request_color.g, storage->frame.clear_request_color.b, storage->frame.clear_request_color.a );
+ glClear(GL_COLOR_BUFFER_BIT);
+ storage->frame.clear_request=false;
+
+
+ }
+
+ Item *current_clip=NULL;
+ RasterizerStorageGLES3::Shader *shader_cache=NULL;
+
+ bool rebind_shader=true;
+
+ Size2 rt_size = Size2(storage->frame.current_rt->width,storage->frame.current_rt->height);
+
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD,false);
+
+ glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+
+ state.current_tex=RID();
+ state.current_tex_ptr=NULL;
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+
+
+ RID canvas_last_material;
+
+ bool prev_distance_field=false;
+
+ while(p_item_list) {
+
+ Item *ci=p_item_list;
+
+
+ if (prev_distance_field!=ci->distance_field) {
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD,ci->distance_field);
+ prev_distance_field=ci->distance_field;
+ rebind_shader=true;
+ }
+
+
+ if (current_clip!=ci->final_clip_owner) {
+
+ current_clip=ci->final_clip_owner;
+
+ //setup clip
+ if (current_clip) {
+
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(current_clip->final_clip_rect.pos.x,(rt_size.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);
+ }
+ }
+#if 0
+ if (ci->copy_back_buffer && framebuffer.active && framebuffer.scale==1) {
+
+ Rect2 rect;
+ int x,y;
+
+ if (ci->copy_back_buffer->full) {
+
+ x = viewport.x;
+ y = window_size.height-(viewport.height+viewport.y);
+ } else {
+ x = viewport.x+ci->copy_back_buffer->screen_rect.pos.x;
+ y = window_size.height-(viewport.y+ci->copy_back_buffer->screen_rect.pos.y+ci->copy_back_buffer->screen_rect.size.y);
+ }
+ glActiveTexture(GL_TEXTURE0+max_texture_units-1);
+ glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color);
+
+#ifdef GLEW_ENABLED
+ if (current_rt) {
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ } else {
+ glReadBuffer(GL_BACK);
+ }
+#endif
+ if (current_rt) {
+ glCopyTexSubImage2D(GL_TEXTURE_2D,0,viewport.x,viewport.y,viewport.x,viewport.y,viewport.width,viewport.height);
+ //window_size.height-(viewport.height+viewport.y)
+ } else {
+ glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
+ }
+
+ canvas_texscreen_used=true;
+ glActiveTexture(GL_TEXTURE0);
+
+ }
+
+#endif
+
+
+ //begin rect
+ Item *material_owner = ci->material_owner?ci->material_owner:ci;
+
+ RID material = material_owner->material;
+
+ if (material!=canvas_last_material || rebind_shader) {
+#if 0
+ Shader *shader = NULL;
+ if (material && material->shader.is_valid()) {
+ shader = shader_owner.get(material->shader);
+ if (shader && !shader->valid) {
+ shader=NULL;
+ }
+ }
+
+ shader_cache=shader;
+
+ if (shader) {
+ canvas_shader.set_custom_shader(shader->custom_code_id);
+ _canvas_item_setup_shader_params(material,shader);
+ } else {
+ shader_cache=NULL;
+ canvas_shader.set_custom_shader(0);
+ canvas_shader.bind();
+ uses_texpixel_size=false;
+
+ }
+
+
+ canvas_shader.set_uniform(CanvasShaderGLES3::PROJECTION_MATRIX,canvas_transform);
+ if (canvas_use_modulate)
+ reset_modulate=true;
+ canvas_last_material=material;
+ rebind_shader=false;
+#endif
+ }
+
+ if (material.is_valid() && shader_cache) {
+#if 0
+ _canvas_item_setup_shader_uniforms(material,shader_cache);
+#endif
+ }
+
+ bool unshaded = false; //(material && material->shading_mode==VS::CANVAS_ITEM_SHADING_UNSHADED) || ci->blend_mode!=VS::MATERIAL_BLEND_MODE_MIX;
+ bool reclip=false;
+#if 0
+ 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);
+ if (current_rt && current_rt_transparent) {
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ else {
+ 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_REVERSE_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;
+ }
+#endif
+
+// canvas_shader.set_uniform(CanvasShaderGLES3::CANVAS_MODULATE,unshaded ? Color(1,1,1,1) : p_modulate);
+
+ state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(
+ ci->final_modulate.r * p_modulate.r,
+ ci->final_modulate.g * p_modulate.g,
+ ci->final_modulate.b * p_modulate.b,
+ ci->final_modulate.a * p_modulate.a );
+
+ state.final_transform = ci->final_transform;
+ state.extra_matrix=Matrix32();
+
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,state.extra_matrix);
+
+
+ if (unshaded || (state.canvas_item_modulate.a>0.001 && (!material.is_valid() /*|| material->shading_mode!=VS::CANVAS_ITEM_SHADING_ONLY_LIGHT*/) && !ci->light_masked ))
+ _canvas_item_render_commands(ci,current_clip,reclip);
+
+ if (/*canvas_blend_mode==VS::MATERIAL_BLEND_MODE_MIX &&*/ p_light && !unshaded) {
+
+ Light *light = p_light;
+ bool light_used=false;
+ VS::CanvasLightMode mode=VS::CANVAS_LIGHT_MODE_ADD;
+ state.canvas_item_modulate=ci->final_modulate; // remove the canvas modulate
+
+
+ while(light) {
+
+
+ if (ci->light_mask&light->item_mask && p_z>=light->z_min && p_z<=light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache,light->rect_cache)) {
+
+ //intersects this light
+
+ if (!light_used || mode!=light->mode) {
+
+ mode=light->mode;
+
+ switch(mode) {
+
+ case VS::CANVAS_LIGHT_MODE_ADD: {
+ glBlendEquation(GL_FUNC_ADD);
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+
+ } break;
+ case VS::CANVAS_LIGHT_MODE_SUB: {
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+ } break;
+ case VS::CANVAS_LIGHT_MODE_MIX:
+ case VS::CANVAS_LIGHT_MODE_MASK: {
+ glBlendEquation(GL_FUNC_ADD);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ } break;
+ }
+
+ }
+
+ if (!light_used) {
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING,true);
+ light_used=true;
+
+ }
+
+
+ bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask&light->item_shadow_mask;
+
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS,has_shadow);
+ if (has_shadow) {
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_USE_GRADIENT,light->shadow_gradient_length>0);
+ switch(light->shadow_filter) {
+
+ case VS::CANVAS_LIGHT_FILTER_NONE: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST,true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF3: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3,true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF5: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5,true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF9: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9,true); break;
+ case VS::CANVAS_LIGHT_FILTER_PCF13: state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13,true); break;
+ }
+
+
+ }
+
+ bool light_rebind = state.canvas_shader.bind();
+
+ if (light_rebind) {
+#if 0
+ if (material && shader_cache) {
+ _canvas_item_setup_shader_params(material,shader_cache);
+ _canvas_item_setup_shader_uniforms(material,shader_cache);
+ }
+#endif
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Matrix32());
+
+ }
+
+ glBindBufferBase(GL_UNIFORM_BUFFER,1,static_cast<LightInternal*>(light->light_internal.get_data())->ubo);
+
+ if (has_shadow) {
+
+ RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
+ glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-2);
+ glBindTexture(GL_TEXTURE_2D,cls->distance);
+
+ /*canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_MATRIX,light->shadow_matrix_cache);
+ canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
+ canvas_shader.set_uniform(CanvasShaderGLES3::LIGHT_SHADOW_COLOR,light->shadow_color);*/
+
+ }
+
+ glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-1);
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(light->texture);
+ if (!t) {
+ glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ } else {
+
+ glBindTexture(t->target,t->tex_id);
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ _canvas_item_render_commands(ci,current_clip,reclip); //redraw using light
+
+ }
+
+ light=light->next_ptr;
+ }
+
+ if (light_used) {
+
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9,false);
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13,false);
+
+
+ state.canvas_shader.bind();
+#if 0
+ if (material && shader_cache) {
+ _canvas_item_setup_shader_params(material,shader_cache);
+ _canvas_item_setup_shader_uniforms(material,shader_cache);
+ }
+#endif
+
+ state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(
+ ci->final_modulate.r * p_modulate.r,
+ ci->final_modulate.g * p_modulate.g,
+ ci->final_modulate.b * p_modulate.b,
+ ci->final_modulate.a * p_modulate.a );
+
+
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Matrix32());
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
+
+
+ glBlendEquation(GL_FUNC_ADD);
+
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ } else {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+
+ //@TODO RESET canvas_blend_mode
+ }
+
+
+ }
+
+ if (reclip) {
+
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(current_clip->final_clip_rect.pos.x,(rt_size.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);
+ }
+
+}
+
+void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light* p_lights_with_shadow){
+
+ Light* light=p_lights_with_shadow;
+
+ canvas_begin(); //reset
+ glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+ int h = 10;
+ int w = storage->frame.current_rt->width;
+ int ofs = h;
+ glDisable(GL_BLEND);
+
+ //print_line(" debug lights ");
+ while(light) {
+
+
+ // print_line("debug light");
+ if (light->shadow_buffer.is_valid()) {
+
+ // print_line("sb is valid");
+ RasterizerStorageGLES3::CanvasLightShadow * sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
+ if (sb) {
+ glBindTexture(GL_TEXTURE_2D,sb->distance);
+ //glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ draw_generic_textured_rect(Rect2(h,ofs,w-h*2,h),Rect2(0,0,1,1));
+ ofs+=h*2;
+
+ }
+ }
+
+ light=light->shadows_next_ptr;
+ }
+}
+
+
+void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, LightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) {
+
+ RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
+ ERR_FAIL_COND(!cls);
+
+
+ glDisable(GL_BLEND);
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_DITHER);
+ glDisable(GL_CULL_FACE);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(true);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
+
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ state.canvas_shadow_shader.bind();
+
+ glViewport(0, 0, cls->size,cls->height);
+ glClearDepth(1.0f);
+ glClearColor(1,1,1,1);
+ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+
+ VS::CanvasOccluderPolygonCullMode cull=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
+
+
+ for(int i=0;i<4;i++) {
+
+ //make sure it remains orthogonal, makes easy to read angle later
+
+ Transform light;
+ light.origin[0]=p_light_xform[2][0];
+ light.origin[1]=p_light_xform[2][1];
+ light.basis[0][0]=p_light_xform[0][0];
+ light.basis[0][1]=p_light_xform[1][0];
+ light.basis[1][0]=p_light_xform[0][1];
+ light.basis[1][1]=p_light_xform[1][1];
+
+ //light.basis.scale(Vector3(to_light.elements[0].length(),to_light.elements[1].length(),1));
+
+ /// p_near=1;
+ CameraMatrix projection;
+ {
+ real_t fov = 90;
+ real_t near = p_near;
+ real_t far = p_far;
+ real_t aspect = 1.0;
+
+ real_t ymax = near * Math::tan( Math::deg2rad( fov * 0.5 ) );
+ real_t ymin = - ymax;
+ real_t xmin = ymin * aspect;
+ real_t xmax = ymax * aspect;
+
+ projection.set_frustum( xmin, xmax, ymin, ymax, near, far );
+ }
+
+ Vector3 cam_target=Matrix3(Vector3(0,0,Math_PI*2*(i/4.0))).xform(Vector3(0,1,0));
+ projection = projection * CameraMatrix(Transform().looking_at(cam_target,Vector3(0,0,-1)).affine_inverse());
+
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::PROJECTION_MATRIX,projection);
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::LIGHT_MATRIX,light);
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::DISTANCE_NORM,1.0/p_far);
+
+
+ if (i==0)
+ *p_xform_cache=projection;
+
+ glViewport(0, (cls->height/4)*i, cls->size,cls->height/4);
+
+ LightOccluderInstance *instance=p_occluders;
+
+ while(instance) {
+
+ RasterizerStorageGLES3::CanvasOccluder *cc = storage->canvas_occluder_owner.get(instance->polygon_buffer);
+ if (!cc || cc->len==0 || !(p_light_mask&instance->light_mask)) {
+
+ instance=instance->next;
+ continue;
+ }
+
+ state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::WORLD_MATRIX,instance->xform_cache);
+ if (cull!=instance->cull_cache) {
+
+ cull=instance->cull_cache;
+ switch(cull) {
+ case VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: {
+
+ glDisable(GL_CULL_FACE);
+
+ } break;
+ case VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: {
+
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_FRONT);
+ } break;
+ case VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: {
+
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+
+ } break;
+ }
+ }
+/*
+ if (i==0) {
+ for(int i=0;i<cc->lines.size();i++) {
+ Vector2 p = instance->xform_cache.xform(cc->lines.get(i));
+ Plane pp(Vector3(p.x,p.y,0),1);
+ pp.normal = light.xform(pp.normal);
+ pp = projection.xform4(pp);
+ print_line(itos(i)+": "+pp.normal/pp.d);
+ //pp=light_mat.xform4(pp);
+ //print_line(itos(i)+": "+pp.normal/pp.d);
+ }
+ }
+*/
+ glBindBuffer(GL_ARRAY_BUFFER,cc->vertex_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,cc->index_id);
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0);
+ glDrawElements(GL_TRIANGLES,cc->len*3,GL_UNSIGNED_SHORT,0);
+
+
+ instance=instance->next;
+ }
+
+
+ }
+
+ glDisableVertexAttribArray(VS::ARRAY_VERTEX);
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+}
+void RasterizerCanvasGLES3::reset_canvas() {
+
+
+ if (storage->frame.current_rt) {
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->front.fbo);
+ glColorMask(1,1,1,1); //don't touch alpha
+ }
+
+
+ glBindVertexArray(0);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_SCISSOR_TEST);
+#ifdef GLEW_ENABLED
+ glDisable(GL_POINT_SPRITE);
+ glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
+#endif
+ glEnable(GL_BLEND);
+ glBlendEquation(GL_FUNC_ADD);
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ else {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
+ glLineWidth(1.0);
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ for(int i=0;i<VS::ARRAY_MAX;i++) {
+ glDisableVertexAttribArray(i);
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture( GL_TEXTURE_2D, storage->resources.white_tex );
+
+
+ glVertexAttrib4f(VS::ARRAY_COLOR,1,1,1,1);
+
+ Transform canvas_transform;
+
+ if (storage->frame.current_rt) {
+
+ float csy = 1.0;
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) {
+ csy = -1.0;
+ }
+ canvas_transform.translate(-(storage->frame.current_rt->width / 2.0f), -(storage->frame.current_rt->height / 2.0f), 0.0f);
+ canvas_transform.scale( Vector3( 2.0f / storage->frame.current_rt->width, csy * -2.0f / storage->frame.current_rt->height, 1.0f ) );
+ } else {
+ Vector2 ssize = OS::get_singleton()->get_window_size();
+ canvas_transform.translate(-(ssize.width / 2.0f), -(ssize.height / 2.0f), 0.0f);
+ canvas_transform.scale( Vector3( 2.0f / ssize.width, -2.0f / ssize.height, 1.0f ) );
+
+ }
+
+ state.vp=canvas_transform;
+
+ store_transform(canvas_transform,state.canvas_item_ubo_data.projection_matrix);
+
+ glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+
+
+ state.canvas_texscreen_used=false;
+
+
+}
+
+
+void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2& p_rect, const Rect2& p_src) {
+
+
+ glVertexAttrib4f(1,p_rect.pos.x,p_rect.pos.y,p_rect.size.x,p_rect.size.y);
+ glVertexAttrib4f(2,p_src.pos.x,p_src.pos.y,p_src.size.x,p_src.size.y);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+}
+
+void RasterizerCanvasGLES3::initialize() {
+
+
+ {
+ //quad buffers
+
+ glGenBuffers(1,&data.canvas_quad_vertices);
+ glBindBuffer(GL_ARRAY_BUFFER,data.canvas_quad_vertices);
+ {
+ const float qv[8]={
+ 0,0,
+ 0,1,
+ 1,1,
+ 1,0
+ };
+
+ glBufferData(GL_ARRAY_BUFFER,sizeof(float)*8,qv,GL_STATIC_DRAW);
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+
+
+ glGenVertexArrays(1,&data.canvas_quad_array);
+ glBindVertexArray(data.canvas_quad_array);
+ glBindBuffer(GL_ARRAY_BUFFER,data.canvas_quad_vertices);
+ glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,sizeof(float)*2,0);
+ glEnableVertexAttribArray(0);
+ glBindVertexArray(0);
+ glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+ }
+
+
+ store_transform(Transform(),state.canvas_item_ubo_data.projection_matrix);
+
+
+
+ glGenBuffers(1, &state.canvas_item_ubo);
+ glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+
+ state.canvas_shader.init();
+ state.canvas_shadow_shader.init();
+
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS,storage->config.use_rgba_2d_shadows);
+ state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES3::USE_RGBA_SHADOWS,storage->config.use_rgba_2d_shadows);
+
+
+}
+
+
+void RasterizerCanvasGLES3::finalize() {
+
+ glDeleteBuffers(1,&data.canvas_quad_vertices);
+ glDeleteVertexArrays(1,&data.canvas_quad_array);
+}
+
+RasterizerCanvasGLES3::RasterizerCanvasGLES3()
+{
+
+}
diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h
new file mode 100644
index 0000000000..1f72a8dbcf
--- /dev/null
+++ b/drivers/gles3/rasterizer_canvas_gles3.h
@@ -0,0 +1,102 @@
+#ifndef RASTERIZERCANVASGLES3_H
+#define RASTERIZERCANVASGLES3_H
+
+#include "servers/visual/rasterizer.h"
+#include "rasterizer_storage_gles3.h"
+#include "shaders/canvas_shadow.glsl.h"
+
+class RasterizerCanvasGLES3 : public RasterizerCanvas {
+public:
+
+ struct CanvasItemUBO {
+
+ float projection_matrix[16];
+
+ };
+
+ struct Data {
+
+ GLuint canvas_quad_vertices;
+ GLuint canvas_quad_array;
+
+ } data;
+
+ struct State {
+ CanvasItemUBO canvas_item_ubo_data;
+ GLuint canvas_item_ubo;
+ bool canvas_texscreen_used;
+ CanvasShaderGLES3 canvas_shader;
+ CanvasShadowShaderGLES3 canvas_shadow_shader;
+
+ bool using_texture_rect;
+
+
+ RID current_tex;
+ RasterizerStorageGLES3::Texture *current_tex_ptr;
+
+ Transform vp;
+
+ Color canvas_item_modulate;
+ Matrix32 extra_matrix;
+ Matrix32 final_transform;
+
+ } state;
+
+ RasterizerStorageGLES3 *storage;
+
+ struct LightInternal : public RID_Data {
+
+ struct UBOData {
+
+ float light_matrix[16];
+ float local_matrix[16];
+ float shadow_matrix[16];
+ float color[4];
+ float shadow_color[4];
+ float light_pos[2];
+ float shadowpixel_size;
+ float shadow_gradient;
+ float light_height;
+ float light_outside_alpha;
+ float shadow_distance_mult;
+ } ubo_data;
+
+ GLuint ubo;
+ };
+
+ RID_Owner<LightInternal> light_internal_owner;
+
+ virtual RID light_internal_create();
+ virtual void light_internal_update(RID p_rid, Light* p_light);
+ virtual void light_internal_free(RID p_rid);
+
+
+ virtual void canvas_begin();
+ virtual void canvas_end();
+
+ _FORCE_INLINE_ void _set_texture_rect_mode(bool p_enable);
+ _FORCE_INLINE_ RasterizerStorageGLES3::Texture* _bind_canvas_texture(const RID& p_texture);
+
+ _FORCE_INLINE_ void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs);
+ _FORCE_INLINE_ void _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);
+ _FORCE_INLINE_ void _canvas_item_render_commands(Item *p_item,Item *current_clip,bool &reclip);
+
+
+ virtual void canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light);
+ virtual void canvas_debug_viewport_shadows(Light* p_lights_with_shadow);
+
+ virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, LightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache);
+
+
+ virtual void reset_canvas();
+
+ void draw_generic_textured_rect(const Rect2& p_rect, const Rect2& p_src);
+
+
+ void initialize();
+ void finalize();
+
+ RasterizerCanvasGLES3();
+};
+
+#endif // RASTERIZERCANVASGLES3_H
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
new file mode 100644
index 0000000000..ba83a572e5
--- /dev/null
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -0,0 +1,266 @@
+#include "rasterizer_gles3.h"
+#include "os/os.h"
+#include "globals.h"
+#include "gl_context/context_gl.h"
+#include <string.h>
+RasterizerStorage *RasterizerGLES3::get_storage() {
+
+ return storage;
+}
+
+RasterizerCanvas *RasterizerGLES3::get_canvas() {
+
+ return canvas;
+}
+
+RasterizerScene *RasterizerGLES3::get_scene() {
+
+ return NULL;
+}
+
+
+static void _gl_debug_print(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam)
+{
+
+ if (type==GL_DEBUG_TYPE_OTHER_ARB)
+ return;
+
+ print_line("mesege");
+ char debSource[256], debType[256], debSev[256];
+ if(source == GL_DEBUG_SOURCE_API_ARB)
+ strcpy(debSource, "OpenGL");
+ else if(source == GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
+ strcpy(debSource, "Windows");
+ else if(source == GL_DEBUG_SOURCE_SHADER_COMPILER_ARB)
+ strcpy(debSource, "Shader Compiler");
+ else if(source == GL_DEBUG_SOURCE_THIRD_PARTY_ARB)
+ strcpy(debSource, "Third Party");
+ else if(source == GL_DEBUG_SOURCE_APPLICATION_ARB)
+ strcpy(debSource, "Application");
+ else if(source == GL_DEBUG_SOURCE_OTHER_ARB)
+ strcpy(debSource, "Other");
+
+ if(type == GL_DEBUG_TYPE_ERROR_ARB)
+ strcpy(debType, "Error");
+ else if(type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
+ strcpy(debType, "Deprecated behavior");
+ else if(type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
+ strcpy(debType, "Undefined behavior");
+ else if(type == GL_DEBUG_TYPE_PORTABILITY_ARB)
+ strcpy(debType, "Portability");
+ else if(type == GL_DEBUG_TYPE_PERFORMANCE_ARB)
+ strcpy(debType, "Performance");
+ else if(type == GL_DEBUG_TYPE_OTHER_ARB)
+ strcpy(debType, "Other");
+
+ if(severity == GL_DEBUG_SEVERITY_HIGH_ARB)
+ strcpy(debSev, "High");
+ else if(severity == GL_DEBUG_SEVERITY_MEDIUM_ARB)
+ strcpy(debSev, "Medium");
+ else if(severity == GL_DEBUG_SEVERITY_LOW_ARB)
+ strcpy(debSev, "Low");
+
+ String output = String()+ "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
+
+ ERR_PRINTS(output);
+
+}
+
+
+void RasterizerGLES3::initialize() {
+
+ if (OS::get_singleton()->is_stdout_verbose()) {
+ print_line("Using GLES3 video driver");
+ }
+
+#ifdef GLEW_ENABLED
+ GLuint res = glewInit();
+ ERR_FAIL_COND(res!=GLEW_OK);
+ if (OS::get_singleton()->is_stdout_verbose()) {
+ print_line(String("GLES2: Using GLEW ") + (const char*) glewGetString(GLEW_VERSION));
+ }
+
+ // Check for GL 2.1 compatibility, if not bail out
+ if (!glewIsSupported("GL_VERSION_3_0")) {
+ ERR_PRINT("Your system's graphic drivers seem not to support OpenGL 3.0+ / GLES 3.0, sorry :(\n"
+ "Try a drivers update, buy a new GPU or try software rendering on Linux; Godot will now crash with a segmentation fault.");
+ OS::get_singleton()->alert("Your system's graphic drivers seem not to support OpenGL 3.0+ / GLES 3.0, sorry :(\n"
+ "Godot Engine will self-destruct as soon as you acknowledge this error message.",
+ "Fatal error: Insufficient OpenGL / GLES drivers");
+ // TODO: If it's even possible, we should stop the execution without segfault and memory leaks :)
+ }
+#endif
+
+ glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
+ glDebugMessageCallbackARB(_gl_debug_print, NULL);
+ glEnable(GL_DEBUG_OUTPUT);
+
+
+/* glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_ERROR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PORTABILITY_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_PERFORMANCE_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_OTHER_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE);
+ glDebugMessageInsertARB(
+
+ GL_DEBUG_SOURCE_API_ARB,
+ GL_DEBUG_TYPE_OTHER_ARB, 1,
+ GL_DEBUG_SEVERITY_HIGH_ARB,5, "hello");
+
+*/
+ storage->initialize();
+ canvas->initialize();
+}
+
+void RasterizerGLES3::begin_frame(){
+
+
+}
+void RasterizerGLES3::set_current_render_target(RID p_render_target){
+
+ if (!p_render_target.is_valid() && storage->frame.current_rt && storage->frame.clear_request) {
+ //handle pending clear request, if the framebuffer was not cleared
+ glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->front.fbo);
+ glClearColor(
+ storage->frame.clear_request_color.r,
+ storage->frame.clear_request_color.g,
+ storage->frame.clear_request_color.b,
+ storage->frame.clear_request_color.a );
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ }
+
+ if (p_render_target.is_valid()) {
+ RasterizerStorageGLES3::RenderTarget * rt = storage->render_target_owner.getornull(p_render_target);
+ if (!rt) {
+ storage->frame.current_rt=NULL;
+ }
+ ERR_FAIL_COND(!rt);
+ storage->frame.current_rt=rt;
+ storage->frame.clear_request=false;
+
+ glViewport(0,0,rt->width,rt->height);
+
+ } else {
+ storage->frame.current_rt=NULL;
+ storage->frame.clear_request=false;
+ glViewport(0,0,OS::get_singleton()->get_window_size().width,OS::get_singleton()->get_window_size().height);
+ glBindFramebuffer(GL_FRAMEBUFFER,storage->config.system_fbo);
+ }
+}
+
+void RasterizerGLES3::restore_render_target() {
+
+ ERR_FAIL_COND(storage->frame.current_rt==NULL);
+ RasterizerStorageGLES3::RenderTarget * rt = storage->frame.current_rt;
+ glViewport(0,0,rt->width,rt->height);
+
+}
+
+void RasterizerGLES3::clear_render_target(const Color& p_color) {
+
+ ERR_FAIL_COND(!storage->frame.current_rt);
+
+ storage->frame.clear_request=true;
+ storage->frame.clear_request_color=p_color;
+
+}
+
+void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target,const Rect2& p_screen_rect,int p_screen){
+
+ ERR_FAIL_COND( storage->frame.current_rt );
+
+ RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
+ ERR_FAIL_COND(!rt);
+
+ canvas->canvas_begin();
+ glBindFramebuffer(GL_FRAMEBUFFER,storage->config.system_fbo);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D,rt->front.color);
+ canvas->draw_generic_textured_rect(p_screen_rect,Rect2(0,0,1,-1));
+ glBindTexture(GL_TEXTURE_2D,0);
+ canvas->canvas_end();
+}
+
+void RasterizerGLES3::end_frame(){
+
+#if 0
+ canvas->canvas_begin();
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D,storage->resources.white_tex);
+ glDisable(GL_BLEND);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+
+
+ float vtx[8]={0,0,
+ 0,1,
+ 1,1,
+ 1,0
+ };
+
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+ glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, 0, vtx );
+
+
+// glBindBuffer(GL_ARRAY_BUFFER,canvas->data.canvas_quad_vertices);
+// glEnableVertexAttribArray(VS::ARRAY_VERTEX);
+// glVertexAttribPointer( VS::ARRAY_VERTEX, 2 ,GL_FLOAT, false, 0, 0 );
+
+ glBindVertexArray(canvas->data.canvas_quad_array);
+
+ canvas->draw_generic_textured_rect(Rect2(0,0,15,15),Rect2(0,0,1,1));
+#endif
+ if (ContextGL::get_singleton())
+ ContextGL::get_singleton()->swap_buffers();
+}
+
+void RasterizerGLES3::finalize(){
+
+ storage->finalize();
+ canvas->finalize();
+}
+
+
+Rasterizer *RasterizerGLES3::_create_current() {
+
+ return memnew( RasterizerGLES3 );
+}
+
+void RasterizerGLES3::make_current() {
+ _create_func=_create_current;
+}
+
+
+void RasterizerGLES3::register_config() {
+
+ GLOBAL_DEF("rendering/gles3/framebuffer_format",RasterizerStorageGLES3::FBO_FORMAT_FLOAT);
+ Globals::get_singleton()->set_custom_property_info("rendering/gles3/framebuffer_format",PropertyInfo(Variant::INT,"",PROPERTY_HINT_ENUM,"16 Bits,32 Bits,Half Float"));
+ GLOBAL_DEF("rendering/gles3/lighting_technique",1);
+ Globals::get_singleton()->set_custom_property_info("rendering/gles3/lighting_technique",PropertyInfo(Variant::INT,"",PROPERTY_HINT_ENUM,"Forward,Deferred"));
+ GLOBAL_DEF("rendering/gles3/use_nearest_mipmap_filter",false);
+ GLOBAL_DEF("rendering/gles3/anisotropic_filter_level",4.0);
+
+
+}
+
+RasterizerGLES3::RasterizerGLES3()
+{
+
+ storage = memnew( RasterizerStorageGLES3 );
+ canvas = memnew( RasterizerCanvasGLES3 );
+ canvas->storage=storage;
+
+
+}
+
+RasterizerGLES3::~RasterizerGLES3() {
+
+ memdelete(storage);
+ memdelete(canvas);
+}
diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h
new file mode 100644
index 0000000000..d461664ea2
--- /dev/null
+++ b/drivers/gles3/rasterizer_gles3.h
@@ -0,0 +1,38 @@
+#ifndef RASTERIZERGLES3_H
+#define RASTERIZERGLES3_H
+
+#include "servers/visual/rasterizer.h"
+#include "rasterizer_storage_gles3.h"
+#include "rasterizer_canvas_gles3.h"
+
+
+class RasterizerGLES3 : public Rasterizer {
+
+ static Rasterizer *_create_current();
+
+ RasterizerStorageGLES3 *storage;
+ RasterizerCanvasGLES3 *canvas;
+public:
+
+ virtual RasterizerStorage *get_storage();
+ virtual RasterizerCanvas *get_canvas();
+ virtual RasterizerScene *get_scene();
+
+ virtual void initialize();
+ virtual void begin_frame();
+ virtual void set_current_render_target(RID p_render_target);
+ virtual void restore_render_target();
+ virtual void clear_render_target(const Color& p_color);
+ virtual void blit_render_target_to_screen(RID p_render_target,const Rect2& p_screen_rect,int p_screen=0);
+ virtual void end_frame();
+ virtual void finalize();
+
+ static void make_current();
+
+
+ static void register_config();
+ RasterizerGLES3();
+ ~RasterizerGLES3();
+};
+
+#endif // RASTERIZERGLES3_H
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
new file mode 100644
index 0000000000..b29de876a4
--- /dev/null
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -0,0 +1,2045 @@
+#include "rasterizer_storage_gles3.h"
+#include "globals.h"
+
+/* 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_SRGB_PVRTC_2BPPV1_EXT 0x8A54
+#define _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
+#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
+#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
+
+
+#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_LUMINANCE_LATC1_EXT 0x8C70
+#define _EXT_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
+#define _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
+#define _EXT_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
+
+
+#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
+
+
+
+#define _EXT_SLUMINANCE_NV 0x8C46
+#define _EXT_SLUMINANCE_ALPHA_NV 0x8C44
+#define _EXT_SRGB8_NV 0x8C41
+#define _EXT_SLUMINANCE8_NV 0x8C47
+#define _EXT_SLUMINANCE8_ALPHA8_NV 0x8C45
+
+
+#define _EXT_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
+#define _EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+
+
+
+#define _EXT_ATC_RGB_AMD 0x8C92
+#define _EXT_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
+#define _EXT_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
+
+
+#define _TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define _DECODE_EXT 0x8A49
+#define _SKIP_DECODE_EXT 0x8A4A
+
+
+#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+
+
+
+Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,GLenum &r_gl_type,bool &r_compressed,bool &srgb) {
+
+
+ r_compressed=false;
+ r_gl_format=0;
+ Image image=p_image;
+ srgb=false;
+
+ bool need_decompress=false;
+
+ switch(p_format) {
+
+ case Image::FORMAT_L8: {
+ r_gl_internal_format=GL_LUMINANCE;
+ r_gl_format=GL_LUMINANCE;
+ r_gl_type=GL_UNSIGNED_BYTE;
+
+ } break;
+ case Image::FORMAT_LA8: {
+
+ r_gl_internal_format=GL_LUMINANCE_ALPHA;
+ r_gl_format=GL_LUMINANCE_ALPHA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+
+ } break;
+ case Image::FORMAT_R8: {
+
+ r_gl_internal_format=GL_R8;
+ r_gl_format=GL_RED;
+ r_gl_type=GL_UNSIGNED_BYTE;
+
+ } break;
+ case Image::FORMAT_RG8: {
+
+ r_gl_internal_format=GL_RG8;
+ r_gl_format=GL_RG;
+ r_gl_type=GL_UNSIGNED_BYTE;
+
+ } break;
+ case Image::FORMAT_RGB8: {
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_SRGB8:GL_RGB8;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ srgb=true;
+
+ } break;
+ case Image::FORMAT_RGBA8: {
+
+ r_gl_format=GL_RGBA;
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_SRGB8_ALPHA8:GL_RGBA8;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ srgb=true;
+
+ } break;
+ case Image::FORMAT_RGB565: {
+
+ r_gl_internal_format=GL_RGB565;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_UNSIGNED_SHORT_5_6_5;
+
+ } break;
+ case Image::FORMAT_RGBA4444: {
+
+ r_gl_internal_format=GL_RGBA4;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_SHORT_4_4_4_4;
+
+ } break;
+ case Image::FORMAT_RGBA5551: {
+
+ r_gl_internal_format=GL_RGB5_A1;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_SHORT_5_5_5_1;
+
+
+ } break;
+ case Image::FORMAT_RF: {
+
+
+ r_gl_internal_format=GL_R32F;
+ r_gl_format=GL_RED;
+ r_gl_type=GL_FLOAT;
+
+ } break;
+ case Image::FORMAT_RGF: {
+
+ r_gl_internal_format=GL_RG32F;
+ r_gl_format=GL_RG;
+ r_gl_type=GL_FLOAT;
+
+ } break;
+ case Image::FORMAT_RGBF: {
+
+ r_gl_internal_format=GL_RGB32F;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_FLOAT;
+
+ } break;
+ case Image::FORMAT_RGBAF: {
+
+ r_gl_internal_format=GL_RGBA32F;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_FLOAT;
+
+ } break;
+ case Image::FORMAT_RH: {
+ r_gl_internal_format=GL_R32F;
+ r_gl_format=GL_RED;
+ r_gl_type=GL_HALF_FLOAT;
+ } break;
+ case Image::FORMAT_RGH: {
+ r_gl_internal_format=GL_RG32F;
+ r_gl_format=GL_RG;
+ r_gl_type=GL_HALF_FLOAT;
+
+ } break;
+ case Image::FORMAT_RGBH: {
+ r_gl_internal_format=GL_RGB32F;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_HALF_FLOAT;
+
+ } break;
+ case Image::FORMAT_RGBAH: {
+ r_gl_internal_format=GL_RGBA32F;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_HALF_FLOAT;
+
+ } break;
+ case Image::FORMAT_DXT1: {
+
+ if (config.s3tc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+
+ } break;
+ case Image::FORMAT_DXT3: {
+
+
+ if (config.s3tc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+
+ } break;
+ case Image::FORMAT_DXT5: {
+
+ if (config.s3tc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+
+ } break;
+ case Image::FORMAT_ATI1: {
+
+ if (config.latc_supported) {
+
+
+ r_gl_internal_format=_EXT_COMPRESSED_LUMINANCE_LATC1_EXT;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+
+
+ } break;
+ case Image::FORMAT_ATI2: {
+
+ if (config.latc_supported) {
+
+
+ r_gl_internal_format=_EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ } else {
+
+ need_decompress=true;
+ }
+
+ } break;
+ case Image::FORMAT_BPTC_RGBA: {
+
+ if (config.bptc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:GL_COMPRESSED_RGBA_BPTC_UNORM;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_BPTC_RGBF: {
+
+ if (config.bptc_supported) {
+
+
+ r_gl_internal_format=GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_FLOAT;
+ r_compressed=true;
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_BPTC_RGBFU: {
+ if (config.bptc_supported) {
+
+
+ r_gl_internal_format=GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_FLOAT;
+ r_compressed=true;
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_PVRTC2: {
+
+ if (config.pvrtc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:_EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_PVRTC2A: {
+
+ if (config.pvrtc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:_EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+
+ } break;
+ case Image::FORMAT_PVRTC4: {
+
+ if (config.pvrtc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:_EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+ } break;
+ case Image::FORMAT_PVRTC4A: {
+
+ if (config.pvrtc_supported) {
+
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:_EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+
+ } break;
+ case Image::FORMAT_ETC: {
+
+ if (config.etc_supported) {
+
+ r_gl_internal_format=_EXT_ETC1_RGB8_OES;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+
+ } break;
+ case Image::FORMAT_ETC2_R11: {
+
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=GL_COMPRESSED_R11_EAC;
+ r_gl_format=GL_RED;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_ETC2_R11S: {
+
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=GL_COMPRESSED_SIGNED_R11_EAC;
+ r_gl_format=GL_RED;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_ETC2_RG11: {
+
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=GL_COMPRESSED_RG11_EAC;
+ r_gl_format=GL_RG;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_ETC2_RG11S: {
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=GL_COMPRESSED_SIGNED_RG11_EAC;
+ r_gl_format=GL_RG;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+
+ } else {
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_ETC2_RGB8: {
+
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB8_ETC2:GL_COMPRESSED_RGB8_ETC2;
+ r_gl_format=GL_RGB;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_ETC2_RGBA8: {
+
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:GL_COMPRESSED_RGBA8_ETC2_EAC;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ case Image::FORMAT_ETC2_RGB8A1: {
+
+ if (config.etc2_supported) {
+
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
+ r_gl_format=GL_RGBA;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=true;
+ srgb=true;
+
+
+ } else {
+
+ need_decompress=true;
+ }
+ } break;
+ default: {
+
+ ERR_FAIL_V(Image());
+ }
+ }
+
+ if (need_decompress) {
+
+ if (!image.empty()) {
+ image.decompress();
+ ERR_FAIL_COND_V(image.is_compressed(),image);
+ image.convert(Image::FORMAT_RGBA8);
+ }
+
+
+ r_gl_format=GL_RGBA;
+ r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_SRGB8_ALPHA8:GL_RGBA8;
+ r_gl_type=GL_UNSIGNED_BYTE;
+ r_compressed=false;
+ srgb=true;
+
+ return image;
+
+ }
+
+
+ return image;
+}
+
+static const GLenum _cube_side_enum[6]={
+
+ GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+ GL_TEXTURE_CUBE_MAP_POSITIVE_X,
+ GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+ GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+
+};
+
+RID RasterizerStorageGLES3::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 RasterizerStorageGLES3::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags) {
+
+ int components;
+ GLenum format;
+ GLenum internal_format;
+ GLenum type;
+
+ bool compressed;
+ bool srgb;
+
+ if (p_flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
+ p_flags&=~VS::TEXTURE_FLAG_MIPMAPS; // no mipies for video
+ }
+
+
+ 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;
+
+ _get_gl_image_and_format(Image(),texture->format,texture->flags,format,internal_format,type,compressed,srgb);
+
+ texture->alloc_width = texture->width;
+ texture->alloc_height = texture->height;
+
+
+ texture->gl_format_cache=format;
+ texture->gl_type_cache=type;
+ texture->gl_internal_format_cache=internal_format;
+ texture->compressed=compressed;
+ texture->srgb=srgb;
+ texture->data_size=0;
+ texture->mipmaps=1;
+
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(texture->target, texture->tex_id);
+
+
+ if (p_flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
+ //prealloc if video
+ glTexImage2D(texture->target, 0, internal_format, p_width, p_height, 0, format, type,NULL);
+ }
+
+ texture->active=true;
+}
+
+void RasterizerStorageGLES3::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->render_target);
+ ERR_FAIL_COND(texture->format != p_image.get_format() );
+ ERR_FAIL_COND( p_image.empty() );
+
+ GLenum type;
+ GLenum format;
+ GLenum internal_format;
+ bool compressed;
+ bool srgb;
+
+
+ Image img = _get_gl_image_and_format(p_image, p_image.get_format(),texture->flags,format,internal_format,type,compressed,srgb);
+
+ if (config.shrink_textures_x2 && (p_image.has_mipmaps() || !p_image.is_compressed()) && !(texture->flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
+
+ texture->alloc_height = MAX(1,texture->alloc_height/2);
+ texture->alloc_width = MAX(1,texture->alloc_width/2);
+
+ if (texture->alloc_width == img.get_width()/2 && texture->alloc_height == img.get_height()/2) {
+
+ img.shrink_x2();
+ } else if (img.get_format() <= Image::FORMAT_RGB565) {
+
+ 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);
+
+ texture->ignore_mipmaps = compressed && !img.has_mipmaps();
+
+ if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps)
+ glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,config.use_fast_texture_filter?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR_MIPMAP_LINEAR);
+ else {
+ if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
+ glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ } else {
+ glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
+
+ }
+ }
+
+
+ if (config.srgb_decode_supported && srgb) {
+
+ if (texture->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+
+ glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
+ } else {
+ glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_SKIP_DECODE_EXT);
+ }
+ }
+
+ 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
+ }
+
+ if ((texture->flags&VS::TEXTURE_FLAG_REPEAT || texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
+
+ if (texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT){
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT );
+ }
+ else{
+ 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 (config.use_anisotropic_filter) {
+
+ if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
+
+ glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config.anisotropic_level);
+ } else {
+ glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
+ }
+ }
+
+ int mipmaps= (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && img.has_mipmaps()) ? img.get_mipmap_count() +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);
+
+ //print_line("mipmap: "+itos(i)+" size: "+itos(size)+" w: "+itos(mm_w)+", h: "+itos(mm_h));
+
+ 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);
+ if (texture->flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING) {
+ glTexSubImage2D( blit_target, i, 0,0,w, h,format,type,&read[ofs] );
+ } else {
+ glTexImage2D(blit_target, i, internal_format, w, h, 0, format, type,&read[ofs]);
+ }
+
+ }
+ tsize+=size;
+
+ w = MAX(1,w>>1);
+ h = MAX(1,h>>1);
+
+ }
+
+ info.texture_mem-=texture->total_data_size;
+ texture->total_data_size=tsize;
+ info.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 (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && mipmaps==1 && !texture->ignore_mipmaps) {
+ //generate mipmaps if they were requested and the image does not contain them
+ glGenerateMipmap(texture->target);
+ }
+
+ texture->mipmaps=mipmaps;
+
+ //texture_set_flags(p_texture,texture->flags);
+
+
+}
+
+Image RasterizerStorageGLES3::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());
+ ERR_FAIL_COND_V(texture->data_size==0,Image());
+ ERR_FAIL_COND_V(texture->render_target,Image());
+
+#ifdef GLEW_ENABLED
+
+ DVector<uint8_t> data;
+
+ int data_size = Image::get_image_data_size(texture->width,texture->height,texture->format,texture->mipmaps>1?-1:0);
+
+ data.resize(data_size);
+ DVector<uint8_t>::Write wb = data.write();
+
+ glActiveTexture(GL_TEXTURE0);
+
+ glBindTexture(texture->target,texture->tex_id);
+
+ for(int i=0;i<texture->mipmaps;i++) {
+
+ int ofs=0;
+ if (i>0) {
+ ofs=Image::get_image_data_size(texture->alloc_width,texture->alloc_height,texture->format,i-1);
+ }
+
+ if (texture->compressed) {
+
+ glPixelStorei(GL_PACK_ALIGNMENT, 4);
+ glGetCompressedTexImage(texture->target,i,&wb[ofs]);
+
+ } else {
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glGetTexImage(texture->target,i,texture->gl_format_cache,texture->gl_type_cache,&wb[ofs]);
+ }
+ }
+
+
+ wb=DVector<uint8_t>::Write();
+
+ Image img(texture->alloc_width,texture->alloc_height,texture->mipmaps>1?true:false,texture->format,data);
+
+ return img;
+#else
+
+ ERR_EXPLAIN("Sorry, It's not posible to obtain images back in OpenGL ES");
+#endif
+}
+
+void RasterizerStorageGLES3::texture_set_flags(RID p_texture,uint32_t p_flags) {
+
+ Texture *texture = texture_owner.get( p_texture );
+ ERR_FAIL_COND(!texture);
+ if (texture->render_target) {
+
+ p_flags&=VS::TEXTURE_FLAG_FILTER;//can change only filter
+ }
+
+ bool had_mipmaps = texture->flags&VS::TEXTURE_FLAG_MIPMAPS;
+
+ 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
+
+
+ if ((texture->flags&VS::TEXTURE_FLAG_REPEAT || texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT) && texture->target != GL_TEXTURE_CUBE_MAP) {
+
+ if (texture->flags&VS::TEXTURE_FLAG_MIRRORED_REPEAT){
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT );
+ }
+ else {
+ 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 (config.use_anisotropic_filter) {
+
+ if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {
+
+ glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config.anisotropic_level);
+ } else {
+ glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
+ }
+ }
+
+ if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) {
+ if (!had_mipmaps && texture->mipmaps==1) {
+ glGenerateMipmap(texture->target);
+ }
+ glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,config.use_fast_texture_filter?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR_MIPMAP_LINEAR);
+
+ } else{
+ if (texture->flags&VS::TEXTURE_FLAG_FILTER) {
+ glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ } else {
+ glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
+
+ }
+ }
+
+
+ if (config.srgb_decode_supported && texture->srgb) {
+
+ if (texture->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) {
+
+ glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT);
+ } else {
+ glTexParameteri(texture->target,_TEXTURE_SRGB_DECODE_EXT,_SKIP_DECODE_EXT);
+ }
+ }
+
+ 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
+ }
+
+}
+uint32_t RasterizerStorageGLES3::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 RasterizerStorageGLES3::texture_get_format(RID p_texture) const {
+
+ Texture * texture = texture_owner.get(p_texture);
+
+ ERR_FAIL_COND_V(!texture,Image::FORMAT_L8);
+
+ return texture->format;
+}
+uint32_t RasterizerStorageGLES3::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 RasterizerStorageGLES3::texture_get_height(RID p_texture) const {
+
+ Texture * texture = texture_owner.get(p_texture);
+
+ ERR_FAIL_COND_V(!texture,0);
+
+ return texture->height;
+}
+
+
+void RasterizerStorageGLES3::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(texture->render_target);
+
+ ERR_FAIL_COND(p_width<=0 || p_width>16384);
+ ERR_FAIL_COND(p_height<=0 || p_height>16384);
+ //real texture size is in alloc width and height
+ texture->width=p_width;
+ texture->height=p_height;
+
+}
+
+void RasterizerStorageGLES3::texture_set_path(RID p_texture,const String& p_path) {
+ Texture * texture = texture_owner.get(p_texture);
+ ERR_FAIL_COND(!texture);
+
+ texture->path=p_path;
+
+}
+
+String RasterizerStorageGLES3::texture_get_path(RID p_texture) const{
+
+ Texture * texture = texture_owner.get(p_texture);
+ ERR_FAIL_COND_V(!texture,String());
+ return texture->path;
+}
+void RasterizerStorageGLES3::texture_debug_usage(List<VS::TextureInfo> *r_info){
+
+ List<RID> textures;
+ texture_owner.get_owned_list(&textures);
+
+ for (List<RID>::Element *E=textures.front();E;E=E->next()) {
+
+ Texture *t = texture_owner.get(E->get());
+ if (!t)
+ continue;
+ VS::TextureInfo tinfo;
+ tinfo.path=t->path;
+ tinfo.format=t->format;
+ tinfo.size.x=t->alloc_width;
+ tinfo.size.y=t->alloc_height;
+ tinfo.bytes=t->total_data_size;
+ r_info->push_back(tinfo);
+ }
+
+}
+
+void RasterizerStorageGLES3::texture_set_shrink_all_x2_on_set_data(bool p_enable) {
+
+ config.shrink_textures_x2=p_enable;
+}
+
+
+
+/* SHADER API */
+
+
+RID RasterizerStorageGLES3::shader_create(VS::ShaderMode p_mode){
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::shader_set_mode(RID p_shader,VS::ShaderMode p_mode){
+
+
+}
+VS::ShaderMode RasterizerStorageGLES3::shader_get_mode(RID p_shader) const {
+
+ return VS::SHADER_SPATIAL;
+}
+void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String& p_code){
+
+
+}
+String RasterizerStorageGLES3::shader_get_code(RID p_shader) const{
+
+ return String();
+}
+void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const{
+
+
+}
+
+void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture){
+
+
+}
+RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
+
+ return RID();
+}
+
+
+/* COMMON MATERIAL API */
+
+RID RasterizerStorageGLES3::material_create(){
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::material_set_shader(RID p_shader_material, RID p_shader){
+
+
+}
+RID RasterizerStorageGLES3::material_get_shader(RID p_shader_material) const{
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value){
+
+
+}
+Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringName& p_param) const{
+
+ return Variant();
+}
+
+/* MESH API */
+
+RID RasterizerStorageGLES3::mesh_create(){
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes){
+
+
+}
+
+void RasterizerStorageGLES3::mesh_set_morph_target_count(RID p_mesh,int p_amount){
+
+
+}
+int RasterizerStorageGLES3::mesh_get_morph_target_count(RID p_mesh) const{
+
+ return 0;
+}
+
+
+void RasterizerStorageGLES3::mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode){
+
+
+}
+VS::MorphTargetMode RasterizerStorageGLES3::mesh_get_morph_target_mode(RID p_mesh) const{
+
+ return VS::MORPH_MODE_NORMALIZED;
+}
+
+void RasterizerStorageGLES3::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material){
+
+
+}
+RID RasterizerStorageGLES3::mesh_surface_get_material(RID p_mesh, int p_surface) const{
+
+ return RID();
+}
+
+int RasterizerStorageGLES3::mesh_surface_get_array_len(RID p_mesh, int p_surface) const{
+
+ return 0;
+}
+int RasterizerStorageGLES3::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const{
+
+
+ return 0;
+}
+
+DVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, int p_surface) const{
+
+ return DVector<uint8_t>();
+}
+DVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_index_array(RID p_mesh, int p_surface) const{
+
+
+ return DVector<uint8_t>();
+}
+
+
+uint32_t RasterizerStorageGLES3::mesh_surface_get_format(RID p_mesh, int p_surface) const{
+
+ return 0;
+}
+VS::PrimitiveType RasterizerStorageGLES3::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const{
+
+ return VS::PRIMITIVE_MAX;
+}
+
+void RasterizerStorageGLES3::mesh_remove_surface(RID p_mesh,int p_index){
+
+
+}
+int RasterizerStorageGLES3::mesh_get_surface_count(RID p_mesh) const{
+
+ return 0;
+}
+
+void RasterizerStorageGLES3::mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb){
+
+
+}
+AABB RasterizerStorageGLES3::mesh_get_custom_aabb(RID p_mesh) const{
+
+ return AABB();
+}
+
+AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh) const{
+
+ return AABB();
+}
+void RasterizerStorageGLES3::mesh_clear(RID p_mesh){
+
+
+}
+
+/* MULTIMESH API */
+
+
+RID RasterizerStorageGLES3::multimesh_create(){
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::multimesh_allocate(RID p_multimesh,int p_instances,VS::MultimeshTransformFormat p_transform_format,VS::MultimeshColorFormat p_color_format,bool p_gen_aabb){
+
+
+}
+int RasterizerStorageGLES3::multimesh_get_instance_count(RID p_multimesh) const{
+
+ return 0;
+}
+
+void RasterizerStorageGLES3::multimesh_set_mesh(RID p_multimesh,RID p_mesh){
+
+
+}
+void RasterizerStorageGLES3::multimesh_set_custom_aabb(RID p_multimesh,const AABB& p_aabb){
+
+
+}
+void RasterizerStorageGLES3::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform){
+
+
+}
+void RasterizerStorageGLES3::multimesh_instance_set_transform_2d(RID p_multimesh,int p_index,const Matrix32& p_transform){
+
+
+}
+void RasterizerStorageGLES3::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color){
+
+
+}
+
+RID RasterizerStorageGLES3::multimesh_get_mesh(RID p_multimesh) const{
+
+
+ return RID();
+}
+AABB RasterizerStorageGLES3::multimesh_get_custom_aabb(RID p_multimesh,const AABB& p_aabb) const{
+
+ return AABB();
+}
+
+Transform RasterizerStorageGLES3::multimesh_instance_get_transform(RID p_multimesh,int p_index) const{
+
+ return Transform();
+}
+Matrix32 RasterizerStorageGLES3::multimesh_instance_get_transform_2d(RID p_multimesh,int p_index) const{
+
+
+ return Matrix32();
+}
+Color RasterizerStorageGLES3::multimesh_instance_get_color(RID p_multimesh,int p_index) const{
+
+ return Color();
+}
+
+void RasterizerStorageGLES3::multimesh_set_visible_instances(RID p_multimesh,int p_visible){
+
+
+}
+int RasterizerStorageGLES3::multimesh_get_visible_instances(RID p_multimesh) const{
+
+ return 0;
+}
+
+AABB RasterizerStorageGLES3::multimesh_get_aabb(RID p_mesh) const{
+
+ return AABB();
+}
+
+/* IMMEDIATE API */
+
+RID RasterizerStorageGLES3::immediate_create(){
+
+ return RID();
+}
+void RasterizerStorageGLES3::immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture){
+
+
+}
+void RasterizerStorageGLES3::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
+
+
+}
+void RasterizerStorageGLES3::immediate_vertex_2d(RID p_immediate,const Vector3& p_vertex){
+
+
+}
+void RasterizerStorageGLES3::immediate_normal(RID p_immediate,const Vector3& p_normal){
+
+
+}
+void RasterizerStorageGLES3::immediate_tangent(RID p_immediate,const Plane& p_tangent){
+
+
+}
+void RasterizerStorageGLES3::immediate_color(RID p_immediate,const Color& p_color){
+
+
+}
+void RasterizerStorageGLES3::immediate_uv(RID p_immediate,const Vector2& tex_uv){
+
+
+}
+void RasterizerStorageGLES3::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
+
+
+}
+void RasterizerStorageGLES3::immediate_end(RID p_immediate){
+
+
+}
+void RasterizerStorageGLES3::immediate_clear(RID p_immediate){
+
+
+}
+void RasterizerStorageGLES3::immediate_set_material(RID p_immediate,RID p_material){
+
+
+}
+RID RasterizerStorageGLES3::immediate_get_material(RID p_immediate) const{
+
+ return RID();
+}
+
+/* SKELETON API */
+
+RID RasterizerStorageGLES3::skeleton_create(){
+
+ return RID();
+}
+void RasterizerStorageGLES3::skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton){
+
+
+}
+int RasterizerStorageGLES3::skeleton_get_bone_count(RID p_skeleton) const{
+
+ return 0;
+}
+void RasterizerStorageGLES3::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform){
+
+
+}
+Transform RasterizerStorageGLES3::skeleton_bone_get_transform(RID p_skeleton,int p_bone){
+
+ return Transform();
+}
+void RasterizerStorageGLES3::skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Matrix32& p_transform){
+
+
+}
+Matrix32 RasterizerStorageGLES3::skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone){
+
+ return Matrix32();
+}
+
+/* Light API */
+
+RID RasterizerStorageGLES3::light_create(VS::LightType p_type){
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::light_set_color(RID p_light,const Color& p_color){
+
+
+}
+void RasterizerStorageGLES3::light_set_param(RID p_light,VS::LightParam p_param,float p_value){
+
+
+}
+void RasterizerStorageGLES3::light_set_shadow(RID p_light,bool p_enabled){
+
+
+}
+void RasterizerStorageGLES3::light_set_projector(RID p_light,RID p_texture){
+
+
+}
+void RasterizerStorageGLES3::light_set_attenuation_texure(RID p_light,RID p_texture){
+
+
+}
+void RasterizerStorageGLES3::light_set_negative(RID p_light,bool p_enable){
+
+
+}
+void RasterizerStorageGLES3::light_set_cull_mask(RID p_light,uint32_t p_mask){
+
+
+}
+void RasterizerStorageGLES3::light_set_shader(RID p_light,RID p_shader){
+
+
+}
+
+
+void RasterizerStorageGLES3::light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode){
+
+
+}
+
+/* PROBE API */
+
+RID RasterizerStorageGLES3::reflection_probe_create(){
+
+ return RID();
+}
+
+void RasterizerStorageGLES3::reflection_probe_set_intensity(RID p_probe, float p_intensity){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_clip(RID p_probe, float p_near, float p_far){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_min_blend_distance(RID p_probe, float p_distance){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_extents(RID p_probe, const Vector3& p_extents){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_enable_parallax_correction(RID p_probe, bool p_enable){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_resolution(RID p_probe, int p_resolution){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_hide_skybox(RID p_probe, bool p_hide){
+
+
+}
+void RasterizerStorageGLES3::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers){
+
+
+}
+
+
+/* ROOM API */
+
+RID RasterizerStorageGLES3::room_create(){
+
+ return RID();
+}
+void RasterizerStorageGLES3::room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform){
+
+
+}
+void RasterizerStorageGLES3::room_clear_bounds(){
+
+
+}
+
+/* PORTAL API */
+
+// portals are only (x/y) points, forming a convex shape, which its clockwise
+// order points outside. (z is 0);
+
+RID RasterizerStorageGLES3::portal_create(){
+
+ return RID();
+}
+void RasterizerStorageGLES3::portal_set_shape(RID p_portal, const Vector<Point2>& p_shape){
+
+
+}
+void RasterizerStorageGLES3::portal_set_enabled(RID p_portal, bool p_enabled){
+
+
+}
+void RasterizerStorageGLES3::portal_set_disable_distance(RID p_portal, float p_distance){
+
+
+}
+void RasterizerStorageGLES3::portal_set_disabled_color(RID p_portal, const Color& p_color){
+
+
+}
+
+
+/* RENDER TARGET */
+
+
+void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
+
+ if (rt->front.fbo) {
+ glDeleteFramebuffers(1,&rt->front.fbo);
+ glDeleteTextures(1,&rt->front.color);
+ rt->front.fbo=0;
+ }
+
+ if (rt->back.fbo) {
+ glDeleteFramebuffers(1,&rt->back.fbo);
+ glDeleteTextures(1,&rt->back.color);
+ rt->back.fbo=0;
+ }
+
+ if (rt->deferred.fbo) {
+ glDeleteFramebuffers(1,&rt->deferred.fbo);
+ glDeleteFramebuffers(1,&rt->deferred.fbo_color);
+ glDeleteTextures(1,&rt->deferred.albedo_ao);
+ glDeleteTextures(1,&rt->deferred.normal_special);
+ glDeleteTextures(1,&rt->deferred.metal_rough_motion);
+ rt->deferred.fbo=0;
+ rt->deferred.fbo_color=0;
+ }
+
+ if (rt->depth) {
+ glDeleteRenderbuffers(1,&rt->depth);
+ rt->depth=0;
+ }
+
+}
+
+void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){
+
+ if (rt->width<=0 || rt->height<=0)
+ return;
+
+ glGenFramebuffers(1, &rt->front.fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, rt->front.fbo);
+
+
+ glGenRenderbuffers(1, &rt->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, rt->depth );
+ if (config.fbo_format==FBO_FORMAT_16_BITS) {
+ glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16, rt->width, rt->height);
+ } else {
+ glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8, rt->width, rt->height);
+ }
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0 );
+
+
+ glGenTextures(1, &rt->front.color);
+ glBindTexture(GL_TEXTURE_2D, rt->front.color);
+
+
+ GLuint color_internal_format;
+ GLuint color_format;
+ GLuint color_type;
+
+
+ if (config.fbo_format==FBO_FORMAT_16_BITS) {
+
+ if (rt->flags[RENDER_TARGET_TRANSPARENT]) {
+ color_internal_format=GL_RGB5_A1;
+ color_format=GL_RGBA;
+ color_type=GL_UNSIGNED_SHORT_5_5_5_1;
+ } else {
+ color_internal_format=GL_RGB565;
+ color_format=GL_RGB;
+ color_type=GL_UNSIGNED_SHORT_5_6_5;
+ }
+
+ } else if (config.fbo_format==FBO_FORMAT_32_BITS) {
+
+ if (rt->flags[RENDER_TARGET_TRANSPARENT]) {
+ color_internal_format=GL_RGBA8;
+ color_format=GL_RGBA;
+ color_type=GL_UNSIGNED_BYTE;
+ } else {
+ color_internal_format=GL_RGB10_A2;
+ color_format=GL_RGBA;
+ color_type=GL_UNSIGNED_INT_2_10_10_10_REV;
+ }
+ } else if (config.fbo_format==FBO_FORMAT_FLOAT) {
+
+ color_internal_format=GL_RGBA16F;
+ color_format=GL_RGBA;
+ color_type=GL_HALF_FLOAT;
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, NULL);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->front.color, 0);
+
+ {
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo);
+
+ ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ }
+
+
+ if (!rt->flags[RENDER_TARGET_NO_SAMPLING]) {
+
+ glGenFramebuffers(1, &rt->back.fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, rt->back.fbo);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
+
+ glGenTextures(1, &rt->back.color);
+ glBindTexture(GL_TEXTURE_2D, rt->back.color);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, color_format, color_type, NULL);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->back.color, 0);
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ _render_target_clear(rt);
+ ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ }
+ }
+
+
+
+ if (config.fbo_deferred && !rt->flags[RENDER_TARGET_NO_3D]) {
+
+
+ //regular fbo
+ glGenFramebuffers(1, &rt->deferred.fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, rt->deferred.fbo);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
+
+ glGenTextures(1, &rt->deferred.albedo_ao);
+ glBindTexture(GL_TEXTURE_2D, rt->deferred.albedo_ao);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rt->width, rt->height, 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);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->deferred.albedo_ao, 0);
+
+ glGenTextures(1, &rt->deferred.metal_rough_motion);
+ glBindTexture(GL_TEXTURE_2D, rt->deferred.metal_rough_motion);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rt->width, rt->height, 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);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, rt->deferred.metal_rough_motion, 0);
+
+ glGenTextures(1, &rt->deferred.normal_special);
+ glBindTexture(GL_TEXTURE_2D, rt->deferred.normal_special);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rt->width, rt->height, 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);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, rt->deferred.normal_special, 0);
+
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ _render_target_clear(rt);
+ ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ }
+
+ //regular fbo with color attachment (needed for emission or objects rendered as forward)
+
+ glGenFramebuffers(1, &rt->deferred.fbo_color);
+ glBindFramebuffer(GL_FRAMEBUFFER, rt->deferred.fbo_color);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->deferred.albedo_ao, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, rt->deferred.metal_rough_motion, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, rt->deferred.normal_special, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, rt->front.color, 0);
+
+
+ status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ _render_target_clear(rt);
+ ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE );
+ }
+ }
+
+
+}
+
+
+RID RasterizerStorageGLES3::render_target_create(){
+
+ RenderTarget *rt = memnew( RenderTarget );
+ return render_target_owner.make_rid(rt);
+}
+
+void RasterizerStorageGLES3::render_target_set_size(RID p_render_target,int p_width, int p_height){
+
+ RenderTarget *rt = render_target_owner.getornull(p_render_target);
+ ERR_FAIL_COND(!rt);
+
+ if (rt->width==p_width && rt->height==p_height)
+ return;
+
+ _render_target_clear(rt);
+ rt->width=p_width;
+ rt->height=p_height;
+ _render_target_allocate(rt);
+
+}
+
+
+RID RasterizerStorageGLES3::render_target_get_texture(RID p_render_target) const{
+
+ RenderTarget *rt = render_target_owner.getornull(p_render_target);
+ ERR_FAIL_COND_V(!rt,RID());
+
+
+ return RID();
+}
+Image RasterizerStorageGLES3::render_target_get_image(RID p_render_target) const{
+
+ return Image();
+}
+void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value) {
+
+ RenderTarget *rt = render_target_owner.getornull(p_render_target);
+ ERR_FAIL_COND(!rt);
+
+ rt->flags[p_flag]=p_value;
+
+ switch(p_flag) {
+ case RENDER_TARGET_NO_3D:
+ case RENDER_TARGET_TRANSPARENT: {
+ //must reset for these formats
+ _render_target_clear(rt);
+ _render_target_allocate(rt);
+
+ } break;
+ default: {}
+ }
+}
+
+bool RasterizerStorageGLES3::render_target_renedered_in_frame(RID p_render_target){
+
+ return false;
+}
+
+/* CANVAS SHADOW */
+
+
+RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) {
+
+ CanvasLightShadow *cls = memnew( CanvasLightShadow );
+ if (p_width>config.max_texture_size)
+ p_width=config.max_texture_size;
+
+ cls->size=p_width;
+ cls->height=16;
+
+ glActiveTexture(GL_TEXTURE0);
+
+ glGenFramebuffers(1, &cls->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
+
+ glGenRenderbuffers(1, &cls->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, cls->depth );
+ glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24, cls->size, cls->height);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, cls->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0 );
+
+ glGenTextures(1,&cls->distance);
+ glBindTexture(GL_TEXTURE_2D, cls->distance);
+ if (config.use_rgba_2d_shadows) {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, cls->size, cls->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ } else {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cls->size, cls->height, 0, GL_RED, GL_FLOAT, NULL);
+ }
+
+
+
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, cls->distance, 0);
+
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ //printf("errnum: %x\n",status);
+ glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo);
+
+ ERR_FAIL_COND_V( status != GL_FRAMEBUFFER_COMPLETE, RID() );
+
+ return canvas_light_shadow_owner.make_rid(cls);
+}
+
+/* LIGHT SHADOW MAPPING */
+
+
+RID RasterizerStorageGLES3::canvas_light_occluder_create() {
+
+ CanvasOccluder *co = memnew( CanvasOccluder );
+ co->index_id=0;
+ co->vertex_id=0;
+ co->len=0;
+
+ return canvas_occluder_owner.make_rid(co);
+}
+
+void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines) {
+
+ CanvasOccluder *co = canvas_occluder_owner.get(p_occluder);
+ ERR_FAIL_COND(!co);
+
+ co->lines=p_lines;
+
+ if (p_lines.size()!=co->len) {
+
+ if (co->index_id)
+ glDeleteBuffers(1,&co->index_id);
+ if (co->vertex_id)
+ glDeleteBuffers(1,&co->vertex_id);
+
+ co->index_id=0;
+ co->vertex_id=0;
+ co->len=0;
+
+ }
+
+ if (p_lines.size()) {
+
+
+
+ DVector<float> geometry;
+ DVector<uint16_t> indices;
+ int lc = p_lines.size();
+
+ geometry.resize(lc*6);
+ indices.resize(lc*3);
+
+ DVector<float>::Write vw=geometry.write();
+ DVector<uint16_t>::Write iw=indices.write();
+
+
+ DVector<Vector2>::Read lr=p_lines.read();
+
+ const int POLY_HEIGHT = 16384;
+
+ for(int i=0;i<lc/2;i++) {
+
+ vw[i*12+0]=lr[i*2+0].x;
+ vw[i*12+1]=lr[i*2+0].y;
+ vw[i*12+2]=POLY_HEIGHT;
+
+ vw[i*12+3]=lr[i*2+1].x;
+ vw[i*12+4]=lr[i*2+1].y;
+ vw[i*12+5]=POLY_HEIGHT;
+
+ vw[i*12+6]=lr[i*2+1].x;
+ vw[i*12+7]=lr[i*2+1].y;
+ vw[i*12+8]=-POLY_HEIGHT;
+
+ vw[i*12+9]=lr[i*2+0].x;
+ vw[i*12+10]=lr[i*2+0].y;
+ vw[i*12+11]=-POLY_HEIGHT;
+
+ iw[i*6+0]=i*4+0;
+ iw[i*6+1]=i*4+1;
+ iw[i*6+2]=i*4+2;
+
+ iw[i*6+3]=i*4+2;
+ iw[i*6+4]=i*4+3;
+ iw[i*6+5]=i*4+0;
+
+ }
+
+ //if same buffer len is being set, just use BufferSubData to avoid a pipeline flush
+
+
+ if (!co->vertex_id) {
+ glGenBuffers(1,&co->vertex_id);
+ glBindBuffer(GL_ARRAY_BUFFER,co->vertex_id);
+ glBufferData(GL_ARRAY_BUFFER,lc*6*sizeof(real_t),vw.ptr(),GL_STATIC_DRAW);
+ } else {
+
+ glBindBuffer(GL_ARRAY_BUFFER,co->vertex_id);
+ glBufferSubData(GL_ARRAY_BUFFER,0,lc*6*sizeof(real_t),vw.ptr());
+
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER,0); //unbind
+
+ if (!co->index_id) {
+
+ glGenBuffers(1,&co->index_id);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,co->index_id);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER,lc*3*sizeof(uint16_t),iw.ptr(),GL_STATIC_DRAW);
+ } else {
+
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,co->index_id);
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,lc*3*sizeof(uint16_t),iw.ptr());
+ }
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind
+
+ co->len=lc;
+
+ }
+
+}
+
+bool RasterizerStorageGLES3::free(RID p_rid){
+
+ if (render_target_owner.owns(p_rid)) {
+
+ RenderTarget *rt = render_target_owner.getornull(p_rid);
+ _render_target_clear(rt);
+ render_target_owner.free(p_rid);
+ memdelete(rt);
+
+ } else if (texture_owner.owns(p_rid)) {
+ // delete the texture
+ Texture *texture = texture_owner.get(p_rid);
+ info.texture_mem-=texture->total_data_size;
+ texture_owner.free(p_rid);
+ memdelete(texture);
+ } else if (canvas_occluder_owner.owns(p_rid)) {
+
+
+ CanvasOccluder *co = canvas_occluder_owner.get(p_rid);
+ if (co->index_id)
+ glDeleteBuffers(1,&co->index_id);
+ if (co->vertex_id)
+ glDeleteBuffers(1,&co->vertex_id);
+
+ canvas_occluder_owner.free(p_rid);
+ memdelete(co);
+
+ } else if (canvas_light_shadow_owner.owns(p_rid)) {
+
+ CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
+ glDeleteFramebuffers(1,&cls->fbo);
+ glDeleteRenderbuffers(1,&cls->depth);
+ glDeleteTextures(1,&cls->distance);
+ canvas_light_shadow_owner.free(p_rid);
+ memdelete(cls);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+////////////////////////////////////////////
+
+
+void RasterizerStorageGLES3::initialize() {
+
+ config.fbo_format=FBOFormat(int(Globals::get_singleton()->get("rendering/gles3/framebuffer_format")));
+ config.fbo_deferred=int(Globals::get_singleton()->get("rendering/gles3/lighting_technique"));
+
+ config.system_fbo=0;
+
+
+ //// extensions config
+ ///
+
+ {
+ Vector<String> ext= String((const char*)glGetString( GL_EXTENSIONS )).split(" ",false);
+ for(int i=0;i<ext.size();i++) {
+ config.extensions.insert(ext[i]);
+ }
+ }
+
+ config.shrink_textures_x2=false;
+ config.use_fast_texture_filter=int(Globals::get_singleton()->get("rendering/gles3/use_nearest_mipmap_filter"));
+ config.use_anisotropic_filter = config.extensions.has("GL_EXT_texture_filter_anisotropic");
+
+ config.s3tc_supported=config.extensions.has("GL_EXT_texture_compression_dxt1") || config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc");
+ config.etc_supported=config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
+ config.latc_supported=config.extensions.has("GL_EXT_texture_compression_latc");
+ config.bptc_supported=config.extensions.has("GL_ARB_texture_compression_bptc");
+#ifdef GLEW_ENABLED
+ config.etc2_supported=false;
+#else
+ config.etc2_supported=true;
+#endif
+ config.pvrtc_supported=config.extensions.has("GL_IMG_texture_compression_pvrtc");
+ config.srgb_decode_supported=config.extensions.has("GL_EXT_texture_sRGB_decode");
+
+
+
+ config.anisotropic_level=1.0;
+ config.use_anisotropic_filter=config.extensions.has("GL_EXT_texture_filter_anisotropic");
+ if (config.use_anisotropic_filter) {
+ glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,&config.anisotropic_level);
+ config.anisotropic_level=MIN(int(Globals::get_singleton()->get("rendering/gles3/anisotropic_filter_level")),config.anisotropic_level);
+ }
+
+
+ frame.clear_request=false;
+
+ shaders.copy.init();
+
+ {
+ //default textures
+
+
+ glGenTextures(1, &resources.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,resources.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);
+
+ glGenTextures(1, &resources.black_tex);
+ unsigned char blacktexdata[8*8*3];
+ for(int i=0;i<8*8;i++) {
+ blacktexdata[i]=0;
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D,resources.black_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,blacktexdata);
+ glGenerateMipmap(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D,0);
+
+ glGenTextures(1, &resources.normal_tex);
+ unsigned char normaltexdata[8*8*3];
+ for(int i=0;i<8*8*3;i+=3) {
+ normaltexdata[i+0]=128;
+ normaltexdata[i+1]=128;
+ normaltexdata[i+2]=255;
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D,resources.normal_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,normaltexdata);
+ glGenerateMipmap(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D,0);
+
+ }
+
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&config.max_texture_image_units);
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE,&config.max_texture_size);
+
+#ifdef GLEW_ENABLED
+ config.use_rgba_2d_shadows=false;
+#else
+ config.use_rgba_2d_shadows=true;
+#endif
+}
+
+void RasterizerStorageGLES3::finalize() {
+
+ glDeleteTextures(1, &resources.white_tex);
+ glDeleteTextures(1, &resources.black_tex);
+ glDeleteTextures(1, &resources.normal_tex);
+
+}
+
+
+RasterizerStorageGLES3::RasterizerStorageGLES3()
+{
+
+}
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
new file mode 100644
index 0000000000..3b2d7d752c
--- /dev/null
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -0,0 +1,445 @@
+#ifndef RASTERIZERSTORAGEGLES3_H
+#define RASTERIZERSTORAGEGLES3_H
+
+#include "servers/visual/rasterizer.h"
+#include "shader_gles3.h"
+#include "shaders/copy.glsl.h"
+#include "shaders/canvas.glsl.h"
+
+
+
+
+class RasterizerStorageGLES3 : public RasterizerStorage {
+public:
+
+ enum FBOFormat {
+ FBO_FORMAT_16_BITS,
+ FBO_FORMAT_32_BITS,
+ FBO_FORMAT_FLOAT,
+ };
+
+ struct Config {
+
+ FBOFormat fbo_format;
+ bool fbo_deferred;
+ GLuint system_fbo; //on some devices, such as apple, screen is rendered to yet another fbo.
+
+ bool shrink_textures_x2;
+ bool use_fast_texture_filter;
+ bool use_anisotropic_filter;
+
+ bool s3tc_supported;
+ bool latc_supported;
+ bool bptc_supported;
+ bool etc_supported;
+ bool etc2_supported;
+ bool pvrtc_supported;
+
+ bool srgb_decode_supported;
+
+ bool use_rgba_2d_shadows;
+
+ float anisotropic_level;
+
+ int max_texture_image_units;
+ int max_texture_size;
+
+ Set<String> extensions;
+ } config;
+
+ struct Shaders {
+
+ CopyShaderGLES3 copy;
+ } shaders;
+
+ struct Resources {
+
+ GLuint white_tex;
+ GLuint black_tex;
+ GLuint normal_tex;
+
+ } resources;
+
+ struct Info {
+
+ uint64_t texture_mem;
+
+ } info;
+
+
+/////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////DATA///////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////API////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////////////
+
+
+ /* TEXTURE API */
+
+ struct RenderTarget;
+
+ struct Texture : public RID_Data {
+
+ String path;
+ uint32_t flags;
+ int width,height;
+ int alloc_width, alloc_height;
+ Image::Format format;
+
+ GLenum target;
+ GLenum gl_format_cache;
+ GLenum gl_internal_format_cache;
+ GLenum gl_type_cache;
+ int data_size; //original data size, useful for retrieving back
+ bool compressed;
+ bool srgb;
+ int total_data_size;
+ bool ignore_mipmaps;
+
+ int mipmaps;
+
+ bool active;
+ GLuint tex_id;
+
+
+ RenderTarget *render_target;
+
+ Texture() {
+
+ ignore_mipmaps=false;
+ render_target=NULL;
+ flags=width=height=0;
+ tex_id=0;
+ data_size=0;
+ format=Image::FORMAT_L8;
+ active=false;
+ compressed=false;
+ total_data_size=0;
+ target=GL_TEXTURE_2D;
+ mipmaps=0;
+
+ }
+
+ ~Texture() {
+
+ if (tex_id!=0) {
+
+ glDeleteTextures(1,&tex_id);
+ }
+ }
+ };
+
+ mutable RID_Owner<Texture> texture_owner;
+
+ Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags, GLenum& r_gl_format, GLenum& r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb);
+
+ 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 void texture_set_size_override(RID p_texture,int p_width, int p_height);
+
+ virtual void texture_set_path(RID p_texture,const String& p_path);
+ virtual String texture_get_path(RID p_texture) const;
+
+ virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable);
+
+ virtual void texture_debug_usage(List<VS::TextureInfo> *r_info);
+
+
+ /* SHADER API */
+
+ struct Shader : public RID_Data {
+
+
+ };
+
+
+ virtual RID shader_create(VS::ShaderMode p_mode=VS::SHADER_SPATIAL);
+
+ 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_code);
+ virtual String shader_get_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;
+
+ /* MESH API */
+
+ virtual RID mesh_create();
+
+ virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >());
+
+ 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);
+ 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 DVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const;
+ virtual DVector<uint8_t> mesh_surface_get_index_array(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 void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb);
+ virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
+
+ virtual AABB mesh_get_aabb(RID p_mesh) const;
+ virtual void mesh_clear(RID p_mesh);
+
+ /* MULTIMESH API */
+
+
+ virtual RID multimesh_create();
+
+ virtual void multimesh_allocate(RID p_multimesh,int p_instances,VS::MultimeshTransformFormat p_transform_format,VS::MultimeshColorFormat p_color_format,bool p_gen_aabb=true);
+ 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_custom_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_transform_2d(RID p_multimesh,int p_index,const Matrix32& 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_custom_aabb(RID p_multimesh,const AABB& p_aabb) const;
+
+ virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const;
+ virtual Matrix32 multimesh_instance_get_transform_2d(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;
+
+ virtual AABB multimesh_get_aabb(RID p_mesh) 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_vertex_2d(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 void immediate_set_material(RID p_immediate,RID p_material);
+ virtual RID immediate_get_material(RID p_immediate) const;
+
+ /* SKELETON API */
+
+ virtual RID skeleton_create();
+ virtual void skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton=false);
+ 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);
+ virtual void skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Matrix32& p_transform);
+ virtual Matrix32 skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone);
+
+ /* Light API */
+
+ virtual RID light_create(VS::LightType p_type);
+
+ virtual void light_set_color(RID p_light,const Color& p_color);
+ virtual void light_set_param(RID p_light,VS::LightParam p_param,float p_value);
+ virtual void light_set_shadow(RID p_light,bool p_enabled);
+ virtual void light_set_projector(RID p_light,RID p_texture);
+ virtual void light_set_attenuation_texure(RID p_light,RID p_texture);
+ virtual void light_set_negative(RID p_light,bool p_enable);
+ virtual void light_set_cull_mask(RID p_light,uint32_t p_mask);
+ virtual void light_set_shader(RID p_light,RID p_shader);
+
+
+ virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode);
+
+ /* PROBE API */
+
+ virtual RID reflection_probe_create();
+
+ virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity);
+ virtual void reflection_probe_set_clip(RID p_probe, float p_near, float p_far);
+ virtual void reflection_probe_set_min_blend_distance(RID p_probe, float p_distance);
+ virtual void reflection_probe_set_extents(RID p_probe, const Vector3& p_extents);
+ virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset);
+ virtual void reflection_probe_set_enable_parallax_correction(RID p_probe, bool p_enable);
+ virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution);
+ virtual void reflection_probe_set_hide_skybox(RID p_probe, bool p_hide);
+ virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
+
+
+ /* ROOM API */
+
+ virtual RID room_create();
+ virtual void room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform);
+ virtual void room_clear_bounds();
+
+ /* PORTAL API */
+
+ // portals are only (x/y) points, forming a convex shape, which its clockwise
+ // order points outside. (z is 0);
+
+ virtual RID portal_create();
+ virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape);
+ virtual void portal_set_enabled(RID p_portal, bool p_enabled);
+ virtual void portal_set_disable_distance(RID p_portal, float p_distance);
+ virtual void portal_set_disabled_color(RID p_portal, const Color& p_color);
+
+
+ /* RENDER TARGET */
+
+ struct RenderTarget : public RID_Data {
+
+ struct Color {
+ GLuint fbo;
+ GLuint color;
+ } front,back;
+
+ GLuint depth;
+
+ struct Deferred {
+ GLuint fbo;
+ GLuint fbo_color;
+
+ GLuint albedo_ao;
+ GLuint metal_rough_motion;
+ GLuint normal_special;
+ } deferred;
+
+ int width,height;
+
+ bool flags[RENDER_TARGET_FLAG_MAX];
+
+ bool used_in_frame;
+
+ RenderTarget() {
+
+ width=0;
+ height=0;
+ depth=0;
+ front.fbo=0;
+ back.fbo=0;
+ deferred.fbo=0;
+ deferred.fbo_color=0;
+ used_in_frame=false;
+
+ flags[RENDER_TARGET_VFLIP]=false;
+ flags[RENDER_TARGET_TRANSPARENT]=false;
+ flags[RENDER_TARGET_NO_3D]=false;
+ flags[RENDER_TARGET_NO_SAMPLING]=false;
+ }
+ };
+
+ mutable RID_Owner<RenderTarget> render_target_owner;
+
+ void _render_target_clear(RenderTarget *rt);
+ void _render_target_allocate(RenderTarget *rt);
+
+ 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 Image render_target_get_image(RID p_render_target) const;
+ virtual void render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value);
+ virtual bool render_target_renedered_in_frame(RID p_render_target);
+
+ /* CANVAS SHADOW */
+
+ struct CanvasLightShadow : public RID_Data {
+
+ int size;
+ int height;
+ GLuint fbo;
+ GLuint depth;
+ GLuint distance; //for older devices
+ };
+
+ RID_Owner<CanvasLightShadow> canvas_light_shadow_owner;
+
+ virtual RID canvas_light_shadow_buffer_create(int p_width);
+
+ /* LIGHT SHADOW MAPPING */
+
+ struct CanvasOccluder : public RID_Data {
+
+ GLuint vertex_id; // 0 means, unconfigured
+ GLuint index_id; // 0 means, unconfigured
+ DVector<Vector2> lines;
+ int len;
+ };
+
+ RID_Owner<CanvasOccluder> canvas_occluder_owner;
+
+ virtual RID canvas_light_occluder_create();
+ virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines);
+
+ virtual bool free(RID p_rid);
+
+
+ struct Frame {
+
+ RenderTarget *current_rt;
+
+ bool clear_request;
+ Color clear_request_color;
+ int canvas_draw_commands;
+ } frame;
+
+ void initialize();
+ void finalize();
+
+
+
+ RasterizerStorageGLES3();
+};
+
+
+#endif // RASTERIZERSTORAGEGLES3_H
diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp
new file mode 100644
index 0000000000..f8c0234943
--- /dev/null
+++ b/drivers/gles3/shader_gles3.cpp
@@ -0,0 +1,754 @@
+/*************************************************************************/
+/* shader_gles2.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2016 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. */
+/*************************************************************************/
+#include "shader_gles3.h"
+
+
+#include "print_string.h"
+
+//#define DEBUG_OPENGL
+
+#ifdef DEBUG_OPENGL
+
+#define DEBUG_TEST_ERROR(m_section)\
+{\
+ uint32_t err = glGetError();\
+ if (err) {\
+ print_line("OpenGL Error #"+itos(err)+" at: "+m_section);\
+ }\
+}
+#else
+
+#define DEBUG_TEST_ERROR(m_section)
+
+#endif
+
+ShaderGLES3 *ShaderGLES3::active=NULL;
+
+
+
+//#define DEBUG_SHADER
+
+#ifdef DEBUG_SHADER
+
+#define DEBUG_PRINT(m_text) print_line(m_text);
+
+#else
+
+#define DEBUG_PRINT(m_text)
+
+#endif
+
+
+void ShaderGLES3::bind_uniforms() {
+
+ if (!uniforms_dirty) {
+ return;
+ };
+
+ // upload default uniforms
+ const Map<uint32_t,Variant>::Element *E =uniform_defaults.front();
+
+ while(E) {
+ int idx=E->key();
+ int location=version->uniform_location[idx];
+
+ if (location<0) {
+ E=E->next();
+ continue;
+
+ }
+
+ const Variant &v=E->value();
+ _set_uniform_variant(location, v);
+ //print_line("uniform "+itos(location)+" value "+v+ " type "+Variant::get_type_name(v.get_type()));
+ E=E->next();
+ };
+
+ const Map<uint32_t,CameraMatrix>::Element* C = uniform_cameras.front();
+ while (C) {
+
+ int location = version->uniform_location[C->key()];
+ if (location<0) {
+ C=C->next();
+ continue;
+ }
+
+ glUniformMatrix4fv(location,1,false,&(C->get().matrix[0][0]));
+ C = C->next();
+ };
+
+ uniforms_dirty = false;
+};
+
+GLint ShaderGLES3::get_uniform_location(int p_idx) const {
+
+ ERR_FAIL_COND_V(!version, -1);
+
+ return version->uniform_location[p_idx];
+};
+
+bool ShaderGLES3::bind() {
+
+ if (active!=this || !version || new_conditional_version.key!=conditional_version.key) {
+ conditional_version=new_conditional_version;
+ version = get_current_version();
+ } else {
+
+ return false;
+ }
+
+ ERR_FAIL_COND_V(!version,false);
+
+ glUseProgram( version->id );
+
+ DEBUG_TEST_ERROR("Use Program");
+
+ active=this;
+ uniforms_dirty = true;
+/*
+ * why on earth is this code here?
+ for (int i=0;i<texunit_pair_count;i++) {
+
+ glUniform1i(texunit_pairs[i].location, texunit_pairs[i].index);
+ DEBUG_TEST_ERROR("Uniform 1 i");
+ }
+
+*/
+ return true;
+}
+
+void ShaderGLES3::unbind() {
+
+ version=NULL;
+ glUseProgram(0);
+ uniforms_dirty = true;
+ active=NULL;
+}
+
+
+static void _display_error_with_code(const String& p_error,const Vector<const char*>& p_code) {
+
+
+ int line=1;
+ String total_code;
+
+ for(int i=0;i<p_code.size();i++) {
+ total_code+=String(p_code[i]);
+ }
+
+ Vector<String> lines = String(total_code).split("\n");
+
+ for(int j=0;j<lines.size();j++) {
+
+ print_line(itos(line)+": "+lines[j]);
+ line++;
+ }
+
+ ERR_PRINTS(p_error);
+
+}
+
+ShaderGLES3::Version* ShaderGLES3::get_current_version() {
+
+ Version *_v=version_map.getptr(conditional_version);
+
+ if (_v) {
+
+ if (conditional_version.code_version!=0) {
+ CustomCode *cc=custom_code_map.getptr(conditional_version.code_version);
+ ERR_FAIL_COND_V(!cc,_v);
+ if (cc->version==_v->code_version)
+ return _v;
+ } else {
+ return _v;
+ }
+
+ }
+
+
+
+ if (!_v)
+ version_map[conditional_version]=Version();
+
+
+ Version &v = version_map[conditional_version];
+
+ if (!_v) {
+
+ v.uniform_location = memnew_arr( GLint, uniform_count );
+
+ } else {
+ if (v.ok) {
+ //bye bye shaders
+ glDeleteShader( v.vert_id );
+ glDeleteShader( v.frag_id );
+ glDeleteProgram( v.id );
+ v.id=0;
+ }
+
+ }
+
+ v.ok=false;
+ /* SETUP CONDITIONALS */
+
+ Vector<const char*> strings;
+#ifdef GLEW_ENABLED
+ //strings.push_back("#version 330\n");
+ strings.push_back("#version 300 es\n");
+#else
+ strings.push_back("#version 300 es\n"); //ATI requieres this before anything
+#endif
+
+
+ int define_line_ofs=1;
+
+ for(int j=0;j<conditional_count;j++) {
+
+ bool enable=((1<<j)&conditional_version.version);
+ strings.push_back(enable?conditional_defines[j]:"");
+ if (enable)
+ define_line_ofs++;
+
+ if (enable) {
+ DEBUG_PRINT(conditional_defines[j]);
+ }
+
+ }
+
+ //keep them around during the function
+ CharString code_string;
+ CharString code_string2;
+ CharString code_globals;
+
+
+ //print_line("code version? "+itos(conditional_version.code_version));
+
+ CustomCode *cc=NULL;
+
+ if ( conditional_version.code_version>0 ) {
+ //do custom code related stuff
+
+ ERR_FAIL_COND_V( !custom_code_map.has( conditional_version.code_version ), NULL );
+ cc=&custom_code_map[conditional_version.code_version];
+ v.code_version=cc->version;
+ define_line_ofs+=2;
+ }
+
+
+ /* CREATE PROGRAM */
+
+ v.id = glCreateProgram();
+
+ ERR_FAIL_COND_V(v.id==0, NULL);
+
+ /* VERTEX SHADER */
+
+
+ if (cc) {
+ for(int i=0;i<cc->custom_defines.size();i++) {
+
+ strings.push_back(cc->custom_defines[i]);
+ DEBUG_PRINT("CD #"+itos(i)+": "+String(cc->custom_defines[i]));
+ }
+ }
+
+ int strings_base_size=strings.size();
+
+ //vertex precision is high
+ strings.push_back("precision highp float;\n");
+ strings.push_back("precision highp int;\n");
+
+#if 0
+ if (cc) {
+
+ String _code_string = "#define VERTEX_SHADER_CODE "+cc->vertex+"\n";
+ String _code_globals = "#define VERTEX_SHADER_GLOBALS "+cc->vertex_globals+"\n";
+
+ code_string=_code_string.ascii();
+ code_globals=_code_globals.ascii();
+ DEBUG_PRINT( code_globals.get_data() );
+ DEBUG_PRINT( code_string.get_data() );
+ strings.push_back(code_globals);
+ strings.push_back(code_string);
+ }
+#endif
+
+
+ strings.push_back(vertex_code0.get_data());
+ if (cc) {
+ code_globals=cc->vertex_globals.ascii();
+ strings.push_back(code_globals.get_data());
+ }
+ strings.push_back(vertex_code1.get_data());
+
+ if (cc) {
+ code_string=cc->vertex.ascii();
+ strings.push_back(code_string.get_data());
+ }
+
+ strings.push_back(vertex_code2.get_data());
+#ifdef DEBUG_SHADER
+
+ DEBUG_PRINT("\nVertex Code:\n\n"+String(code_string.get_data()));
+ for(int i=0;i<strings.size();i++) {
+
+ //print_line("vert strings "+itos(i)+":"+String(strings[i]));
+ }
+#endif
+
+
+ v.vert_id = glCreateShader(GL_VERTEX_SHADER);
+ glShaderSource(v.vert_id,strings.size(),&strings[0],NULL);
+ glCompileShader(v.vert_id);
+
+ GLint status;
+
+ glGetShaderiv(v.vert_id,GL_COMPILE_STATUS,&status);
+ if (status==GL_FALSE) {
+ // error compiling
+ GLsizei iloglen;
+ glGetShaderiv(v.vert_id,GL_INFO_LOG_LENGTH,&iloglen);
+
+ if (iloglen<0) {
+
+ glDeleteShader(v.vert_id);
+ glDeleteProgram( v.id );
+ v.id=0;
+
+ ERR_PRINT("NO LOG, WTF");
+ } else {
+
+ if (iloglen==0) {
+
+ iloglen = 4096; //buggy driver (Adreno 220+....)
+ }
+
+
+ char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
+ ilogmem[iloglen]=0;
+ glGetShaderInfoLog(v.vert_id, iloglen, &iloglen, ilogmem);
+
+ String err_string=get_shader_name()+": Vertex Program Compilation Failed:\n";
+
+ err_string+=ilogmem;
+ _display_error_with_code(err_string,strings);
+ Memory::free_static(ilogmem);
+ glDeleteShader(v.vert_id);
+ glDeleteProgram( v.id );
+ v.id=0;
+
+ }
+
+ ERR_FAIL_V(NULL);
+ }
+
+ /* FRAGMENT SHADER */
+
+ strings.resize(strings_base_size);
+ //fragment precision is medium
+ strings.push_back("precision mediump float;\n");
+ strings.push_back("precision mediump int;\n");
+
+#if 0
+ if (cc) {
+
+ String _code_string = "#define FRAGMENT_SHADER_CODE "+cc->fragment+"\n";
+ String _code_globals = "#define FRAGMENT_SHADER_GLOBALS "+cc->fragment_globals+"\n";
+
+ code_string=_code_string.ascii();
+ code_globals=_code_globals.ascii();
+ DEBUG_PRINT( code_globals.get_data() );
+ DEBUG_PRINT( code_string.get_data() );
+ strings.push_back(code_globals);
+ strings.push_back(code_string);
+ }
+#endif
+
+
+ strings.push_back(fragment_code0.get_data());
+ if (cc) {
+ code_globals=cc->fragment_globals.ascii();
+ strings.push_back(code_globals.get_data());
+ }
+ strings.push_back(fragment_code1.get_data());
+
+ if (cc) {
+ code_string=cc->fragment.ascii();
+ strings.push_back(code_string.get_data());
+ }
+
+ strings.push_back(fragment_code2.get_data());
+
+ if (cc) {
+ code_string2=cc->light.ascii();
+ strings.push_back(code_string2.get_data());
+ }
+
+ strings.push_back(fragment_code3.get_data());
+
+#ifdef DEBUG_SHADER
+ DEBUG_PRINT("\nFragment Code:\n\n"+String(code_string.get_data()));
+ for(int i=0;i<strings.size();i++) {
+
+ //print_line("frag strings "+itos(i)+":"+String(strings[i]));
+ }
+#endif
+
+ v.frag_id = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(v.frag_id,strings.size(),&strings[0],NULL);
+ glCompileShader(v.frag_id);
+
+ glGetShaderiv(v.frag_id,GL_COMPILE_STATUS,&status);
+ if (status==GL_FALSE) {
+ // error compiling
+ GLsizei iloglen;
+ glGetShaderiv(v.frag_id,GL_INFO_LOG_LENGTH,&iloglen);
+
+ if (iloglen<0) {
+
+ glDeleteShader(v.frag_id);
+ glDeleteShader(v.vert_id);
+ glDeleteProgram( v.id );
+ v.id=0;
+ ERR_PRINT("NO LOG, WTF");
+ } else {
+
+ if (iloglen==0) {
+
+ iloglen = 4096; //buggy driver (Adreno 220+....)
+ }
+
+ char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
+ ilogmem[iloglen]=0;
+ glGetShaderInfoLog(v.frag_id, iloglen, &iloglen, ilogmem);
+
+ String err_string=get_shader_name()+": Fragment Program Compilation Failed:\n";
+
+ err_string+=ilogmem;
+ _display_error_with_code(err_string,strings);
+ ERR_PRINT(err_string.ascii().get_data());
+ Memory::free_static(ilogmem);
+ glDeleteShader(v.frag_id);
+ glDeleteShader(v.vert_id);
+ glDeleteProgram( v.id );
+ v.id=0;
+
+ }
+
+ ERR_FAIL_V( NULL );
+ }
+
+ glAttachShader(v.id,v.frag_id);
+ glAttachShader(v.id,v.vert_id);
+
+ // bind attributes before linking
+ for (int i=0;i<attribute_pair_count;i++) {
+
+ glBindAttribLocation(v.id, attribute_pairs[i].index, attribute_pairs[i].name );
+ }
+
+ glLinkProgram(v.id);
+
+ glGetProgramiv(v.id, GL_LINK_STATUS, &status);
+
+ if (status==GL_FALSE) {
+ // error linking
+ GLsizei iloglen;
+ glGetProgramiv(v.id,GL_INFO_LOG_LENGTH,&iloglen);
+
+ if (iloglen<0) {
+
+ glDeleteShader(v.frag_id);
+ glDeleteShader(v.vert_id);
+ glDeleteProgram( v.id );
+ v.id=0;
+ ERR_FAIL_COND_V(iloglen<=0, NULL);
+ }
+
+ if (iloglen==0) {
+
+ iloglen = 4096; //buggy driver (Adreno 220+....)
+ }
+
+
+ char *ilogmem = (char*)Memory::alloc_static(iloglen+1);
+ ilogmem[iloglen]=0;
+ glGetProgramInfoLog(v.id, iloglen, &iloglen, ilogmem);
+
+ String err_string=get_shader_name()+": Program LINK FAILED:\n";
+
+ err_string+=ilogmem;
+ _display_error_with_code(err_string,strings);
+ ERR_PRINT(err_string.ascii().get_data());
+ Memory::free_static(ilogmem);
+ glDeleteShader(v.frag_id);
+ glDeleteShader(v.vert_id);
+ glDeleteProgram( v.id );
+ v.id=0;
+
+ ERR_FAIL_V(NULL);
+ }
+
+ /* UNIFORMS */
+
+ glUseProgram(v.id);
+
+
+ //print_line("uniforms: ");
+ for(int j=0;j<uniform_count;j++) {
+
+
+ v.uniform_location[j]=glGetUniformLocation(v.id,uniform_names[j]);
+ // print_line("uniform "+String(uniform_names[j])+" location "+itos(v.uniform_location[j]));
+ }
+
+ // set texture uniforms
+ for (int i=0;i<texunit_pair_count;i++) {
+
+ GLint loc = glGetUniformLocation(v.id,texunit_pairs[i].name);
+ if (loc>=0) {
+ if (texunit_pairs[i].index<0) {
+ glUniform1i(loc,max_image_units+texunit_pairs[i].index); //negative, goes down
+ } else {
+
+ glUniform1i(loc,texunit_pairs[i].index);
+ }
+ }
+ }
+
+ // assign uniform block bind points
+ for (int i=0;i<ubo_count;i++) {
+
+ GLint loc = glGetUniformBlockIndex(v.id,ubo_pairs[i].name);
+ if (loc>=0)
+ glUniformBlockBinding(v.id,loc,ubo_pairs[i].index);
+ }
+
+ if ( cc ) {
+
+ v.custom_uniform_locations.resize(cc->custom_uniforms.size());
+ for(int i=0;i<cc->custom_uniforms.size();i++) {
+
+ v.custom_uniform_locations[i]=glGetUniformLocation(v.id,String(cc->custom_uniforms[i]).ascii().get_data());
+ }
+ }
+
+ glUseProgram(0);
+
+
+ v.ok=true;
+
+ return &v;
+}
+
+GLint ShaderGLES3::get_uniform_location(const String& p_name) const {
+
+ ERR_FAIL_COND_V(!version,-1);
+ return glGetUniformLocation(version->id,p_name.ascii().get_data());
+}
+
+
+void ShaderGLES3::setup(const char** p_conditional_defines, int p_conditional_count,const char** p_uniform_names,int p_uniform_count, const AttributePair* p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count,const char*p_vertex_code, const char *p_fragment_code,int p_vertex_code_start,int p_fragment_code_start) {
+
+ ERR_FAIL_COND(version);
+ conditional_version.key=0;
+ new_conditional_version.key=0;
+ uniform_count=p_uniform_count;
+ conditional_count=p_conditional_count;
+ conditional_defines=p_conditional_defines;
+ uniform_names=p_uniform_names;
+ vertex_code=p_vertex_code;
+ fragment_code=p_fragment_code;
+ texunit_pairs=p_texunit_pairs;
+ texunit_pair_count=p_texunit_pair_count;
+ vertex_code_start=p_vertex_code_start;
+ fragment_code_start=p_fragment_code_start;
+ attribute_pairs=p_attribute_pairs;
+ attribute_pair_count=p_attribute_count;
+ ubo_pairs=p_ubo_pairs;
+ ubo_count=p_ubo_pair_count;
+
+ //split vertex and shader code (thank you, retarded shader compiler programmers from you know what company).
+ {
+ String globals_tag="\nVERTEX_SHADER_GLOBALS";
+ String code_tag="\nVERTEX_SHADER_CODE";
+ String code = vertex_code;
+ int cpos = code.find(globals_tag);
+ if (cpos==-1) {
+ vertex_code0=code.ascii();
+ } else {
+ vertex_code0=code.substr(0,cpos).ascii();
+ code = code.substr(cpos+globals_tag.length(),code.length());
+
+ cpos = code.find(code_tag);
+
+ if (cpos==-1) {
+ vertex_code1=code.ascii();
+ } else {
+
+ vertex_code1=code.substr(0,cpos).ascii();
+ vertex_code2=code.substr(cpos+code_tag.length(),code.length()).ascii();
+ }
+ }
+ }
+
+ {
+ String globals_tag="\nFRAGMENT_SHADER_GLOBALS";
+ String code_tag="\nFRAGMENT_SHADER_CODE";
+ String light_code_tag="\nLIGHT_SHADER_CODE";
+ String code = fragment_code;
+ int cpos = code.find(globals_tag);
+ if (cpos==-1) {
+ fragment_code0=code.ascii();
+ } else {
+ fragment_code0=code.substr(0,cpos).ascii();
+ code = code.substr(cpos+globals_tag.length(),code.length());
+
+ cpos = code.find(code_tag);
+
+ if (cpos==-1) {
+ fragment_code1=code.ascii();
+ } else {
+
+ fragment_code1=code.substr(0,cpos).ascii();
+ String code2 = code.substr(cpos+code_tag.length(),code.length());
+
+ cpos = code2.find(light_code_tag);
+ if (cpos==-1) {
+ fragment_code2=code2.ascii();
+ } else {
+
+ fragment_code2=code2.substr(0,cpos).ascii();
+ fragment_code3 = code2.substr(cpos+light_code_tag.length(),code2.length()).ascii();
+ }
+ }
+ }
+ }
+
+}
+
+void ShaderGLES3::finish() {
+
+ const VersionKey *V=NULL;
+ while((V=version_map.next(V))) {
+
+ Version &v=version_map[*V];
+ glDeleteShader( v.vert_id );
+ glDeleteShader( v.frag_id );
+ glDeleteProgram( v.id );
+ memdelete_arr( v.uniform_location );
+
+ }
+
+}
+
+
+void ShaderGLES3::clear_caches() {
+
+ const VersionKey *V=NULL;
+ while((V=version_map.next(V))) {
+
+ Version &v=version_map[*V];
+ glDeleteShader( v.vert_id );
+ glDeleteShader( v.frag_id );
+ glDeleteProgram( v.id );
+ memdelete_arr( v.uniform_location );
+ }
+
+ version_map.clear();
+
+ custom_code_map.clear();
+ version=NULL;
+ last_custom_code=1;
+ uniforms_dirty = true;
+
+}
+
+uint32_t ShaderGLES3::create_custom_shader() {
+
+ custom_code_map[last_custom_code]=CustomCode();
+ custom_code_map[last_custom_code].version=1;
+ return last_custom_code++;
+}
+
+void ShaderGLES3::set_custom_shader_code(uint32_t p_code_id, const String& p_vertex, const String& p_vertex_globals,const String& p_fragment,const String& p_light, const String& p_fragment_globals,const Vector<StringName>& p_uniforms,const Vector<const char*> &p_custom_defines) {
+
+ ERR_FAIL_COND(!custom_code_map.has(p_code_id));
+ CustomCode *cc=&custom_code_map[p_code_id];
+
+ cc->vertex=p_vertex;
+ cc->vertex_globals=p_vertex_globals;
+ cc->fragment=p_fragment;
+ cc->fragment_globals=p_fragment_globals;
+ cc->light=p_light;
+ cc->custom_uniforms=p_uniforms;
+ cc->custom_defines=p_custom_defines;
+ cc->version++;
+}
+
+void ShaderGLES3::set_custom_shader(uint32_t p_code_id) {
+
+ new_conditional_version.code_version=p_code_id;
+}
+
+void ShaderGLES3::free_custom_shader(uint32_t p_code_id) {
+
+ /* if (! custom_code_map.has( p_code_id )) {
+ print_line("no code id "+itos(p_code_id));
+ } else {
+ print_line("freed code id "+itos(p_code_id));
+
+ }*/
+
+ ERR_FAIL_COND(! custom_code_map.has( p_code_id ));
+ if (conditional_version.code_version==p_code_id)
+ conditional_version.code_version=0; //bye
+
+ custom_code_map.erase(p_code_id);
+
+}
+
+
+
+ShaderGLES3::ShaderGLES3() {
+ version=NULL;
+ last_custom_code=1;
+ uniforms_dirty = true;
+
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&max_image_units);
+}
+
+
+ShaderGLES3::~ShaderGLES3() {
+
+ finish();
+}
+
+
+
diff --git a/drivers/gles3/shader_gles3.h b/drivers/gles3/shader_gles3.h
new file mode 100644
index 0000000000..7aaf65d450
--- /dev/null
+++ b/drivers/gles3/shader_gles3.h
@@ -0,0 +1,377 @@
+/*************************************************************************/
+/* shader_gles2.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2016 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 SHADER_GLES3_H
+#define SHADER_GLES3_H
+
+
+#include "platform_config.h"
+#ifndef GLES3_INCLUDE_H
+#include <GLES3/gl3.h>
+#else
+#include GLES3_INCLUDE_H
+#endif
+
+#include "hash_map.h"
+#include "map.h"
+#include "variant.h"
+#include "camera_matrix.h"
+
+/**
+ @author Juan Linietsky <reduzio@gmail.com>
+*/
+
+
+class ShaderGLES3 {
+protected:
+
+ struct Enum {
+
+ uint64_t mask;
+ uint64_t shift;
+ const char *defines[16];
+ };
+
+ struct EnumValue {
+
+ uint64_t set_mask;
+ uint64_t clear_mask;
+ };
+
+ struct AttributePair {
+
+ const char *name;
+ int index;
+ };
+
+ struct UniformPair {
+ const char* name;
+ Variant::Type type_hint;
+ };
+
+ struct TexUnitPair {
+
+ const char *name;
+ int index;
+ };
+
+ struct UBOPair {
+
+ const char *name;
+ int index;
+ };
+
+ bool uniforms_dirty;
+private:
+
+ //@TODO Optimize to a fixed set of shader pools and use a LRU
+ int uniform_count;
+ int texunit_pair_count;
+ int conditional_count;
+ int ubo_count;
+ int vertex_code_start;
+ int fragment_code_start;
+ int attribute_pair_count;
+
+ struct CustomCode {
+
+ String vertex;
+ String vertex_globals;
+ String fragment;
+ String fragment_globals;
+ String light;
+ uint32_t version;
+ Vector<StringName> custom_uniforms;
+ Vector<const char*> custom_defines;
+
+ };
+
+
+ struct Version {
+
+ GLuint id;
+ GLuint vert_id;
+ GLuint frag_id;
+ GLint *uniform_location;
+ Vector<GLint> custom_uniform_locations;
+ uint32_t code_version;
+ bool ok;
+ Version() { code_version=0; ok=false; uniform_location=NULL; }
+ };
+
+ Version *version;
+
+ union VersionKey {
+
+ struct {
+ uint32_t version;
+ uint32_t code_version;
+ };
+ uint64_t key;
+ bool operator==(const VersionKey& p_key) const { return key==p_key.key; }
+ bool operator<(const VersionKey& p_key) const { return key<p_key.key; }
+
+ };
+
+ struct VersionKeyHash {
+
+ static _FORCE_INLINE_ uint32_t hash( const VersionKey& p_key) { return HashMapHahserDefault::hash(p_key.key); };
+ };
+
+ //this should use a way more cachefriendly version..
+ HashMap<VersionKey,Version,VersionKeyHash> version_map;
+
+ HashMap<uint32_t,CustomCode> custom_code_map;
+ uint32_t last_custom_code;
+
+
+ VersionKey conditional_version;
+ VersionKey new_conditional_version;
+
+ virtual String get_shader_name() const=0;
+
+ const char** conditional_defines;
+ const char** uniform_names;
+ const AttributePair *attribute_pairs;
+ const TexUnitPair *texunit_pairs;
+ const UBOPair *ubo_pairs;
+ const char* vertex_code;
+ const char* fragment_code;
+ CharString fragment_code0;
+ CharString fragment_code1;
+ CharString fragment_code2;
+ CharString fragment_code3;
+
+ CharString vertex_code0;
+ CharString vertex_code1;
+ CharString vertex_code2;
+
+ Version * get_current_version();
+
+ static ShaderGLES3 *active;
+
+ int max_image_units;
+
+ _FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform,const Variant& p_value) {
+
+ if (p_uniform<0)
+ return; // do none
+ switch(p_value.get_type()) {
+
+ case Variant::BOOL:
+ case Variant::INT: {
+
+ int val=p_value;
+ glUniform1i( p_uniform, val );
+ } break;
+ case Variant::REAL: {
+
+ real_t val=p_value;
+ glUniform1f( p_uniform, val );
+ } break;
+ case Variant::COLOR: {
+
+ Color val=p_value;
+ glUniform4f( p_uniform, val.r, val.g,val.b,val.a );
+ } break;
+ case Variant::VECTOR2: {
+
+ Vector2 val=p_value;
+ glUniform2f( p_uniform, val.x,val.y );
+ } break;
+ case Variant::VECTOR3: {
+
+ Vector3 val=p_value;
+ glUniform3f( p_uniform, val.x,val.y,val.z );
+ } break;
+ case Variant::PLANE: {
+
+ Plane val=p_value;
+ glUniform4f( p_uniform, val.normal.x,val.normal.y,val.normal.z,val.d );
+ } break;
+ case Variant::QUAT: {
+
+ Quat val=p_value;
+ glUniform4f( p_uniform, val.x,val.y,val.z,val.w );
+ } break;
+
+ case Variant::MATRIX32: {
+
+ Matrix32 tr=p_value;
+ 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
+ };
+
+ glUniformMatrix4fv(p_uniform,1,false,matrix);
+
+ } break;
+ case Variant::MATRIX3:
+ case Variant::TRANSFORM: {
+
+ Transform tr=p_value;
+ 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
+ };
+
+
+ glUniformMatrix4fv(p_uniform,1,false,matrix);
+ } break;
+ default: { ERR_FAIL(); } // do nothing
+
+ }
+ }
+
+ Map<uint32_t,Variant> uniform_defaults;
+ Map<uint32_t,CameraMatrix> uniform_cameras;
+
+
+protected:
+
+ _FORCE_INLINE_ int _get_uniform(int p_which) const;
+ _FORCE_INLINE_ void _set_conditional(int p_which, bool p_value);
+
+ void setup(const char** p_conditional_defines, int p_conditional_count,const char** p_uniform_names,int p_uniform_count, const AttributePair* p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count,const char*p_vertex_code, const char *p_fragment_code,int p_vertex_code_start,int p_fragment_code_start);
+
+ ShaderGLES3();
+public:
+
+ enum {
+ CUSTOM_SHADER_DISABLED=0
+ };
+
+ GLint get_uniform_location(const String& p_name) const;
+ GLint get_uniform_location(int p_uniform) const;
+
+ static _FORCE_INLINE_ ShaderGLES3 *get_active() { return active; };
+ bool bind();
+ void unbind();
+ void bind_uniforms();
+
+
+ inline GLuint get_program() const { return version?version->id:0; }
+
+ void clear_caches();
+
+ uint32_t create_custom_shader();
+ void set_custom_shader_code(uint32_t p_id,const String& p_vertex, const String& p_vertex_globals,const String& p_fragment,const String& p_p_light,const String& p_fragment_globals,const Vector<StringName>& p_uniforms,const Vector<const char*> &p_custom_defines);
+ void set_custom_shader(uint32_t p_id);
+ void free_custom_shader(uint32_t p_id);
+
+ void set_uniform_default(int p_idx, const Variant& p_value) {
+
+ if (p_value.get_type()==Variant::NIL) {
+
+ uniform_defaults.erase(p_idx);
+ } else {
+
+ uniform_defaults[p_idx]=p_value;
+ }
+ uniforms_dirty = true;
+ }
+
+ uint32_t get_version() const { return new_conditional_version.version; }
+
+ void set_uniform_camera(int p_idx, const CameraMatrix& p_mat) {
+
+ uniform_cameras[p_idx] = p_mat;
+ uniforms_dirty = true;
+ };
+
+ _FORCE_INLINE_ void set_custom_uniform(int p_idx, const Variant& p_value) {
+
+ ERR_FAIL_COND(!version);
+ ERR_FAIL_INDEX(p_idx,version->custom_uniform_locations.size());
+ _set_uniform_variant( version->custom_uniform_locations[p_idx], p_value );
+ }
+
+ _FORCE_INLINE_ GLint get_custom_uniform_location(int p_idx) {
+
+ ERR_FAIL_COND_V(!version,-1);
+ ERR_FAIL_INDEX_V(p_idx,version->custom_uniform_locations.size(),-1);
+ return version->custom_uniform_locations[p_idx];
+ }
+
+ virtual void init()=0;
+ void finish();
+
+ virtual ~ShaderGLES3();
+
+};
+
+
+// called a lot, made inline
+
+
+int ShaderGLES3::_get_uniform(int p_which) const {
+
+ ERR_FAIL_INDEX_V( p_which, uniform_count,-1 );
+ ERR_FAIL_COND_V( !version, -1 );
+ return version->uniform_location[p_which];
+}
+
+void ShaderGLES3::_set_conditional(int p_which, bool p_value) {
+
+ ERR_FAIL_INDEX(p_which,conditional_count);
+ if (p_value)
+ new_conditional_version.version|=(1<<p_which);
+ else
+ new_conditional_version.version&=~(1<<p_which);
+}
+
+#endif
+
diff --git a/drivers/gles3/shaders/SCsub b/drivers/gles3/shaders/SCsub
new file mode 100644
index 0000000000..628fa14e4e
--- /dev/null
+++ b/drivers/gles3/shaders/SCsub
@@ -0,0 +1,7 @@
+Import('env')
+
+if env['BUILDERS'].has_key('GLES3_GLSL'):
+ env.GLES3_GLSL('copy.glsl');
+ env.GLES3_GLSL('canvas.glsl');
+ env.GLES3_GLSL('canvas_shadow.glsl');
+
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl
new file mode 100644
index 0000000000..eed2239ec9
--- /dev/null
+++ b/drivers/gles3/shaders/canvas.glsl
@@ -0,0 +1,428 @@
+[vertex]
+
+
+layout(location=0) in highp vec3 vertex;
+layout(location=3) in vec4 color_attrib;
+
+#ifdef USE_TEXTURE_RECT
+
+layout(location=1) in highp vec4 dst_rect;
+layout(location=2) in highp vec4 src_rect;
+
+#else
+
+layout(location=4) in highp vec2 uv_attrib;
+
+//skeletn
+#endif
+
+
+layout(std140) uniform CanvasItemData { //ubo:0
+
+ highp mat4 projection_matrix;
+};
+
+uniform highp mat4 modelview_matrix;
+uniform highp mat4 extra_matrix;
+
+
+out mediump vec2 uv_interp;
+out mediump vec4 color_interp;
+
+#if defined(USE_TIME)
+uniform float time;
+#endif
+
+#ifdef USE_LIGHTING
+
+layout(std140) uniform LightData { //ubo:1
+
+ //light matrices
+ highp mat4 light_matrix;
+ highp mat4 light_local_matrix;
+ highp mat4 shadow_matrix;
+ highp vec4 light_color;
+ highp vec4 light_shadow_color;
+ highp vec2 light_pos;
+ highp float shadowpixel_size;
+ highp float shadow_gradient;
+ highp float light_height;
+ highp float light_outside_alpha;
+ highp float shadow_distance_mult;
+};
+
+out vec4 light_uv_interp;
+
+#if defined(NORMAL_USED)
+out vec4 local_rot;
+#endif
+
+#ifdef USE_SHADOWS
+out highp vec2 pos;
+#endif
+
+#endif
+
+
+VERTEX_SHADER_GLOBALS
+
+void main() {
+
+ color_interp = color_attrib;
+
+
+#ifdef USE_TEXTURE_RECT
+
+
+ uv_interp = src_rect.xy + abs(src_rect.zw) * vertex.xy;
+ highp vec4 outvec = vec4(dst_rect.xy + dst_rect.zw * mix(vertex.xy,vec2(1.0,1.0)-vertex.xy,lessThan(src_rect.zw,vec2(0.0,0.0))),0.0,1.0);
+
+#else
+ uv_interp = uv_attrib;
+ highp vec4 outvec = vec4(vertex, 1.0);
+#endif
+
+
+{
+ 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);
+#endif
+
+
+ gl_Position = projection_matrix * outvec;
+
+#ifdef USE_LIGHTING
+
+ light_uv_interp.xy = (light_matrix * outvec).xy;
+ light_uv_interp.zw =(light_local_matrix * outvec).xy;
+#ifdef USE_SHADOWS
+ pos=outvec.xy;
+#endif
+
+#if defined(NORMAL_USED)
+ local_rot.xy=normalize( (modelview_matrix * ( extra_matrix * vec4(1.0,0.0,0.0,0.0) )).xy );
+ local_rot.zw=normalize( (modelview_matrix * ( extra_matrix * vec4(0.0,1.0,0.0,0.0) )).xy );
+#ifdef USE_TEXTURE_RECT
+ local_rot.xy*=sign(src_rect.z);
+ local_rot.zw*=sign(src_rect.w);
+#endif
+
+#endif
+
+#endif
+
+}
+
+[fragment]
+
+
+
+uniform mediump sampler2D color_texture; // texunit:0
+
+in mediump vec2 uv_interp;
+in mediump vec4 color_interp;
+
+
+#if defined(ENABLE_TEXSCREEN)
+
+uniform sampler2D texscreen_tex; // texunit:-3
+
+#endif
+
+#if defined(USE_TIME)
+uniform float time;
+#endif
+
+#ifdef USE_LIGHTING
+
+layout(std140) uniform LightData {
+
+ highp mat4 light_matrix;
+ highp mat4 light_local_matrix;
+ highp mat4 shadow_matrix;
+ highp vec4 light_color;
+ highp vec4 light_shadow_color;
+ highp vec2 light_pos;
+ highp float shadowpixel_size;
+ highp float shadow_gradient;
+ highp float light_height;
+ highp float light_outside_alpha;
+ highp float shadow_distance_mult;
+};
+
+uniform lowp sampler2D light_texture; // texunit:-1
+in vec4 light_uv_interp;
+
+
+#if defined(NORMAL_USED)
+in vec4 local_rot;
+#endif
+
+#ifdef USE_SHADOWS
+
+uniform highp sampler2D shadow_texture; // texunit:-2
+in highp vec2 pos;
+
+#endif
+
+#endif
+
+uniform mediump vec4 final_modulate;
+
+FRAGMENT_SHADER_GLOBALS
+
+
+layout(location=0) out mediump vec4 frag_color;
+
+void main() {
+
+ vec4 color = color_interp;
+#if defined(NORMAL_USED)
+ vec3 normal = vec3(0.0,0.0,1.0);
+#endif
+
+#ifdef USE_DISTANCE_FIELD
+ const float smoothing = 1.0/32.0;
+ float distance = texture(color_texture, uv_interp).a;
+ color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a;
+#else
+ color *= texture( color_texture, uv_interp );
+
+#endif
+
+
+#if defined(ENABLE_SCREEN_UV)
+ vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult;
+#endif
+
+
+{
+#if defined(USE_NORMALMAP)
+ vec3 normal_map=vec3(0.0,0.0,1.0);
+ float normal_depth=1.0;
+#endif
+
+FRAGMENT_SHADER_CODE
+
+#if defined(USE_NORMALMAP)
+ normal = mix(vec3(0.0,0.0,1.0), normal_map * vec3(2.0,-2.0,1.0) - vec3( 1.0, -1.0, 0.0 ), normal_depth );
+#endif
+
+}
+#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
+
+
+ color*=final_modulate;
+
+
+
+
+#ifdef USE_LIGHTING
+
+ vec2 light_vec = light_uv_interp.zw;; //for shadow and normal mapping
+
+#if defined(NORMAL_USED)
+ normal.xy = mat2(local_rot.xy,local_rot.zw) * normal.xy;
+#endif
+
+ float att=1.0;
+
+ vec2 light_uv = light_uv_interp.xy;
+ vec4 light = texture(light_texture,light_uv) * light_color;
+#if defined(USE_OUTPUT_SHADOW_COLOR)
+ vec4 shadow_color=vec4(0.0,0.0,0.0,0.0);
+#endif
+
+ if (any(lessThan(light_uv_interp.xy,vec2(0.0,0.0))) || any(greaterThanEqual(light_uv_interp.xy,vec2(1.0,1.0)))) {
+ color.a*=light_outside_alpha; //invisible
+
+ } else {
+
+#if defined(USE_LIGHT_SHADER_CODE)
+//light is written by the light shader
+ {
+ vec4 light_out=light*color;
+LIGHT_SHADER_CODE
+ color=light_out;
+ }
+
+#else
+
+#if defined(NORMAL_USED)
+ vec3 light_normal = normalize(vec3(light_vec,-light_height));
+ light*=max(dot(-light_normal,normal),0.0);
+#endif
+
+ color*=light;
+/*
+#ifdef USE_NORMAL
+ color.xy=local_rot.xy;//normal.xy;
+ color.zw=vec2(0.0,1.0);
+#endif
+*/
+
+//light shader code
+#endif
+
+
+#ifdef USE_SHADOWS
+
+ float angle_to_light = -atan(light_vec.x,light_vec.y);
+ float PI = 3.14159265358979323846264;
+ /*int i = int(mod(floor((angle_to_light+7.0*PI/6.0)/(4.0*PI/6.0))+1.0, 3.0)); // +1 pq os indices estao em ordem 2,0,1 nos arrays
+ float ang*/
+
+ float su,sz;
+
+ float abs_angle = abs(angle_to_light);
+ vec2 point;
+ float sh;
+ if (abs_angle<45.0*PI/180.0) {
+ point = light_vec;
+ sh=0.0+(1.0/8.0);
+ } else if (abs_angle>135.0*PI/180.0) {
+ point = -light_vec;
+ sh = 0.5+(1.0/8.0);
+ } else if (angle_to_light>0.0) {
+
+ point = vec2(light_vec.y,-light_vec.x);
+ sh = 0.25+(1.0/8.0);
+ } else {
+
+ point = vec2(-light_vec.y,light_vec.x);
+ sh = 0.75+(1.0/8.0);
+
+ }
+
+
+ highp vec4 s = shadow_matrix * vec4(point,0.0,1.0);
+ s.xyz/=s.w;
+ su=s.x*0.5+0.5;
+ sz=s.z*0.5+0.5;
+ //sz=lightlength(light_vec);
+
+ highp float shadow_attenuation=0.0;
+
+#ifdef USE_RGBA_SHADOWS
+
+#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) )
+
+#else
+
+#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).r)
+
+#endif
+
+
+
+#ifdef SHADOW_USE_GRADIENT
+
+#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture,vec2(m_ofs,sh)); shadow_attenuation+=1.0-smoothstep(sd,sd+shadow_gradient,sz); }
+
+#else
+
+#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture,vec2(m_ofs,sh)); shadow_attenuation+=step(sz,sd); }
+
+#endif
+
+
+#ifdef SHADOW_FILTER_NEAREST
+
+ SHADOW_TEST(su+shadowpixel_size);
+
+#endif
+
+
+#ifdef SHADOW_FILTER_PCF3
+
+ SHADOW_TEST(su+shadowpixel_size);
+ SHADOW_TEST(su);
+ SHADOW_TEST(su-shadowpixel_size);
+ shadow_attenuation/=3.0;
+
+#endif
+
+
+#ifdef SHADOW_FILTER_PCF5
+
+ SHADOW_TEST(su+shadowpixel_size*3.0);
+ SHADOW_TEST(su+shadowpixel_size*2.0);
+ SHADOW_TEST(su+shadowpixel_size);
+ SHADOW_TEST(su);
+ SHADOW_TEST(su-shadowpixel_size);
+ SHADOW_TEST(su-shadowpixel_size*2.0);
+ SHADOW_TEST(su-shadowpixel_size*3.0);
+ shadow_attenuation/=5.0;
+
+#endif
+
+
+#ifdef SHADOW_FILTER_PCF9
+
+ SHADOW_TEST(su+shadowpixel_size*4.0);
+ SHADOW_TEST(su+shadowpixel_size*3.0);
+ SHADOW_TEST(su+shadowpixel_size*2.0);
+ SHADOW_TEST(su+shadowpixel_size);
+ SHADOW_TEST(su);
+ SHADOW_TEST(su-shadowpixel_size);
+ SHADOW_TEST(su-shadowpixel_size*2.0);
+ SHADOW_TEST(su-shadowpixel_size*3.0);
+ SHADOW_TEST(su-shadowpixel_size*4.0);
+ shadow_attenuation/=9.0;
+
+#endif
+
+#ifdef SHADOW_FILTER_PCF13
+
+ SHADOW_TEST(su+shadowpixel_size*6.0);
+ SHADOW_TEST(su+shadowpixel_size*5.0);
+ SHADOW_TEST(su+shadowpixel_size*4.0);
+ SHADOW_TEST(su+shadowpixel_size*3.0);
+ SHADOW_TEST(su+shadowpixel_size*2.0);
+ SHADOW_TEST(su+shadowpixel_size);
+ SHADOW_TEST(su);
+ SHADOW_TEST(su-shadowpixel_size);
+ SHADOW_TEST(su-shadowpixel_size*2.0);
+ SHADOW_TEST(su-shadowpixel_size*3.0);
+ SHADOW_TEST(su-shadowpixel_size*4.0);
+ SHADOW_TEST(su-shadowpixel_size*5.0);
+ SHADOW_TEST(su-shadowpixel_size*6.0);
+ shadow_attenuation/=13.0;
+
+#endif
+
+
+#if defined(USE_OUTPUT_SHADOW_COLOR)
+ color=mix(shadow_color,color,shadow_attenuation);
+#else
+ //color*=shadow_attenuation;
+ color=mix(light_shadow_color,color,shadow_attenuation);
+#endif
+//use shadows
+#endif
+ }
+
+//use lighting
+#endif
+// color.rgb*=color.a;
+ frag_color = color;
+
+}
+
diff --git a/drivers/gles3/shaders/canvas_shadow.glsl b/drivers/gles3/shaders/canvas_shadow.glsl
new file mode 100644
index 0000000000..c757990de0
--- /dev/null
+++ b/drivers/gles3/shaders/canvas_shadow.glsl
@@ -0,0 +1,49 @@
+[vertex]
+
+
+
+uniform highp mat4 projection_matrix;
+uniform highp mat4 light_matrix;
+uniform highp mat4 world_matrix;
+uniform highp float distance_norm;
+
+layout(location=0) in highp vec3 vertex;
+
+out highp vec4 position_interp;
+
+void main() {
+
+ gl_Position = projection_matrix * (light_matrix * (world_matrix * vec4(vertex,1.0)));
+ position_interp=gl_Position;
+}
+
+[fragment]
+
+in highp vec4 position_interp;
+
+#ifdef USE_RGBA_SHADOWS
+
+layout(location=0) out lowp vec4 distance_buf;
+
+#else
+
+layout(location=0) out highp float distance_buf;
+
+#endif
+
+void main() {
+
+ highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0;//bias;
+
+#ifdef USE_RGBA_SHADOWS
+
+ highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
+ comp -= comp.xxyz * vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
+ distance_buf=comp;
+#else
+
+ distance_buf=depth;
+
+#endif
+}
+
diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl
new file mode 100644
index 0000000000..aba280186a
--- /dev/null
+++ b/drivers/gles3/shaders/copy.glsl
@@ -0,0 +1,52 @@
+[vertex]
+
+
+layout(location=0) in highp vec4 vertex_attrib;
+#ifdef USE_CUBEMAP
+layout(location=4) in vec3 cube_in;
+#else
+layout(location=4) in vec2 uv_in; // attrib:4
+#endif
+layout(location=5) in vec2 uv2_in; // attrib:5
+
+#ifdef USE_CUBEMAP
+out vec3 cube_interp;
+#else
+out vec2 uv_interp;
+#endif
+
+out vec2 uv2_interp;
+
+void main() {
+
+#ifdef USE_CUBEMAP
+ cube_interp = cube_in;
+#else
+ uv_interp = uv_in;
+#endif
+ uv2_interp = uv2_in;
+ gl_Position = vertex_attrib;
+}
+
+[fragment]
+
+
+#ifdef USE_CUBEMAP
+in vec3 cube_interp;
+uniform samplerCube source_cube;
+#else
+in vec2 uv_interp;
+uniform sampler2D source;
+#endif
+
+in vec2 uv2_interp;
+
+layout(location = 0) vec4 frag_color; //color:0
+
+void main() {
+
+ //vec4 color = color_interp;
+
+ frag_color = color;
+}
+
diff --git a/drivers/jpegd/image_loader_jpegd.cpp b/drivers/jpegd/image_loader_jpegd.cpp
index 496334605d..2ea9748034 100644
--- a/drivers/jpegd/image_loader_jpegd.cpp
+++ b/drivers/jpegd/image_loader_jpegd.cpp
@@ -83,9 +83,9 @@ Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_
Image::Format fmt;
if (comps==1)
- fmt=Image::FORMAT_GRAYSCALE;
+ fmt=Image::FORMAT_L8;
else
- fmt=Image::FORMAT_RGBA;
+ fmt=Image::FORMAT_RGBA8;
dw = DVector<uint8_t>::Write();
p_image->create(image_width,image_height,0,fmt,data);
diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp
index 4967b0f9df..cd4f2d6529 100644
--- a/drivers/png/image_loader_png.cpp
+++ b/drivers/png/image_loader_png.cpp
@@ -113,25 +113,36 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
printf("Color type:%i\n", color);
*/
+ bool update_info=false;
+
if (depth<8) { //only bit dept 8 per channel is handled
png_set_packing(png);
+ update_info=true;
+
};
+ if (png_get_color_type(png,info)==PNG_COLOR_TYPE_PALETTE) {
+ png_set_palette_to_rgb(png);
+ update_info=true;
+ }
+
if (depth > 8) {
png_set_strip_16(png);
- png_read_update_info(png, info);
+ update_info=true;
}
if (png_get_valid(png,info,PNG_INFO_tRNS)) {
// png_set_expand_gray_1_2_4_to_8(png);
png_set_tRNS_to_alpha(png);
+ update_info=true;
+ }
+
+ if (update_info) {
png_read_update_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
}
- int palette_colors = 0;
- int palette_components = 0;
int components = 0;
Image::Format fmt;
@@ -140,38 +151,24 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
case PNG_COLOR_TYPE_GRAY: {
- fmt=Image::FORMAT_GRAYSCALE;
+ fmt=Image::FORMAT_L8;
components=1;
} break;
case PNG_COLOR_TYPE_GRAY_ALPHA: {
- fmt=Image::FORMAT_GRAYSCALE_ALPHA;
+ fmt=Image::FORMAT_LA8;
components=2;
} break;
case PNG_COLOR_TYPE_RGB: {
- fmt=Image::FORMAT_RGB;
+ fmt=Image::FORMAT_RGB8;
components=3;
} break;
case PNG_COLOR_TYPE_RGB_ALPHA: {
- fmt=Image::FORMAT_RGBA;
+ fmt=Image::FORMAT_RGBA8;
components=4;
- } break;
- case PNG_COLOR_TYPE_PALETTE: {
-
- int ntrans = 0;
- png_get_tRNS(png, info, NULL, &ntrans, NULL);
- //printf("transparent colors %i\n", ntrans);
-
- fmt = ntrans > 0 ? Image::FORMAT_INDEXED_ALPHA : Image::FORMAT_INDEXED;
- palette_components = ntrans > 0 ? 4 : 3;
- components = 1;
-
- png_colorp colors;
- png_get_PLTE(png, info, &colors, &palette_colors);
-
- } break;
+ } break;
default: {
ERR_PRINT("INVALID PNG TYPE");
@@ -185,7 +182,7 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
DVector<uint8_t> dstbuff;
- dstbuff.resize( rowsize * height + palette_components * 256 ); // alloc the entire palette? - yes always
+ dstbuff.resize( rowsize * height );
DVector<uint8_t>::Write dstbuff_write = dstbuff.write();
@@ -199,38 +196,6 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image)
png_read_image(png, (png_bytep*)row_p);
- if (palette_colors) {
-
- uint8_t *r_pal = &data[components*width*height]; // end of the array
- png_colorp colors;
- int num;
- png_get_PLTE(png, info, &colors, &num);
-
- int ofs = 0;
- for (int i=0; i < palette_colors; i++) {
-
- r_pal[ofs + 0] = colors[i].red;
- r_pal[ofs + 1] = colors[i].green;
- r_pal[ofs + 2] = colors[i].blue;
- if (palette_components == 4) {
- r_pal[ofs + 3] = 255;
- };
- ofs += palette_components;
- };
-
- if (fmt == Image::FORMAT_INDEXED_ALPHA) {
- png_color_16p alphas;
- png_bytep alpha_idx;
- int count;
- png_get_tRNS(png, info, &alpha_idx, &count, &alphas);
- for (int i=0; i<count; i++) {
-
- //printf("%i: loading alpha fron transparent color %i, values %i, %i, %i, %i, %i\n", i, (int)alpha_idx[i], (int)alphas[i].index, (int)alphas[i].red, (int)alphas[i].green, (int)alphas[i].blue, (int)alphas[i].gray);
- //r_pal[alpha_idx[i]] = alphas[i].gray >> 8;
- r_pal[i*4+3] = alpha_idx[i];
- };
- };
- };
memdelete_arr( row_p );
@@ -324,11 +289,11 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) {
Image img = p_image;
- if (img.get_format() > Image::FORMAT_INDEXED_ALPHA)
+ if (img.is_compressed())
img.decompress();
- ERR_FAIL_COND_V(img.get_format() > Image::FORMAT_INDEXED_ALPHA, DVector<uint8_t>());
+ ERR_FAIL_COND_V(img.is_compressed(), DVector<uint8_t>());
png_structp png_ptr;
png_infop info_ptr;
@@ -365,22 +330,22 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) {
switch(img.get_format()) {
- case Image::FORMAT_GRAYSCALE: {
+ case Image::FORMAT_L8: {
pngf=PNG_COLOR_TYPE_GRAY;
cs=1;
} break;
- case Image::FORMAT_GRAYSCALE_ALPHA: {
+ case Image::FORMAT_LA8: {
pngf=PNG_COLOR_TYPE_GRAY_ALPHA;
cs=2;
} break;
- case Image::FORMAT_RGB: {
+ case Image::FORMAT_RGB8: {
pngf=PNG_COLOR_TYPE_RGB;
cs=3;
} break;
- case Image::FORMAT_RGBA: {
+ case Image::FORMAT_RGBA8: {
pngf=PNG_COLOR_TYPE_RGB_ALPHA;
cs=4;
@@ -389,12 +354,12 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) {
if (img.detect_alpha()) {
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
pngf=PNG_COLOR_TYPE_RGB_ALPHA;
cs=4;
} else {
- img.convert(Image::FORMAT_RGB);
+ img.convert(Image::FORMAT_RGB8);
pngf=PNG_COLOR_TYPE_RGB;
cs=3;
}
diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp
index 2578fe9eb6..c641f6ee85 100644
--- a/drivers/png/resource_saver_png.cpp
+++ b/drivers/png/resource_saver_png.cpp
@@ -96,10 +96,10 @@ Error ResourceSaverPNG::save(const String &p_path,const RES& p_resource,uint32_t
Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) {
- if (p_img.get_format() > Image::FORMAT_INDEXED_ALPHA)
+ if (p_img.is_compressed())
p_img.decompress();
- ERR_FAIL_COND_V(p_img.get_format() > Image::FORMAT_INDEXED_ALPHA, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(p_img.is_compressed(), ERR_INVALID_PARAMETER);
png_structp png_ptr;
png_infop info_ptr;
@@ -138,22 +138,22 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) {
switch(p_img.get_format()) {
- case Image::FORMAT_GRAYSCALE: {
+ case Image::FORMAT_L8: {
pngf=PNG_COLOR_TYPE_GRAY;
cs=1;
} break;
- case Image::FORMAT_GRAYSCALE_ALPHA: {
+ case Image::FORMAT_LA8: {
pngf=PNG_COLOR_TYPE_GRAY_ALPHA;
cs=2;
} break;
- case Image::FORMAT_RGB: {
+ case Image::FORMAT_RGB8: {
pngf=PNG_COLOR_TYPE_RGB;
cs=3;
} break;
- case Image::FORMAT_RGBA: {
+ case Image::FORMAT_RGBA8: {
pngf=PNG_COLOR_TYPE_RGB_ALPHA;
cs=4;
@@ -162,12 +162,12 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) {
if (p_img.detect_alpha()) {
- p_img.convert(Image::FORMAT_RGBA);
+ p_img.convert(Image::FORMAT_RGBA8);
pngf=PNG_COLOR_TYPE_RGB_ALPHA;
cs=4;
} else {
- p_img.convert(Image::FORMAT_RGB);
+ p_img.convert(Image::FORMAT_RGB8);
pngf=PNG_COLOR_TYPE_RGB;
cs=3;
}
diff --git a/drivers/pvr/texture_loader_pvr.cpp b/drivers/pvr/texture_loader_pvr.cpp
index 3ab3240512..b2063292e9 100644
--- a/drivers/pvr/texture_loader_pvr.cpp
+++ b/drivers/pvr/texture_loader_pvr.cpp
@@ -116,33 +116,33 @@ RES ResourceFormatPVR::load(const String &p_path,const String& p_original_path,E
switch(flags&0xFF) {
case 0x18:
- case 0xC: format=(flags&PVR_HAS_ALPHA)?Image::FORMAT_PVRTC2_ALPHA:Image::FORMAT_PVRTC2; break;
+ case 0xC: format=(flags&PVR_HAS_ALPHA)?Image::FORMAT_PVRTC2A:Image::FORMAT_PVRTC2; break;
case 0x19:
- case 0xD: format=(flags&PVR_HAS_ALPHA)?Image::FORMAT_PVRTC4_ALPHA:Image::FORMAT_PVRTC4; break;
+ case 0xD: format=(flags&PVR_HAS_ALPHA)?Image::FORMAT_PVRTC4A:Image::FORMAT_PVRTC4; break;
case 0x16:
- format=Image::FORMAT_GRAYSCALE; break;
+ format=Image::FORMAT_L8; break;
case 0x17:
- format=Image::FORMAT_GRAYSCALE_ALPHA; break;
+ format=Image::FORMAT_LA8; break;
case 0x20:
case 0x80:
case 0x81:
- format=Image::FORMAT_BC1; break;
+ format=Image::FORMAT_DXT1; break;
case 0x21:
case 0x22:
case 0x82:
case 0x83:
- format=Image::FORMAT_BC2; break;
+ format=Image::FORMAT_DXT3; break;
case 0x23:
case 0x24:
case 0x84:
case 0x85:
- format=Image::FORMAT_BC3; break;
+ format=Image::FORMAT_DXT5; break;
case 0x4:
case 0x15:
- format=Image::FORMAT_RGB; break;
+ format=Image::FORMAT_RGB8; break;
case 0x5:
case 0x12:
- format=Image::FORMAT_RGBA; break;
+ format=Image::FORMAT_RGBA8; break;
case 0x36:
format=Image::FORMAT_ETC; break;
default:
@@ -198,24 +198,24 @@ static void _compress_pvrtc4(Image * p_img) {
bool make_mipmaps=false;
if (img.get_width()%8 || img.get_height()%8) {
- make_mipmaps=img.get_mipmaps()>0;
+ make_mipmaps=img.has_mipmaps();
img.resize(img.get_width()+(8-(img.get_width()%8)),img.get_height()+(8-(img.get_height()%8)));
}
- img.convert(Image::FORMAT_RGBA);
- if (img.get_mipmaps()==0 && make_mipmaps)
+ img.convert(Image::FORMAT_RGBA8);
+ if (!img.has_mipmaps() && make_mipmaps)
img.generate_mipmaps();
bool use_alpha=img.detect_alpha();
Image new_img;
- new_img.create(img.get_width(),img.get_height(),true,use_alpha?Image::FORMAT_PVRTC4_ALPHA:Image::FORMAT_PVRTC4);
+ new_img.create(img.get_width(),img.get_height(),true,use_alpha?Image::FORMAT_PVRTC4A:Image::FORMAT_PVRTC4);
DVector<uint8_t> data=new_img.get_data();
{
DVector<uint8_t>::Write wr=data.write();
DVector<uint8_t>::Read r=img.get_data().read();
- for(int i=0;i<=new_img.get_mipmaps();i++) {
+ for(int i=0;i<=new_img.get_mipmap_count();i++) {
int ofs,size,w,h;
img.get_mipmap_offset_size_and_dimensions(i,ofs,size,w,h);
@@ -234,7 +234,7 @@ static void _compress_pvrtc4(Image * p_img) {
}
- *p_img = Image(new_img.get_width(),new_img.get_height(),new_img.get_mipmaps(),new_img.get_format(),data);
+ *p_img = Image(new_img.get_width(),new_img.get_height(),new_img.has_mipmaps(),new_img.get_format(),data);
}
@@ -673,9 +673,9 @@ static void _pvrtc_decompress(Image* p_img) {
// decompress_pvrtc((PVRTCBlock*)p_comp_img,p_2bit,p_width,p_height,1,p_dst);
// }
- ERR_FAIL_COND( p_img->get_format()!=Image::FORMAT_PVRTC2 && p_img->get_format()!=Image::FORMAT_PVRTC2_ALPHA && p_img->get_format()!=Image::FORMAT_PVRTC4 && p_img->get_format()!=Image::FORMAT_PVRTC4_ALPHA);
+ ERR_FAIL_COND( p_img->get_format()!=Image::FORMAT_PVRTC2 && p_img->get_format()!=Image::FORMAT_PVRTC2A && p_img->get_format()!=Image::FORMAT_PVRTC4 && p_img->get_format()!=Image::FORMAT_PVRTC4A);
- bool _2bit = (p_img->get_format()==Image::FORMAT_PVRTC2 || p_img->get_format()==Image::FORMAT_PVRTC2_ALPHA );
+ bool _2bit = (p_img->get_format()==Image::FORMAT_PVRTC2 || p_img->get_format()==Image::FORMAT_PVRTC2A );
DVector<uint8_t> data = p_img->get_data();
DVector<uint8_t>::Read r = data.read();
@@ -694,8 +694,8 @@ static void _pvrtc_decompress(Image* p_img) {
w=DVector<uint8_t>::Write();
r=DVector<uint8_t>::Read();
- bool make_mipmaps=p_img->get_mipmaps()>0;
- Image newimg(p_img->get_width(),p_img->get_height(),0,Image::FORMAT_RGBA,newdata);
+ bool make_mipmaps=p_img->has_mipmaps();
+ Image newimg(p_img->get_width(),p_img->get_height(),false,Image::FORMAT_RGBA8,newdata);
if (make_mipmaps)
newimg.generate_mipmaps();
*p_img=newimg;
diff --git a/drivers/squish/image_compress_squish.cpp b/drivers/squish/image_compress_squish.cpp
index 95de83d5a5..2cab6e6059 100644
--- a/drivers/squish/image_compress_squish.cpp
+++ b/drivers/squish/image_compress_squish.cpp
@@ -35,7 +35,7 @@ void image_compress_squish(Image *p_image) {
int w=p_image->get_width();
int h=p_image->get_height();
- if (p_image->get_mipmaps() == 0) {
+ if (!p_image->has_mipmaps() ) {
ERR_FAIL_COND( !w || w % 4 != 0);
ERR_FAIL_COND( !h || h % 4 != 0);
} else {
@@ -43,26 +43,26 @@ void image_compress_squish(Image *p_image) {
ERR_FAIL_COND( !h || h !=nearest_power_of_2(h) );
};
- if (p_image->get_format()>=Image::FORMAT_BC1)
+ if (p_image->get_format()>=Image::FORMAT_DXT1)
return; //do not compress, already compressed
int shift=0;
int squish_comp=squish::kColourRangeFit;
Image::Format target_format;
- if (p_image->get_format()==Image::FORMAT_GRAYSCALE_ALPHA) {
+ if (p_image->get_format()==Image::FORMAT_LA8) {
//compressed normalmap
- target_format = Image::FORMAT_BC3; squish_comp|=squish::kDxt5;;
+ target_format = Image::FORMAT_DXT5; squish_comp|=squish::kDxt5;;
} else if (p_image->detect_alpha()!=Image::ALPHA_NONE) {
- target_format = Image::FORMAT_BC2; squish_comp|=squish::kDxt3;;
+ target_format = Image::FORMAT_DXT3; squish_comp|=squish::kDxt3;;
} else {
- target_format = Image::FORMAT_BC1; shift=1; squish_comp|=squish::kDxt1;;
+ target_format = Image::FORMAT_DXT1; shift=1; squish_comp|=squish::kDxt1;;
}
- p_image->convert(Image::FORMAT_RGBA); //always expects rgba
+ p_image->convert(Image::FORMAT_RGBA8); //always expects rgba
- int mm_count = p_image->get_mipmaps();
+ int mm_count = p_image->get_mipmap_count();
DVector<uint8_t> data;
int target_size = Image::get_image_data_size(w,h,target_format,mm_count);
@@ -85,7 +85,7 @@ void image_compress_squish(Image *p_image) {
rb = DVector<uint8_t>::Read();
wb = DVector<uint8_t>::Write();
- p_image->create(p_image->get_width(),p_image->get_height(),p_image->get_mipmaps(),target_format,data);
+ p_image->create(p_image->get_width(),p_image->get_height(),p_image->has_mipmaps(),target_format,data);
}
diff --git a/drivers/theora/video_stream_theora.cpp b/drivers/theora/video_stream_theora.cpp
index 1f3832ec16..7f7449de94 100644
--- a/drivers/theora/video_stream_theora.cpp
+++ b/drivers/theora/video_stream_theora.cpp
@@ -105,7 +105,7 @@ void VideoStreamPlaybackTheora::video_write(void){
dst[p++] = 255;
};
}
- format = Image::FORMAT_RGBA;
+ format = Image::FORMAT_RGBA8;
}
// */
@@ -132,10 +132,10 @@ void VideoStreamPlaybackTheora::video_write(void){
yuv420_2_rgb8888((uint8_t*)dst, (uint8_t*)yuv[0].data, (uint8_t*)yuv[2].data, (uint8_t*)yuv[1].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x<<2, 0);
};
- format = Image::FORMAT_RGBA;
+ format = Image::FORMAT_RGBA8;
}
- Image img(size.x,size.y,0,Image::FORMAT_RGBA,frame_data); //zero copy image creation
+ Image img(size.x,size.y,0,Image::FORMAT_RGBA8,frame_data); //zero copy image creation
texture->set_data(img); //zero copy send to visual server
@@ -204,7 +204,7 @@ void VideoStreamPlaybackTheora::video_write(void){
}
}
- format = Image::FORMAT_RGBA;
+ format = Image::FORMAT_RGBA8;
} else {
@@ -472,7 +472,7 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
size.x = w;
size.y = h;
- texture->create(w,h,Image::FORMAT_RGBA,Texture::FLAG_FILTER|Texture::FLAG_VIDEO_SURFACE);
+ texture->create(w,h,Image::FORMAT_RGBA8,Texture::FLAG_FILTER|Texture::FLAG_VIDEO_SURFACE);
}else{
/* tear down the partial theora setup */
diff --git a/drivers/webp/image_loader_webp.cpp b/drivers/webp/image_loader_webp.cpp
index 68bb857293..d0b9285153 100644
--- a/drivers/webp/image_loader_webp.cpp
+++ b/drivers/webp/image_loader_webp.cpp
@@ -41,9 +41,9 @@ static DVector<uint8_t> _webp_lossy_pack(const Image& p_image,float p_quality) {
Image img=p_image;
if (img.detect_alpha())
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
else
- img.convert(Image::FORMAT_RGB);
+ img.convert(Image::FORMAT_RGB8);
Size2 s(img.get_width(),img.get_height());
DVector<uint8_t> data = img.get_data();
@@ -51,7 +51,7 @@ static DVector<uint8_t> _webp_lossy_pack(const Image& p_image,float p_quality) {
uint8_t *dst_buff=NULL;
size_t dst_size=0;
- if (img.get_format()==Image::FORMAT_RGB) {
+ if (img.get_format()==Image::FORMAT_RGB8) {
dst_size = WebPEncodeRGB(r.ptr(),s.width,s.height,3*s.width,CLAMP(p_quality*100.0,0,100.0),&dst_buff);
} else {
@@ -108,7 +108,7 @@ static Image _webp_lossy_unpack(const DVector<uint8_t>& p_buffer) {
dst_w = DVector<uint8_t>::Write();
- return Image(features.width,features.height,0,features.has_alpha?Image::FORMAT_RGBA:Image::FORMAT_RGB,dst_image);
+ return Image(features.width,features.height,0,features.has_alpha?Image::FORMAT_RGBA8:Image::FORMAT_RGB8,dst_image);
}
@@ -160,7 +160,7 @@ Error ImageLoaderWEBP::load_image(Image *p_image,FileAccess *f) {
src_r = DVector<uint8_t>::Read();
dst_w = DVector<uint8_t>::Write();
- *p_image = Image(features.width,features.height,0,features.has_alpha?Image::FORMAT_RGBA:Image::FORMAT_RGB,dst_image);
+ *p_image = Image(features.width,features.height,0,features.has_alpha?Image::FORMAT_RGBA8:Image::FORMAT_RGB8,dst_image);
return OK;
diff --git a/methods.py b/methods.py
index c4951c69bd..7ad42a559a 100755
--- a/methods.py
+++ b/methods.py
@@ -123,7 +123,7 @@ def build_glsl_header( filename ):
uline=line[:line.lower().find("//")]
uline = uline[uline.find("uniform")+len("uniform"):];
uline = uline.replace(";","");
- uline = uline.replace("{","");
+ uline = uline.replace("{","").strip();
lines = uline.split(",")
for x in lines:
@@ -767,9 +767,31 @@ def include_file_in_legacygl_header( filename, header_data, depth ):
header_data.texunits+=[(x,texunit)]
header_data.texunit_names+=[x]
+ elif (line.find("uniform")!=-1 and line.lower().find("ubo:")!=-1):
+ #uniform buffer object
+ ubostr = line[line.find(":")+1:].strip()
+ ubo = str(int(ubostr ))
+ uline=line[:line.lower().find("//")]
+ uline = uline[uline.find("uniform")+len("uniform"):];
+ uline = uline.replace("highp","");
+ uline = uline.replace(";","");
+ uline = uline.replace("{","").strip();
+ lines = uline.split(",")
+ for x in lines:
+
+ x = x.strip()
+ x = x[ x.rfind(" ")+1: ]
+ if (x.find("[")!=-1):
+ #unfiorm array
+ x = x[ :x.find("[") ]
+
+ if (not x in header_data.ubo_names):
+ header_data.ubos+=[(x,ubo)]
+ header_data.ubo_names+=[x]
- elif (line.find("uniform")!=-1):
+
+ elif (line.find("uniform")!=-1 and line.find("{")==-1 and line.find(";")!=-1):
uline = line.replace("uniform","");
uline = uline.replace(";","");
lines = uline.split(",")
@@ -785,7 +807,7 @@ def include_file_in_legacygl_header( filename, header_data, depth ):
header_data.uniforms+=[x]
- if ((line.strip().find("in ")==0 or line.strip().find("attribute ")==0) and line.find("attrib:")!=-1):
+ if ( line.strip().find("attribute ")==0 and line.find("attrib:")!=-1):
uline = line.replace("in ","");
uline = uline.replace("attribute ","");
uline = uline.replace("highp ","");
@@ -1036,6 +1058,7 @@ def build_legacygl_header( filename, include, class_suffix, output_attribs ):
else:
fd.write("\t\tstatic const char **_uniform_strings=NULL;\n")
+
if output_attribs:
if (len(header_data.attributes)):
@@ -1055,6 +1078,14 @@ def build_legacygl_header( filename, include, class_suffix, output_attribs ):
else:
fd.write("\t\tstatic TexUnitPair *_texunit_pairs=NULL;\n")
+ if (len(header_data.ubos)):
+ fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
+ for x in header_data.ubos:
+ fd.write("\t\t\t{\""+x[0]+"\","+x[1]+"},\n");
+ fd.write("\t\t};\n\n");
+ else:
+ fd.write("\t\tstatic UBOPair *_ubo_pairs=NULL;\n")
+
fd.write("\t\tstatic const char _vertex_code[]={\n")
for x in header_data.vertex_lines:
for i in range(len(x)):
@@ -1077,9 +1108,9 @@ def build_legacygl_header( filename, include, class_suffix, output_attribs ):
fd.write("\t\tstatic const int _fragment_code_start="+str(header_data.fragment_offset)+";\n")
if output_attribs:
- fd.write("\t\tsetup(_conditional_strings,"+str(len(header_data.conditionals))+",_uniform_strings,"+str(len(header_data.uniforms))+",_attribute_pairs,"+str(len(header_data.attributes))+", _texunit_pairs,"+str(len(header_data.texunits))+",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
+ fd.write("\t\tsetup(_conditional_strings,"+str(len(header_data.conditionals))+",_uniform_strings,"+str(len(header_data.uniforms))+",_attribute_pairs,"+str(len(header_data.attributes))+", _texunit_pairs,"+str(len(header_data.texunits))+",_ubo_pairs,"+str(len(header_data.ubos))+",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
else:
- fd.write("\t\tsetup(_conditional_strings,"+str(len(header_data.conditionals))+",_uniform_strings,"+str(len(header_data.uniforms))+",_texunit_pairs,"+str(len(header_data.texunits))+",_enums,"+str(len(header_data.enums))+",_enum_values,"+str(enum_value_count)+",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
+ fd.write("\t\tsetup(_conditional_strings,"+str(len(header_data.conditionals))+",_uniform_strings,"+str(len(header_data.uniforms))+",_texunit_pairs,"+str(len(header_data.texunits))+",_enums,"+str(len(header_data.enums))+",_enum_values,"+str(enum_value_count)+",_ubo_pairs,"+str(len(header_data.ubos))+",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
fd.write("\t};\n\n")
@@ -1111,6 +1142,11 @@ def build_gles2_headers( target, source, env ):
for x in source:
build_legacygl_header(str(x), include="drivers/gles2/shader_gles2.h", class_suffix = "GLES2", output_attribs = True)
+
+def build_gles3_headers( target, source, env ):
+
+ for x in source:
+ build_legacygl_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix = "GLES3", output_attribs = True)
def update_version():
diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py
index ea7e83378a..9826689218 100644
--- a/modules/gridmap/config.py
+++ b/modules/gridmap/config.py
@@ -1,7 +1,7 @@
def can_build(platform):
- return True
+ return False
def configure(env):
diff --git a/platform/iphone/rasterizer_iphone.cpp b/platform/iphone/rasterizer_iphone.cpp
index 99e83343d0..5478569a42 100644
--- a/platform/iphone/rasterizer_iphone.cpp
+++ b/platform/iphone/rasterizer_iphone.cpp
@@ -134,21 +134,21 @@ static Image _get_gl_image_and_format(const Image& p_image, Image::Format p_form
switch(p_format) {
- case Image::FORMAT_GRAYSCALE: {
+ case Image::FORMAT_L8: {
r_gl_components=1;
r_gl_format=GL_LUMINANCE;
} break;
case Image::FORMAT_INTENSITY: {
- image.convert(Image::FORMAT_RGBA);
+ image.convert(Image::FORMAT_RGBA8);
r_gl_components=4;
r_gl_format=GL_RGBA;
r_has_alpha_cache=true;
} break;
- case Image::FORMAT_GRAYSCALE_ALPHA: {
+ case Image::FORMAT_LA8: {
- image.convert(Image::FORMAT_RGBA);
+ image.convert(Image::FORMAT_RGBA8);
r_gl_components=4;
r_gl_format=GL_RGBA;
r_has_alpha_cache=true;
@@ -156,7 +156,7 @@ static Image _get_gl_image_and_format(const Image& p_image, Image::Format p_form
case Image::FORMAT_INDEXED: {
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
r_gl_components=3;
r_gl_format=GL_RGB;
@@ -164,17 +164,17 @@ static Image _get_gl_image_and_format(const Image& p_image, Image::Format p_form
case Image::FORMAT_INDEXED_ALPHA: {
- image.convert(Image::FORMAT_RGBA);
+ image.convert(Image::FORMAT_RGBA8);
r_gl_components=4;
r_gl_format=GL_RGB;
r_has_alpha_cache=true;
} break;
- case Image::FORMAT_RGB: {
+ case Image::FORMAT_RGB8: {
r_gl_components=3; r_gl_format=GL_RGB;
} break;
- case Image::FORMAT_RGBA: {
+ case Image::FORMAT_RGBA8: {
r_gl_components=4;
r_gl_format=GL_RGBA;
@@ -344,7 +344,7 @@ Image::Format RasterizerIPhone::texture_get_format(RID p_texture) const {
Texture * texture = texture_owner.get(p_texture);
- ERR_FAIL_COND_V(!texture,Image::FORMAT_GRAYSCALE);
+ ERR_FAIL_COND_V(!texture,Image::FORMAT_L8);
return texture->format;
}
diff --git a/platform/iphone/rasterizer_iphone.h b/platform/iphone/rasterizer_iphone.h
index add656b190..fcbb339ab3 100644
--- a/platform/iphone/rasterizer_iphone.h
+++ b/platform/iphone/rasterizer_iphone.h
@@ -74,7 +74,7 @@ class RasterizerIPhone : public Rasterizer {
flags=width=height=0;
tex_id=0;
- format=Image::FORMAT_GRAYSCALE;
+ format=Image::FORMAT_L8;
gl_components_cache=0;
format_has_alpha=false;
has_alpha=false;
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 30f4c58150..c55bf0eadb 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -207,7 +207,7 @@ void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& ic
while(size>=16) {
Image copy = p_icon;
- copy.convert(Image::FORMAT_RGBA);
+ copy.convert(Image::FORMAT_RGBA8);
copy.resize(size,size);
it->create_from_image(copy);
String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/icon.png";
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index cc893cc7a0..5a5ddccd60 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -1313,7 +1313,7 @@ void OS_OSX::set_window_title(const String& p_title) {
void OS_OSX::set_icon(const Image& p_icon) {
Image img=p_icon;
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
NSBitmapImageRep *imgrep= [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
pixelsWide: p_icon.get_width()
pixelsHigh: p_icon.get_height()
diff --git a/platform/osx/platform_config.h b/platform/osx/platform_config.h
index 86505206ae..dc04e9b4f1 100644
--- a/platform/osx/platform_config.h
+++ b/platform/osx/platform_config.h
@@ -27,5 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <alloca.h>
+
#define GLES2_INCLUDE_H "gl_context/GL/glew.h"
+#define GLES3_INCLUDE_H "gl_context/GL/glew.h"
#define PTHREAD_RENAME_SELF
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 5404980ff3..cb00fdaac8 100644
--- a/platform/server/os_server.cpp
+++ b/platform/server/os_server.cpp
@@ -26,8 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "servers/visual/visual_server_raster.h"
-#include "servers/visual/rasterizer_dummy.h"
+//#include "servers/visual/visual_server_raster.h"
+//#include "servers/visual/rasterizer_dummy.h"
#include "os_server.h"
#include <stdio.h>
#include <stdlib.h>
@@ -57,9 +57,9 @@ void OS_Server::initialize(const VideoMode& p_desired,int p_video_driver,int p_a
current_videomode=p_desired;
main_loop=NULL;
- rasterizer = memnew( RasterizerDummy );
+ //rasterizer = memnew( RasterizerDummy );
- visual_server = memnew( VisualServerRaster(rasterizer) );
+ //visual_server = memnew( VisualServerRaster(rasterizer) );
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton();
@@ -114,7 +114,7 @@ void OS_Server::finalize() {
visual_server->finish();
memdelete(visual_server);
- memdelete(rasterizer);
+ //memdelete(rasterizer);
physics_server->finish();
memdelete(physics_server);
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index 2081d5f2f4..ed5111d831 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -51,7 +51,7 @@
class OS_Server : public OS_Unix {
- Rasterizer *rasterizer;
+// Rasterizer *rasterizer;
VisualServer *visual_server;
VideoMode current_videomode;
List<String> args;
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 35d90a8308..1af7cb2a49 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -2081,8 +2081,8 @@ void OS_Windows::set_icon(const Image& p_icon) {
Image icon=p_icon;
- if (icon.get_format()!=Image::FORMAT_RGBA)
- icon.convert(Image::FORMAT_RGBA);
+ if (icon.get_format()!=Image::FORMAT_RGBA8)
+ icon.convert(Image::FORMAT_RGBA8);
int w = icon.get_width();
int h = icon.get_height();
diff --git a/platform/windows/platform_config.h b/platform/windows/platform_config.h
index 9e20750816..296a778ac8 100644
--- a/platform/windows/platform_config.h
+++ b/platform/windows/platform_config.h
@@ -31,5 +31,6 @@
//#include <alloca.h>
//#endif
#define GLES2_INCLUDE_H "gl_context/GL/glew.h"
+#define GLES3_INCLUDE_H "gl_context/GL/glew.h"
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp
index cd325dfc99..ccf7a801ef 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -140,6 +140,7 @@ Error ContextGL_X11::initialize() {
static int context_attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+ GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index ba232f6d4e..6e3a8af676 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -198,9 +198,9 @@ def configure(env):
import methods
- env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
- env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
- env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
+ #env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
+ #env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
+ #env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
#env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } )
if (env["use_static_cpp"]=="yes"):
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 5f1ab5b4aa..d2d6e88c4b 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "servers/visual/visual_server_raster.h"
-#include "drivers/gles2/rasterizer_gles2.h"
+#include "drivers/gles3/rasterizer_gles3.h"
#include "os_x11.h"
#include "key_mapping_x11.h"
#include <stdio.h>
@@ -74,7 +74,7 @@ int OS_X11::get_video_driver_count() const {
}
const char * OS_X11::get_video_driver_name(int p_driver) const {
- return "GLES2";
+ return "GLES3";
}
OS::VideoMode OS_X11::get_default_video_mode() const {
@@ -203,19 +203,22 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+
context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) );
context_gl->initialize();
- rasterizer = memnew( RasterizerGLES2 );
+ RasterizerGLES3::register_config();
-#endif
- visual_server = memnew( VisualServerRaster(rasterizer) );
+ RasterizerGLES3::make_current();
+#endif
+ visual_server = memnew( VisualServerRaster );
+#if 0
if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) {
visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD));
}
-
+#endif
// borderless fullscreen window mode
if (current_videomode.fullscreen) {
// needed for lxde/openbox, possibly others
@@ -487,7 +490,7 @@ void OS_X11::finalize() {
visual_server->finish();
memdelete(visual_server);
- memdelete(rasterizer);
+ //memdelete(rasterizer);
physics_server->finish();
memdelete(physics_server);
@@ -1878,7 +1881,7 @@ void OS_X11::set_icon(const Image& p_icon) {
if (!p_icon.empty()) {
Image img=p_icon;
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
int w = img.get_width();
int h = img.get_height();
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index b27f71406a..b351309d80 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -34,7 +34,7 @@
#include "drivers/unix/os_unix.h"
#include "context_gl_x11.h"
#include "servers/visual_server.h"
-#include "servers/visual/visual_server_wrap_mt.h"
+//#include "servers/visual/visual_server_wrap_mt.h"
#include "servers/visual/rasterizer.h"
#include "servers/physics_server.h"
#include "servers/audio/audio_server_sw.h"
@@ -99,7 +99,7 @@ class OS_X11 : public OS_Unix {
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
ContextGL_X11 *context_gl;
#endif
- Rasterizer *rasterizer;
+ //Rasterizer *rasterizer;
VisualServer *visual_server;
VideoMode current_videomode;
List<String> args;
diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h
index 3b47b2c92d..1873e712ec 100644
--- a/platform/x11/platform_config.h
+++ b/platform/x11/platform_config.h
@@ -35,5 +35,6 @@
#endif
#define GLES2_INCLUDE_H "gl_context/GL/glew.h"
+#define GLES3_INCLUDE_H "gl_context/GL/glew.h"
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index ed1d606ba8..07ee1ff753 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -42,9 +42,6 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value)
if (p_name==SceneStringNames::get_singleton()->shader_shader) {
set_shader(p_value);
return true;
- } else if (p_name==SceneStringNames::get_singleton()->shading_mode) {
- set_shading_mode(ShadingMode(p_value.operator int()));
- return true;
} else {
if (shader.is_valid()) {
@@ -58,7 +55,7 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value)
}
}
if (pr) {
- VisualServer::get_singleton()->canvas_item_material_set_shader_param(material,pr,p_value);
+ VisualServer::get_singleton()->material_set_param(material,pr,p_value);
return true;
}
}
@@ -74,18 +71,14 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
r_ret=get_shader();
return true;
- } else if (p_name==SceneStringNames::get_singleton()->shading_mode) {
-
- r_ret=shading_mode;
- return true;
} else {
if (shader.is_valid()) {
StringName pr = shader->remap_param(p_name);
if (pr) {
- r_ret=VisualServer::get_singleton()->canvas_item_material_get_shader_param(material,pr);
+ r_ret=VisualServer::get_singleton()->material_get_param(material,pr);
return true;
}
}
@@ -100,7 +93,6 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
void CanvasItemMaterial::_get_property_list( List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemShader,CanvasItemShaderGraph" ) );
- p_list->push_back( PropertyInfo( Variant::INT, "shader/shading_mode",PROPERTY_HINT_ENUM,"Normal,Unshaded,Light Only") );
if (!shader.is_null()) {
@@ -119,7 +111,7 @@ void CanvasItemMaterial::set_shader(const Ref<Shader>& p_shader) {
if (shader.is_valid())
rid=shader->get_rid();
- VS::get_singleton()->canvas_item_material_set_shader(material,rid);
+ VS::get_singleton()->material_set_shader(material,rid);
_change_notify(); //properties for shader exposed
emit_changed();
}
@@ -131,12 +123,12 @@ Ref<Shader> CanvasItemMaterial::get_shader() const{
void CanvasItemMaterial::set_shader_param(const StringName& p_param,const Variant& p_value){
- VS::get_singleton()->canvas_item_material_set_shader_param(material,p_param,p_value);
+ VS::get_singleton()->material_set_param(material,p_param,p_value);
}
Variant CanvasItemMaterial::get_shader_param(const StringName& p_param) const{
- return VS::get_singleton()->canvas_item_material_get_shader_param(material,p_param);
+ return VS::get_singleton()->material_get_param(material,p_param);
}
RID CanvasItemMaterial::get_rid() const {
@@ -144,16 +136,6 @@ RID CanvasItemMaterial::get_rid() const {
return material;
}
-void CanvasItemMaterial::set_shading_mode(ShadingMode p_mode) {
-
- shading_mode=p_mode;
- VS::get_singleton()->canvas_item_material_set_shading_mode(material,VS::CanvasItemShadingMode(p_mode));
-}
-
-CanvasItemMaterial::ShadingMode CanvasItemMaterial::get_shading_mode() const {
- return shading_mode;
-}
-
void CanvasItemMaterial::_bind_methods() {
@@ -161,12 +143,7 @@ void CanvasItemMaterial::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_shader:Shader"),&CanvasItemMaterial::get_shader);
ObjectTypeDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param);
ObjectTypeDB::bind_method(_MD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param);
- ObjectTypeDB::bind_method(_MD("set_shading_mode","mode"),&CanvasItemMaterial::set_shading_mode);
- ObjectTypeDB::bind_method(_MD("get_shading_mode"),&CanvasItemMaterial::get_shading_mode);
- BIND_CONSTANT( SHADING_NORMAL );
- BIND_CONSTANT( SHADING_UNSHADED );
- BIND_CONSTANT( SHADING_ONLY_LIGHT );
}
@@ -189,13 +166,13 @@ void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p
CanvasItemMaterial::CanvasItemMaterial() {
- material=VS::get_singleton()->canvas_item_material_create();
- shading_mode=SHADING_NORMAL;
+
+
}
CanvasItemMaterial::~CanvasItemMaterial(){
- VS::get_singleton()->free(material);
+
}
@@ -374,6 +351,8 @@ Matrix32 CanvasItem::get_global_transform_with_canvas() const {
return last_valid->canvas_layer->get_transform() * xform;
else if (is_inside_tree())
return get_viewport()->get_canvas_transform() * xform;
+
+ return xform;
}
Matrix32 CanvasItem::get_global_transform() const {
@@ -394,42 +373,17 @@ Matrix32 CanvasItem::get_global_transform() const {
}
-
-void CanvasItem::_queue_sort_children() {
-
- if (pending_children_sort)
- return;
-
- pending_children_sort=true;
- MessageQueue::get_singleton()->push_call(this,"_sort_children");
-}
-
-void CanvasItem::_sort_children() {
-
- pending_children_sort=false;
+void CanvasItem::_toplevel_raise_self() {
if (!is_inside_tree())
return;
- for(int i=0;i<get_child_count();i++) {
-
- Node *n = get_child(i);
- CanvasItem *ci=n->cast_to<CanvasItem>();
-
- if (ci) {
- if (ci->toplevel || ci->group!="")
- continue;
- VisualServer::get_singleton()->canvas_item_raise(n->cast_to<CanvasItem>()->canvas_item);
- }
- }
-}
-
-void CanvasItem::_raise_self() {
+ if (canvas_layer)
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,canvas_layer->get_sort_index());
+ else
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_viewport()->gui_get_canvas_sort_index());
- if (!is_inside_tree())
- return;
- VisualServer::get_singleton()->canvas_item_raise(canvas_item);
}
@@ -461,14 +415,19 @@ void CanvasItem::_enter_canvas() {
group = "root_canvas"+itos(canvas.get_id());
add_to_group(group);
- get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_raise_self");
+ if (canvas_layer)
+ canvas_layer->reset_sort_index();
+ else
+ get_viewport()->gui_reset_canvas_sort_index();
+
+ get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_toplevel_raise_self");
} else {
CanvasItem *parent = get_parent_item();
canvas_layer=parent->canvas_layer;
VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent->get_canvas_item());
- parent->_queue_sort_children();
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_index());
}
pending_update=false;
@@ -495,7 +454,6 @@ void CanvasItem::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
first_draw=true;
- pending_children_sort=false;
if (get_parent()) {
CanvasItem *ci = get_parent()->cast_to<CanvasItem>();
if (ci)
@@ -508,13 +466,15 @@ void CanvasItem::_notification(int p_what) {
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
+ if (!is_inside_tree())
+ break;
if (group!="") {
- get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_raise_self");
+ get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_toplevel_raise_self");
} else {
CanvasItem *p = get_parent_item();
ERR_FAIL_COND(!p);
- p->_queue_sort_children();
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_index());
}
@@ -569,15 +529,15 @@ void CanvasItem::update() {
MessageQueue::get_singleton()->push_call(this,"_update_callback");
}
-void CanvasItem::set_opacity(float p_opacity) {
+void CanvasItem::set_modulate(const Color& p_modulate) {
- opacity=p_opacity;
- VisualServer::get_singleton()->canvas_item_set_opacity(canvas_item,opacity);
+ modulate=p_modulate;
+ VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item,modulate);
}
-float CanvasItem::get_opacity() const {
+Color CanvasItem::get_modulate() const {
- return opacity;
+ return modulate;
}
@@ -614,29 +574,17 @@ CanvasItem *CanvasItem::get_parent_item() const {
}
-void CanvasItem::set_self_opacity(float p_self_opacity) {
+void CanvasItem::set_self_modulate(const Color& p_self_modulate) {
- self_opacity=p_self_opacity;
- VisualServer::get_singleton()->canvas_item_set_self_opacity(canvas_item,self_opacity);
-
-}
-float CanvasItem::get_self_opacity() const {
+ self_modulate=p_self_modulate;
+ VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item,self_modulate);
- return self_opacity;
}
+Color CanvasItem::get_self_modulate() const {
-void CanvasItem::set_blend_mode(BlendMode p_blend_mode) {
-
- ERR_FAIL_INDEX(p_blend_mode,5);
- blend_mode=p_blend_mode;
- VisualServer::get_singleton()->canvas_item_set_blend_mode(canvas_item,VS::MaterialBlendMode(blend_mode));
-
+ return self_modulate;
}
-CanvasItem::BlendMode CanvasItem::get_blend_mode() const {
-
- return blend_mode;
-}
void CanvasItem::set_light_mask(int p_light_mask) {
@@ -913,7 +861,7 @@ void CanvasItem::set_draw_behind_parent(bool p_enable) {
if (behind==p_enable)
return;
behind=p_enable;
- VisualServer::get_singleton()->canvas_item_set_on_top(canvas_item,!behind);
+ VisualServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item,behind);
}
@@ -983,8 +931,7 @@ Vector2 CanvasItem::get_local_mouse_pos() const{
void CanvasItem::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("_sort_children"),&CanvasItem::_sort_children);
- ObjectTypeDB::bind_method(_MD("_raise_self"),&CanvasItem::_raise_self);
+ ObjectTypeDB::bind_method(_MD("_toplevel_raise_self"),&CanvasItem::_toplevel_raise_self);
ObjectTypeDB::bind_method(_MD("_update_callback"),&CanvasItem::_update_callback);
ObjectTypeDB::bind_method(_MD("_set_visible_"),&CanvasItem::_set_visible_);
ObjectTypeDB::bind_method(_MD("_is_visible_"),&CanvasItem::_is_visible_);
@@ -1011,16 +958,13 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_as_toplevel","enable"),&CanvasItem::set_as_toplevel);
ObjectTypeDB::bind_method(_MD("is_set_as_toplevel"),&CanvasItem::is_set_as_toplevel);
- ObjectTypeDB::bind_method(_MD("set_blend_mode","blend_mode"),&CanvasItem::set_blend_mode);
- ObjectTypeDB::bind_method(_MD("get_blend_mode"),&CanvasItem::get_blend_mode);
-
ObjectTypeDB::bind_method(_MD("set_light_mask","light_mask"),&CanvasItem::set_light_mask);
ObjectTypeDB::bind_method(_MD("get_light_mask"),&CanvasItem::get_light_mask);
- ObjectTypeDB::bind_method(_MD("set_opacity","opacity"),&CanvasItem::set_opacity);
- ObjectTypeDB::bind_method(_MD("get_opacity"),&CanvasItem::get_opacity);
- ObjectTypeDB::bind_method(_MD("set_self_opacity","self_opacity"),&CanvasItem::set_self_opacity);
- ObjectTypeDB::bind_method(_MD("get_self_opacity"),&CanvasItem::get_self_opacity);
+ ObjectTypeDB::bind_method(_MD("set_modulate","modulate"),&CanvasItem::set_modulate);
+ ObjectTypeDB::bind_method(_MD("get_modulate"),&CanvasItem::get_modulate);
+ ObjectTypeDB::bind_method(_MD("set_self_modulate","self_modulate"),&CanvasItem::set_self_modulate);
+ ObjectTypeDB::bind_method(_MD("get_self_modulate"),&CanvasItem::get_self_modulate);
ObjectTypeDB::bind_method(_MD("set_draw_behind_parent","enable"),&CanvasItem::set_draw_behind_parent);
ObjectTypeDB::bind_method(_MD("is_draw_behind_parent_enabled"),&CanvasItem::is_draw_behind_parent_enabled);
@@ -1069,12 +1013,11 @@ void CanvasItem::_bind_methods() {
BIND_VMETHOD(MethodInfo("_draw"));
ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
- ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
- ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/modulate",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_modulate"),_SCS("get_modulate") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/self_modulate",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_modulate"),_SCS("get_self_modulate") );
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_PROPERTYNO( PropertyInfo(Variant::INT,"visibility/light_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_light_mask"),_SCS("get_light_mask") );
ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"material/material",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), _SCS("set_material"),_SCS("get_material") );
ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"material/use_parent"), _SCS("set_use_parent_material"),_SCS("get_use_parent_material") );
@@ -1176,12 +1119,10 @@ CanvasItem::CanvasItem() : xform_change(this) {
canvas_item=VisualServer::get_singleton()->canvas_item_create();
hidden=false;
pending_update=false;
- opacity=1;
- self_opacity=1;
+ modulate=Color(1,1,1,1);
+ self_modulate=Color(1,1,1,1);
toplevel=false;
- pending_children_sort=false;
first_draw=false;
- blend_mode=BLEND_MODE_MIX;
drawing=false;
behind=false;
block_transform_notify=false;
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 7849a66185..b65c1a60b4 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -33,6 +33,7 @@
#include "scene/resources/texture.h"
#include "scene/main/scene_main_loop.h"
#include "scene/resources/shader.h"
+#include "scene/resources/material.h"
class CanvasLayer;
class Viewport;
@@ -40,22 +41,19 @@ class Font;
class StyleBox;
-class CanvasItemMaterial : public Resource{
+class CanvasItemMaterial : public Material{
- OBJ_TYPE(CanvasItemMaterial,Resource);
+ OBJ_TYPE(CanvasItemMaterial,Material);
RID material;
Ref<Shader> shader;
public:
- enum ShadingMode {
+ /*enum ShadingMode {
SHADING_NORMAL,
SHADING_UNSHADED,
SHADING_ONLY_LIGHT,
- };
+ };*/
protected:
-
- ShadingMode shading_mode;
-
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;
@@ -72,15 +70,12 @@ public:
void set_shader_param(const StringName& p_param,const Variant& p_value);
Variant get_shader_param(const StringName& p_param) const;
- void set_shading_mode(ShadingMode p_mode);
- ShadingMode get_shading_mode() const;
-
virtual RID get_rid() const;
CanvasItemMaterial();
~CanvasItemMaterial();
};
-VARIANT_ENUM_CAST( CanvasItemMaterial::ShadingMode );
+
class CanvasItem : public Node {
@@ -107,8 +102,8 @@ private:
CanvasLayer *canvas_layer;
- float opacity;
- float self_opacity;
+ Color modulate;
+ Color self_modulate;
List<CanvasItem*> children_items;
List<CanvasItem*>::Element *C;
@@ -120,7 +115,6 @@ private:
bool hidden;
bool pending_update;
bool toplevel;
- bool pending_children_sort;
bool drawing;
bool block_transform_notify;
bool behind;
@@ -133,7 +127,7 @@ private:
mutable bool global_invalid;
- void _raise_self();
+ void _toplevel_raise_self();
void _propagate_visibility_changed(bool p_visible);
@@ -145,9 +139,6 @@ private:
void _enter_canvas();
void _exit_canvas();
- void _queue_sort_children();
- void _sort_children();
-
void _notify_transform(CanvasItem *p_node);
void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); }
@@ -193,17 +184,14 @@ public:
void update();
- void set_blend_mode(BlendMode p_blend_mode);
- BlendMode get_blend_mode() const;
-
virtual void set_light_mask(int p_light_mask);
int get_light_mask() const;
- void set_opacity(float p_opacity);
- float get_opacity() const;
+ void set_modulate(const Color& p_modulate);
+ Color get_modulate() const;
- void set_self_opacity(float p_self_opacity);
- float get_self_opacity() const;
+ void set_self_modulate(const Color& p_self_modulate);
+ Color get_self_modulate() const;
/* DRAWING API */
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index f37cef673d..8e5b8ba0a4 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -208,26 +208,26 @@ int Light2D::get_layer_range_max() const {
return layer_max;
}
-void Light2D::set_item_mask( int p_mask) {
+void Light2D::set_item_cull_mask( int p_mask) {
item_mask=p_mask;
- VS::get_singleton()->canvas_light_set_item_mask(canvas_light,item_mask);
+ VS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light,item_mask);
}
-int Light2D::get_item_mask() const {
+int Light2D::get_item_cull_mask() const {
return item_mask;
}
-void Light2D::set_item_shadow_mask( int p_mask) {
+void Light2D::set_item_shadow_cull_mask( int p_mask) {
item_shadow_mask=p_mask;
- VS::get_singleton()->canvas_light_set_item_shadow_mask(canvas_light,item_shadow_mask);
+ VS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light,item_shadow_mask);
}
-int Light2D::get_item_shadow_mask() const {
+int Light2D::get_item_shadow_cull_mask() const {
return item_shadow_mask;
}
@@ -265,17 +265,30 @@ int Light2D::get_shadow_buffer_size() const {
return shadow_buffer_size;
}
-void Light2D::set_shadow_esm_multiplier( float p_multiplier) {
+void Light2D::set_shadow_gradient_length( float p_multiplier) {
- shadow_esm_multiplier=p_multiplier;
- VS::get_singleton()->canvas_light_set_shadow_esm_multiplier(canvas_light,p_multiplier);
+ shadow_gradient_length=p_multiplier;
+ VS::get_singleton()->canvas_light_set_shadow_gradient_length(canvas_light,p_multiplier);
}
-float Light2D::get_shadow_esm_multiplier() const{
+float Light2D::get_shadow_gradient_length() const{
- return shadow_esm_multiplier;
+ return shadow_gradient_length;
}
+
+void Light2D::set_shadow_filter( ShadowFilter p_filter) {
+ shadow_filter=p_filter;
+ VS::get_singleton()->canvas_light_set_shadow_filter(canvas_light,VS::CanvasLightShadowFilter(p_filter ));
+}
+
+Light2D::ShadowFilter Light2D::get_shadow_filter() const {
+
+ return shadow_filter;
+}
+
+
+
void Light2D::set_shadow_color( const Color& p_shadow_color) {
shadow_color=p_shadow_color;
VS::get_singleton()->canvas_light_set_shadow_color(canvas_light,shadow_color);
@@ -360,11 +373,11 @@ void Light2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_layer_range_max"),&Light2D::get_layer_range_max);
- ObjectTypeDB::bind_method(_MD("set_item_mask","item_mask"),&Light2D::set_item_mask);
- ObjectTypeDB::bind_method(_MD("get_item_mask"),&Light2D::get_item_mask);
+ ObjectTypeDB::bind_method(_MD("set_item_cull_mask","item_cull_mask"),&Light2D::set_item_cull_mask);
+ ObjectTypeDB::bind_method(_MD("get_item_cull_mask"),&Light2D::get_item_cull_mask);
- ObjectTypeDB::bind_method(_MD("set_item_shadow_mask","item_shadow_mask"),&Light2D::set_item_shadow_mask);
- ObjectTypeDB::bind_method(_MD("get_item_shadow_mask"),&Light2D::get_item_shadow_mask);
+ ObjectTypeDB::bind_method(_MD("set_item_shadow_cull_mask","item_shadow_cull_mask"),&Light2D::set_item_shadow_cull_mask);
+ ObjectTypeDB::bind_method(_MD("get_item_shadow_cull_mask"),&Light2D::get_item_shadow_cull_mask);
ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Light2D::set_mode);
ObjectTypeDB::bind_method(_MD("get_mode"),&Light2D::get_mode);
@@ -375,8 +388,11 @@ void Light2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_shadow_buffer_size","size"),&Light2D::set_shadow_buffer_size);
ObjectTypeDB::bind_method(_MD("get_shadow_buffer_size"),&Light2D::get_shadow_buffer_size);
- ObjectTypeDB::bind_method(_MD("set_shadow_esm_multiplier","multiplier"),&Light2D::set_shadow_esm_multiplier);
- ObjectTypeDB::bind_method(_MD("get_shadow_esm_multiplier"),&Light2D::get_shadow_esm_multiplier);
+ ObjectTypeDB::bind_method(_MD("set_shadow_gradient_length","multiplier"),&Light2D::set_shadow_gradient_length);
+ ObjectTypeDB::bind_method(_MD("get_shadow_gradient_length"),&Light2D::get_shadow_gradient_length);
+
+ ObjectTypeDB::bind_method(_MD("set_shadow_filter","filter"),&Light2D::set_shadow_filter);
+ ObjectTypeDB::bind_method(_MD("get_shadow_filter"),&Light2D::get_shadow_filter);
ObjectTypeDB::bind_method(_MD("set_shadow_color","shadow_color"),&Light2D::set_shadow_color);
ObjectTypeDB::bind_method(_MD("get_shadow_color"),&Light2D::get_shadow_color);
@@ -394,12 +410,13 @@ void Light2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_min",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_min"),_SCS("get_layer_range_min"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"range/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"range/item_cull_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_cull_mask"),_SCS("get_item_cull_mask"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow/enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled"));
ADD_PROPERTY( PropertyInfo(Variant::COLOR,"shadow/color"),_SCS("set_shadow_color"),_SCS("get_shadow_color"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/buffer_size",PROPERTY_HINT_RANGE,"32,16384,1"),_SCS("set_shadow_buffer_size"),_SCS("get_shadow_buffer_size"));
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/esm_multiplier",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_esm_multiplier"),_SCS("get_shadow_esm_multiplier"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_mask"),_SCS("get_item_shadow_mask"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/gradient_length",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_gradient_length"),_SCS("get_shadow_gradient_length"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/filter",PROPERTY_HINT_ENUM,"None,PCF3,PCF5,PCF9,PCF13"),_SCS("set_shadow_filter"),_SCS("get_shadow_filter"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_cull_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_cull_mask"),_SCS("get_item_shadow_cull_mask"));
BIND_CONSTANT( MODE_ADD );
BIND_CONSTANT( MODE_SUB );
@@ -425,9 +442,10 @@ Light2D::Light2D() {
item_shadow_mask=1;
mode=MODE_ADD;
shadow_buffer_size=2048;
- shadow_esm_multiplier=80;
+ shadow_gradient_length=0;
energy=1.0;
shadow_color=Color(0,0,0,0);
+ shadow_filter=SHADOW_FILTER_NONE;
}
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index c03ef96eff..75dcf67936 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -42,6 +42,14 @@ public:
MODE_MASK,
};
+ enum ShadowFilter {
+ SHADOW_FILTER_NONE,
+ SHADOW_FILTER_PCF3,
+ SHADOW_FILTER_PCF5,
+ SHADOW_FILTER_PCF9,
+ SHADOW_FILTER_PCF13,
+ };
+
private:
RID canvas_light;
bool enabled;
@@ -58,10 +66,12 @@ private:
int item_mask;
int item_shadow_mask;
int shadow_buffer_size;
- float shadow_esm_multiplier;
+ float shadow_gradient_length;
Mode mode;
Ref<Texture> texture;
Vector2 texture_offset;
+ ShadowFilter shadow_filter;
+
void _update_light_visibility();
protected:
@@ -108,11 +118,11 @@ public:
void set_layer_range_max( int p_max_layer);
int get_layer_range_max() const;
- void set_item_mask( int p_mask);
- int get_item_mask() const;
+ void set_item_cull_mask( int p_mask);
+ int get_item_cull_mask() const;
- void set_item_shadow_mask( int p_mask);
- int get_item_shadow_mask() const;
+ void set_item_shadow_cull_mask( int p_mask);
+ int get_item_shadow_cull_mask() const;
void set_mode( Mode p_mode );
Mode get_mode() const;
@@ -123,8 +133,11 @@ public:
void set_shadow_buffer_size( int p_size );
int get_shadow_buffer_size() const;
- void set_shadow_esm_multiplier( float p_multiplier);
- float get_shadow_esm_multiplier() const;
+ void set_shadow_gradient_length( float p_multiplier);
+ float get_shadow_gradient_length() const;
+
+ void set_shadow_filter( ShadowFilter p_filter);
+ ShadowFilter get_shadow_filter() const;
void set_shadow_color( const Color& p_shadow_color);
Color get_shadow_color() const;
@@ -139,5 +152,7 @@ public:
};
VARIANT_ENUM_CAST(Light2D::Mode);
+VARIANT_ENUM_CAST(Light2D::ShadowFilter);
+
#endif // LIGHT_2D_H
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index c5b338bf59..00ce59a6f6 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -376,7 +376,7 @@ Sprite::Sprite() {
///
///
-
+#if 0
void ViewportSprite::edit_set_pivot(const Point2& p_pivot) {
set_offset(p_pivot);
@@ -588,3 +588,4 @@ ViewportSprite::ViewportSprite() {
centered=true;
modulate=Color(1,1,1,1);
}
+#endif
diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h
index 32d3f476d1..2e7b753a04 100644
--- a/scene/2d/sprite.h
+++ b/scene/2d/sprite.h
@@ -107,6 +107,7 @@ public:
Sprite();
};
+#if 0
class ViewportSprite : public Node2D {
OBJ_TYPE( ViewportSprite, Node2D );
@@ -149,4 +150,5 @@ public:
ViewportSprite();
};
+#endif
#endif // SPRITE_H
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 1a4f88c30e..972ce8378a 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -477,7 +477,7 @@ void TileMap::_update_dirty_quadrants() {
_fix_cell_transform(xform,c,shape_ofs+center_ofs,s);
- if (debug_canvas_item) {
+ if (debug_canvas_item.is_valid()) {
vs->canvas_item_add_set_transform(debug_canvas_item,xform);
shape->draw(debug_canvas_item,debug_collision_color);
@@ -488,7 +488,7 @@ void TileMap::_update_dirty_quadrants() {
}
}
- if (debug_canvas_item) {
+ if (debug_canvas_item.is_valid()) {
vs->canvas_item_add_set_transform(debug_canvas_item,Matrix32());
}
@@ -541,26 +541,19 @@ void TileMap::_update_dirty_quadrants() {
if (quadrant_order_dirty) {
+ int index=-0x80000000; //always must be drawn below children
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Quadrant &q=E->get();
for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
- VS::get_singleton()->canvas_item_raise(E->get());
+ VS::get_singleton()->canvas_item_set_draw_index(E->get(),index++);
}
}
quadrant_order_dirty=false;
}
- for(int i=0;i<get_child_count();i++) {
-
- CanvasItem *c=get_child(i)->cast_to<CanvasItem>();
-
- if (c)
- VS::get_singleton()->canvas_item_raise(c->get_canvas_item());
- }
-
_recompute_rect_cache();
}
diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp
index ca3a309568..07f0e4ee57 100644
--- a/scene/3d/baked_light_instance.cpp
+++ b/scene/3d/baked_light_instance.cpp
@@ -29,6 +29,7 @@
#include "baked_light_instance.h"
#include "scene/scene_string_names.h"
+#if 0
RID BakedLightInstance::get_baked_light_instance() const {
@@ -179,3 +180,4 @@ BakedLightSampler::~BakedLightSampler(){
VS::get_singleton()->free(base);
}
+#endif
diff --git a/scene/3d/baked_light_instance.h b/scene/3d/baked_light_instance.h
index 002e55df1d..15f04fea31 100644
--- a/scene/3d/baked_light_instance.h
+++ b/scene/3d/baked_light_instance.h
@@ -32,6 +32,7 @@
#include "scene/3d/visual_instance.h"
#include "scene/resources/baked_light.h"
+#if 0
class BakedLightBaker;
@@ -101,5 +102,5 @@ public:
VARIANT_ENUM_CAST( BakedLightSampler::Param );
-
+#endif
#endif // BAKED_LIGHT_H
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index e76c0938fb..1ce07b0264 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -96,8 +96,8 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) {
} else {
clear_current();
}
- } else if (p_name=="visible_layers") {
- set_visible_layers(p_value);
+ } else if (p_name=="cull_mask") {
+ set_cull_mask(p_value);
} else if (p_name=="environment") {
set_environment(p_value);
} else
@@ -130,8 +130,8 @@ bool Camera::_get(const StringName& p_name,Variant &r_ret) const {
} else {
r_ret=is_current();
}
- } else if (p_name=="visible_layers") {
- r_ret=get_visible_layers();
+ } else if (p_name=="cull_mask") {
+ r_ret=get_cull_mask();
} else if (p_name=="h_offset") {
r_ret=get_h_offset();
} else if (p_name=="v_offset") {
@@ -176,7 +176,7 @@ void Camera::_get_property_list( List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo( Variant::REAL, "far" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") );
p_list->push_back( PropertyInfo( Variant::INT, "keep_aspect",PROPERTY_HINT_ENUM,"Keep Width,Keep Height") );
p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) );
- p_list->push_back( PropertyInfo( Variant::INT, "visible_layers",PROPERTY_HINT_ALL_FLAGS ) );
+ p_list->push_back( PropertyInfo( Variant::INT, "cull_mask",PROPERTY_HINT_ALL_FLAGS ) );
p_list->push_back( PropertyInfo( Variant::OBJECT, "environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment" ) );
p_list->push_back( PropertyInfo( Variant::REAL, "h_offset" ) );
p_list->push_back( PropertyInfo( Variant::REAL, "v_offset" ) );
@@ -342,91 +342,6 @@ bool Camera::_can_gizmo_scale() const {
}
-RES Camera::_get_gizmo_geometry() const {
-
-
- Ref<SurfaceTool> surface_tool( memnew( SurfaceTool ));
-
- Ref<FixedMaterial> mat( memnew( FixedMaterial ));
-
- mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(1.0,0.5,1.0,0.5) );
- mat->set_line_width(4);
- mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- mat->set_flag(Material::FLAG_UNSHADED,true);
- //mat->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
-
- surface_tool->begin(Mesh::PRIMITIVE_LINES);
- surface_tool->set_material(mat);
-
- switch(mode) {
-
- case PROJECTION_PERSPECTIVE: {
-
-
-
- Vector3 side=Vector3( Math::sin(Math::deg2rad(fov)), 0, -Math::cos(Math::deg2rad(fov)) );
- Vector3 nside=side;
- nside.x=-nside.x;
- Vector3 up=Vector3(0,side.x,0);
-
-
-#define ADD_TRIANGLE( m_a, m_b, m_c)\
-{\
- surface_tool->add_vertex(m_a);\
- surface_tool->add_vertex(m_b);\
- surface_tool->add_vertex(m_b);\
- surface_tool->add_vertex(m_c);\
- surface_tool->add_vertex(m_c);\
- surface_tool->add_vertex(m_a);\
-}
-
- ADD_TRIANGLE( Vector3(), side+up, side-up );
- ADD_TRIANGLE( Vector3(), nside+up, nside-up );
- ADD_TRIANGLE( Vector3(), side+up, nside+up );
- ADD_TRIANGLE( Vector3(), side-up, nside-up );
-
- side.x*=0.25;
- nside.x*=0.25;
- Vector3 tup( 0, up.y*3/2,side.z);
- ADD_TRIANGLE( tup, side+up, nside+up );
-
- } break;
- case PROJECTION_ORTHOGONAL: {
-
-#define ADD_QUAD( m_a, m_b, m_c, m_d)\
-{\
- surface_tool->add_vertex(m_a);\
- surface_tool->add_vertex(m_b);\
- surface_tool->add_vertex(m_b);\
- surface_tool->add_vertex(m_c);\
- surface_tool->add_vertex(m_c);\
- surface_tool->add_vertex(m_d);\
- surface_tool->add_vertex(m_d);\
- surface_tool->add_vertex(m_a);\
-}
-
- float hsize=size*0.5;
- Vector3 right(hsize,0,0);
- Vector3 up(0,hsize,0);
- Vector3 back(0,0,-1.0);
- Vector3 front(0,0,0);
-
- ADD_QUAD( -up-right,-up+right,up+right,up-right);
- ADD_QUAD( -up-right+back,-up+right+back,up+right+back,up-right+back);
- ADD_QUAD( up+right,up+right+back,up-right+back,up-right);
- ADD_QUAD( -up+right,-up+right+back,-up-right+back,-up-right);
-
- right.x*=0.25;
- Vector3 tup( 0, up.y*3/2,back.z );
- ADD_TRIANGLE( tup, right+up+back, -right+up+back );
-
- } break;
-
- }
-
- return surface_tool->commit();
-
-}
Vector3 Camera::project_ray_normal(const Point2& p_pos) const {
@@ -648,8 +563,8 @@ void Camera::_bind_methods() {
ObjectTypeDB::bind_method( _MD("get_zfar"),&Camera::get_zfar );
ObjectTypeDB::bind_method( _MD("get_znear"),&Camera::get_znear );
ObjectTypeDB::bind_method( _MD("get_projection"),&Camera::get_projection );
- ObjectTypeDB::bind_method( _MD("set_visible_layers","mask"),&Camera::set_visible_layers );
- ObjectTypeDB::bind_method( _MD("get_visible_layers"),&Camera::get_visible_layers );
+ ObjectTypeDB::bind_method( _MD("set_cull_mask","mask"),&Camera::set_cull_mask );
+ ObjectTypeDB::bind_method( _MD("get_cull_mask"),&Camera::get_cull_mask );
ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&Camera::set_environment);
ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&Camera::get_environment);
ObjectTypeDB::bind_method(_MD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode);
@@ -690,13 +605,13 @@ Camera::Projection Camera::get_projection() const {
return mode;
}
-void Camera::set_visible_layers(uint32_t p_layers) {
+void Camera::set_cull_mask(uint32_t p_layers) {
layers=p_layers;
- VisualServer::get_singleton()->camera_set_visible_layers(camera,layers);
+ VisualServer::get_singleton()->camera_set_cull_mask(camera,layers);
}
-uint32_t Camera::get_visible_layers() const{
+uint32_t Camera::get_cull_mask() const{
return layers;
}
@@ -757,7 +672,7 @@ Camera::Camera() {
layers=0xfffff;
v_offset=0;
h_offset=0;
- VisualServer::get_singleton()->camera_set_visible_layers(camera,layers);
+ VisualServer::get_singleton()->camera_set_cull_mask(camera,layers);
//active=false;
}
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index 30c6928245..3ea0bd711c 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -75,7 +75,7 @@ private:
Ref<Environment> environment;
virtual bool _can_gizmo_scale() const;
- virtual RES _get_gizmo_geometry() const;
+
//void _camera_make_current(Node *p_camera);
@@ -126,8 +126,8 @@ public:
bool is_position_behind(const Vector3& p_pos) const;
Vector3 project_position(const Point2& p_point) const;
- void set_visible_layers(uint32_t p_layers);
- uint32_t get_visible_layers() const;
+ void set_cull_mask(uint32_t p_layers);
+ uint32_t get_cull_mask() const;
Vector<Plane> get_frustum() const;
diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp
index 227bb3a59d..d98f100020 100644
--- a/scene/3d/light.cpp
+++ b/scene/3d/light.cpp
@@ -32,75 +32,6 @@
#include "scene/resources/surface_tool.h"
-static const char* _light_param_names[VS::LIGHT_PARAM_MAX]={
- "params/spot_attenuation",
- "params/spot_angle",
- "params/radius",
- "params/energy",
- "params/attenuation",
- "shadow/darkening",
- "shadow/z_offset",
- "shadow/z_slope_scale",
- "shadow/esm_multiplier",
- "shadow/blur_passes"
-};
-
-void Light::set_parameter(Parameter p_param, float p_value) {
-
- ERR_FAIL_INDEX(p_param, PARAM_MAX);
- vars[p_param]=p_value;
- VisualServer::get_singleton()->light_set_param(light,(VisualServer::LightParam)p_param,p_value);
- if (p_param==PARAM_RADIUS || p_param==PARAM_SPOT_ANGLE)
- update_gizmo();
- _change_notify(_light_param_names[p_param]);
-// _change_notify(_param_names[p_param]);
-}
-
-float Light::get_parameter(Parameter p_param) const {
-
- ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
- return vars[p_param];
-
-}
-
-void Light::set_color(LightColor p_color, const Color& p_value) {
-
- ERR_FAIL_INDEX(p_color, 3);
- colors[p_color]=p_value;
- VisualServer::get_singleton()->light_set_color(light,(VisualServer::LightColor)p_color,p_value);
- //_change_notify(_color_names[p_color]);
-
-}
-Color Light::get_color(LightColor p_color) const {
-
- ERR_FAIL_INDEX_V(p_color, 3, Color());
- return colors[p_color];
-
-}
-
-
-void Light::set_project_shadows(bool p_enabled) {
-
- shadows=p_enabled;
- VisualServer::get_singleton()->light_set_shadow(light, p_enabled);
- _change_notify("shadow");
-}
-bool Light::has_project_shadows() const {
-
- return shadows;
-}
-
-void Light::set_projector(const Ref<Texture>& p_projector) {
-
- projector=p_projector;
- VisualServer::get_singleton()->light_set_projector(light, projector.is_null()?RID():projector->get_rid());
-}
-
-Ref<Texture> Light::get_projector() const {
-
- return projector;
-}
-
bool Light::_can_gizmo_scale() const {
@@ -108,220 +39,9 @@ bool Light::_can_gizmo_scale() const {
}
-static void _make_sphere(int p_lats, int p_lons, float p_radius, Ref<SurfaceTool> p_tool) {
-
-
- p_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
-
- for(int i = 1; i <= p_lats; i++) {
- double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats);
- double z0 = Math::sin(lat0);
- double zr0 = Math::cos(lat0);
-
- double lat1 = Math_PI * (-0.5 + (double) i / p_lats);
- double z1 = Math::sin(lat1);
- double zr1 = Math::cos(lat1);
-
- for(int j = p_lons; j >= 1; j--) {
-
- double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons;
- double x0 = Math::cos(lng0);
- double y0 = Math::sin(lng0);
-
- double lng1 = 2 * Math_PI * (double) (j) / p_lons;
- double x1 = Math::cos(lng1);
- double y1 = Math::sin(lng1);
-
-
- Vector3 v[4]={
- Vector3(x1 * zr0, z0, y1 *zr0),
- Vector3(x1 * zr1, z1, y1 *zr1),
- Vector3(x0 * zr1, z1, y0 *zr1),
- Vector3(x0 * zr0, z0, y0 *zr0)
- };
-
-#define ADD_POINT(m_idx) \
- p_tool->add_normal(v[m_idx]);\
- p_tool->add_vertex(v[m_idx]*p_radius);
-
- ADD_POINT(0);
- ADD_POINT(1);
- ADD_POINT(2);
-
- ADD_POINT(2);
- ADD_POINT(3);
- ADD_POINT(0);
- }
- }
-
-}
-
-RES Light::_get_gizmo_geometry() const {
-
-
- Ref<FixedMaterial> mat_area( memnew( FixedMaterial ));
-
- mat_area->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(0.7,0.6,0.0,0.05) );
- mat_area->set_parameter( FixedMaterial::PARAM_EMISSION,Color(0.7,0.7,0.7) );
- mat_area->set_blend_mode( Material::BLEND_MODE_ADD );
- mat_area->set_flag(Material::FLAG_DOUBLE_SIDED,true);
-// mat_area->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
-
- Ref<FixedMaterial> mat_light( memnew( FixedMaterial ));
-
- mat_light->set_parameter( FixedMaterial::PARAM_DIFFUSE, Color(1.0,1.0,0.8,0.9) );
- mat_light->set_flag(Material::FLAG_UNSHADED,true);
-
- Ref< Mesh > mesh;
-
- Ref<SurfaceTool> surftool( memnew( SurfaceTool ));
-
- switch(type) {
-
- case VisualServer::LIGHT_DIRECTIONAL: {
-
-
- mat_area->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(0.9,0.8,0.1,0.8) );
- mat_area->set_blend_mode( Material::BLEND_MODE_MIX);
- mat_area->set_flag(Material::FLAG_DOUBLE_SIDED,false);
- mat_area->set_flag(Material::FLAG_UNSHADED,true);
-
- _make_sphere( 5,5,0.6, surftool );
- surftool->set_material(mat_light);
- mesh=surftool->commit(mesh);
-
- // float radius=1;
-
- surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
-
- const int arrow_points=5;
- Vector3 arrow[arrow_points]={
- Vector3(0,0,2),
- Vector3(1,1,2),
- Vector3(1,1,-1),
- Vector3(2,2,-1),
- Vector3(0,0,-3)
- };
-
- int arrow_sides=4;
-
-
- for(int i = 0; i < arrow_sides ; i++) {
-
-
- Matrix3 ma(Vector3(0,0,1),Math_PI*2*float(i)/arrow_sides);
- Matrix3 mb(Vector3(0,0,1),Math_PI*2*float(i+1)/arrow_sides);
-
-
- for(int j=0;j<arrow_points-1;j++) {
-
- Vector3 points[4]={
- ma.xform(arrow[j]),
- mb.xform(arrow[j]),
- mb.xform(arrow[j+1]),
- ma.xform(arrow[j+1]),
- };
-
- Vector3 n = Plane(points[0],points[1],points[2]).normal;
-
- surftool->add_normal(n);
- surftool->add_vertex(points[0]);
- surftool->add_normal(n);
- surftool->add_vertex(points[1]);
- surftool->add_normal(n);
- surftool->add_vertex(points[2]);
-
- surftool->add_normal(n);
- surftool->add_vertex(points[0]);
- surftool->add_normal(n);
- surftool->add_vertex(points[2]);
- surftool->add_normal(n);
- surftool->add_vertex(points[3]);
-
-
- }
-
-
- }
-
- surftool->set_material(mat_area);
- mesh=surftool->commit(mesh);
-
-
-
- } break;
- case VisualServer::LIGHT_OMNI: {
-
-
- _make_sphere( 20,20,vars[PARAM_RADIUS], surftool );
- surftool->set_material(mat_area);
- mesh=surftool->commit(mesh);
- _make_sphere(5,5, 0.1, surftool );
- surftool->set_material(mat_light);
- mesh=surftool->commit(mesh);
- } break;
-
- case VisualServer::LIGHT_SPOT: {
-
- _make_sphere( 5,5,0.1, surftool );
- surftool->set_material(mat_light);
- mesh=surftool->commit(mesh);
-
- // make cone
- int points=24;
- float len=vars[PARAM_RADIUS];
- float size=Math::tan(Math::deg2rad(vars[PARAM_SPOT_ANGLE]))*len;
-
- surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
-
- for(int i = 0; i < points; i++) {
-
- float x0=Math::sin(i * Math_PI * 2 / points);
- float y0=Math::cos(i * Math_PI * 2 / points);
- float x1=Math::sin((i+1) * Math_PI * 2 / points);
- float y1=Math::cos((i+1) * Math_PI * 2 / points);
-
- Vector3 v1=Vector3(x0*size,y0*size,-len).normalized()*len;
- Vector3 v2=Vector3(x1*size,y1*size,-len).normalized()*len;
-
- Vector3 v3=Vector3(0,0,0);
- Vector3 v4=Vector3(0,0,v1.z);
-
- Vector3 n = Plane(v1,v2,v3).normal;
-
-
- surftool->add_normal(n);
- surftool->add_vertex(v1);
- surftool->add_normal(n);
- surftool->add_vertex(v2);
- surftool->add_normal(n);
- surftool->add_vertex(v3);
-
- n=Vector3(0,0,-1);
-
- surftool->add_normal(n);
- surftool->add_vertex(v1);
- surftool->add_normal(n);
- surftool->add_vertex(v2);
- surftool->add_normal(n);
- surftool->add_vertex(v4);
-
-
- }
-
- surftool->set_material(mat_area);
- mesh=surftool->commit(mesh);
-
-
- } break;
- }
-
- return mesh;
-}
-
-
AABB Light::get_aabb() const {
+#if 0
if (type==VisualServer::LIGHT_DIRECTIONAL) {
return AABB( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) );
@@ -336,7 +56,7 @@ AABB Light::get_aabb() const {
float size=Math::tan(Math::deg2rad(vars[PARAM_SPOT_ANGLE]))*len;
return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) );
}
-
+#endif
return AABB();
}
@@ -346,89 +66,6 @@ DVector<Face3> Light::get_faces(uint32_t p_usage_flags) const {
}
-void Light::set_operator(Operator p_op) {
- ERR_FAIL_INDEX(p_op,2);
- op=p_op;
- VisualServer::get_singleton()->light_set_operator(light,VS::LightOp(op));
-
-}
-
-void Light::set_bake_mode(BakeMode p_bake_mode) {
-
- bake_mode=p_bake_mode;
-}
-
-Light::BakeMode Light::get_bake_mode() const {
-
- return bake_mode;
-}
-
-
-Light::Operator Light::get_operator() const {
-
- return op;
-}
-
-void Light::approximate_opengl_attenuation(float p_constant, float p_linear, float p_quadratic,float p_radius_treshold) {
-
- //this is horrible and must never be used
-
- float a = p_quadratic * p_radius_treshold;
- float b = p_linear * p_radius_treshold;
- float c = p_constant * p_radius_treshold -1;
-
- float radius=10000;
-
- if(a == 0) { // solve linear
- float d = Math::abs(-c/b);
- if(d<radius)
- radius=d;
-
-
- } else { // solve quadratic
- // now ad^2 + bd + c = 0, solve quadratic equation:
-
- float denominator = 2*a;
-
- if(denominator != 0) {
-
-
- float root = b*b - 4*a*c;
-
- if(root >=0) {
-
- root = sqrt(root);
-
- float solution1 = fabs( (-b + root) / denominator);
- float solution2 = fabs( (-b - root) / denominator);
-
- if(solution1 > radius)
- solution1 = radius;
-
- if(solution2 > radius)
- solution2 = radius;
-
- radius = (solution1 > solution2 ? solution1 : solution2);
- }
- }
- }
-
- float energy=1.0;
-
- /*if (p_constant>0)
- energy=1.0/p_constant; //energy is this
- else
- energy=8.0; // some high number..
-*/
-
- if (radius==10000)
- radius=100; //bug?
-
- set_parameter(PARAM_RADIUS,radius);
- set_parameter(PARAM_ENERGY,energy);
-
-}
-
void Light::_update_visibility() {
@@ -436,7 +73,7 @@ void Light::_update_visibility() {
return;
-bool editor_ok=true;
+ bool editor_ok=true;
#ifdef TOOLS_ENABLED
if (editor_only) {
@@ -448,7 +85,7 @@ bool editor_ok=true;
}
#endif
- VS::get_singleton()->instance_light_set_enabled(get_instance(),is_visible() && enabled && editor_ok);
+ //VS::get_singleton()->instance_light_set_enabled(get_instance(),is_visible() && editor_ok);
_change_notify("geometry/visible");
}
@@ -461,16 +98,6 @@ void Light::_notification(int p_what) {
}
}
-void Light::set_enabled(bool p_enabled) {
-
- enabled=p_enabled;
- _update_visibility();
-}
-
-bool Light::is_enabled() const{
-
- return enabled;
-}
void Light::set_editor_only(bool p_editor_only) {
@@ -486,68 +113,15 @@ bool Light::is_editor_only() const{
void Light::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_parameter","variable","value"), &Light::set_parameter );
- ObjectTypeDB::bind_method(_MD("get_parameter","variable"), &Light::get_parameter );
- ObjectTypeDB::bind_method(_MD("set_color","color","value"), &Light::set_color );
- ObjectTypeDB::bind_method(_MD("get_color","color"), &Light::get_color );
- ObjectTypeDB::bind_method(_MD("set_project_shadows","enable"), &Light::set_project_shadows );
- ObjectTypeDB::bind_method(_MD("has_project_shadows"), &Light::has_project_shadows );
- ObjectTypeDB::bind_method(_MD("set_projector","projector:Texture"), &Light::set_projector );
- ObjectTypeDB::bind_method(_MD("get_projector:Texture"), &Light::get_projector );
- ObjectTypeDB::bind_method(_MD("set_operator","operator"), &Light::set_operator );
- ObjectTypeDB::bind_method(_MD("get_operator"), &Light::get_operator );
- ObjectTypeDB::bind_method(_MD("set_bake_mode","bake_mode"), &Light::set_bake_mode );
- ObjectTypeDB::bind_method(_MD("get_bake_mode"), &Light::get_bake_mode );
- ObjectTypeDB::bind_method(_MD("set_enabled","enabled"), &Light::set_enabled );
- ObjectTypeDB::bind_method(_MD("is_enabled"), &Light::is_enabled );
+
ObjectTypeDB::bind_method(_MD("set_editor_only","editor_only"), &Light::set_editor_only );
ObjectTypeDB::bind_method(_MD("is_editor_only"), &Light::is_editor_only );
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "params/enabled"), _SCS("set_enabled"), _SCS("is_enabled"));
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "params/editor_only"), _SCS("set_editor_only"), _SCS("is_editor_only"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "params/bake_mode",PROPERTY_HINT_ENUM,"Disabled,Indirect,Indirect+Shadows,Full"), _SCS("set_bake_mode"), _SCS("get_bake_mode"));
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/energy", PROPERTY_HINT_EXP_RANGE, "0,64,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_ENERGY );
- /*
- if (type == VisualServer::LIGHT_OMNI || type == VisualServer::LIGHT_SPOT) {
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/radius", PROPERTY_HINT_RANGE, "0.01,4096,0.01"));
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/attenuation", PROPERTY_HINT_RANGE, "0,8,0.01"));
- }
- if (type == VisualServer::LIGHT_SPOT) {
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/spot_angle", PROPERTY_HINT_RANGE, "0.01,90.0,0.01"));
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/spot_attenuation", PROPERTY_HINT_RANGE, "0,8,0.01"));
- }*/
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "colors/diffuse"), _SCS("set_color"), _SCS("get_color"),COLOR_DIFFUSE);
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "colors/specular"), _SCS("set_color"), _SCS("get_color"),COLOR_SPECULAR);
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "shadow/shadow"), _SCS("set_project_shadows"), _SCS("has_project_shadows"));
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/darkening", PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADOW_DARKENING );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/z_offset", PROPERTY_HINT_RANGE, "0,128,0.001"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADOW_Z_OFFSET);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/z_slope_scale", PROPERTY_HINT_RANGE, "0,128,0.001"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADOW_Z_SLOPE_SCALE);
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/esm_multiplier", PROPERTY_HINT_RANGE, "1.0,512.0,0.1"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADOW_ESM_MULTIPLIER);
- ADD_PROPERTYI( PropertyInfo( Variant::INT, "shadow/blur_passes", PROPERTY_HINT_RANGE, "0,4,1"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADOW_BLUR_PASSES);
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "projector",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_projector"), _SCS("get_projector"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "operator",PROPERTY_HINT_ENUM,"Add,Sub"), _SCS("set_operator"), _SCS("get_operator"));
-
-
- BIND_CONSTANT( PARAM_RADIUS );
- BIND_CONSTANT( PARAM_ENERGY );
- BIND_CONSTANT( PARAM_ATTENUATION );
- BIND_CONSTANT( PARAM_SPOT_ANGLE );
- BIND_CONSTANT( PARAM_SPOT_ATTENUATION );
- BIND_CONSTANT( PARAM_SHADOW_DARKENING );
- BIND_CONSTANT( PARAM_SHADOW_Z_OFFSET );
-
-
- BIND_CONSTANT( COLOR_DIFFUSE );
- BIND_CONSTANT( COLOR_SPECULAR );
-
- BIND_CONSTANT( BAKE_MODE_DISABLED );
- BIND_CONSTANT( BAKE_MODE_INDIRECT );
- BIND_CONSTANT( BAKE_MODE_INDIRECT_AND_SHADOWS );
- BIND_CONSTANT( BAKE_MODE_FULL );
}
@@ -558,27 +132,8 @@ Light::Light(VisualServer::LightType p_type) {
type=p_type;
light=VisualServer::get_singleton()->light_create(p_type);
- set_parameter(PARAM_SPOT_ATTENUATION,1.0);
- set_parameter(PARAM_SPOT_ANGLE,30.0);
- set_parameter(PARAM_RADIUS,2.0);
- set_parameter(PARAM_ENERGY,1.0);
- set_parameter(PARAM_ATTENUATION,1.0);
- set_parameter(PARAM_SHADOW_DARKENING,0.0);
- set_parameter(PARAM_SHADOW_Z_OFFSET,0.05);
- set_parameter(PARAM_SHADOW_Z_SLOPE_SCALE,0);
- set_parameter(PARAM_SHADOW_ESM_MULTIPLIER,60);
- set_parameter(PARAM_SHADOW_BLUR_PASSES,1);
-
-
- set_color( COLOR_DIFFUSE, Color(1,1,1));
- set_color( COLOR_SPECULAR, Color(1,1,1));
-
- op=OPERATOR_ADD;
- set_project_shadows( false );
- set_base(light);
- enabled=true;
+
editor_only=false;
- bake_mode=BAKE_MODE_DISABLED;
}
@@ -598,59 +153,15 @@ Light::~Light() {
/////////////////////////////////////////
-void DirectionalLight::set_shadow_mode(ShadowMode p_mode) {
-
- shadow_mode=p_mode;
- VS::get_singleton()->light_directional_set_shadow_mode(light,(VS::LightDirectionalShadowMode)p_mode);
-
-}
-
-DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const{
-
- return shadow_mode;
-}
-
-void DirectionalLight::set_shadow_param(ShadowParam p_param, float p_value) {
-
- ERR_FAIL_INDEX(p_param,3);
- shadow_param[p_param]=p_value;
- VS::get_singleton()->light_directional_set_shadow_param(light,VS::LightDirectionalShadowParam(p_param),p_value);
-}
-
-float DirectionalLight::get_shadow_param(ShadowParam p_param) const {
- ERR_FAIL_INDEX_V(p_param,3,0);
- return shadow_param[p_param];
-}
-
void DirectionalLight::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_shadow_mode","mode"),&DirectionalLight::set_shadow_mode);
- ObjectTypeDB::bind_method(_MD("get_shadow_mode"),&DirectionalLight::get_shadow_mode);
- ObjectTypeDB::bind_method(_MD("set_shadow_param","param","value"),&DirectionalLight::set_shadow_param);
- ObjectTypeDB::bind_method(_MD("get_shadow_param","param"),&DirectionalLight::get_shadow_param);
-
- ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/mode",PROPERTY_HINT_ENUM,"Orthogonal,Perspective,PSSM 2 Splits,PSSM 4 Splits"),_SCS("set_shadow_mode"),_SCS("get_shadow_mode"));
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"shadow/max_distance",PROPERTY_HINT_EXP_RANGE,"0.00,99999,0.01"),_SCS("set_shadow_param"),_SCS("get_shadow_param"), SHADOW_PARAM_MAX_DISTANCE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"shadow/split_weight",PROPERTY_HINT_RANGE,"0.01,1.0,0.01"),_SCS("set_shadow_param"),_SCS("get_shadow_param"), SHADOW_PARAM_PSSM_SPLIT_WEIGHT);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"shadow/zoffset_scale",PROPERTY_HINT_RANGE,"0.01,1024.0,0.01"),_SCS("set_shadow_param"),_SCS("get_shadow_param"), SHADOW_PARAM_PSSM_ZOFFSET_SCALE);
- BIND_CONSTANT( SHADOW_ORTHOGONAL );
- BIND_CONSTANT( SHADOW_PERSPECTIVE );
- BIND_CONSTANT( SHADOW_PARALLEL_2_SPLITS );
- BIND_CONSTANT( SHADOW_PARALLEL_4_SPLITS );
- BIND_CONSTANT( SHADOW_PARAM_MAX_DISTANCE );
- BIND_CONSTANT( SHADOW_PARAM_PSSM_SPLIT_WEIGHT );
- BIND_CONSTANT( SHADOW_PARAM_PSSM_ZOFFSET_SCALE );
}
DirectionalLight::DirectionalLight() : Light( VisualServer::LIGHT_DIRECTIONAL ) {
- shadow_mode=SHADOW_ORTHOGONAL;
- shadow_param[SHADOW_PARAM_MAX_DISTANCE]=0;
- shadow_param[SHADOW_PARAM_PSSM_SPLIT_WEIGHT]=0.5;
- shadow_param[SHADOW_PARAM_PSSM_ZOFFSET_SCALE]=2.0;
}
@@ -658,19 +169,11 @@ DirectionalLight::DirectionalLight() : Light( VisualServer::LIGHT_DIRECTIONAL )
void OmniLight::_bind_methods() {
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/radius", PROPERTY_HINT_EXP_RANGE, "0.2,4096,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_RADIUS );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_ATTENUATION );
}
void SpotLight::_bind_methods() {
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/radius", PROPERTY_HINT_EXP_RANGE, "0.2,4096,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_RADIUS );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_ATTENUATION );
-
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/spot_angle", PROPERTY_HINT_RANGE, "0.01,89.9,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SPOT_ANGLE );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/spot_attenuation", PROPERTY_HINT_EXP_EASING, "spot_attenuation"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SPOT_ATTENUATION );
-
}
diff --git a/scene/3d/light.h b/scene/3d/light.h
index b25c6a44b5..3c31d90d4c 100644
--- a/scene/3d/light.h
+++ b/scene/3d/light.h
@@ -44,57 +44,12 @@ class Light : public VisualInstance {
public:
- enum Parameter {
- PARAM_RADIUS=VisualServer::LIGHT_PARAM_RADIUS,
- PARAM_ENERGY=VisualServer::LIGHT_PARAM_ENERGY,
- PARAM_ATTENUATION=VisualServer::LIGHT_PARAM_ATTENUATION,
- PARAM_SPOT_ANGLE=VisualServer::LIGHT_PARAM_SPOT_ANGLE,
- PARAM_SPOT_ATTENUATION=VisualServer::LIGHT_PARAM_SPOT_ATTENUATION,
- PARAM_SHADOW_DARKENING=VisualServer::LIGHT_PARAM_SHADOW_DARKENING,
- PARAM_SHADOW_Z_OFFSET=VisualServer::LIGHT_PARAM_SHADOW_Z_OFFSET,
- PARAM_SHADOW_Z_SLOPE_SCALE=VisualServer::LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE,
- PARAM_SHADOW_ESM_MULTIPLIER=VisualServer::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER,
- PARAM_SHADOW_BLUR_PASSES=VisualServer::LIGHT_PARAM_SHADOW_BLUR_PASSES,
- PARAM_MAX=VisualServer::LIGHT_PARAM_MAX
- };
- enum LightColor {
-
- COLOR_DIFFUSE=VisualServer::LIGHT_COLOR_DIFFUSE,
- COLOR_SPECULAR=VisualServer::LIGHT_COLOR_SPECULAR
- };
-
- enum BakeMode {
-
- BAKE_MODE_DISABLED,
- BAKE_MODE_INDIRECT,
- BAKE_MODE_INDIRECT_AND_SHADOWS,
- BAKE_MODE_FULL
-
- };
-
-
- enum Operator {
-
- OPERATOR_ADD,
- OPERATOR_SUB
- };
private:
-
- Ref<Texture> projector;
- float vars[PARAM_MAX];
- Color colors[3];
-
-
- BakeMode bake_mode;
- VisualServer::LightType type;
- bool shadows;
- bool enabled;
+ VS::LightType type;
bool editor_only;
- Operator op;
-
void _update_visibility();
// bind helpers
@@ -103,8 +58,7 @@ protected:
RID light;
virtual bool _can_gizmo_scale() const;
- virtual RES _get_gizmo_geometry() const;
-
+
static void _bind_methods();
void _notification(int p_what);
@@ -114,44 +68,17 @@ public:
VS::LightType get_light_type() const { return type; }
- void set_parameter(Parameter p_var, float p_value);
- float get_parameter(Parameter p_var) const;
-
- void set_color(LightColor p_color,const Color& p_value);
- Color get_color(LightColor p_color) const;
-
- void set_project_shadows(bool p_enabled);
- bool has_project_shadows() const;
-
- void set_projector(const Ref<Texture>& p_projector);
- Ref<Texture> get_projector() const;
-
- void set_operator(Operator p_op);
- Operator get_operator() const;
-
- void set_bake_mode(BakeMode p_bake_mode);
- BakeMode get_bake_mode() const;
-
- void set_enabled(bool p_enabled);
- bool is_enabled() const;
-
void set_editor_only(bool p_editor_only);
bool is_editor_only() const;
virtual AABB get_aabb() const;
virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const;
- void approximate_opengl_attenuation(float p_constant, float p_linear, float p_quadratic, float p_radius_treshold=0.5);
-
Light();
~Light();
};
-VARIANT_ENUM_CAST( Light::Parameter );
-VARIANT_ENUM_CAST( Light::LightColor );
-VARIANT_ENUM_CAST( Light::Operator );
-VARIANT_ENUM_CAST( Light::BakeMode);
class DirectionalLight : public Light {
@@ -160,39 +87,18 @@ class DirectionalLight : public Light {
public:
- enum ShadowMode {
- SHADOW_ORTHOGONAL,
- SHADOW_PERSPECTIVE,
- SHADOW_PARALLEL_2_SPLITS,
- SHADOW_PARALLEL_4_SPLITS
- };
- enum ShadowParam {
- SHADOW_PARAM_MAX_DISTANCE,
- SHADOW_PARAM_PSSM_SPLIT_WEIGHT,
- SHADOW_PARAM_PSSM_ZOFFSET_SCALE
- };
private:
- ShadowMode shadow_mode;
- float shadow_param[3];
+
+
protected:
static void _bind_methods();
public:
- void set_shadow_mode(ShadowMode p_mode);
- ShadowMode get_shadow_mode() const;
-
- void set_shadow_max_distance(float p_distance);
- float get_shadow_max_distance() const;
- void set_shadow_param(ShadowParam p_param, float p_value);
- float get_shadow_param(ShadowParam p_param) const;
DirectionalLight();
};
-VARIANT_ENUM_CAST( DirectionalLight::ShadowMode );
-VARIANT_ENUM_CAST( DirectionalLight::ShadowParam );
-
class OmniLight : public Light {
@@ -203,7 +109,7 @@ protected:
public:
- OmniLight() : Light( VisualServer::LIGHT_OMNI ) { set_parameter(PARAM_SHADOW_Z_OFFSET,0.001);}
+ OmniLight() : Light( VisualServer::LIGHT_OMNI ) { }
};
class SpotLight : public Light {
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp
index 3ac5d8ed7b..994e329853 100644
--- a/scene/3d/particles.cpp
+++ b/scene/3d/particles.cpp
@@ -30,6 +30,7 @@
#include "servers/visual_server.h"
#include "scene/resources/surface_tool.h"
+#if 0
/*
static const char* _var_names[Particles::VAR_MAX]={
"vars/lifetime",
@@ -557,3 +558,4 @@ Particles::~Particles() {
VisualServer::get_singleton()->free(particles);
}
+#endif
diff --git a/scene/3d/particles.h b/scene/3d/particles.h
index 42d27c41d7..fb3bb258ef 100644
--- a/scene/3d/particles.h
+++ b/scene/3d/particles.h
@@ -37,7 +37,7 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
+#if 0
class Particles : public GeometryInstance {
public:
@@ -163,3 +163,4 @@ public:
VARIANT_ENUM_CAST( Particles::Variable );
#endif
+#endif
diff --git a/scene/3d/portal.cpp b/scene/3d/portal.cpp
index 23bc64615d..131bbd7000 100644
--- a/scene/3d/portal.cpp
+++ b/scene/3d/portal.cpp
@@ -96,45 +96,6 @@ void Portal::_get_property_list( List<PropertyInfo> *p_list) const {
}
-RES Portal::_get_gizmo_geometry() const {
-
- Ref<SurfaceTool> surface_tool( memnew( SurfaceTool ));
-
- Ref<FixedMaterial> mat( memnew( FixedMaterial ));
-
- mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(1.0,0.8,0.8,0.7) );
- mat->set_line_width(4);
- mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- mat->set_flag(Material::FLAG_UNSHADED,true);
-// mat->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER,true);
-
- surface_tool->begin(Mesh::PRIMITIVE_LINES);
- surface_tool->set_material(mat);
-
- Vector<Point2> shape = get_shape();
-
- Vector2 center;
- for (int i=0;i<shape.size();i++) {
-
- int n=(i+1)%shape.size();
- Vector<Vector3> points;
- surface_tool->add_vertex( Vector3( shape[i].x, shape[i].y,0 ));
- surface_tool->add_vertex( Vector3( shape[n].x, shape[n].y,0 ));
- center+=shape[i];
-
- }
-
- if (shape.size()>0) {
-
- center/=shape.size();
- Vector<Vector3> points;
- surface_tool->add_vertex( Vector3( center.x, center.y,0 ));
- surface_tool->add_vertex( Vector3( center.x, center.y,1.0 ));
- }
-
- return surface_tool->commit();
-}
-
AABB Portal::get_aabb() const {
@@ -178,18 +139,19 @@ void Portal::set_shape(const Vector<Point2>& p_shape) {
VisualServer::get_singleton()->portal_set_shape(portal, p_shape);
+ shape=p_shape;
update_gizmo();
}
Vector<Point2> Portal::get_shape() const {
- return VisualServer::get_singleton()->portal_get_shape(portal);
+ return shape;
}
void Portal::set_connect_range(float p_range) {
connect_range=p_range;
- VisualServer::get_singleton()->portal_set_connect_range(portal,p_range);
+ //VisualServer::get_singleton()->portal_set_connect_range(portal,p_range);
}
float Portal::get_connect_range() const {
diff --git a/scene/3d/portal.h b/scene/3d/portal.h
index 149a56900f..8bcfa1ea4b 100644
--- a/scene/3d/portal.h
+++ b/scene/3d/portal.h
@@ -47,6 +47,7 @@ class Portal : public VisualInstance {
OBJ_TYPE(Portal, VisualInstance);
RID portal;
+ Vector<Point2> shape;
bool enabled;
float disable_distance;
@@ -55,7 +56,6 @@ class Portal : public VisualInstance {
AABB aabb;
- virtual RES _get_gizmo_geometry() const;
protected:
diff --git a/scene/3d/position_3d.cpp b/scene/3d/position_3d.cpp
index 27130cbe6a..de1a0b73f4 100644
--- a/scene/3d/position_3d.cpp
+++ b/scene/3d/position_3d.cpp
@@ -29,37 +29,6 @@
#include "position_3d.h"
#include "scene/resources/mesh.h"
-RES Position3D::_get_gizmo_geometry() const {
-
-
- Ref<Mesh> mesh = memnew( Mesh );
-
- DVector<Vector3> cursor_points;
- DVector<Color> cursor_colors;
- float cs = 0.25;
- cursor_points.push_back(Vector3(+cs,0,0));
- cursor_points.push_back(Vector3(-cs,0,0));
- cursor_points.push_back(Vector3(0,+cs,0));
- cursor_points.push_back(Vector3(0,-cs,0));
- cursor_points.push_back(Vector3(0,0,+cs));
- cursor_points.push_back(Vector3(0,0,-cs));
- cursor_colors.push_back(Color(1,0.5,0.5,1));
- cursor_colors.push_back(Color(1,0.5,0.5,1));
- cursor_colors.push_back(Color(0.5,1,0.5,1));
- cursor_colors.push_back(Color(0.5,1,0.5,1));
- cursor_colors.push_back(Color(0.5,0.5,1,1));
- cursor_colors.push_back(Color(0.5,0.5,1,1));
-
- Ref<FixedMaterial> mat = memnew( FixedMaterial );
- mat->set_flag(Material::FLAG_UNSHADED,true);
- mat->set_line_width(3);
- Array d;
- d[Mesh::ARRAY_VERTEX]=cursor_points;
- d[Mesh::ARRAY_COLOR]=cursor_colors;
- mesh->add_surface(Mesh::PRIMITIVE_LINES,d);
- mesh->surface_set_material(0,mat);
- return mesh;
-}
Position3D::Position3D()
{
diff --git a/scene/3d/position_3d.h b/scene/3d/position_3d.h
index 6bac540fcb..676f46c2ee 100644
--- a/scene/3d/position_3d.h
+++ b/scene/3d/position_3d.h
@@ -35,7 +35,6 @@ class Position3D : public Spatial {
OBJ_TYPE(Position3D,Spatial);
- virtual RES _get_gizmo_geometry() const;
public:
diff --git a/scene/3d/quad.cpp b/scene/3d/quad.cpp
index 1a7eeef180..f31d248ba7 100644
--- a/scene/3d/quad.cpp
+++ b/scene/3d/quad.cpp
@@ -120,7 +120,7 @@ void Quad::_update() {
} else {
configured=true;
}
- VS::get_singleton()->mesh_add_surface(mesh,VS::PRIMITIVE_TRIANGLES,arr);
+ VS::get_singleton()->mesh_add_surface_from_arrays(mesh,VS::PRIMITIVE_TRIANGLES,arr);
pending_update=false;
}
diff --git a/scene/3d/room_instance.cpp b/scene/3d/room_instance.cpp
index 9e6867d2a2..080fa880ba 100644
--- a/scene/3d/room_instance.cpp
+++ b/scene/3d/room_instance.cpp
@@ -75,50 +75,6 @@ void Room::_notification(int p_what) {
}
-RES Room::_get_gizmo_geometry() const {
-
- DVector<Face3> faces;
- if (!room.is_null())
- faces=room->get_geometry_hint();
-
- int count=faces.size();
- if (count==0)
- return RES();
-
- DVector<Face3>::Read facesr=faces.read();
-
- const Face3* facesptr=facesr.ptr();
-
- DVector<Vector3> points;
-
- Ref<SurfaceTool> surface_tool( memnew( SurfaceTool ));
-
- Ref<FixedMaterial> mat( memnew( FixedMaterial ));
-
- mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(0.2,0.8,0.9,0.3) );
- mat->set_line_width(4);
- mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- mat->set_flag(Material::FLAG_UNSHADED,true);
-// mat->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
-
- surface_tool->begin(Mesh::PRIMITIVE_LINES);
- surface_tool->set_material(mat);
-
- for (int i=0;i<count;i++) {
-
- surface_tool->add_vertex(facesptr[i].vertex[0]);
- surface_tool->add_vertex(facesptr[i].vertex[1]);
-
- surface_tool->add_vertex(facesptr[i].vertex[1]);
- surface_tool->add_vertex(facesptr[i].vertex[2]);
-
- surface_tool->add_vertex(facesptr[i].vertex[2]);
- surface_tool->add_vertex(facesptr[i].vertex[0]);
-
- }
-
- return surface_tool->commit();
-}
@@ -127,8 +83,9 @@ AABB Room::get_aabb() const {
if (room.is_null())
return AABB();
- return room->get_bounds().get_aabb();
+ return AABB();
}
+
DVector<Face3> Room::get_faces(uint32_t p_usage_flags) const {
return DVector<Face3>();
@@ -154,9 +111,6 @@ void Room::set_room( const Ref<RoomBounds>& p_room ) {
propagate_notification(NOTIFICATION_AREA_CHANGED);
update_gizmo();
- if (room.is_valid())
- SpatialSoundServer::get_singleton()->room_set_bounds(sound_room,room->get_bounds());
-
}
@@ -202,32 +156,6 @@ void Room::_parse_node_faces(DVector<Face3> &all_faces,const Node *p_node) const
}
-void Room::compute_room_from_subtree() {
-
-
- DVector<Face3> all_faces;
- _parse_node_faces(all_faces,this);
-
-
- if (all_faces.size()==0)
- return;
- float error;
- DVector<Face3> wrapped_faces = Geometry::wrap_geometry(all_faces,&error);
-
-
- if (wrapped_faces.size()==0)
- return;
-
- BSP_Tree tree(wrapped_faces,error);
-
- Ref<RoomBounds> room( memnew( RoomBounds ) );
- room->set_bounds(tree);
- room->set_geometry_hint(wrapped_faces);
-
- set_room(room);
-
-}
-
void Room::set_simulate_acoustics(bool p_enable) {
@@ -268,7 +196,6 @@ void Room::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_room","room:Room"),&Room::set_room );
ObjectTypeDB::bind_method(_MD("get_room:Room"),&Room::get_room );
- ObjectTypeDB::bind_method(_MD("compute_room_from_subtree"),&Room::compute_room_from_subtree);
diff --git a/scene/3d/room_instance.h b/scene/3d/room_instance.h
index c7df4ceadd..346e687d9e 100644
--- a/scene/3d/room_instance.h
+++ b/scene/3d/room_instance.h
@@ -45,6 +45,8 @@
*/
+
+
class Room : public VisualInstance {
OBJ_TYPE( Room, VisualInstance );
@@ -65,7 +67,7 @@ private:
void _bounds_changed();
- virtual RES _get_gizmo_geometry() const;
+
protected:
@@ -89,7 +91,6 @@ public:
void set_simulate_acoustics(bool p_enable);
bool is_simulating_acoustics() const;
- void compute_room_from_subtree();
RID get_sound_room() const;
diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp
index c996a8123c..96233c5ed7 100644
--- a/scene/3d/skeleton.cpp
+++ b/scene/3d/skeleton.cpp
@@ -163,7 +163,7 @@ void Skeleton::_notification(int p_what) {
Bone *bonesptr=&bones[0];
int len=bones.size();
- vs->skeleton_resize( skeleton, len ); // if same size, nothin really happens
+ vs->skeleton_allocate( skeleton, len ); // if same size, nothin really happens
// pose changed, rebuild cache of inverses
if (rest_global_inverse_dirty) {
@@ -513,51 +513,6 @@ void Skeleton::_make_dirty() {
}
-RES Skeleton::_get_gizmo_geometry() const {
-
- if (!GLOBAL_DEF("debug/draw_skeleton", true))
- return RES();
-
- if (bones.size()==0)
- return RES();
-
- Ref<SurfaceTool> surface_tool( memnew( SurfaceTool ));
-
- Ref<FixedMaterial> mat( memnew( FixedMaterial ));
-
- mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(0.6,1.0,0.3,0.1) );
- mat->set_line_width(4);
- mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- mat->set_flag(Material::FLAG_UNSHADED,true);
- mat->set_flag(Material::FLAG_ONTOP,true);
-// mat->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
-
- surface_tool->begin(Mesh::PRIMITIVE_LINES);
- surface_tool->set_material(mat);
-
-
- const Bone *bonesptr=&bones[0];
- int len=bones.size();
-
- for (int i=0;i<len;i++) {
-
- const Bone &b=bonesptr[i];
-
- Transform t;
- if (b.parent<0)
- continue;
-
- Vector3 v1=(bonesptr[b.parent].pose_global * bonesptr[b.parent].rest_global_inverse).xform(bonesptr[b.parent].rest_global_inverse.affine_inverse().origin);
- Vector3 v2=(b.pose_global * b.rest_global_inverse).xform(b.rest_global_inverse.affine_inverse().origin);
-
- surface_tool->add_vertex(v1);
- surface_tool->add_vertex(v2);
-
- }
-
- return surface_tool->commit();
-
-}
void Skeleton::localize_rests() {
diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h
index bfdb1d1499..1b8136b06c 100644
--- a/scene/3d/skeleton.h
+++ b/scene/3d/skeleton.h
@@ -84,7 +84,6 @@ class Skeleton : public Spatial {
return bound;
}
- virtual RES _get_gizmo_geometry() const;
protected:
diff --git a/scene/3d/spatial_player.cpp b/scene/3d/spatial_player.cpp
index c7cf03e284..70370c51e7 100644
--- a/scene/3d/spatial_player.cpp
+++ b/scene/3d/spatial_player.cpp
@@ -88,146 +88,6 @@ bool SpatialPlayer::_can_gizmo_scale() const {
return false;
}
-RES SpatialPlayer::_get_gizmo_geometry() const {
-
- Ref<SurfaceTool> surface_tool( memnew( SurfaceTool ));
-
- Ref<FixedMaterial> mat( memnew( FixedMaterial ));
-
- mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(0.0,0.6,0.7,0.05) );
- mat->set_parameter( FixedMaterial::PARAM_EMISSION,Color(0.5,0.7,0.8) );
- mat->set_blend_mode( Material::BLEND_MODE_ADD );
- mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
-// mat->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
-
-
- surface_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
- surface_tool->set_material(mat);
-
- int sides=16;
- int sections=24;
-
-// float len=1;
- float deg=Math::deg2rad(params[PARAM_EMISSION_CONE_DEGREES]);
- if (deg==180)
- deg=179.5;
-
- Vector3 to=Vector3(0,0,-1);
-
- for(int j=0;j<sections;j++) {
-
- Vector3 p1=Matrix3(Vector3(1,0,0),deg*j/sections).xform(to);
- Vector3 p2=Matrix3(Vector3(1,0,0),deg*(j+1)/sections).xform(to);
-
- for(int i=0;i<sides;i++) {
-
- Vector3 p1r = Matrix3(Vector3(0,0,1),Math_PI*2*float(i)/sides).xform(p1);
- Vector3 p1s = Matrix3(Vector3(0,0,1),Math_PI*2*float(i+1)/sides).xform(p1);
- Vector3 p2s = Matrix3(Vector3(0,0,1),Math_PI*2*float(i+1)/sides).xform(p2);
- Vector3 p2r = Matrix3(Vector3(0,0,1),Math_PI*2*float(i)/sides).xform(p2);
-
- surface_tool->add_normal(p1r.normalized());
- surface_tool->add_vertex(p1r);
- surface_tool->add_normal(p1s.normalized());
- surface_tool->add_vertex(p1s);
- surface_tool->add_normal(p2s.normalized());
- surface_tool->add_vertex(p2s);
-
- surface_tool->add_normal(p1r.normalized());
- surface_tool->add_vertex(p1r);
- surface_tool->add_normal(p2s.normalized());
- surface_tool->add_vertex(p2s);
- surface_tool->add_normal(p2r.normalized());
- surface_tool->add_vertex(p2r);
-
- if (j==sections-1) {
-
- surface_tool->add_normal(p2r.normalized());
- surface_tool->add_vertex(p2r);
- surface_tool->add_normal(p2s.normalized());
- surface_tool->add_vertex(p2s);
- surface_tool->add_normal(Vector3(0,0,1));
- surface_tool->add_vertex(Vector3());
- }
- }
- }
-
-
- Ref<Mesh> mesh = surface_tool->commit();
-
- Ref<FixedMaterial> mat_speaker( memnew( FixedMaterial ));
-
- mat_speaker->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(0.3,0.3,0.6) );
- mat_speaker->set_parameter( FixedMaterial::PARAM_SPECULAR,Color(0.5,0.5,0.6) );
- //mat_speaker->set_blend_mode( Material::BLEND_MODE_MIX);
- //mat_speaker->set_flag(Material::FLAG_DOUBLE_SIDED,false);
- //mat_speaker->set_flag(Material::FLAG_UNSHADED,true);
-
- surface_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
- surface_tool->set_material(mat_speaker);
-
-// float radius=1;
-
-
- const int speaker_points=8;
- Vector3 speaker[speaker_points]={
- Vector3(0,0,1)*0.15,
- Vector3(1,1,1)*0.15,
- Vector3(1,1,0)*0.15,
- Vector3(2,2,-1)*0.15,
- Vector3(1,1,-1)*0.15,
- Vector3(0.8,0.8,-1.2)*0.15,
- Vector3(0.5,0.5,-1.4)*0.15,
- Vector3(0.0,0.0,-1.6)*0.15
- };
-
- int speaker_sides=10;
-
-
- for(int i = 0; i < speaker_sides ; i++) {
-
-
- Matrix3 ma(Vector3(0,0,1),Math_PI*2*float(i)/speaker_sides);
- Matrix3 mb(Vector3(0,0,1),Math_PI*2*float(i+1)/speaker_sides);
-
-
- for(int j=0;j<speaker_points-1;j++) {
-
- Vector3 points[4]={
- ma.xform(speaker[j]),
- mb.xform(speaker[j]),
- mb.xform(speaker[j+1]),
- ma.xform(speaker[j+1]),
- };
-
- Vector3 n = -Plane(points[0],points[1],points[2]).normal;
-
- surface_tool->add_normal(n);
- surface_tool->add_vertex(points[0]);
- surface_tool->add_normal(n);
- surface_tool->add_vertex(points[2]);
- surface_tool->add_normal(n);
- surface_tool->add_vertex(points[1]);
-
- surface_tool->add_normal(n);
- surface_tool->add_vertex(points[0]);
- surface_tool->add_normal(n);
- surface_tool->add_vertex(points[3]);
- surface_tool->add_normal(n);
- surface_tool->add_vertex(points[2]);
-
-
- }
-
-
- }
-
-
- return surface_tool->commit(mesh);
-
-}
-
-
void SpatialPlayer::_bind_methods() {
diff --git a/scene/3d/spatial_player.h b/scene/3d/spatial_player.h
index 5a8687b854..594fc8f850 100644
--- a/scene/3d/spatial_player.h
+++ b/scene/3d/spatial_player.h
@@ -60,7 +60,7 @@ private:
RID source_rid;
virtual bool _can_gizmo_scale() const;
- virtual RES _get_gizmo_geometry() const;
+
protected:
diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp
index b4f7a4e5b4..5bc332f8fb 100644
--- a/scene/3d/visual_instance.cpp
+++ b/scene/3d/visual_instance.cpp
@@ -52,7 +52,7 @@ void VisualInstance::_notification(int p_what) {
Room *room=NULL;
bool is_geom = cast_to<GeometryInstance>();
- while(parent) {
+ /* while(parent) {
room = parent->cast_to<Room>();
if (room)
@@ -64,7 +64,7 @@ void VisualInstance::_notification(int p_what) {
}
parent=parent->get_parent_spatial();
- }
+ }*/
@@ -92,7 +92,7 @@ void VisualInstance::_notification(int p_what) {
VisualServer::get_singleton()->instance_set_scenario( instance, RID() );
VisualServer::get_singleton()->instance_set_room(instance,RID());
VisualServer::get_singleton()->instance_attach_skeleton( instance, RID() );
- VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
+ // VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
} break;
@@ -172,30 +172,55 @@ Ref<Material> GeometryInstance::get_material_override() const{
-void GeometryInstance::set_draw_range_begin(float p_dist){
+void GeometryInstance::set_lod_min_distance(float p_dist){
+
+ lod_min_distance=p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
+}
+
+float GeometryInstance::get_lod_min_distance() const{
+
+ return lod_min_distance;
+}
+
+
+void GeometryInstance::set_lod_max_distance(float p_dist) {
+
+ lod_max_distance=p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
- draw_begin=p_dist;
- VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),draw_begin,draw_end);
}
-float GeometryInstance::get_draw_range_begin() const{
+float GeometryInstance::get_lod_max_distance() const {
- return draw_begin;
+ return lod_max_distance;
}
+void GeometryInstance::set_lod_min_hysteresis(float p_dist){
-void GeometryInstance::set_draw_range_end(float p_dist) {
+ lod_min_hysteresis=p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
+}
- draw_end=p_dist;
- VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),draw_begin,draw_end);
+float GeometryInstance::get_lod_min_hysteresis() const{
+ return lod_min_hysteresis;
}
-float GeometryInstance::get_draw_range_end() const {
- return draw_end;
+void GeometryInstance::set_lod_max_hysteresis(float p_dist) {
+
+ lod_max_hysteresis=p_dist;
+ VS::get_singleton()->instance_geometry_set_draw_range(get_instance(),lod_min_distance,lod_max_distance,lod_min_hysteresis,lod_max_hysteresis);
+
}
+float GeometryInstance::get_lod_max_hysteresis() const {
+
+ return lod_max_hysteresis;
+}
+
+
void GeometryInstance::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_WORLD) {
@@ -212,8 +237,8 @@ void GeometryInstance::_notification(int p_what) {
if (flags[FLAG_USE_BAKED_LIGHT]) {
if (baked_light_instance) {
- baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
- baked_light_instance=NULL;
+ // baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ // baked_light_instance=NULL;
}
_baked_light_changed();
@@ -229,15 +254,15 @@ void GeometryInstance::_notification(int p_what) {
void GeometryInstance::_baked_light_changed() {
- if (!baked_light_instance)
- VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID());
- else
- VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance());
+ //if (!baked_light_instance)
+ // VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID());
+// else
+// VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance());
}
void GeometryInstance::_find_baked_light() {
-
+/*
Node *n=get_parent();
while(n) {
@@ -255,6 +280,7 @@ void GeometryInstance::_find_baked_light() {
}
_baked_light_changed();
+ */
}
void GeometryInstance::_update_visibility() {
@@ -288,7 +314,7 @@ void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
}
if (p_flag==FLAG_USE_BAKED_LIGHT) {
- if (is_inside_world()) {
+ /* if (is_inside_world()) {
if (!p_value) {
if (baked_light_instance) {
baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
@@ -298,7 +324,7 @@ void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
} else {
_find_baked_light();
}
- }
+ }*/
}
}
@@ -333,8 +359,8 @@ GeometryInstance::ShadowCastingSetting GeometryInstance::get_cast_shadows_settin
void GeometryInstance::set_baked_light_texture_id(int p_id) {
- baked_light_texture_id=p_id;
- VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),baked_light_texture_id);
+// baked_light_texture_id=p_id;
+// VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),baked_light_texture_id);
}
@@ -366,11 +392,18 @@ void GeometryInstance::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance::set_cast_shadows_setting);
ObjectTypeDB::bind_method(_MD("get_cast_shadows_setting"), &GeometryInstance::get_cast_shadows_setting);
- ObjectTypeDB::bind_method(_MD("set_draw_range_begin","mode"), &GeometryInstance::set_draw_range_begin);
- ObjectTypeDB::bind_method(_MD("get_draw_range_begin"), &GeometryInstance::get_draw_range_begin);
+ ObjectTypeDB::bind_method(_MD("set_lod_max_hysteresis","mode"), &GeometryInstance::set_lod_max_hysteresis);
+ ObjectTypeDB::bind_method(_MD("get_lod_max_hysteresis"), &GeometryInstance::get_lod_max_hysteresis);
+
+ ObjectTypeDB::bind_method(_MD("set_lod_max_distance","mode"), &GeometryInstance::set_lod_max_distance);
+ ObjectTypeDB::bind_method(_MD("get_lod_max_distance"), &GeometryInstance::get_lod_max_distance);
+
+ ObjectTypeDB::bind_method(_MD("set_lod_min_hysteresis","mode"), &GeometryInstance::set_lod_min_hysteresis);
+ ObjectTypeDB::bind_method(_MD("get_lod_min_hysteresis"), &GeometryInstance::get_lod_min_hysteresis);
+
+ ObjectTypeDB::bind_method(_MD("set_lod_min_distance","mode"), &GeometryInstance::set_lod_min_distance);
+ ObjectTypeDB::bind_method(_MD("get_lod_min_distance"), &GeometryInstance::get_lod_min_distance);
- ObjectTypeDB::bind_method(_MD("set_draw_range_end","mode"), &GeometryInstance::set_draw_range_end);
- ObjectTypeDB::bind_method(_MD("get_draw_range_end"), &GeometryInstance::get_draw_range_end);
ObjectTypeDB::bind_method(_MD("set_baked_light_texture_id","id"), &GeometryInstance::set_baked_light_texture_id);
ObjectTypeDB::bind_method(_MD("get_baked_light_texture_id"), &GeometryInstance::get_baked_light_texture_id);
@@ -385,9 +418,6 @@ void GeometryInstance::_bind_methods() {
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/visible"), _SCS("set_flag"), _SCS("get_flag"),FLAG_VISIBLE);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "geometry/material_override",PROPERTY_HINT_RESOURCE_TYPE,"Material"), _SCS("set_material_override"), _SCS("get_material_override"));
ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry/cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), _SCS("set_cast_shadows_setting"), _SCS("get_cast_shadows_setting"));
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/receive_shadows"), _SCS("set_flag"), _SCS("get_flag"),FLAG_RECEIVE_SHADOWS);
- ADD_PROPERTY( PropertyInfo( Variant::INT, "geometry/range_begin",PROPERTY_HINT_RANGE,"0,32768,0.01"), _SCS("set_draw_range_begin"), _SCS("get_draw_range_begin"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "geometry/range_end",PROPERTY_HINT_RANGE,"0,32768,0.01"), _SCS("set_draw_range_end"), _SCS("get_draw_range_end"));
ADD_PROPERTY( PropertyInfo( Variant::REAL, "geometry/extra_cull_margin",PROPERTY_HINT_RANGE,"0,16384,0"), _SCS("set_extra_cull_margin"), _SCS("get_extra_cull_margin"));
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/billboard"), _SCS("set_flag"), _SCS("get_flag"),FLAG_BILLBOARD);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/billboard_y"), _SCS("set_flag"), _SCS("get_flag"),FLAG_BILLBOARD_FIX_Y);
@@ -395,12 +425,15 @@ void GeometryInstance::_bind_methods() {
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/visible_in_all_rooms"), _SCS("set_flag"), _SCS("get_flag"),FLAG_VISIBLE_IN_ALL_ROOMS);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/use_baked_light"), _SCS("set_flag"), _SCS("get_flag"),FLAG_USE_BAKED_LIGHT);
ADD_PROPERTY( PropertyInfo( Variant::INT, "geometry/baked_light_tex_id"), _SCS("set_baked_light_texture_id"), _SCS("get_baked_light_texture_id"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "lod/min_distance",PROPERTY_HINT_RANGE,"0,32768,0.01"), _SCS("set_lod_min_distance"), _SCS("get_lod_min_distance"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "lod/min_hysteresis",PROPERTY_HINT_RANGE,"0,32768,0.01"), _SCS("set_lod_min_hysteresis"), _SCS("get_lod_min_hysteresis"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "lod/max_distance",PROPERTY_HINT_RANGE,"0,32768,0.01"), _SCS("set_lod_max_distance"), _SCS("get_lod_max_distance"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "lod/max_hysteresis",PROPERTY_HINT_RANGE,"0,32768,0.01"), _SCS("set_lod_max_hysteresis"), _SCS("get_lod_max_hysteresis"));
// ADD_SIGNAL( MethodInfo("visibility_changed"));
BIND_CONSTANT(FLAG_VISIBLE );
BIND_CONSTANT(FLAG_CAST_SHADOW );
- BIND_CONSTANT(FLAG_RECEIVE_SHADOWS );
BIND_CONSTANT(FLAG_BILLBOARD );
BIND_CONSTANT(FLAG_BILLBOARD_FIX_Y );
BIND_CONSTANT(FLAG_DEPH_SCALE );
@@ -415,20 +448,23 @@ void GeometryInstance::_bind_methods() {
}
GeometryInstance::GeometryInstance() {
- draw_begin=0;
- draw_end=0;
+ lod_min_distance=0;
+ lod_max_distance=0;
+ lod_min_hysteresis=0;
+ lod_max_hysteresis=0;
+
for(int i=0;i<FLAG_MAX;i++) {
flags[i]=false;
}
flags[FLAG_VISIBLE]=true;
flags[FLAG_CAST_SHADOW]=true;
- flags[FLAG_RECEIVE_SHADOWS]=true;
+
shadow_casting_setting=SHADOW_CASTING_SETTING_ON;
baked_light_instance=NULL;
baked_light_texture_id=0;
extra_cull_margin=0;
- VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0);
+// VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0);
}
diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h
index e286d5fa88..eb0587815f 100644
--- a/scene/3d/visual_instance.h
+++ b/scene/3d/visual_instance.h
@@ -89,7 +89,6 @@ public:
enum Flags {
FLAG_VISIBLE=VS::INSTANCE_FLAG_VISIBLE,
FLAG_CAST_SHADOW=VS::INSTANCE_FLAG_CAST_SHADOW,
- FLAG_RECEIVE_SHADOWS=VS::INSTANCE_FLAG_RECEIVE_SHADOWS,
FLAG_BILLBOARD=VS::INSTANCE_FLAG_BILLBOARD,
FLAG_BILLBOARD_FIX_Y=VS::INSTANCE_FLAG_BILLBOARD_FIX_Y,
FLAG_DEPH_SCALE=VS::INSTANCE_FLAG_DEPH_SCALE,
@@ -110,8 +109,10 @@ private:
bool flags[FLAG_MAX];
ShadowCastingSetting shadow_casting_setting;
Ref<Material> material_override;
- float draw_begin;
- float draw_end;
+ float lod_min_distance;
+ float lod_max_distance;
+ float lod_min_hysteresis;
+ float lod_max_hysteresis;
void _find_baked_light();
BakedLightInstance *baked_light_instance;
int baked_light_texture_id;
@@ -131,11 +132,17 @@ public:
void set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
ShadowCastingSetting get_cast_shadows_setting() const;
- void set_draw_range_begin(float p_dist);
- float get_draw_range_begin() const;
+ void set_lod_min_distance(float p_dist);
+ float get_lod_min_distance() const;
- void set_draw_range_end(float p_dist);
- float get_draw_range_end() const;
+ void set_lod_max_distance(float p_dist);
+ float get_lod_max_distance() const;
+
+ void set_lod_min_hysteresis(float p_dist);
+ float get_lod_min_hysteresis() const;
+
+ void set_lod_max_hysteresis(float p_dist);
+ float get_lod_max_hysteresis() const;
void set_material_override(const Ref<Material>& p_material);
Ref<Material> get_material_override() const;
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 5e66544153..27bdb581e1 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -59,6 +59,10 @@ void ColorPicker::_notification(int p_what) {
w_material->set_shader(get_shader("w_editor"));
update_material(uv_material,color,h,s,v);
update_material(w_material,color,h,s,v);
+ uv_edit->set_texture(get_icon("color_main"));
+ w_edit->set_texture(get_icon("color_hue"));
+ sample->set_texture(get_icon("color_sample"));
+
_update_controls();
} break;
@@ -192,10 +196,24 @@ void ColorPicker::_update_presets()
{
Size2 size=bt_add_preset->get_size();
preset->set_custom_minimum_size(Size2(size.width*presets.size(),size.height));
- Image i(size.x*presets.size(),size.y, false, Image::FORMAT_RGB);
- for (int y=0;y<size.y;y++)
- for (int x=0;x<size.x*presets.size();x++)
- i.put_pixel(x,y,presets[(int)x/size.x]);
+
+ DVector<uint8_t> img;
+ img.resize(size.x*presets.size()*size.y*3);
+
+ {
+ DVector<uint8_t>::Write w=img.write();
+ for (int y=0;y<size.y;y++) {
+ for (int x=0;x<size.x*presets.size();x++) {
+ int ofs = (y*(size.x*presets.size())+x)*3;
+ w[ofs+0]=uint8_t(CLAMP(presets[(int)x/size.x].r*255.0,0,255));
+ w[ofs+1]=uint8_t(CLAMP(presets[(int)x/size.x].g*255.0,0,255));
+ w[ofs+2]=uint8_t(CLAMP(presets[(int)x/size.x].b*255.0,0,255));
+ }
+ }
+ }
+
+ Image i(size.x*presets.size(),size.y, false, Image::FORMAT_RGB8,img);
+
Ref<ImageTexture> t;
t.instance();
t->create_from_image(i);
@@ -394,15 +412,23 @@ void ColorPicker::_screen_input(const InputEvent &ev)
} else if (ev.type==InputEvent::MOUSE_MOTION) {
const InputEventMouse &mev = ev.mouse_motion;
Viewport *r=get_tree()->get_root();
- if (!r->get_rect().has_point(Point2(mev.global_x,mev.global_y)))
+ if (!r->get_visible_rect().has_point(Point2(mev.global_x,mev.global_y)))
return;
Image img =r->get_screen_capture();
if (!img.empty()) {
last_capture=img;
r->queue_screen_capture();
}
- if (!last_capture.empty())
- set_color(last_capture.get_pixel(mev.global_x,mev.global_y));
+ if (!last_capture.empty()) {
+ int pw = last_capture.get_format()==Image::FORMAT_RGBA8?4:3;
+ int ofs = (mev.global_y*last_capture.get_width()+mev.global_x)*pw;
+
+ DVector<uint8_t>::Read r = last_capture.get_data().read();
+
+ Color c( r[ofs+0]/255.0, r[ofs+1]/255.0, r[ofs+2]/255.0 );
+
+ set_color(c);
+ }
}
}
@@ -474,16 +500,10 @@ ColorPicker::ColorPicker() :
HBoxContainer *hb_edit = memnew( HBoxContainer );
uv_edit= memnew ( TextureFrame );
- Image i(256, 256, false, Image::FORMAT_RGB);
- for (int y=0;y<256;y++)
- for (int x=0;x<256;x++)
- i.put_pixel(x,y,Color());
- Ref<ImageTexture> t;
- t.instance();
- t->create_from_image(i);
- uv_edit->set_texture(t);
+
+
+
uv_edit->set_ignore_mouse(false);
- uv_edit->set_custom_minimum_size(Size2(256,256));
uv_edit->connect("input_event", this, "_uv_input");
Control *c= memnew( Control );
uv_edit->add_child(c);
@@ -497,16 +517,9 @@ ColorPicker::ColorPicker() :
add_child(hb_edit);
w_edit= memnew( TextureFrame );
- i = Image(15, 256, false, Image::FORMAT_RGB);
- for (int y=0;y<256;y++)
- for (int x=0;x<15;x++)
- i.put_pixel(x,y,Color());
- Ref<ImageTexture> tw;
- tw.instance();
- tw->create_from_image(i);
- w_edit->set_texture(tw);
- w_edit->set_ignore_mouse(false);
- w_edit->set_custom_minimum_size(Size2(15,256));
+
+
+ w_edit->set_ignore_mouse(false);
w_edit->connect("input_event", this, "_w_input");
c= memnew( Control );
w_edit->add_child(c);
@@ -594,17 +607,6 @@ ColorPicker::ColorPicker() :
set_color(Color(1,1,1));
- i.create(256,20,false,Image::FORMAT_RGB);
- for (int y=0;y<20;y++)
- for(int x=0;x<256;x++)
- if ((x/4+y/4)%2)
- i.put_pixel(x,y,Color(1,1,1));
- else
- i.put_pixel(x,y,Color(0.6,0.6,0.6));
- Ref<ImageTexture> t_smpl;
- t_smpl.instance();
- t_smpl->create_from_image(i);
- sample->set_texture(t_smpl);
HBoxContainer *bbc = memnew( HBoxContainer );
add_child(bbc);
diff --git a/scene/gui/patch_9_frame.cpp b/scene/gui/patch_9_frame.cpp
index 9ad6398359..ed1abbadee 100644
--- a/scene/gui/patch_9_frame.cpp
+++ b/scene/gui/patch_9_frame.cpp
@@ -39,7 +39,7 @@ void Patch9Frame::_notification(int p_what) {
Size2 s=get_size();
RID ci = get_canvas_item();
- VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate);
+ VS::get_singleton()->canvas_item_add_nine_patch(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),VS::NINE_PATCH_STRETCH,VS::NINE_PATCH_STRETCH,draw_center,modulate);
// draw_texture_rect(texture,Rect2(Point2(),s),false,modulate);
/*
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index 8e238c7d77..9ee0cf9349 100644
--- a/scene/main/canvas_layer.cpp
+++ b/scene/main/canvas_layer.cpp
@@ -246,6 +246,15 @@ Node* CanvasLayer::get_custom_viewport() const {
return custom_viewport;
}
+void CanvasLayer::reset_sort_index() {
+ sort_index=0;
+}
+
+int CanvasLayer::get_sort_index() {
+
+ return sort_index++;
+}
+
void CanvasLayer::_bind_methods() {
@@ -296,4 +305,5 @@ CanvasLayer::CanvasLayer() {
canvas = Ref<World2D>( memnew(World2D) );
custom_viewport=NULL;
custom_viewport_id=0;
+ sort_index=0;
}
diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h
index a1311390be..bb63c96cdf 100644
--- a/scene/main/canvas_layer.h
+++ b/scene/main/canvas_layer.h
@@ -52,6 +52,8 @@ class CanvasLayer : public Node {
RID viewport;
Viewport *vp;
+ int sort_index;
+
// Deprecated, should be removed in a future version.
void _set_rotationd(real_t p_rotation);
real_t _get_rotationd() const;
@@ -93,6 +95,9 @@ public:
void set_custom_viewport(Node *p_viewport);
Node* get_custom_viewport() const;
+ void reset_sort_index();
+ int get_sort_index();
+
CanvasLayer();
};
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 1892240426..5d4e46f9ac 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -315,6 +315,12 @@ void Node::move_child(Node *p_child,int p_pos) {
}
+ if (p_child->data.pos==p_pos)
+ return; //do nothing
+
+ int motion_from = MIN(p_pos,p_child->data.pos);
+ int motion_to = MAX(p_pos,p_child->data.pos);
+
data.children.remove( p_child->data.pos );
data.children.insert( p_pos, p_child );
@@ -324,13 +330,13 @@ void Node::move_child(Node *p_child,int p_pos) {
data.blocked++;
//new pos first
- for (int i=0;i<data.children.size();i++) {
+ for (int i=motion_from;i<=motion_to;i++) {
data.children[i]->data.pos=i;
}
// notification second
move_child_notify(p_child);
- for (int i=0;i<data.children.size();i++) {
+ for (int i=motion_from;i<=motion_to;i++) {
data.children[i]->notification( NOTIFICATION_MOVED_IN_PARENT );
}
diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp
index e3472c074a..c1552a4167 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -746,11 +746,11 @@ Ref<Material> SceneTree::get_debug_navigation_material() {
return navigation_material;
Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial ));
- line_material->set_flag(Material::FLAG_UNSHADED, true);
+/* line_material->set_flag(Material::FLAG_UNSHADED, true);
line_material->set_line_width(3.0);
line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true);
line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true);
- line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_color());
+ line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_color());*/
navigation_material=line_material;
@@ -764,11 +764,11 @@ Ref<Material> SceneTree::get_debug_navigation_disabled_material(){
return navigation_disabled_material;
Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial ));
- line_material->set_flag(Material::FLAG_UNSHADED, true);
+/* line_material->set_flag(Material::FLAG_UNSHADED, true);
line_material->set_line_width(3.0);
line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true);
line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true);
- line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_disabled_color());
+ line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_disabled_color());*/
navigation_disabled_material=line_material;
@@ -782,11 +782,11 @@ Ref<Material> SceneTree::get_debug_collision_material() {
Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial ));
- line_material->set_flag(Material::FLAG_UNSHADED, true);
+ /*line_material->set_flag(Material::FLAG_UNSHADED, true);
line_material->set_line_width(3.0);
line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true);
line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true);
- line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collisions_color());
+ line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collisions_color());*/
collision_material=line_material;
@@ -801,10 +801,10 @@ Ref<Mesh> SceneTree::get_debug_contact_mesh() {
debug_contact_mesh = Ref<Mesh>( memnew( Mesh ) );
Ref<FixedMaterial> mat = memnew( FixedMaterial );
- mat->set_flag(Material::FLAG_UNSHADED,true);
+ /*mat->set_flag(Material::FLAG_UNSHADED,true);
mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
- mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collision_contact_color());
+ mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collision_contact_color());*/
Vector3 diamond[6]={
Vector3(-1, 0, 0),
@@ -1098,7 +1098,11 @@ void SceneTree::_update_root_rect() {
if (stretch_mode==STRETCH_MODE_DISABLED) {
- root->set_rect(Rect2(Point2(),last_screen_size));
+
+ root->set_size(last_screen_size);
+ root->set_attach_to_screen_rect(Rect2(Point2(),last_screen_size));
+ root->set_size_override_stretch(false);
+ root->set_size_override(false,Size2());
return; //user will take care
}
@@ -1174,21 +1178,18 @@ void SceneTree::_update_root_rect() {
switch (stretch_mode) {
case STRETCH_MODE_2D: {
-// root->set_rect(Rect2(Point2(),video_mode));
- root->set_as_render_target(false);
- root->set_rect(Rect2(margin,screen_size));
+ root->set_size(screen_size);
+ root->set_attach_to_screen_rect(Rect2(margin,screen_size));
root->set_size_override_stretch(true);
root->set_size_override(true,viewport_size);
} break;
case STRETCH_MODE_VIEWPORT: {
- root->set_rect(Rect2(Point2(),viewport_size));
+ root->set_size(viewport_size);
+ root->set_attach_to_screen_rect(Rect2(margin,screen_size));
root->set_size_override_stretch(false);
root->set_size_override(false,Size2());
- root->set_as_render_target(true);
- root->set_render_target_update_mode(Viewport::RENDER_TARGET_UPDATE_ALWAYS);
- root->set_render_target_to_screen_rect(Rect2(margin,screen_size));
} break;
@@ -2300,7 +2301,7 @@ SceneTree::SceneTree() {
stretch_aspect=STRETCH_ASPECT_IGNORE;
last_screen_size=Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height );
- root->set_rect(Rect2(Point2(),last_screen_size));
+ root->set_size(last_screen_size);
if (ScriptDebugger::get_singleton()) {
ScriptDebugger::get_singleton()->set_request_scene_tree_message_func(_debugger_request_tree,this);
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index b22d1fcdf4..44a3f41a4a 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -54,22 +54,22 @@
int RenderTargetTexture::get_width() const {
ERR_FAIL_COND_V(!vp,0);
- return vp->rect.size.width;
+ return vp->size.width;
}
int RenderTargetTexture::get_height() const{
ERR_FAIL_COND_V(!vp,0);
- return vp->rect.size.height;
+ return vp->size.height;
}
Size2 RenderTargetTexture::get_size() const{
ERR_FAIL_COND_V(!vp,Size2());
- return vp->rect.size;
+ return vp->size;
}
RID RenderTargetTexture::get_rid() const{
ERR_FAIL_COND_V(!vp,RID());
- return vp->render_target_texture_rid;
+ return vp->texture_rid;
}
bool RenderTargetTexture::has_alpha() const{
@@ -85,7 +85,7 @@ void RenderTargetTexture::set_flags(uint32_t p_flags){
else
flags=0;
- VS::get_singleton()->texture_set_flags(vp->render_target_texture_rid,flags);
+ VS::get_singleton()->texture_set_flags(vp->texture_rid,flags);
}
@@ -141,9 +141,9 @@ void Viewport::_update_stretch_transform() {
if (size_override_stretch && size_override) {
//print_line("sive override size "+size_override_size);
- //print_line("rect size "+rect.size);
+ //print_line("rect size "+size);
stretch_transform=Matrix32();
- Size2 scale = rect.size/(size_override_size+size_override_margin*2);
+ Size2 scale = size/(size_override_size+size_override_margin*2);
stretch_transform.scale(scale);
stretch_transform.elements[2]=size_override_margin*scale;
@@ -164,14 +164,14 @@ void Viewport::_update_rect() {
return;
- if (!render_target && parent_control) {
+ /*if (!render_target && parent_control) {
Control *c = parent_control;
rect.pos=Point2();
rect.size=c->get_size();
- }
-
+ }*/
+/*
VisualServer::ViewportRect vr;
vr.x=rect.pos.x;
vr.y=rect.pos.y;
@@ -191,8 +191,8 @@ void Viewport::_update_rect() {
}
emit_signal("size_changed");
- render_target_texture->emit_changed();
-
+ texture->emit_changed();
+*/
}
@@ -232,12 +232,12 @@ void Viewport::_vp_enter_tree() {
VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent_ci);
VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false);
- VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport);
+// VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport);
parent_control->connect("resized",this,"_parent_resized");
parent_control->connect("visibility_changed",this,"_parent_visibility_changed");
} else if (!parent){
- VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0);
+// VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0);
}
@@ -246,6 +246,7 @@ void Viewport::_vp_enter_tree() {
void Viewport::_vp_exit_tree() {
+ /*
if (parent_control) {
parent_control->disconnect("resized",this,"_parent_resized");
@@ -268,7 +269,7 @@ void Viewport::_vp_exit_tree() {
VisualServer::get_singleton()->viewport_detach(viewport);
}
-
+*/
}
@@ -346,11 +347,6 @@ void Viewport::_notification(int p_what) {
parent_node=parent_node->get_parent();
}
-
- if (!render_target)
- _vp_enter_tree();
-
-
current_canvas=find_world_2d()->get_canvas();
VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario());
VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas);
@@ -370,7 +366,7 @@ void Viewport::_notification(int p_what) {
//3D
PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(),get_tree()->get_collision_debug_contact_count());
contact_3d_debug_multimesh=VisualServer::get_singleton()->multimesh_create();
- VisualServer::get_singleton()->multimesh_set_instance_count(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count());
+ VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count(),VS::MULTIMESH_TRANSFORM_3D,VS::MULTIMESH_COLOR_8BIT);
VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,0);
VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh,get_tree()->get_debug_contact_mesh()->get_rid());
contact_3d_debug_instance=VisualServer::get_singleton()->instance_create();
@@ -380,6 +376,7 @@ void Viewport::_notification(int p_what) {
}
+ VS::get_singleton()->viewport_set_active(viewport,true);
} break;
case NOTIFICATION_READY: {
#ifndef _3D_DISABLED
@@ -418,8 +415,8 @@ void Viewport::_notification(int p_what) {
if (world_2d.is_valid())
world_2d->_remove_viewport(this);
- if (!render_target)
- _vp_exit_tree();
+ //if (!render_target)
+ // _vp_exit_tree();
VisualServer::get_singleton()->viewport_set_scenario(viewport,RID());
SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID());
@@ -439,6 +436,9 @@ void Viewport::_notification(int p_what) {
remove_from_group("_viewports");
parent_control=NULL;
+ VS::get_singleton()->viewport_set_active(viewport,false);
+
+
} break;
case NOTIFICATION_FIXED_PROCESS: {
@@ -452,7 +452,7 @@ void Viewport::_notification(int p_what) {
if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
VisualServer::get_singleton()->canvas_item_clear(contact_2d_debug);
- VisualServer::get_singleton()->canvas_item_raise(contact_2d_debug);
+ VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug,0xFFFFF); //very high index
Vector<Vector2> points = Physics2DServer::get_singleton()->space_get_contacts(find_world_2d()->get_space());
int point_count = Physics2DServer::get_singleton()->space_get_contact_count(find_world_2d()->get_space());
@@ -488,13 +488,13 @@ void Viewport::_notification(int p_what) {
VisualServer::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh,i,t);
}
aabb.grow(aabb.get_longest_axis_size()*0.01);
- VisualServer::get_singleton()->multimesh_set_aabb(contact_3d_debug_multimesh,aabb);
+ VisualServer::get_singleton()->multimesh_set_custom_aabb(contact_3d_debug_multimesh,aabb);
}
}
- if (physics_object_picking && (render_target || Input::get_singleton()->get_mouse_mode()!=Input::MOUSE_MODE_CAPTURED)) {
+ if (physics_object_picking && (to_screen_rect==Rect2() || Input::get_singleton()->get_mouse_mode()!=Input::MOUSE_MODE_CAPTURED)) {
Vector2 last_pos(1e20,1e20);
CollisionObject *last_object;
@@ -708,15 +708,18 @@ RID Viewport::get_viewport() const {
return viewport;
}
-void Viewport::set_rect(const Rect2& p_rect) {
+void Viewport::set_size(const Size2 &p_size) {
- if (rect==p_rect)
+ if (size==p_size.floor())
return;
- rect=p_rect;
+ size=p_size.floor();
+ VS::get_singleton()->viewport_set_size(viewport,size.width,size.height);
_update_rect();
_update_stretch_transform();
+ emit_signal("size_changed");
+
}
Rect2 Viewport::get_visible_rect() const {
@@ -724,12 +727,12 @@ Rect2 Viewport::get_visible_rect() const {
Rect2 r;
- if (rect.pos==Vector2() && rect.size==Size2()) {
+ if (size==Size2()) {
r=Rect2( Point2(), Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ) );
} else {
- r=Rect2( rect.pos , rect.size );
+ r=Rect2( Point2() , size );
}
if (size_override) {
@@ -740,9 +743,9 @@ Rect2 Viewport::get_visible_rect() const {
return r;
}
-Rect2 Viewport::get_rect() const {
+Size2 Viewport::get_size() const {
- return rect;
+ return size;
}
@@ -1219,10 +1222,10 @@ bool Viewport::is_size_override_stretch_enabled() const {
return size_override_stretch;
}
-
+#if 0
void Viewport::set_as_render_target(bool p_enable){
- if (render_target==p_enable)
+/* if (render_target==p_enable)
return;
render_target=p_enable;
@@ -1238,117 +1241,114 @@ void Viewport::set_as_render_target(bool p_enable){
if (p_enable) {
- render_target_texture_rid = VS::get_singleton()->viewport_get_render_target_texture(viewport);
+ texture_rid = VS::get_singleton()->viewport_get_texture(viewport);
} else {
- render_target_texture_rid=RID();
+ texture_rid=RID();
}
- render_target_texture->set_flags(render_target_texture->flags);
- render_target_texture->emit_changed();
+ texture->set_flags(texture->flags);
+ texture->emit_changed();
update_configuration_warning();
+ */
}
bool Viewport::is_set_as_render_target() const{
return render_target;
+
}
-void Viewport::set_render_target_update_mode(RenderTargetUpdateMode p_mode){
+#endif
+void Viewport::set_update_mode(UpdateMode p_mode){
- render_target_update_mode=p_mode;
- VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RenderTargetUpdateMode(p_mode));
+ update_mode=p_mode;
+// VS::get_singleton()->viewport_set_update_mode(viewport,VS::RenderTargetUpdateMode(p_mode));
}
-Viewport::RenderTargetUpdateMode Viewport::get_render_target_update_mode() const{
+Viewport::UpdateMode Viewport::get_update_mode() const{
- return render_target_update_mode;
+ return update_mode;
}
-//RID get_render_target_texture() const;
+//RID get_texture() const;
void Viewport::queue_screen_capture(){
- VS::get_singleton()->viewport_queue_screen_capture(viewport);
+ //VS::get_singleton()->viewport_queue_screen_capture(viewport);
}
Image Viewport::get_screen_capture() const {
- return VS::get_singleton()->viewport_get_screen_capture(viewport);
+// return VS::get_singleton()->viewport_get_screen_capture(viewport);
+ return Image();
}
-Ref<RenderTargetTexture> Viewport::get_render_target_texture() const {
+Ref<RenderTargetTexture> Viewport::get_texture() const {
- return render_target_texture;
+ return texture;
}
-void Viewport::set_render_target_vflip(bool p_enable) {
+void Viewport::set_vflip(bool p_enable) {
- render_target_vflip=p_enable;
- VisualServer::get_singleton()->viewport_set_render_target_vflip(viewport,p_enable);
+ vflip=p_enable;
+// VisualServer::get_singleton()->viewport_set_vflip(viewport,p_enable);
}
-bool Viewport::get_render_target_vflip() const{
+bool Viewport::get_vflip() const{
- return render_target_vflip;
+ return vflip;
}
-void Viewport::set_render_target_clear_on_new_frame(bool p_enable) {
+void Viewport::set_clear_on_new_frame(bool p_enable) {
- render_target_clear_on_new_frame=p_enable;
- VisualServer::get_singleton()->viewport_set_render_target_clear_on_new_frame(viewport,p_enable);
+ clear_on_new_frame=p_enable;
+ //VisualServer::get_singleton()->viewport_set_clear_on_new_frame(viewport,p_enable);
}
-bool Viewport::get_render_target_clear_on_new_frame() const{
+bool Viewport::get_clear_on_new_frame() const{
- return render_target_clear_on_new_frame;
+ return clear_on_new_frame;
}
-void Viewport::render_target_clear() {
+void Viewport::clear() {
- //render_target_clear=true;
- VisualServer::get_singleton()->viewport_render_target_clear(viewport);
+ //clear=true;
+// VisualServer::get_singleton()->viewport_clear(viewport);
}
-void Viewport::set_render_target_filter(bool p_enable) {
-
- if(!render_target)
- return;
+void Viewport::set_filter(bool p_enable) {
- render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0));
+ texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0));
}
-bool Viewport::get_render_target_filter() const{
+bool Viewport::get_filter() const{
- return (render_target_texture->get_flags()&Texture::FLAG_FILTER)!=0;
+ return (texture->get_flags()&Texture::FLAG_FILTER)!=0;
}
-void Viewport::set_render_target_gen_mipmaps(bool p_enable) {
+void Viewport::set_gen_mipmaps(bool p_enable) {
- //render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0));
- render_target_gen_mipmaps=p_enable;
+ //texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0));
+ gen_mipmaps=p_enable;
}
-bool Viewport::get_render_target_gen_mipmaps() const{
+bool Viewport::get_gen_mipmaps() const{
- //return (render_target_texture->get_flags()&Texture::FLAG_FILTER)!=0;
- return render_target_gen_mipmaps;
+ //return (texture->get_flags()&Texture::FLAG_FILTER)!=0;
+ return gen_mipmaps;
}
Matrix32 Viewport::_get_input_pre_xform() const {
Matrix32 pre_xf;
- if (render_target) {
- if (to_screen_rect!=Rect2()) {
- pre_xf.elements[2]=-to_screen_rect.pos;
- pre_xf.scale(rect.size/to_screen_rect.size);
- }
- } else {
+ if (to_screen_rect!=Rect2()) {
- pre_xf.elements[2]=-rect.pos;
+ pre_xf.elements[2]=-to_screen_rect.pos;
+ pre_xf.scale(size/to_screen_rect.size);
}
return pre_xf;
@@ -1457,7 +1457,7 @@ void Viewport::_vp_input(const InputEvent& p_ev) {
if (parent_control && !parent_control->is_visible())
return;
- if (render_target && to_screen_rect==Rect2())
+ if (to_screen_rect==Rect2())
return; //if render target, can't get input events
//this one handles system input, p_ev are in system coordinates
@@ -1483,7 +1483,7 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) {
if (parent_control && !parent_control->is_visible())
return;
- if (render_target && to_screen_rect==Rect2())
+ if (to_screen_rect==Rect2())
return; //if render target, can't get input events
//this one handles system input, p_ev are in system coordinates
@@ -2518,17 +2518,18 @@ bool Viewport::is_using_own_world() const {
return own_world.is_valid();
}
-void Viewport::set_render_target_to_screen_rect(const Rect2& p_rect) {
+void Viewport::set_attach_to_screen_rect(const Rect2& p_rect) {
+ VS::get_singleton()->viewport_attach_to_screen(viewport,p_rect);
to_screen_rect=p_rect;
- VisualServer::get_singleton()->viewport_set_render_target_to_screen_rect(viewport,to_screen_rect);
}
-Rect2 Viewport::get_render_target_to_screen_rect() const{
+Rect2 Viewport::get_attach_to_screen_rect() const{
return to_screen_rect;
}
+
void Viewport::set_physics_object_picking(bool p_enable) {
physics_object_picking=p_enable;
@@ -2584,19 +2585,28 @@ Control *Viewport::get_modal_stack_top() const {
String Viewport::get_configuration_warning() const {
- if (get_parent() && !get_parent()->cast_to<Control>() && !render_target) {
+ /*if (get_parent() && !get_parent()->cast_to<Control>() && !render_target) {
return TTR("This viewport is not set as render target. If you intend for it to display its contents directly to the screen, make it a child of a Control so it can obtain a size. Otherwise, make it a RenderTarget and assign its internal texture to some node for display.");
- }
+ }*/
return String();
}
+void Viewport::gui_reset_canvas_sort_index() {
+ gui.canvas_sort_index=0;
+}
+int Viewport::gui_get_canvas_sort_index() {
+
+ return gui.canvas_sort_index++;
+}
+
+
void Viewport::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_rect","rect"), &Viewport::set_rect);
- ObjectTypeDB::bind_method(_MD("get_rect"), &Viewport::get_rect);
+ ObjectTypeDB::bind_method(_MD("set_size","size"), &Viewport::set_size);
+ ObjectTypeDB::bind_method(_MD("get_size"), &Viewport::get_size);
ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d);
ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d);
ObjectTypeDB::bind_method(_MD("find_world_2d:World2D"), &Viewport::find_world_2d);
@@ -2630,27 +2640,25 @@ void Viewport::_bind_methods() {
ObjectTypeDB::bind_method(_MD("queue_screen_capture"), &Viewport::queue_screen_capture);
ObjectTypeDB::bind_method(_MD("get_screen_capture"), &Viewport::get_screen_capture);
- ObjectTypeDB::bind_method(_MD("set_as_render_target","enable"), &Viewport::set_as_render_target);
- ObjectTypeDB::bind_method(_MD("is_set_as_render_target"), &Viewport::is_set_as_render_target);
- ObjectTypeDB::bind_method(_MD("set_render_target_vflip","enable"), &Viewport::set_render_target_vflip);
- ObjectTypeDB::bind_method(_MD("get_render_target_vflip"), &Viewport::get_render_target_vflip);
+ ObjectTypeDB::bind_method(_MD("set_vflip","enable"), &Viewport::set_vflip);
+ ObjectTypeDB::bind_method(_MD("get_vflip"), &Viewport::get_vflip);
- ObjectTypeDB::bind_method(_MD("set_render_target_clear_on_new_frame","enable"), &Viewport::set_render_target_clear_on_new_frame);
- ObjectTypeDB::bind_method(_MD("get_render_target_clear_on_new_frame"), &Viewport::get_render_target_clear_on_new_frame);
+ ObjectTypeDB::bind_method(_MD("set_clear_on_new_frame","enable"), &Viewport::set_clear_on_new_frame);
+ ObjectTypeDB::bind_method(_MD("get_clear_on_new_frame"), &Viewport::get_clear_on_new_frame);
- ObjectTypeDB::bind_method(_MD("render_target_clear"), &Viewport::render_target_clear);
+ ObjectTypeDB::bind_method(_MD("clear"), &Viewport::clear);
- ObjectTypeDB::bind_method(_MD("set_render_target_filter","enable"), &Viewport::set_render_target_filter);
- ObjectTypeDB::bind_method(_MD("get_render_target_filter"), &Viewport::get_render_target_filter);
+ ObjectTypeDB::bind_method(_MD("set_filter","enable"), &Viewport::set_filter);
+ ObjectTypeDB::bind_method(_MD("get_filter"), &Viewport::get_filter);
- ObjectTypeDB::bind_method(_MD("set_render_target_gen_mipmaps","enable"), &Viewport::set_render_target_gen_mipmaps);
- ObjectTypeDB::bind_method(_MD("get_render_target_gen_mipmaps"), &Viewport::get_render_target_gen_mipmaps);
+ ObjectTypeDB::bind_method(_MD("set_gen_mipmaps","enable"), &Viewport::set_gen_mipmaps);
+ ObjectTypeDB::bind_method(_MD("get_gen_mipmaps"), &Viewport::get_gen_mipmaps);
- ObjectTypeDB::bind_method(_MD("set_render_target_update_mode","mode"), &Viewport::set_render_target_update_mode);
- ObjectTypeDB::bind_method(_MD("get_render_target_update_mode"), &Viewport::get_render_target_update_mode);
+ ObjectTypeDB::bind_method(_MD("set_update_mode","mode"), &Viewport::set_update_mode);
+ ObjectTypeDB::bind_method(_MD("get_update_mode"), &Viewport::get_update_mode);
- ObjectTypeDB::bind_method(_MD("get_render_target_texture:RenderTargetTexture"), &Viewport::get_render_target_texture);
+ ObjectTypeDB::bind_method(_MD("get_texture:RenderTargetTexture"), &Viewport::get_texture);
ObjectTypeDB::bind_method(_MD("set_physics_object_picking","enable"), &Viewport::set_physics_object_picking);
ObjectTypeDB::bind_method(_MD("get_physics_object_picking"), &Viewport::get_physics_object_picking);
@@ -2671,7 +2679,7 @@ void Viewport::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_as_audio_listener_2d","enable"), &Viewport::set_as_audio_listener_2d);
ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d);
- ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect","rect"), &Viewport::set_render_target_to_screen_rect);
+ ObjectTypeDB::bind_method(_MD("set_attach_to_screen_rect","rect"), &Viewport::set_attach_to_screen_rect);
ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos);
ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse);
@@ -2685,17 +2693,16 @@ void Viewport::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip);
ObjectTypeDB::bind_method(_MD("_gui_remove_focus"), &Viewport::_gui_remove_focus);
- ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") );
+ ADD_PROPERTY( PropertyInfo(Variant::RECT2,"size"), _SCS("set_size"), _SCS("get_size") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") );
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), _SCS("set_world"), _SCS("get_world") );
// ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), _SCS("set_world_2d"), _SCS("get_world_2d") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transparent_bg"), _SCS("set_transparent_background"), _SCS("has_transparent_background") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/enabled"), _SCS("set_as_render_target"), _SCS("is_set_as_render_target") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/v_flip"), _SCS("set_render_target_vflip"), _SCS("get_render_target_vflip") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/clear_on_new_frame"), _SCS("set_render_target_clear_on_new_frame"), _SCS("get_render_target_clear_on_new_frame") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/filter"), _SCS("set_render_target_filter"), _SCS("get_render_target_filter") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/gen_mipmaps"), _SCS("set_render_target_gen_mipmaps"), _SCS("get_render_target_gen_mipmaps") );
- ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target/update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), _SCS("set_render_target_update_mode"), _SCS("get_render_target_update_mode") );
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/v_flip"), _SCS("set_vflip"), _SCS("get_vflip") );
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/clear_on_new_frame"), _SCS("set_clear_on_new_frame"), _SCS("get_clear_on_new_frame") );
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/filter"), _SCS("set_filter"), _SCS("get_filter") );
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/gen_mipmaps"), _SCS("set_gen_mipmaps"), _SCS("get_gen_mipmaps") );
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target/update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), _SCS("set_update_mode"), _SCS("get_update_mode") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_2d"), _SCS("set_as_audio_listener_2d"), _SCS("is_audio_listener_2d") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_3d"), _SCS("set_as_audio_listener"), _SCS("is_audio_listener") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking") );
@@ -2703,10 +2710,10 @@ void Viewport::_bind_methods() {
ADD_SIGNAL(MethodInfo("size_changed"));
- BIND_CONSTANT( RENDER_TARGET_UPDATE_DISABLED );
- BIND_CONSTANT( RENDER_TARGET_UPDATE_ONCE );
- BIND_CONSTANT( RENDER_TARGET_UPDATE_WHEN_VISIBLE );
- BIND_CONSTANT( RENDER_TARGET_UPDATE_ALWAYS );
+ BIND_CONSTANT( UPDATE_DISABLED );
+ BIND_CONSTANT( UPDATE_ONCE );
+ BIND_CONSTANT( UPDATE_WHEN_VISIBLE );
+ BIND_CONSTANT( UPDATE_ALWAYS );
}
@@ -2731,13 +2738,13 @@ Viewport::Viewport() {
size_override=false;
size_override_stretch=false;
size_override_size=Size2(1,1);
- render_target_gen_mipmaps=false;
- render_target=false;
- render_target_vflip=false;
- render_target_clear_on_new_frame=true;
- //render_target_clear=true;
- render_target_update_mode=RENDER_TARGET_UPDATE_WHEN_VISIBLE;
- render_target_texture = Ref<RenderTargetTexture>( memnew( RenderTargetTexture(this) ) );
+ gen_mipmaps=false;
+
+ vflip=false;
+ clear_on_new_frame=true;
+ //clear=true;
+ update_mode=UPDATE_WHEN_VISIBLE;
+ texture = Ref<RenderTargetTexture>( memnew( RenderTargetTexture(this) ) );
physics_object_picking=false;
physics_object_capture=0;
@@ -2763,6 +2770,7 @@ Viewport::Viewport() {
gui.tooltip_label=NULL;
gui.drag_preview=NULL;
gui.drag_attempted=false;
+ gui.canvas_sort_index=0;
parent_control=NULL;
@@ -2776,8 +2784,8 @@ Viewport::~Viewport() {
VisualServer::get_singleton()->free( viewport );
SpatialSoundServer::get_singleton()->free(internal_listener);
SpatialSound2DServer::get_singleton()->free(internal_listener_2d);
- if (render_target_texture.is_valid())
- render_target_texture->vp=NULL; //so if used, will crash
+ if (texture.is_valid())
+ texture->vp=NULL; //so if used, will crash
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index f657f0507d..d610237bec 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -79,11 +79,11 @@ class Viewport : public Node {
OBJ_TYPE( Viewport, Node );
public:
- enum RenderTargetUpdateMode {
- RENDER_TARGET_UPDATE_DISABLED,
- RENDER_TARGET_UPDATE_ONCE, //then goes to disabled
- RENDER_TARGET_UPDATE_WHEN_VISIBLE, // default
- RENDER_TARGET_UPDATE_ALWAYS
+ enum UpdateMode {
+ UPDATE_DISABLED,
+ UPDATE_ONCE, //then goes to disabled
+ UPDATE_WHEN_VISIBLE, // default
+ UPDATE_ALWAYS
};
private:
@@ -114,7 +114,7 @@ friend class RenderTargetTexture;
Matrix32 global_canvas_transform;
Matrix32 stretch_transform;
- Rect2 rect;
+ Size2 size;
Rect2 to_screen_rect;
RID contact_2d_debug;
@@ -131,10 +131,10 @@ friend class RenderTargetTexture;
Rect2 last_vp_rect;
bool transparent_bg;
- bool render_target_vflip;
- bool render_target_clear_on_new_frame;
- bool render_target_filter;
- bool render_target_gen_mipmaps;
+ bool vflip;
+ bool clear_on_new_frame;
+ bool filter;
+ bool gen_mipmaps;
bool physics_object_picking;
List<InputEvent> physics_picking_events;
@@ -170,10 +170,10 @@ friend class RenderTargetTexture;
void _update_stretch_transform();
void _update_global_transform();
- bool render_target;
- RenderTargetUpdateMode render_target_update_mode;
- RID render_target_texture_rid;
- Ref<RenderTargetTexture> render_target_texture;
+
+ UpdateMode update_mode;
+ RID texture_rid;
+ Ref<RenderTargetTexture> texture;
struct GUI {
@@ -202,6 +202,7 @@ friend class RenderTargetTexture;
List<Control*> subwindows;
bool roots_order_dirty;
List<Control*> roots;
+ int canvas_sort_index; //for sorting items with canvas as root
GUI();
@@ -299,8 +300,10 @@ public:
void set_as_audio_listener_2d(bool p_enable);
bool is_audio_listener_2d() const;
- void set_rect(const Rect2& p_rect);
- Rect2 get_rect() const;
+ void set_size(const Size2& p_size);
+
+
+ Size2 get_size() const;
Rect2 get_visible_rect() const;
RID get_viewport() const;
@@ -327,29 +330,27 @@ public:
void set_size_override(bool p_enable,const Size2& p_size=Size2(-1,-1),const Vector2& p_margin=Vector2());
Size2 get_size_override() const;
+
bool is_size_override_enabled() const;
void set_size_override_stretch(bool p_enable);
bool is_size_override_stretch_enabled() const;
- void set_as_render_target(bool p_enable);
- bool is_set_as_render_target() const;
+ void set_vflip(bool p_enable);
+ bool get_vflip() const;
- void set_render_target_vflip(bool p_enable);
- bool get_render_target_vflip() const;
+ void set_clear_on_new_frame(bool p_enable);
+ bool get_clear_on_new_frame() const;
+ void clear();
- void set_render_target_clear_on_new_frame(bool p_enable);
- bool get_render_target_clear_on_new_frame() const;
- void render_target_clear();
+ void set_filter(bool p_enable);
+ bool get_filter() const;
- void set_render_target_filter(bool p_enable);
- bool get_render_target_filter() const;
+ void set_gen_mipmaps(bool p_enable);
+ bool get_gen_mipmaps() const;
- void set_render_target_gen_mipmaps(bool p_enable);
- bool get_render_target_gen_mipmaps() const;
-
- void set_render_target_update_mode(RenderTargetUpdateMode p_mode);
- RenderTargetUpdateMode get_render_target_update_mode() const;
- Ref<RenderTargetTexture> get_render_target_texture() const;
+ void set_update_mode(UpdateMode p_mode);
+ UpdateMode get_update_mode() const;
+ Ref<RenderTargetTexture> get_texture() const;
Vector2 get_camera_coords(const Vector2& p_viewport_coords) const;
@@ -367,8 +368,8 @@ public:
void set_disable_input(bool p_disable);
bool is_input_disabled() const;
- void set_render_target_to_screen_rect(const Rect2& p_rect);
- Rect2 get_render_target_to_screen_rect() const;
+ void set_attach_to_screen_rect(const Rect2& p_rect);
+ Rect2 get_attach_to_screen_rect() const;
Vector2 get_mouse_pos() const;
void warp_mouse(const Vector2& p_pos);
@@ -381,12 +382,17 @@ public:
Variant gui_get_drag_data() const;
Control *get_modal_stack_top() const;
+ void gui_reset_canvas_sort_index();
+ int gui_get_canvas_sort_index();
+
virtual String get_configuration_warning() const;
+
+
Viewport();
~Viewport();
};
-VARIANT_ENUM_CAST(Viewport::RenderTargetUpdateMode);
+VARIANT_ENUM_CAST(Viewport::UpdateMode);
#endif
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 104aeb2b5e..dcb2edf872 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -235,7 +235,6 @@ static ResourceFormatLoaderWAV *resource_loader_wav=NULL;
#endif
static ResourceFormatLoaderTheme *resource_loader_theme=NULL;
-static ResourceFormatLoaderShader *resource_loader_shader=NULL;
static ResourceFormatSaverText *resource_saver_text=NULL;
static ResourceFormatLoaderText *resource_loader_text=NULL;
@@ -269,8 +268,6 @@ void register_scene_types() {
resource_loader_theme = memnew( ResourceFormatLoaderTheme );
ResourceLoader::add_resource_format_loader( resource_loader_theme );
- resource_loader_shader = memnew( ResourceFormatLoaderShader );
- ResourceLoader::add_resource_format_loader( resource_loader_shader );
bool default_theme_hidpi=GLOBAL_DEF("display/use_hidpi_theme",false);
Globals::get_singleton()->set_custom_property_info("display/use_hidpi_theme",PropertyInfo(Variant::BOOL,"display/use_hidpi_theme",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED));
@@ -424,7 +421,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<SpotLight>();
ObjectTypeDB::register_type<AnimationTreePlayer>();
ObjectTypeDB::register_type<Portal>();
- ObjectTypeDB::register_type<Particles>();
+ //ObjectTypeDB::register_type<Particles>();
ObjectTypeDB::register_type<Position3D>();
ObjectTypeDB::register_type<Quad>();
ObjectTypeDB::register_type<NavigationMeshInstance>();
@@ -453,8 +450,8 @@ void register_scene_types() {
ObjectTypeDB::register_type<PathFollow>();
ObjectTypeDB::register_type<VisibilityNotifier>();
ObjectTypeDB::register_type<VisibilityEnabler>();
- ObjectTypeDB::register_type<BakedLightInstance>();
- ObjectTypeDB::register_type<BakedLightSampler>();
+ //ObjectTypeDB::register_type<BakedLightInstance>();
+ //ObjectTypeDB::register_type<BakedLightSampler>();
ObjectTypeDB::register_type<WorldEnvironment>();
ObjectTypeDB::register_type<RemoteTransform>();
@@ -489,7 +486,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<Particles2D>();
ObjectTypeDB::register_type<ParticleAttractor2D>();
ObjectTypeDB::register_type<Sprite>();
- ObjectTypeDB::register_type<ViewportSprite>();
+// ObjectTypeDB::register_type<ViewportSprite>();
ObjectTypeDB::register_type<SpriteFrames>();
ObjectTypeDB::register_type<AnimatedSprite>();
ObjectTypeDB::register_type<Position2D>();
@@ -538,17 +535,17 @@ void register_scene_types() {
/* REGISTER RESOURCES */
ObjectTypeDB::register_virtual_type<Shader>();
- ObjectTypeDB::register_virtual_type<ShaderGraph>();
+// ObjectTypeDB::register_virtual_type<ShaderGraph>();
ObjectTypeDB::register_type<CanvasItemShader>();
- ObjectTypeDB::register_type<CanvasItemShaderGraph>();
+// ObjectTypeDB::register_type<CanvasItemShaderGraph>();
#ifndef _3D_DISABLED
ObjectTypeDB::register_type<Mesh>();
ObjectTypeDB::register_virtual_type<Material>();
ObjectTypeDB::register_type<FixedMaterial>();
- ObjectTypeDB::register_type<ShaderMaterial>();
+// ObjectTypeDB::register_type<ShaderMaterial>();
ObjectTypeDB::register_type<RoomBounds>();
- ObjectTypeDB::register_type<MaterialShaderGraph>();
+// ObjectTypeDB::register_type<MaterialShaderGraph>();
ObjectTypeDB::register_type<MaterialShader>();
ObjectTypeDB::add_compatibility_type("Shader","MaterialShader");
ObjectTypeDB::add_compatibility_type("ParticleSystemMaterial","FixedMaterial");
@@ -568,7 +565,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<SurfaceTool>();
ObjectTypeDB::register_type<MeshDataTool>();
- ObjectTypeDB::register_type<BakedLight>();
+ //ObjectTypeDB::register_type<BakedLight>();
OS::get_singleton()->yield(); //may take time to init
@@ -590,8 +587,7 @@ void register_scene_types() {
ObjectTypeDB::register_type<StyleBoxEmpty>();
ObjectTypeDB::register_type<StyleBoxTexture>();
- ObjectTypeDB::register_type<StyleBoxFlat>();
- ObjectTypeDB::register_type<StyleBoxImageMask>();
+ ObjectTypeDB::register_type<StyleBoxFlat>();
ObjectTypeDB::register_type<Theme>();
ObjectTypeDB::add_compatibility_type("Font","BitmapFont");
@@ -664,7 +660,6 @@ void unregister_scene_types() {
memdelete( resource_loader_theme );
- memdelete( resource_loader_shader );
if (resource_saver_text) {
memdelete(resource_saver_text);
diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp
index e4510be874..38ed661cdd 100644
--- a/scene/resources/baked_light.cpp
+++ b/scene/resources/baked_light.cpp
@@ -29,6 +29,8 @@
#include "baked_light.h"
#include "servers/visual_server.h"
+#if 0
+
void BakedLight::set_mode(Mode p_mode) {
mode=p_mode;
@@ -582,7 +584,7 @@ BakedLight::BakedLight() {
tint=0.0;
ao_radius=2.5;
ao_strength=0.7;
- format=FORMAT_RGB;
+ format=FORMAT_RGB8;
transfer_only_uv2=false;
@@ -600,3 +602,4 @@ BakedLight::~BakedLight() {
VS::get_singleton()->free(baked_light);
}
+#endif
diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h
index 16806d29e3..0eaa3df276 100644
--- a/scene/resources/baked_light.h
+++ b/scene/resources/baked_light.h
@@ -32,6 +32,7 @@
#include "resource.h"
#include "scene/resources/texture.h"
+#if 0
class BakedLight : public Resource {
OBJ_TYPE( BakedLight, Resource);
@@ -44,7 +45,7 @@ public:
enum Format {
- FORMAT_RGB,
+ FORMAT_RGB8,
FORMAT_HDR8,
FORMAT_HDR16
};
@@ -195,5 +196,5 @@ public:
VARIANT_ENUM_CAST(BakedLight::Format);
VARIANT_ENUM_CAST(BakedLight::Mode);
VARIANT_ENUM_CAST(BakedLight::BakeFlags);
-
+#endif
#endif // BAKED_LIGHT_H
diff --git a/scene/resources/bit_mask.cpp b/scene/resources/bit_mask.cpp
index f5bfce3ef8..57dc39138a 100644
--- a/scene/resources/bit_mask.cpp
+++ b/scene/resources/bit_mask.cpp
@@ -45,8 +45,8 @@ void BitMap::create_from_image_alpha(const Image& p_image){
ERR_FAIL_COND(p_image.empty());
Image img=p_image;
- img.convert(Image::FORMAT_INTENSITY);
- ERR_FAIL_COND(img.get_format()!=Image::FORMAT_INTENSITY);
+ img.convert(Image::FORMAT_LA8);
+ ERR_FAIL_COND(img.get_format()!=Image::FORMAT_LA8);
create(Size2(img.get_width(),img.get_height()));
@@ -58,7 +58,7 @@ void BitMap::create_from_image_alpha(const Image& p_image){
int bbyte = i/8;
int bbit = i % 8;
- if (r[i])
+ if (r[i*2])
w[bbyte]|=(1<<bbit);
}
@@ -193,7 +193,6 @@ void BitMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_data"),_SCS("_get_data"));
-
}
BitMap::BitMap() {
diff --git a/scene/resources/default_theme/color_picker_hue.png b/scene/resources/default_theme/color_picker_hue.png
new file mode 100644
index 0000000000..9bdd24f4fe
--- /dev/null
+++ b/scene/resources/default_theme/color_picker_hue.png
Binary files differ
diff --git a/scene/resources/default_theme/color_picker_main.png b/scene/resources/default_theme/color_picker_main.png
new file mode 100644
index 0000000000..0498628180
--- /dev/null
+++ b/scene/resources/default_theme/color_picker_main.png
Binary files differ
diff --git a/scene/resources/default_theme/color_picker_sample.png b/scene/resources/default_theme/color_picker_sample.png
new file mode 100644
index 0000000000..b145a3e384
--- /dev/null
+++ b/scene/resources/default_theme/color_picker_sample.png
Binary files differ
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 0740b591c4..266de77ca0 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -58,14 +58,14 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src,float p_left, float p_top, flo
if (scale>1) {
Size2 orig_size = Size2(img.get_width(),img.get_height());
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
img.expand_x2_hq2x();
if (scale!=2.0) {
img.resize(orig_size.x*scale,orig_size.y*scale);
}
} else if (scale<1) {
Size2 orig_size = Size2(img.get_width(),img.get_height());
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
img.resize(orig_size.x*scale,orig_size.y*scale);
}
@@ -108,14 +108,14 @@ static Ref<Texture> make_icon(T p_src) {
if (scale>1) {
Size2 orig_size = Size2(img.get_width(),img.get_height());
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
img.expand_x2_hq2x();
if (scale!=2.0) {
img.resize(orig_size.x*scale,orig_size.y*scale);
}
} else if (scale<1) {
Size2 orig_size = Size2(img.get_width(),img.get_height());
- img.convert(Image::FORMAT_RGBA);
+ img.convert(Image::FORMAT_RGBA8);
img.resize(orig_size.x*scale,orig_size.y*scale);
}
texture->create_from_image( img,ImageTexture::FLAG_FILTER );
@@ -125,7 +125,7 @@ static Ref<Texture> make_icon(T p_src) {
static Ref<Shader> make_shader(const char*vertex_code,const char*fragment_code,const char*lighting_code) {
Ref<Shader> shader = (memnew( Shader(Shader::MODE_CANVAS_ITEM) ));
- shader->set_code(vertex_code, fragment_code, lighting_code);
+// shader->set_code(vertex_code, fragment_code, lighting_code);
return shader;
}
@@ -214,6 +214,8 @@ static Ref<StyleBox> make_empty_stylebox(float p_margin_left=-1, float p_margin_
return style;
}
+
+
void fill_default_theme(Ref<Theme>& t, const Ref<Font> & default_font, const Ref<Font> & large_font, Ref<Texture>& default_icon, Ref<StyleBox>& default_style, float p_scale) {
scale=p_scale;
@@ -832,10 +834,15 @@ void fill_default_theme(Ref<Theme>& t, const Ref<Font> & default_font, const Ref
t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) );
t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) );
+ t->set_icon("color_area", "ColorPicker", make_icon( color_picker_main_png));
+ t->set_icon("color_hue", "ColorPicker", make_icon( color_picker_hue_png));
+ t->set_icon("color_sample", "ColorPicker", make_icon( color_picker_sample_png));
t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, ""));
t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, ""));
+
+
// TooltipPanel
Ref<StyleBoxTexture> style_tt = make_stylebox( tooltip_bg_png,4,4,4,4);
@@ -962,7 +969,6 @@ void fill_default_theme(Ref<Theme>& t, const Ref<Font> & default_font, const Ref
t->set_icon( "logo","Icons", make_icon(logo_png) );
-
// Theme
default_icon= make_icon(error_icon_png) ;
diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h
index 73c801483f..913ea9b5e9 100644
--- a/scene/resources/default_theme/theme_data.h
+++ b/scene/resources/default_theme/theme_data.h
@@ -69,6 +69,21 @@ static const unsigned char close_hl_png[]={
};
+static const unsigned char color_picker_hue_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x1,0x0,0x8,0x2,0x0,0x0,0x0,0x35,0x30,0x61,0x19,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x9,0x18,0xc,0x24,0x18,0xa9,0xb3,0x2c,0xb7,0x0,0x0,0x0,0x23,0x49,0x44,0x41,0x54,0x68,0xde,0xed,0xc1,0x31,0x1,0x0,0x0,0x0,0xc2,0xa0,0xf5,0x4f,0x6d,0xd,0xf,0xa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xbe,0xd,0x31,0x0,0x0,0x1,0x35,0x84,0x14,0xe2,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
+static const unsigned char color_picker_main_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x8,0x2,0x0,0x0,0x0,0xd3,0x10,0x3f,0x31,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x9,0x18,0xc,0x23,0x22,0x20,0xfe,0x63,0xc2,0x0,0x0,0x0,0xd5,0x49,0x44,0x41,0x54,0x78,0xda,0xed,0xc1,0x31,0x1,0x0,0x0,0x0,0xc2,0xa0,0xf5,0x4f,0xed,0x65,0xb,0xa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0x1b,0x1,0x2d,0x0,0x1,0x9e,0xcb,0xc2,0xed,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
+static const unsigned char color_picker_sample_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x14,0x8,0x2,0x0,0x0,0x0,0xed,0x20,0x74,0x8,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x9,0x18,0xc,0x27,0x37,0x29,0x4f,0x42,0x2d,0x0,0x0,0x0,0x61,0x49,0x44,0x41,0x54,0x68,0xde,0xed,0xd9,0xb1,0xd,0x0,0x21,0xc,0x3,0x40,0x40,0xbf,0x5f,0x66,0xcd,0x84,0xf9,0x96,0x19,0xf0,0x5d,0x87,0x5c,0x5b,0x9,0xca,0x9e,0x99,0x75,0xe9,0xee,0xfb,0x59,0x55,0x52,0xe9,0xc3,0xe9,0x59,0x10,0x4c,0x1,0x50,0x0,0x50,0x0,0x8,0xf4,0xf9,0x15,0x49,0x93,0x53,0x13,0x0,0x2b,0x10,0x28,0x0,0x28,0x0,0x64,0xd9,0x2e,0xc1,0xd2,0xe4,0xd4,0x4,0xc0,0xa,0x4,0xa,0x0,0xa,0x0,0x59,0x5c,0x82,0xa5,0xd1,0xa9,0x9,0x80,0x15,0x8,0x14,0x0,0x14,0x0,0xb2,0xfc,0x5b,0xb2,0x3c,0x5a,0x4,0xa1,0xf3,0x57,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
static const unsigned char dosfont_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x80,0x0,0x0,0x0,0x80,0x1,0x0,0x0,0x0,0x0,0xeb,0x45,0x5c,0x66,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0x2,0x74,0x52,0x4e,0x53,0x0,0x0,0x76,0x93,0xcd,0x38,0x0,0x0,0x0,0x2,0x62,0x4b,0x47,0x44,0x0,0x1,0xdd,0x8a,0x13,0xa4,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x89,0x0,0x0,0xb,0x89,0x1,0x37,0xc9,0xcb,0xad,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x2,0x83,0x49,0x44,0x41,0x54,0x48,0xc7,0xed,0xd4,0xb1,0x6e,0xdb,0x30,0x10,0x0,0x50,0x22,0x3,0x27,0x22,0xc8,0x78,0x83,0x91,0xa9,0x1f,0xc0,0xa9,0x10,0xa,0x7e,0xc,0x11,0x14,0x87,0xc,0x1c,0x32,0x9,0x1a,0xe,0x46,0xa6,0xfc,0x43,0xff,0x86,0xb5,0x80,0x9b,0x88,0x8e,0x5d,0x64,0x18,0x9e,0xdc,0xd5,0x53,0x91,0xc1,0xa0,0x7a,0xa4,0xe4,0xd4,0x31,0xd2,0x25,0x70,0x97,0xa2,0x37,0x48,0xe6,0x33,0x45,0xdd,0x51,0x24,0x95,0x7a,0x23,0xe0,0x75,0x13,0xb,0xd8,0x93,0xbf,0x51,0x51,0xa3,0xac,0x99,0xc9,0x29,0x87,0x81,0x83,0xb2,0x0,0xc7,0xfe,0xee,0x43,0x58,0x85,0x95,0xb7,0xa6,0xb6,0xaf,0x7a,0xe9,0x93,0x63,0xc3,0xf2,0xc,0x96,0x3e,0xba,0x97,0x11,0x3,0xb5,0x46,0xc0,0x15,0x30,0x43,0x1,0xbd,0x6,0x81,0x71,0xa9,0xb2,0x82,0x9,0x92,0x3d,0xf6,0xb0,0xbd,0x5c,0xf2,0x53,0xf2,0x75,0xc,0x11,0x5f,0xc7,0xe0,0xc4,0xaa,0xb4,0x40,0x41,0xc4,0x69,0xd0,0x27,0x55,0x12,0x13,0x78,0x74,0xa7,0xb5,0xd8,0x3f,0x14,0x77,0x81,0x0,0x22,0x93,0x9b,0x4c,0x54,0x5b,0x72,0x6d,0x98,0x17,0xd1,0x33,0xb3,0x94,0xaa,0x3c,0x93,0xea,0xb4,0x76,0x31,0x6a,0x66,0x0,0xa9,0x59,0x1c,0x8c,0xe,0x33,0xc0,0x12,0x4c,0x29,0xc2,0xa5,0xc3,0xc1,0xd0,0xb2,0x64,0x6a,0x60,0xa3,0xc0,0xea,0xac,0x19,0x58,0x4b,0xa9,0x4a,0x17,0xf0,0xda,0x68,0xb6,0x5,0xec,0xb2,0xf6,0x88,0x33,0xc8,0x18,0x52,0xd5,0x5a,0x1,0xb3,0x61,0x1,0x53,0xdf,0x2,0x51,0x2d,0x33,0xdd,0x12,0x59,0xea,0x94,0x95,0x3c,0x80,0x2e,0x5e,0xf9,0xdb,0x71,0x73,0x70,0xcf,0x39,0x3b,0x76,0xb7,0xbb,0x7d,0xcf,0x74,0x50,0xd,0x62,0x40,0x44,0x6,0x83,0xfe,0xc7,0x8e,0x51,0x5,0x5c,0xe1,0xdd,0xdd,0xaa,0xc2,0xf8,0x53,0x80,0x31,0xe2,0xfd,0x7d,0x14,0x8,0x7e,0xcc,0x5,0x28,0x62,0xd7,0xc5,0xc,0xa6,0xf3,0xc3,0x46,0xa6,0x30,0xd7,0x1e,0x1b,0x2e,0xd0,0x7f,0x63,0x5f,0x1f,0xf1,0x32,0xc9,0x90,0x82,0xef,0xb9,0x82,0xc,0x5a,0x1,0xef,0x66,0x90,0xd7,0x7a,0x2c,0x80,0x13,0x94,0xc4,0xf6,0x9f,0xd8,0x75,0xbb,0x2c,0x89,0xed,0xff,0x42,0xe9,0xa7,0xfb,0xa4,0x84,0xec,0x13,0x45,0x7,0x1a,0xb9,0x97,0x18,0x65,0xab,0x4,0xf9,0x54,0x8c,0x3c,0x54,0xe8,0xed,0xa3,0x7c,0x7b,0x55,0xe0,0x8b,0x0,0xf6,0x4f,0x36,0xd6,0x3d,0xc3,0xe8,0x41,0xc0,0xa1,0xb1,0xdb,0x9,0xa8,0x29,0x0,0xe,0xec,0xc3,0x4,0xc1,0x8,0xc,0x0,0xd6,0x36,0xf3,0x23,0xba,0x80,0x3,0x6f,0x17,0x15,0xbe,0x4b,0xe5,0x8c,0x23,0xc2,0x57,0x7b,0x5d,0x61,0x53,0xc0,0x61,0xf,0xbd,0xd5,0x15,0x68,0x47,0x8e,0x0,0x7b,0x37,0xba,0xab,0xba,0x59,0xcc,0x79,0x3d,0xd7,0xaf,0x5a,0xe3,0x85,0x66,0x69,0xab,0x16,0x32,0x31,0x5b,0xd0,0xdb,0x66,0x2,0x2f,0x6f,0xe,0xb2,0x42,0xb5,0x87,0xdf,0xf0,0x59,0xae,0x6a,0x86,0xae,0x93,0x4c,0x7d,0x1b,0x9a,0x6b,0x84,0xdd,0x9a,0xd6,0xca,0xc8,0x89,0xc3,0xfb,0xd4,0x82,0xe,0x30,0xa2,0x2c,0x18,0xc2,0x98,0xb2,0x4f,0x8,0xba,0x83,0xa1,0x40,0x12,0x88,0x6f,0x43,0x38,0x82,0x1c,0x1f,0x15,0x70,0x82,0x96,0xa8,0xa5,0x3d,0xed,0x9c,0xde,0xb9,0x1,0xe9,0xb8,0x5f,0x4c,0x39,0xd2,0xa6,0xac,0xa6,0x48,0xe7,0xd0,0x95,0x53,0xb0,0xc4,0x7b,0x97,0xd4,0xcd,0x3c,0xdd,0xf0,0xd0,0x4e,0xbf,0xe6,0x65,0x24,0x5b,0x7b,0x7d,0xe,0xe5,0xd6,0xae,0xe9,0x90,0x64,0xfd,0x70,0x9e,0x21,0xb5,0x6c,0x5,0xa4,0xa2,0x87,0xe9,0xa3,0x25,0xf4,0x5,0x5c,0x39,0x61,0xa6,0x1e,0xbe,0x11,0x18,0x80,0xed,0xb,0x18,0x9b,0x70,0x70,0xec,0x5f,0x80,0x3f,0x26,0x27,0xb3,0xc9,0x33,0xc8,0x5c,0x2c,0x5a,0x59,0x1f,0xcb,0x2c,0x89,0x9d,0xae,0xf,0x7d,0xcc,0xdb,0x9c,0xdd,0xd5,0xed,0x7c,0x7f,0xbe,0xd0,0x52,0xf9,0x1f,0xff,0x76,0xfc,0x2,0x24,0x3a,0x65,0x42,0xf6,0x41,0x91,0x95,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index 679c8a000c..83518e1f3e 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -573,7 +573,7 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
//blit to image and texture
{
- Image img(tex.texture_size,tex.texture_size,0,Image::FORMAT_GRAYSCALE_ALPHA,tex.imgdata);
+ Image img(tex.texture_size,tex.texture_size,0,Image::FORMAT_LA8,tex.imgdata);
if (tex.texture.is_null()) {
tex.texture.instance();
diff --git a/scene/resources/dynamic_font_stb.cpp b/scene/resources/dynamic_font_stb.cpp
index 456e6a5ee7..d1efc0f705 100644
--- a/scene/resources/dynamic_font_stb.cpp
+++ b/scene/resources/dynamic_font_stb.cpp
@@ -321,7 +321,7 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
//blit to image and texture
{
- Image img(tex.texture_size,tex.texture_size,0,Image::FORMAT_GRAYSCALE_ALPHA,tex.imgdata);
+ Image img(tex.texture_size,tex.texture_size,0,Image::FORMAT_LA8,tex.imgdata);
if (tex.texture.is_null()) {
tex.texture.instance();
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 4551aff0ef..6fecdef59d 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -28,59 +28,7 @@
/*************************************************************************/
#include "environment.h"
#include "texture.h"
-void Environment::set_background(BG p_bg) {
- ERR_FAIL_INDEX(p_bg,BG_MAX);
- bg_mode=p_bg;
- VS::get_singleton()->environment_set_background(environment,VS::EnvironmentBG(p_bg));
-}
-
-Environment::BG Environment::get_background() const{
-
- return bg_mode;
-}
-
-void Environment::set_background_param(BGParam p_param, const Variant& p_value){
-
- ERR_FAIL_INDEX(p_param,BG_PARAM_MAX);
- bg_param[p_param]=p_value;
- VS::get_singleton()->environment_set_background_param(environment,VS::EnvironmentBGParam(p_param),p_value);
-
-}
-Variant Environment::get_background_param(BGParam p_param) const{
-
- ERR_FAIL_INDEX_V(p_param,BG_PARAM_MAX,Variant());
- return bg_param[p_param];
-
-}
-
-void Environment::set_enable_fx(Fx p_effect,bool p_enabled){
-
- ERR_FAIL_INDEX(p_effect,FX_MAX);
- fx_enabled[p_effect]=p_enabled;
- VS::get_singleton()->environment_set_enable_fx(environment,VS::EnvironmentFx(p_effect),p_enabled);
-
-}
-bool Environment::is_fx_enabled(Fx p_effect) const{
-
- ERR_FAIL_INDEX_V(p_effect,FX_MAX,false);
- return fx_enabled[p_effect];
-
-}
-
-void Environment::fx_set_param(FxParam p_param,const Variant& p_value){
-
- ERR_FAIL_INDEX(p_param,FX_PARAM_MAX);
- fx_param[p_param]=p_value;
- VS::get_singleton()->environment_fx_set_param(environment,VS::EnvironmentFxParam(p_param),p_value);
-
-}
-Variant Environment::fx_get_param(FxParam p_param) const{
-
- ERR_FAIL_INDEX_V(p_param,FX_PARAM_MAX,Variant());
- return fx_param[p_param];
-
-}
RID Environment::get_rid() const {
@@ -89,160 +37,6 @@ RID Environment::get_rid() const {
void Environment::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_background","bgmode"),&Environment::set_background);
- ObjectTypeDB::bind_method(_MD("get_background"),&Environment::get_background);
-
- ObjectTypeDB::bind_method(_MD("set_background_param","param","value"),&Environment::set_background_param);
- ObjectTypeDB::bind_method(_MD("get_background_param","param"),&Environment::get_background_param);
-
- ObjectTypeDB::bind_method(_MD("set_enable_fx","effect","enabled"),&Environment::set_enable_fx);
- ObjectTypeDB::bind_method(_MD("is_fx_enabled","effect"),&Environment::is_fx_enabled);
-
- ObjectTypeDB::bind_method(_MD("fx_set_param","param","value"),&Environment::fx_set_param);
- ObjectTypeDB::bind_method(_MD("fx_get_param","param"),&Environment::fx_get_param);
-
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"ambient_light/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_AMBIENT_LIGHT);
- ADD_PROPERTYI( PropertyInfo(Variant::COLOR,"ambient_light/color",PROPERTY_HINT_COLOR_NO_ALPHA),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_AMBIENT_LIGHT_COLOR);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"ambient_light/energy",PROPERTY_HINT_RANGE,"0,64,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_AMBIENT_LIGHT_ENERGY);
-
-
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"fxaa/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_FXAA);
-
- ADD_PROPERTY( PropertyInfo(Variant::INT,"background/mode",PROPERTY_HINT_ENUM,"Keep,Default Color,Color,Texture,Cubemap,Canvas"),_SCS("set_background"),_SCS("get_background"));
- ADD_PROPERTYI( PropertyInfo(Variant::COLOR,"background/color"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_COLOR);
- ADD_PROPERTYI( PropertyInfo(Variant::OBJECT,"background/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_TEXTURE);
- ADD_PROPERTYI( PropertyInfo(Variant::OBJECT,"background/cubemap",PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_CUBEMAP);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"background/energy",PROPERTY_HINT_RANGE,"0,128,0.01"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_ENERGY);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"background/scale",PROPERTY_HINT_RANGE,"0.001,16,0.001"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_SCALE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"background/glow",PROPERTY_HINT_RANGE,"0.00,8,0.01"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_GLOW);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"background/canvas_max_layer"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_CANVAS_MAX_LAYER);
-
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"glow/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_GLOW);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"glow/blur_passes",PROPERTY_HINT_RANGE,"1,4,1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLUR_PASSES);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"glow/blur_scale",PROPERTY_HINT_RANGE,"0.01,4,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLUR_SCALE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"glow/blur_strength",PROPERTY_HINT_RANGE,"0.01,4,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLUR_STRENGTH);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"glow/blur_blend_mode",PROPERTY_HINT_ENUM,"Additive,Screen,SoftLight"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLUR_BLEND_MODE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"glow/bloom",PROPERTY_HINT_RANGE,"0,8,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLOOM);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"glow/bloom_treshold",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLOOM_TRESHOLD);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"dof_blur/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_DOF_BLUR);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"dof_blur/blur_passes",PROPERTY_HINT_RANGE,"1,4,1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_DOF_BLUR_PASSES);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"dof_blur/begin",PROPERTY_HINT_RANGE,"0,4096,0.1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_DOF_BLUR_BEGIN);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"dof_blur/range",PROPERTY_HINT_RANGE,"0,4096,0.1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_DOF_BLUR_RANGE);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"hdr/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_HDR);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/tonemapper",PROPERTY_HINT_ENUM,"Linear,Log,Reinhardt,ReinhardtAutoWhite"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_TONEMAPPER);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/exposure",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_EXPOSURE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/white",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_WHITE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/glow_treshold",PROPERTY_HINT_RANGE,"0.00,8,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_GLOW_TRESHOLD);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/glow_scale",PROPERTY_HINT_RANGE,"0.00,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_GLOW_SCALE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/min_luminance",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_MIN_LUMINANCE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/max_luminance",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_MAX_LUMINANCE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/exposure_adj_speed",PROPERTY_HINT_RANGE,"0.001,64,0.001"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"fog/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_FOG);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"fog/begin",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_FOG_BEGIN);
- ADD_PROPERTYI( PropertyInfo(Variant::COLOR,"fog/begin_color",PROPERTY_HINT_COLOR_NO_ALPHA),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_FOG_BEGIN_COLOR);
- ADD_PROPERTYI( PropertyInfo(Variant::COLOR,"fog/end_color",PROPERTY_HINT_COLOR_NO_ALPHA),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_FOG_END_COLOR);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"fog/attenuation",PROPERTY_HINT_EXP_EASING),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_FOG_ATTENUATION);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"fog/bg"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_FOG_BG);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"bcs/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_BCS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"bcs/brightness",PROPERTY_HINT_RANGE,"0.01,8,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_BCS_BRIGHTNESS);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"bcs/contrast",PROPERTY_HINT_RANGE,"0.01,8,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_BCS_CONTRAST);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"bcs/saturation",PROPERTY_HINT_RANGE,"0.01,8,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_BCS_SATURATION);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"srgb/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_SRGB);
-
-
-
-
-
-/*
- FX_PARAM_BLOOM_GLOW_BLUR_PASSES=VS::ENV_FX_PARAM_BLOOM_GLOW_BLUR_PASSES,
- FX_PARAM_BLOOM_AMOUNT=VS::ENV_FX_PARAM_BLOOM_AMOUNT,
- FX_PARAM_DOF_BLUR_PASSES=VS::ENV_FX_PARAM_DOF_BLUR_PASSES,
- FX_PARAM_DOF_BLUR_BEGIN=VS::ENV_FX_PARAM_DOF_BLUR_BEGIN,
- FX_PARAM_DOF_BLUR_END=VS::ENV_FX_PARAM_DOF_BLUR_END,
- FX_PARAM_HDR_EXPOSURE=VS::ENV_FX_PARAM_HDR_EXPOSURE,
- FX_PARAM_HDR_WHITE=VS::ENV_FX_PARAM_HDR_WHITE,
- FX_PARAM_HDR_GLOW_TRESHOLD=VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD,
- FX_PARAM_HDR_GLOW_SCALE=VS::ENV_FX_PARAM_HDR_GLOW_SCALE,
- FX_PARAM_HDR_MIN_LUMINANCE=VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE,
- FX_PARAM_HDR_MAX_LUMINANCE=VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE,
- FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED=VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED,
- FX_PARAM_FOG_BEGIN=VS::ENV_FX_PARAM_FOG_BEGIN,
- FX_PARAM_FOG_ATTENUATION=VS::ENV_FX_PARAM_FOG_ATTENUATION,
- FX_PARAM_FOG_BEGIN_COLOR=VS::ENV_FX_PARAM_FOG_BEGIN_COLOR,
- FX_PARAM_FOG_END_COLOR=VS::ENV_FX_PARAM_FOG_END_COLOR,
- FX_PARAM_FOG_BG=VS::ENV_FX_PARAM_FOG_BG,
- FX_PARAM_GAMMA_VALUE=VS::ENV_FX_PARAM_GAMMA_VALUE,
- FX_PARAM_BRIGHTNESS_VALUE=VS::ENV_FX_PARAM_BRIGHTNESS_VALUE,
- FX_PARAM_CONTRAST_VALUE=VS::ENV_FX_PARAM_CONTRAST_VALUE,
- FX_PARAM_SATURATION_VALUE=VS::ENV_FX_PARAM_SATURATION_VALUE,
- FX_PARAM_MAX=VS::ENV_FX_PARAM_MAX
-*/
-
- BIND_CONSTANT( BG_KEEP );
- BIND_CONSTANT( BG_DEFAULT_COLOR );
- BIND_CONSTANT( BG_COLOR );
- BIND_CONSTANT( BG_TEXTURE );
- BIND_CONSTANT( BG_CUBEMAP );
- BIND_CONSTANT( BG_CANVAS );
- BIND_CONSTANT( BG_MAX );
-
- BIND_CONSTANT( BG_PARAM_CANVAS_MAX_LAYER );
- BIND_CONSTANT( BG_PARAM_COLOR );
- BIND_CONSTANT( BG_PARAM_TEXTURE );
- BIND_CONSTANT( BG_PARAM_CUBEMAP );
- BIND_CONSTANT( BG_PARAM_ENERGY );
- BIND_CONSTANT( BG_PARAM_GLOW );
- BIND_CONSTANT( BG_PARAM_MAX );
-
-
- BIND_CONSTANT( FX_AMBIENT_LIGHT );
- BIND_CONSTANT( FX_FXAA );
- BIND_CONSTANT( FX_GLOW );
- BIND_CONSTANT( FX_DOF_BLUR );
- BIND_CONSTANT( FX_HDR );
- BIND_CONSTANT( FX_FOG );
- BIND_CONSTANT( FX_BCS);
- BIND_CONSTANT( FX_SRGB );
- BIND_CONSTANT( FX_MAX );
-
-
- BIND_CONSTANT( FX_BLUR_BLEND_MODE_ADDITIVE );
- BIND_CONSTANT( FX_BLUR_BLEND_MODE_SCREEN );
- BIND_CONSTANT( FX_BLUR_BLEND_MODE_SOFTLIGHT );
-
- BIND_CONSTANT( FX_HDR_TONE_MAPPER_LINEAR );
- BIND_CONSTANT( FX_HDR_TONE_MAPPER_LOG );
- BIND_CONSTANT( FX_HDR_TONE_MAPPER_REINHARDT );
- BIND_CONSTANT( FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE );
-
- BIND_CONSTANT( FX_PARAM_AMBIENT_LIGHT_COLOR );
- BIND_CONSTANT( FX_PARAM_AMBIENT_LIGHT_ENERGY );
- BIND_CONSTANT( FX_PARAM_GLOW_BLUR_PASSES );
- BIND_CONSTANT( FX_PARAM_GLOW_BLUR_SCALE );
- BIND_CONSTANT( FX_PARAM_GLOW_BLUR_STRENGTH );
- BIND_CONSTANT( FX_PARAM_GLOW_BLUR_BLEND_MODE );
- BIND_CONSTANT( FX_PARAM_GLOW_BLOOM);
- BIND_CONSTANT( FX_PARAM_GLOW_BLOOM_TRESHOLD);
- BIND_CONSTANT( FX_PARAM_DOF_BLUR_PASSES );
- BIND_CONSTANT( FX_PARAM_DOF_BLUR_BEGIN );
- BIND_CONSTANT( FX_PARAM_DOF_BLUR_RANGE );
- BIND_CONSTANT( FX_PARAM_HDR_TONEMAPPER);
- BIND_CONSTANT( FX_PARAM_HDR_EXPOSURE );
- BIND_CONSTANT( FX_PARAM_HDR_WHITE );
- BIND_CONSTANT( FX_PARAM_HDR_GLOW_TRESHOLD );
- BIND_CONSTANT( FX_PARAM_HDR_GLOW_SCALE );
- BIND_CONSTANT( FX_PARAM_HDR_MIN_LUMINANCE );
- BIND_CONSTANT( FX_PARAM_HDR_MAX_LUMINANCE );
- BIND_CONSTANT( FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED );
- BIND_CONSTANT( FX_PARAM_FOG_BEGIN );
- BIND_CONSTANT( FX_PARAM_FOG_ATTENUATION );
- BIND_CONSTANT( FX_PARAM_FOG_BEGIN_COLOR );
- BIND_CONSTANT( FX_PARAM_FOG_END_COLOR );
- BIND_CONSTANT( FX_PARAM_FOG_BG );
- BIND_CONSTANT( FX_PARAM_BCS_BRIGHTNESS );
- BIND_CONSTANT( FX_PARAM_BCS_CONTRAST );
- BIND_CONSTANT( FX_PARAM_BCS_SATURATION );
- BIND_CONSTANT( FX_PARAM_MAX );
}
@@ -250,45 +44,8 @@ Environment::Environment() {
environment = VS::get_singleton()->environment_create();
- set_background(BG_DEFAULT_COLOR);
- set_background_param(BG_PARAM_COLOR,Color(0,0,0));
- set_background_param(BG_PARAM_TEXTURE,Ref<ImageTexture>());
- set_background_param(BG_PARAM_CUBEMAP,Ref<CubeMap>());
- set_background_param(BG_PARAM_ENERGY,1.0);
- set_background_param(BG_PARAM_SCALE,1.0);
- set_background_param(BG_PARAM_GLOW,0.0);
-
- for(int i=0;i<FX_MAX;i++)
- set_enable_fx(Fx(i),false);
-
- fx_set_param(FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0,0,0));
- fx_set_param(FX_PARAM_AMBIENT_LIGHT_ENERGY,1.0);
- fx_set_param(FX_PARAM_GLOW_BLUR_PASSES,1);
- fx_set_param(FX_PARAM_GLOW_BLUR_SCALE,1);
- fx_set_param(FX_PARAM_GLOW_BLUR_STRENGTH,1);
- fx_set_param(FX_PARAM_GLOW_BLOOM,0.0);
- fx_set_param(FX_PARAM_GLOW_BLOOM_TRESHOLD,0.5);
- fx_set_param(FX_PARAM_DOF_BLUR_PASSES,1);
- fx_set_param(FX_PARAM_DOF_BLUR_BEGIN,100.0);
- fx_set_param(FX_PARAM_DOF_BLUR_RANGE,10.0);
- fx_set_param(FX_PARAM_HDR_TONEMAPPER,FX_HDR_TONE_MAPPER_LINEAR);
- fx_set_param(FX_PARAM_HDR_EXPOSURE,0.4);
- fx_set_param(FX_PARAM_HDR_WHITE,1.0);
- fx_set_param(FX_PARAM_HDR_GLOW_TRESHOLD,0.95);
- fx_set_param(FX_PARAM_HDR_GLOW_SCALE,0.2);
- fx_set_param(FX_PARAM_HDR_MIN_LUMINANCE,0.4);
- fx_set_param(FX_PARAM_HDR_MAX_LUMINANCE,8.0);
- fx_set_param(FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED,0.5);
- fx_set_param(FX_PARAM_FOG_BEGIN,100.0);
- fx_set_param(FX_PARAM_FOG_ATTENUATION,1.0);
- fx_set_param(FX_PARAM_FOG_BEGIN_COLOR,Color(0,0,0));
- fx_set_param(FX_PARAM_FOG_END_COLOR,Color(0,0,0));
- fx_set_param(FX_PARAM_FOG_BG,true);
- fx_set_param(FX_PARAM_BCS_BRIGHTNESS,1.0);
- fx_set_param(FX_PARAM_BCS_CONTRAST,1.0);
- fx_set_param(FX_PARAM_BCS_SATURATION,1.0);
-
}
+
Environment::~Environment() {
VS::get_singleton()->free(environment);
diff --git a/scene/resources/environment.h b/scene/resources/environment.h
index a72cc6a47f..f8ea0cb36f 100644
--- a/scene/resources/environment.h
+++ b/scene/resources/environment.h
@@ -37,107 +37,16 @@ class Environment : public Resource {
OBJ_TYPE(Environment,Resource);
public:
- enum BG {
- BG_KEEP=VS::ENV_BG_KEEP,
- BG_DEFAULT_COLOR=VS::ENV_BG_DEFAULT_COLOR,
- BG_COLOR=VS::ENV_BG_COLOR,
- BG_TEXTURE=VS::ENV_BG_TEXTURE,
- BG_CUBEMAP=VS::ENV_BG_CUBEMAP,
- BG_CANVAS=VS::ENV_BG_CANVAS,
- BG_MAX=VS::ENV_BG_MAX
- };
-
- enum BGParam {
-
- BG_PARAM_CANVAS_MAX_LAYER=VS::ENV_BG_PARAM_CANVAS_MAX_LAYER,
- BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR,
- BG_PARAM_TEXTURE=VS::ENV_BG_PARAM_TEXTURE,
- BG_PARAM_CUBEMAP=VS::ENV_BG_PARAM_CUBEMAP,
- BG_PARAM_ENERGY=VS::ENV_BG_PARAM_ENERGY,
- BG_PARAM_SCALE=VS::ENV_BG_PARAM_SCALE,
- BG_PARAM_GLOW=VS::ENV_BG_PARAM_GLOW,
- BG_PARAM_MAX=VS::ENV_BG_PARAM_MAX
- };
-
- enum Fx {
- FX_AMBIENT_LIGHT=VS::ENV_FX_AMBIENT_LIGHT,
- FX_FXAA=VS::ENV_FX_FXAA,
- FX_GLOW=VS::ENV_FX_GLOW,
- FX_DOF_BLUR=VS::ENV_FX_DOF_BLUR,
- FX_HDR=VS::ENV_FX_HDR,
- FX_FOG=VS::ENV_FX_FOG,
- FX_BCS=VS::ENV_FX_BCS,
- FX_SRGB=VS::ENV_FX_SRGB,
- FX_MAX=VS::ENV_FX_MAX,
- };
-
- enum FxBlurBlendMode {
- FX_BLUR_BLEND_MODE_ADDITIVE,
- FX_BLUR_BLEND_MODE_SCREEN,
- FX_BLUR_BLEND_MODE_SOFTLIGHT,
- };
-
- enum FxHDRToneMapper {
- FX_HDR_TONE_MAPPER_LINEAR,
- FX_HDR_TONE_MAPPER_LOG,
- FX_HDR_TONE_MAPPER_REINHARDT,
- FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE,
- };
-
- enum FxParam {
- FX_PARAM_AMBIENT_LIGHT_COLOR=VS::ENV_FX_PARAM_AMBIENT_LIGHT_COLOR,
- FX_PARAM_AMBIENT_LIGHT_ENERGY=VS::ENV_FX_PARAM_AMBIENT_LIGHT_ENERGY,
- FX_PARAM_GLOW_BLUR_PASSES=VS::ENV_FX_PARAM_GLOW_BLUR_PASSES,
- FX_PARAM_GLOW_BLUR_SCALE=VS::ENV_FX_PARAM_GLOW_BLUR_SCALE,
- FX_PARAM_GLOW_BLUR_STRENGTH=VS::ENV_FX_PARAM_GLOW_BLUR_STRENGTH,
- FX_PARAM_GLOW_BLUR_BLEND_MODE=VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE,
- FX_PARAM_GLOW_BLOOM=VS::ENV_FX_PARAM_GLOW_BLOOM,
- FX_PARAM_GLOW_BLOOM_TRESHOLD=VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD,
- FX_PARAM_DOF_BLUR_PASSES=VS::ENV_FX_PARAM_DOF_BLUR_PASSES,
- FX_PARAM_DOF_BLUR_BEGIN=VS::ENV_FX_PARAM_DOF_BLUR_BEGIN,
- FX_PARAM_DOF_BLUR_RANGE=VS::ENV_FX_PARAM_DOF_BLUR_RANGE,
- FX_PARAM_HDR_EXPOSURE=VS::ENV_FX_PARAM_HDR_EXPOSURE,
- FX_PARAM_HDR_TONEMAPPER=VS::ENV_FX_PARAM_HDR_TONEMAPPER,
- FX_PARAM_HDR_WHITE=VS::ENV_FX_PARAM_HDR_WHITE,
- FX_PARAM_HDR_GLOW_TRESHOLD=VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD,
- FX_PARAM_HDR_GLOW_SCALE=VS::ENV_FX_PARAM_HDR_GLOW_SCALE,
- FX_PARAM_HDR_MIN_LUMINANCE=VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE,
- FX_PARAM_HDR_MAX_LUMINANCE=VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE,
- FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED=VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED,
- FX_PARAM_FOG_BEGIN=VS::ENV_FX_PARAM_FOG_BEGIN,
- FX_PARAM_FOG_BEGIN_COLOR=VS::ENV_FX_PARAM_FOG_BEGIN_COLOR,
- FX_PARAM_FOG_END_COLOR=VS::ENV_FX_PARAM_FOG_END_COLOR,
- FX_PARAM_FOG_ATTENUATION=VS::ENV_FX_PARAM_FOG_ATTENUATION,
- FX_PARAM_FOG_BG=VS::ENV_FX_PARAM_FOG_BG,
- FX_PARAM_BCS_BRIGHTNESS=VS::ENV_FX_PARAM_BCS_BRIGHTNESS,
- FX_PARAM_BCS_CONTRAST=VS::ENV_FX_PARAM_BCS_CONTRAST,
- FX_PARAM_BCS_SATURATION=VS::ENV_FX_PARAM_BCS_SATURATION,
- FX_PARAM_MAX=VS::ENV_FX_PARAM_MAX
- };
private:
- BG bg_mode;
- Variant bg_param[BG_PARAM_MAX];
- bool fx_enabled[FX_MAX];
- Variant fx_param[FX_PARAM_MAX];
+
RID environment;
protected:
static void _bind_methods();
public:
- void set_background(BG p_bg);
- BG get_background() const;
-
- void set_background_param(BGParam p_param, const Variant& p_value);
- Variant get_background_param(BGParam p_param) const;
-
- void set_enable_fx(Fx p_effect,bool p_enabled);
- bool is_fx_enabled(Fx p_effect) const;
-
- void fx_set_param(FxParam p_param,const Variant& p_value);
- Variant fx_get_param(FxParam p_param) const;
virtual RID get_rid() const;
@@ -145,9 +54,5 @@ public:
~Environment();
};
-VARIANT_ENUM_CAST( Environment::BG );
-VARIANT_ENUM_CAST( Environment::BGParam );
-VARIANT_ENUM_CAST( Environment::Fx );
-VARIANT_ENUM_CAST( Environment::FxParam );
#endif // ENVIRONMENT_H
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 9dc54ef0e4..3ebe5b7800 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -29,144 +29,14 @@
#include "material.h"
#include "scene/scene_string_names.h"
-
-static const char*_flag_names[Material::FLAG_MAX]={
- "visible",
- "double_sided",
- "invert_faces",
- "unshaded",
- "on_top",
- "lightmap_on_uv2",
- "colarray_is_srgb"
-};
-
-
-static const Material::Flag _flag_indices[Material::FLAG_MAX]={
- Material::FLAG_VISIBLE,
- Material::FLAG_DOUBLE_SIDED,
- Material::FLAG_INVERT_FACES,
- Material::FLAG_UNSHADED,
- Material::FLAG_ONTOP,
- Material::FLAG_LIGHTMAP_ON_UV2,
- Material::FLAG_COLOR_ARRAY_SRGB,
-};
-
-
RID Material::get_rid() const {
return material;
}
-void Material::set_flag(Flag p_flag,bool p_enabled) {
-
- ERR_FAIL_INDEX(p_flag,FLAG_MAX);
- flags[p_flag]=p_enabled;
- VisualServer::get_singleton()->material_set_flag(material,(VS::MaterialFlag)p_flag,p_enabled);
- _change_notify();
-}
-
-
-void Material::set_blend_mode(BlendMode p_blend_mode) {
-
- ERR_FAIL_INDEX(p_blend_mode,4);
- blend_mode=p_blend_mode;
- VisualServer::get_singleton()->material_set_blend_mode(material,(VS::MaterialBlendMode)p_blend_mode);
- _change_notify();
-}
-
-Material::BlendMode Material::get_blend_mode() const {
-
- return blend_mode;
-}
-
-
-void Material::set_depth_draw_mode(DepthDrawMode p_depth_draw_mode) {
-
- depth_draw_mode=p_depth_draw_mode;
- VisualServer::get_singleton()->material_set_depth_draw_mode(material,(VS::MaterialDepthDrawMode)p_depth_draw_mode);
-}
-
-Material::DepthDrawMode Material::get_depth_draw_mode() const {
-
- return depth_draw_mode;
-}
-
-bool Material::get_flag(Flag p_flag) const {
-
- ERR_FAIL_INDEX_V(p_flag,FLAG_MAX,false);
- return flags[p_flag];
-}
-
-void Material::set_line_width(float p_width) {
-
- line_width=p_width;
- VisualServer::get_singleton()->material_set_line_width(material,p_width);
- _change_notify("line_width");
-}
-
-float Material::get_line_width() const {
-
- return line_width;
-}
-
-
-void Material::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("set_flag","flag","enable"),&Material::set_flag);
- ObjectTypeDB::bind_method(_MD("get_flag","flag"),&Material::get_flag);
- ObjectTypeDB::bind_method(_MD("set_blend_mode","mode"),&Material::set_blend_mode);
- ObjectTypeDB::bind_method(_MD("get_blend_mode"),&Material::get_blend_mode);
- ObjectTypeDB::bind_method(_MD("set_line_width","width"),&Material::set_line_width);
- ObjectTypeDB::bind_method(_MD("get_line_width"),&Material::get_line_width);
- ObjectTypeDB::bind_method(_MD("set_depth_draw_mode","mode"),&Material::set_depth_draw_mode);
- ObjectTypeDB::bind_method(_MD("get_depth_draw_mode"),&Material::get_depth_draw_mode);
-
-
- for(int i=0;i<FLAG_MAX;i++)
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, String()+"flags/"+_flag_names[i] ),_SCS("set_flag"),_SCS("get_flag"),_flag_indices[i]);
-
- ADD_PROPERTY( PropertyInfo( Variant::INT, "params/blend_mode",PROPERTY_HINT_ENUM,"Mix,Add,Sub,PMAlpha" ), _SCS("set_blend_mode"),_SCS("get_blend_mode"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "params/depth_draw",PROPERTY_HINT_ENUM,"Always,Opaque Only,Pre-Pass Alpha,Never" ), _SCS("set_depth_draw_mode"),_SCS("get_depth_draw_mode"));
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/line_width",PROPERTY_HINT_RANGE,"0.1,32.0,0.1" ), _SCS("set_line_width"),_SCS("get_line_width"));
-
- BIND_CONSTANT( FLAG_VISIBLE );
- BIND_CONSTANT( FLAG_DOUBLE_SIDED );
- BIND_CONSTANT( FLAG_INVERT_FACES );
- BIND_CONSTANT( FLAG_UNSHADED );
- BIND_CONSTANT( FLAG_ONTOP );
- BIND_CONSTANT( FLAG_LIGHTMAP_ON_UV2 );
- BIND_CONSTANT( FLAG_COLOR_ARRAY_SRGB );
- BIND_CONSTANT( FLAG_MAX );
-
- BIND_CONSTANT( DEPTH_DRAW_ALWAYS );
- BIND_CONSTANT( DEPTH_DRAW_OPAQUE_ONLY );
- BIND_CONSTANT( DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA );
- BIND_CONSTANT( DEPTH_DRAW_NEVER );
-
- BIND_CONSTANT( BLEND_MODE_MIX );
- BIND_CONSTANT( BLEND_MODE_ADD );
- BIND_CONSTANT( BLEND_MODE_SUB );
- BIND_CONSTANT( BLEND_MODE_MUL );
- BIND_CONSTANT( BLEND_MODE_PREMULT_ALPHA );
-
-}
-
-Material::Material(const RID& p_material) {
-
- material=p_material;
-
- flags[FLAG_VISIBLE]=true;
- flags[FLAG_DOUBLE_SIDED]=false;
- flags[FLAG_INVERT_FACES]=false;
- flags[FLAG_UNSHADED]=false;
- flags[FLAG_ONTOP]=false;
- flags[FLAG_LIGHTMAP_ON_UV2]=true;
- flags[FLAG_COLOR_ARRAY_SRGB]=false;
-
- depth_draw_mode=DEPTH_DRAW_OPAQUE_ONLY;
-
- blend_mode=BLEND_MODE_MIX;
+Material::Material() {
+ material=VisualServer::get_singleton()->material_create();
}
Material::~Material() {
@@ -174,431 +44,15 @@ Material::~Material() {
VisualServer::get_singleton()->free(material);
}
-static const char*_param_names[FixedMaterial::PARAM_MAX]={
- "diffuse",
- "detail",
- "specular",
- "emission",
- "specular_exp",
- "glow",
- "normal",
- "shade_param"
-};
-
-static const char*_full_param_names[FixedMaterial::PARAM_MAX]={
- "params/diffuse",
- "params/detail",
- "params/specular",
- "params/emission",
- "params/specular_exp",
- "params/glow",
- "params/normal",
- "params/shade_param"
-};
-
-/*
-static const char*_texture_param_names[FixedMaterial::PARAM_MAX]={
- "tex_diffuse",
- "tex_detail",
- "tex_specular",
- "tex_emission",
- "tex_specular_exp",
- "tex_glow",
- "tex_detail_mix",
- "tex_normal",
- "tex_shade_param"
-};
-*/
-static const FixedMaterial::Parameter _param_indices[FixedMaterial::PARAM_MAX]={
- FixedMaterial::PARAM_DIFFUSE,
- FixedMaterial::PARAM_DETAIL,
- FixedMaterial::PARAM_SPECULAR,
- FixedMaterial::PARAM_EMISSION,
- FixedMaterial::PARAM_SPECULAR_EXP,
- FixedMaterial::PARAM_GLOW,
- FixedMaterial::PARAM_NORMAL,
- FixedMaterial::PARAM_SHADE_PARAM,
-};
-
-
-
-
-void FixedMaterial::set_parameter(Parameter p_parameter, const Variant& p_value) {
-
- ERR_FAIL_INDEX(p_parameter,PARAM_MAX);
- if ((p_parameter==PARAM_DIFFUSE || p_parameter==PARAM_SPECULAR || p_parameter==PARAM_EMISSION)) {
-
- if (p_value.get_type()!=Variant::COLOR) {
- ERR_EXPLAIN(String(_param_names[p_parameter])+" expects Color");
- ERR_FAIL();
- }
- } else {
-
- if (!p_value.is_num()) {
- ERR_EXPLAIN(String(_param_names[p_parameter])+" expects scalar");
- ERR_FAIL();
- }
- }
-
- ERR_FAIL_COND( (p_parameter==PARAM_DIFFUSE || p_parameter==PARAM_SPECULAR || p_parameter==PARAM_EMISSION) && p_value.get_type()!=Variant::COLOR );
- ERR_FAIL_COND( p_parameter!=PARAM_SHADE_PARAM && p_parameter!=PARAM_DIFFUSE && p_parameter!=PARAM_DETAIL && p_parameter!=PARAM_SPECULAR && p_parameter!=PARAM_EMISSION && p_value.get_type()!=Variant::REAL && p_value.get_type()!=Variant::INT );
-
- param[p_parameter]=p_value;
-
- VisualServer::get_singleton()->fixed_material_set_param(material,(VS::FixedMaterialParam)p_parameter,p_value);
-
- _change_notify(_full_param_names[p_parameter]);
-}
-
-Variant FixedMaterial::get_parameter(Parameter p_parameter) const {
- ERR_FAIL_INDEX_V(p_parameter,PARAM_MAX,Variant());
- return param[p_parameter];
-}
-
-
-
-void FixedMaterial::set_texture(Parameter p_parameter, Ref<Texture> p_texture) {
-
- ERR_FAIL_INDEX(p_parameter,PARAM_MAX);
-
- texture_param[p_parameter]=p_texture;
- VisualServer::get_singleton()->fixed_material_set_texture(material,(VS::FixedMaterialParam)p_parameter,p_texture.is_null()?RID():p_texture->get_rid());
-
- _change_notify();
-}
-Ref<Texture> FixedMaterial::get_texture(Parameter p_parameter) const {
-
- ERR_FAIL_INDEX_V(p_parameter,PARAM_MAX,Ref<Texture>());
- return texture_param[p_parameter];
-}
-
-void FixedMaterial::set_texcoord_mode(Parameter p_parameter, TexCoordMode p_mode) {
-
- ERR_FAIL_INDEX(p_parameter,PARAM_MAX);
- ERR_FAIL_INDEX(p_mode,4);
-
- if (p_mode==texture_texcoord[p_parameter])
- return;
-
- texture_texcoord[p_parameter]=p_mode;
-
- VisualServer::get_singleton()->fixed_material_set_texcoord_mode(material,(VS::FixedMaterialParam)p_parameter,(VS::FixedMaterialTexCoordMode)p_mode);
-
- _change_notify();
-}
-
-FixedMaterial::TexCoordMode FixedMaterial::get_texcoord_mode(Parameter p_parameter) const {
-
- ERR_FAIL_INDEX_V(p_parameter,PARAM_MAX,TEXCOORD_UV);
- return texture_texcoord[p_parameter];
-}
-
-void FixedMaterial::set_light_shader(LightShader p_shader) {
-
- light_shader=p_shader;
- VS::get_singleton()->fixed_material_set_light_shader(material,VS::FixedMaterialLightShader(p_shader));
-}
-
-FixedMaterial::LightShader FixedMaterial::get_light_shader() const {
-
- return light_shader;
-}
-
-
-void FixedMaterial::set_uv_transform(const Transform& p_transform) {
-
- uv_transform=p_transform;
- VisualServer::get_singleton()->fixed_material_set_uv_transform(material, p_transform );
- _change_notify();
-}
-
-Transform FixedMaterial::get_uv_transform() const {
-
- return uv_transform;
-}
-
-
-
-
-
-void FixedMaterial::set_fixed_flag(FixedFlag p_flag, bool p_value) {
- ERR_FAIL_INDEX(p_flag,5);
- fixed_flags[p_flag]=p_value;
- VisualServer::get_singleton()->fixed_material_set_flag(material,(VS::FixedMaterialFlags)p_flag,p_value);
-
-}
-
-bool FixedMaterial::get_fixed_flag(FixedFlag p_flag) const {
- ERR_FAIL_INDEX_V(p_flag,5,false);
- return fixed_flags[p_flag];
-}
-
-void FixedMaterial::set_point_size(float p_size) {
-
- ERR_FAIL_COND(p_size<0);
- point_size=p_size;
- VisualServer::get_singleton()->fixed_material_set_point_size(material,p_size);
-}
-
-float FixedMaterial::get_point_size() const{
-
-
- return point_size;
-}
-
-
-void FixedMaterial::_bind_methods() {
-
-
- ObjectTypeDB::bind_method(_MD("set_parameter","param","value"),&FixedMaterial::set_parameter);
- ObjectTypeDB::bind_method(_MD("get_parameter","param"),&FixedMaterial::get_parameter);
-
- ObjectTypeDB::bind_method(_MD("set_texture","param","texture:Texture"),&FixedMaterial::set_texture);
- ObjectTypeDB::bind_method(_MD("get_texture:Texture","param"),&FixedMaterial::get_texture);
+FixedMaterial::FixedMaterial() {
- ObjectTypeDB::bind_method(_MD("set_texcoord_mode","param","mode"),&FixedMaterial::set_texcoord_mode);
- ObjectTypeDB::bind_method(_MD("get_texcoord_mode","param"),&FixedMaterial::get_texcoord_mode);
-
- ObjectTypeDB::bind_method(_MD("set_fixed_flag","flag","value"),&FixedMaterial::set_fixed_flag);
- ObjectTypeDB::bind_method(_MD("get_fixed_flag","flag"),&FixedMaterial::get_fixed_flag);
-
- ObjectTypeDB::bind_method(_MD("set_uv_transform","transform"),&FixedMaterial::set_uv_transform);
- ObjectTypeDB::bind_method(_MD("get_uv_transform"),&FixedMaterial::get_uv_transform);
-
- ObjectTypeDB::bind_method(_MD("set_light_shader","shader"),&FixedMaterial::set_light_shader);
- ObjectTypeDB::bind_method(_MD("get_light_shader"),&FixedMaterial::get_light_shader);
-
- ObjectTypeDB::bind_method(_MD("set_point_size","size"),&FixedMaterial::set_point_size);
- ObjectTypeDB::bind_method(_MD("get_point_size"),&FixedMaterial::get_point_size);
-
-
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/use_alpha" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_USE_ALPHA);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/use_color_array" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_USE_COLOR_ARRAY);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/use_point_size" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_USE_POINT_SIZE);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/discard_alpha" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_DISCARD_ALPHA);
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/use_xy_normalmap" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_USE_XY_NORMALMAP);
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "params/diffuse" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_DIFFUSE);
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "params/specular", PROPERTY_HINT_COLOR_NO_ALPHA ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SPECULAR );
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "params/emission", PROPERTY_HINT_COLOR_NO_ALPHA ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_EMISSION );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/specular_exp", PROPERTY_HINT_RANGE,"1,64,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SPECULAR_EXP );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/detail_mix", PROPERTY_HINT_RANGE,"0,1,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_DETAIL );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/normal_depth", PROPERTY_HINT_RANGE,"-4,4,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_NORMAL );
- ADD_PROPERTY( PropertyInfo( Variant::INT, "params/shader", PROPERTY_HINT_ENUM,"Lambert,Wrap,Velvet,Toon" ), _SCS("set_light_shader"), _SCS("get_light_shader") );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/shader_param", PROPERTY_HINT_RANGE,"0,1,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADE_PARAM );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/glow", PROPERTY_HINT_RANGE,"0,8,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_GLOW );
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/point_size", PROPERTY_HINT_RANGE,"0,1024,1" ), _SCS("set_point_size"), _SCS("get_point_size"));
- ADD_PROPERTY( PropertyInfo( Variant::TRANSFORM, "uv_xform"), _SCS("set_uv_transform"), _SCS("get_uv_transform") );
-
- for(int i=0;i<PARAM_MAX;i++) {
- ADD_PROPERTYI( PropertyInfo( Variant::OBJECT, String()+"textures/"+_param_names[i],PROPERTY_HINT_RESOURCE_TYPE,"Texture" ), _SCS("set_texture"), _SCS("get_texture"), _param_indices[i]);
- ADD_PROPERTYI( PropertyInfo( Variant::INT, String()+"textures/"+_param_names[i]+"_tc",PROPERTY_HINT_ENUM,"UV,UV Xform,UV2,Sphere" ), _SCS("set_texcoord_mode"), _SCS("get_texcoord_mode"), _param_indices[i] );
- }
-
-
- BIND_CONSTANT( PARAM_DIFFUSE );
- BIND_CONSTANT( PARAM_DETAIL );
- BIND_CONSTANT( PARAM_SPECULAR );
- BIND_CONSTANT( PARAM_EMISSION );
- BIND_CONSTANT( PARAM_SPECULAR_EXP );
- BIND_CONSTANT( PARAM_GLOW );
- BIND_CONSTANT( PARAM_NORMAL );
- BIND_CONSTANT( PARAM_SHADE_PARAM );
- BIND_CONSTANT( PARAM_MAX );
-
- BIND_CONSTANT( TEXCOORD_UV );
- BIND_CONSTANT( TEXCOORD_UV_TRANSFORM );
- BIND_CONSTANT( TEXCOORD_UV2 );
- BIND_CONSTANT( TEXCOORD_SPHERE );
-
- BIND_CONSTANT( FLAG_USE_ALPHA );
- BIND_CONSTANT( FLAG_USE_COLOR_ARRAY );
- BIND_CONSTANT( FLAG_USE_POINT_SIZE );
- BIND_CONSTANT( FLAG_DISCARD_ALPHA );
-
- BIND_CONSTANT( LIGHT_SHADER_LAMBERT );
- BIND_CONSTANT( LIGHT_SHADER_WRAP );
- BIND_CONSTANT( LIGHT_SHADER_VELVET );
- BIND_CONSTANT( LIGHT_SHADER_TOON );
}
-
-FixedMaterial::FixedMaterial() : Material(VS::get_singleton()->fixed_material_create()) {
-
-
-
- param[PARAM_DIFFUSE]=Color(1,1,1);
- param[PARAM_SPECULAR]=Color(0.0,0.0,0.0);
- param[PARAM_EMISSION]=Color(0.0,0.0,0.0);
- param[PARAM_SPECULAR_EXP]=40;
- param[PARAM_GLOW]=0;
- param[PARAM_NORMAL]=1;
- param[PARAM_SHADE_PARAM]=0.5;
- param[PARAM_DETAIL]=1.0;
-
- set_flag(FLAG_COLOR_ARRAY_SRGB,true);
-
- fixed_flags[FLAG_USE_ALPHA]=false;
- fixed_flags[FLAG_USE_COLOR_ARRAY]=false;
- fixed_flags[FLAG_USE_POINT_SIZE]=false;
- fixed_flags[FLAG_USE_XY_NORMALMAP]=false;
- fixed_flags[FLAG_DISCARD_ALPHA]=false;
-
-
- for(int i=0;i<PARAM_MAX;i++) {
-
- texture_texcoord[i]=TEXCOORD_UV;
- }
-
- light_shader=LIGHT_SHADER_LAMBERT;
-
- point_size=1.0;
-}
-
-
FixedMaterial::~FixedMaterial() {
-}
-
-
-
-
-bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) {
-
- if (p_name==SceneStringNames::get_singleton()->shader_shader) {
- set_shader(p_value);
- return true;
- } else {
-
- if (shader.is_valid()) {
-
-
- StringName pr = shader->remap_param(p_name);
- if (!pr) {
- String n = p_name;
- if (n.find("param/")==0) { //backwards compatibility
- pr = n.substr(6,n.length());
- }
- }
- if (pr) {
- VisualServer::get_singleton()->material_set_param(material,pr,p_value);
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool ShaderMaterial::_get(const StringName& p_name,Variant &r_ret) const {
-
- if (p_name==SceneStringNames::get_singleton()->shader_shader) {
-
- r_ret=get_shader();
- return true;
- } else {
-
- if (shader.is_valid()) {
-
- StringName pr = shader->remap_param(p_name);
- if (pr) {
- r_ret=VisualServer::get_singleton()->material_get_param(material,pr);
- return true;
- }
- }
-
- }
-
-
- return false;
-}
-
-
-void ShaderMaterial::_get_property_list( List<PropertyInfo> *p_list) const {
-
- p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"MaterialShader,MaterialShaderGraph" ) );
-
- if (!shader.is_null()) {
-
- shader->get_param_list(p_list);
- }
-
-}
-
-
-void ShaderMaterial::_shader_changed() {
-
- _change_notify(); //also all may have changed then
-}
-
-void ShaderMaterial::set_shader(const Ref<Shader>& p_shader) {
-
- ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_MATERIAL);
-
- if (shader.is_valid())
- shader->disconnect(SceneStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_shader_changed);
- shader=p_shader;
- VS::get_singleton()->material_set_shader(material,shader.is_valid()?shader->get_rid():RID());
- if (shader.is_valid()) {
- shader->connect(SceneStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_shader_changed);
- }
- _change_notify();
-
-}
-
-Ref<Shader> ShaderMaterial::get_shader() const {
-
- return shader;
}
-
-void ShaderMaterial::set_shader_param(const StringName& p_param,const Variant& p_value) {
-
- VisualServer::get_singleton()->material_set_param(material,p_param,p_value);
-
-}
-
-Variant ShaderMaterial::get_shader_param(const StringName& p_param) const{
-
- return VisualServer::get_singleton()->material_get_param(material,p_param);
-}
-
-
-
-void ShaderMaterial::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"), &ShaderMaterial::set_shader );
- ObjectTypeDB::bind_method(_MD("get_shader:Shader"), &ShaderMaterial::get_shader );
-
- ObjectTypeDB::bind_method(_MD("set_shader_param","param","value:Variant"), &ShaderMaterial::set_shader_param);
- ObjectTypeDB::bind_method(_MD("get_shader_param:Variant","param"), &ShaderMaterial::get_shader_param);
-
- ObjectTypeDB::bind_method(_MD("_shader_changed"), &ShaderMaterial::_shader_changed );
-}
-
-
-void ShaderMaterial::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
-
- String f = p_function.operator String();
- if ((f=="get_shader_param" || f=="set_shader_param") && p_idx==0) {
-
- if (shader.is_valid()) {
- List<PropertyInfo> pl;
- shader->get_param_list(&pl);
- for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
- r_options->push_back("\""+E->get().name.replace_first("shader_param/","")+"\"");
- }
- }
- }
- Material::get_argument_options(p_function,p_idx,r_options);
-}
-
-ShaderMaterial::ShaderMaterial() :Material(VisualServer::get_singleton()->material_create()){
-
-
-}
-
-
/////////////////////////////////
diff --git a/scene/resources/material.h b/scene/resources/material.h
index dbd05c466f..87afa60ce9 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -45,209 +45,27 @@ class Material : public Resource {
RES_BASE_EXTENSION("mtl");
OBJ_SAVE_TYPE( Material );
-public:
-
- enum Flag {
- FLAG_VISIBLE = VS::MATERIAL_FLAG_VISIBLE,
- FLAG_DOUBLE_SIDED = VS::MATERIAL_FLAG_DOUBLE_SIDED,
- FLAG_INVERT_FACES = VS::MATERIAL_FLAG_INVERT_FACES,
- FLAG_UNSHADED = VS::MATERIAL_FLAG_UNSHADED,
- FLAG_ONTOP = VS::MATERIAL_FLAG_ONTOP,
- FLAG_LIGHTMAP_ON_UV2 = VS::MATERIAL_FLAG_LIGHTMAP_ON_UV2,
- FLAG_COLOR_ARRAY_SRGB = VS::MATERIAL_FLAG_COLOR_ARRAY_SRGB,
- FLAG_MAX = VS::MATERIAL_FLAG_MAX
- };
-
- enum BlendMode {
- BLEND_MODE_MIX = VS::MATERIAL_BLEND_MODE_MIX,
- BLEND_MODE_MUL = VS::MATERIAL_BLEND_MODE_MUL,
- BLEND_MODE_ADD = VS::MATERIAL_BLEND_MODE_ADD,
- BLEND_MODE_SUB = VS::MATERIAL_BLEND_MODE_SUB,
- BLEND_MODE_PREMULT_ALPHA = VS::MATERIAL_BLEND_MODE_PREMULT_ALPHA,
-
- };
-
- enum DepthDrawMode {
- DEPTH_DRAW_ALWAYS = VS::MATERIAL_DEPTH_DRAW_ALWAYS,
- DEPTH_DRAW_OPAQUE_ONLY = VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY,
- DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA = VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA,
- DEPTH_DRAW_NEVER = VS::MATERIAL_DEPTH_DRAW_NEVER
- };
-
-
-
-private:
- BlendMode blend_mode;
- bool flags[VS::MATERIAL_FLAG_MAX];
- float line_width;
- DepthDrawMode depth_draw_mode;
-protected:
RID material;
-
- static void _bind_methods();
-
public:
- void set_flag(Flag p_flag,bool p_enabled);
- bool get_flag(Flag p_flag) const;
-
- void set_blend_mode(BlendMode p_blend_mode);
- BlendMode get_blend_mode() const;
-
- void set_depth_draw_mode(DepthDrawMode p_depth_draw_mode);
- DepthDrawMode get_depth_draw_mode() const;
-
- void set_line_width(float p_width);
- float get_line_width() const;
virtual RID get_rid() const;
-
- Material(const RID& p_rid=RID());
+ Material();
virtual ~Material();
};
-VARIANT_ENUM_CAST( Material::Flag );
-VARIANT_ENUM_CAST( Material::DepthDrawMode );
-
-VARIANT_ENUM_CAST( Material::BlendMode );
-
class FixedMaterial : public Material {
- OBJ_TYPE( FixedMaterial, Material );
- REVERSE_GET_PROPERTY_LIST
-public:
-
- enum Parameter {
- PARAM_DIFFUSE=VS::FIXED_MATERIAL_PARAM_DIFFUSE,
- PARAM_DETAIL=VS::FIXED_MATERIAL_PARAM_DETAIL,
- PARAM_SPECULAR=VS::FIXED_MATERIAL_PARAM_SPECULAR,
- PARAM_EMISSION=VS::FIXED_MATERIAL_PARAM_EMISSION,
- PARAM_SPECULAR_EXP=VS::FIXED_MATERIAL_PARAM_SPECULAR_EXP,
- PARAM_GLOW=VS::FIXED_MATERIAL_PARAM_GLOW,
- PARAM_NORMAL=VS::FIXED_MATERIAL_PARAM_NORMAL,
- PARAM_SHADE_PARAM=VS::FIXED_MATERIAL_PARAM_SHADE_PARAM,
- PARAM_MAX=VS::FIXED_MATERIAL_PARAM_MAX
- };
-
-
- enum TexCoordMode {
-
- TEXCOORD_UV=VS::FIXED_MATERIAL_TEXCOORD_UV,
- TEXCOORD_UV_TRANSFORM=VS::FIXED_MATERIAL_TEXCOORD_UV_TRANSFORM,
- TEXCOORD_UV2=VS::FIXED_MATERIAL_TEXCOORD_UV2,
- TEXCOORD_SPHERE=VS::FIXED_MATERIAL_TEXCOORD_SPHERE
- };
-
- enum FixedFlag {
- FLAG_USE_ALPHA=VS::FIXED_MATERIAL_FLAG_USE_ALPHA,
- FLAG_USE_COLOR_ARRAY=VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,
- FLAG_USE_POINT_SIZE=VS::FIXED_MATERIAL_FLAG_USE_POINT_SIZE,
- FLAG_DISCARD_ALPHA=VS::FIXED_MATERIAL_FLAG_DISCARD_ALPHA,
- FLAG_USE_XY_NORMALMAP=VS::FIXED_MATERIAL_FLAG_USE_XY_NORMALMAP,
- FLAG_MAX=VS::FIXED_MATERIAL_FLAG_MAX
- };
-
- enum LightShader {
-
- LIGHT_SHADER_LAMBERT=VS::FIXED_MATERIAL_LIGHT_SHADER_LAMBERT,
- LIGHT_SHADER_WRAP=VS::FIXED_MATERIAL_LIGHT_SHADER_WRAP,
- LIGHT_SHADER_VELVET=VS::FIXED_MATERIAL_LIGHT_SHADER_VELVET,
- LIGHT_SHADER_TOON=VS::FIXED_MATERIAL_LIGHT_SHADER_TOON
- };
-
-private:
-
-
- struct Node {
-
- int param;
- int mult;
- int tex;
- };
-
- Variant param[PARAM_MAX];
- Ref<Texture> texture_param[PARAM_MAX];
- TexCoordMode texture_texcoord[PARAM_MAX];
- LightShader light_shader;
- bool fixed_flags[FLAG_MAX];
- float point_size;
-
-
- Transform uv_transform;
-
-protected:
-
-
- static void _bind_methods();
+ OBJ_TYPE(FixedMaterial,Resource);
public:
- void set_fixed_flag(FixedFlag p_flag, bool p_value);
- bool get_fixed_flag(FixedFlag p_flag) const;
-
- void set_parameter(Parameter p_parameter, const Variant& p_value);
- Variant get_parameter(Parameter p_parameter) const;
-
- void set_texture(Parameter p_parameter, Ref<Texture> p_texture);
- Ref<Texture> get_texture(Parameter p_parameter) const;
-
- void set_texcoord_mode(Parameter p_parameter, TexCoordMode p_mode);
- TexCoordMode get_texcoord_mode(Parameter p_parameter) const;
-
- void set_light_shader(LightShader p_shader);
- LightShader get_light_shader() const;
-
- void set_uv_transform(const Transform& p_transform);
- Transform get_uv_transform() const;
-
- void set_point_size(float p_transform);
- float get_point_size() const;
-
FixedMaterial();
- ~FixedMaterial();
-
+ virtual ~FixedMaterial();
};
-
-VARIANT_ENUM_CAST( FixedMaterial::Parameter );
-VARIANT_ENUM_CAST( FixedMaterial::TexCoordMode );
-VARIANT_ENUM_CAST( FixedMaterial::FixedFlag );
-VARIANT_ENUM_CAST( FixedMaterial::LightShader );
-
-class ShaderMaterial : public Material {
-
- OBJ_TYPE( ShaderMaterial, Material );
-
- Ref<Shader> shader;
-
-
-
- void _shader_changed();
- static void _shader_parse(void*p_self,ShaderLanguage::ProgramNode*p_node);
-
-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;
-
- static void _bind_methods();
-
-public:
-
- void set_shader(const Ref<Shader>& p_shader);
- Ref<Shader> get_shader() const;
-
- void set_shader_param(const StringName& p_param,const Variant& p_value);
- Variant get_shader_param(const StringName& p_param) const;
-
- void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
-
- ShaderMaterial();
-};
-
//////////////////////
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 921466585d..132ec54e48 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -122,22 +122,14 @@ bool Mesh::_set(const StringName& p_name, const Variant& p_value) {
if (idx==surfaces.size()) {
- if (what=="custom") {
- add_custom_surface(p_value);
- return true;
-
- }
-
//create
Dictionary d=p_value;
ERR_FAIL_COND_V(!d.has("primitive"),false);
ERR_FAIL_COND_V(!d.has("arrays"),false);
ERR_FAIL_COND_V(!d.has("morph_arrays"),false);
- bool alphasort = d.has("alphasort") && bool(d["alphasort"]);
-
- add_surface(PrimitiveType(int(d["primitive"])),d["arrays"],d["morph_arrays"],alphasort);
+ add_surface(PrimitiveType(int(d["primitive"])),d["arrays"],d["morph_arrays"]);
if (d.has("material")) {
surface_set_material(idx,d["material"]);
@@ -196,7 +188,6 @@ bool Mesh::_get(const StringName& p_name,Variant &r_ret) const {
d["primitive"]=surface_get_primitive_type(idx);
d["arrays"]=surface_get_arrays(idx);
d["morph_arrays"]=surface_get_morph_arrays(idx);
- d["alphasort"]=surface_is_alpha_sorting_enabled(idx);
Ref<Material> m = surface_get_material(idx);
if (m.is_valid())
d["material"]=m;
@@ -243,14 +234,14 @@ void Mesh::_recompute_aabb() {
}
-void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,bool p_alphasort) {
+void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes) {
ERR_FAIL_COND(p_arrays.size()!=ARRAY_MAX);
Surface s;
- VisualServer::get_singleton()->mesh_add_surface(mesh,(VisualServer::PrimitiveType)p_primitive, p_arrays,p_blend_shapes,p_alphasort);
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh,(VisualServer::PrimitiveType)p_primitive, p_arrays,p_blend_shapes);
surfaces.push_back(s);
@@ -274,7 +265,6 @@ void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Arr
}
surfaces[surfaces.size()-1].aabb=aabb;
- surfaces[surfaces.size()-1].alphasort=p_alphasort;
_recompute_aabb();
@@ -289,29 +279,19 @@ void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Arr
Array Mesh::surface_get_arrays(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface,surfaces.size(),Array());
- return VisualServer::get_singleton()->mesh_get_surface_arrays(mesh,p_surface);
+ //return VisualServer::get_singleton()->mesh_get_surface_arrays(mesh,p_surface);
+ return Array();
}
Array Mesh::surface_get_morph_arrays(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface,surfaces.size(),Array());
- return VisualServer::get_singleton()->mesh_get_surface_morph_arrays(mesh,p_surface);
+ return Array();
}
-void Mesh::add_custom_surface(const Variant& p_data) {
-
- Surface s;
- s.aabb=AABB();
- VisualServer::get_singleton()->mesh_add_custom_surface(mesh,p_data);
- surfaces.push_back(s);
-
- triangle_mesh=Ref<TriangleMesh>();
- _change_notify();
-}
-
int Mesh::get_surface_count() const {
@@ -418,11 +398,6 @@ Mesh::PrimitiveType Mesh::surface_get_primitive_type(int p_idx) const {
return (PrimitiveType)VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, p_idx );
}
-bool Mesh::surface_is_alpha_sorting_enabled(int p_idx) const {
-
- ERR_FAIL_INDEX_V( p_idx, surfaces.size(), 0 );
- return surfaces[p_idx].alphasort;
-}
void Mesh::surface_set_material(int p_idx, const Ref<Material>& p_material) {
@@ -968,7 +943,6 @@ void Mesh::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_morph_target_mode","mode"),&Mesh::set_morph_target_mode);
ObjectTypeDB::bind_method(_MD("get_morph_target_mode"),&Mesh::get_morph_target_mode);
- ObjectTypeDB::bind_method(_MD("add_surface","primitive","arrays","morph_arrays","alphasort"),&Mesh::add_surface,DEFVAL(Array()),DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_surface_count"),&Mesh::get_surface_count);
ObjectTypeDB::bind_method(_MD("surface_remove","surf_idx"),&Mesh::surface_remove);
ObjectTypeDB::bind_method(_MD("surface_get_array_len","surf_idx"),&Mesh::surface_get_array_len);
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index dc1d97a49e..e329c353a0 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -99,7 +99,6 @@ private:
struct Surface {
String name;
AABB aabb;
- bool alphasort;
Ref<Material> material;
};
Vector<Surface> surfaces;
@@ -123,12 +122,10 @@ protected:
public:
- void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alphasort=false);
+ void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array());
Array surface_get_arrays(int p_surface) const;
virtual Array surface_get_morph_arrays(int p_surface) const;
- void add_custom_surface(const Variant& p_data); //only recognized by driver
-
void add_morph_target(const StringName& p_name);
int get_morph_target_count() const;
StringName get_morph_target_name(int p_index) const;
diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp
index c5ade63124..0a005d8c54 100644
--- a/scene/resources/multimesh.cpp
+++ b/scene/resources/multimesh.cpp
@@ -141,7 +141,7 @@ Ref<Mesh> MultiMesh::get_mesh() const {
void MultiMesh::set_instance_count(int p_count) {
- VisualServer::get_singleton()->multimesh_set_instance_count(multimesh,p_count);
+ VisualServer::get_singleton()->multimesh_allocate(multimesh,p_count,VS::MultimeshTransformFormat(transform_format),VS::MultimeshColorFormat(color_format));
}
int MultiMesh::get_instance_count() const {
@@ -177,7 +177,7 @@ Color MultiMesh::get_instance_color(int p_instance) const {
void MultiMesh::set_aabb(const AABB& p_aabb) {
aabb=p_aabb;
- VisualServer::get_singleton()->multimesh_set_aabb(multimesh,p_aabb);
+ VisualServer::get_singleton()->multimesh_set_custom_aabb(multimesh,p_aabb);
}
@@ -220,10 +220,36 @@ RID MultiMesh::get_rid() const {
}
+
+void MultiMesh::set_color_format(ColorFormat p_color_format) {
+
+ color_format=p_color_format;
+}
+
+MultiMesh::ColorFormat MultiMesh::get_color_format() const{
+
+ return color_format;
+}
+
+void MultiMesh::set_transform_format(TransformFormat p_transform_format){
+
+ transform_format=p_transform_format;
+}
+MultiMesh::TransformFormat MultiMesh::get_transform_format() const{
+
+ return transform_format;
+}
+
+
void MultiMesh::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MultiMesh::set_mesh);
ObjectTypeDB::bind_method(_MD("get_mesh:Mesh"),&MultiMesh::get_mesh);
+ ObjectTypeDB::bind_method(_MD("set_color_format","format"),&MultiMesh::set_color_format);
+ ObjectTypeDB::bind_method(_MD("get_color_format"),&MultiMesh::get_color_format);
+ ObjectTypeDB::bind_method(_MD("set_transform_format","format"),&MultiMesh::set_transform_format);
+ ObjectTypeDB::bind_method(_MD("get_transform_format"),&MultiMesh::get_transform_format);
+
ObjectTypeDB::bind_method(_MD("set_instance_count","count"),&MultiMesh::set_instance_count);
ObjectTypeDB::bind_method(_MD("get_instance_count"),&MultiMesh::get_instance_count);
ObjectTypeDB::bind_method(_MD("set_instance_transform","instance","transform"),&MultiMesh::set_instance_transform);
@@ -241,17 +267,29 @@ void MultiMesh::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_get_color_array"),&MultiMesh::_get_color_array);
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"color_format",PROPERTY_HINT_ENUM,"None,Byte,Float"), _SCS("set_color_format"), _SCS("get_color_format"));
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"transform_format",PROPERTY_HINT_ENUM,"None,2D,3D"), _SCS("set_transform_format"), _SCS("get_transform_format"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"instance_count",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_instance_count"), _SCS("get_instance_count"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"mesh",PROPERTY_HINT_RESOURCE_TYPE,"Mesh"), _SCS("set_mesh"), _SCS("get_mesh"));
ADD_PROPERTY(PropertyInfo(Variant::_AABB,"aabb"), _SCS("set_aabb"), _SCS("get_aabb") );
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3_ARRAY,"transform_array",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_transform_array"), _SCS("_get_transform_array"));
ADD_PROPERTY(PropertyInfo(Variant::COLOR_ARRAY,"color_array",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_color_array"), _SCS("_get_color_array"));
+
+ BIND_CONSTANT( TRANSFORM_NONE );
+ BIND_CONSTANT( TRANSFORM_2D );
+ BIND_CONSTANT( TRANSFORM_3D );
+ BIND_CONSTANT( COLOR_NONE );
+ BIND_CONSTANT( COLOR_8BIT );
+ BIND_CONSTANT( COLOR_FLOAT );
+
}
MultiMesh::MultiMesh() {
multimesh = VisualServer::get_singleton()->multimesh_create();
+ color_format=COLOR_NONE;
+ transform_format=TRANSFORM_NONE;
}
MultiMesh::~MultiMesh() {
diff --git a/scene/resources/multimesh.h b/scene/resources/multimesh.h
index 0cf9e92def..be4ee38fcd 100644
--- a/scene/resources/multimesh.h
+++ b/scene/resources/multimesh.h
@@ -30,16 +30,33 @@
#define MULTIMESH_H
#include "scene/resources/mesh.h"
-
+#include "servers/visual_server.h"
class MultiMesh : public Resource {
OBJ_TYPE( MultiMesh, Resource );
RES_BASE_EXTENSION("mmsh");
+public:
+ enum TransformFormat {
+ TRANSFORM_NONE = VS::MULTIMESH_TRANSFORM_NONE,
+ TRANSFORM_2D = VS::MULTIMESH_TRANSFORM_2D,
+ TRANSFORM_3D = VS::MULTIMESH_TRANSFORM_3D
+ };
+
+ enum ColorFormat {
+ COLOR_NONE = VS::MULTIMESH_COLOR_NONE,
+ COLOR_8BIT = VS::MULTIMESH_COLOR_8BIT,
+ COLOR_FLOAT = VS::MULTIMESH_COLOR_FLOAT,
+ };
+private:
AABB aabb;
Ref<Mesh> mesh;
RID multimesh;
+ TransformFormat transform_format;
+ ColorFormat color_format;
+
+
protected:
static void _bind_methods();
@@ -55,6 +72,12 @@ public:
void set_mesh(const Ref<Mesh>& p_mesh);
Ref<Mesh> get_mesh() const;
+ void set_color_format(ColorFormat p_color_format);
+ ColorFormat get_color_format() const;
+
+ void set_transform_format(TransformFormat p_transform_format);
+ TransformFormat get_transform_format() const;
+
void set_instance_count(int p_count);
int get_instance_count() const;
@@ -76,4 +99,8 @@ public:
};
+
+VARIANT_ENUM_CAST( MultiMesh::TransformFormat );
+VARIANT_ENUM_CAST( MultiMesh::ColorFormat);
+
#endif // MULTI_MESH_H
diff --git a/scene/resources/room.cpp b/scene/resources/room.cpp
index f28220531b..978a15ab5e 100644
--- a/scene/resources/room.cpp
+++ b/scene/resources/room.cpp
@@ -36,16 +36,6 @@ RID RoomBounds::get_rid() const {
return area;
}
-void RoomBounds::set_bounds( const BSP_Tree& p_bounds ) {
-
- VisualServer::get_singleton()->room_set_bounds(area,p_bounds);
- emit_signal("changed");
-}
-
-BSP_Tree RoomBounds::get_bounds() const {
-
- return VisualServer::get_singleton()->room_get_bounds(area);
-}
void RoomBounds::set_geometry_hint(const DVector<Face3>& p_geometry_hint) {
@@ -57,41 +47,15 @@ DVector<Face3> RoomBounds::get_geometry_hint() const {
return geometry_hint;
}
-void RoomBounds::_regenerate_bsp_cubic() {
-
- if (geometry_hint.size()) {
-
- float err=0;
- geometry_hint= Geometry::wrap_geometry( geometry_hint, &err ); ///< create a "wrap" that encloses the given geometry
- BSP_Tree new_bounds(geometry_hint,err);
- set_bounds(new_bounds);
- }
-
-}
-
-void RoomBounds::_regenerate_bsp() {
-
- if (geometry_hint.size()) {
-
- BSP_Tree new_bounds(geometry_hint,0);
- set_bounds(new_bounds);
- }
-}
void RoomBounds::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_bounds","bsp_tree"),&RoomBounds::set_bounds);
- ObjectTypeDB::bind_method(_MD("get_bounds"),&RoomBounds::get_bounds);
ObjectTypeDB::bind_method(_MD("set_geometry_hint","triangles"),&RoomBounds::set_geometry_hint);
ObjectTypeDB::bind_method(_MD("get_geometry_hint"),&RoomBounds::get_geometry_hint);
- ObjectTypeDB::bind_method(_MD("regenerate_bsp"),&RoomBounds::_regenerate_bsp);
- ObjectTypeDB::set_method_flags(get_type_static(),_SCS("regenerate_bsp"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
- ObjectTypeDB::bind_method(_MD("regenerate_bsp_cubic"),&RoomBounds::_regenerate_bsp_cubic);
- ObjectTypeDB::set_method_flags(get_type_static(),_SCS("regenerate_bsp_cubic"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
- ADD_PROPERTY( PropertyInfo( Variant::DICTIONARY, "bounds"), _SCS("set_bounds"),_SCS("get_bounds") );
+ //ADD_PROPERTY( PropertyInfo( Variant::DICTIONARY, "bounds"), _SCS("set_bounds"),_SCS("get_bounds") );
ADD_PROPERTY( PropertyInfo( Variant::VECTOR3_ARRAY, "geometry_hint"),_SCS("set_geometry_hint"),_SCS("get_geometry_hint") );
}
diff --git a/scene/resources/room.h b/scene/resources/room.h
index dc5e284838..6200521044 100644
--- a/scene/resources/room.h
+++ b/scene/resources/room.h
@@ -34,6 +34,7 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class RoomBounds : public Resource {
OBJ_TYPE( RoomBounds, Resource );
@@ -42,8 +43,7 @@ class RoomBounds : public Resource {
RID area;
DVector<Face3> geometry_hint;
- void _regenerate_bsp();
- void _regenerate_bsp_cubic();
+
protected:
static void _bind_methods();
@@ -52,8 +52,6 @@ public:
virtual RID get_rid() const;
- void set_bounds( const BSP_Tree& p_bounds );
- BSP_Tree get_bounds() const;
void set_geometry_hint(const DVector<Face3>& geometry_hint);
DVector<Face3> get_geometry_hint() const;
@@ -63,4 +61,6 @@ public:
};
+
+
#endif // ROOM_H
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index ee9f23dd2a..b6c8fcf7a1 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -39,37 +39,17 @@ Shader::Mode Shader::get_mode() const {
return mode;
}
-void Shader::set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs,int p_light_ofs) {
+void Shader::set_code(const String& p_code) {
- VisualServer::get_singleton()->shader_set_code(shader,p_vertex,p_fragment,p_light,0,p_fragment_ofs,p_light_ofs);
+ VisualServer::get_singleton()->shader_set_code(shader,p_code);
params_cache_dirty=true;
emit_signal(SceneStringNames::get_singleton()->changed);
}
-String Shader::get_vertex_code() const {
+String Shader::get_code() const {
- return VisualServer::get_singleton()->shader_get_vertex_code(shader);
-}
-
-String Shader::get_fragment_code() const {
-
- return VisualServer::get_singleton()->shader_get_fragment_code(shader);
-
-}
-
-String Shader::get_light_code() const {
-
- return VisualServer::get_singleton()->shader_get_light_code(shader);
-
-}
-
-bool Shader::has_param(const StringName& p_param) const {
-
- if (params_cache_dirty)
- get_param_list(NULL);
-
- return (params_cache.has(p_param));
+ return VisualServer::get_singleton()->shader_get_code(shader);
}
@@ -101,48 +81,6 @@ RID Shader::get_rid() const {
return shader;
}
-Dictionary Shader::_get_code() {
-
- String fs = VisualServer::get_singleton()->shader_get_fragment_code(shader);
- String vs = VisualServer::get_singleton()->shader_get_vertex_code(shader);
- String ls = VisualServer::get_singleton()->shader_get_light_code(shader);
-
- Dictionary c;
- c["fragment"]=fs;
- c["fragment_ofs"]=0;
- c["vertex"]=vs;
- c["vertex_ofs"]=0;
- c["light"]=ls;
- c["light_ofs"]=0;
- Array arr;
- for(const Map<StringName,Ref<Texture> >::Element *E=default_textures.front();E;E=E->next()) {
- arr.push_back(E->key());
- arr.push_back(E->get());
- }
- if (arr.size())
- c["default_tex"]=arr;
- return c;
-}
-
-void Shader::_set_code(const Dictionary& p_string) {
-
- ERR_FAIL_COND(!p_string.has("fragment"));
- ERR_FAIL_COND(!p_string.has("vertex"));
- String light;
- if (p_string.has("light"))
- light=p_string["light"];
-
- set_code(p_string["vertex"],p_string["fragment"],light);
- if (p_string.has("default_tex")) {
- Array arr=p_string["default_tex"];
- if ((arr.size()&1)==0) {
- for(int i=0;i<arr.size();i+=2) {
-
- set_default_texture_param(arr[i],arr[i+1]);
- }
- }
- }
-}
void Shader::set_default_texture_param(const StringName& p_param,const Ref<Texture>& p_texture) {
@@ -171,29 +109,27 @@ void Shader::get_default_texture_param_list(List<StringName>* r_textures) const{
}
}
+bool Shader::has_param(const StringName& p_param) const {
+ return params_cache.has(p_param);
+}
void Shader::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_mode"),&Shader::get_mode);
- ObjectTypeDB::bind_method(_MD("set_code","vcode","fcode","lcode","fofs","lofs"),&Shader::set_code,DEFVAL(0),DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_vertex_code"),&Shader::get_vertex_code);
- ObjectTypeDB::bind_method(_MD("get_fragment_code"),&Shader::get_fragment_code);
- ObjectTypeDB::bind_method(_MD("get_light_code"),&Shader::get_light_code);
+ ObjectTypeDB::bind_method(_MD("set_code","code"),&Shader::set_code);
+ ObjectTypeDB::bind_method(_MD("get_code"),&Shader::get_code);
ObjectTypeDB::bind_method(_MD("set_default_texture_param","param","texture:Texture"),&Shader::set_default_texture_param);
ObjectTypeDB::bind_method(_MD("get_default_texture_param:Texture","param"),&Shader::get_default_texture_param);
ObjectTypeDB::bind_method(_MD("has_param","name"),&Shader::has_param);
- ObjectTypeDB::bind_method(_MD("_set_code","code"),&Shader::_set_code);
- ObjectTypeDB::bind_method(_MD("_get_code"),&Shader::_get_code);
-
//ObjectTypeDB::bind_method(_MD("get_param_list"),&Shader::get_fragment_code);
- ADD_PROPERTY( PropertyInfo(Variant::STRING, "_code",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_code"), _SCS("_get_code") );
+ ADD_PROPERTY( PropertyInfo(Variant::STRING, "code",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("set_code"), _SCS("get_code") );
BIND_CONSTANT( MODE_MATERIAL );
BIND_CONSTANT( MODE_CANVAS_ITEM );
@@ -214,253 +150,3 @@ Shader::~Shader() {
}
-
-/************ Loader from text ***************/
-
-
-
-RES ResourceFormatLoaderShader::load(const String &p_path, const String& p_original_path, Error *r_error) {
-
- if (r_error)
- *r_error=ERR_FILE_CANT_OPEN;
-
- String fragment_code;
- String vertex_code;
- String light_code;
-
- int mode=-1;
-
- Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
-
-
- ERR_EXPLAIN("Unable to open shader file: "+p_path);
- ERR_FAIL_COND_V(err,RES());
- String base_path = p_path.get_base_dir();
-
- if (r_error)
- *r_error=ERR_FILE_CORRUPT;
-
- Ref<Shader> shader;//( memnew( Shader ) );
-
- int line=0;
-
- while(!f->eof_reached()) {
-
- String l = f->get_line();
- line++;
-
- if (mode<=0) {
- l = l.strip_edges();
- int comment = l.find(";");
- if (comment!=-1)
- l=l.substr(0,comment);
- }
-
- if (mode<1)
- vertex_code+="\n";
- if (mode<2)
- fragment_code+="\n";
-
- if (mode < 1 && l=="")
- continue;
-
- if (l.begins_with("[")) {
- l=l.strip_edges();
- if (l=="[params]") {
- if (mode>=0) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [params] section.");
- ERR_FAIL_V(RES());
- }
- mode=0;
- } else if (l=="[vertex]") {
- if (mode>=1) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [vertex] section.");
- ERR_FAIL_V(RES());
- }
- mode=1;
- } else if (l=="[fragment]") {
- if (mode>=2) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [fragment] section.");
- ERR_FAIL_V(RES());
- }
- mode=1;
- } else {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Unknown section type: '"+l+"'.");
- ERR_FAIL_V(RES());
- }
- continue;
- }
-
- if (mode==0) {
-
- int eqpos = l.find("=");
- if (eqpos==-1) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Expected '='.");
- ERR_FAIL_V(RES());
- }
-
-
- String right=l.substr(eqpos+1,l.length()).strip_edges();
- if (right=="") {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Expected value after '='.");
- ERR_FAIL_V(RES());
- }
-
- Variant value;
-
- if (right=="true") {
- value = true;
- } else if (right=="false") {
- value = false;
- } else if (right.is_valid_float()) {
- //is number
- value = right.to_double();
- } else if (right.is_valid_html_color()) {
- //is html color
- value = Color::html(right);
- } else {
- //attempt to parse a constructor
- int popenpos = right.find("(");
-
- if (popenpos==-1) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor syntax: "+right);
- ERR_FAIL_V(RES());
- }
-
- int pclosepos = right.find_last(")");
-
- if (pclosepos==-1) {
- ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor parameter syntax: "+right);
- ERR_FAIL_V(RES());
-
- }
-
- String type = right.substr(0,popenpos);
- String param = right.substr(popenpos+1,pclosepos-popenpos-1).strip_edges();
-
-
- if (type=="tex") {
-
- if (param=="") {
-
- value=RID();
- } else {
-
- String path;
-
- if (param.is_abs_path())
- path=param;
- else
- path=base_path+"/"+param;
-
- Ref<Texture> texture = ResourceLoader::load(path);
- if (!texture.is_valid()) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Couldn't find icon at path: "+path);
- ERR_FAIL_V(RES());
- }
-
- value=texture;
- }
-
- } else if (type=="vec3") {
-
- if (param=="") {
- value=Vector3();
- } else {
- Vector<String> params = param.split(",");
- if (params.size()!=3) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid param count for vec3(): '"+right+"'.");
- ERR_FAIL_V(RES());
-
- }
-
- Vector3 v;
- for(int i=0;i<3;i++)
- v[i]=params[i].to_double();
- value=v;
- }
-
-
- } else if (type=="xform") {
-
- if (param=="") {
- value=Transform();
- } else {
-
- Vector<String> params = param.split(",");
- if (params.size()!=12) {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid param count for xform(): '"+right+"'.");
- ERR_FAIL_V(RES());
-
- }
-
- Transform t;
- for(int i=0;i<9;i++)
- t.basis[i%3][i/3]=params[i].to_double();
- for(int i=0;i<3;i++)
- t.origin[i]=params[i-9].to_double();
-
- value=t;
- }
-
- } else {
- memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor type: '"+type+"'.");
- ERR_FAIL_V(RES());
-
- }
-
- }
-
- String left= l.substr(0,eqpos);
-
-// shader->set_param(left,value);
- } else if (mode==1) {
-
- vertex_code+=l;
-
- } else if (mode==2) {
-
- fragment_code+=l;
- }
- }
-
- shader->set_code(vertex_code,fragment_code,light_code);
-
- f->close();
- memdelete(f);
- if (r_error)
- *r_error=OK;
-
- return shader;
-}
-
-void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const {
-
- ObjectTypeDB::get_extensions_for_type("Shader", p_extensions);
-}
-
-bool ResourceFormatLoaderShader::handles_type(const String& p_type) const {
-
- return ObjectTypeDB::is_type(p_type, "Shader");
-}
-
-
-String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
-
- if (p_path.extension().to_lower()=="shd")
- return "Shader";
- return "";
-}
-
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index 6ee8d4e793..988305b654 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -32,6 +32,7 @@
#include "resource.h"
#include "io/resource_loader.h"
#include "scene/resources/texture.h"
+
class Shader : public Resource {
OBJ_TYPE(Shader,Resource);
@@ -49,9 +50,6 @@ public:
private:
RID shader;
Mode mode;
- Dictionary _get_code();
- void _set_code(const Dictionary& p_string);
-
// hack the name of performance
// shaders keep a list of ShaderMaterial -> VisualServer name translations, to make
@@ -73,10 +71,8 @@ public:
//void set_mode(Mode p_mode);
Mode get_mode() const;
- void set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs=0,int p_light_ofs=0);
- String get_vertex_code() const;
- String get_fragment_code() const;
- String get_light_code() const;
+ void set_code( const String& p_code);
+ String get_code() const;
void get_param_list(List<PropertyInfo> *p_params) const;
bool has_param(const StringName& p_param) const;
@@ -124,14 +120,5 @@ public:
-class ResourceFormatLoaderShader : public ResourceFormatLoader {
-public:
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
- virtual void get_recognized_extensions(List<String> *p_extensions) const;
- virtual bool handles_type(const String& p_type) const;
- virtual String get_resource_type(const String &p_path) const;
-};
-
-
#endif // SHADER_H
diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp
index 02faa9425d..c62479ca89 100644
--- a/scene/resources/shader_graph.cpp
+++ b/scene/resources/shader_graph.cpp
@@ -29,6 +29,7 @@
#include "shader_graph.h"
#include "scene/scene_string_names.h"
+#if 0
Array ShaderGraph::_get_node_list(ShaderType p_type) const {
List<int> nodes;
@@ -2489,7 +2490,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str
}
}
- Image gradient(color_ramp_len,1,0,Image::FORMAT_RGBA,cramp);
+ Image gradient(color_ramp_len,1,0,Image::FORMAT_RGBA8,cramp);
Ref<ImageTexture> it = memnew( ImageTexture );
it->create_from_image(gradient,Texture::FLAG_FILTER|Texture::FLAG_MIPMAPS);
@@ -2559,7 +2560,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str
- Image gradient(curve_map_len,1,0,Image::FORMAT_GRAYSCALE,cmap);
+ Image gradient(curve_map_len,1,0,Image::FORMAT_L8,cmap);
Ref<ImageTexture> it = memnew( ImageTexture );
it->create_from_image(gradient,Texture::FLAG_FILTER|Texture::FLAG_MIPMAPS);
@@ -2660,3 +2661,5 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str
#undef DEF_MATRIX
#undef DEF_VEC
}
+
+#endif
diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h
index 1e6fc3507c..d5a5102f3a 100644
--- a/scene/resources/shader_graph.h
+++ b/scene/resources/shader_graph.h
@@ -30,7 +30,7 @@
#define SHADER_GRAPH_H
-
+#if 0
#include "map.h"
#include "scene/resources/shader.h"
@@ -440,5 +440,5 @@ public:
}
};
-
+#endif
#endif // SHADER_GRAPH_H
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 59246dfabe..34d66df915 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -141,7 +141,7 @@ void StyleBoxTexture::draw(RID p_canvas_item,const Rect2& p_rect) const {
r.pos.y-=expand_margin[MARGIN_TOP];
r.size.x+=expand_margin[MARGIN_LEFT]+expand_margin[MARGIN_RIGHT];
r.size.y+=expand_margin[MARGIN_TOP]+expand_margin[MARGIN_BOTTOM];
- VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate);
+ VisualServer::get_singleton()->canvas_item_add_nine_patch( p_canvas_item,r,region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),VS::NINE_PATCH_STRETCH,VS::NINE_PATCH_STRETCH,draw_center,modulate);
}
void StyleBoxTexture::set_draw_center(bool p_draw) {
@@ -423,127 +423,3 @@ StyleBoxFlat::~StyleBoxFlat() {
}
-////////////////
-
-
-
-void StyleBoxImageMask::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("set_image","image"),&StyleBoxImageMask::set_image);
- ObjectTypeDB::bind_method(_MD("get_image"),&StyleBoxImageMask::get_image);
- ObjectTypeDB::bind_method(_MD("set_expand","expand"),&StyleBoxImageMask::set_expand);
- ObjectTypeDB::bind_method(_MD("get_expand"),&StyleBoxImageMask::get_expand);
- ObjectTypeDB::bind_method(_MD("set_expand_margin_size","margin","size"),&StyleBoxImageMask::set_expand_margin_size);
- ObjectTypeDB::bind_method(_MD("get_expand_margin_size","margin"),&StyleBoxImageMask::get_expand_margin_size);
-
- ADD_PROPERTY( PropertyInfo(Variant::IMAGE, "image"), _SCS("set_image"), _SCS("get_image"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL, "expand"), _SCS("set_expand"), _SCS("get_expand"));
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/left", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_LEFT );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/right", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_RIGHT );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/top", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_TOP );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/bottom", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_BOTTOM );
-
-}
-
-
-bool StyleBoxImageMask::test_mask(const Point2& p_point, const Rect2& p_rect) const {
-
- if (image.empty())
- return false;
- if (p_rect.size.x<1)
- return false;
- if (p_rect.size.y<1)
- return false;
-
- Size2i imgsize(image.get_width(),image.get_height());
- if (imgsize.x<=0 || imgsize.y<=0)
- return false;
-
- Point2i img_expand_size( imgsize.x - expand_margin[MARGIN_LEFT] - expand_margin[MARGIN_RIGHT], imgsize.y - expand_margin[MARGIN_TOP] - expand_margin[MARGIN_BOTTOM]);
- Point2i rect_expand_size( p_rect.size.x - expand_margin[MARGIN_LEFT] - expand_margin[MARGIN_RIGHT], p_rect.size.y - expand_margin[MARGIN_TOP] - expand_margin[MARGIN_BOTTOM]);
- if (rect_expand_size.x<1)
- rect_expand_size.x=1;
- if (rect_expand_size.y<1)
- rect_expand_size.y=1;
-
-
- Point2i click_pos;
-
-
- //treat x
-
- if (p_point.x<p_rect.pos.x)
- click_pos.x=0;
- else if (expand) {
-
- if (p_point.x>=p_rect.pos.x+p_rect.size.x)
- click_pos.x=imgsize.x-1;
- else if ((p_point.x-p_rect.pos.x)<expand_margin[MARGIN_LEFT])
- click_pos.x=p_point.x;
- else if ((p_point.x-(p_rect.pos.x+p_rect.size.x))<expand_margin[MARGIN_RIGHT])
- click_pos.x=imgsize.x-(p_point.x-(p_rect.pos.x+p_rect.size.x));
- else //expand
- click_pos.x=(p_point.x-p_rect.pos.x-expand_margin[MARGIN_LEFT])*img_expand_size.x/rect_expand_size.x;
- } else if ((p_point.x-p_rect.pos.x) > imgsize.x)
- click_pos.x=imgsize.x;
-
- //treat y
-
- if (p_point.y<p_rect.pos.y)
- click_pos.y=0;
- else if (expand) {
-
- if (p_point.y>=p_rect.pos.y+p_rect.size.y)
- click_pos.y=imgsize.y-1;
- else if ((p_point.y-p_rect.pos.y)<expand_margin[MARGIN_TOP])
- click_pos.y=p_point.y;
- else if ((p_point.y-(p_rect.pos.y+p_rect.size.y))<expand_margin[MARGIN_BOTTOM])
- click_pos.y=imgsize.y-(p_point.y-(p_rect.pos.y+p_rect.size.y));
- else //expand
- click_pos.y=(p_point.y-p_rect.pos.y-expand_margin[MARGIN_TOP])*img_expand_size.y/rect_expand_size.y;
- } else if ((p_point.y-p_rect.pos.y) > imgsize.y)
- click_pos.y=imgsize.y;
-
- return image.get_pixel(click_pos.x,click_pos.y).gray()>0.5;
-
-}
-
-
-void StyleBoxImageMask::set_image(const Image& p_image) {
-
- image=p_image;
-}
-Image StyleBoxImageMask::get_image() const {
-
- return image;
-}
-
-
-void StyleBoxImageMask::set_expand(bool p_expand) {
-
- expand=p_expand;
-}
-bool StyleBoxImageMask::get_expand() const {
-
- return expand;
-}
-void StyleBoxImageMask::set_expand_margin_size(Margin p_expand_margin,float p_size) {
-
- ERR_FAIL_INDEX(p_expand_margin,4);
- expand_margin[p_expand_margin]=p_size;
-}
-
-
-float StyleBoxImageMask::get_expand_margin_size(Margin p_expand_margin) const {
-
- ERR_FAIL_INDEX_V(p_expand_margin,4,0);
- return expand_margin[p_expand_margin];
-}
-
-StyleBoxImageMask::StyleBoxImageMask() {
-
- for (int i=0;i<4;i++) {
- expand_margin[i]=0;
- }
- expand=true;
-}
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index f667318e24..6ac67148c5 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -167,35 +167,5 @@ public:
};
-class StyleBoxImageMask : public StyleBox {
-
- OBJ_TYPE( StyleBoxImageMask, StyleBox );
- virtual float get_style_margin(Margin p_margin) const { return 0; }
-
- Image image;
- float expand_margin[4];
- bool expand;
-
-protected:
-
- static void _bind_methods();
-
-public:
-
- virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {}
- virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const;
-
- void set_image(const Image& p_image);
- Image get_image() const;
-
- void set_expand(bool p_expand);
- bool get_expand() const;
- void set_expand_margin_size(Margin p_expand_margin,float p_size);
- float get_expand_margin_size(Margin p_expand_margin) const;
-
- StyleBoxImageMask();
-
-};
-
#endif
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 726b1938c4..c83c5e6b80 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -258,23 +258,13 @@ void ImageTexture::load(const String& p_path) {
void ImageTexture::set_data(const Image& p_image) {
VisualServer::get_singleton()->texture_set_data(texture,p_image);
- VisualServer::get_singleton()->texture_set_reload_hook(texture,0,StringName()); //hook is erased if data is changed
+
_change_notify();
}
void ImageTexture::_resource_path_changed() {
String path=get_path();
- if (VS::get_singleton()->has_feature(VS::FEATURE_NEEDS_RELOAD_HOOK)) {
- //this needs to be done much better, but probably will end up being deprecated as technology advances
- if (path.is_resource_file() && ImageLoader::recognize(path.extension())) {
-
- //hook is set only if path is hookable
- VisualServer::get_singleton()->texture_set_reload_hook(texture,get_instance_ID(),"_reload_hook");
- } else {
- VisualServer::get_singleton()->texture_set_reload_hook(texture,0,StringName());
- }
- }
}
Image ImageTexture::get_data() const {
@@ -300,7 +290,7 @@ RID ImageTexture::get_rid() const {
void ImageTexture::fix_alpha_edges() {
- if (format==Image::FORMAT_RGBA /*&& !(flags&FLAG_CUBEMAP)*/) {
+ if (format==Image::FORMAT_RGBA8 /*&& !(flags&FLAG_CUBEMAP)*/) {
Image img = get_data();
img.fix_alpha_edges();
@@ -310,7 +300,7 @@ void ImageTexture::fix_alpha_edges() {
void ImageTexture::premultiply_alpha() {
- if (format==Image::FORMAT_RGBA /*&& !(flags&FLAG_CUBEMAP)*/) {
+ if (format==Image::FORMAT_RGBA8 /*&& !(flags&FLAG_CUBEMAP)*/) {
Image img = get_data();
img.premultiply_alpha();
@@ -337,7 +327,7 @@ void ImageTexture::shrink_x2_and_keep_size() {
bool ImageTexture::has_alpha() const {
- return ( format==Image::FORMAT_GRAYSCALE_ALPHA || format==Image::FORMAT_INDEXED_ALPHA || format==Image::FORMAT_RGBA );
+ return ( format==Image::FORMAT_LA8 || format==Image::FORMAT_RGBA8 );
}
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index 05ea833978..fc5f05479c 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -54,7 +54,7 @@ public:
FLAG_FILTER=VisualServer::TEXTURE_FLAG_FILTER,
FLAG_ANISOTROPIC_FILTER=VisualServer::TEXTURE_FLAG_ANISOTROPIC_FILTER,
FLAG_CONVERT_TO_LINEAR=VisualServer::TEXTURE_FLAG_CONVERT_TO_LINEAR,
- FLAG_VIDEO_SURFACE=VisualServer::TEXTURE_FLAG_VIDEO_SURFACE,
+ FLAG_VIDEO_SURFACE=VisualServer::TEXTURE_FLAG_USED_FOR_STREAMING,
FLAGS_DEFAULT=FLAG_MIPMAPS|FLAG_REPEAT|FLAG_FILTER,
FLAG_MIRRORED_REPEAT=VisualServer::TEXTURE_FLAG_MIRRORED_REPEAT
};
diff --git a/servers/audio/audio_server_sw.h b/servers/audio/audio_server_sw.h
index fda952fa94..2f56479404 100644
--- a/servers/audio/audio_server_sw.h
+++ b/servers/audio/audio_server_sw.h
@@ -53,7 +53,7 @@ class AudioServerSW : public AudioServer {
virtual AudioMixer *get_mixer();
virtual void audio_mixer_chunk_callback(int p_frames);
- struct Voice {
+ struct Voice : public RID_Data {
float volume;
volatile bool active;
@@ -67,7 +67,7 @@ class AudioServerSW : public AudioServer {
mutable RID_Owner<Voice> voice_owner;
SelfList<Voice>::List active_list;
- struct Stream {
+ struct Stream : public RID_Data {
bool active;
List<Stream*>::Element *E;
AudioStream *audio_stream;
diff --git a/servers/audio/sample_manager_sw.h b/servers/audio/sample_manager_sw.h
index bd7a11a3d2..6ca3a8e8fb 100644
--- a/servers/audio/sample_manager_sw.h
+++ b/servers/audio/sample_manager_sw.h
@@ -74,7 +74,7 @@ public:
class SampleManagerMallocSW : public SampleManagerSW {
- struct Sample {
+ struct Sample : public RID_Data {
void *data;
int length;
diff --git a/servers/physics/broad_phase_octree.cpp b/servers/physics/broad_phase_octree.cpp
index bfe41f8423..f1c19a618f 100644
--- a/servers/physics/broad_phase_octree.cpp
+++ b/servers/physics/broad_phase_octree.cpp
@@ -29,7 +29,7 @@
#include "broad_phase_octree.h"
#include "collision_object_sw.h"
-ID BroadPhaseOctree::create(CollisionObjectSW *p_object, int p_subindex) {
+BroadPhaseSW::ID BroadPhaseOctree::create(CollisionObjectSW *p_object, int p_subindex) {
ID oid = octree.create(p_object,AABB(),p_subindex,false,1<<p_object->get_type(),0);
return oid;
diff --git a/servers/physics/constraint_sw.h b/servers/physics/constraint_sw.h
index d61701ac07..5aa96bc026 100644
--- a/servers/physics/constraint_sw.h
+++ b/servers/physics/constraint_sw.h
@@ -31,7 +31,7 @@
#include "body_sw.h"
-class ConstraintSW {
+class ConstraintSW : public RID_Data {
BodySW **_body_ptr;
int _body_count;
diff --git a/servers/physics/shape_sw.h b/servers/physics/shape_sw.h
index 39779bcda3..8901c706cc 100644
--- a/servers/physics/shape_sw.h
+++ b/servers/physics/shape_sw.h
@@ -46,7 +46,7 @@ SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_creat
class ShapeSW;
-class ShapeOwnerSW {
+class ShapeOwnerSW : public RID_Data {
public:
virtual void _shape_changed()=0;
@@ -56,7 +56,7 @@ public:
};
-class ShapeSW {
+class ShapeSW : public RID_Data {
RID self;
AABB aabb;
diff --git a/servers/physics/space_sw.h b/servers/physics/space_sw.h
index 3fdef7e62b..30720b8be2 100644
--- a/servers/physics/space_sw.h
+++ b/servers/physics/space_sw.h
@@ -57,7 +57,7 @@ public:
-class SpaceSW {
+class SpaceSW : public RID_Data {
public:
diff --git a/servers/physics_2d/broad_phase_2d_basic.cpp b/servers/physics_2d/broad_phase_2d_basic.cpp
index 3a95bb2411..0f45735d56 100644
--- a/servers/physics_2d/broad_phase_2d_basic.cpp
+++ b/servers/physics_2d/broad_phase_2d_basic.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "broad_phase_2d_basic.h"
-ID BroadPhase2DBasic::create(CollisionObject2DSW *p_object_, int p_subindex) {
+BroadPhase2DBasic::ID BroadPhase2DBasic::create(CollisionObject2DSW *p_object_, int p_subindex) {
current++;
diff --git a/servers/physics_2d/constraint_2d_sw.h b/servers/physics_2d/constraint_2d_sw.h
index f776dbfe2c..c2d1357f26 100644
--- a/servers/physics_2d/constraint_2d_sw.h
+++ b/servers/physics_2d/constraint_2d_sw.h
@@ -31,7 +31,7 @@
#include "body_2d_sw.h"
-class Constraint2DSW {
+class Constraint2DSW : public RID_Data {
Body2DSW **_body_ptr;
int _body_count;
diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h
index b90c36bc04..e069de883f 100644
--- a/servers/physics_2d/shape_2d_sw.h
+++ b/servers/physics_2d/shape_2d_sw.h
@@ -46,7 +46,7 @@ SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_creat
class Shape2DSW;
-class ShapeOwner2DSW {
+class ShapeOwner2DSW : public RID_Data{
public:
virtual void _shape_changed()=0;
@@ -55,7 +55,7 @@ public:
virtual ~ShapeOwner2DSW() {}
};
-class Shape2DSW {
+class Shape2DSW : public RID_Data {
RID self;
Rect2 aabb;
diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h
index f58e8c3fe7..93dbc99c40 100644
--- a/servers/physics_2d/space_2d_sw.h
+++ b/servers/physics_2d/space_2d_sw.h
@@ -58,7 +58,7 @@ public:
-class Space2DSW {
+class Space2DSW : public RID_Data {
public:
diff --git a/servers/spatial_sound/spatial_sound_server_sw.h b/servers/spatial_sound/spatial_sound_server_sw.h
index b4295bf145..68bcf60707 100644
--- a/servers/spatial_sound/spatial_sound_server_sw.h
+++ b/servers/spatial_sound/spatial_sound_server_sw.h
@@ -67,7 +67,7 @@ class SpatialSoundServerSW : public SpatialSoundServer {
struct Room;
- struct Space {
+ struct Space : public RID_Data {
RID default_room;
Set<RID> rooms;
@@ -79,7 +79,7 @@ class SpatialSoundServerSW : public SpatialSoundServer {
mutable RID_Owner<Space> space_owner;
- struct Room {
+ struct Room : public RID_Data{
RID space;
Transform transform;
Transform inverse_transform;
@@ -97,7 +97,7 @@ class SpatialSoundServerSW : public SpatialSoundServer {
- struct Source {
+ struct Source : public RID_Data {
struct Voice {
@@ -161,7 +161,7 @@ class SpatialSoundServerSW : public SpatialSoundServer {
mutable RID_Owner<Source> source_owner;
- struct Listener {
+ struct Listener : public RID_Data {
RID space;
Transform transform;
diff --git a/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h b/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h
index 619b11f376..e601de6eed 100644
--- a/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h
+++ b/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h
@@ -66,7 +66,7 @@ class SpatialSound2DServerSW : public SpatialSound2DServer {
struct Room;
- struct Space {
+ struct Space : public RID_Data {
RID default_room;
Set<RID> rooms;
@@ -78,7 +78,7 @@ class SpatialSound2DServerSW : public SpatialSound2DServer {
mutable RID_Owner<Space> space_owner;
- struct Room {
+ struct Room : public RID_Data {
RID space;
Matrix32 transform;
Matrix32 inverse_transform;
@@ -96,7 +96,7 @@ class SpatialSound2DServerSW : public SpatialSound2DServer {
- struct Source {
+ struct Source : public RID_Data {
struct Voice {
@@ -160,7 +160,7 @@ class SpatialSound2DServerSW : public SpatialSound2DServer {
mutable RID_Owner<Source> source_owner;
- struct Listener {
+ struct Listener : public RID_Data {
RID space;
Matrix32 transform;
diff --git a/servers/visual/particle_system_sw.cpp b/servers/visual/particle_system_sw.cpp
deleted file mode 100644
index 07cc6d8a2a..0000000000
--- a/servers/visual/particle_system_sw.cpp
+++ /dev/null
@@ -1,412 +0,0 @@
-/*************************************************************************/
-/* particle_system_sw.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "particle_system_sw.h"
-#include "sort.h"
-
-
-ParticleSystemSW::ParticleSystemSW() {
-
- amount=8;
- emitting=true;
-
- for (int i=0;i<VS::PARTICLE_VAR_MAX;i++) {
- particle_randomness[i]=0.0;
- }
-
- particle_vars[VS::PARTICLE_LIFETIME]=2.0;//
- particle_vars[VS::PARTICLE_SPREAD]=0.2;//
- particle_vars[VS::PARTICLE_GRAVITY]=9.8;//
- particle_vars[VS::PARTICLE_LINEAR_VELOCITY]=0.2;//
- particle_vars[VS::PARTICLE_ANGULAR_VELOCITY]=0.0;//
- particle_vars[VS::PARTICLE_LINEAR_ACCELERATION]=0.0;//
- particle_vars[VS::PARTICLE_RADIAL_ACCELERATION]=0.0;//
- particle_vars[VS::PARTICLE_TANGENTIAL_ACCELERATION]=1.0;//
- particle_vars[VS::PARTICLE_DAMPING]=0.0;//
- particle_vars[VS::PARTICLE_INITIAL_SIZE]=1.0;
- particle_vars[VS::PARTICLE_FINAL_SIZE]=0.8;
- particle_vars[VS::PARTICLE_HEIGHT]=1;
- particle_vars[VS::PARTICLE_HEIGHT_SPEED_SCALE]=1;
-
- height_from_velocity=false;
- local_coordinates=false;
-
- particle_vars[VS::PARTICLE_INITIAL_ANGLE]=0.0;//
-
- gravity_normal=Vector3(0,-1.0,0);
- //emission_half_extents=Vector3(0.1,0.1,0.1);
- emission_half_extents=Vector3(1,1,1);
- color_phase_count=0;
- color_phases[0].pos=0.0;
- color_phases[0].color=Color(1.0,0.0,0.0);
- visibility_aabb=AABB(Vector3(-64,-64,-64),Vector3(128,128,128));
-
- attractor_count=0;
-
-}
-
-
-ParticleSystemSW::~ParticleSystemSW()
-{
-}
-
-
-#define DEFAULT_SEED 1234567
-
-_FORCE_INLINE_ static float _rand_from_seed(uint32_t *seed) {
-
- uint32_t k;
- uint32_t s = (*seed);
- if (s == 0)
- s = 0x12345987;
- k = s / 127773;
- s = 16807 * (s - k * 127773) - 2836 * k;
- if (s < 0)
- s += 2147483647;
- (*seed) = s;
-
- float v=((float)((*seed) & 0xFFFFF))/(float)0xFFFFF;
- v=v*2.0-1.0;
- return v;
-}
-
-_FORCE_INLINE_ static uint32_t _irand_from_seed(uint32_t *seed) {
-
- uint32_t k;
- uint32_t s = (*seed);
- if (s == 0)
- s = 0x12345987;
- k = s / 127773;
- s = 16807 * (s - k * 127773) - 2836 * k;
- if (s < 0)
- s += 2147483647;
- (*seed) = s;
-
- return s;
-}
-
-void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Transform& p_transform,float p_time) {
-
- valid=false;
- if (p_system->amount<=0) {
- ERR_EXPLAIN("Invalid amount of particles: "+itos(p_system->amount));
- ERR_FAIL_COND(p_system->amount<=0);
- }
- if (p_system->attractor_count<0 || p_system->attractor_count>VS::MAX_PARTICLE_ATTRACTORS) {
- ERR_EXPLAIN("Invalid amount of particle attractors.");
- ERR_FAIL_COND(p_system->attractor_count<0 || p_system->attractor_count>VS::MAX_PARTICLE_ATTRACTORS);
- }
- float lifetime = p_system->particle_vars[VS::PARTICLE_LIFETIME];
- if (lifetime<CMP_EPSILON) {
- ERR_EXPLAIN("Particle system lifetime too small.");
- ERR_FAIL_COND(lifetime<CMP_EPSILON);
- }
- valid=true;
- int particle_count=MIN(p_system->amount,ParticleSystemSW::MAX_PARTICLES);;
-
-
- int emission_point_count = p_system->emission_points.size();
- DVector<Vector3>::Read r;
- if (emission_point_count)
- r=p_system->emission_points.read();
-
- if (particle_count!=particle_data.size()) {
-
- //clear the whole system if particle amount changed
- particle_data.clear();
- particle_data.resize(p_system->amount);
- particle_system_time=0;
- }
-
- float next_time = particle_system_time+p_time;
-
- if (next_time > lifetime)
- next_time=Math::fmod(next_time,lifetime);
-
-
- ParticleData *pdata=&particle_data[0];
- Vector3 attractor_positions[VS::MAX_PARTICLE_ATTRACTORS];
-
- for(int i=0;i<p_system->attractor_count;i++) {
-
- attractor_positions[i]=p_transform.xform(p_system->attractors[i].pos);
- }
-
-
- for(int i=0;i<particle_count;i++) {
-
- ParticleData &p=pdata[i];
-
- float restart_time = (i * lifetime / p_system->amount);
-
- bool restart=false;
-
- if ( next_time < particle_system_time ) {
-
- if (restart_time > particle_system_time || restart_time < next_time )
- restart=true;
-
- } else if (restart_time > particle_system_time && restart_time < next_time ) {
- restart=true;
- }
-
- if (restart) {
-
-
- if (p_system->emitting) {
- if (emission_point_count==0) { //use AABB
- if (p_system->local_coordinates)
- p.pos = p_system->emission_half_extents * Vector3( _rand_from_seed(&rand_seed), _rand_from_seed(&rand_seed), _rand_from_seed(&rand_seed) );
- else
- p.pos = p_transform.xform( p_system->emission_half_extents * Vector3( _rand_from_seed(&rand_seed), _rand_from_seed(&rand_seed), _rand_from_seed(&rand_seed) ) );
- } else {
- //use preset positions
- if (p_system->local_coordinates)
- p.pos = r[_irand_from_seed(&rand_seed)%emission_point_count];
- else
- p.pos = p_transform.xform( r[_irand_from_seed(&rand_seed)%emission_point_count] );
- }
-
-
- float angle1 = _rand_from_seed(&rand_seed)*p_system->particle_vars[VS::PARTICLE_SPREAD]*Math_PI;
- float angle2 = _rand_from_seed(&rand_seed)*20.0*Math_PI; // make it more random like
-
- Vector3 rot_xz=Vector3( Math::sin(angle1), 0.0, Math::cos(angle1) );
- Vector3 rot = Vector3( Math::cos(angle2)*rot_xz.x,Math::sin(angle2)*rot_xz.x, rot_xz.z);
-
- p.vel=(rot*p_system->particle_vars[VS::PARTICLE_LINEAR_VELOCITY]+rot*p_system->particle_randomness[VS::PARTICLE_LINEAR_VELOCITY]*_rand_from_seed(&rand_seed));
- if (!p_system->local_coordinates)
- p.vel=p_transform.basis.xform( p.vel );
-
- p.vel+=p_system->emission_base_velocity;
-
- p.rot=p_system->particle_vars[VS::PARTICLE_INITIAL_ANGLE]+p_system->particle_randomness[VS::PARTICLE_INITIAL_ANGLE]*_rand_from_seed(&rand_seed);
- p.active=true;
- for(int r=0;r<PARTICLE_RANDOM_NUMBERS;r++)
- p.random[r]=_rand_from_seed(&rand_seed);
-
- } else {
-
- p.pos=Vector3();
- p.rot=0;
- p.vel=Vector3();
- p.active=false;
- }
-
- } else {
-
- if (!p.active)
- continue;
-
- Vector3 force;
- //apply gravity
- force=p_system->gravity_normal * (p_system->particle_vars[VS::PARTICLE_GRAVITY]+(p_system->particle_randomness[VS::PARTICLE_GRAVITY]*p.random[0]));
- //apply linear acceleration
- force+=p.vel.normalized() * (p_system->particle_vars[VS::PARTICLE_LINEAR_ACCELERATION]+p_system->particle_randomness[VS::PARTICLE_LINEAR_ACCELERATION]*p.random[1]);
- //apply radial acceleration
- Vector3 org;
- if (!p_system->local_coordinates)
- org=p_transform.origin;
- force+=(p.pos-org).normalized() * (p_system->particle_vars[VS::PARTICLE_RADIAL_ACCELERATION]+p_system->particle_randomness[VS::PARTICLE_RADIAL_ACCELERATION]*p.random[2]);
- //apply tangential acceleration
- force+=(p.pos-org).cross(p_system->gravity_normal).normalized() * (p_system->particle_vars[VS::PARTICLE_TANGENTIAL_ACCELERATION]+p_system->particle_randomness[VS::PARTICLE_TANGENTIAL_ACCELERATION]*p.random[3]);
- //apply attractor forces
- for(int a=0;a<p_system->attractor_count;a++) {
-
- force+=(p.pos-attractor_positions[a]).normalized() * p_system->attractors[a].force;
- }
-
-
- p.vel+=force * p_time;
- if (p_system->particle_vars[VS::PARTICLE_DAMPING]) {
-
- float v = p.vel.length();
- float damp = p_system->particle_vars[VS::PARTICLE_DAMPING] + p_system->particle_vars[VS::PARTICLE_DAMPING] * p_system->particle_randomness[VS::PARTICLE_DAMPING];
- v -= damp * p_time;
- if (v<0) {
- p.vel=Vector3();
- } else {
- p.vel=p.vel.normalized() * v;
- }
-
- }
- p.rot+=(p_system->particle_vars[VS::PARTICLE_ANGULAR_VELOCITY]+p_system->particle_randomness[VS::PARTICLE_ANGULAR_VELOCITY]*p.random[4]) *p_time;
- p.pos+=p.vel * p_time;
- }
- }
-
- particle_system_time=Math::fmod( particle_system_time+p_time, lifetime );
-
-
-}
-
-ParticleSystemProcessSW::ParticleSystemProcessSW() {
-
- particle_system_time=0;
- rand_seed=1234567;
- valid=false;
-}
-
-
-struct _ParticleSorterSW {
-
-
- _FORCE_INLINE_ bool operator()(const ParticleSystemDrawInfoSW::ParticleDrawInfo *p_a,const ParticleSystemDrawInfoSW::ParticleDrawInfo *p_b) const {
-
- return p_a->d > p_b->d; // draw from further away to closest
- }
-};
-
-void ParticleSystemDrawInfoSW::prepare(const ParticleSystemSW *p_system,const ParticleSystemProcessSW *p_process,const Transform& p_system_transform,const Transform& p_camera_transform) {
-
- ERR_FAIL_COND(p_process->particle_data.size() != p_system->amount);
- ERR_FAIL_COND(p_system->amount<=0 || p_system->amount>=ParticleSystemSW::MAX_PARTICLES);
-
- const ParticleSystemProcessSW::ParticleData *pdata=&p_process->particle_data[0];
- float time_pos=p_process->particle_system_time/p_system->particle_vars[VS::PARTICLE_LIFETIME];
-
- ParticleSystemSW::ColorPhase cphase[VS::MAX_PARTICLE_COLOR_PHASES];
-
- float last=-1;
- int col_count=0;
-
- for(int i=0;i<p_system->color_phase_count;i++) {
-
- if (p_system->color_phases[i].pos<=last)
- break;
- cphase[i]=p_system->color_phases[i];
- col_count++;
- }
-
-
-
-
-
- Vector3 camera_z_axis = p_camera_transform.basis.get_axis(2);
-
- for(int i=0;i<p_system->amount;i++) {
-
- ParticleDrawInfo &pdi=draw_info[i];
- pdi.data=&pdata[i];
- pdi.transform.origin=pdi.data->pos;
- if (p_system->local_coordinates)
- pdi.transform.origin=p_system_transform.xform(pdi.transform.origin);
-
- pdi.d=-camera_z_axis.dot(pdi.transform.origin);
-
- // adjust particle size, color and rotation
-
- float time = ((float)i / p_system->amount);
- if (time<time_pos)
- time=time_pos-time;
- else
- time=(1.0-time)+time_pos;
-
- Vector3 up=p_camera_transform.basis.get_axis(1); // up determines the rotation
- float up_scale=1.0;
-
- if (p_system->height_from_velocity) {
-
- Vector3 veld = pdi.data->vel;
- Vector3 cam_z = camera_z_axis.normalized();
- float vc = Math::abs(veld.normalized().dot(cam_z));
-
- if (vc<(1.0-CMP_EPSILON)) {
- up = Plane(cam_z,0).project(veld).normalized();
- float h = p_system->particle_vars[VS::PARTICLE_HEIGHT]+p_system->particle_randomness[VS::PARTICLE_HEIGHT]*pdi.data->random[7];
- float velh = veld.length();
- h+=velh*(p_system->particle_vars[VS::PARTICLE_HEIGHT_SPEED_SCALE]+p_system->particle_randomness[VS::PARTICLE_HEIGHT_SPEED_SCALE]*pdi.data->random[7]);
-
-
- up_scale=Math::lerp(1.0,h,(1.0-vc));
- }
-
- } else if (pdi.data->rot) {
-
- up.rotate(camera_z_axis,pdi.data->rot);
- }
-
- {
- // matrix
- Vector3 v_z = (p_camera_transform.origin-pdi.transform.origin).normalized();
-// Vector3 v_z = (p_camera_transform.origin-pdi.data->pos).normalized();
- Vector3 v_y = up;
- Vector3 v_x = v_y.cross(v_z);
- v_y = v_z.cross(v_x);
- v_x.normalize();
- v_y.normalize();
-
-
- float initial_scale, final_scale;
- initial_scale = p_system->particle_vars[VS::PARTICLE_INITIAL_SIZE]+p_system->particle_randomness[VS::PARTICLE_INITIAL_SIZE]*pdi.data->random[5];
- final_scale = p_system->particle_vars[VS::PARTICLE_FINAL_SIZE]+p_system->particle_randomness[VS::PARTICLE_FINAL_SIZE]*pdi.data->random[6];
- float scale = initial_scale + time * (final_scale - initial_scale);
-
- pdi.transform.basis.set_axis(0,v_x * scale);
- pdi.transform.basis.set_axis(1,v_y * scale * up_scale);
- pdi.transform.basis.set_axis(2,v_z * scale);
- }
-
-
-
- int cpos=0;
-
- while(cpos<col_count) {
-
- if (cphase[cpos].pos > time)
- break;
- cpos++;
- }
-
- cpos--;
-
-
- if (cpos==-1)
- pdi.color=Color(1,1,1,1);
- else {
- if (cpos==col_count-1)
- pdi.color=cphase[cpos].color;
- else {
- float diff = (cphase[cpos+1].pos-cphase[cpos].pos);
- if (diff>0)
- pdi.color=cphase[cpos].color.linear_interpolate(cphase[cpos+1].color, (time - cphase[cpos].pos) / diff );
- else
- pdi.color=cphase[cpos+1].color;
- }
- }
-
-
- draw_info_order[i]=&pdi;
-
- }
-
-
- SortArray<ParticleDrawInfo*,_ParticleSorterSW> particle_sort;
- particle_sort.sort(&draw_info_order[0],p_system->amount);
-
-}
diff --git a/servers/visual/particle_system_sw.h b/servers/visual/particle_system_sw.h
deleted file mode 100644
index 4edcecaaa9..0000000000
--- a/servers/visual/particle_system_sw.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/*************************************************************************/
-/* particle_system_sw.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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 PARTICLE_SYSTEM_SW_H
-#define PARTICLE_SYSTEM_SW_H
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
-#include "servers/visual_server.h"
-
-struct ParticleSystemSW {
- enum {
-
- MAX_PARTICLES=1024
- };
-
- float particle_vars[VS::PARTICLE_VAR_MAX];
- float particle_randomness[VS::PARTICLE_VAR_MAX];
-
- Vector3 emission_half_extents;
- DVector<Vector3> emission_points;
- Vector3 gravity_normal;
- Vector3 emission_base_velocity;
- int amount;
- bool emitting;
- bool height_from_velocity;
- AABB visibility_aabb;
- bool sort;
- bool local_coordinates;
-
- struct ColorPhase {
-
- float pos;
- Color color;
- ColorPhase() { pos=1.0; color=Color(0.0,0.0,1.0,1.0); }
- };
-
- int color_phase_count;
- ColorPhase color_phases[VS::MAX_PARTICLE_COLOR_PHASES];
-
-
- struct Attractor {
-
- Vector3 pos;
- float force;
- };
-
- int attractor_count;
- Attractor attractors[VS::MAX_PARTICLE_ATTRACTORS];
-
-
- ParticleSystemSW();
- ~ParticleSystemSW();
-
-};
-
-
-struct ParticleSystemProcessSW {
-
- enum {
- PARTICLE_RANDOM_NUMBERS = 8,
- };
-
- struct ParticleData {
-
- Vector3 pos;
- Vector3 vel;
- float rot;
- bool active;
- float random[PARTICLE_RANDOM_NUMBERS];
-
- ParticleData() { active=0; rot=0; }
- };
-
-
- bool valid;
- float particle_system_time;
- uint32_t rand_seed;
- Vector<ParticleData> particle_data;
-
- void process(const ParticleSystemSW *p_system,const Transform& p_transform,float p_time);
-
- ParticleSystemProcessSW();
-};
-
-struct ParticleSystemDrawInfoSW {
-
- struct ParticleDrawInfo {
-
- const ParticleSystemProcessSW::ParticleData *data;
- float d;
- Transform transform;
- Color color;
-
- };
-
- ParticleDrawInfo draw_info[ParticleSystemSW::MAX_PARTICLES];
- ParticleDrawInfo *draw_info_order[ParticleSystemSW::MAX_PARTICLES];
-
- void prepare(const ParticleSystemSW *p_system,const ParticleSystemProcessSW *p_process,const Transform& p_system_transform,const Transform& p_camera_transform);
-
-};
-
-#endif
diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp
index a4b91e17fe..2952098a3c 100644
--- a/servers/visual/rasterizer.cpp
+++ b/servers/visual/rasterizer.cpp
@@ -30,6 +30,23 @@
#include "print_string.h"
#include "os/os.h"
+
+Rasterizer* (*Rasterizer::_create_func)()=NULL;
+
+Rasterizer *Rasterizer::create() {
+
+ return _create_func();
+}
+
+RasterizerStorage*RasterizerStorage::base_signleton=NULL;
+
+RasterizerStorage::RasterizerStorage() {
+
+ base_signleton=this;
+}
+
+#if 0
+
RID Rasterizer::create_default_material() {
return material_create();
@@ -636,3 +653,5 @@ RID Rasterizer::create_overdraw_debug_material() {
return mat;
}
+
+#endif
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 8cc567072f..df18dd1679 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -29,6 +29,670 @@
#ifndef RASTERIZER_H
#define RASTERIZER_H
+
+#include "servers/visual_server.h"
+#include "camera_matrix.h"
+
+
+
+class RasterizerStorage {
+public:
+ /* TEXTURE API */
+
+ virtual RID texture_create()=0;
+ 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)=0;
+ virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT)=0;
+ virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const=0;
+ virtual void texture_set_flags(RID p_texture,uint32_t p_flags)=0;
+ virtual uint32_t texture_get_flags(RID p_texture) const=0;
+ virtual Image::Format texture_get_format(RID p_texture) const=0;
+ virtual uint32_t texture_get_width(RID p_texture) const=0;
+ virtual uint32_t texture_get_height(RID p_texture) const=0;
+ virtual void texture_set_size_override(RID p_texture,int p_width, int p_height)=0;
+
+ virtual void texture_set_path(RID p_texture,const String& p_path)=0;
+ virtual String texture_get_path(RID p_texture) const=0;
+
+ virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable)=0;
+
+ virtual void texture_debug_usage(List<VS::TextureInfo> *r_info)=0;
+
+
+ /* SHADER API */
+
+
+ virtual RID shader_create(VS::ShaderMode p_mode=VS::SHADER_SPATIAL)=0;
+
+ virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode)=0;
+ virtual VS::ShaderMode shader_get_mode(RID p_shader) const=0;
+
+ virtual void shader_set_code(RID p_shader, const String& p_code)=0;
+ virtual String shader_get_code(RID p_shader) const=0;
+ virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const=0;
+
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0;
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0;
+
+
+ /* COMMON MATERIAL API */
+
+ virtual RID material_create()=0;
+
+ virtual void material_set_shader(RID p_shader_material, RID p_shader)=0;
+ virtual RID material_get_shader(RID p_shader_material) const=0;
+
+ virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value)=0;
+ virtual Variant material_get_param(RID p_material, const StringName& p_param) const=0;
+
+ /* MESH API */
+
+ virtual RID mesh_create()=0;
+
+ virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >())=0;
+
+ virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount)=0;
+ virtual int mesh_get_morph_target_count(RID p_mesh) const=0;
+
+
+ virtual void mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode)=0;
+ virtual VS::MorphTargetMode mesh_get_morph_target_mode(RID p_mesh) const=0;
+
+ virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material)=0;
+ virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const=0;
+
+ virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const=0;
+ virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const=0;
+
+ virtual DVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const=0;
+ virtual DVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const=0;
+
+
+ virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const=0;
+ virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const=0;
+
+ virtual void mesh_remove_surface(RID p_mesh,int p_index)=0;
+ virtual int mesh_get_surface_count(RID p_mesh) const=0;
+
+ virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb)=0;
+ virtual AABB mesh_get_custom_aabb(RID p_mesh) const=0;
+
+ virtual AABB mesh_get_aabb(RID p_mesh) const=0;
+ virtual void mesh_clear(RID p_mesh)=0;
+
+ /* MULTIMESH API */
+
+
+ virtual RID multimesh_create()=0;
+
+ virtual void multimesh_allocate(RID p_multimesh,int p_instances,VS::MultimeshTransformFormat p_transform_format,VS::MultimeshColorFormat p_color_format,bool p_gen_aabb=true)=0;
+ virtual int multimesh_get_instance_count(RID p_multimesh) const=0;
+
+ virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh)=0;
+ virtual void multimesh_set_custom_aabb(RID p_multimesh,const AABB& p_aabb)=0;
+ virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform)=0;
+ virtual void multimesh_instance_set_transform_2d(RID p_multimesh,int p_index,const Matrix32& p_transform)=0;
+ virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color)=0;
+
+ virtual RID multimesh_get_mesh(RID p_multimesh) const=0;
+ virtual AABB multimesh_get_custom_aabb(RID p_multimesh,const AABB& p_aabb) const=0;
+
+ virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const=0;
+ virtual Matrix32 multimesh_instance_get_transform_2d(RID p_multimesh,int p_index) const=0;
+ virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const=0;
+
+ virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible)=0;
+ virtual int multimesh_get_visible_instances(RID p_multimesh) const=0;
+
+ virtual AABB multimesh_get_aabb(RID p_mesh) const=0;
+
+ /* IMMEDIATE API */
+
+ virtual RID immediate_create()=0;
+ virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID())=0;
+ virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex)=0;
+ virtual void immediate_vertex_2d(RID p_immediate,const Vector3& p_vertex)=0;
+ virtual void immediate_normal(RID p_immediate,const Vector3& p_normal)=0;
+ virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent)=0;
+ virtual void immediate_color(RID p_immediate,const Color& p_color)=0;
+ virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv)=0;
+ virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv)=0;
+ virtual void immediate_end(RID p_immediate)=0;
+ virtual void immediate_clear(RID p_immediate)=0;
+ virtual void immediate_set_material(RID p_immediate,RID p_material)=0;
+ virtual RID immediate_get_material(RID p_immediate) const=0;
+
+ /* SKELETON API */
+
+ virtual RID skeleton_create()=0;
+ virtual void skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton=false)=0;
+ virtual int skeleton_get_bone_count(RID p_skeleton) const=0;
+ virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0;
+ virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0;
+ virtual void skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Matrix32& p_transform)=0;
+ virtual Matrix32 skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone)=0;
+
+ /* Light API */
+
+ virtual RID light_create(VS::LightType p_type)=0;
+
+ virtual void light_set_color(RID p_light,const Color& p_color)=0;
+ virtual void light_set_param(RID p_light,VS::LightParam p_param,float p_value)=0;
+ virtual void light_set_shadow(RID p_light,bool p_enabled)=0;
+ virtual void light_set_projector(RID p_light,RID p_texture)=0;
+ virtual void light_set_attenuation_texure(RID p_light,RID p_texture)=0;
+ virtual void light_set_negative(RID p_light,bool p_enable)=0;
+ virtual void light_set_cull_mask(RID p_light,uint32_t p_mask)=0;
+ virtual void light_set_shader(RID p_light,RID p_shader)=0;
+
+
+ virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode)=0;
+
+ /* PROBE API */
+
+ virtual RID reflection_probe_create()=0;
+
+ virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity)=0;
+ virtual void reflection_probe_set_clip(RID p_probe, float p_near, float p_far)=0;
+ virtual void reflection_probe_set_min_blend_distance(RID p_probe, float p_distance)=0;
+ virtual void reflection_probe_set_extents(RID p_probe, const Vector3& p_extents)=0;
+ virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset)=0;
+ virtual void reflection_probe_set_enable_parallax_correction(RID p_probe, bool p_enable)=0;
+ virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution)=0;
+ virtual void reflection_probe_set_hide_skybox(RID p_probe, bool p_hide)=0;
+ virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers)=0;
+
+
+ /* ROOM API */
+
+ virtual RID room_create()=0;
+ virtual void room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform)=0;
+ virtual void room_clear_bounds()=0;
+
+ /* PORTAL API */
+
+ // portals are only (x/y) points, forming a convex shape, which its clockwise
+ // order points outside. (z is 0)=0;
+
+ virtual RID portal_create()=0;
+ virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape)=0;
+ virtual void portal_set_enabled(RID p_portal, bool p_enabled)=0;
+ virtual void portal_set_disable_distance(RID p_portal, float p_distance)=0;
+ virtual void portal_set_disabled_color(RID p_portal, const Color& p_color)=0;
+
+
+ /* RENDER TARGET */
+
+ enum RenderTargetFlags {
+ RENDER_TARGET_VFLIP,
+ RENDER_TARGET_TRANSPARENT,
+ RENDER_TARGET_NO_3D,
+ RENDER_TARGET_NO_SAMPLING,
+ RENDER_TARGET_FLAG_MAX
+ };
+
+ virtual RID render_target_create()=0;
+ virtual void render_target_set_size(RID p_render_target,int p_width, int p_height)=0;
+ virtual RID render_target_get_texture(RID p_render_target) const=0;
+ virtual Image render_target_get_image(RID p_render_target) const=0;
+ virtual void render_target_set_flag(RID p_render_target,RenderTargetFlags p_flag,bool p_value)=0;
+ virtual bool render_target_renedered_in_frame(RID p_render_target)=0;
+
+
+ /* CANVAS SHADOW */
+
+ virtual RID canvas_light_shadow_buffer_create(int p_width)=0;
+
+ /* LIGHT SHADOW MAPPING */
+
+ virtual RID canvas_light_occluder_create()=0;
+ virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines)=0;
+
+ virtual bool free(RID p_rid)=0;
+
+
+ static RasterizerStorage*base_signleton;
+ RasterizerStorage();
+ virtual ~RasterizerStorage() {}
+};
+
+
+
+
+class RasterizerCanvas {
+public:
+
+ enum CanvasRectFlags {
+
+ CANVAS_RECT_REGION=1,
+ CANVAS_RECT_TILE=2,
+ CANVAS_RECT_FLIP_H=4,
+ CANVAS_RECT_FLIP_V=8,
+ CANVAS_RECT_TRANSPOSE=16
+ };
+
+
+ struct Light : public RID_Data {
+
+
+
+ bool enabled;
+ Color color;
+ Matrix32 xform;
+ float height;
+ float energy;
+ float scale;
+ int z_min;
+ int z_max;
+ int layer_min;
+ int layer_max;
+ int item_mask;
+ int item_shadow_mask;
+ VS::CanvasLightMode mode;
+ RID texture;
+ Vector2 texture_offset;
+ RID canvas;
+ RID shadow_buffer;
+ int shadow_buffer_size;
+ float shadow_gradient_length;
+ VS::CanvasLightShadowFilter shadow_filter;
+ Color shadow_color;
+
+
+ void *texture_cache; // implementation dependent
+ Rect2 rect_cache;
+ Matrix32 xform_cache;
+ float radius_cache; //used for shadow far plane
+ CameraMatrix shadow_matrix_cache;
+
+ Matrix32 light_shader_xform;
+ Vector2 light_shader_pos;
+
+ Light *shadows_next_ptr;
+ Light *filter_next_ptr;
+ Light *next_ptr;
+ Light *mask_next_ptr;
+
+ RID light_internal;
+
+ Light() {
+ enabled=true;
+ color=Color(1,1,1);
+ shadow_color=Color(0,0,0,0);
+ height=0;
+ z_min=-1024;
+ z_max=1024;
+ layer_min=0;
+ layer_max=0;
+ item_mask=1;
+ scale=1.0;
+ energy=1.0;
+ item_shadow_mask=-1;
+ mode=VS::CANVAS_LIGHT_MODE_ADD;
+ texture_cache=NULL;
+ next_ptr=NULL;
+ mask_next_ptr=NULL;
+ filter_next_ptr=NULL;
+ shadow_buffer_size=256;
+ shadow_gradient_length=0;
+ shadow_filter=VS::CANVAS_LIGHT_FILTER_NONE;
+
+ }
+ };
+
+ virtual RID light_internal_create()=0;
+ virtual void light_internal_update(RID p_rid, Light* p_light)=0;
+ virtual void light_internal_free(RID p_rid)=0;
+
+ struct Item : public RID_Data {
+
+ struct Command {
+
+ enum Type {
+
+ TYPE_LINE,
+ TYPE_RECT,
+ TYPE_NINEPATCH,
+ TYPE_PRIMITIVE,
+ TYPE_POLYGON,
+ TYPE_MESH,
+ TYPE_MULTIMESH,
+ TYPE_CIRCLE,
+ TYPE_TRANSFORM,
+ TYPE_CLIP_IGNORE,
+ };
+
+ Type type;
+ virtual ~Command(){}
+ };
+
+ struct CommandLine : public Command {
+
+ Point2 from,to;
+ Color color;
+ float width;
+ bool antialiased;
+ CommandLine() { type = TYPE_LINE; }
+ };
+
+ struct CommandRect : public Command {
+
+ Rect2 rect;
+ RID texture;
+ Color modulate;
+ Rect2 source;
+ uint8_t flags;
+
+ CommandRect() { flags=0; type = TYPE_RECT; }
+ };
+
+ struct CommandNinePatch : public Command {
+
+ Rect2 rect;
+ Rect2 source;
+ RID texture;
+ float margin[4];
+ bool draw_center;
+ Color color;
+ VS::NinePatchAxisMode axis_x;
+ VS::NinePatchAxisMode axis_y;
+ CommandNinePatch() { draw_center=true; type = TYPE_NINEPATCH; }
+ };
+
+ struct CommandPrimitive : public Command {
+
+ Vector<Point2> points;
+ Vector<Point2> uvs;
+ Vector<Color> colors;
+ RID texture;
+ float width;
+
+ CommandPrimitive() { type = TYPE_PRIMITIVE; width=1;}
+ };
+
+ struct CommandPolygon : public Command {
+
+ Vector<int> indices;
+ Vector<Point2> points;
+ Vector<Point2> uvs;
+ Vector<Color> colors;
+ RID texture;
+ int count;
+
+ CommandPolygon() { type = TYPE_POLYGON; count = 0; }
+ };
+
+
+ struct CommandMesh : public Command {
+
+ RID mesh;
+ RID skeleton;
+ CommandMesh() { type = TYPE_MESH; }
+ };
+
+ struct CommandMultiMesh : public Command {
+
+ RID multimesh;
+ RID skeleton;
+ CommandMultiMesh() { type = TYPE_MULTIMESH; }
+ };
+
+ struct CommandCircle : public Command {
+
+ Point2 pos;
+ float radius;
+ Color color;
+ CommandCircle() { type = TYPE_CIRCLE; }
+ };
+
+ struct CommandTransform : public Command {
+
+ Matrix32 xform;
+ CommandTransform() { type = TYPE_TRANSFORM; }
+ };
+
+
+ struct CommandClipIgnore : public Command {
+
+ bool ignore;
+ CommandClipIgnore() { type = TYPE_CLIP_IGNORE; ignore=false; }
+ };
+
+
+ struct ViewportRender {
+ VisualServer*owner;
+ void* udata;
+ Rect2 rect;
+ };
+
+ Matrix32 xform;
+ bool clip;
+ bool visible;
+ bool behind;
+ //VS::MaterialBlendMode blend_mode;
+ int light_mask;
+ Vector<Command*> commands;
+ mutable bool custom_rect;
+ mutable bool rect_dirty;
+ mutable Rect2 rect;
+ RID material;
+ Item*next;
+
+ struct CopyBackBuffer {
+ Rect2 rect;
+ Rect2 screen_rect;
+ bool full;
+ };
+ CopyBackBuffer *copy_back_buffer;
+
+
+ Color final_modulate;
+ Matrix32 final_transform;
+ Rect2 final_clip_rect;
+ Item* final_clip_owner;
+ Item* material_owner;
+ ViewportRender *vp_render;
+ bool distance_field;
+ bool light_masked;
+
+ Rect2 global_rect_cache;
+
+ const Rect2& get_rect() const {
+ if (custom_rect || !rect_dirty)
+ return rect;
+
+ //must update rect
+ int s=commands.size();
+ if (s==0) {
+
+ rect=Rect2();
+ rect_dirty=false;
+ return rect;
+ }
+
+ Matrix32 xf;
+ bool found_xform=false;
+ bool first=true;
+
+ const Item::Command * const *cmd = &commands[0];
+
+
+ for (int i=0;i<s;i++) {
+
+ const Item::Command *c=cmd[i];
+ Rect2 r;
+
+ switch(c->type) {
+ case Item::Command::TYPE_LINE: {
+
+ const Item::CommandLine* line = static_cast< const Item::CommandLine*>(c);
+ r.pos=line->from;
+ r.expand_to(line->to);
+ } break;
+ case Item::Command::TYPE_RECT: {
+
+ const Item::CommandRect* crect = static_cast< const Item::CommandRect*>(c);
+ r=crect->rect;
+
+ } break;
+ case Item::Command::TYPE_NINEPATCH: {
+
+ const Item::CommandNinePatch* style = static_cast< const Item::CommandNinePatch*>(c);
+ r=style->rect;
+ } break;
+ case Item::Command::TYPE_PRIMITIVE: {
+
+ const Item::CommandPrimitive* primitive = static_cast< const Item::CommandPrimitive*>(c);
+ r.pos=primitive->points[0];
+ for(int i=1;i<primitive->points.size();i++) {
+
+ r.expand_to(primitive->points[i]);
+
+ }
+ } break;
+ case Item::Command::TYPE_POLYGON: {
+
+ const Item::CommandPolygon* polygon = static_cast< const Item::CommandPolygon*>(c);
+ int l = polygon->points.size();
+ const Point2*pp=&polygon->points[0];
+ r.pos=pp[0];
+ for(int i=1;i<l;i++) {
+
+ r.expand_to(pp[i]);
+
+ }
+ } break;
+ case Item::Command::TYPE_MESH: {
+
+ const Item::CommandMesh* mesh = static_cast< const Item::CommandMesh*>(c);
+ AABB aabb = RasterizerStorage::base_signleton->mesh_get_aabb(mesh->mesh);
+
+ r=Rect2(aabb.pos.x,aabb.pos.y,aabb.size.x,aabb.size.y);
+
+ } break;
+ case Item::Command::TYPE_MULTIMESH: {
+
+ const Item::CommandMultiMesh* multimesh = static_cast< const Item::CommandMultiMesh*>(c);
+ AABB aabb = RasterizerStorage::base_signleton->multimesh_get_aabb(multimesh->multimesh);
+
+ r=Rect2(aabb.pos.x,aabb.pos.y,aabb.size.x,aabb.size.y);
+
+ } break;
+ case Item::Command::TYPE_CIRCLE: {
+
+ const Item::CommandCircle* circle = static_cast< const Item::CommandCircle*>(c);
+ r.pos=Point2(-circle->radius,-circle->radius)+circle->pos;
+ r.size=Point2(circle->radius*2.0,circle->radius*2.0);
+ } break;
+ case Item::Command::TYPE_TRANSFORM: {
+
+ const Item::CommandTransform* transform = static_cast<const Item::CommandTransform*>(c);
+ xf=transform->xform;
+ found_xform=true;
+ continue;
+ } break;
+
+ case Item::Command::TYPE_CLIP_IGNORE: {
+
+ } break;
+ }
+
+ if (found_xform) {
+ r = xf.xform(r);
+ found_xform=false;
+ }
+
+
+ if (first) {
+ rect=r;
+ first=false;
+ } else
+ rect=rect.merge(r);
+ }
+
+ rect_dirty=false;
+ return rect;
+ }
+
+ void clear() { for (int i=0;i<commands.size();i++) memdelete( commands[i] ); commands.clear(); clip=false; rect_dirty=true; final_clip_owner=NULL; material_owner=NULL; light_masked=false; }
+ Item() { light_mask=1; vp_render=NULL; next=NULL; final_clip_owner=NULL; clip=false; final_modulate=Color(1,1,1,1); visible=true; rect_dirty=true; custom_rect=false; behind=false; material_owner=NULL; copy_back_buffer=NULL; distance_field=false; light_masked=false; }
+ virtual ~Item() { clear(); if (copy_back_buffer) memdelete(copy_back_buffer); }
+ };
+
+
+ virtual void canvas_begin()=0;
+
+ virtual void canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light)=0;
+ virtual void canvas_debug_viewport_shadows(Light* p_lights_with_shadow)=0;
+
+
+
+ struct LightOccluderInstance : public RID_Data {
+
+
+ bool enabled;
+ RID canvas;
+ RID polygon;
+ RID polygon_buffer;
+ Rect2 aabb_cache;
+ Matrix32 xform;
+ Matrix32 xform_cache;
+ int light_mask;
+ VS::CanvasOccluderPolygonCullMode cull_cache;
+
+ LightOccluderInstance *next;
+
+ LightOccluderInstance() { enabled=true; next=NULL; light_mask=1; cull_cache=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; }
+ };
+
+
+
+ virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, LightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache)=0;
+
+
+ virtual void reset_canvas()=0;
+
+ virtual ~RasterizerCanvas() {}
+};
+
+
+
+class RasterizerScene {
+public:
+
+
+
+ virtual ~RasterizerScene() {}
+};
+
+
+
+class Rasterizer {
+protected:
+ static Rasterizer* (*_create_func)();
+public:
+ static Rasterizer *create();
+
+ virtual RasterizerStorage *get_storage()=0;
+ virtual RasterizerCanvas *get_canvas()=0;
+ virtual RasterizerScene *get_scene()=0;
+
+ virtual void initialize()=0;
+ virtual void begin_frame()=0;
+ virtual void set_current_render_target(RID p_render_target)=0;
+ virtual void restore_render_target()=0;
+ virtual void clear_render_target(const Color& p_color)=0;
+ virtual void blit_render_target_to_screen(RID p_render_target,const Rect2& p_screen_rect,int p_screen=0)=0;
+ virtual void end_frame()=0;
+ virtual void finalize()=0;
+
+
+ virtual ~Rasterizer() {}
+};
+
+
+
+
+#if 0
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -41,7 +705,7 @@ class Rasterizer {
protected:
- typedef void (*CanvasItemDrawViewportFunc)(VisualServer*owner,void*ud,const Rect2& p_rect);
+ typedef void (*ItemDrawViewportFunc)(VisualServer*owner,void*ud,const Rect2& p_rect);
RID create_default_material();
RID create_overdraw_debug_material();
@@ -581,7 +1245,7 @@ public:
};
- struct CanvasLight {
+ struct Light {
@@ -597,7 +1261,7 @@ public:
int layer_max;
int item_mask;
int item_shadow_mask;
- VS::CanvasLightMode mode;
+ VS::LightMode mode;
RID texture;
Vector2 texture_offset;
RID canvas;
@@ -616,12 +1280,12 @@ public:
Matrix32 light_shader_xform;
Vector2 light_shader_pos;
- CanvasLight *shadows_next_ptr;
- CanvasLight *filter_next_ptr;
- CanvasLight *next_ptr;
- CanvasLight *mask_next_ptr;
+ Light *shadows_next_ptr;
+ Light *filter_next_ptr;
+ Light *next_ptr;
+ Light *mask_next_ptr;
- CanvasLight() {
+ Light() {
enabled=true;
color=Color(1,1,1);
shadow_color=Color(0,0,0,0);
@@ -645,20 +1309,20 @@ public:
}
};
- struct CanvasItem;
+ struct Item;
- struct CanvasItemMaterial {
+ struct ItemMaterial {
RID shader;
Map<StringName,Variant> shader_param;
uint32_t shader_version;
- Set<CanvasItem*> owners;
- VS::CanvasItemShadingMode shading_mode;
+ Set<Item*> owners;
+ VS::ItemShadingMode shading_mode;
- CanvasItemMaterial() {shading_mode=VS::CANVAS_ITEM_SHADING_NORMAL; shader_version=0; }
+ ItemMaterial() {shading_mode=VS::CANVAS_ITEM_SHADING_NORMAL; shader_version=0; }
};
- struct CanvasItem {
+ struct Item {
struct Command {
@@ -788,8 +1452,8 @@ public:
mutable bool custom_rect;
mutable bool rect_dirty;
mutable Rect2 rect;
- CanvasItem*next;
- CanvasItemMaterial* material;
+ Item*next;
+ ItemMaterial* material;
struct CopyBackBuffer {
Rect2 rect;
Rect2 screen_rect;
@@ -801,8 +1465,8 @@ public:
float final_opacity;
Matrix32 final_transform;
Rect2 final_clip_rect;
- CanvasItem* final_clip_owner;
- CanvasItem* material_owner;
+ Item* final_clip_owner;
+ Item* material_owner;
ViewportRender *vp_render;
bool distance_field;
bool light_masked;
@@ -826,35 +1490,35 @@ public:
bool found_xform=false;
bool first=true;
- const CanvasItem::Command * const *cmd = &commands[0];
+ const Item::Command * const *cmd = &commands[0];
for (int i=0;i<s;i++) {
- const CanvasItem::Command *c=cmd[i];
+ const Item::Command *c=cmd[i];
Rect2 r;
switch(c->type) {
- case CanvasItem::Command::TYPE_LINE: {
+ case Item::Command::TYPE_LINE: {
- const CanvasItem::CommandLine* line = static_cast< const CanvasItem::CommandLine*>(c);
+ const Item::CommandLine* line = static_cast< const Item::CommandLine*>(c);
r.pos=line->from;
r.expand_to(line->to);
} break;
- case CanvasItem::Command::TYPE_RECT: {
+ case Item::Command::TYPE_RECT: {
- const CanvasItem::CommandRect* crect = static_cast< const CanvasItem::CommandRect*>(c);
+ const Item::CommandRect* crect = static_cast< const Item::CommandRect*>(c);
r=crect->rect;
} break;
- case CanvasItem::Command::TYPE_STYLE: {
+ case Item::Command::TYPE_STYLE: {
- const CanvasItem::CommandStyle* style = static_cast< const CanvasItem::CommandStyle*>(c);
+ const Item::CommandStyle* style = static_cast< const Item::CommandStyle*>(c);
r=style->rect;
} break;
- case CanvasItem::Command::TYPE_PRIMITIVE: {
+ case Item::Command::TYPE_PRIMITIVE: {
- const CanvasItem::CommandPrimitive* primitive = static_cast< const CanvasItem::CommandPrimitive*>(c);
+ const Item::CommandPrimitive* primitive = static_cast< const Item::CommandPrimitive*>(c);
r.pos=primitive->points[0];
for(int i=1;i<primitive->points.size();i++) {
@@ -862,9 +1526,9 @@ public:
}
} break;
- case CanvasItem::Command::TYPE_POLYGON: {
+ case Item::Command::TYPE_POLYGON: {
- const CanvasItem::CommandPolygon* polygon = static_cast< const CanvasItem::CommandPolygon*>(c);
+ const Item::CommandPolygon* polygon = static_cast< const Item::CommandPolygon*>(c);
int l = polygon->points.size();
const Point2*pp=&polygon->points[0];
r.pos=pp[0];
@@ -875,9 +1539,9 @@ public:
}
} break;
- case CanvasItem::Command::TYPE_POLYGON_PTR: {
+ case Item::Command::TYPE_POLYGON_PTR: {
- const CanvasItem::CommandPolygonPtr* polygon = static_cast< const CanvasItem::CommandPolygonPtr*>(c);
+ const Item::CommandPolygonPtr* polygon = static_cast< const Item::CommandPolygonPtr*>(c);
int l = polygon->count;
if (polygon->indices != NULL) {
@@ -894,23 +1558,23 @@ public:
}
}
} break;
- case CanvasItem::Command::TYPE_CIRCLE: {
+ case Item::Command::TYPE_CIRCLE: {
- const CanvasItem::CommandCircle* circle = static_cast< const CanvasItem::CommandCircle*>(c);
+ const Item::CommandCircle* circle = static_cast< const Item::CommandCircle*>(c);
r.pos=Point2(-circle->radius,-circle->radius)+circle->pos;
r.size=Point2(circle->radius*2.0,circle->radius*2.0);
} break;
- case CanvasItem::Command::TYPE_TRANSFORM: {
+ case Item::Command::TYPE_TRANSFORM: {
- const CanvasItem::CommandTransform* transform = static_cast<const CanvasItem::CommandTransform*>(c);
+ const Item::CommandTransform* transform = static_cast<const Item::CommandTransform*>(c);
xf=transform->xform;
found_xform=true;
continue;
} break;
- case CanvasItem::Command::TYPE_BLEND_MODE: {
+ case Item::Command::TYPE_BLEND_MODE: {
} break;
- case CanvasItem::Command::TYPE_CLIP_IGNORE: {
+ case Item::Command::TYPE_CLIP_IGNORE: {
} break;
}
@@ -933,12 +1597,12 @@ public:
}
void clear() { for (int i=0;i<commands.size();i++) memdelete( commands[i] ); commands.clear(); clip=false; rect_dirty=true; final_clip_owner=NULL; material_owner=NULL; light_masked=false; }
- CanvasItem() { light_mask=1; vp_render=NULL; next=NULL; final_clip_owner=NULL; clip=false; final_opacity=1; blend_mode=VS::MATERIAL_BLEND_MODE_MIX; visible=true; rect_dirty=true; custom_rect=false; ontop=true; material_owner=NULL; material=NULL; copy_back_buffer=NULL; distance_field=false; light_masked=false; }
- virtual ~CanvasItem() { clear(); if (copy_back_buffer) memdelete(copy_back_buffer); }
+ Item() { light_mask=1; vp_render=NULL; next=NULL; final_clip_owner=NULL; clip=false; final_opacity=1; blend_mode=VS::MATERIAL_BLEND_MODE_MIX; visible=true; rect_dirty=true; custom_rect=false; ontop=true; material_owner=NULL; material=NULL; copy_back_buffer=NULL; distance_field=false; light_masked=false; }
+ virtual ~Item() { clear(); if (copy_back_buffer) memdelete(copy_back_buffer); }
};
- CanvasItemDrawViewportFunc draw_viewport_func;
+ ItemDrawViewportFunc draw_viewport_func;
virtual void begin_canvas_bg()=0;
@@ -956,8 +1620,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)=0;
virtual void canvas_set_transform(const Matrix32& p_transform)=0;
- virtual void canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light)=0;
- virtual void canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow)=0;
+ virtual void canvas_render_items(Item *p_item_list,int p_z,const Color& p_modulate,Light *p_light)=0;
+ virtual void canvas_debug_viewport_shadows(Light* p_lights_with_shadow)=0;
/* LIGHT SHADOW MAPPING */
virtual RID canvas_light_occluder_create()=0;
@@ -966,7 +1630,7 @@ public:
virtual RID canvas_light_shadow_buffer_create(int p_width)=0;
- struct CanvasLightOccluderInstance {
+ struct LightOccluderInstance {
bool enabled;
@@ -979,14 +1643,14 @@ public:
int light_mask;
VS::CanvasOccluderPolygonCullMode cull_cache;
- CanvasLightOccluderInstance *next;
+ LightOccluderInstance *next;
- CanvasLightOccluderInstance() { enabled=true; next=NULL; light_mask=1; cull_cache=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; }
+ LightOccluderInstance() { enabled=true; next=NULL; light_mask=1; cull_cache=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; }
};
- virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache)=0;
+ virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, LightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache)=0;
/* ENVIRONMENT */
@@ -1050,5 +1714,5 @@ public:
};
-
+#endif
#endif
diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp
deleted file mode 100644
index edbdc2fe23..0000000000
--- a/servers/visual/rasterizer_dummy.cpp
+++ /dev/null
@@ -1,1961 +0,0 @@
-/*************************************************************************/
-/* rasterizer_dummy.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "rasterizer_dummy.h"
-
-/* TEXTURE API */
-
-
-RID RasterizerDummy::texture_create() {
-
- Texture *texture = memnew(Texture);
- ERR_FAIL_COND_V(!texture,RID());
- return texture_owner.make_rid( texture );
-
-}
-
-void RasterizerDummy::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags) {
-
-
- 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;
-}
-
-void RasterizerDummy::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->format != p_image.get_format() );
-
- texture->image[p_cube_side]=p_image;
-
-}
-
-Image RasterizerDummy::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());
-
- return texture->image[p_cube_side];
-}
-
-void RasterizerDummy::texture_set_flags(RID p_texture,uint32_t p_flags) {
-
- Texture *texture = texture_owner.get( p_texture );
- ERR_FAIL_COND(!texture);
- uint32_t cube = texture->flags & VS::TEXTURE_FLAG_CUBEMAP;
- texture->flags=p_flags|cube; // can't remove a cube from being a cube
-
-}
-uint32_t RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::texture_get_height(RID p_texture) const {
-
- Texture * texture = texture_owner.get(p_texture);
-
- ERR_FAIL_COND_V(!texture,0);
-
- return texture->height;
-}
-
-bool RasterizerDummy::texture_has_alpha(RID p_texture) const {
-
- Texture * texture = texture_owner.get(p_texture);
-
- ERR_FAIL_COND_V(!texture,0);
-
- return false;
-
-}
-
-void RasterizerDummy::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 RasterizerDummy::texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const {
-
-
-}
-
-/* SHADER API */
-
-/* SHADER API */
-
-RID RasterizerDummy::shader_create(VS::ShaderMode p_mode) {
-
- Shader *shader = memnew( Shader );
- shader->mode=p_mode;
- shader->fragment_line=0;
- shader->vertex_line=0;
- shader->light_line=0;
- RID rid = shader_owner.make_rid(shader);
-
- return rid;
-
-}
-
-
-
-void RasterizerDummy::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);
- shader->mode=p_mode;
-
-}
-VS::ShaderMode RasterizerDummy::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 RasterizerDummy::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);
- 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_vertex_ofs;
-
-}
-
-
-String RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
-
- Shader *shader=shader_owner.get(p_shader);
- ERR_FAIL_COND(!shader);
-
-}
-
-
-void RasterizerDummy::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
-
-}
-
-RID RasterizerDummy::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const {
-
- return RID();
-}
-
-Variant RasterizerDummy::shader_get_default_param(RID p_shader, const StringName& p_name) {
-
- return Variant();
-}
-
-/* COMMON MATERIAL API */
-
-
-RID RasterizerDummy::material_create() {
-
- return material_owner.make_rid( memnew( Material ) );
-}
-
-void RasterizerDummy::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 RasterizerDummy::material_get_shader(RID p_material) const {
-
- Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,RID());
- return material->shader;
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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;
-}
-
-/* MESH API */
-
-
-RID RasterizerDummy::mesh_create() {
-
-
- return mesh_owner.make_rid( memnew( Mesh ) );
-}
-
-
-void RasterizerDummy::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);
-
- Surface s;
-
-
- s.format=0;
-
- for(int i=0;i<p_arrays.size();i++) {
-
- if (p_arrays[i].get_type()==Variant::NIL)
- continue;
-
- s.format|=(1<<i);
-
- if (i==VS::ARRAY_VERTEX) {
-
- Vector3Array v = p_arrays[i];
- int len = v.size();
- ERR_FAIL_COND(len==0);
- Vector3Array::Read r = v.read();
-
-
- for(int i=0;i<len;i++) {
-
- if (i==0)
- s.aabb.pos=r[0];
- else
- s.aabb.expand_to(r[i]);
- }
-
- }
- }
-
- ERR_FAIL_COND((s.format&VS::ARRAY_FORMAT_VERTEX)==0); // mandatory
-
- s.data=p_arrays;
- s.morph_data=p_blend_shapes;
- s.primitive=p_primitive;
- s.alpha_sort=p_alpha_sort;
- s.morph_target_count=mesh->morph_target_count;
- s.morph_format=s.format;
-
-
- Surface *surface = memnew( Surface );
- *surface=s;
-
- mesh->surfaces.push_back(surface);
-
-
-}
-
-
-
-void RasterizerDummy::mesh_add_custom_surface(RID p_mesh,const Variant& p_dat) {
-
- ERR_EXPLAIN("Dummy Rasterizer does not support custom surfaces. Running on wrong platform?");
- ERR_FAIL_V();
-}
-
-Array RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 );
-
- Vector3Array arr = surface->data[VS::ARRAY_VERTEX];
- return arr.size();
-
-}
-
-int RasterizerDummy::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 );
-
- IntArray arr = surface->data[VS::ARRAY_INDEX];
- return arr.size();
-
-}
-uint32_t RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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);
-
- memdelete( mesh->surfaces[p_index] );
- mesh->surfaces.remove(p_index);
-
-}
-int RasterizerDummy::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 RasterizerDummy::mesh_get_aabb(RID p_mesh,RID p_skeleton) const {
-
- Mesh *mesh = mesh_owner.get( p_mesh );
- ERR_FAIL_COND_V(!mesh,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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::multimesh_create() {
-
- return multimesh_owner.make_rid( memnew( MultiMesh ));
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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->elements[p_index].xform=p_transform;
-
-}
-void RasterizerDummy::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->elements[p_index].color=p_color;
-
-}
-
-RID RasterizerDummy::multimesh_get_mesh(RID p_multimesh) const {
-
- MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,RID());
-
- return multimesh->mesh;
-}
-AABB RasterizerDummy::multimesh_get_aabb(RID p_multimesh) const {
-
- MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
- ERR_FAIL_COND_V(!multimesh,AABB());
-
- return multimesh->aabb;
-}
-
-Transform RasterizerDummy::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());
-
- return multimesh->elements[p_index].xform;
-
-}
-Color RasterizerDummy::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());
-
- return multimesh->elements[p_index].color;
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::immediate_create() {
-
- Immediate *im = memnew( Immediate );
- return immediate_owner.make_rid(im);
-
-}
-
-void RasterizerDummy::immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture){
-
-
-}
-void RasterizerDummy::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
-
-
-}
-void RasterizerDummy::immediate_normal(RID p_immediate,const Vector3& p_normal){
-
-
-}
-void RasterizerDummy::immediate_tangent(RID p_immediate,const Plane& p_tangent){
-
-
-}
-void RasterizerDummy::immediate_color(RID p_immediate,const Color& p_color){
-
-
-}
-void RasterizerDummy::immediate_uv(RID p_immediate,const Vector2& tex_uv){
-
-
-}
-void RasterizerDummy::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
-
-
-}
-
-void RasterizerDummy::immediate_end(RID p_immediate){
-
-
-}
-void RasterizerDummy::immediate_clear(RID p_immediate) {
-
-
-}
-
-AABB RasterizerDummy::immediate_get_aabb(RID p_immediate) const {
-
- return AABB(Vector3(-1,-1,-1),Vector3(2,2,2));
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::particles_create() {
-
- Particles *particles = memnew( Particles );
- ERR_FAIL_COND_V(!particles,RID());
- return particles_owner.make_rid(particles);
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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> RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::skeleton_create() {
-
- Skeleton *skeleton = memnew( Skeleton );
- ERR_FAIL_COND_V(!skeleton,RID());
- return skeleton_owner.make_rid( skeleton );
-}
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::light_create(VS::LightType p_type) {
-
- Light *light = memnew( Light );
- light->type=p_type;
- return light_owner.make_rid(light);
-}
-
-VS::LightType RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::light_get_projector(RID p_light) const {
-
- Light *light = light_owner.get(p_light);
- ERR_FAIL_COND_V(!light,RID());
- return light->projector;
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::light_set_operator(RID p_light,VS::LightOp p_op) {
-
- Light * light = light_owner.get( p_light );
- ERR_FAIL_COND(!light);
-
-
-};
-
-VS::LightOp RasterizerDummy::light_get_operator(RID p_light) const {
-
- return VS::LightOp(0);
-};
-
-void RasterizerDummy::light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode) {
-
-
-}
-
-VS::LightOmniShadowMode RasterizerDummy::light_omni_get_shadow_mode(RID p_light) const{
-
- return VS::LightOmniShadowMode(0);
-}
-
-void RasterizerDummy::light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode) {
-
-
-}
-
-VS::LightDirectionalShadowMode RasterizerDummy::light_directional_get_shadow_mode(RID p_light) const {
-
- return VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
-}
-
-void RasterizerDummy::light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value) {
-
-
-}
-
-float RasterizerDummy::light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const {
-
- return 0;
-}
-
-
-AABB RasterizerDummy::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 RasterizerDummy::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;
-
-
- return light_instance_owner.make_rid( light_instance );
-}
-void RasterizerDummy::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 RasterizerDummy::light_instance_has_shadow(RID p_light_instance) const {
-
- return false;
-
-}
-
-
-bool RasterizerDummy::light_instance_assign_shadow(RID p_light_instance) {
-
- return false;
-
-}
-
-
-Rasterizer::ShadowType RasterizerDummy::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 RasterizerDummy::light_instance_get_shadow_type(RID p_light_instance,bool p_far) const {
-
- return SHADOW_NONE;
-}
-void RasterizerDummy::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 RasterizerDummy::light_instance_get_shadow_passes(RID p_light_instance) const {
-
- return 0;
-}
-
-bool RasterizerDummy::light_instance_get_pssm_shadow_overlap(RID p_light_instance) const {
-
- return false;
-}
-
-
-void RasterizerDummy::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 RasterizerDummy::shadow_clear_near() {
-
-
-}
-
-bool RasterizerDummy::shadow_allocate_near(RID p_light) {
-
- return false;
-}
-
-bool RasterizerDummy::shadow_allocate_far(RID p_light) {
-
- return false;
-}
-
-/* PARTICLES INSTANCE */
-
-RID RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::viewport_data_create() {
-
- return RID();
-}
-
-RID RasterizerDummy::render_target_create(){
-
- return RID();
-
-}
-void RasterizerDummy::render_target_set_size(RID p_render_target, int p_width, int p_height){
-
-
-}
-RID RasterizerDummy::render_target_get_texture(RID p_render_target) const{
-
- return RID();
-
-}
-bool RasterizerDummy::render_target_renedered_in_frame(RID p_render_target){
-
- return false;
-}
-
-
-void RasterizerDummy::begin_frame() {
-
-
-
-}
-
-void RasterizerDummy::capture_viewport(Image* r_capture) {
-
-
-}
-
-
-void RasterizerDummy::clear_viewport(const Color& p_color) {
-
-
-};
-
-void RasterizerDummy::set_viewport(const VS::ViewportRect& p_viewport) {
-
-
-
-}
-
-void RasterizerDummy::set_render_target(RID p_render_target, bool p_transparent_bg, bool p_vflip) {
-
-
-}
-
-
-void RasterizerDummy::begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug) {
-
-
-};
-
-void RasterizerDummy::begin_shadow_map( RID p_light_instance, int p_shadow_pass ) {
-
-}
-
-void RasterizerDummy::set_camera(const Transform& p_world, const CameraMatrix& p_projection, bool p_ortho_hint) {
-
-
-}
-
-void RasterizerDummy::add_light( RID p_light_instance ) {
-
-
-
-}
-
-
-
-
-void RasterizerDummy::add_mesh( const RID& p_mesh, const InstanceData *p_data) {
-
-
-}
-
-void RasterizerDummy::add_multimesh( const RID& p_multimesh, const InstanceData *p_data){
-
-
-
-
-}
-
-void RasterizerDummy::add_particles( const RID& p_particle_instance, const InstanceData *p_data){
-
-
-
-}
-
-
-
-void RasterizerDummy::end_scene() {
-
-
-}
-void RasterizerDummy::end_shadow_map() {
-
-}
-
-
-void RasterizerDummy::end_frame() {
-
-
-}
-
-RID RasterizerDummy::canvas_light_occluder_create() {
- return RID();
-}
-
-void RasterizerDummy::canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines) {
-
-
-}
-
-RID RasterizerDummy::canvas_light_shadow_buffer_create(int p_width) {
-
- return RID();
-}
-
-void RasterizerDummy::canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) {
-
-
-}
-
-void RasterizerDummy::canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow) {
-
-
-}
-
-/* CANVAS API */
-
-
-void RasterizerDummy::begin_canvas_bg() {
-
-}
-void RasterizerDummy::canvas_begin() {
-
-
-
-}
-void RasterizerDummy::canvas_disable_blending() {
-
-
-
-}
-
-void RasterizerDummy::canvas_set_opacity(float p_opacity) {
-
-
-}
-
-void RasterizerDummy::canvas_set_blend_mode(VS::MaterialBlendMode p_mode) {
-
-
-}
-
-
-void RasterizerDummy::canvas_begin_rect(const Matrix32& p_transform) {
-
-
-
-}
-
-void RasterizerDummy::canvas_set_clip(bool p_clip, const Rect2& p_rect) {
-
-
-
-
-}
-
-void RasterizerDummy::canvas_end_rect() {
-
-
-}
-
-void RasterizerDummy::canvas_draw_line(const Point2& p_from, const Point2& p_to, const Color& p_color, float p_width, bool p_antialiased) {
-
-
-
-}
-
-void RasterizerDummy::canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate) {
-
-
-
-
-}
-void RasterizerDummy::canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) {
-
-
-}
-void RasterizerDummy::canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) {
-
-
-
-}
-
-
-void RasterizerDummy::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) {
-
-
-
-}
-
-void RasterizerDummy::canvas_set_transform(const Matrix32& p_transform) {
-
-
-}
-
-void RasterizerDummy::canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light) {
-
-
-}
-
-/* ENVIRONMENT */
-
-RID RasterizerDummy::environment_create() {
-
- Environment * env = memnew( Environment );
- return environment_owner.make_rid(env);
-}
-
-void RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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 RasterizerDummy::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];
-
-}
-
-
-RID RasterizerDummy::sampled_light_dp_create(int p_width,int p_height) {
-
- return sampled_light_owner.make_rid(memnew(SampledLight));
-}
-
-void RasterizerDummy::sampled_light_dp_update(RID p_sampled_light, const Color *p_data, float p_multiplier) {
-
-
-}
-
-
-/*MISC*/
-
-bool RasterizerDummy::is_texture(const RID& p_rid) const {
-
- return texture_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_material(const RID& p_rid) const {
-
- return material_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_mesh(const RID& p_rid) const {
-
- return mesh_owner.owns(p_rid);
-}
-
-bool RasterizerDummy::is_immediate(const RID& p_rid) const {
-
- return immediate_owner.owns(p_rid);
-}
-
-bool RasterizerDummy::is_multimesh(const RID& p_rid) const {
-
- return multimesh_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_particles(const RID &p_beam) const {
-
- return particles_owner.owns(p_beam);
-}
-
-bool RasterizerDummy::is_light(const RID& p_rid) const {
-
- return light_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_light_instance(const RID& p_rid) const {
-
- return light_instance_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_particles_instance(const RID& p_rid) const {
-
- return particles_instance_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_skeleton(const RID& p_rid) const {
-
- return skeleton_owner.owns(p_rid);
-}
-bool RasterizerDummy::is_environment(const RID& p_rid) const {
-
- return environment_owner.owns(p_rid);
-}
-
-bool RasterizerDummy::is_canvas_light_occluder(const RID& p_rid) const {
-
- return false;
-}
-
-bool RasterizerDummy::is_shader(const RID& p_rid) const {
-
- return false;
-}
-
-void RasterizerDummy::free(const RID& p_rid) {
-
- if (texture_owner.owns(p_rid)) {
-
- // delete the texture
- Texture *texture = texture_owner.get(p_rid);
- 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 );
- material_owner.free(p_rid);
- memdelete(material);
-
- } else if (mesh_owner.owns(p_rid)) {
-
- Mesh *mesh = mesh_owner.get(p_rid);
-
- for (int i=0;i<mesh->surfaces.size();i++) {
-
- memdelete( mesh->surfaces[i] );
- };
-
- mesh->surfaces.clear();
- mesh_owner.free(p_rid);
- memdelete(mesh);
-
- } else if (multimesh_owner.owns(p_rid)) {
-
- MultiMesh *multimesh = multimesh_owner.get(p_rid);
- multimesh_owner.free(p_rid);
- memdelete(multimesh);
-
- } else if (immediate_owner.owns(p_rid)) {
-
- Immediate *immediate = immediate_owner.get(p_rid);
- immediate_owner.free(p_rid);
- memdelete(immediate);
-
- } else if (particles_owner.owns(p_rid)) {
-
- Particles *particles = particles_owner.get(p_rid);
- particles_owner.free(p_rid);
- memdelete(particles);
- } else if (particles_instance_owner.owns(p_rid)) {
-
- ParticlesInstance *particles_isntance = particles_instance_owner.get(p_rid);
- particles_instance_owner.free(p_rid);
- memdelete(particles_isntance);
-
- } else if (skeleton_owner.owns(p_rid)) {
-
- Skeleton *skeleton = skeleton_owner.get( p_rid );
- skeleton_owner.free(p_rid);
- memdelete(skeleton);
-
- } else if (light_owner.owns(p_rid)) {
-
- Light *light = light_owner.get( p_rid );
- light_owner.free(p_rid);
- memdelete(light);
-
- } else if (light_instance_owner.owns(p_rid)) {
-
- LightInstance *light_instance = light_instance_owner.get( p_rid );
- light_instance_owner.free(p_rid);
- memdelete( light_instance );
-
-
- } else if (environment_owner.owns(p_rid)) {
-
- Environment *env = environment_owner.get( p_rid );
- 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 RasterizerDummy::custom_shade_model_set_shader(int p_model, RID p_shader) {
-
-
-};
-
-RID RasterizerDummy::custom_shade_model_get_shader(int p_model) const {
-
- return RID();
-};
-
-void RasterizerDummy::custom_shade_model_set_name(int p_model, const String& p_name) {
-
-};
-
-String RasterizerDummy::custom_shade_model_get_name(int p_model) const {
-
- return String();
-};
-
-void RasterizerDummy::custom_shade_model_set_param_info(int p_model, const List<PropertyInfo>& p_info) {
-
-};
-
-void RasterizerDummy::custom_shade_model_get_param_info(int p_model, List<PropertyInfo>* p_info) const {
-
-};
-
-
-
-void RasterizerDummy::init() {
-
-
-}
-
-void RasterizerDummy::finish() {
-
-
-}
-
-int RasterizerDummy::get_render_info(VS::RenderInfo p_info) {
-
- return 0;
-}
-
-bool RasterizerDummy::needs_to_draw_next_frame() const {
-
- return false;
-}
-
-
-bool RasterizerDummy::has_feature(VS::Features p_feature) const {
-
- return false;
-
-}
-
-void RasterizerDummy::restore_framebuffer() {
-
-}
-
-RasterizerDummy::RasterizerDummy() {
-
-};
-
-RasterizerDummy::~RasterizerDummy() {
-
-};
diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h
deleted file mode 100644
index cac36eb6fc..0000000000
--- a/servers/visual/rasterizer_dummy.h
+++ /dev/null
@@ -1,791 +0,0 @@
-/*************************************************************************/
-/* rasterizer_dummy.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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_DUMMY_H
-#define RASTERIZER_DUMMY_H
-
-#include "servers/visual/rasterizer.h"
-
-
-#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 "servers/visual/particle_system_sw.h"
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-class RasterizerDummy : public Rasterizer {
-
- struct Texture {
-
- uint32_t flags;
- int width,height;
- Image::Format format;
- Image image[6];
- Texture() {
-
- flags=width=height=0;
- format=Image::FORMAT_GRAYSCALE;
- }
-
- ~Texture() {
-
- }
- };
-
- 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 flags[VS::MATERIAL_FLAG_MAX];
-
- VS::MaterialDepthDrawMode depth_draw_mode;
-
- VS::MaterialBlendMode blend_mode;
-
- float line_width;
- float point_size;
-
- RID shader; // shader material
-
- Map<StringName,Variant> shader_params;
-
-
- Material() {
-
-
- for(int i=0;i<VS::MATERIAL_FLAG_MAX;i++)
- flags[i]=false;
- flags[VS::MATERIAL_FLAG_VISIBLE]=true;
-
- depth_draw_mode=VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY;
- line_width=1;
- blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
- 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 {
-
- Array data;
- Array morph_data;
-
- bool packed;
- bool alpha_sort;
- int morph_target_count;
- AABB aabb;
-
- VS::PrimitiveType primitive;
-
- uint32_t format;
- uint32_t morph_format;
-
- Surface() {
-
- packed=false;
- morph_target_count=0;
- material_owned=false;
- format=0;
- morph_format=0;
-
- primitive=VS::PRIMITIVE_POINTS;
- }
-
- ~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;
-
- struct MultiMesh;
-
- struct MultiMeshSurface : public Geometry {
-
- Surface *surface;
- MultiMeshSurface() { type=GEOMETRY_MULTISURFACE; }
- };
-
- struct MultiMesh : public GeometryOwner {
-
- struct Element {
-
- Transform xform;
- Color color;
- };
-
- AABB aabb;
- RID mesh;
- int visible;
-
- //IDirect3DVertexBuffer9* instance_buffer;
- Vector<Element> elements;
-
- MultiMesh() {
- 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;
-
-
- LightInstance() { linear_att=1.0; }
-
- };
-
- mutable RID_Owner<Light> light_owner;
- mutable RID_Owner<LightInstance> light_instance_owner;
-
-
- RID default_material;
-
-
-
-
-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;
-
- virtual void texture_set_path(RID p_texture,const String& p_path) {}
- virtual String texture_get_path(RID p_texture) const { return String(); }
- virtual void texture_debug_usage(List<VS::TextureInfo> *r_info) {}
-
- virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable) {}
-
- /* 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;
-
- virtual Variant shader_get_default_param(RID p_shader, const StringName& p_name);
-
- /* 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;
-
- /* 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 void immediate_set_material(RID p_immediate,RID p_material);
- virtual RID immediate_get_material(RID p_immediate) const;
-
- virtual AABB immediate_get_aabb(RID p_mesh) 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,bool p_ortho_hint);
-
- 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 begin_canvas_bg();
- 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,bool p_antialiased);
- 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, const Rect2& p_src_region, 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);
-
- virtual void canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light);
-
- virtual RID canvas_light_occluder_create();
- virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines);
-
- virtual RID canvas_light_shadow_buffer_create(int p_width);
- virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache);
-
- virtual void canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow);
-
- /* 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_immediate(const RID& p_rid) const;
- virtual bool is_multimesh(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_canvas_light_occluder(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);
-
- virtual bool needs_to_draw_next_frame() const;
-
- virtual bool has_feature(VS::Features p_feature) const;
-
- virtual void restore_framebuffer();
-
- RasterizerDummy();
- virtual ~RasterizerDummy();
-};
-
-
-#endif // RASTERIZER_DUMMY_H
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index fdf3cb622d..287293a437 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -46,7 +46,7 @@ static bool _is_hex(CharType c) {
const char * ShaderLanguage::token_names[TK_MAX]={
"EMPTY",
- "INDENTIFIER",
+ "IDENTIFIER",
"TRUE",
"FALSE",
"REAL_CONSTANT",
@@ -97,401 +97,402 @@ const char * ShaderLanguage::token_names[TK_MAX]={
"ERROR",
};
-ShaderLanguage::Token ShaderLanguage::read_token(const CharType* p_text,int p_len,int &r_line,int &r_chars) {
+String ShaderLanguage::get_token_text(Token p_token) {
-#define GETCHAR(m_idx) ((m_idx<p_len)?p_text[m_idx]:CharType(0))
-
- r_chars=1; //by default everything eats one char
- switch(GETCHAR(0)) {
-
- case '\t':
- case '\r':
- case ' ':
- return Token();
- case '\n':
- r_line++;
- return Token();
- case '/': {
+ String name=token_names[p_token.type];
+ if (p_token.type==TK_INT_CONSTANT || p_token.type==TK_REAL_CONSTANT) {
+ name+="("+rtos(p_token.constant)+")";
+ } else if (p_token.type==TK_IDENTIFIER) {
+ name+="("+String(p_token.text)+")";
+ }
- switch(GETCHAR(1)) {
- case '*': { // block comment
+ return name;
+}
+ShaderLanguage::Token ShaderLanguage::_make_token(TokenType p_type,const StringName& p_text) {
- while(true) {
- if (GETCHAR(r_chars+1)==0) {
- r_chars+=1;
- break;
- } if (GETCHAR(r_chars+1)=='*' && GETCHAR(r_chars+2)=='/') {
- r_chars+=3;
- break;
- } if (GETCHAR(r_chars+1)=='\n') {
- r_line++;
- }
+ Token tk;
+ tk.type=p_type;
+ tk.text=p_text;
+ tk.line=tk_line;
+ return tk;
+}
- r_chars++;
- }
- return Token();
+ShaderLanguage::Token ShaderLanguage::_get_token() {
- } break;
- case '/': { // line comment skip
+#define GETCHAR(m_idx) ((char_idx<code.length())?code[char_idx]:CharType(0))
- while(GETCHAR(r_chars+1)!='\n' && GETCHAR(r_chars+1)!=0) {
- r_chars++;
- }
- r_chars++;
- //r_line++;
+ while(true) {
+ char_idx++;
+ switch(GETCHAR(-1)) {
- return Token();
+ case '\t':
+ case '\r':
+ case ' ':
+ continue;
+ case '\n':
+ tk_line++;
+ continue;
+ case '/': {
- } break;
- case '=': { // diveq
+ switch(GETCHAR(0)) {
+ case '*': { // block comment
- r_chars=2;
- return Token(TK_OP_ASSIGN_DIV);
+ char_idx++;
+ while(true) {
+ if (GETCHAR(0)==0) {
+ return _make_token(TK_EOF);
+ } if (GETCHAR(0)=='*' && GETCHAR(1)=='/') {
+ char_idx+=2;
+ break;
+ } if (GETCHAR(r_chars+1)=='\n') {
+ tk_line++;
+ }
- } break;
- default:
- return Token(TK_OP_DIV);
+ char_idx++;
+ }
- }
- } break;
- case '=': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_EQUAL);
- }
+ } break;
+ case '/': { // line comment skip
- return Token(TK_OP_ASSIGN);
- } break;
- case '<': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_LESS_EQUAL);
- } /*else if (GETCHAR(1)=='<') {
- r_chars++;
- if (GETCHAR(2)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_SHIFT_LEFT);
- }
+ while(true) {
+ if (GETCHAR(0)=='\n') {
+ char_idx++;
+ break;
+ }
+ if (GETCHAR(0)==0) {
+ return _make_token(TK_EOF);
+ }
+ char_idx++;
+ }
- return Token(TK_OP_SHIFT_LEFT);
- }*/
+ } break;
+ case '=': { // diveq
- return Token(TK_OP_LESS);
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_DIV);
- } break;
- case '>': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_GREATER_EQUAL);
- }/* else if (GETCHAR(1)=='<') {
- r_chars++;
- if (GETCHAR(2)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_SHIFT_RIGHT);
+ } break;
+ default:
+ return _make_token(TK_OP_DIV);
}
- return Token(TK_OP_SHIFT_RIGHT);
- }*/
+ continue; //a comment, continue to next token
+ } break;
+ case '=': {
- return Token(TK_OP_GREATER);
-
- } break;
- case '!': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_NOT_EQUAL);
- }
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_EQUAL);
+ }
- return Token(TK_OP_NOT);
+ return _make_token(TK_OP_ASSIGN);
+
+ } break;
+ case '<': {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_LESS_EQUAL);
+ } else if (GETCHAR(0)=='<') {
+ char_idx++;
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_SHIFT_LEFT);
+ }
- } break;
- //case '"' //string - no strings in shader
- //case '\'' //string - no strings in shader
- case '{':
- return Token(TK_CURLY_BRACKET_OPEN);
- case '}':
- return Token(TK_CURLY_BRACKET_CLOSE);
- //case '[':
- // return Token(TK_BRACKET_OPEN);
- //case ']':
- // return Token(TK_BRACKET_CLOSE);
- case '(':
- return Token(TK_PARENTHESIS_OPEN);
- case ')':
- return Token(TK_PARENTHESIS_CLOSE);
- case ',':
- return Token(TK_COMMA);
- case ';':
- return Token(TK_SEMICOLON);
- //case '?':
- // return Token(TK_QUESTION_MARK);
- //case ':':
- // return Token(TK_COLON); //for methods maybe but now useless.
- //case '^':
- // return Token(TK_OP_BIT_XOR);
- //case '~':
- // return Token(TK_OP_BIT_INVERT);
- case '&': {
-
- if (GETCHAR(1)=='&') {
-
- r_chars++;
- return Token(TK_OP_AND);
- }
+ return _make_token(TK_OP_SHIFT_LEFT);
+ }
- return Token(TK_ERROR,"Unknown character");
+ return _make_token(TK_OP_LESS);
+
+ } break;
+ case '>': {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_GREATER_EQUAL);
+ } else if (GETCHAR(0)=='<') {
+ char_idx++;;
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_SHIFT_RIGHT);
+ }
-/*
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_BIT_AND);
- } else if (GETCHAR(1)=='&') {
- r_chars++;
- return Token(TK_OP_AND);
- }
- return TK_OP_BIT_AND;*/
- } break;
- case '|': {
+ return _make_token(TK_OP_SHIFT_RIGHT);
+ }
- if (GETCHAR(1)=='|') {
+ return _make_token(TK_OP_GREATER);
- r_chars++;
- return Token(TK_OP_OR);
- }
+ } break;
+ case '!': {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_NOT_EQUAL);
+ }
- return Token(TK_ERROR,"Unknown character");
+ return _make_token(TK_OP_NOT);
+
+ } break;
+ //case '"' //string - no strings in shader
+ //case '\'' //string - no strings in shader
+ case '{':
+ return _make_token(TK_CURLY_BRACKET_OPEN);
+ case '}':
+ return _make_token(TK_CURLY_BRACKET_CLOSE);
+ case '[':
+ return _make_token(TK_BRACKET_OPEN);
+ case ']':
+ return _make_token(TK_BRACKET_CLOSE);
+ case '(':
+ return _make_token(TK_PARENTHESIS_OPEN);
+ case ')':
+ return _make_token(TK_PARENTHESIS_CLOSE);
+ case ',':
+ return _make_token(TK_COMMA);
+ case ';':
+ return _make_token(TK_SEMICOLON);
+ case '?':
+ return _make_token(TK_QUESTION);
+ case ':':
+ return _make_token(TK_COLON);
+ case '^':
+ return _make_token(TK_OP_BIT_XOR);
+ case '~':
+ return _make_token(TK_OP_BIT_INVERT);
+ case '&': {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_BIT_AND);
+ } else if (GETCHAR(0)=='&') {
+ char_idx++;
+ return _make_token(TK_OP_AND);
+ }
+ return _make_token(TK_OP_BIT_AND);
+ } break;
+ case '|': {
+
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_BIT_OR);
+ } else if (GETCHAR(0)=='|') {
+ char_idx++;
+ return _make_token(TK_OP_OR);
+ }
+ return _make_token(TK_OP_BIT_OR);
- /*
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_BIT_OR);
- } else if (GETCHAR(1)=='|') {
- r_chars++;
- return Token(TK_OP_OR);
- }
- return TK_OP_BIT_OR;
- */
- } break;
- case '*': {
+ } break;
+ case '*': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_MUL);
- }
- return TK_OP_MUL;
- } break;
- case '+': {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_MUL);
+ }
+ return _make_token(TK_OP_MUL);
+ } break;
+ case '+': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_ADD);
- } /*else if (GETCHAR(1)=='+') {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_ADD);
+ } else if (GETCHAR(0)=='+') {
- r_chars++;
- return Token(TK_OP_PLUS_PLUS);
- }*/
+ char_idx++;
+ return _make_token(TK_OP_INCREMENT);
+ }
- return TK_OP_ADD;
- } break;
- case '-': {
+ return _make_token(TK_OP_ADD);
+ } break;
+ case '-': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_SUB);
- }/* else if (GETCHAR(1)=='-') {
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_SUB);
+ }else if (GETCHAR(0)=='-') {
- r_chars++;
- return Token(TK_OP_MINUS_MINUS);
- }*/
+ char_idx++;
+ return _make_token(TK_OP_DECREMENT);
+ }
- return TK_OP_SUB;
- } break;
- /*case '%': {
+ return _make_token(TK_OP_SUB);
+ } break;
+ case '%': {
- if (GETCHAR(1)=='=') {
- r_chars++;
- return Token(TK_OP_ASSIGN_MOD);
- }
+ if (GETCHAR(0)=='=') {
+ char_idx++;
+ return _make_token(TK_OP_ASSIGN_MOD);
+ }
- return TK_OP_MOD;
- } break;*/
- default: {
+ return _make_token(TK_OP_MOD);
+ } break;
+ default: {
- if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) {
- // parse number
- bool period_found=false;
- bool exponent_found=false;
- bool hexa_found=false;
- bool sign_found=false;
+ char_idx--; //go back one, since we have no idea what this is
- String str;
- int i=0;
+ if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) {
+ // parse number
+ bool period_found=false;
+ bool exponent_found=false;
+ bool hexa_found=false;
+ bool sign_found=false;
+ bool minus_exponent_found=false;
- while(true) {
- if (GETCHAR(i)=='.') {
- if (period_found || exponent_found)
- return Token(TK_ERROR,"Invalid numeric constant");
- period_found=true;
- } else if (GETCHAR(i)=='x') {
- if (hexa_found || str.length()!=1 || str[0]!='0')
- return Token(TK_ERROR,"Invalid numeric constant");
- hexa_found=true;
- } else if (GETCHAR(i)=='e') {
- if (hexa_found || exponent_found)
- return Token(TK_ERROR,"Invalid numeric constant");
- exponent_found=true;
- } else if (_is_number(GETCHAR(i))) {
- //all ok
- } else if (hexa_found && _is_hex(GETCHAR(i))) {
-
- } else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) {
- if (sign_found)
- return Token(TK_ERROR,"Invalid numeric constant");
- sign_found=true;
- } else
- break;
+ String str;
+ int i=0;
- str+=CharType(GETCHAR(i));
- i++;
- }
+ while(true) {
+ if (GETCHAR(i)=='.') {
+ if (period_found || exponent_found)
+ return _make_token(TK_ERROR,"Invalid numeric constant");
+ period_found=true;
+ } else if (GETCHAR(i)=='x') {
+ if (hexa_found || str.length()!=1 || str[0]!='0')
+ return _make_token(TK_ERROR,"Invalid numeric constant");
+ hexa_found=true;
+ } else if (GETCHAR(i)=='e') {
+ if (hexa_found || exponent_found)
+ return _make_token(TK_ERROR,"Invalid numeric constant");
+ exponent_found=true;
+ } else if (_is_number(GETCHAR(i))) {
+ //all ok
+ } else if (hexa_found && _is_hex(GETCHAR(i))) {
+
+ } else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) {
+ if (sign_found)
+ return _make_token(TK_ERROR,"Invalid numeric constant");
+ sign_found=true;
+ if (GETCHAR(i)=='-')
+ minus_exponent_found=true;
+ } else
+ break;
- if (!_is_number(str[str.length()-1]))
- return Token(TK_ERROR,"Invalid numeric constant");
+ str+=CharType(GETCHAR(i));
+ i++;
+ }
- r_chars+=str.length()-1;
- return Token(TK_REAL_CONSTANT,str);
- /*
- if (period_found)
- return Token(TK_NUMBER_REAL,str);
- else
- return Token(TK_NUMBER_INTEGER,str);*/
+ if (!_is_number(str[str.length()-1]))
+ return _make_token(TK_ERROR,"Invalid numeric constant");
- }
+ char_idx+=str.length()-1;
+ Token tk;
+ if (period_found || minus_exponent_found)
+ tk.type=TK_REAL_CONSTANT;
+ else
+ tk.type=TK_INT_CONSTANT;
- if (GETCHAR(0)=='.') {
- //parse period
- return Token(TK_PERIOD);
- }
+ if (!str.is_valid_float()) {
+ return _make_token(TK_ERROR,"Invalid numeric constant");
+ }
- if (_is_text_char(GETCHAR(0))) {
- // parse identifier
- String str;
- str+=CharType(GETCHAR(0));
+ tk.constant=str.to_double();
+ tk.line=tk_line;
- while(_is_text_char(GETCHAR(r_chars))) {
+ return tk;
- str+=CharType(GETCHAR(r_chars));
- r_chars++;
}
- //see if keyword
- struct _kws { TokenType token; const char *text;};
- static const _kws keyword_list[]={
- {TK_TRUE,"true"},
- {TK_FALSE,"false"},
- {TK_TYPE_VOID,"void"},
- {TK_TYPE_BOOL,"bool"},
- /*{TK_TYPE_INT,"int"},
- {TK_TYPE_INT2,"int2"},
- {TK_TYPE_INT3,"int3"},
- {TK_TYPE_INT4,"int4"},*/
- {TK_TYPE_FLOAT,"float"},
- /*{TK_TYPE_FLOAT2,"float2"},
- {TK_TYPE_FLOAT3,"float3"},
- {TK_TYPE_FLOAT4,"float4"},*/
- {TK_TYPE_VEC2,"vec2"},
- {TK_TYPE_VEC3,"vec3"},
- {TK_TYPE_VEC4,"vec4"},
- {TK_TYPE_TEXTURE,"texture"},
- {TK_TYPE_CUBEMAP,"cubemap"},
- {TK_TYPE_COLOR,"color"},
-
- {TK_TYPE_MAT2,"mat2"},
- /*{TK_TYPE_MAT3,"mat3"},
- {TK_TYPE_MAT4,"mat3"},*/
- {TK_TYPE_MAT3,"mat3"},
- {TK_TYPE_MAT4,"mat4"},
- {TK_CF_IF,"if"},
- {TK_CF_ELSE,"else"},
- /*
- {TK_CF_FOR,"for"},
- {TK_CF_WHILE,"while"},
- {TK_CF_DO,"do"},
- {TK_CF_SWITCH,"switch"},
- {TK_CF_BREAK,"break"},
- {TK_CF_CONTINUE,"continue"},*/
- {TK_CF_RETURN,"return"},
- {TK_UNIFORM,"uniform"},
- {TK_ERROR,NULL}
- };
-
- int idx=0;
-
- while(keyword_list[idx].text) {
-
- if (str==keyword_list[idx].text)
- return Token(keyword_list[idx].token);
- idx++;
+ if (GETCHAR(0)=='.') {
+ //parse period
+ return _make_token(TK_PERIOD);
}
+ if (_is_text_char(GETCHAR(0))) {
+ // parse identifier
+ String str;
+ str+=CharType(GETCHAR(0));
- return Token(TK_INDENTIFIER,str);
- }
-
- if (GETCHAR(0)>32)
- return Token(TK_ERROR,"Tokenizer: Unknown character #"+itos(GETCHAR(0))+": '"+String::chr(GETCHAR(0))+"'");
- else
- return Token(TK_ERROR,"Tokenizer: Unknown character #"+itos(GETCHAR(0)));
-
- } break;
- }
- ERR_PRINT("BUG");
- return Token();
-}
+ while(_is_text_char(GETCHAR(1))) {
-Error ShaderLanguage::tokenize(const String& p_text,Vector<Token> *p_tokens,String *r_error,int *r_err_line,int *r_err_column) {
-
-
- int len =p_text.length();
- int pos=0;
+ str+=CharType(GETCHAR(1));
+ char_idx++;
+ }
- int line=0;
+ //see if keyword
+ //should be converted to a static map
+ struct _kws { TokenType token; const char *text;};
+ static const _kws keyword_list[]={
+ {TK_TRUE,"true"},
+ {TK_FALSE,"false"},
+ {TK_TYPE_VOID,"void"},
+ {TK_TYPE_BOOL,"bool"},
+ {TK_TYPE_BVEC2,"bvec2"},
+ {TK_TYPE_BVEC3,"bvec3"},
+ {TK_TYPE_BVEC4,"bvec4"},
+ {TK_TYPE_INT,"int"},
+ {TK_TYPE_IVEC2,"ivec2"},
+ {TK_TYPE_IVEC3,"ivec3"},
+ {TK_TYPE_IVEC4,"ivec4"},
+ {TK_TYPE_UINT,"uint"},
+ {TK_TYPE_UVEC2,"uvec2"},
+ {TK_TYPE_UVEC3,"uvec3"},
+ {TK_TYPE_UVEC4,"uvec4"},
+ {TK_TYPE_FLOAT,"float"},
+ {TK_TYPE_VEC2,"vec2"},
+ {TK_TYPE_VEC3,"vec3"},
+ {TK_TYPE_VEC4,"vec4"},
+ {TK_TYPE_MAT2,"mat2"},
+ {TK_TYPE_MAT3,"mat3"},
+ {TK_TYPE_MAT4,"mat4"},
+ {TK_TYPE_SAMPLER2D,"sampler2D"},
+ {TK_TYPE_ISAMPLER2D,"isampler2D"},
+ {TK_TYPE_USAMPLER2D,"usampler2D"},
+ {TK_TYPE_SAMPLERCUBE,"samplerCube"},
+ {TK_PRECISION_LOW,"lowp"},
+ {TK_PRECISION_MID,"mediump"},
+ {TK_PRECISION_HIGH,"highp"},
+ {TK_CF_IF,"if"},
+ {TK_CF_ELSE,"else"},
+ {TK_CF_FOR,"for"},
+ {TK_CF_WHILE,"while"},
+ {TK_CF_DO,"do"},
+ {TK_CF_SWITCH,"switch"},
+ {TK_CF_CASE,"case"},
+ {TK_CF_BREAK,"break"},
+ {TK_CF_CONTINUE,"continue"},
+ {TK_CF_RETURN,"return"},
+ {TK_UNIFORM,"uniform"},
+ {TK_VARYING,"varying"},
+ {TK_RENDER_MODE,"render_mode"},
+ {TK_HINT_WHITE_TEXTURE,"hint_white"},
+ {TK_HINT_BLACK_TEXTURE,"hint_black"},
+ {TK_HINT_NORMAL_TEXTURE,"hint_normal"},
+ {TK_HINT_RANGE,"hint_range"},
+
+ {TK_ERROR,NULL}
+ };
+
+ int idx=0;
+
+ while(keyword_list[idx].text) {
+
+ if (str==keyword_list[idx].text) {
+
+ _make_token(keyword_list[idx].token);
+ }
+ idx++;
+ }
- while(pos<len) {
- int advance=0;
- int prev_line=line;
- Token t = read_token(&p_text[pos],len-pos,line,advance);
- t.line=prev_line;
+ return _make_token(TK_IDENTIFIER,str);
+ }
- if (t.type==TK_ERROR) {
+ if (GETCHAR(0)>32)
+ return _make_token(TK_ERROR,"Tokenizer: Unknown character #"+itos(GETCHAR(0))+": '"+String::chr(GETCHAR(0))+"'");
+ else
+ return _make_token(TK_ERROR,"Tokenizer: Unknown character #"+itos(GETCHAR(0)));
- if (r_error) {
- *r_error=t.text;
- *r_err_line=line;
- return ERR_COMPILATION_FAILED;
- }
+ } break;
}
-
- if (t.type!=TK_EMPTY)
- p_tokens->push_back(t);
- //if (prev_line!=line)
- // p_tokens->push_back(Token(TK_LINE,itos(line)));
-
- pos+=advance;
-
}
-
- return OK;
-
+ ERR_PRINT("BUG");
+ return Token();
}
+
String ShaderLanguage::lex_debug(const String& p_code) {
+#if 0
Vector<Token> tokens;
String error;
int errline,errcol;
@@ -503,47 +504,64 @@ String ShaderLanguage::lex_debug(const String& p_code) {
}
return ret;
+#endif
+ return String();
}
bool ShaderLanguage::is_token_datatype(TokenType p_type) {
- return
- (p_type==TK_TYPE_VOID) ||
- (p_type==TK_TYPE_BOOL) ||
- (p_type==TK_TYPE_FLOAT) ||
- (p_type==TK_TYPE_VEC2) ||
- (p_type==TK_TYPE_VEC3) ||
- (p_type==TK_TYPE_VEC4) ||
- (p_type==TK_TYPE_COLOR) ||
- (p_type==TK_TYPE_MAT2) ||
- (p_type==TK_TYPE_MAT3) ||
- (p_type==TK_TYPE_MAT4) ||
- (p_type==TK_TYPE_CUBEMAP) ||
- (p_type==TK_TYPE_TEXTURE);
+ return (
+ p_type==TK_TYPE_VOID ||
+ p_type==TK_TYPE_BOOL ||
+ p_type==TK_TYPE_BVEC2 ||
+ p_type==TK_TYPE_BVEC3 ||
+ p_type==TK_TYPE_BVEC4 ||
+ p_type==TK_TYPE_INT ||
+ p_type==TK_TYPE_IVEC2 ||
+ p_type==TK_TYPE_IVEC3 ||
+ p_type==TK_TYPE_IVEC4 ||
+ p_type==TK_TYPE_UINT ||
+ p_type==TK_TYPE_UVEC2 ||
+ p_type==TK_TYPE_UVEC3 ||
+ p_type==TK_TYPE_UVEC4 ||
+ p_type==TK_TYPE_FLOAT ||
+ p_type==TK_TYPE_VEC2 ||
+ p_type==TK_TYPE_VEC3 ||
+ p_type==TK_TYPE_VEC4 ||
+ p_type==TK_TYPE_MAT2 ||
+ p_type==TK_TYPE_MAT3 ||
+ p_type==TK_TYPE_MAT4 ||
+ p_type==TK_TYPE_SAMPLER2D ||
+ p_type==TK_TYPE_ISAMPLER2D ||
+ p_type==TK_TYPE_USAMPLER2D ||
+ p_type==TK_TYPE_SAMPLERCUBE );
}
ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) {
- switch(p_type) {
+ return DataType(p_type-TK_TYPE_VOID);
+}
- case TK_TYPE_VOID: return TYPE_VOID;
- case TK_TYPE_BOOL: return TYPE_BOOL;
- case TK_TYPE_FLOAT: return TYPE_FLOAT;
- case TK_TYPE_VEC2: return TYPE_VEC2;
- case TK_TYPE_VEC3: return TYPE_VEC3;
- case TK_TYPE_VEC4: return TYPE_VEC4;
- case TK_TYPE_COLOR: return TYPE_VEC4;
- case TK_TYPE_MAT2: return TYPE_MAT2;
- case TK_TYPE_MAT3: return TYPE_MAT3;
- case TK_TYPE_MAT4: return TYPE_MAT4;
- case TK_TYPE_TEXTURE: return TYPE_TEXTURE;
- case TK_TYPE_CUBEMAP: return TYPE_CUBEMAP;
- default: return TYPE_VOID;
- }
- return TYPE_VOID;
+bool ShaderLanguage::is_token_precision(TokenType p_type) {
+
+ return (
+ p_type==TK_PRECISION_LOW ||
+ p_type==TK_PRECISION_MID ||
+ p_type==TK_PRECISION_HIGH );
+
+}
+
+ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_type) {
+
+ if (p_type==TK_PRECISION_LOW)
+ return PRECISION_LOWP;
+ else if (p_type==TK_PRECISION_HIGH)
+ return PRECISION_HIGHP;
+ else
+ return PRECISION_MEDIUMP;
}
@@ -553,16 +571,28 @@ String ShaderLanguage::get_datatype_name(DataType p_type) {
case TYPE_VOID: return "void";
case TYPE_BOOL: return "bool";
+ case TYPE_BVEC2: return "bvec2";
+ case TYPE_BVEC3: return "bvec3";
+ case TYPE_BVEC4: return "bvec4";
+ case TYPE_INT: return "int";
+ case TYPE_IVEC2: return "ivec2";
+ case TYPE_IVEC3: return "ivec3";
+ case TYPE_IVEC4: return "ivec4";
+ case TYPE_UINT: return "uint";
+ case TYPE_UVEC2: return "uvec2";
+ case TYPE_UVEC3: return "uvec3";
+ case TYPE_UVEC4: return "uvec4";
case TYPE_FLOAT: return "float";
case TYPE_VEC2: return "vec2";
case TYPE_VEC3: return "vec3";
- case TYPE_VEC4: return "vec4";
+ case TYPE_VEC4: return "vec5";
case TYPE_MAT2: return "mat2";
case TYPE_MAT3: return "mat3";
case TYPE_MAT4: return "mat4";
- case TYPE_TEXTURE: return "texture";
- case TYPE_CUBEMAP: return "cubemap";
- default: return "";
+ case TYPE_SAMPLER2D: return "sampler2D";
+ case TYPE_ISAMPLER2D: return "isampler2D";
+ case TYPE_USAMPLER2D: return "usampler2D";
+ case TYPE_SAMPLERCUBE: return "samplerCube";
}
return "";
@@ -571,211 +601,488 @@ String ShaderLanguage::get_datatype_name(DataType p_type) {
bool ShaderLanguage::is_token_nonvoid_datatype(TokenType p_type) {
- return
- (p_type==TK_TYPE_BOOL) ||
- (p_type==TK_TYPE_FLOAT) ||
- (p_type==TK_TYPE_VEC2) ||
- (p_type==TK_TYPE_VEC3) ||
- (p_type==TK_TYPE_VEC4) ||
- (p_type==TK_TYPE_COLOR) ||
- (p_type==TK_TYPE_MAT2) ||
- (p_type==TK_TYPE_MAT3) ||
- (p_type==TK_TYPE_MAT4) ||
- (p_type==TK_TYPE_TEXTURE) ||
- (p_type==TK_TYPE_CUBEMAP);
+ return is_token_datatype(p_type) && p_type!=TK_TYPE_VOID;
}
-bool ShaderLanguage::parser_is_at_function(Parser& parser) {
+void ShaderLanguage::clear() {
- return (is_token_datatype(parser.get_token_type(0)) && parser.get_token_type(1)==TK_INDENTIFIER && parser.get_token_type(2)==TK_PARENTHESIS_OPEN);
-}
+ tk_line=0;
+ char_idx=0;
+ error_set=false;
+ error_str="";
+ while(nodes) {
+ Node *n = nodes;
+ nodes=nodes->next;
+ memdelete(n);
+ }
+}
-bool ShaderLanguage::test_existing_identifier(Node *p_node,const StringName p_identifier,bool p_func,bool p_var,bool p_builtin) {
+bool ShaderLanguage::_find_identifier(const BlockNode* p_block,const Map<StringName, DataType> &p_builtin_types,const StringName& p_identifier, DataType *r_data_type, IdentifierType *r_type) {
- Node *node = p_node;
- while(node) {
+ if (p_builtin_types.has(p_identifier)) {
- if (node->type==Node::TYPE_BLOCK) {
+ if (r_data_type) {
+ *r_data_type=p_builtin_types[p_identifier];
+ }
+ if (r_type) {
+ *r_type=IDENTIFIER_BUILTIN_VAR;
+ }
- BlockNode *block = (BlockNode*)node;
- if (block->variables.has(p_identifier))
- return true;
- } else if (node->type==Node::TYPE_PROGRAM) {
+ return true;
+ }
- ProgramNode *program = (ProgramNode*)node;
- for(int i=0;i<program->functions.size();i++) {
+ FunctionNode *function=NULL;
- if (program->functions[i].name==p_identifier) {
- return true;
- }
- }
+ while(p_block) {
- if(program->builtin_variables.has(p_identifier)) {
- return true;
+ if (p_block->variables.has(p_identifier)) {
+ if (r_data_type) {
+ *r_data_type=p_block->variables[p_identifier].type;
}
- if(program->uniforms.has(p_identifier)) {
- return true;
+ if (r_type) {
+ *r_type=IDENTIFIER_LOCAL_VAR;
}
- } else if (node->type==Node::TYPE_FUNCTION) {
-
- FunctionNode *func=(FunctionNode*)node;
- for(int i=0;i<func->arguments.size();i++)
- if (func->arguments[i].name==p_identifier)
- return true;
+ return true;
}
- node=node->parent;
+ if (p_block->parent_function) {
+ function=p_block->parent_function;
+ break;
+ } else {
+ ERR_FAIL_COND_V(!p_block->parent_block,false);
+ p_block=p_block->parent_block;
+ }
}
- // try keywords
-
- int idx=0;
-
- //todo optimize
- while(intrinsic_func_defs[idx].name) {
+ if (function) {
+ for(int i=0;i<function->arguments.size();i++) {
+ if (function->arguments[i].name==p_identifier) {
+ if (r_data_type) {
+ *r_data_type=function->arguments[i].type;
+ }
+ if (r_type) {
+ *r_type=IDENTIFIER_FUNCTION_ARGUMENT;
+ }
- if (p_identifier.operator String()==intrinsic_func_defs[idx].name)
- return true;
- idx++;
+ return true;
+ }
+ }
}
- return false;
-
-}
+ if (shader->varyings.has(p_identifier)) {
+ if (r_data_type) {
+ *r_data_type=shader->varyings[p_identifier].type;
+ }
+ if (r_type) {
+ *r_type=IDENTIFIER_VARYING;
+ }
+ return true;
+ }
+ if (shader->uniforms.has(p_identifier)) {
+ if (r_data_type) {
+ *r_data_type=shader->uniforms[p_identifier].type;
+ }
+ if (r_type) {
+ *r_type=IDENTIFIER_UNIFORM;
+ }
+ return true;
+ }
-Error ShaderLanguage::parse_function(Parser& parser,BlockNode *p_block) {
+ for(int i=0;i<shader->functions.size();i++) {
- if (!p_block->parent || p_block->parent->type!=Node::TYPE_PROGRAM) {
- parser.set_error("Misplaced function");
- return ERR_PARSE_ERROR;
+ if (!shader->functions[i].callable)
+ continue;
+ if (shader->functions[i].name==p_identifier) {
+ if (r_data_type) {
+ *r_data_type=shader->functions[i].function->return_type;
+ }
+ if (r_type) {
+ *r_type=IDENTIFIER_FUNCTION;
+ }
+ }
}
+ return false;
- ProgramNode *program = (ProgramNode*)p_block->parent;
+}
- StringName name = parser.get_token(1).text;
- if (test_existing_identifier(p_block,name)) {
+bool ShaderLanguage::_validate_operator(OperatorNode *p_op,DataType *r_ret_type) {
- parser.set_error("Duplicate Identifier (existing variable/builtin/function): "+name);
- return ERR_PARSE_ERROR;
+ bool valid=false;
+ DataType ret_type;
+
+ switch(p_op->op) {
+ case OP_EQUAL:
+ case OP_NOT_EQUAL: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
+ valid=na==nb;
+ ret_type=TYPE_BOOL;
+ } break;
+ case OP_LESS:
+ case OP_LESS_EQUAL:
+ case OP_GREATER:
+ case OP_GREATER_EQUAL: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
- }
+ valid = na==nb && (na==TYPE_UINT || na==TYPE_INT || na==TYPE_FLOAT);
+ ret_type=TYPE_BOOL;
+ } break;
+ case OP_AND:
+ case OP_OR: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
- FunctionNode *function = parser.create_node<FunctionNode>(program);
- function->body = parser.create_node<BlockNode>(function);
+ valid = na==nb && na==TYPE_BOOL;
+ ret_type=TYPE_BOOL;
- function->name=name;
+ } break;
+ case OP_NOT: {
- function->return_type=get_token_datatype(parser.get_token_type(0));
+ DataType na = p_op->arguments[0]->get_datatype();
+ valid = na==TYPE_BOOL;
+ ret_type=TYPE_BOOL;
- { //add to programnode
- ProgramNode::Function f;
- f.name=name;
- f.function=function;
- program->functions.push_back(f);
- }
+ } break;
+ case OP_INCREMENT:
+ case OP_DECREMENT:
+ case OP_POST_INCREMENT:
+ case OP_POST_DECREMENT:
+ case OP_NEGATE: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ valid = na>TYPE_BOOL && na<TYPE_MAT2;
+ ret_type=na;
+ } break;
+ case OP_ADD:
+ case OP_SUB:
+ case OP_MUL:
+ case OP_DIV: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
+
+ if (na>nb) {
+ //make things easier;
+ SWAP(na,nb);
+ }
+
+ if (na==nb) {
+ valid = (na>TYPE_BOOL && na<TYPE_MAT2) || (p_op->op==OP_MUL && na>=TYPE_MAT2 && na<=TYPE_MAT4);
+ ret_type=na;
+ } else if (na==TYPE_INT && nb==TYPE_IVEC2) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_INT && nb==TYPE_IVEC3) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_INT && nb==TYPE_IVEC4) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ } else if (na==TYPE_UINT && nb==TYPE_UVEC2) {
+ valid=true;
+ ret_type=TYPE_UVEC2;
+ } else if (na==TYPE_UINT && nb==TYPE_UVEC3) {
+ valid=true;
+ ret_type=TYPE_UVEC3;
+ } else if (na==TYPE_UINT && nb==TYPE_UVEC4) {
+ valid=true;
+ ret_type=TYPE_UVEC4;
+ } else if (na==TYPE_FLOAT && nb==TYPE_VEC2) {
+ valid=true;
+ ret_type=TYPE_VEC2;
+ } else if (na==TYPE_FLOAT && nb==TYPE_VEC3) {
+ valid=true;
+ ret_type=TYPE_VEC3;
+ } else if (na==TYPE_FLOAT && nb==TYPE_VEC4) {
+ valid=true;
+ ret_type=TYPE_VEC4;
+ } else if (p_op->op==OP_MUL && na==TYPE_VEC2 && nb==TYPE_MAT2) {
+ valid=true;
+ ret_type=TYPE_MAT2;
+ } else if (p_op->op==OP_MUL && na==TYPE_VEC3 && nb==TYPE_MAT3) {
+ valid=true;
+ ret_type=TYPE_MAT3;
+ } else if (p_op->op==OP_MUL && na==TYPE_VEC4 && nb==TYPE_MAT4) {
+ valid=true;
+ ret_type=TYPE_MAT4;
+ }
+ } break;
+ case OP_ASSIGN_MOD:
+ case OP_MOD: {
+ /*
+ * The operator modulus (%) operates on signed or unsigned integers or integer vectors. The operand
+ * types must both be signed or both be unsigned. The operands cannot be vectors of differing size. If
+ * one operand is a scalar and the other vector, then the scalar is applied component-wise to the vector,
+ * resulting in the same type as the vector. If both are vectors of the same size, the result is computed
+ * component-wise.
+ */
- int ofs=3;
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
- while(true) {
- //end of arguments
- if (parser.get_token_type(ofs)==TK_PARENTHESIS_CLOSE) {
- ofs++;
- break;
- }
- //next argument awaits
- if (parser.get_token_type(ofs)==TK_COMMA) {
- if (!is_token_nonvoid_datatype(parser.get_token_type(ofs+1))) {
- parser.set_error("Expected Identifier or ')' following ','");
- return ERR_PARSE_ERROR;
+ if (na==TYPE_INT && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_INT;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_IVEC2) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_IVEC3) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_IVEC4) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ /////
+ } else if (na==TYPE_UINT && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UINT;
+ } else if (na==TYPE_UVEC2 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC2;
+ } else if (na==TYPE_UVEC3 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC3;
+ } else if (na==TYPE_UVEC4 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC4;
+ } else if (na==TYPE_UVEC2 && nb==TYPE_UVEC2) {
+ valid=true;
+ ret_type=TYPE_UVEC2;
+ } else if (na==TYPE_UVEC3 && nb==TYPE_UVEC3) {
+ valid=true;
+ ret_type=TYPE_UVEC3;
+ } else if (na==TYPE_UVEC4 && nb==TYPE_UVEC4) {
+ valid=true;
+ ret_type=TYPE_UVEC4;
}
- ofs++;
- continue;
- }
-
+ } break;
+ case OP_ASSIGN_SHIFT_LEFT:
+ case OP_ASSIGN_SHIFT_RIGHT:
+ case OP_SHIFT_LEFT:
+ case OP_SHIFT_RIGHT: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
- if (!is_token_nonvoid_datatype(parser.get_token_type(ofs+0))) {
- parser.set_error("Invalid Argument Type");
- return ERR_PARSE_ERROR;
- }
-
- DataType identtype=get_token_datatype(parser.get_token_type(ofs+0));
+ if (na>=TYPE_UINT && na<=TYPE_UVEC4) {
+ na=DataType(na-4);
+ }
- if (parser.get_token_type(ofs+1)!=TK_INDENTIFIER) {
- parser.set_error("Expected Argument Identifier");
- return ERR_PARSE_ERROR;
- }
+ if (nb>=TYPE_UINT && nb<=TYPE_UVEC4) {
+ nb=DataType(nb-4);
+ }
- StringName identname=parser.get_token(ofs+1).text;
+ if (na==TYPE_INT && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_INT;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_IVEC2) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_IVEC3) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_IVEC4) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ }
+ } break;
+ case OP_ASSIGN: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
+ valid=na==nb;
+ ret_type=na;
+ } break;
+ case OP_ASSIGN_ADD:
+ case OP_ASSIGN_SUB:
+ case OP_ASSIGN_MUL:
+ case OP_ASSIGN_DIV: {
- if (test_existing_identifier(function,identname)) {
- parser.set_error("Duplicate Argument Identifier: "+identname);
- return ERR_DUPLICATE_SYMBOL;
- }
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
- FunctionNode::Argument arg;
- arg.name=identname;
- arg.type=identtype;
- //function->body->variables[arg.name]=arg.type;
- function->arguments.push_back(arg);
- ofs+=2;
- }
+ if (na==nb) {
+ valid = (na>TYPE_BOOL && na<TYPE_MAT2) || (p_op->op==OP_ASSIGN_MUL && na>=TYPE_MAT2 && na<=TYPE_MAT4);
+ ret_type=na;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_INT ) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ } else if (na==TYPE_UVEC2 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC2;
+ } else if (na==TYPE_UVEC3 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC3;
+ } else if (na==TYPE_UVEC4 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC4;
+ } else if (na==TYPE_VEC2 && nb==TYPE_FLOAT ) {
+ valid=true;
+ ret_type=TYPE_VEC2;
+ } else if (na==TYPE_VEC3 && nb==TYPE_FLOAT) {
+ valid=true;
+ ret_type=TYPE_VEC3;
+ } else if (na==TYPE_VEC4 && nb==TYPE_FLOAT) {
+ valid=true;
+ ret_type=TYPE_VEC4;
+ } else if (p_op->op==OP_ASSIGN_MUL && na==TYPE_MAT2 && nb==TYPE_VEC2) {
+ valid=true;
+ ret_type=TYPE_MAT2;
+ } else if (p_op->op==OP_ASSIGN_MUL && na==TYPE_MAT3 && nb==TYPE_VEC3) {
+ valid=true;
+ ret_type=TYPE_MAT3;
+ } else if (p_op->op==OP_ASSIGN_MUL && na==TYPE_MAT4 && nb==TYPE_VEC4) {
+ valid=true;
+ ret_type=TYPE_MAT4;
+ }
+ } break;
+ case OP_ASSIGN_BIT_AND:
+ case OP_ASSIGN_BIT_OR:
+ case OP_ASSIGN_BIT_XOR:
+ case OP_BIT_AND:
+ case OP_BIT_OR:
+ case OP_BIT_XOR: {
- parser.advance(ofs);
- // match {
- if (parser.get_token_type()!=TK_CURLY_BRACKET_OPEN) {
- parser.set_error("Expected '{'");
- return ERR_PARSE_ERROR;
- }
+ /*
+ * The bitwise operators and (&), exclusive-or (^), and inclusive-or (|). The operands must be of type
+ * signed or unsigned integers or integer vectors. The operands cannot be vectors of differing size. If
+ * one operand is a scalar and the other a vector, the scalar is applied component-wise to the vector,
+ * resulting in the same type as the vector. The fundamental types of the operands (signed or unsigned)
+ * must match.
+ */
- parser.advance();
- Error err = parse_block(parser,function->body);
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
- if (err)
- return err;
+ if (na>nb && p_op->op>=OP_BIT_AND) {
+ //can swap for non assign
+ SWAP(na,nb);
+ }
- // make sure that if the function has a return type, it does return something..
- if (function->return_type!=TYPE_VOID) {
- bool found=false;
- for(int i=0;i<function->body->statements.size();i++) {
- if (function->body->statements[i]->type==Node::TYPE_CONTROL_FLOW) {
-
- ControlFlowNode *cf = (ControlFlowNode*)function->body->statements[i];
- if (cf->flow_op==FLOW_OP_RETURN) {
- // type of return was already checked when inserted
- // no need to check here
- found=true;
- }
+ if (na==TYPE_INT && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_INT;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_INT) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ } else if (na==TYPE_IVEC2 && nb==TYPE_IVEC2) {
+ valid=true;
+ ret_type=TYPE_IVEC2;
+ } else if (na==TYPE_IVEC3 && nb==TYPE_IVEC3) {
+ valid=true;
+ ret_type=TYPE_IVEC3;
+ } else if (na==TYPE_IVEC4 && nb==TYPE_IVEC4) {
+ valid=true;
+ ret_type=TYPE_IVEC4;
+ /////
+ } else if (na==TYPE_UINT && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UINT;
+ } else if (na==TYPE_UVEC2 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC2;
+ } else if (na==TYPE_UVEC3 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC3;
+ } else if (na==TYPE_UVEC4 && nb==TYPE_UINT) {
+ valid=true;
+ ret_type=TYPE_UVEC4;
+ } else if (na==TYPE_UVEC2 && nb==TYPE_UVEC2) {
+ valid=true;
+ ret_type=TYPE_UVEC2;
+ } else if (na==TYPE_UVEC3 && nb==TYPE_UVEC3) {
+ valid=true;
+ ret_type=TYPE_UVEC3;
+ } else if (na==TYPE_UVEC4 && nb==TYPE_UVEC4) {
+ valid=true;
+ ret_type=TYPE_UVEC4;
}
- }
+ } break;
+ case OP_BIT_INVERT: { //unaries
+ DataType na = p_op->arguments[0]->get_datatype();
+ valid = na>=TYPE_INT && na<TYPE_FLOAT;
+ ret_type=na;
+ } break;
+ case OP_SELECT_IF: {
+ DataType na = p_op->arguments[0]->get_datatype();
+ DataType nb = p_op->arguments[1]->get_datatype();
+ DataType nc = p_op->arguments[2]->get_datatype();
- if (!found) {
- parser.set_error("Function must return a value (use the main block)");
- return ERR_PARSE_ERROR;
+ valid = na==TYPE_BOOL && (nb==nc);
+ ret_type=nb;
+ } break;
+ default: {
+ ERR_FAIL_V(false);
}
}
- return OK;
-}
+ if (r_ret_type)
+ *r_ret_type=ret_type;
+ return valid;
+}
const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
//constructors
{"bool",TYPE_BOOL,{TYPE_BOOL,TYPE_VOID}},
+ {"bvec2",TYPE_BVEC2,{TYPE_BOOL,TYPE_VOID}},
+ {"bvec2",TYPE_BVEC2,{TYPE_BOOL,TYPE_BOOL,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_BOOL,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_BOOL,TYPE_BOOL,TYPE_BOOL,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_BVEC2,TYPE_BOOL,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_BOOL,TYPE_BVEC2,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BOOL,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BOOL,TYPE_BOOL,TYPE_BOOL,TYPE_BOOL,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BOOL,TYPE_BVEC2,TYPE_BOOL,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BVEC2,TYPE_BOOL,TYPE_BOOL,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BOOL,TYPE_BOOL,TYPE_BVEC2,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BOOL,TYPE_BVEC3,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BVEC3,TYPE_BOOL,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_BVEC2,TYPE_BVEC2,TYPE_VOID}},
+
+
{"float",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
{"vec2",TYPE_VEC2,{TYPE_FLOAT,TYPE_VOID}},
{"vec2",TYPE_VEC2,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
@@ -791,9 +1098,131 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+
+ {"int",TYPE_INT,{TYPE_INT,TYPE_VOID}},
+ {"ivec2",TYPE_IVEC2,{TYPE_INT,TYPE_VOID}},
+ {"ivec2",TYPE_IVEC2,{TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_INT,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_INT,TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_IVEC2,TYPE_INT,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_INT,TYPE_IVEC2,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_INT,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_INT,TYPE_INT,TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_INT,TYPE_IVEC2,TYPE_INT,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_IVEC2,TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_INT,TYPE_INT,TYPE_IVEC2,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_INT,TYPE_IVEC3,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_IVEC3,TYPE_INT,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+
+ {"uint",TYPE_UINT,{TYPE_UINT,TYPE_VOID}},
+ {"uvec2",TYPE_UVEC2,{TYPE_UINT,TYPE_VOID}},
+ {"uvec2",TYPE_UVEC2,{TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_UINT,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_UINT,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_UVEC2,TYPE_UINT,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_UINT,TYPE_UVEC2,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UINT,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UINT,TYPE_UINT,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UINT,TYPE_UVEC2,TYPE_UINT,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UVEC2,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UINT,TYPE_UINT,TYPE_UVEC2,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UINT,TYPE_UVEC3,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UVEC3,TYPE_UINT,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+
{"mat2",TYPE_MAT2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"mat3",TYPE_MAT3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"mat4",TYPE_MAT4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+
+ {"mat2",TYPE_MAT2,{TYPE_FLOAT,TYPE_VOID}},
+ {"mat3",TYPE_MAT3,{TYPE_FLOAT,TYPE_VOID}},
+ {"mat4",TYPE_MAT4,{TYPE_FLOAT,TYPE_VOID}},
+
+ //conversion scalars
+
+ {"int",TYPE_INT,{TYPE_BOOL,TYPE_VOID}},
+ {"int",TYPE_INT,{TYPE_INT,TYPE_VOID}},
+ {"int",TYPE_INT,{TYPE_UINT,TYPE_VOID}},
+ {"int",TYPE_INT,{TYPE_FLOAT,TYPE_VOID}},
+
+ {"float",TYPE_FLOAT,{TYPE_BOOL,TYPE_VOID}},
+ {"float",TYPE_FLOAT,{TYPE_INT,TYPE_VOID}},
+ {"float",TYPE_FLOAT,{TYPE_UINT,TYPE_VOID}},
+ {"float",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
+
+ {"uint",TYPE_UINT,{TYPE_BOOL,TYPE_VOID}},
+ {"uint",TYPE_UINT,{TYPE_INT,TYPE_VOID}},
+ {"uint",TYPE_UINT,{TYPE_UINT,TYPE_VOID}},
+ {"uint",TYPE_UINT,{TYPE_FLOAT,TYPE_VOID}},
+
+ {"bool",TYPE_BOOL,{TYPE_BOOL,TYPE_VOID}},
+ {"bool",TYPE_BOOL,{TYPE_INT,TYPE_VOID}},
+ {"bool",TYPE_BOOL,{TYPE_UINT,TYPE_VOID}},
+ {"bool",TYPE_BOOL,{TYPE_FLOAT,TYPE_VOID}},
+
+ //conversion vectors
+
+ {"ivec2",TYPE_IVEC2,{TYPE_BVEC2,TYPE_VOID}},
+ {"ivec2",TYPE_IVEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"ivec2",TYPE_IVEC2,{TYPE_UVEC2,TYPE_VOID}},
+ {"ivec2",TYPE_IVEC2,{TYPE_VEC2,TYPE_VOID}},
+
+ {"vec2",TYPE_VEC2,{TYPE_BVEC2,TYPE_VOID}},
+ {"vec2",TYPE_VEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"vec2",TYPE_VEC2,{TYPE_UVEC2,TYPE_VOID}},
+ {"vec2",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
+
+ {"uvec2",TYPE_UVEC2,{TYPE_BVEC2,TYPE_VOID}},
+ {"uvec2",TYPE_UVEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"uvec2",TYPE_UVEC2,{TYPE_UVEC2,TYPE_VOID}},
+ {"uvec2",TYPE_UVEC2,{TYPE_VEC2,TYPE_VOID}},
+
+ {"bvec2",TYPE_BVEC2,{TYPE_BVEC2,TYPE_VOID}},
+ {"bvec2",TYPE_BVEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"bvec2",TYPE_BVEC2,{TYPE_UVEC2,TYPE_VOID}},
+ {"bvec2",TYPE_BVEC2,{TYPE_VEC2,TYPE_VOID}},
+
+ {"ivec3",TYPE_IVEC3,{TYPE_BVEC3,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_UVEC3,TYPE_VOID}},
+ {"ivec3",TYPE_IVEC3,{TYPE_VEC3,TYPE_VOID}},
+
+ {"vec3",TYPE_VEC3,{TYPE_BVEC3,TYPE_VOID}},
+ {"vec3",TYPE_VEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"vec3",TYPE_VEC3,{TYPE_UVEC3,TYPE_VOID}},
+ {"vec3",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
+
+ {"uvec3",TYPE_UVEC3,{TYPE_BVEC3,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_UVEC3,TYPE_VOID}},
+ {"uvec3",TYPE_UVEC3,{TYPE_VEC3,TYPE_VOID}},
+
+ {"bvec3",TYPE_BVEC3,{TYPE_BVEC3,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_UVEC3,TYPE_VOID}},
+ {"bvec3",TYPE_BVEC3,{TYPE_VEC3,TYPE_VOID}},
+
+ {"ivec4",TYPE_IVEC4,{TYPE_BVEC4,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_IVEC4,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_UVEC4,TYPE_VOID}},
+ {"ivec4",TYPE_IVEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"vec4",TYPE_VEC4,{TYPE_BVEC4,TYPE_VOID}},
+ {"vec4",TYPE_VEC4,{TYPE_IVEC4,TYPE_VOID}},
+ {"vec4",TYPE_VEC4,{TYPE_UVEC4,TYPE_VOID}},
+ {"vec4",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"uvec4",TYPE_UVEC4,{TYPE_BVEC4,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_IVEC4,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_UVEC4,TYPE_VOID}},
+ {"uvec4",TYPE_UVEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"bvec4",TYPE_BVEC4,{TYPE_BVEC4,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_IVEC4,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_UVEC4,TYPE_VOID}},
+ {"bvec4",TYPE_BVEC4,{TYPE_VEC4,TYPE_VOID}},
+
//intrinsics - trigonometry
{"sin",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
{"cos",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
@@ -830,10 +1259,29 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"abs",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
{"abs",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
{"abs",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"abs",TYPE_INT,{TYPE_INT,TYPE_VOID}},
+ {"abs",TYPE_IVEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"abs",TYPE_IVEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"abs",TYPE_IVEC4,{TYPE_IVEC4,TYPE_VOID}},
+
+ {"abs",TYPE_UINT,{TYPE_UINT,TYPE_VOID}},
+ {"abs",TYPE_UVEC2,{TYPE_UVEC2,TYPE_VOID}},
+ {"abs",TYPE_UVEC3,{TYPE_UVEC3,TYPE_VOID}},
+ {"abs",TYPE_UVEC4,{TYPE_UVEC4,TYPE_VOID}},
+
+
{"sign",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
{"sign",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
{"sign",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
{"sign",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"sign",TYPE_INT,{TYPE_INT,TYPE_VOID}},
+ {"sign",TYPE_IVEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"sign",TYPE_IVEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"sign",TYPE_IVEC4,{TYPE_IVEC4,TYPE_VOID}},
+
+
{"floor",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
{"floor",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
{"floor",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
@@ -854,18 +1302,51 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"fract",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
{"fract",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
{"fract",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
{"mod",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"mod",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"mod",TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
{"mod",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"mod",TYPE_VEC3,{TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
{"mod",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+ {"mod",TYPE_VEC4,{TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"modf",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+ {"modf",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"modf",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"modf",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+
{"min",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"min",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"min",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"min",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+
+ {"min",TYPE_INT,{TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"min",TYPE_IVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"min",TYPE_IVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"min",TYPE_IVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
+
+ {"min",TYPE_UINT,{TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"min",TYPE_UVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"min",TYPE_UVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"min",TYPE_UVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
+
{"max",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"max",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"max",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"max",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+
+ {"max",TYPE_INT,{TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"max",TYPE_IVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"max",TYPE_IVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"max",TYPE_IVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
+
+ {"max",TYPE_UINT,{TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"max",TYPE_UVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"max",TYPE_UVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"max",TYPE_UVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
+
+
{"clamp",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"clamp",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"clamp",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
@@ -873,6 +1354,24 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"clamp",TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"clamp",TYPE_VEC3,{TYPE_VEC3,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"clamp",TYPE_VEC4,{TYPE_VEC4,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+
+
+ {"clamp",TYPE_INT,{TYPE_INT,TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"clamp",TYPE_IVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"clamp",TYPE_IVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"clamp",TYPE_IVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
+ {"clamp",TYPE_IVEC2,{TYPE_IVEC2,TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"clamp",TYPE_IVEC3,{TYPE_IVEC3,TYPE_INT,TYPE_INT,TYPE_VOID}},
+ {"clamp",TYPE_IVEC4,{TYPE_IVEC4,TYPE_INT,TYPE_INT,TYPE_VOID}},
+
+ {"clamp",TYPE_UINT,{TYPE_UINT,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"clamp",TYPE_UVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"clamp",TYPE_UVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"clamp",TYPE_UVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
+ {"clamp",TYPE_UVEC2,{TYPE_UVEC2,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"clamp",TYPE_UVEC3,{TYPE_UVEC3,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+ {"clamp",TYPE_UVEC4,{TYPE_UVEC4,TYPE_UINT,TYPE_UINT,TYPE_VOID}},
+
{"mix",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"mix",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
{"mix",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
@@ -895,6 +1394,36 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"smoothstep",TYPE_VEC3,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
{"smoothstep",TYPE_VEC4,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VEC4,TYPE_VOID}},
+ {"isnan",TYPE_BOOL,{TYPE_FLOAT,TYPE_VOID}},
+ {"isnan",TYPE_BOOL,{TYPE_VEC2,TYPE_VOID}},
+ {"isnan",TYPE_BOOL,{TYPE_VEC3,TYPE_VOID}},
+ {"isnan",TYPE_BOOL,{TYPE_VEC4,TYPE_VOID}},
+
+ {"isinf",TYPE_BOOL,{TYPE_FLOAT,TYPE_VOID}},
+ {"isinf",TYPE_BOOL,{TYPE_VEC2,TYPE_VOID}},
+ {"isinf",TYPE_BOOL,{TYPE_VEC3,TYPE_VOID}},
+ {"isinf",TYPE_BOOL,{TYPE_VEC4,TYPE_VOID}},
+
+ {"floatBitsToInt",TYPE_INT,{TYPE_FLOAT,TYPE_VOID}},
+ {"floatBitsToInt",TYPE_IVEC2,{TYPE_VEC2,TYPE_VOID}},
+ {"floatBitsToInt",TYPE_IVEC3,{TYPE_VEC3,TYPE_VOID}},
+ {"floatBitsToInt",TYPE_IVEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"floatBitsToUInt",TYPE_UINT,{TYPE_FLOAT,TYPE_VOID}},
+ {"floatBitsToUInt",TYPE_UVEC2,{TYPE_VEC2,TYPE_VOID}},
+ {"floatBitsToUInt",TYPE_UVEC3,{TYPE_VEC3,TYPE_VOID}},
+ {"floatBitsToUInt",TYPE_UVEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"intBitsToFloat",TYPE_FLOAT,{TYPE_INT,TYPE_VOID}},
+ {"intBitsToFloat",TYPE_VEC2,{TYPE_IVEC2,TYPE_VOID}},
+ {"intBitsToFloat",TYPE_VEC3,{TYPE_IVEC3,TYPE_VOID}},
+ {"intBitsToFloat",TYPE_VEC4,{TYPE_IVEC4,TYPE_VOID}},
+
+ {"uintBitsToFloat",TYPE_FLOAT,{TYPE_UINT,TYPE_VOID}},
+ {"uintBitsToFloat",TYPE_VEC2,{TYPE_UVEC2,TYPE_VOID}},
+ {"uintBitsToFloat",TYPE_VEC3,{TYPE_UVEC3,TYPE_VOID}},
+ {"uintBitsToFloat",TYPE_VEC4,{TYPE_UVEC4,TYPE_VOID}},
+
//intrinsics - geometric
{"length",TYPE_FLOAT,{TYPE_VEC2,TYPE_VOID}},
{"length",TYPE_FLOAT,{TYPE_VEC3,TYPE_VOID}},
@@ -911,318 +1440,211 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"normalize",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
{"reflect",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"refract",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
- //intrinsics - texture
- {"tex",TYPE_VEC4,{TYPE_TEXTURE,TYPE_VEC2,TYPE_VOID}},
- {"texcube",TYPE_VEC4,{TYPE_CUBEMAP,TYPE_VEC3,TYPE_VOID}},
- {"texscreen",TYPE_VEC3,{TYPE_VEC2,TYPE_VOID}},
- {"texpos",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
- {NULL,TYPE_VOID,{TYPE_VOID}}
+ {"facefordward",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"facefordward",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"facefordward",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
-};
+ {"matrixCompMult",TYPE_MAT2,{TYPE_MAT2,TYPE_MAT2,TYPE_VOID}},
+ {"matrixCompMult",TYPE_MAT3,{TYPE_MAT3,TYPE_MAT3,TYPE_VOID}},
+ {"matrixCompMult",TYPE_MAT4,{TYPE_MAT4,TYPE_MAT4,TYPE_VOID}},
-const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
-
- {OP_ASSIGN,TYPE_VOID,{TYPE_BOOL,TYPE_BOOL}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_MAT2,TYPE_MAT2}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_MAT3,TYPE_MAT3}},
- {OP_ASSIGN,TYPE_VOID,{TYPE_MAT4,TYPE_MAT4}},
- {OP_ADD,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_ADD,TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2}},
- {OP_ADD,TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3}},
- {OP_ADD,TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4}},
- {OP_SUB,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_SUB,TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2}},
- {OP_SUB,TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3}},
- {OP_SUB,TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4}},
- {OP_MUL,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2}},
- {OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT}},
- {OP_MUL,TYPE_VEC2,{TYPE_FLOAT,TYPE_VEC2}},
- {OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT3}},
- {OP_MUL,TYPE_VEC2,{TYPE_MAT2,TYPE_VEC2}},
- {OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT2}},
- {OP_MUL,TYPE_VEC2,{TYPE_MAT3,TYPE_VEC2}},
- {OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT4}},
- {OP_MUL,TYPE_VEC2,{TYPE_MAT4,TYPE_VEC2}},
- {OP_MUL,TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3}},
- {OP_MUL,TYPE_VEC3,{TYPE_VEC3,TYPE_FLOAT}},
- {OP_MUL,TYPE_VEC3,{TYPE_FLOAT,TYPE_VEC3}},
- {OP_MUL,TYPE_VEC3,{TYPE_MAT3,TYPE_VEC3}},
- {OP_MUL,TYPE_VEC3,{TYPE_MAT4,TYPE_VEC3}},
- {OP_MUL,TYPE_VEC3,{TYPE_VEC3,TYPE_MAT3}},
- {OP_MUL,TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4}},
- {OP_MUL,TYPE_VEC4,{TYPE_VEC4,TYPE_FLOAT}},
- {OP_MUL,TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC4}},
- {OP_MUL,TYPE_VEC4,{TYPE_MAT4,TYPE_VEC4}},
- {OP_MUL,TYPE_VEC4,{TYPE_VEC4,TYPE_MAT4}},
- {OP_MUL,TYPE_MAT2,{TYPE_MAT2,TYPE_MAT2}},
- {OP_MUL,TYPE_MAT3,{TYPE_MAT3,TYPE_MAT3}},
- {OP_MUL,TYPE_MAT4,{TYPE_MAT4,TYPE_MAT4}},
- {OP_DIV,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_DIV,TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2}},
- {OP_DIV,TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT}},
- {OP_DIV,TYPE_VEC2,{TYPE_FLOAT,TYPE_VEC2}},
- {OP_DIV,TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3}},
- {OP_DIV,TYPE_VEC3,{TYPE_VEC3,TYPE_FLOAT}},
- {OP_DIV,TYPE_VEC3,{TYPE_FLOAT,TYPE_VEC3}},
- {OP_DIV,TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4}},
- {OP_DIV,TYPE_VEC4,{TYPE_VEC4,TYPE_FLOAT}},
- {OP_DIV,TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC4}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_VEC2,TYPE_FLOAT}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_VEC3,TYPE_FLOAT}},
- {OP_ASSIGN_ADD,TYPE_VOID,{TYPE_VEC4,TYPE_FLOAT}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_VEC2,TYPE_FLOAT}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_VEC3,TYPE_FLOAT}},
- {OP_ASSIGN_SUB,TYPE_VOID,{TYPE_VEC4,TYPE_FLOAT}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC2,TYPE_FLOAT}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC2,TYPE_MAT2}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT2,TYPE_MAT2}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_MAT3}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_FLOAT}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_MAT4}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC4,TYPE_FLOAT}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC4,TYPE_MAT4}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT3,TYPE_MAT3}},
- {OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT4,TYPE_MAT4}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_VEC2,TYPE_FLOAT}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_VEC3,TYPE_FLOAT}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
- {OP_ASSIGN_DIV,TYPE_VOID,{TYPE_VEC4,TYPE_FLOAT}},
- {OP_NEG,TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
- {OP_NEG,TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
- {OP_NEG,TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
- {OP_NEG,TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
- {OP_NOT,TYPE_BOOL,{TYPE_BOOL,TYPE_VOID}},
- {OP_CMP_EQ,TYPE_BOOL,{TYPE_BOOL,TYPE_BOOL}},
- {OP_CMP_EQ,TYPE_BOOL,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_CMP_EQ,TYPE_BOOL,{TYPE_VEC3,TYPE_VEC2}},
- {OP_CMP_EQ,TYPE_BOOL,{TYPE_VEC3,TYPE_VEC3}},
- {OP_CMP_EQ,TYPE_BOOL,{TYPE_VEC3,TYPE_VEC4}},
- //{OP_CMP_EQ,TYPE_MAT3,{TYPE_MAT4,TYPE_MAT3}}, ??
- //{OP_CMP_EQ,TYPE_MAT4,{TYPE_MAT4,TYPE_MAT4}}, ??
- {OP_CMP_NEQ,TYPE_BOOL,{TYPE_BOOL,TYPE_BOOL}},
- {OP_CMP_NEQ,TYPE_BOOL,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_CMP_NEQ,TYPE_BOOL,{TYPE_VEC2,TYPE_VEC2}},
- {OP_CMP_NEQ,TYPE_BOOL,{TYPE_VEC3,TYPE_VEC3}},
- {OP_CMP_NEQ,TYPE_BOOL,{TYPE_VEC4,TYPE_VEC4}},
- //{OP_CMP_NEQ,TYPE_MAT4,{TYPE_MAT4,TYPE_MAT4}}, //?
- {OP_CMP_LEQ,TYPE_BOOL,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_CMP_GEQ,TYPE_BOOL,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_CMP_LESS,TYPE_BOOL,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_CMP_GREATER,TYPE_BOOL,{TYPE_FLOAT,TYPE_FLOAT}},
- {OP_CMP_OR,TYPE_BOOL,{TYPE_BOOL,TYPE_BOOL}},
- {OP_CMP_AND,TYPE_BOOL,{TYPE_BOOL,TYPE_BOOL}},
- {OP_MAX,TYPE_VOID,{TYPE_VOID,TYPE_VOID}}
-};
+ {"outerProduct",TYPE_MAT2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"outerProduct",TYPE_MAT3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"outerProduct",TYPE_MAT4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+ {"transpose",TYPE_MAT2,{TYPE_MAT2,TYPE_VOID}},
+ {"transpose",TYPE_MAT3,{TYPE_MAT3,TYPE_VOID}},
+ {"transpose",TYPE_MAT4,{TYPE_MAT4,TYPE_VOID}},
-const ShaderLanguage::BuiltinsDef ShaderLanguage::vertex_builtins_defs[]={
-
- { "SRC_VERTEX", TYPE_VEC3},
- { "SRC_NORMAL", TYPE_VEC3},
- { "SRC_TANGENT", TYPE_VEC3},
- { "SRC_BINORMALF", TYPE_FLOAT},
-
- { "POSITION", TYPE_VEC4 },
- { "VERTEX", TYPE_VEC3},
- { "NORMAL", TYPE_VEC3},
- { "TANGENT", TYPE_VEC3},
- { "BINORMAL", TYPE_VEC3},
- { "UV", TYPE_VEC2},
- { "UV2", TYPE_VEC2},
- { "COLOR", TYPE_VEC4},
- { "BONES", TYPE_VEC4},
- { "WEIGHTS", TYPE_VEC4},
- { "VAR1", TYPE_VEC4},
- { "VAR2", TYPE_VEC4},
- { "SPEC_EXP", TYPE_FLOAT},
- { "POINT_SIZE", TYPE_FLOAT},
-
- //builtins
- { "WORLD_MATRIX", TYPE_MAT4},
- { "INV_CAMERA_MATRIX", TYPE_MAT4},
- { "PROJECTION_MATRIX", TYPE_MAT4},
- { "MODELVIEW_MATRIX", TYPE_MAT4},
- { "INSTANCE_ID", TYPE_FLOAT},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID},
-};
-const ShaderLanguage::BuiltinsDef ShaderLanguage::fragment_builtins_defs[]={
-
- { "VERTEX", TYPE_VEC3},
- { "POSITION", TYPE_VEC4},
- { "NORMAL", TYPE_VEC3},
- { "TANGENT", TYPE_VEC3},
- { "BINORMAL", TYPE_VEC3},
- { "NORMALMAP", TYPE_VEC3},
- { "NORMALMAP_DEPTH", TYPE_FLOAT},
- { "UV", TYPE_VEC2},
- { "UV2", TYPE_VEC2},
- { "COLOR", TYPE_VEC4},
- { "NORMAL", TYPE_VEC3},
- { "VAR1", TYPE_VEC4},
- { "VAR2", TYPE_VEC4},
- { "DIFFUSE", TYPE_VEC3},
- { "DIFFUSE_ALPHA", TYPE_VEC4},
- { "SPECULAR", TYPE_VEC3},
- { "EMISSION", TYPE_VEC3},
- { "SPEC_EXP", TYPE_FLOAT},
- { "GLOW", TYPE_FLOAT},
- { "SHADE_PARAM", TYPE_FLOAT},
- { "DISCARD", TYPE_BOOL},
- { "SCREEN_UV", TYPE_VEC2},
- { "POINT_COORD", TYPE_VEC2},
- { "INV_CAMERA_MATRIX", TYPE_MAT4},
-
-// { "SCREEN_POS", TYPE_VEC2},
-// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID}
+ {"determinant",TYPE_FLOAT,{TYPE_MAT2,TYPE_VOID}},
+ {"determinant",TYPE_FLOAT,{TYPE_MAT3,TYPE_VOID}},
+ {"determinant",TYPE_FLOAT,{TYPE_MAT4,TYPE_VOID}},
-};
+ {"inverse",TYPE_MAT2,{TYPE_MAT2,TYPE_VOID}},
+ {"inverse",TYPE_MAT3,{TYPE_MAT3,TYPE_VOID}},
+ {"inverse",TYPE_MAT4,{TYPE_MAT4,TYPE_VOID}},
-const ShaderLanguage::BuiltinsDef ShaderLanguage::light_builtins_defs[]={
-
- { "NORMAL", TYPE_VEC3},
- { "LIGHT_DIR", TYPE_VEC3},
- { "LIGHT_DIFFUSE", TYPE_VEC3},
- { "LIGHT_SPECULAR", TYPE_VEC3},
- { "EYE_VEC", TYPE_VEC3},
- { "DIFFUSE", TYPE_VEC3},
- { "SPECULAR", TYPE_VEC3},
- { "SPECULAR_EXP", TYPE_FLOAT},
- { "SHADE_PARAM", TYPE_FLOAT},
- { "LIGHT", TYPE_VEC3},
- { "SHADOW", TYPE_VEC3 },
- { "POINT_COORD", TYPE_VEC2 },
-// { "SCREEN_POS", TYPE_VEC2},
-// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID}
-};
+ {"lessThan",TYPE_BVEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"lessThan",TYPE_BVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
-const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={
+ {"greaterThan",TYPE_BVEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"greaterThan",TYPE_BVEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"greaterThan",TYPE_BVEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
- { "SRC_VERTEX", TYPE_VEC2},
- { "VERTEX", TYPE_VEC2},
- { "WORLD_VERTEX", TYPE_VEC2},
- { "UV", TYPE_VEC2},
- { "COLOR", TYPE_VEC4},
- { "VAR1", TYPE_VEC4},
- { "VAR2", TYPE_VEC4},
- { "POINT_SIZE", TYPE_FLOAT},
+ {"greaterThan",TYPE_BVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"greaterThan",TYPE_BVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"greaterThan",TYPE_BVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
- //builtins
- { "WORLD_MATRIX", TYPE_MAT4},
- { "PROJECTION_MATRIX", TYPE_MAT4},
- { "EXTRA_MATRIX", TYPE_MAT4},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID},
-};
-const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_fragment_builtins_defs[]={
-
- { "SRC_COLOR", TYPE_VEC4},
- { "POSITION", TYPE_VEC4},
- { "NORMAL", TYPE_VEC3},
- { "NORMALMAP", TYPE_VEC3},
- { "NORMALMAP_DEPTH", TYPE_FLOAT},
- { "UV", TYPE_VEC2},
- { "COLOR", TYPE_VEC4},
- { "TEXTURE", TYPE_TEXTURE},
- { "TEXTURE_PIXEL_SIZE", TYPE_VEC2},
- { "VAR1", TYPE_VEC4},
- { "VAR2", TYPE_VEC4},
- { "SCREEN_UV", TYPE_VEC2},
- { "POINT_COORD", TYPE_VEC2},
-
-// { "SCREEN_POS", TYPE_VEC2},
-// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID}
+ {"greaterThan",TYPE_BVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"greaterThan",TYPE_BVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"greaterThan",TYPE_BVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
-};
+ {"lessThanEqual",TYPE_BVEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"lessThanEqual",TYPE_BVEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"lessThanEqual",TYPE_BVEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
-const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_light_builtins_defs[]={
-
- { "POSITION", TYPE_VEC4},
- { "NORMAL", TYPE_VEC3},
- { "UV", TYPE_VEC2},
- { "COLOR", TYPE_VEC4},
- { "TEXTURE", TYPE_TEXTURE},
- { "TEXTURE_PIXEL_SIZE", TYPE_VEC2},
- { "VAR1", TYPE_VEC4},
- { "VAR2", TYPE_VEC4},
- { "SCREEN_UV", TYPE_VEC2},
- { "LIGHT_VEC", TYPE_VEC2},
- { "LIGHT_HEIGHT", TYPE_FLOAT},
- { "LIGHT_COLOR", TYPE_VEC4},
- { "LIGHT_UV", TYPE_VEC2},
- { "LIGHT_SHADOW", TYPE_VEC4},
- { "LIGHT", TYPE_VEC4},
- { "SHADOW", TYPE_VEC4},
- { "POINT_COORD", TYPE_VEC2},
-// { "SCREEN_POS", TYPE_VEC2},
-// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID}
+ {"lessThanEqual",TYPE_BVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"lessThanEqual",TYPE_BVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"lessThanEqual",TYPE_BVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
-};
+ {"lessThanEqual",TYPE_BVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"lessThanEqual",TYPE_BVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"lessThanEqual",TYPE_BVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
-const ShaderLanguage::BuiltinsDef ShaderLanguage::postprocess_fragment_builtins_defs[]={
+ {"greaterThanEqual",TYPE_BVEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
- { "IN_COLOR", TYPE_VEC3},
- { "IN_POSITION", TYPE_VEC3},
- { "OUT_COLOR", TYPE_VEC3},
- { "SCREEN_POS", TYPE_VEC2},
- { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
- { "TIME", TYPE_FLOAT},
- { NULL, TYPE_VOID}
-};
+ {"greaterThanEqual",TYPE_BVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"greaterThanEqual",TYPE_BVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
+ {"equal",TYPE_BVEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"equal",TYPE_BVEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"equal",TYPE_BVEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
-ShaderLanguage::DataType ShaderLanguage::compute_node_type(Node *p_node) {
+ {"equal",TYPE_BVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"equal",TYPE_BVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"equal",TYPE_BVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
- switch(p_node->type) {
+ {"equal",TYPE_BVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"equal",TYPE_BVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"equal",TYPE_BVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
- case Node::TYPE_PROGRAM: ERR_FAIL_V(TYPE_VOID);
- case Node::TYPE_FUNCTION: return static_cast<FunctionNode*>(p_node)->return_type;
- case Node::TYPE_BLOCK: ERR_FAIL_V(TYPE_VOID);
- case Node::TYPE_VARIABLE: return static_cast<VariableNode*>(p_node)->datatype_cache;
- case Node::TYPE_CONSTANT: return static_cast<ConstantNode*>(p_node)->datatype;
- case Node::TYPE_OPERATOR: return static_cast<OperatorNode*>(p_node)->return_cache;
- case Node::TYPE_CONTROL_FLOW: ERR_FAIL_V(TYPE_VOID);
- case Node::TYPE_MEMBER: return static_cast<MemberNode*>(p_node)->datatype;
- }
+ {"equal",TYPE_BVEC2,{TYPE_BVEC2,TYPE_BVEC2,TYPE_VOID}},
+ {"equal",TYPE_BVEC3,{TYPE_BVEC3,TYPE_BVEC3,TYPE_VOID}},
+ {"equal",TYPE_BVEC4,{TYPE_BVEC4,TYPE_BVEC4,TYPE_VOID}},
- return TYPE_VOID;
-}
+ {"notEqual",TYPE_BVEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+
+ {"notEqual",TYPE_BVEC2,{TYPE_IVEC2,TYPE_IVEC2,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC3,{TYPE_IVEC3,TYPE_IVEC3,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC4,{TYPE_IVEC4,TYPE_IVEC4,TYPE_VOID}},
+
+ {"notEqual",TYPE_BVEC2,{TYPE_UVEC2,TYPE_UVEC2,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC3,{TYPE_UVEC3,TYPE_UVEC3,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC4,{TYPE_UVEC4,TYPE_UVEC4,TYPE_VOID}},
+
+ {"notEqual",TYPE_BVEC2,{TYPE_BVEC2,TYPE_BVEC2,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC3,{TYPE_BVEC3,TYPE_BVEC3,TYPE_VOID}},
+ {"notEqual",TYPE_BVEC4,{TYPE_BVEC4,TYPE_BVEC4,TYPE_VOID}},
+
+ {"any",TYPE_BOOL,{TYPE_BVEC2,TYPE_VOID}},
+ {"any",TYPE_BOOL,{TYPE_BVEC3,TYPE_VOID}},
+ {"any",TYPE_BOOL,{TYPE_BVEC4,TYPE_VOID}},
+
+ {"all",TYPE_BOOL,{TYPE_BVEC2,TYPE_VOID}},
+ {"all",TYPE_BOOL,{TYPE_BVEC3,TYPE_VOID}},
+ {"all",TYPE_BOOL,{TYPE_BVEC4,TYPE_VOID}},
+
+ {"not",TYPE_BOOL,{TYPE_BVEC2,TYPE_VOID}},
+ {"not",TYPE_BOOL,{TYPE_BVEC3,TYPE_VOID}},
+ {"not",TYPE_BOOL,{TYPE_BVEC4,TYPE_VOID}},
+
+ //intrinsics - texture
+ {"textureSize",TYPE_VEC2,{TYPE_SAMPLER2D,TYPE_INT,TYPE_VOID}},
+ {"textureSize",TYPE_VEC2,{TYPE_ISAMPLER2D,TYPE_INT,TYPE_VOID}},
+ {"textureSize",TYPE_VEC2,{TYPE_USAMPLER2D,TYPE_INT,TYPE_VOID}},
+ {"textureSize",TYPE_VEC2,{TYPE_SAMPLERCUBE,TYPE_INT,TYPE_VOID}},
+
+ {"texture",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC2,TYPE_VOID}},
+ {"texture",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC3,TYPE_VOID}},
+ {"texture",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
+ {"texture",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+
+ {"texture",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC2,TYPE_VOID}},
+ {"texture",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC3,TYPE_VOID}},
+ {"texture",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
+ {"texture",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"texture",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC2,TYPE_VOID}},
+ {"texture",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC3,TYPE_VOID}},
+ {"texture",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
+ {"texture",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
-ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, OperatorNode *p_func) {
+ {"texture",TYPE_VEC4,{TYPE_SAMPLERCUBE,TYPE_VEC3,TYPE_VOID}},
+ {"texture",TYPE_VEC4,{TYPE_SAMPLERCUBE,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureProj",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC3,TYPE_VOID}},
+ {"textureProj",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC4,TYPE_VOID}},
+ {"textureProj",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureProj",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureProj",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC3,TYPE_VOID}},
+ {"textureProj",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC4,TYPE_VOID}},
+ {"textureProj",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureProj",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureProj",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC3,TYPE_VOID}},
+ {"textureProj",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC4,TYPE_VOID}},
+ {"textureProj",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureProj",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureLod",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureLod",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureLod",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureLod",TYPE_VEC4,{TYPE_SAMPLERCUBE,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+
+ {"texelFetch",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_IVEC2,TYPE_INT,TYPE_VOID}},
+ {"texelFetch",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_IVEC2,TYPE_INT,TYPE_VOID}},
+ {"texelFetch",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_IVEC2,TYPE_INT,TYPE_VOID}},
+
+ {"textureProjLod",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureProjLod",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureProjLod",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureProjLod",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureProjLod",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"textureProjLod",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
+
+ {"textureGrad",TYPE_VEC4,{TYPE_SAMPLER2D,TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"textureGrad",TYPE_IVEC4,{TYPE_ISAMPLER2D,TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"textureGrad",TYPE_UVEC4,{TYPE_USAMPLER2D,TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"textureGrad",TYPE_VEC4,{TYPE_SAMPLERCUBE,TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+
+ {"textureScreen",TYPE_VEC4,{TYPE_VEC2,TYPE_VOID}},
+
+ {"dFdx",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
+ {"dFdx",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
+ {"dFdx",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
+ {"dFdx",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"dFdy",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
+ {"dFdy",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
+ {"dFdy",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
+ {"dFdy",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
+ {"fwidth",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
+ {"fwidth",TYPE_VEC2,{TYPE_VEC2,TYPE_VOID}},
+ {"fwidth",TYPE_VEC3,{TYPE_VEC3,TYPE_VOID}},
+ {"fwidth",TYPE_VEC4,{TYPE_VEC4,TYPE_VOID}},
+
+
+ {NULL,TYPE_VOID,{TYPE_VOID}}
+
+};
+
+
+
+bool ShaderLanguage::_validate_function_call(BlockNode* p_block, OperatorNode *p_func,DataType *r_ret_type) {
ERR_FAIL_COND_V(p_func->op!=OP_CALL && p_func->op!=OP_CONSTRUCT,NULL);
@@ -1231,13 +1653,13 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
ERR_FAIL_COND_V( p_func->arguments[0]->type!=Node::TYPE_VARIABLE, NULL );
- String name = static_cast<VariableNode*>(p_func->arguments[0])->name.operator String();
+ StringName name = static_cast<VariableNode*>(p_func->arguments[0])->name.operator String();
bool all_const=true;
for(int i=1;i<p_func->arguments.size();i++) {
if (p_func->arguments[i]->type!=Node::TYPE_CONSTANT)
all_const=false;
- args.push_back(compute_node_type(p_func->arguments[i]));
+ args.push_back(p_func->arguments[i]->get_datatype());
}
int argcount=args.size();
@@ -1265,10 +1687,11 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
fail=true; //make sure the number of arguments matches
if (!fail) {
- p_func->return_cache=intrinsic_func_defs[idx].rettype;
found_intrinsic=true;
- break;
+ if (r_ret_type)
+ *r_ret_type=intrinsic_func_defs[idx].rettype;
+ return true;
}
}
@@ -1277,7 +1700,7 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
}
}
-
+#if 0
if (found_intrinsic) {
if (p_func->op==OP_CONSTRUCT && all_const) {
@@ -1290,6 +1713,7 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
switch(v.get_type()) {
case Variant::REAL: cdata.push_back(v); break;
+ case Variant::INT: cdata.push_back(v); break;
case Variant::VECTOR2: { Vector2 v2=v; cdata.push_back(v2.x); cdata.push_back(v2.y); } break;
case Variant::VECTOR3: { Vector3 v3=v; cdata.push_back(v3.x); cdata.push_back(v3.y); cdata.push_back(v3.z);} break;
case Variant::PLANE: { Plane v4=v; cdata.push_back(v4.normal.x); cdata.push_back(v4.normal.y); cdata.push_back(v4.normal.z); cdata.push_back(v4.d); } break;
@@ -1331,39 +1755,45 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
}
return p_func;
}
-
+#endif
// try existing functions..
- FunctionNode *exclude_function=NULL; //exclude current function (in case inside one)
+ StringName exclude_function;
+ BlockNode *block = p_block;
+ while(block) {
- Node *node = p_func;
+ if (block->parent_function) {
+ exclude_function=block->parent_function->name;
+ }
+ block=block->parent_block;
+ }
- while(node->parent) {
- if (node->type==Node::TYPE_FUNCTION) {
+ for(int i=0;i<shader->functions.size();i++) {
- exclude_function = (FunctionNode*)node;
+ if (shader->functions[i].name==exclude_function) {
+ _set_error("Recursion is not allowed");
+ return false;
}
- node=node->parent;
- }
-
- ERR_FAIL_COND_V(node->type!=Node::TYPE_PROGRAM,NULL);
- ProgramNode *program = (ProgramNode*)node;
-
- for(int i=0;i<program->functions.size();i++) {
+ if (!shader->functions[i].callable) {
+ _set_error("Function '"+String(name)+" can't be called from source code.");
+ return false;
+ }
- if (program->functions[i].function==exclude_function)
+ if (name != shader->functions[i].name)
continue;
- FunctionNode *pfunc = program->functions[i].function;
+ FunctionNode *pfunc = shader->functions[i].function;
+
if (pfunc->arguments.size()!=args.size())
continue;
bool fail=false;
+
for(int i=0;i<args.size();i++) {
if (args[i]!=pfunc->arguments[i].type) {
fail=true;
@@ -1371,153 +1801,94 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
}
}
- if (!fail && name == program->functions[i].name) {
+ if (!fail) {
p_func->return_cache=pfunc->return_type;
- return p_func;
+ return true;
}
}
- return NULL;
+ return false;
}
-ShaderLanguage::Node * ShaderLanguage::validate_operator(Parser& parser,OperatorNode *p_func) {
-
- int argcount = p_func->arguments.size();
- ERR_FAIL_COND_V(argcount>2,NULL);
-
- DataType argtype[2]={TYPE_VOID,TYPE_VOID};
- bool all_const=true;
-
- for(int i=0;i<argcount;i++) {
+bool ShaderLanguage::_parse_function_arguments(BlockNode* p_block,const Map<StringName,DataType> &p_builtin_types,OperatorNode* p_func) {
- argtype[i]=compute_node_type(p_func->arguments[i]);
- if (p_func->arguments[i]->type!=Node::TYPE_CONSTANT)
- all_const=false;
+ Token tk = _get_token();
- }
- int idx=0;
- bool valid=false;
- while(operator_defs[idx].op!=OP_MAX) {
+ while(true) {
- if (p_func->op==operator_defs[idx].op) {
+ if (tk.type==TK_PARENTHESIS_CLOSE) {
+ return true;
+ }
+ Node *arg= _parse_expression(p_block,p_builtin_types);
+ if (!arg)
+ return false;
+ p_func->arguments.push_back(arg);
- if (operator_defs[idx].args[0]==argtype[0] && operator_defs[idx].args[1]==argtype[1]) {
+ tk = _get_token();
- p_func->return_cache=operator_defs[idx].rettype;
- valid=true;
- break;
- }
+ if (tk.type==TK_PARENTHESIS_CLOSE) {
+ //none
+ } else if (tk.type==TK_COMMA) {
+ tk = _get_token(); //next
+ } else {
+ // something is broken
+ _set_error("Expected ',' or ')' after argument");
+ return false;
}
- idx++;
- }
-
- if (!valid)
- return NULL;
-
-#define _RCO2(m_op,m_vop)\
-case m_op: {\
- ConstantNode *cn = parser.create_node<ConstantNode>(p_func->parent);\
- cn->datatype=p_func->return_cache; \
- Variant::evaluate(m_vop,static_cast<ConstantNode*>(p_func->arguments[0])->value,static_cast<ConstantNode*>(p_func->arguments[1])->value,cn->value,valid);\
- if (!valid)\
- return NULL;\
- return cn;\
-} break;
-
-#define _RCO1(m_op,m_vop)\
-case m_op: {\
- ConstantNode *cn = parser.create_node<ConstantNode>(p_func->parent);\
- cn->datatype=p_func->return_cache; \
- Variant::evaluate(m_vop,static_cast<ConstantNode*>(p_func->arguments[0])->value,Variant(),cn->value,valid);\
- if (!valid)\
- return NULL;\
- return cn;\
-} break;
-
- if (all_const) {
- //reduce constant operator
- switch(p_func->op) {
- _RCO2(OP_ADD,Variant::OP_ADD);
- _RCO2(OP_SUB,Variant::OP_SUBSTRACT);
- _RCO2(OP_MUL,Variant::OP_MULTIPLY);
- _RCO2(OP_DIV,Variant::OP_DIVIDE);
- _RCO1(OP_NEG,Variant::OP_NEGATE);
- _RCO1(OP_NOT,Variant::OP_NOT);
- _RCO2(OP_CMP_EQ,Variant::OP_EQUAL);
- _RCO2(OP_CMP_NEQ,Variant::OP_NOT_EQUAL);
- _RCO2(OP_CMP_LEQ,Variant::OP_LESS_EQUAL);
- _RCO2(OP_CMP_GEQ,Variant::OP_GREATER_EQUAL);
- _RCO2(OP_CMP_LESS,Variant::OP_LESS);
- _RCO2(OP_CMP_GREATER,Variant::OP_GREATER);
- _RCO2(OP_CMP_OR,Variant::OP_OR);
- _RCO2(OP_CMP_AND,Variant::OP_AND);
- default: {}
- }
}
-
- return p_func;
-
+ return true;
}
bool ShaderLanguage::is_token_operator(TokenType p_type) {
- return (p_type==TK_OP_EQUAL) ||
- (p_type==TK_OP_NOT_EQUAL) ||
- (p_type==TK_OP_LESS) ||
- (p_type==TK_OP_LESS_EQUAL) ||
- (p_type==TK_OP_GREATER) ||
- (p_type==TK_OP_GREATER_EQUAL) ||
- (p_type==TK_OP_AND) ||
- (p_type==TK_OP_OR) ||
- (p_type==TK_OP_NOT) ||
- (p_type==TK_OP_ADD) ||
- (p_type==TK_OP_SUB) ||
- (p_type==TK_OP_MUL) ||
- (p_type==TK_OP_DIV) ||
- (p_type==TK_OP_NEG) ||
- (p_type==TK_OP_ASSIGN) ||
- (p_type==TK_OP_ASSIGN_ADD) ||
- (p_type==TK_OP_ASSIGN_SUB) ||
- (p_type==TK_OP_ASSIGN_MUL) ||
- (p_type==TK_OP_ASSIGN_DIV);
-}
-ShaderLanguage::Operator ShaderLanguage::get_token_operator(TokenType p_type) {
+ return (p_type==TK_OP_EQUAL ||
+ p_type==TK_OP_NOT_EQUAL ||
+ p_type==TK_OP_LESS ||
+ p_type==TK_OP_LESS_EQUAL ||
+ p_type==TK_OP_GREATER ||
+ p_type==TK_OP_GREATER_EQUAL ||
+ p_type==TK_OP_AND ||
+ p_type==TK_OP_OR ||
+ p_type==TK_OP_NOT ||
+ p_type==TK_OP_ADD ||
+ p_type==TK_OP_SUB ||
+ p_type==TK_OP_MUL ||
+ p_type==TK_OP_DIV ||
+ p_type==TK_OP_MOD ||
+ p_type==TK_OP_SHIFT_LEFT ||
+ p_type==TK_OP_SHIFT_RIGHT ||
+ p_type==TK_OP_ASSIGN ||
+ p_type==TK_OP_ASSIGN_ADD ||
+ p_type==TK_OP_ASSIGN_SUB ||
+ p_type==TK_OP_ASSIGN_MUL ||
+ p_type==TK_OP_ASSIGN_DIV ||
+ p_type==TK_OP_ASSIGN_MOD ||
+ p_type==TK_OP_ASSIGN_SHIFT_LEFT ||
+ p_type==TK_OP_ASSIGN_SHIFT_RIGHT ||
+ p_type==TK_OP_ASSIGN_BIT_AND ||
+ p_type==TK_OP_ASSIGN_BIT_OR ||
+ p_type==TK_OP_ASSIGN_BIT_XOR ||
+ p_type==TK_OP_BIT_AND ||
+ p_type==TK_OP_BIT_OR ||
+ p_type==TK_OP_BIT_XOR ||
+ p_type==TK_OP_BIT_INVERT ||
+ p_type==TK_OP_INCREMENT ||
+ p_type==TK_OP_DECREMENT ||
+ p_type==TK_QUESTION ||
+ p_type==TK_COLON );
- switch(p_type) {
- case TK_OP_EQUAL: return OP_CMP_EQ ;
- case TK_OP_NOT_EQUAL: return OP_CMP_NEQ;
- case TK_OP_LESS: return OP_CMP_LESS ;
- case TK_OP_LESS_EQUAL: return OP_CMP_LEQ ;
- case TK_OP_GREATER: return OP_CMP_GREATER ;
- case TK_OP_GREATER_EQUAL: return OP_CMP_GEQ ;
- case TK_OP_AND: return OP_CMP_AND ;
- case TK_OP_OR: return OP_CMP_OR ;
- case TK_OP_NOT: return OP_NOT ;
- case TK_OP_ADD: return OP_ADD ;
- case TK_OP_SUB: return OP_SUB ;
- case TK_OP_MUL: return OP_MUL ;
- case TK_OP_DIV: return OP_DIV ;
- case TK_OP_NEG: return OP_NEG ;
- case TK_OP_ASSIGN: return OP_ASSIGN ;
- case TK_OP_ASSIGN_ADD: return OP_ASSIGN_ADD ;
- case TK_OP_ASSIGN_SUB: return OP_ASSIGN_SUB ;
- case TK_OP_ASSIGN_MUL: return OP_ASSIGN_MUL ;
- case TK_OP_ASSIGN_DIV: return OP_ASSIGN_DIV ;
- default: ERR_FAIL_V(OP_MAX);
- }
-
- return OP_MAX;
}
-Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_expr) {
+
+ShaderLanguage::Node* ShaderLanguage::_parse_expression(BlockNode* p_block,const Map<StringName,DataType> &p_builtin_types) {
Vector<Expression> expression;
//Vector<TokenType> operators;
@@ -1525,416 +1896,413 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
while(true) {
Node *expr=NULL;
+ int pos = char_idx;
+ Token tk = _get_token();
- if (parser.get_token_type()==TK_PARENTHESIS_OPEN) {
+ if (tk.type==TK_PARENTHESIS_OPEN) {
//handle subexpression
- parser.advance();
- Error err = parse_expression(parser,p_parent,&expr);
- if (err)
- return err;
- if (parser.get_token_type()!=TK_PARENTHESIS_CLOSE) {
+ expr = _parse_expression(p_block,p_builtin_types);
+ if (!expr)
+ return NULL;
- parser.set_error("Expected ')' in expression");
- return ERR_PARSE_ERROR;
- }
+ tk = _get_token();
- parser.advance();
+ if (tk.type!=TK_PARENTHESIS_CLOSE) {
- } else if (parser.get_token_type()==TK_REAL_CONSTANT) {
+ _set_error("Expected ')' in expression");
+ return NULL;
+ }
+ } else if (tk.type==TK_REAL_CONSTANT) {
- ConstantNode *constant = parser.create_node<ConstantNode>(p_parent);
- constant->value=parser.get_token().text.operator String().to_double();
+
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value=tk.constant;
constant->datatype=TYPE_FLOAT;
expr=constant;
- parser.advance();
- } else if (parser.get_token_type()==TK_TRUE) {
+
+ } else if (tk.type==TK_REAL_CONSTANT) {
+
+
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value=int(tk.constant);
+ constant->datatype=TYPE_INT;
+ expr=constant;
+
+ } else if (tk.type==TK_TRUE) {
//print_line("found true");
//handle true constant
- ConstantNode *constant = parser.create_node<ConstantNode>(p_parent);
+ ConstantNode *constant = alloc_node<ConstantNode>();
constant->value=true;
constant->datatype=TYPE_BOOL;
expr=constant;
- parser.advance();
- } else if (parser.get_token_type()==TK_FALSE) {
+
+ } else if (tk.type==TK_FALSE) {
//handle false constant
- ConstantNode *constant = parser.create_node<ConstantNode>(p_parent);
+ ConstantNode *constant = alloc_node<ConstantNode>();
constant->value=false;
constant->datatype=TYPE_BOOL;
expr=constant;
- parser.advance();
- } else if (parser.get_token_type()==TK_TYPE_VOID) {
-
- //make sure void is not used in expression
- parser.set_error("Void value not allowed in Expression");
- return ERR_PARSE_ERROR;
- } else if (parser.get_token_type(1)==TK_PARENTHESIS_OPEN && (is_token_nonvoid_datatype(parser.get_token_type()) || parser.get_token_type()==TK_INDENTIFIER)) {
-
-
- //function or constructor
- StringName name;
- DataType constructor=TYPE_VOID;
- if (is_token_nonvoid_datatype(parser.get_token_type())) {
-
- constructor=get_token_datatype(parser.get_token_type());
- switch(get_token_datatype(parser.get_token_type())) {
- case TYPE_BOOL: name="bool"; break;
- case TYPE_FLOAT: name="float"; break;
- case TYPE_VEC2: name="vec2"; break;
- case TYPE_VEC3: name="vec3"; break;
- case TYPE_VEC4: name="vec4"; break;
- case TYPE_MAT2: name="mat2"; break;
- case TYPE_MAT3: name="mat3"; break;
- case TYPE_MAT4: name="mat4"; break;
- default: ERR_FAIL_V(ERR_BUG);
- }
- } else {
- name=parser.get_token().text;
- }
+ } else if (tk.type==TK_TYPE_VOID) {
- if (!test_existing_identifier(p_parent,name)) {
+ //make sure void is not used in expression
+ _set_error("Void value not allowed in Expression");
+ return NULL;
+ } else if (is_token_precision(tk.type) || is_token_nonvoid_datatype(tk.type)) {
+ //basic type constructor
- parser.set_error("Unknown identifier in expression: "+name);
- return ERR_PARSE_ERROR;
- }
+ OperatorNode *func = alloc_node<OperatorNode>();
+ func->op=OP_CONSTRUCT;
- parser.advance(2);
- OperatorNode *func = parser.create_node<OperatorNode>(p_parent);
+ if (is_token_precision(tk.type)) {
- func->op=constructor!=TYPE_VOID?OP_CONSTRUCT:OP_CALL;
+ func->return_precision_cache=get_token_precision(tk.type);
+ tk=_get_token();
+ }
- VariableNode *funcname = parser.create_node<VariableNode>(func);
- funcname->name=name;
+ VariableNode *funcname = alloc_node<VariableNode>();
+ funcname->name=get_datatype_name(get_token_datatype(tk.type));
func->arguments.push_back(funcname);
- //parse parameters
-
- if (parser.get_token_type()==TK_PARENTHESIS_CLOSE) {
- parser.advance();
- } else {
-
- while(true) {
-
-
- Node *arg=NULL;
- Error err = parse_expression(parser,func,&arg);
- if (err)
- return err;
- func->arguments.push_back(arg);
-
- if (parser.get_token_type()==TK_PARENTHESIS_CLOSE) {
- parser.advance();
- break;
-
- } else if (parser.get_token_type()==TK_COMMA) {
-
- if (parser.get_token_type(1)==TK_PARENTHESIS_CLOSE) {
-
- parser.set_error("Expression expected");
- return ERR_PARSE_ERROR;
- }
-
- parser.advance();
- } else {
- // something is broken
- parser.set_error("Expected ',' or ')'");
- return ERR_PARSE_ERROR;
- }
-
- }
+ tk=_get_token();
+ if (tk.type!=TK_PARENTHESIS_OPEN) {
+ _set_error("Expected '(' after type name");
+ return NULL;
}
- expr=validate_function_call(parser,func);
- if (!expr) {
+ if (!_parse_function_arguments(p_block,p_builtin_types,func))
+ return NULL;
- parser.set_error("Invalid arguments to function/constructor: "+StringName(name));
- return ERR_PARSE_ERROR;
+ if (!_validate_function_call(p_block,func,&func->return_cache)) {
+ _set_error("No matching constructor found for: '"+String(funcname->name)+"'");
+ return NULL;
}
+ //validate_Function_call()
- } else if (parser.get_token_type()==TK_INDENTIFIER) {
- //probably variable
+ expr=func;
- Node *node =p_parent;
- bool existing=false;
- DataType datatype;
- StringName identifier=parser.get_token().text;
+ } else if (tk.type==TK_IDENTIFIER) {
- while(node) {
- if (node->type==Node::TYPE_BLOCK) {
+ tk=_get_token();
+ if (tk.type==TK_PARENTHESIS_OPEN) {
+ //a function
+ StringName name = tk.text;
- BlockNode *block = (BlockNode*)node;
+ OperatorNode *func = alloc_node<OperatorNode>();
+ func->op=OP_CALL;
+ VariableNode *funcname = alloc_node<VariableNode>();
+ funcname->name=name;
+ func->arguments.push_back(funcname);
- if (block->variables.has(identifier)) {
- existing=true;
- datatype=block->variables[identifier];
- break;
- }
- }
+ if (!_parse_function_arguments(p_block,p_builtin_types,func))
+ return NULL;
- if (node->type==Node::TYPE_FUNCTION) {
- FunctionNode *function=(FunctionNode*)node;
- for(int i=0;i<function->arguments.size();i++) {
- if (function->arguments[i].name==identifier) {
- existing=true;
- datatype=function->arguments[i].type;
- break;
- }
- }
+ if (!_validate_function_call(p_block,func,&func->return_cache)) {
+ _set_error("No matching function found for: '"+String(funcname->name)+"'");
+ return NULL;
+ }
- if (existing)
- break;
+ expr=func;
- }
+ } else {
+ //an identifier
+ char_idx=pos; //rollback
- if (node->type==Node::TYPE_PROGRAM) {
+ StringName identifier = tk.text;
- ProgramNode *program = (ProgramNode*)node;
- if (program->builtin_variables.has(identifier)) {
- datatype = program->builtin_variables[identifier];
- existing=true;
- break;
- }
- if (program->uniforms.has(identifier)) {
- datatype = program->uniforms[identifier].type;
- existing=true;
- break;
- }
+ DataType data_type;
+ IdentifierType ident_type;
+ if (!_find_identifier(p_block,p_builtin_types,identifier,&data_type,&ident_type)) {
+ _set_error("Unknown identifier in expression: "+String(identifier));
+ return NULL;
}
- node=node->parent;
- }
+ if (ident_type==IDENTIFIER_FUNCTION) {
+ _set_error("Can't use function as identifier: "+String(identifier));
+ return NULL;
+ }
- if (!existing) {
- parser.set_error("Nonexistent identifier in expression: "+identifier);
- return ERR_PARSE_ERROR;
+ VariableNode *varname = alloc_node<VariableNode>();
+ varname->name=identifier;
+ varname->datatype_cache=data_type;
+ expr=varname;
}
- VariableNode *varname = parser.create_node<VariableNode>(p_parent);
- varname->name=identifier;
- varname->datatype_cache=datatype;
- parser.advance();
- expr=varname;
-
- } else if (parser.get_token_type()==TK_OP_SUB || parser.get_token_type()==TK_OP_NOT) {
- //single prefix operators
- TokenType token_type=parser.get_token_type();
- parser.advance();
- //Node *subexpr=NULL;
- //Error err = parse_expression(parser,p_parent,&subexpr);
- //if (err)
- // return err;
+ } else if (tk.type==TK_OP_ADD) {
+ continue; //this one does nothing
+ } if (tk.type==TK_OP_SUB || tk.type==TK_OP_NOT || tk.type==TK_OP_BIT_INVERT || tk.type==TK_OP_INCREMENT || tk.type==TK_OP_DECREMENT) {
- //OperatorNode *op = parser.create_node<OperatorNode>(p_parent);
Expression e;
e.is_op=true;
- switch(token_type) {
- case TK_OP_SUB: e.op=TK_OP_NEG; break;
- case TK_OP_NOT: e.op=TK_OP_NOT; break;
- //case TK_OP_PLUS_PLUS: op->op=OP_PLUS_PLUS; break;
- //case TK_OP_MINUS_MINUS: op->op=OP_MINUS_MINUS; break;
- default: ERR_FAIL_V(ERR_BUG);
+ switch(tk.type) {
+ case TK_OP_SUB: e.op=OP_NEGATE; break;
+ case TK_OP_NOT: e.op=OP_NOT; break;
+ case TK_OP_BIT_INVERT: e.op=OP_BIT_INVERT; break;
+ case TK_OP_INCREMENT: e.op=OP_INCREMENT; break;
+ case TK_OP_DECREMENT: e.op=OP_DECREMENT; break;
+ default: ERR_FAIL_V(NULL);
}
expression.push_back(e);
-
continue;
} else {
- print_line("found bug?");
- print_line("misplaced token: "+String(token_names[parser.get_token_type()]));
-
- parser.set_error("Error parsing expression, misplaced: "+String(token_names[parser.get_token_type()]));
- return ERR_PARSE_ERROR;
+ _set_error("Expected expression, found: "+get_token_text(tk));
+ return NULL;
//nothing
}
- ERR_FAIL_COND_V(!expr,ERR_BUG);
+ ERR_FAIL_COND_V(!expr,NULL);
/* OK now see what's NEXT to the operator.. */
/* OK now see what's NEXT to the operator.. */
/* OK now see what's NEXT to the operator.. */
+ while(true) {
+ int pos = char_idx;
+ tk=_get_token();
- if (parser.get_token_type()==TK_PERIOD) {
-
- if (parser.get_token_type(1)!=TK_INDENTIFIER) {
- parser.set_error("Expected identifier as member");
- return ERR_PARSE_ERROR;
- }
-
- DataType dt = compute_node_type(expr);
- String ident = parser.get_token(1).text;
-
- bool ok=true;
- DataType member_type;
- switch(dt) {
- case TYPE_VEC2: {
-
- int l = ident.length();
- if (l==1) {
- member_type=TYPE_FLOAT;
- } else if (l==2) {
- member_type=TYPE_VEC2;
- } else {
- ok=false;
- break;
- }
+ if (tk.type==TK_PERIOD) {
- const CharType *c=ident.ptr();
- for(int i=0;i<l;i++) {
+ tk=_get_token();
+ if (tk.type!=TK_IDENTIFIER) {
+ _set_error("Expected identifier as member");
+ return NULL;
+ }
- switch(c[i]) {
- case 'r':
- case 'g':
- case 'x':
- case 'y':
- break;
- default:
- ok=false;
- break;
+ DataType dt = expr->get_datatype();
+ String ident = tk.text;
+
+ bool ok=true;
+ DataType member_type;
+ switch(dt) {
+ case TYPE_BVEC2:
+ case TYPE_IVEC2:
+ case TYPE_UVEC2:
+ case TYPE_VEC2: {
+
+ int l = ident.length();
+ if (l==1) {
+ member_type=DataType(dt-1);
+ } else if (l==2) {
+ member_type=dt;
+ } else {
+ ok=false;
+ break;
}
- }
- } break;
- case TYPE_VEC3: {
-
- int l = ident.length();
- if (l==1) {
- member_type=TYPE_FLOAT;
- } else if (l==2) {
- member_type=TYPE_VEC2;
- } else if (l==3) {
- member_type=TYPE_VEC3;
- } else {
- ok=false;
- break;
- }
+ const CharType *c=ident.ptr();
+ for(int i=0;i<l;i++) {
+
+ switch(c[i]) {
+ case 'r':
+ case 'g':
+ case 'x':
+ case 'y':
+ break;
+ default:
+ ok=false;
+ break;
+ }
+ }
- const CharType *c=ident.ptr();
- for(int i=0;i<l;i++) {
+ } break;
+ case TYPE_BVEC3:
+ case TYPE_IVEC3:
+ case TYPE_UVEC3:
+ case TYPE_VEC3: {
+
+ int l = ident.length();
+ if (l==1) {
+ member_type=DataType(dt-2);
+ } else if (l==2) {
+ member_type=DataType(dt-1);
+ } else if (l==3) {
+ member_type=dt;
+ } else {
+ ok=false;
+ break;
+ }
- switch(c[i]) {
- case 'r':
- case 'g':
- case 'b':
- case 'x':
- case 'y':
- case 'z':
- break;
- default:
- ok=false;
- break;
+ const CharType *c=ident.ptr();
+ for(int i=0;i<l;i++) {
+
+ switch(c[i]) {
+ case 'r':
+ case 'g':
+ case 'b':
+ case 'x':
+ case 'y':
+ case 'z':
+ break;
+ default:
+ ok=false;
+ break;
+ }
}
- }
- } break;
- case TYPE_VEC4: {
-
- int l = ident.length();
- if (l==1) {
- member_type=TYPE_FLOAT;
- } else if (l==2) {
- member_type=TYPE_VEC2;
- } else if (l==3) {
- member_type=TYPE_VEC3;
- } else if (l==4) {
- member_type=TYPE_VEC4;
- } else {
- ok=false;
- break;
- }
+ } break;
+ case TYPE_BVEC4:
+ case TYPE_IVEC4:
+ case TYPE_UVEC4:
+ case TYPE_VEC4: {
+
+ int l = ident.length();
+ if (l==1) {
+ member_type=DataType(dt-3);
+ } else if (l==2) {
+ member_type=DataType(dt-2);
+ } else if (l==3) {
+ member_type=DataType(dt-1);;
+ } else if (l==4) {
+ member_type=dt;
+ } else {
+ ok=false;
+ break;
+ }
- const CharType *c=ident.ptr();
- for(int i=0;i<l;i++) {
-
- switch(c[i]) {
- case 'r':
- case 'g':
- case 'b':
- case 'a':
- case 'x':
- case 'y':
- case 'z':
- case 'w':
- break;
- default:
- ok=false;
- break;
+ const CharType *c=ident.ptr();
+ for(int i=0;i<l;i++) {
+
+ switch(c[i]) {
+ case 'r':
+ case 'g':
+ case 'b':
+ case 'a':
+ case 'x':
+ case 'y':
+ case 'z':
+ case 'w':
+ break;
+ default:
+ ok=false;
+ break;
+ }
}
- }
- } break;
- case TYPE_MAT2: ok=(ident=="x" || ident=="y"); member_type=TYPE_VEC2; break;
- case TYPE_MAT3: ok=(ident=="x" || ident=="y" || ident=="z" ); member_type=TYPE_VEC3; break;
- case TYPE_MAT4: ok=(ident=="x" || ident=="y" || ident=="z" || ident=="w"); member_type=TYPE_VEC4; break;
- default: {}
- }
+ } break;
+ case TYPE_MAT2: ok=(ident=="x" || ident=="y"); member_type=TYPE_VEC2; break;
+ case TYPE_MAT3: ok=(ident=="x" || ident=="y" || ident=="z" ); member_type=TYPE_VEC3; break;
+ case TYPE_MAT4: ok=(ident=="x" || ident=="y" || ident=="z" || ident=="w"); member_type=TYPE_VEC4; break;
+ default: {}
+ }
- if (!ok) {
+ if (!ok) {
- parser.set_error("Invalid member for expression: ."+ident);
- return ERR_PARSE_ERROR;
- }
+ _set_error("Invalid member for expression: ."+ident);
+ return NULL;
+ }
- MemberNode *mn = parser.create_node<MemberNode>(p_parent);
- mn->basetype=dt;
- mn->datatype=member_type;
- mn->name=ident;
- mn->owner=expr;
- expr=mn;
+ MemberNode *mn = alloc_node<MemberNode>();
+ mn->basetype=dt;
+ mn->datatype=member_type;
+ mn->name=ident;
+ mn->owner=expr;
+ expr=mn;
- parser.advance(2);
- //todo
- //member (period) has priority over any operator
- //creates a subindexing expression in place
+ //todo
+ //member (period) has priority over any operator
+ //creates a subindexing expression in place
- } else if (parser.get_token_type()==TK_BRACKET_OPEN) {
- //todo
- //subindexing has priority over any operator
- //creates a subindexing expression in place
+ /*} else if (tk.type==TK_BRACKET_OPEN) {
+ //todo
+ //subindexing has priority over any operator
+ //creates a subindexing expression in place
- } /*else if (parser.get_token_type()==TK_OP_PLUS_PLUS || parser.get_token_type()==TK_OP_MINUS_MINUS) {
- //todo
- //inc/dec operators have priority over any operator
- //creates a subindexing expression in place
- //return OK; //wtfs
+ */
+ } else if (tk.type==TK_OP_INCREMENT || tk.type==TK_OP_DECREMENT) {
- } */
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op=tk.type==TK_OP_DECREMENT ? OP_POST_DECREMENT : OP_POST_INCREMENT;
+ op->arguments.push_back(expr);
+
+ if (!_validate_operator(op,&op->return_cache)) {
+ _set_error("Invalid base type for increment/decrement operator");
+ return NULL;
+ }
+ expr=op;
+ } else {
+ char_idx=pos; //rollback
+ break;
+ }
+ }
Expression e;
e.is_op=false;
e.node=expr;
expression.push_back(e);
+ pos = char_idx;
+ tk = _get_token();
- if (is_token_operator(parser.get_token_type())) {
+ if (is_token_operator(tk.type)) {
Expression o;
o.is_op=true;
- o.op=parser.get_token_type();
+
+ switch(tk.type) {
+
+ case TK_OP_EQUAL: o.op = OP_EQUAL; break;
+ case TK_OP_NOT_EQUAL: o.op = OP_NOT_EQUAL; break;
+ case TK_OP_LESS: o.op = OP_LESS; break;
+ case TK_OP_LESS_EQUAL: o.op = OP_LESS_EQUAL; break;
+ case TK_OP_GREATER: o.op = OP_GREATER; break;
+ case TK_OP_GREATER_EQUAL: o.op = OP_GREATER_EQUAL; break;
+ case TK_OP_AND: o.op = OP_AND; break;
+ case TK_OP_OR: o.op = OP_OR; break;
+ case TK_OP_ADD: o.op = OP_ADD; break;
+ case TK_OP_SUB: o.op = OP_SUB; break;
+ case TK_OP_MUL: o.op = OP_MUL; break;
+ case TK_OP_DIV: o.op = OP_DIV; break;
+ case TK_OP_MOD: o.op = OP_MOD; break;
+ case TK_OP_SHIFT_LEFT: o.op = OP_SHIFT_LEFT; break;
+ case TK_OP_SHIFT_RIGHT: o.op = OP_SHIFT_RIGHT; break;
+ case TK_OP_ASSIGN: o.op = OP_ASSIGN; break;
+ case TK_OP_ASSIGN_ADD: o.op = OP_ASSIGN_ADD; break;
+ case TK_OP_ASSIGN_SUB: o.op = OP_ASSIGN_SUB; break;
+ case TK_OP_ASSIGN_MUL: o.op = OP_ASSIGN_MUL; break;
+ case TK_OP_ASSIGN_DIV: o.op = OP_ASSIGN_DIV; break;
+ case TK_OP_ASSIGN_MOD: o.op = OP_ASSIGN_MOD; break;
+ case TK_OP_ASSIGN_SHIFT_LEFT: o.op = OP_ASSIGN_SHIFT_LEFT; break;
+ case TK_OP_ASSIGN_SHIFT_RIGHT: o.op = OP_ASSIGN_SHIFT_RIGHT; break;
+ case TK_OP_ASSIGN_BIT_AND: o.op = OP_ASSIGN_BIT_AND; break;
+ case TK_OP_ASSIGN_BIT_OR: o.op = OP_ASSIGN_BIT_OR; break;
+ case TK_OP_ASSIGN_BIT_XOR: o.op = OP_ASSIGN_BIT_XOR; break;
+ case TK_OP_BIT_AND: o.op = OP_BIT_AND; break;
+ case TK_OP_BIT_OR: o.op = OP_BIT_OR ; break;
+ case TK_OP_BIT_XOR: o.op = OP_BIT_XOR; break;
+ case TK_QUESTION: o.op = OP_SELECT_IF; break;
+ case TK_COLON: o.op = OP_SELECT_ELSE; break;
+ default: {
+ _set_error("Invalid token for operator: "+get_token_text(tk));
+ return NULL;
+ }
+ } break;
+
expression.push_back(o);
- parser.advance();
+
} else {
+ char_idx=pos; //something else, so rollback and end
break;
}
}
@@ -1948,6 +2316,7 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
int next_op=-1;
int min_priority=0xFFFFF;
bool is_unary=false;
+ bool is_ternary=false;
for(int i=0;i<expression.size();i++) {
@@ -1957,45 +2326,48 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
}
bool unary=false;
+ bool ternary=false;
int priority;
switch(expression[i].op) {
-
- case TK_OP_NOT: priority=0; unary=true; break;
- case TK_OP_NEG: priority=0; unary=true; break;
-
- case TK_OP_MUL: priority=1; break;
- case TK_OP_DIV: priority=1; break;
-
- case TK_OP_ADD: priority=2; break;
- case TK_OP_SUB: priority=2; break;
-
- // shift left/right =2
-
- case TK_OP_LESS: priority=4; break;
- case TK_OP_LESS_EQUAL: priority=4; break;
- case TK_OP_GREATER: priority=4; break;
- case TK_OP_GREATER_EQUAL: priority=4; break;
-
- case TK_OP_EQUAL: priority=5; break;
- case TK_OP_NOT_EQUAL: priority=5; break;
-
- //bit and =5
- //bit xor =6
- //bit or=7
-
- case TK_OP_AND: priority=8; break;
- case TK_OP_OR: priority=9; break;
-
- // ?: = 10
-
- case TK_OP_ASSIGN_ADD: priority=11; break;
- case TK_OP_ASSIGN_SUB: priority=11; break;
- case TK_OP_ASSIGN_MUL: priority=11; break;
- case TK_OP_ASSIGN_DIV: priority=11; break;
- case TK_OP_ASSIGN: priority=11; break;
-
- default: ERR_FAIL_V(ERR_BUG); //unexpected operator
+ case OP_EQUAL: priority=8; break;
+ case OP_NOT_EQUAL: priority=8; break;
+ case OP_LESS: priority=7; break;
+ case OP_LESS_EQUAL: priority=7; break;
+ case OP_GREATER: priority=7; break;
+ case OP_GREATER_EQUAL: priority=7; break;
+ case OP_AND: priority=12; break;
+ case OP_OR: priority=14; break;
+ case OP_NOT: priority=3; unary=true; break;
+ case OP_NEGATE: priority=3; unary=true; break;
+ case OP_ADD: priority=5; break;
+ case OP_SUB: priority=5; break;
+ case OP_MUL: priority=4; break;
+ case OP_DIV: priority=4; break;
+ case OP_MOD: priority=4; break;
+ case OP_SHIFT_LEFT: priority=6; break;
+ case OP_SHIFT_RIGHT: priority=6; break;
+ case OP_ASSIGN: priority=16; break;
+ case OP_ASSIGN_ADD: priority=16; break;
+ case OP_ASSIGN_SUB: priority=16; break;
+ case OP_ASSIGN_MUL: priority=16; break;
+ case OP_ASSIGN_DIV: priority=16; break;
+ case OP_ASSIGN_MOD: priority=16; break;
+ case OP_ASSIGN_SHIFT_LEFT: priority=16; break;
+ case OP_ASSIGN_SHIFT_RIGHT: priority=16; break;
+ case OP_ASSIGN_BIT_AND: priority=16; break;
+ case OP_ASSIGN_BIT_OR: priority=16; break;
+ case OP_ASSIGN_BIT_XOR: priority=16; break;
+ case OP_BIT_AND: priority=9; break;
+ case OP_BIT_OR: priority=11; break;
+ case OP_BIT_XOR: priority=10; break;
+ case OP_BIT_INVERT: priority=3; unary=true; break;
+ case OP_INCREMENT: priority=3; unary=true; break;
+ case OP_DECREMENT: priority=3; unary=true; break;
+ case OP_SELECT_IF: priority=15; ternary=true; break;
+ case OP_SELECT_ELSE: priority=15; ternary=true; break;
+
+ default: ERR_FAIL_V(NULL); //unexpected operator
}
@@ -2005,11 +2377,12 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
next_op=i;
min_priority=priority;
is_unary=unary;
+ is_ternary=ternary;
}
}
- ERR_FAIL_COND_V(next_op==-1,ERR_BUG);
+ ERR_FAIL_COND_V(next_op==-1,NULL);
// OK! create operator..
// OK! create operator..
@@ -2021,48 +2394,90 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
expr_pos++;
if (expr_pos==expression.size()) {
//can happen..
- parser.set_error("Unexpected end of expression..");
- return ERR_BUG;
+ _set_error("Unexpected end of expression..");
+ return NULL;
}
}
//consecutively do unary opeators
for(int i=expr_pos-1;i>=next_op;i--) {
- OperatorNode *op = parser.create_node<OperatorNode>(p_parent);
- op->op=get_token_operator(expression[i].op);
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op=expression[i].op;
op->arguments.push_back(expression[i+1].node);
expression[i].is_op=false;
- expression[i].node=validate_operator(parser,op);
- if (!expression[i].node) {
+ expression[i].node=op;
+
+
+ if (!_validate_operator(op,&op->return_cache)) {
String at;
for(int i=0;i<op->arguments.size();i++) {
if (i>0)
at+=" and ";
- at+=get_datatype_name(compute_node_type(op->arguments[i]));
+ at+=get_datatype_name(op->arguments[i]->get_datatype());
}
- parser.set_error("Invalid argument to unary operator "+String(token_names[op->op])+": "+at);
- return ERR_PARSE_ERROR;
+ _set_error("Invalid argument to unary operator: "+at);
+ return NULL;
}
expression.remove(i+1);
}
+
+ } else if (is_ternary) {
+
+ if (next_op <1 || next_op>=(expression.size()-1)) {
+ _set_error("Parser bug..");
+ ERR_FAIL_V(NULL);
+ }
+
+ if (next_op+2 >= expression.size() || !expression[next_op+2].is_op || expression[next_op+2].op!=OP_SELECT_ELSE) {
+ _set_error("Mising matching ':' for select operator");
+ return NULL;
+ }
+
+
+
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op=expression[next_op].op;
+ op->arguments.push_back(expression[next_op-1].node);
+ op->arguments.push_back(expression[next_op+1].node);
+ op->arguments.push_back(expression[next_op+3].node);
+
+ expression[next_op-1].is_op=false;
+ expression[next_op-1].node=op;
+ if (!_validate_operator(op,&op->return_cache)) {
+
+ String at;
+ for(int i=0;i<op->arguments.size();i++) {
+ if (i>0)
+ at+=" and ";
+ at+=get_datatype_name(op->arguments[i]->get_datatype());
+
+ }
+ _set_error("Invalid argument to ternary ?: operator: "+at);
+ return NULL;
+ }
+
+ for(int i=0;i<4;i++) {
+ expression.remove(next_op);
+ }
+
} else {
if (next_op <1 || next_op>=(expression.size()-1)) {
- parser.set_error("Parser bug..");
- ERR_FAIL_V(ERR_BUG);
+ _set_error("Parser bug..");
+ ERR_FAIL_V(NULL);
}
- OperatorNode *op = parser.create_node<OperatorNode>(p_parent);
- op->op=get_token_operator(expression[next_op].op);
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op=expression[next_op].op;
if (expression[next_op-1].is_op) {
- parser.set_error("Parser bug..");
- ERR_FAIL_V(ERR_BUG);
+ _set_error("Parser bug..");
+ ERR_FAIL_V(NULL);
}
if (expression[next_op+1].is_op) {
@@ -2071,645 +2486,660 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
// can be followed by an unary op in a valid combination,
// due to how precedence works, unaries will always dissapear first
- parser.set_error("Parser bug..");
+ _set_error("Parser bug..");
}
op->arguments.push_back(expression[next_op-1].node); //expression goes as left
op->arguments.push_back(expression[next_op+1].node); //next expression goes as right
+ expression[next_op-1].node=op;
//replace all 3 nodes by this operator and make it an expression
- expression[next_op-1].node=validate_operator(parser,op);
- if (!expression[next_op-1].node) {
+
+ if (!_validate_operator(op,&op->return_cache)) {
String at;
for(int i=0;i<op->arguments.size();i++) {
if (i>0)
at+=" and ";
- at+=get_datatype_name(compute_node_type(op->arguments[i]));
+ at+=get_datatype_name(op->arguments[i]->get_datatype());
}
- static const char *op_names[OP_MAX]={"=","+","-","*","/","+=","-=","*=","/=","-","!","==","!=","<=",">=","<",">","||","&&","call","()"};
-
- parser.set_error("Invalid arguments to operator "+String(op_names[op->op])+": "+at);
- return ERR_PARSE_ERROR;
+ _set_error("Invalid arguments to operator: "+at);
+ return NULL;
}
+
expression.remove(next_op);
expression.remove(next_op);
}
-#if 0
- OperatorNode *op = parser.create_node<OperatorNode>(p_parent);
- op->op=get_token_operator(operators[next_op]);
+ }
- op->arguments.push_back(expressions[next_op]); //expression goes as left
- op->arguments.push_back(expressions[next_op+1]); //next expression goes as right
+ return expression[0].node;
+}
- expressions[next_op]=validate_operator(parser,op);
- if (!expressions[next_op]) {
- String at;
- for(int i=0;i<op->arguments.size();i++) {
- if (i>0)
- at+=" and ";
- at+=get_datatype_name(compute_node_type(op->arguments[i]));
+ShaderLanguage::Node* ShaderLanguage::_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node) {
- }
- parser.set_error("Invalid arguments to operator "+String(token_names[operators[next_op]])+": "+at);
- return ERR_PARSE_ERROR;
- }
+ if (p_node->type!=Node::TYPE_OPERATOR)
+ return p_node;
+ //for now only reduce simple constructors
+ OperatorNode *op=static_cast<OperatorNode*>(p_node);
- expressions.remove(next_op+1);
- operators.remove(next_op);
-#endif
+ if (op->op==OP_CONSTRUCT) {
- }
+ ERR_FAIL_COND_V(op->arguments[0]->type!=Node::TYPE_VARIABLE,p_node);
+ VariableNode *vn = static_cast<VariableNode*>(op->arguments[0]);
+ StringName name=vn->name;
- *r_expr=expression[0].node;
+ if (name=="vec2" || name=="vec3" || name=="vec4") {
+ Vector<Variant> values;
- return OK;
+ for(int i=1;i<op->arguments.size();i++) {
-/*
- TokenType token_type=parser.get_token_type();
- OperatorNode *op = parser.create_node<OperatorNode>(p_parent);
- op->op=get_token_operator(parser.get_token_type());
+ op->arguments[i]=_reduce_expression(p_block,op->arguments[i]);
+ if (op->arguments[i]->type==Node::TYPE_CONSTANT) {
+ ConstantNode *cn = static_cast<ConstantNode*>(op->arguments[i]);
+ values.push_back(cn->value);
- op->arguments.push_back(*r_expr); //expression goes as left
- parser.advance();
- Node *right_expr=NULL;
- Error err = parse_expression(parser,p_parent,&right_expr);
- if (err)
- return err;
- op->arguments.push_back(right_expr);
+ } else {
+ return p_node; //do not bother, not reducible
+ }
+ }
- if (!validate_operator(op)) {
+ ConstantNode *cn=alloc_node<ConstantNode>();
- parser.set_error("Invalid arguments to operator "+String(token_names[token_type]));
- return ERR_PARSE_ERROR;
+ if (name=="vec2") {
+ cn->datatype=TYPE_VEC2;
+ cn->value=Vector2(values[0],values[1]);
+ } else if (name=="vec3") {
+ cn->datatype=TYPE_VEC3;
+ cn->value=Vector3(values[0],values[1],values[2]);
+ } else if (name=="vec4") {
+ cn->datatype=TYPE_VEC4;
+ cn->value=Plane(values[0],values[1],values[2],values[3]);
+ } else {
+ ERR_FAIL_V(p_node);
}
-*/
+ return cn;
+ }
+ }
+
+
+ return p_node;
+
}
-Error ShaderLanguage::parse_variable_declaration(Parser& parser,BlockNode *p_block) {
- bool uniform = parser.get_token(-1).type==TK_UNIFORM;
+ShaderLanguage::Node* ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName,DataType> &p_builtin_types) {
- DataType type=get_token_datatype(parser.get_token_type(0));
- bool iscolor = parser.get_token_type(0)==TK_TYPE_COLOR;
- if (type==TYPE_VOID) {
+ ShaderLanguage::Node* expr = _parse_expression(p_block,p_builtin_types);
- parser.set_error("Cannot Declare a 'void' Variable");
- return ERR_PARSE_ERROR;
- }
+ expr = _reduce_expression(p_block,expr);
- if (type==TYPE_TEXTURE && !uniform) {
+ return expr;
+}
- parser.set_error("Cannot Declare a Non-Uniform Texture");
- return ERR_PARSE_ERROR;
- }
- if (type==TYPE_CUBEMAP && !uniform) {
- parser.set_error("Cannot Declare a Non-Uniform Cubemap");
- return ERR_PARSE_ERROR;
- }
- parser.advance();
- int found=0;
+Error ShaderLanguage::_parse_block(BlockNode* p_block,const Map<StringName,DataType> &p_builtin_types,bool p_just_one,bool p_can_break,bool p_can_continue) {
while(true) {
+ int pos = char_idx;
- if (found && parser.get_token_type()!=TK_COMMA) {
- break;
- }
+ Token tk = _get_token();
+ if (tk.type==TK_CURLY_BRACKET_CLOSE) { //end of block
+ if (p_just_one) {
+ _set_error("Unexpected '}'");
+ return ERR_PARSE_ERROR;
+ }
- if (parser.get_token_type()!=TK_INDENTIFIER) {
+ return OK;
- parser.set_error("Identifier Expected");
- return ERR_PARSE_ERROR;
+ } else if (is_token_precision(tk.type) || is_token_nonvoid_datatype(tk.type)) {
+ DataPrecision precision=PRECISION_DEFAULT;
+ if (is_token_precision(tk.type)) {
+ precision=get_token_precision(tk.type);
+ tk = _get_token();
+ if (!is_token_nonvoid_datatype(tk.type)) {
+ _set_error("Expected datatype after precission");
+ return ERR_PARSE_ERROR;
+ }
+ }
- }
+ DataType type = get_token_datatype(tk.type);
- StringName name = parser.get_token().text;
+ tk = _get_token();
- if (test_existing_identifier(p_block,name)) {
- parser.set_error("Duplicate Identifier (existing variable/function): "+name);
- return ERR_PARSE_ERROR;
- }
+ while(true) {
- found=true;
+ if (tk.type!=TK_IDENTIFIER) {
+ _set_error("Expected identifier after type");
+ return ERR_PARSE_ERROR;
+ }
- parser.advance();
- //see if declaration has an initializer
- if (parser.get_token_type()==TK_OP_ASSIGN) {
- parser.advance();
- OperatorNode * op = parser.create_node<OperatorNode>(p_block);
- VariableNode * var = parser.create_node<VariableNode>(op);
- var->name=name;
- var->datatype_cache=type;
- var->uniform=uniform;
- Node *expr;
- Error err = parse_expression(parser,p_block,&expr);
+ StringName name = tk.text;
+ if (_find_identifier(p_block,p_builtin_types,name)) {
+ _set_error("Redefinition of '"+String(name)+"'");
+ return ERR_PARSE_ERROR;
+ }
- if (err)
- return err;
+ BlockNode::Variable var;
+ var.type=type;
+ var.precision=precision;
+ p_block->variables[name]=var;
- if (var->uniform) {
+ tk = _get_token();
- if (expr->type!=Node::TYPE_CONSTANT) {
+ if (tk.type==TK_OP_ASSIGN) {
+ //variable creted with assignment! must parse an expression
+ Node* n = _parse_and_reduce_expression(p_block,p_builtin_types);
+ if (!n)
+ return ERR_PARSE_ERROR;
- parser.set_error("Uniform can only be initialized to a constant.");
- return ERR_PARSE_ERROR;
+ OperatorNode *assign = alloc_node<OperatorNode>();
+ VariableNode *vnode = alloc_node<VariableNode>();
+ vnode->name=name;
+ vnode->datatype_cache=type;
+ assign->arguments.push_back(vnode);
+ assign->arguments.push_back(n);
+ assign->op=OP_ASSIGN;
+ p_block->statements.push_back(assign);
+ tk = _get_token();
}
- Uniform u;
- u.order=parser.program->uniforms.size();
- u.type=type;
- u.default_value=static_cast<ConstantNode*>(expr)->value;
- if (iscolor && u.default_value.get_type()==Variant::PLANE) {
- Color c;
- Plane p = u.default_value;
- c=Color(p.normal.x,p.normal.y,p.normal.z,p.d);
- u.default_value=c;
- }
- parser.program->uniforms[var->name]=u;
- } else {
- op->op=OP_ASSIGN;
- op->arguments.push_back(var);
- op->arguments.push_back(expr);
- Node *n=validate_operator(parser,op);
- if (!n) {
- parser.set_error("Invalid initializer for variable: "+name);
+ if (tk.type==TK_COMMA) {
+ tk = _get_token();
+ //another variable
+ } else if (tk.type==TK_SEMICOLON) {
+ break;
+ } else {
+ _set_error("Expected ',' or ';' after variable");
return ERR_PARSE_ERROR;
}
- p_block->statements.push_back(n);
+ }
+ } else if (tk.type==TK_CURLY_BRACKET_OPEN) {
+ //a sub block, just because..
+ BlockNode* block = alloc_node<BlockNode>();
+ block->parent_block=p_block;
+ _parse_block(block,p_builtin_types,false,p_can_break,p_can_continue);
+ } else if (tk.type==TK_CF_IF) {
+ //if () {}
+ tk = _get_token();
+ if (tk.type!=TK_PARENTHESIS_OPEN) {
+ _set_error("Expected '(' after if");
+ return ERR_PARSE_ERROR;
}
- } else {
- //initialize it EMPTY
-
- OperatorNode * op = parser.create_node<OperatorNode>(p_block);
- VariableNode * var = parser.create_node<VariableNode>(op);
- ConstantNode * con = parser.create_node<ConstantNode>(op);
-
- var->name=name;
- var->datatype_cache=type;
- var->uniform=uniform;
- con->datatype=type;
-
- switch(type) {
- case TYPE_BOOL: con->value=false; break;
- case TYPE_FLOAT: con->value=0.0; break;
- case TYPE_VEC2: con->value=Vector2(); break;
- case TYPE_VEC3: con->value=Vector3(); break;
- case TYPE_VEC4: con->value=iscolor?Variant(Color()):Variant(Plane()); break;
- case TYPE_MAT2: con->value=Matrix32(); break;
- case TYPE_MAT3: con->value=Matrix3(); break;
- case TYPE_MAT4: con->value=Transform(); break;
- case TYPE_TEXTURE:
- case TYPE_CUBEMAP: con->value=RID(); break;
- default: {}
+ ControlFlowNode *cf = alloc_node<ControlFlowNode>();
+ cf->flow_op=FLOW_OP_IF;
+ Node* n = _parse_and_reduce_expression(p_block,p_builtin_types);
+ if (!n)
+ return ERR_PARSE_ERROR;
+
+ tk = _get_token();
+ if (tk.type!=TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected '(' after expression");
+ return ERR_PARSE_ERROR;
}
- if (uniform) {
- Uniform u;
- u.type=type;
- u.default_value=con->value;
- u.order=parser.program->uniforms.size();
- parser.program->uniforms[var->name]=u;
+ BlockNode* block = alloc_node<BlockNode>();
+ block->parent_block=p_block;
+ cf->blocks.push_back(block);
+
+
+ Error err=_parse_block(p_block,p_builtin_types,true,p_can_break,p_can_continue);
+
+ pos=char_idx;
+ tk = _get_token();
+ if (tk.type==TK_CF_ELSE) {
+
+ block = alloc_node<BlockNode>();
+ block->parent_block=p_block;
+ cf->blocks.push_back(block);
+ err=_parse_block(p_block,p_builtin_types,true,p_can_break,p_can_continue);
} else {
- op->op=OP_ASSIGN;
- op->arguments.push_back(var);
- op->arguments.push_back(con);
- p_block->statements.push_back(op);
+ char_idx=pos; //rollback
}
- }
+ } else {
- if (!uniform)
- p_block->variables[name]=type;
+ //nothng else, so expression
+ char_idx=pos; //rollback
+ _parse_and_reduce_expression(p_block,p_builtin_types);
+ tk = _get_token();
- }
+ if (tk.type!=TK_SEMICOLON) {
+ _set_error("Expected ';' after statement");
+ return ERR_PARSE_ERROR;
+ }
+ }
- if (parser.get_token_type()!=TK_SEMICOLON) {
- parser.set_error("Expected ';'");
- return ERR_PARSE_ERROR;
+ if (p_just_one)
+ break;
}
-
return OK;
-
}
-Error ShaderLanguage::parse_flow_if(Parser& parser,Node *p_parent,Node **r_statement) {
- ControlFlowNode *cf = parser.create_node<ControlFlowNode>(p_parent);
+Error ShaderLanguage::_parse_shader(const Map< StringName, Map<StringName,DataType> > &p_functions, const Set<String> &p_render_modes) {
- cf->flow_op=FLOW_OP_IF;
- parser.advance();
+ Token tk = _get_token();
- if (parser.get_token_type()!=TK_PARENTHESIS_OPEN) {
- parser.set_error("Expected '(' after 'if'");
- return ERR_PARSE_ERROR;
- }
- parser.advance();
+ while(tk.type!=TK_EOF) {
- Node *expression=NULL;
- Error err = parse_expression(parser,cf,&expression);
- if (err)
- return err;
+ switch(tk.type) {
+ case TK_RENDER_MODE: {
- if (compute_node_type(expression)!=TYPE_BOOL) {
+ while(true) {
+ tk = _get_token();
+ if (tk.type!=TK_IDENTIFIER) {
+ _set_error("Expected identifier for render mode");
+ return ERR_PARSE_ERROR;
+ }
- parser.set_error("Expression for 'if' is not boolean");
- return ERR_PARSE_ERROR;
- }
+ if (!p_render_modes.has(tk.text)) {
+ _set_error("Invalid render mode: '"+String(tk.text)+"'");
+ return ERR_PARSE_ERROR;
+ }
- cf->statements.push_back(expression);
+ if (shader->render_modes.has(tk.text)) {
+ _set_error("Duplicate render mode: '"+String(tk.text)+"'");
+ return ERR_PARSE_ERROR;
+ }
- if (parser.get_token_type()!=TK_PARENTHESIS_CLOSE) {
- parser.set_error("Expected ')' after expression");
- return ERR_PARSE_ERROR;
- }
+ shader->render_modes.insert(tk.text);
- parser.advance();
+ tk = _get_token();
+ if (tk.type==TK_COMMA) {
+ //all good, do nothing
+ } else if (tk.type==TK_SEMICOLON) {
+ break; //done
+ } else {
+ _set_error("Unexpected token: "+get_token_text(tk));
+ return ERR_PARSE_ERROR;
+ }
+ }
+ } break;
+ case TK_UNIFORM:
+ case TK_VARYING: {
+
+ bool uniform = tk.type==TK_UNIFORM;
+ DataPrecision precision = PRECISION_DEFAULT;
+ DataType type;
+ StringName name;
+
+ tk = _get_token();
+ if (is_token_precision(tk.type)) {
+ precision=get_token_precision(tk.type);
+ tk = _get_token();
+ }
- if (parser.get_token_type()!=TK_CURLY_BRACKET_OPEN) {
- parser.set_error("Expected statement block after 'if()'");
- return ERR_PARSE_ERROR;
- }
+ if (!is_token_datatype(tk.type)) {
+ _set_error("Expected datatype. ");
+ return ERR_PARSE_ERROR;
+ }
- Node *substatement=NULL;
- err = parse_statement(parser,cf,&substatement);
- if (err)
- return err;
+ type = get_token_datatype(tk.type);
- cf->statements.push_back(substatement);
+ if (type==TYPE_VOID) {
+ _set_error("void datatype not allowed here");
+ return ERR_PARSE_ERROR;
+ }
+ if (!uniform && type<TYPE_FLOAT && type>TYPE_VEC4) {
+ _set_error("Invalid type for varying, only float,vec2,vec3,vec4 allowed.");
+ return ERR_PARSE_ERROR;
+ }
- if (parser.get_token_type()==TK_CF_ELSE) {
+ tk = _get_token();
+ if (tk.type!=TK_IDENTIFIER) {
+ _set_error("Expected identifier!");
+ return ERR_PARSE_ERROR;
+ }
- parser.advance();
+ name=tk.text;
- if (parser.get_token_type()!=TK_CURLY_BRACKET_OPEN) {
- parser.set_error("Expected statement block after 'else'");
- return ERR_PARSE_ERROR;
- }
+ if (_find_identifier(NULL,Map<StringName,DataType>(),name)) {
+ _set_error("Redefinition of '"+String(name)+"'");
+ return ERR_PARSE_ERROR;
+ }
- substatement=NULL;
- err = parse_statement(parser,cf,&substatement);
- if (err)
- return err;
+ if (uniform) {
- cf->statements.push_back(substatement);
- }
+ ShaderNode::Uniform uniform;
+ uniform.order=shader->uniforms.size();
+ uniform.type=type;
+ uniform.precission=precision;
+ shader->uniforms[name]=uniform;
+ //todo parse default value
+ tk = _get_token();
+ if (tk.type==TK_OP_ASSIGN) {
- *r_statement=cf;
+ Node* expr = _parse_and_reduce_expression(NULL,Map<StringName,DataType>());
+ if (!expr)
+ return ERR_PARSE_ERROR;
+ if (expr->type!=Node::TYPE_CONSTANT) {
+ _set_error("Expected constant expression after '='");
+ return ERR_PARSE_ERROR;
+ }
- return OK;
-}
+ uniform.default_value=static_cast<ConstantNode*>(expr)->value;
+ tk = _get_token();
+ }
-Error ShaderLanguage::parse_flow_return(Parser& parser,Node *p_parent,Node **r_statement) {
+ if (tk.type==TK_COLON) {
+ //hint
+ tk = _get_token();
+ if (tk.type==TK_HINT_WHITE_TEXTURE) {
+ uniform.hint=ShaderNode::Uniform::HINT_WHITE_TEXTURE;
+ } else if (tk.type==TK_HINT_BLACK_TEXTURE) {
+ uniform.hint=ShaderNode::Uniform::HINT_BLACK_TEXTURE;
+ } else if (tk.type==TK_HINT_NORMAL_TEXTURE) {
+ uniform.hint=ShaderNode::Uniform::HINT_NORMAL_TEXTURE;
+ } else if (tk.type==TK_HINT_RANGE) {
+ uniform.hint=ShaderNode::Uniform::HINT_RANGE;
+ if (type!=TYPE_FLOAT && type!=TYPE_INT) {
+ _set_error("Range hint is for float and int only");
+ return ERR_PARSE_ERROR;
+ }
- FunctionNode *function=NULL;
+ tk = _get_token();
+ if (tk.type!=TK_PARENTHESIS_OPEN) {
+ _set_error("Expected '(' after hint_range");
+ return ERR_PARSE_ERROR;
+ }
- Node *parent=p_parent;
+ tk = _get_token();
- while(parent) {
+ if (tk.type!=TK_REAL_CONSTANT ||tk.type!=TK_INT_CONSTANT) {
+ _set_error("Expected integer constant");
+ return ERR_PARSE_ERROR;
+ }
- if (parent->type==Node::TYPE_FUNCTION) {
+ uniform.hint_range[0]=tk.constant;
- function=(FunctionNode*)parent;
- break;
- }
+ tk = _get_token();
- parent=parent->parent;
- }
+ if (tk.type!=TK_COMMA) {
+ _set_error("Expected ',' after integer constant");
+ return ERR_PARSE_ERROR;
+ }
- if (!function) {
+ tk = _get_token();
- parser.set_error("'return' must be inside a function");
- return ERR_PARSE_ERROR;
- }
+ if (tk.type!=TK_REAL_CONSTANT || tk.type!=TK_INT_CONSTANT) {
+ _set_error("Expected integer constant after ','");
+ return ERR_PARSE_ERROR;
+ }
- ControlFlowNode *cf = parser.create_node<ControlFlowNode>(p_parent);
+ uniform.hint_range[1]=tk.constant;
- cf->flow_op=FLOW_OP_RETURN;
+ tk = _get_token();
- parser.advance();
+ if (tk.type==TK_COMMA) {
+ tk = _get_token();
- if (function->return_type!=TYPE_VOID) {
- // should expect a return expression.
+ if (tk.type!=TK_REAL_CONSTANT || tk.type!=TK_INT_CONSTANT) {
+ _set_error("Expected integer constant after ','");
+ return ERR_PARSE_ERROR;
+ }
- Node *expr=NULL;
- Error err = parse_expression(parser,cf,&expr);
- if (err)
- return err;
+ uniform.hint_range[2]=tk.constant;
+ tk = _get_token();
+ } else {
+ if (type==TYPE_INT) {
+ uniform.hint_range[2]=1;
+ } else {
+ uniform.hint_range[2]=0.001;
+ }
+ }
- if (compute_node_type(expr)!=function->return_type) {
- parser.set_error("Invalid type for 'return' expression");
- return ERR_PARSE_ERROR;
- }
- cf->statements.push_back(expr);
- }
+ if (tk.type!=TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ','");
+ return ERR_PARSE_ERROR;
+ }
- *r_statement=cf;
+ }
- if (parser.get_token_type()!=TK_SEMICOLON) {
- parser.set_error("Expected ';'");
- return ERR_PARSE_ERROR;
- }
+ if (uniform.hint!=ShaderNode::Uniform::HINT_RANGE && uniform.hint!=ShaderNode::Uniform::HINT_NONE && type <=TYPE_MAT4) {
+ _set_error("This hint is only for sampler types");
+ return ERR_PARSE_ERROR;
- return OK;
-}
+ }
-Error ShaderLanguage::parse_statement(Parser& parser,Node *p_parent,Node **r_statement) {
- *r_statement=NULL;
+ }
- TokenType token_type = parser.get_token_type();
+ if (tk.type!=TK_SEMICOLON) {
+ _set_error("Expected ';'");
+ return ERR_PARSE_ERROR;
+ }
+ } else {
- if (token_type==TK_CURLY_BRACKET_OPEN) {
- //sub-block
- parser.advance();
- BlockNode *block = parser.create_node<BlockNode>(p_parent);
+ ShaderNode::Varying varying;
+ varying.type=type;
+ varying.precission=precision;
+ shader->varyings[name]=varying;
- *r_statement=block;
- return parse_block(parser,block);
- } else if (token_type==TK_SEMICOLON) {
- // empty ;
- parser.advance();
- return OK;
- } else if (token_type==TK_CF_IF) {
- return parse_flow_if(parser,p_parent,r_statement);
+ tk = _get_token();
+ if (tk.type!=TK_SEMICOLON) {
+ _set_error("Expected ';'");
+ return ERR_PARSE_ERROR;
+ }
- } else if (token_type==TK_CF_RETURN) {
- return parse_flow_return(parser,p_parent,r_statement);
- } else {
- Error err=parse_expression(parser,p_parent,r_statement);
+ }
- if (err)
- return err;
- if (parser.get_token_type()!=TK_SEMICOLON) {
- parser.set_error("Expected ';'");
- return ERR_PARSE_ERROR;
- }
- }
+ } break;
+ default: {
+ //function
- return OK;
-}
+ DataPrecision precision = PRECISION_DEFAULT;
+ DataType type;
+ StringName name;
-Error ShaderLanguage::parse_block(Parser& parser,BlockNode *p_block) {
+ if (is_token_precision(tk.type)) {
+ precision=get_token_precision(tk.type);
+ tk = _get_token();
+ }
- while(true) {
+ if (!is_token_datatype(tk.type)) {
+ _set_error("Expected funtion, uniform or varying ");
+ return ERR_PARSE_ERROR;
+ }
- if (parser.is_at_end()) {
- if (p_block->parent->type!=Node::TYPE_PROGRAM) {
- parser.set_error("Unexpected End of File");
- return ERR_PARSE_ERROR;
- }
- return OK; //bye
- }
+ type = get_token_datatype(tk.type);
- TokenType token_type = parser.get_token_type();
- if (token_type==TK_CURLY_BRACKET_CLOSE) {
- if (p_block->parent->type==Node::TYPE_PROGRAM) {
- parser.set_error("Unexpected '}'");
- return ERR_PARSE_ERROR;
- }
- parser.advance();
- return OK; // exit block
+ tk = _get_token();
+ if (tk.type!=TK_IDENTIFIER) {
+ _set_error("Expected function name after datatype");
+ return ERR_PARSE_ERROR;
- } else if (token_type==TK_UNIFORM) {
+ }
- if (p_block!=parser.program->body) {
+ name=tk.text;
- parser.set_error("Uniform only allowed in main program body.");
- return ERR_PARSE_ERROR;
- }
- parser.advance();
- Error err=parse_variable_declaration(parser,p_block);
- if (err)
- return err;
-
- } else if (is_token_datatype(token_type)) {
-
- Error err=OK;
- if (parser_is_at_function(parser))
- err = parse_function(parser,p_block);
- else {
- err = parse_variable_declaration(parser,p_block);
- }
+ if (_find_identifier(NULL,Map<StringName,DataType>(),name)) {
+ _set_error("Redefinition of '"+String(name)+"'");
+ return ERR_PARSE_ERROR;
+ }
- if (err)
- return err;
+ tk = _get_token();
+ if (tk.type!=TK_PARENTHESIS_OPEN) {
+ _set_error("Expected '(' after identifier");
+ return ERR_PARSE_ERROR;
- } else {
- // must be a statement
- Node *statement=NULL;
-
- Error err = parse_statement(parser,p_block,&statement);
- if (err)
- return err;
- if (statement) {
- p_block->statements.push_back(statement);
- }
+ }
- }
- }
- return OK;
-}
+ Map<StringName,DataType> builtin_types;
+ if (p_functions.has(name)) {
+ builtin_types=p_functions[name];
+ }
+ ShaderNode::Function function;
+ function.callable=!p_functions.has(name);
+ function.name=name;
-Error ShaderLanguage::parse(const Vector<Token>& p_tokens,ShaderType p_type,CompileFunc p_compile_func,void *p_userdata,String *r_error,int *r_err_line,int *r_err_column) {
+ FunctionNode* func_node=alloc_node<FunctionNode>();
+ function.function=func_node;
- Parser parser(p_tokens);
- parser.program = parser.create_node<ProgramNode>(NULL);
- parser.program->body = parser.create_node<BlockNode>(parser.program);
+ shader->functions.push_back(function);
+ func_node->name=name;
+ func_node->return_type=type;
+ func_node->return_precision=precision;
- //add builtins
- switch(p_type) {
- case SHADER_MATERIAL_VERTEX: {
- int idx=0;
- while (vertex_builtins_defs[idx].name) {
- parser.program->builtin_variables[vertex_builtins_defs[idx].name]=vertex_builtins_defs[idx].type;
- idx++;
- }
- } break;
- case SHADER_MATERIAL_FRAGMENT: {
- int idx=0;
- while (fragment_builtins_defs[idx].name) {
- parser.program->builtin_variables[fragment_builtins_defs[idx].name]=fragment_builtins_defs[idx].type;
- idx++;
- }
- } break;
- case SHADER_MATERIAL_LIGHT: {
- int idx=0;
- while (light_builtins_defs[idx].name) {
- parser.program->builtin_variables[light_builtins_defs[idx].name]=light_builtins_defs[idx].type;
- idx++;
- }
- } break;
- case SHADER_CANVAS_ITEM_VERTEX: {
- int idx=0;
- while (ci_vertex_builtins_defs[idx].name) {
- parser.program->builtin_variables[ci_vertex_builtins_defs[idx].name]=ci_vertex_builtins_defs[idx].type;
- idx++;
- }
- } break;
- case SHADER_CANVAS_ITEM_FRAGMENT: {
- int idx=0;
- while (ci_fragment_builtins_defs[idx].name) {
- parser.program->builtin_variables[ci_fragment_builtins_defs[idx].name]=ci_fragment_builtins_defs[idx].type;
- idx++;
- }
- } break;
- case SHADER_CANVAS_ITEM_LIGHT: {
- int idx=0;
- while (ci_light_builtins_defs[idx].name) {
- parser.program->builtin_variables[ci_light_builtins_defs[idx].name]=ci_light_builtins_defs[idx].type;
- idx++;
- }
- } break;
- case SHADER_POST_PROCESS: {
- int idx=0;
- while (postprocess_fragment_builtins_defs[idx].name) {
- parser.program->builtin_variables[postprocess_fragment_builtins_defs[idx].name]=postprocess_fragment_builtins_defs[idx].type;
- idx++;
- }
- } break;
- }
+ func_node->body = alloc_node<BlockNode>();
+ func_node->body->parent_function=func_node;
- Error err = parse_block(parser,parser.program->body);
- if (err) {
- parser.get_error(r_error,r_err_line,r_err_column);
- return err;
- }
- if (p_compile_func) {
- err = p_compile_func(p_userdata,parser.program);
- }
+ tk = _get_token();
- //clean up nodes created
- while(parser.nodegc.size()) {
+ while(true) {
+ if (tk.type==TK_PARENTHESIS_CLOSE) {
+ break;
+ }
- memdelete( parser.nodegc.front()->get() );
- parser.nodegc.pop_front();
- }
- return err;
-}
+ DataType ptype;
+ StringName pname;
+ DataPrecision pprecision = PRECISION_DEFAULT;
-Error ShaderLanguage::compile(const String& p_code,ShaderType p_type,CompileFunc p_compile_func,void *p_userdata,String *r_error,int *r_err_line,int *r_err_column) {
+ if (is_token_precision(tk.type)) {
+ pprecision=get_token_precision(tk.type);
+ tk = _get_token();
+ }
- *r_error="";
- *r_err_line=0;
- *r_err_column=0;
- Vector<Token> tokens;
+ if (!is_token_datatype(tk.type)) {
+ _set_error("Expected a valid datatype for argument");
+ return ERR_PARSE_ERROR;
+ }
- Error err = tokenize(p_code,&tokens,r_error,r_err_line,r_err_column);
- if (err!=OK) {
- print_line("tokenizer error!");
- }
+ ptype=get_token_datatype(tk.type);
- if (err!=OK) {
- return err;
- }
- err = parse(tokens,p_type,p_compile_func,p_userdata,r_error,r_err_line,r_err_column);
- if (err!=OK) {
- return err;
+ if (ptype==TYPE_VOID) {
+ _set_error("void not allowed in argument");
+ return ERR_PARSE_ERROR;
+ }
+
+ tk = _get_token();
+
+ if (tk.type!=TK_IDENTIFIER) {
+ _set_error("Expected identifier for argument name");
+ return ERR_PARSE_ERROR;
+ }
+
+ pname = tk.text;
+
+ if (_find_identifier(func_node->body,builtin_types,pname)) {
+ _set_error("Redefinition of '"+String(pname)+"'");
+ return ERR_PARSE_ERROR;
+ }
+ FunctionNode::Argument arg;
+ arg.type=ptype;
+ arg.name=pname;
+ arg.precision=pprecision;
+
+ func_node->arguments.push_back(arg);
+
+ tk = _get_token();
+
+
+ if (tk.type==TK_COMMA) {
+ tk = _get_token();
+ //do none and go on
+ } else if (tk.type!=TK_PARENTHESIS_CLOSE) {
+ _set_error("Expected ',' or ')' after identifier");
+ return ERR_PARSE_ERROR;
+ }
+
+ }
+
+ if (p_functions.has(name)) {
+ //if one of the core functions, make sure they are of the correct form
+ if (func_node->arguments.size() > 0) {
+ _set_error("Function '"+String(name)+"' expects no arguments.");
+ return ERR_PARSE_ERROR;
+ }
+ if (func_node->return_type!=TYPE_VOID) {
+ _set_error("Function '"+String(name)+"' must be of void return type.");
+ return ERR_PARSE_ERROR;
+ }
+ }
+
+
+ //all good let's parse inside the fucntion!
+ tk = _get_token();
+ if (tk.type!=TK_CURLY_BRACKET_OPEN) {
+ _set_error("Expected '{' to begin function");
+ return ERR_PARSE_ERROR;
+ }
+
+ Error err = _parse_block(func_node->body,builtin_types);
+ if (err)
+ return err;
+ }
+ }
+
+ tk = _get_token();
}
+
return OK;
}
+Error ShaderLanguage::compile(const String& p_code, const Map< StringName, Map<StringName,DataType> > &p_functions, const Set<String> &p_render_modes) {
+
+ clear();
-void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keywords) {
+ code=p_code;
- int idx=0;
+ nodes=NULL;
- p_keywords->push_back("uniform");
- p_keywords->push_back("texture");
- p_keywords->push_back("cubemap");
- p_keywords->push_back("color");
- p_keywords->push_back("if");
- p_keywords->push_back("else");
- while(intrinsic_func_defs[idx].name) {
+ shader = alloc_node<ShaderNode>();
+ Error err = _parse_shader(p_functions,p_render_modes);
- p_keywords->push_back(intrinsic_func_defs[idx].name);
- idx++;
+ if (err!=OK) {
+ return err;
}
+ return OK;
+}
+String ShaderLanguage::get_error_text() {
+ return error_str;
+}
- switch(p_type) {
- case SHADER_MATERIAL_VERTEX: {
- idx=0;
- while (vertex_builtins_defs[idx].name) {
- p_keywords->push_back(vertex_builtins_defs[idx].name);
- idx++;
- }
- } break;
- case SHADER_MATERIAL_FRAGMENT: {
- idx=0;
- while (fragment_builtins_defs[idx].name) {
- p_keywords->push_back(fragment_builtins_defs[idx].name);
- idx++;
- }
- } break;
- case SHADER_MATERIAL_LIGHT: {
- idx=0;
- while (light_builtins_defs[idx].name) {
- p_keywords->push_back(light_builtins_defs[idx].name);
- idx++;
- }
- } break;
- case SHADER_CANVAS_ITEM_VERTEX: {
- idx=0;
- while (ci_vertex_builtins_defs[idx].name) {
- p_keywords->push_back(ci_vertex_builtins_defs[idx].name);
- idx++;
- }
- } break;
- case SHADER_CANVAS_ITEM_FRAGMENT: {
- idx=0;
- while (ci_fragment_builtins_defs[idx].name) {
- p_keywords->push_back(ci_fragment_builtins_defs[idx].name);
- idx++;
- }
- } break;
- case SHADER_CANVAS_ITEM_LIGHT: {
- idx=0;
- while (ci_light_builtins_defs[idx].name) {
- p_keywords->push_back(ci_light_builtins_defs[idx].name);
- idx++;
- }
- } break;
+int ShaderLanguage::get_error_line() {
- case SHADER_POST_PROCESS: {
- idx=0;
- while (postprocess_fragment_builtins_defs[idx].name) {
- p_keywords->push_back(postprocess_fragment_builtins_defs[idx].name);
- idx++;
- }
- } break;
+ return error_line;
+}
- }
+ShaderLanguage::ShaderLanguage() {
+ nodes=NULL;
}
+
+ShaderLanguage::~ShaderLanguage() {
+
+ clear();
+}
+
+
diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h
index 31e9fcda5b..b37853c77e 100644
--- a/servers/visual/shader_language.h
+++ b/servers/visual/shader_language.h
@@ -46,12 +46,24 @@ public:
enum TokenType {
TK_EMPTY,
- TK_INDENTIFIER,
+ TK_IDENTIFIER,
TK_TRUE,
TK_FALSE,
TK_REAL_CONSTANT,
+ TK_INT_CONSTANT,
TK_TYPE_VOID,
TK_TYPE_BOOL,
+ TK_TYPE_BVEC2,
+ TK_TYPE_BVEC3,
+ TK_TYPE_BVEC4,
+ TK_TYPE_INT,
+ TK_TYPE_IVEC2,
+ TK_TYPE_IVEC3,
+ TK_TYPE_IVEC4,
+ TK_TYPE_UINT,
+ TK_TYPE_UVEC2,
+ TK_TYPE_UVEC3,
+ TK_TYPE_UVEC4,
TK_TYPE_FLOAT,
TK_TYPE_VEC2,
TK_TYPE_VEC3,
@@ -59,9 +71,13 @@ public:
TK_TYPE_MAT2,
TK_TYPE_MAT3,
TK_TYPE_MAT4,
- TK_TYPE_TEXTURE,
- TK_TYPE_CUBEMAP,
- TK_TYPE_COLOR,
+ TK_TYPE_SAMPLER2D,
+ TK_TYPE_ISAMPLER2D,
+ TK_TYPE_USAMPLER2D,
+ TK_TYPE_SAMPLERCUBE,
+ TK_PRECISION_LOW,
+ TK_PRECISION_MID,
+ TK_PRECISION_HIGH,
TK_OP_EQUAL,
TK_OP_NOT_EQUAL,
TK_OP_LESS,
@@ -75,14 +91,35 @@ public:
TK_OP_SUB,
TK_OP_MUL,
TK_OP_DIV,
- TK_OP_NEG,
+ TK_OP_MOD,
+ TK_OP_SHIFT_LEFT,
+ TK_OP_SHIFT_RIGHT,
TK_OP_ASSIGN,
TK_OP_ASSIGN_ADD,
TK_OP_ASSIGN_SUB,
TK_OP_ASSIGN_MUL,
TK_OP_ASSIGN_DIV,
+ TK_OP_ASSIGN_MOD,
+ TK_OP_ASSIGN_SHIFT_LEFT,
+ TK_OP_ASSIGN_SHIFT_RIGHT,
+ TK_OP_ASSIGN_BIT_AND,
+ TK_OP_ASSIGN_BIT_OR,
+ TK_OP_ASSIGN_BIT_XOR,
+ TK_OP_BIT_AND,
+ TK_OP_BIT_OR,
+ TK_OP_BIT_XOR,
+ TK_OP_BIT_INVERT,
+ TK_OP_INCREMENT,
+ TK_OP_DECREMENT,
TK_CF_IF,
TK_CF_ELSE,
+ TK_CF_FOR,
+ TK_CF_WHILE,
+ TK_CF_DO,
+ TK_CF_SWITCH,
+ TK_CF_CASE,
+ TK_CF_BREAK,
+ TK_CF_CONTINUE,
TK_CF_RETURN,
TK_BRACKET_OPEN,
TK_BRACKET_CLOSE,
@@ -90,31 +127,39 @@ public:
TK_CURLY_BRACKET_CLOSE,
TK_PARENTHESIS_OPEN,
TK_PARENTHESIS_CLOSE,
+ TK_QUESTION,
TK_COMMA,
+ TK_COLON,
TK_SEMICOLON,
TK_PERIOD,
TK_UNIFORM,
+ TK_VARYING,
+ TK_RENDER_MODE,
+ TK_HINT_WHITE_TEXTURE,
+ TK_HINT_BLACK_TEXTURE,
+ TK_HINT_NORMAL_TEXTURE,
+ TK_HINT_RANGE,
TK_ERROR,
+ TK_EOF,
TK_MAX
};
-
-
/* COMPILER */
- enum ShaderType {
- SHADER_MATERIAL_VERTEX,
- SHADER_MATERIAL_FRAGMENT,
- SHADER_MATERIAL_LIGHT,
- SHADER_CANVAS_ITEM_VERTEX,
- SHADER_CANVAS_ITEM_FRAGMENT,
- SHADER_CANVAS_ITEM_LIGHT,
- SHADER_POST_PROCESS,
- };
-
enum DataType {
TYPE_VOID,
TYPE_BOOL,
+ TYPE_BVEC2,
+ TYPE_BVEC3,
+ TYPE_BVEC4,
+ TYPE_INT,
+ TYPE_IVEC2,
+ TYPE_IVEC3,
+ TYPE_IVEC4,
+ TYPE_UINT,
+ TYPE_UVEC2,
+ TYPE_UVEC3,
+ TYPE_UVEC4,
TYPE_FLOAT,
TYPE_VEC2,
TYPE_VEC3,
@@ -122,30 +167,58 @@ public:
TYPE_MAT2,
TYPE_MAT3,
TYPE_MAT4,
- TYPE_TEXTURE,
- TYPE_CUBEMAP,
+ TYPE_SAMPLER2D,
+ TYPE_ISAMPLER2D,
+ TYPE_USAMPLER2D,
+ TYPE_SAMPLERCUBE,
+ };
+
+ enum DataPrecision {
+ PRECISION_LOWP,
+ PRECISION_MEDIUMP,
+ PRECISION_HIGHP,
+ PRECISION_DEFAULT,
};
enum Operator {
- OP_ASSIGN,
+ OP_EQUAL,
+ OP_NOT_EQUAL,
+ OP_LESS,
+ OP_LESS_EQUAL,
+ OP_GREATER,
+ OP_GREATER_EQUAL,
+ OP_AND,
+ OP_OR,
+ OP_NOT,
+ OP_NEGATE,
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
+ OP_MOD,
+ OP_SHIFT_LEFT,
+ OP_SHIFT_RIGHT,
+ OP_ASSIGN,
OP_ASSIGN_ADD,
OP_ASSIGN_SUB,
OP_ASSIGN_MUL,
OP_ASSIGN_DIV,
- OP_NEG,
- OP_NOT,
- OP_CMP_EQ,
- OP_CMP_NEQ,
- OP_CMP_LEQ,
- OP_CMP_GEQ,
- OP_CMP_LESS,
- OP_CMP_GREATER,
- OP_CMP_OR,
- OP_CMP_AND,
+ OP_ASSIGN_MOD,
+ OP_ASSIGN_SHIFT_LEFT,
+ OP_ASSIGN_SHIFT_RIGHT,
+ OP_ASSIGN_BIT_AND,
+ OP_ASSIGN_BIT_OR,
+ OP_ASSIGN_BIT_XOR,
+ OP_BIT_AND,
+ OP_BIT_OR,
+ OP_BIT_XOR,
+ OP_BIT_INVERT,
+ OP_INCREMENT,
+ OP_DECREMENT,
+ OP_SELECT_IF,
+ OP_SELECT_ELSE, //used only internally, then only IF appears with 3 arguments
+ OP_POST_INCREMENT,
+ OP_POST_DECREMENT,
OP_CALL,
OP_CONSTRUCT,
OP_MAX
@@ -154,18 +227,21 @@ public:
enum FlowOperation {
FLOW_OP_IF,
FLOW_OP_RETURN,
- //FLOW_OP_FOR,
- //FLOW_OP_WHILE,
- //FLOW_OP_DO,
- //FLOW_OP_BREAK,
- //FLOW_OP_CONTINUE,
+ FLOW_OP_FOR,
+ FLOW_OP_WHILE,
+ FLOW_OP_DO,
+ FLOW_OP_BREAK,
+ FLOW_OP_SWITCH,
+ FLOW_OP_CONTINUE
};
struct Node {
+ Node *next;
+
enum Type {
- TYPE_PROGRAM,
+ TYPE_SHADER,
TYPE_FUNCTION,
TYPE_BLOCK,
TYPE_VARIABLE,
@@ -175,7 +251,6 @@ public:
TYPE_MEMBER
};
- Node * parent;
Type type;
virtual DataType get_datatype() const { return TYPE_VOID; }
@@ -183,24 +258,34 @@ public:
virtual ~Node() {}
};
+ template<class T>
+ T* alloc_node() {
+ T* node = memnew(T);
+ node->next=nodes;
+ nodes=node;
+ return node;
+ }
+
+ Node *nodes;
+
struct OperatorNode : public Node {
DataType return_cache;
+ DataPrecision return_precision_cache;
Operator op;
Vector<Node*> arguments;
virtual DataType get_datatype() const { return return_cache; }
- OperatorNode() { type=TYPE_OPERATOR; return_cache=TYPE_VOID; }
+ OperatorNode() { type=TYPE_OPERATOR; return_cache=TYPE_VOID; return_precision_cache=PRECISION_DEFAULT; }
};
struct VariableNode : public Node {
- bool uniform;
DataType datatype_cache;
StringName name;
virtual DataType get_datatype() const { return datatype_cache; }
- VariableNode() { type=TYPE_VARIABLE; datatype_cache=TYPE_VOID; uniform=false; }
+ VariableNode() { type=TYPE_VARIABLE; datatype_cache=TYPE_VOID; }
};
struct ConstantNode : public Node {
@@ -212,17 +297,26 @@ public:
ConstantNode() { type=TYPE_CONSTANT; }
};
+ struct FunctionNode;
+
struct BlockNode : public Node {
+ FunctionNode *parent_function;
+ BlockNode *parent_block;
- Map<StringName,DataType> variables;
+ struct Variable {
+ DataType type;
+ DataPrecision precision;
+ };
+
+ Map<StringName,Variable> variables;
List<Node*> statements;
- BlockNode() { type=TYPE_BLOCK; }
+ BlockNode() { type=TYPE_BLOCK; parent_block=NULL; parent_function=NULL; }
};
struct ControlFlowNode : public Node {
FlowOperation flow_op;
- Vector<Node*> statements;
+ Vector<BlockNode*> blocks;
ControlFlowNode() { type=TYPE_CONTROL_FLOW; flow_op=FLOW_OP_IF;}
};
@@ -244,39 +338,60 @@ public:
StringName name;
DataType type;
+ DataPrecision precision;
};
StringName name;
DataType return_type;
+ DataPrecision return_precision;
Vector<Argument> arguments;
BlockNode *body;
- FunctionNode() { type=TYPE_FUNCTION; }
+ FunctionNode() { type=TYPE_FUNCTION; return_precision=PRECISION_DEFAULT; }
};
- struct Uniform {
-
- int order;
- DataType type;
- Variant default_value;
- };
- struct ProgramNode : public Node {
+ struct ShaderNode : public Node {
struct Function {
StringName name;
FunctionNode*function;
+ bool callable;
+ };
+
+ struct Varying {
+ DataType type;
+ DataPrecision precission;
+ };
+
+ struct Uniform {
+ enum Hint {
+ HINT_NONE,
+ HINT_WHITE_TEXTURE,
+ HINT_BLACK_TEXTURE,
+ HINT_NORMAL_TEXTURE,
+ HINT_RANGE,
+ };
+
+ int order;
+ DataType type;
+ DataPrecision precission;
+ Variant default_value;
+ Hint hint;
+ float hint_range[3];
+
+ Uniform() { hint=HINT_NONE; hint_range[0]=0; hint_range[1]=1; hint_range[2]=0.001;}
};
- Map<StringName,DataType> builtin_variables;
+ Map<StringName,Varying> varyings;
Map<StringName,Uniform> uniforms;
+ Set<StringName> render_modes;
Vector<Function> functions;
- BlockNode *body;
- ProgramNode() { type=TYPE_PROGRAM; }
+ ShaderNode() { type=TYPE_SHADER; }
};
@@ -284,12 +399,12 @@ public:
bool is_op;
union {
- TokenType op;
+ Operator op;
Node *node;
};
};
- typedef Error (*CompileFunc)(void*,ProgramNode*);
+
struct VarInfo {
@@ -297,59 +412,78 @@ public:
DataType type;
};
-private:
-
-
-
- static const char * token_names[TK_MAX];
+ enum CompletionType {
+ COMPLETION_NONE,
+ COMPLETION_BUILT_IN_TYPE_CONSTANT,
+ COMPLETION_FUNCTION,
+ COMPLETION_IDENTIFIER,
+ COMPLETION_PARENT_FUNCTION,
+ COMPLETION_METHOD,
+ COMPLETION_CALL_ARGUMENTS,
+ COMPLETION_INDEX,
+ COMPLETION_VIRTUAL_FUNC,
+ COMPLETION_YIELD,
+ };
struct Token {
TokenType type;
StringName text;
- uint16_t line,col;
-
- Token(TokenType p_type=TK_EMPTY,const String& p_text=String()) { type=p_type; text=p_text; line=0; col=0; }
+ double constant;
+ uint16_t line;
};
+ static String get_token_text(Token p_token);
+ static bool is_token_datatype(TokenType p_type);
+ static DataType get_token_datatype(TokenType p_type);
+ static bool is_token_precision(TokenType p_type);
+ static DataPrecision get_token_precision(TokenType p_type);
+ static String get_datatype_name(DataType p_type);
+ static bool is_token_nonvoid_datatype(TokenType p_type);
+ static bool is_token_operator(TokenType p_type);
+
+private:
+ bool error_set;
+ String error_str;
+ int error_line;
- static Token read_token(const CharType* p_text,int p_len,int &r_line,int &r_chars);
- static Error tokenize(const String& p_text,Vector<Token> *p_tokens,String *r_error,int *r_err_line,int *r_err_column);
+ String code;
+ int char_idx;
+ int tk_line;
+ void _set_error(const String& p_str) {
+ if (error_set)
+ return;
+ error_set=true;
+ error_str=p_str;
+ }
- class Parser {
+ static const char * token_names[TK_MAX];
- Vector<Token> tokens;
- int pos;
- String error;
- public:
- void set_error(const String& p_error) { error=p_error; }
- void get_error(String *r_error, int *r_line, int *r_column) {
- *r_error=error;
- *r_line=get_token(pos).line;
- *r_column=get_token(pos).col;
- }
+ Token _make_token(TokenType p_type, const StringName& p_text=StringName());
+ Token _get_token();
+ ShaderNode *shader;
+ enum IdentifierType {
+ IDENTIFIER_FUNCTION,
+ IDENTIFIER_UNIFORM,
+ IDENTIFIER_VARYING,
+ IDENTIFIER_FUNCTION_ARGUMENT,
+ IDENTIFIER_LOCAL_VAR,
+ IDENTIFIER_BUILTIN_VAR,
+ };
- Token get_token(int ofs=0) const { int idx=pos+ofs; if (idx<0 || idx>=tokens.size()) return Token(TK_ERROR); return tokens[idx]; }
- TokenType get_token_type(int ofs=0) const { int idx=pos+ofs; if (idx<0 || idx>=tokens.size()) return TK_ERROR; return tokens[idx].type; }
- void advance(int p_amount=1) { pos+=p_amount; }
- bool is_at_end() const { return pos>=tokens.size(); }
+ bool _find_identifier(const BlockNode* p_block,const Map<StringName, DataType> &p_builtin_types,const StringName& p_identifier, DataType *r_data_type=NULL, IdentifierType *r_type=NULL);
- ProgramNode *program;
- template<class T>
- T* create_node(Node *p_parent) { T*n=memnew( T ); nodegc.push_back(n); n->parent=p_parent; return n; }
- List<Node*> nodegc;
+ bool _validate_operator(OperatorNode *p_op,DataType *r_ret_type=NULL);
- Parser(const Vector<Token>& p_tokens) { tokens=p_tokens; pos=0;}
- };
struct IntrinsicFuncDef {
@@ -360,70 +494,35 @@ private:
};
- static const IntrinsicFuncDef intrinsic_func_defs[];
-
- struct OperatorDef {
-
- enum { MAX_ARGS=2 };
- Operator op;
- DataType rettype;
- const DataType args[MAX_ARGS];
- };
-
- static const OperatorDef operator_defs[];
-
- struct BuiltinsDef {
-
- const char* name;
- DataType type;
- };
-
- static const BuiltinsDef vertex_builtins_defs[];
- static const BuiltinsDef fragment_builtins_defs[];
- static const BuiltinsDef light_builtins_defs[];
-
- static const BuiltinsDef ci_vertex_builtins_defs[];
- static const BuiltinsDef ci_fragment_builtins_defs[];
- static const BuiltinsDef ci_light_builtins_defs[];
-
- static const BuiltinsDef postprocess_fragment_builtins_defs[];
-
- static DataType get_token_datatype(TokenType p_type);
- static String get_datatype_name(DataType p_type);
- static bool is_token_datatype(TokenType p_type);
- static bool is_token_nonvoid_datatype(TokenType p_type);
-
- static bool test_existing_identifier(Node *p_node,const StringName p_identifier,bool p_func=true,bool p_var=true,bool p_builtin=true);
+ static const IntrinsicFuncDef intrinsic_func_defs[];
+ bool _validate_function_call(BlockNode* p_block, OperatorNode *p_func,DataType *r_ret_type);
- static bool parser_is_at_function(Parser& parser);
- static DataType compute_node_type(Node *p_node);
+ bool _parse_function_arguments(BlockNode *p_block, const Map<StringName,DataType> &p_builtin_types, OperatorNode* p_func);
- static Node* validate_function_call(Parser&parser, OperatorNode *p_func);
- static Node* validate_operator(Parser& parser,OperatorNode *p_func);
- static bool is_token_operator(TokenType p_type);
- static Operator get_token_operator(TokenType p_type);
+ Node* _parse_expression(BlockNode *p_block, const Map<StringName,DataType> &p_builtin_types);
- static Error parse_expression(Parser& parser,Node *p_parent,Node **r_expr);
+ ShaderLanguage::Node* _reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node);
+ Node* _parse_and_reduce_expression(BlockNode *p_block,const Map<StringName,DataType> &p_builtin_types);
- static Error parse_variable_declaration(Parser& parser,BlockNode *p_block);
- static Error parse_function(Parser& parser,BlockNode *p_block);
- static Error parse_flow_if(Parser& parser,Node *p_parent,Node **r_statement);
- static Error parse_flow_return(Parser& parser,Node *p_parent,Node **r_statement);
- static Error parse_statement(Parser& parser,Node *p_parent,Node **r_statement);
- static Error parse_block(Parser& parser,BlockNode *p_block);
+ Error _parse_block(BlockNode *p_block, const Map<StringName, DataType> &p_builtin_types, bool p_just_one=false, bool p_can_break=false, bool p_can_continue=false);
+ Error _parse_shader(const Map< StringName, Map<StringName,DataType> > &p_functions, const Set<String> &p_render_modes);
- static Error parse(const Vector<Token> &p_tokens,ShaderType p_type,CompileFunc p_compile_func,void *p_userdata,String *r_error,int *r_err_line,int *r_err_column);
-;
public:
- static void get_keyword_list(ShaderType p_type,List<String> *p_keywords);
+// static void get_keyword_list(ShaderType p_type,List<String> *p_keywords);
+
+ void clear();
+ Error compile(const String& p_code,const Map< StringName, Map<StringName,DataType> > &p_functions,const Set<String>& p_render_modes);
+ String get_error_text();
+ int get_error_line();
- static Error compile(const String& p_code,ShaderType p_type, CompileFunc p_compile_func,void *p_userdata,String *r_error,int *r_err_line,int *r_err_column);
static String lex_debug(const String& p_code);
+ ShaderLanguage();
+ ~ShaderLanguage();
};
diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp
new file mode 100644
index 0000000000..f70ce46a3d
--- /dev/null
+++ b/servers/visual/visual_server_canvas.cpp
@@ -0,0 +1,1268 @@
+#include "visual_server_canvas.h"
+#include "visual_server_global.h"
+#include "visual_server_viewport.h"
+
+void VisualServerCanvas::_render_canvas_item_tree(Item *p_canvas_item, const Matrix32& p_transform, const Rect2& p_clip_rect, const Color& p_modulate, RasterizerCanvas::Light *p_lights) {
+
+
+ static const int z_range = VS::CANVAS_ITEM_Z_MAX-VS::CANVAS_ITEM_Z_MIN+1;
+ RasterizerCanvas::Item *z_list[z_range];
+ RasterizerCanvas::Item *z_last_list[z_range];
+
+ for(int i=0;i<z_range;i++) {
+ z_list[i]=NULL;
+ z_last_list[i]=NULL;
+ }
+
+
+ _render_canvas_item(p_canvas_item,p_transform,p_clip_rect,Color(1,1,1,1),0,z_list,z_last_list,NULL,NULL);
+
+ for(int i=0;i<z_range;i++) {
+ if (!z_list[i])
+ continue;
+ VSG::canvas_render->canvas_render_items(z_list[i],VS::CANVAS_ITEM_Z_MIN+i,p_modulate,p_lights);
+ }
+
+}
+
+void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item,const Matrix32& p_transform,const Rect2& p_clip_rect, const Color &p_modulate,int p_z,RasterizerCanvas::Item **z_list,RasterizerCanvas::Item **z_last_list,Item *p_canvas_clip,Item *p_material_owner) {
+
+ Item *ci = p_canvas_item;
+
+ if (!ci->visible)
+ return;
+
+ Rect2 rect = ci->get_rect();
+ Matrix32 xform = p_transform * ci->xform;
+ Rect2 global_rect = xform.xform(rect);
+ global_rect.pos+=p_clip_rect.pos;
+
+
+ if (ci->use_parent_material && p_material_owner)
+ ci->material_owner=p_material_owner;
+ else {
+ p_material_owner=ci;
+ ci->material_owner=NULL;
+ }
+
+
+ Color modulate( ci->modulate.r * p_modulate.r, ci->modulate.g * p_modulate.g,ci->modulate.b * p_modulate.b,ci->modulate.a * p_modulate.a);
+
+ if (modulate.a<0.007)
+ return;
+
+
+ int child_item_count=ci->child_items.size();
+ Item **child_items=(Item**)alloca(child_item_count*sizeof(Item*));
+ copymem(child_items,ci->child_items.ptr(),child_item_count*sizeof(Item*));
+
+ if (ci->clip) {
+ if (p_canvas_clip != NULL) {
+ ci->final_clip_rect=p_canvas_clip->final_clip_rect.clip(global_rect);
+ } else {
+ ci->final_clip_rect=global_rect;
+ }
+ ci->final_clip_owner=ci;
+
+ } else {
+ ci->final_clip_owner=p_canvas_clip;
+ }
+
+ if (ci->sort_y) {
+
+ SortArray<Item*,ItemPtrSort> sorter;
+ sorter.sort(child_items,child_item_count);
+ }
+
+ if (ci->z_relative)
+ p_z=CLAMP(p_z+ci->z,VS::CANVAS_ITEM_Z_MIN,VS::CANVAS_ITEM_Z_MAX);
+ else
+ p_z=ci->z;
+
+ for(int i=0;i<child_item_count;i++) {
+
+ if (!child_items[i]->behind)
+ continue;
+ _render_canvas_item(child_items[i],xform,p_clip_rect,modulate,p_z,z_list,z_last_list,(Item*)ci->final_clip_owner,p_material_owner);
+ }
+
+ if (ci->copy_back_buffer) {
+
+ ci->copy_back_buffer->screen_rect = xform.xform(ci->copy_back_buffer->rect).clip(p_clip_rect);
+ }
+
+ if ((!ci->commands.empty() && p_clip_rect.intersects(global_rect)) || ci->vp_render || ci->copy_back_buffer) {
+ //something to draw?
+ ci->final_transform=xform;
+ ci->final_modulate=Color(modulate.r*ci->self_modulate.r, modulate.g*ci->self_modulate.g, modulate.b*ci->self_modulate.b, modulate.a*ci->self_modulate.a );
+ ci->global_rect_cache=global_rect;
+ ci->global_rect_cache.pos-=p_clip_rect.pos;
+ ci->light_masked=false;
+
+ int zidx = p_z-VS::CANVAS_ITEM_Z_MIN;
+
+ if (z_last_list[zidx]) {
+ z_last_list[zidx]->next=ci;
+ z_last_list[zidx]=ci;
+
+ } else {
+ z_list[zidx]=ci;
+ z_last_list[zidx]=ci;
+ }
+
+ ci->next=NULL;
+
+ }
+
+ for(int i=0;i<child_item_count;i++) {
+
+ if (child_items[i]->behind)
+ continue;
+ _render_canvas_item(child_items[i],xform,p_clip_rect,modulate,p_z,z_list,z_last_list,(Item*)ci->final_clip_owner,p_material_owner);
+ }
+
+}
+
+void VisualServerCanvas::_light_mask_canvas_items(int p_z,RasterizerCanvas::Item *p_canvas_item,RasterizerCanvas::Light *p_masked_lights) {
+
+ if (!p_masked_lights)
+ return;
+
+ RasterizerCanvas::Item *ci=p_canvas_item;
+
+ while(ci) {
+
+ RasterizerCanvas::Light *light=p_masked_lights;
+ while(light) {
+
+ if (ci->light_mask&light->item_mask && p_z>=light->z_min && p_z<=light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache,light->rect_cache)) {
+ ci->light_masked=true;
+ }
+
+ light=light->mask_next_ptr;
+ }
+
+ ci=ci->next;
+ }
+
+
+
+
+}
+
+void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Matrix32 &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect) {
+
+ VSG::canvas_render->canvas_begin();
+
+ int l = p_canvas->child_items.size();
+ Canvas::ChildItem *ci=p_canvas->child_items.ptr();
+
+ bool has_mirror=false;
+ for(int i=0;i<l;i++) {
+ if (ci[i].mirror.x || ci[i].mirror.y) {
+ has_mirror=true;
+ break;
+ }
+ }
+
+
+ if (!has_mirror) {
+
+ static const int z_range = VS::CANVAS_ITEM_Z_MAX-VS::CANVAS_ITEM_Z_MIN+1;
+ RasterizerCanvas::Item *z_list[z_range];
+ RasterizerCanvas::Item *z_last_list[z_range];
+
+ for(int i=0;i<z_range;i++) {
+ z_list[i]=NULL;
+ z_last_list[i]=NULL;
+ }
+ for(int i=0;i<l;i++) {
+ _render_canvas_item(ci[i].item,p_transform,p_clip_rect,Color(1,1,1,1),0,z_list,z_last_list,NULL,NULL);
+ }
+
+ for(int i=0;i<z_range;i++) {
+ if (!z_list[i])
+ continue;
+
+ if (p_masked_lights) {
+ _light_mask_canvas_items(VS::CANVAS_ITEM_Z_MIN+i,z_list[i],p_masked_lights);
+ }
+
+ VSG::canvas_render->canvas_render_items(z_list[i],VS::CANVAS_ITEM_Z_MIN+i,p_canvas->modulate,p_lights);
+ }
+ } else {
+
+ for(int i=0;i<l;i++) {
+
+ Canvas::ChildItem& ci=p_canvas->child_items[i];
+ _render_canvas_item_tree(ci.item,p_transform,p_clip_rect,p_canvas->modulate,p_lights);
+
+ //mirroring (useful for scrolling backgrounds)
+ if (ci.mirror.x!=0) {
+
+ Matrix32 xform2 = p_transform * Matrix32(0,Vector2(ci.mirror.x,0));
+ _render_canvas_item_tree(ci.item,xform2,p_clip_rect,p_canvas->modulate,p_lights);
+ }
+ if (ci.mirror.y!=0) {
+
+ Matrix32 xform2 = p_transform * Matrix32(0,Vector2(0,ci.mirror.y));
+ _render_canvas_item_tree(ci.item,xform2,p_clip_rect,p_canvas->modulate,p_lights);
+ }
+ if (ci.mirror.y!=0 && ci.mirror.x!=0) {
+
+ Matrix32 xform2 = p_transform * Matrix32(0,ci.mirror);
+ _render_canvas_item_tree(ci.item,xform2,p_clip_rect,p_canvas->modulate,p_lights);
+ }
+
+ }
+ }
+
+}
+
+
+RID VisualServerCanvas::canvas_create() {
+
+ Canvas * canvas = memnew( Canvas );
+ ERR_FAIL_COND_V(!canvas,RID());
+ RID rid = canvas_owner.make_rid( canvas );
+
+ return rid;
+}
+
+void VisualServerCanvas::canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring) {
+
+ Canvas * canvas = canvas_owner.getornull(p_canvas);
+ ERR_FAIL_COND(!canvas);
+ Item *canvas_item = canvas_item_owner.getornull(p_item);
+ ERR_FAIL_COND(!canvas_item);
+
+ int idx = canvas->find_item(canvas_item);
+ ERR_FAIL_COND(idx==-1);
+ canvas->child_items[idx].mirror=p_mirroring;
+
+}
+void VisualServerCanvas::canvas_set_modulate(RID p_canvas,const Color& p_color) {
+
+ Canvas * canvas = canvas_owner.get(p_canvas);
+ ERR_FAIL_COND(!canvas);
+ canvas->modulate=p_color;
+}
+
+
+RID VisualServerCanvas::canvas_item_create() {
+
+ Item *canvas_item = memnew( Item );
+ ERR_FAIL_COND_V(!canvas_item,RID());
+
+ return canvas_item_owner.make_rid( canvas_item );
+}
+
+void VisualServerCanvas::canvas_item_set_parent(RID p_item,RID p_parent) {
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ if (canvas_item->parent.is_valid()) {
+
+ if (canvas_owner.owns(canvas_item->parent)) {
+
+ Canvas *canvas = canvas_owner.get(canvas_item->parent);
+ canvas->erase_item(canvas_item);
+ } else if (canvas_item_owner.owns(canvas_item->parent)) {
+
+ Item *item_owner = canvas_item_owner.get(canvas_item->parent);
+ item_owner->child_items.erase(canvas_item);
+ }
+
+ canvas_item->parent=RID();
+ }
+
+
+ if (p_parent.is_valid()) {
+ if (canvas_owner.owns(p_parent)) {
+
+ Canvas *canvas = canvas_owner.get(p_parent);
+ Canvas::ChildItem ci;
+ ci.item=canvas_item;
+ canvas->child_items.push_back(ci);
+ canvas->children_order_dirty=true;
+ } else if (canvas_item_owner.owns(p_parent)) {
+
+ Item *item_owner = canvas_item_owner.get(p_parent);
+ item_owner->child_items.push_back(canvas_item);
+ item_owner->children_order_dirty=true;
+
+ } else {
+
+ ERR_EXPLAIN("Invalid parent");
+ ERR_FAIL();
+ }
+
+
+ }
+
+ canvas_item->parent=p_parent;
+
+
+}
+void VisualServerCanvas::canvas_item_set_visible(RID p_item,bool p_visible){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->visible=p_visible;
+
+}
+void VisualServerCanvas::canvas_item_set_light_mask(RID p_item,int p_mask){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->light_mask=p_mask;
+
+}
+
+void VisualServerCanvas::canvas_item_set_transform(RID p_item, const Matrix32& p_transform){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->xform=p_transform;
+
+}
+void VisualServerCanvas::canvas_item_set_clip(RID p_item, bool p_clip){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->clip=p_clip;
+
+}
+void VisualServerCanvas::canvas_item_set_distance_field_mode(RID p_item, bool p_enable){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->distance_field=p_enable;
+
+
+}
+void VisualServerCanvas::canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->custom_rect=p_custom_rect;
+ canvas_item->rect=p_rect;
+
+}
+void VisualServerCanvas::canvas_item_set_modulate(RID p_item, const Color& p_color) {
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->modulate=p_color;
+
+}
+void VisualServerCanvas::canvas_item_set_self_modulate(RID p_item, const Color& p_color){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->self_modulate=p_color;
+
+}
+
+void VisualServerCanvas::canvas_item_set_draw_behind_parent(RID p_item, bool p_enable){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->behind=p_enable;
+
+}
+
+
+void VisualServerCanvas::canvas_item_add_line(RID p_item, const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width,bool p_antialiased) {
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandLine * line = memnew( Item::CommandLine );
+ ERR_FAIL_COND(!line);
+ line->color=p_color;
+ line->from=p_from;
+ line->to=p_to;
+ line->width=p_width;
+ line->antialiased=p_antialiased;
+ canvas_item->rect_dirty=true;
+
+
+ canvas_item->commands.push_back(line);
+}
+
+void VisualServerCanvas::canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color) {
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandRect * rect = memnew( Item::CommandRect );
+ ERR_FAIL_COND(!rect);
+ rect->modulate=p_color;
+ rect->rect=p_rect;
+ canvas_item->rect_dirty=true;
+
+ canvas_item->commands.push_back(rect);
+}
+
+void VisualServerCanvas::canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color) {
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandCircle * circle = memnew( Item::CommandCircle );
+ ERR_FAIL_COND(!circle);
+ circle->color=p_color;
+ circle->pos=p_pos;
+ circle->radius=p_radius;
+
+ canvas_item->commands.push_back(circle);
+
+}
+
+void VisualServerCanvas::canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile,const Color& p_modulate,bool p_transpose) {
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandRect * rect = memnew( Item::CommandRect );
+ ERR_FAIL_COND(!rect);
+ rect->modulate=p_modulate;
+ rect->rect=p_rect;
+ rect->flags=0;
+ if (p_tile) {
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_TILE;
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_REGION;
+ rect->source=Rect2(0,0,p_rect.size.width,p_rect.size.height);
+ }
+
+ if (p_rect.size.x<0) {
+
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_FLIP_H;
+ rect->rect.size.x = -rect->rect.size.x;
+ }
+ if (p_rect.size.y<0) {
+
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_FLIP_V;
+ rect->rect.size.y = -rect->rect.size.y;
+ }
+ if (p_transpose) {
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_TRANSPOSE;
+ SWAP(rect->rect.size.x, rect->rect.size.y);
+ }
+ rect->texture=p_texture;
+ canvas_item->rect_dirty=true;
+ canvas_item->commands.push_back(rect);
+}
+
+void VisualServerCanvas::canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate,bool p_transpose) {
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandRect * rect = memnew( Item::CommandRect );
+ ERR_FAIL_COND(!rect);
+ rect->modulate=p_modulate;
+ rect->rect=p_rect;
+ rect->texture=p_texture;
+ rect->source=p_src_rect;
+ rect->flags=RasterizerCanvas::CANVAS_RECT_REGION;
+
+ if (p_rect.size.x<0) {
+
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_FLIP_H;
+ rect->rect.size.x = -rect->rect.size.x;
+ }
+ if (p_rect.size.y<0) {
+
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_FLIP_V;
+ rect->rect.size.y = -rect->rect.size.y;
+ }
+ if (p_transpose) {
+ rect->flags|=RasterizerCanvas::CANVAS_RECT_TRANSPOSE;
+ SWAP(rect->rect.size.x, rect->rect.size.y);
+ }
+
+ canvas_item->rect_dirty=true;
+
+ canvas_item->commands.push_back(rect);
+
+}
+
+void VisualServerCanvas::canvas_item_add_nine_patch(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright,VS::NinePatchAxisMode p_x_axis_mode, VS::NinePatchAxisMode p_y_axis_mode,bool p_draw_center,const Color& p_modulate) {
+
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandNinePatch * style = memnew( Item::CommandNinePatch );
+ ERR_FAIL_COND(!style);
+ style->texture=p_texture;
+ style->rect=p_rect;
+ style->source=p_source;
+ style->draw_center=p_draw_center;
+ style->color=p_modulate;
+ style->margin[MARGIN_LEFT]=p_topleft.x;
+ style->margin[MARGIN_TOP]=p_topleft.y;
+ style->margin[MARGIN_RIGHT]=p_bottomright.x;
+ style->margin[MARGIN_BOTTOM]=p_bottomright.y;
+ style->axis_x=p_x_axis_mode;
+ style->axis_y=p_y_axis_mode;
+ canvas_item->rect_dirty=true;
+
+ canvas_item->commands.push_back(style);
+}
+void VisualServerCanvas::canvas_item_add_primitive(RID p_item,const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) {
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandPrimitive * prim = memnew( Item::CommandPrimitive );
+ ERR_FAIL_COND(!prim);
+ prim->texture=p_texture;
+ prim->points=p_points;
+ prim->uvs=p_uvs;
+ prim->colors=p_colors;
+ prim->width=p_width;
+ canvas_item->rect_dirty=true;
+
+ canvas_item->commands.push_back(prim);
+}
+
+void VisualServerCanvas::canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture) {
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+#ifdef DEBUG_ENABLED
+ int pointcount = p_points.size();
+ ERR_FAIL_COND(pointcount<3);
+ int color_size=p_colors.size();
+ int uv_size=p_uvs.size();
+ ERR_FAIL_COND(color_size!=0 && color_size!=1 && color_size!=pointcount);
+ ERR_FAIL_COND(uv_size!=0 && (uv_size!=pointcount || !p_texture.is_valid()));
+#endif
+ Vector<int> indices = Geometry::triangulate_polygon(p_points);
+
+ if (indices.empty()) {
+
+ ERR_EXPLAIN("Bad Polygon!");
+ ERR_FAIL_V();
+ }
+
+ Item::CommandPolygon * polygon = memnew( Item::CommandPolygon );
+ ERR_FAIL_COND(!polygon);
+ polygon->texture=p_texture;
+ polygon->points=p_points;
+ polygon->uvs=p_uvs;
+ polygon->colors=p_colors;
+ polygon->indices=indices;
+ polygon->count=indices.size();
+ canvas_item->rect_dirty=true;
+
+ canvas_item->commands.push_back(polygon);
+
+}
+
+
+void VisualServerCanvas::canvas_item_add_triangle_array(RID p_item, const Vector<int>& p_indices, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture, int p_count) {
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ int ps = p_points.size();
+ ERR_FAIL_COND(!p_colors.empty() && p_colors.size()!=ps && p_colors.size()!=1);
+ ERR_FAIL_COND(!p_uvs.empty() && p_uvs.size()!=ps);
+
+ Vector<int> indices = p_indices;
+
+ int count = p_count * 3;
+
+ if (indices.empty()) {
+
+ ERR_FAIL_COND( ps % 3 != 0 );
+ if (p_count == -1)
+ count = ps;
+ } else {
+
+ ERR_FAIL_COND( indices.size() % 3 != 0 );
+ if (p_count == -1)
+ count = indices.size();
+ }
+
+ Item::CommandPolygon * polygon = memnew( Item::CommandPolygon );
+ ERR_FAIL_COND(!polygon);
+ polygon->texture=p_texture;
+ polygon->points=p_points;
+ polygon->uvs=p_uvs;
+ polygon->colors=p_colors;
+ polygon->indices=indices;
+ polygon->count = count;
+ canvas_item->rect_dirty=true;
+
+ canvas_item->commands.push_back(polygon);
+}
+
+
+void VisualServerCanvas::canvas_item_add_set_transform(RID p_item,const Matrix32& p_transform) {
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandTransform * tr = memnew( Item::CommandTransform );
+ ERR_FAIL_COND(!tr);
+ tr->xform=p_transform;
+
+ canvas_item->commands.push_back(tr);
+
+}
+
+void VisualServerCanvas::canvas_item_add_mesh(RID p_item, const RID& p_mesh,RID p_skeleton){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandMesh * m = memnew( Item::CommandMesh );
+ ERR_FAIL_COND(!m);
+ m->mesh=p_mesh;
+ m->skeleton=p_skeleton;
+
+ canvas_item->commands.push_back(m);
+}
+void VisualServerCanvas::canvas_item_add_multimesh(RID p_item, RID p_mesh,RID p_skeleton){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandMultiMesh * mm = memnew( Item::CommandMultiMesh );
+ ERR_FAIL_COND(!mm);
+ mm->multimesh=p_mesh;
+ mm->skeleton=p_skeleton;
+
+ canvas_item->commands.push_back(mm);
+
+}
+
+void VisualServerCanvas::canvas_item_add_clip_ignore(RID p_item, bool p_ignore){
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ Item::CommandClipIgnore * ci = memnew( Item::CommandClipIgnore);
+ ERR_FAIL_COND(!ci);
+ ci->ignore=p_ignore;
+
+ canvas_item->commands.push_back(ci);
+}
+void VisualServerCanvas::canvas_item_set_sort_children_by_y(RID p_item, bool p_enable){
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->sort_y=p_enable;
+}
+void VisualServerCanvas::canvas_item_set_z(RID p_item, int p_z){
+
+ ERR_FAIL_COND(p_z<VS::CANVAS_ITEM_Z_MIN || p_z>VS::CANVAS_ITEM_Z_MAX);
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->z=p_z;
+}
+void VisualServerCanvas::canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->z_relative=p_enable;
+
+}
+void VisualServerCanvas::canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect){
+
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+ if (bool(canvas_item->copy_back_buffer!=NULL) !=p_enable) {
+ if (p_enable) {
+ canvas_item->copy_back_buffer = memnew( RasterizerCanvas::Item::CopyBackBuffer );
+ } else {
+ memdelete(canvas_item->copy_back_buffer);
+ canvas_item->copy_back_buffer=NULL;
+ }
+ }
+
+ if (p_enable) {
+ canvas_item->copy_back_buffer->rect=p_rect;
+ canvas_item->copy_back_buffer->full=p_rect==Rect2();
+ }
+
+}
+
+void VisualServerCanvas::canvas_item_clear(RID p_item){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->clear();
+}
+void VisualServerCanvas::canvas_item_set_draw_index(RID p_item,int p_index){
+
+ Item *canvas_item = canvas_item_owner.getornull( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->index=p_index;
+
+ if (canvas_item_owner.owns( canvas_item->parent)) {
+ Item *canvas_item_parent = canvas_item_owner.getornull( canvas_item->parent );
+ canvas_item_parent->children_order_dirty=true;
+ return;
+ }
+
+ Canvas* canvas = canvas_owner.getornull( canvas_item->parent );
+ if (canvas) {
+ canvas->children_order_dirty=true;
+ return;
+ }
+
+}
+
+void VisualServerCanvas::canvas_item_set_material(RID p_item, RID p_material){
+
+ Item *canvas_item = canvas_item_owner.get( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->material=p_material;
+}
+
+void VisualServerCanvas::canvas_item_set_use_parent_material(RID p_item, bool p_enable){
+
+ Item *canvas_item = canvas_item_owner.get( p_item );
+ ERR_FAIL_COND(!canvas_item);
+
+ canvas_item->use_parent_material=p_enable;
+
+}
+
+RID VisualServerCanvas::canvas_light_create(){
+
+ RasterizerCanvas::Light *clight = memnew( RasterizerCanvas::Light );
+ clight->light_internal = VSG::canvas_render->light_internal_create();
+ return canvas_light_owner.make_rid(clight);
+
+}
+void VisualServerCanvas::canvas_light_attach_to_canvas(RID p_light,RID p_canvas){
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ if (clight->canvas.is_valid()) {
+
+ Canvas *canvas = canvas_owner.getornull(clight->canvas);
+ canvas->lights.erase(clight);
+ }
+
+ if (!canvas_owner.owns(p_canvas))
+ p_canvas=RID();
+
+ clight->canvas=p_canvas;
+
+ if (clight->canvas.is_valid()) {
+
+ Canvas *canvas = canvas_owner.get(clight->canvas);
+ canvas->lights.insert(clight);
+ }
+}
+
+
+void VisualServerCanvas::canvas_light_set_enabled(RID p_light, bool p_enabled){
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->enabled=p_enabled;
+
+}
+void VisualServerCanvas::canvas_light_set_scale(RID p_light, float p_scale){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->scale=p_scale;
+
+}
+void VisualServerCanvas::canvas_light_set_transform(RID p_light, const Matrix32& p_transform){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->xform=p_transform;
+
+}
+void VisualServerCanvas::canvas_light_set_texture(RID p_light, RID p_texture){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->texture=p_texture;
+
+}
+void VisualServerCanvas::canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->texture_offset=p_offset;
+
+}
+void VisualServerCanvas::canvas_light_set_color(RID p_light, const Color& p_color){
+
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->color=p_color;
+}
+void VisualServerCanvas::canvas_light_set_height(RID p_light, float p_height){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->height=p_height;
+
+}
+void VisualServerCanvas::canvas_light_set_energy(RID p_light, float p_energy){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->energy=p_energy;
+
+}
+void VisualServerCanvas::canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->z_min=p_min_z;
+ clight->z_max=p_max_z;
+
+}
+void VisualServerCanvas::canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+
+ clight->layer_max=p_max_layer;
+ clight->layer_min=p_min_layer;
+
+
+}
+void VisualServerCanvas::canvas_light_set_item_cull_mask(RID p_light, int p_mask){
+
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->item_mask=p_mask;
+
+}
+void VisualServerCanvas::canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask){
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->item_shadow_mask=p_mask;
+
+}
+void VisualServerCanvas::canvas_light_set_mode(RID p_light, VS::CanvasLightMode p_mode){
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->mode=p_mode;
+
+}
+
+
+void VisualServerCanvas::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled){
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ if (clight->shadow_buffer.is_valid()==p_enabled)
+ return;
+ if (p_enabled) {
+ clight->shadow_buffer=VSG::storage->canvas_light_shadow_buffer_create(clight->shadow_buffer_size);
+ } else {
+ VSG::storage->free(clight->shadow_buffer);
+ clight->shadow_buffer=RID();
+ }
+
+}
+void VisualServerCanvas::canvas_light_set_shadow_buffer_size(RID p_light, int p_size){
+
+ ERR_FAIL_COND(p_size<32 || p_size>16384);
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ int new_size = nearest_power_of_2(p_size);;
+ if (new_size==clight->shadow_buffer_size)
+ return;
+
+ clight->shadow_buffer_size=nearest_power_of_2(p_size);
+
+ if (clight->shadow_buffer.is_valid()) {
+ VSG::storage->free(clight->shadow_buffer);
+ clight->shadow_buffer=VSG::storage->canvas_light_shadow_buffer_create(clight->shadow_buffer_size);
+ }
+}
+
+void VisualServerCanvas::canvas_light_set_shadow_gradient_length(RID p_light, float p_length) {
+
+ ERR_FAIL_COND(p_length<0);
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->shadow_gradient_length=p_length;
+
+}
+void VisualServerCanvas::canvas_light_set_shadow_filter(RID p_light, VS::CanvasLightShadowFilter p_filter) {
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->shadow_filter=p_filter;
+
+}
+void VisualServerCanvas::canvas_light_set_shadow_color(RID p_light, const Color& p_color) {
+
+ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
+ ERR_FAIL_COND(!clight);
+
+ clight->shadow_color=p_color;
+}
+
+
+
+RID VisualServerCanvas::canvas_light_occluder_create() {
+
+ RasterizerCanvas::LightOccluderInstance *occluder = memnew( RasterizerCanvas::LightOccluderInstance );
+
+ return canvas_light_occluder_owner.make_rid(occluder);
+}
+void VisualServerCanvas::canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas){
+
+ RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
+ ERR_FAIL_COND(!occluder);
+
+ if (occluder->canvas.is_valid()) {
+
+ Canvas *canvas = canvas_owner.get(occluder->canvas);
+ canvas->occluders.erase(occluder);
+ }
+
+ if (!canvas_owner.owns(p_canvas))
+ p_canvas=RID();
+
+ occluder->canvas=p_canvas;
+
+ if (occluder->canvas.is_valid()) {
+
+ Canvas *canvas = canvas_owner.get(occluder->canvas);
+ canvas->occluders.insert(occluder);
+ }
+}
+void VisualServerCanvas::canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled) {
+
+ RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
+ ERR_FAIL_COND(!occluder);
+
+ occluder->enabled=p_enabled;
+}
+void VisualServerCanvas::canvas_light_occluder_set_polygon(RID p_occluder,RID p_polygon) {
+
+ RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
+ ERR_FAIL_COND(!occluder);
+
+ if (occluder->polygon.is_valid()) {
+ LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon);
+ if (occluder_poly) {
+ occluder_poly->owners.erase(occluder);
+ }
+ }
+
+ occluder->polygon=p_polygon;
+ occluder->polygon_buffer=RID();
+
+ if (occluder->polygon.is_valid()) {
+ LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon);
+ if (!occluder_poly)
+ occluder->polygon=RID();
+ ERR_FAIL_COND(!occluder_poly);
+ occluder_poly->owners.insert(occluder);
+ occluder->polygon_buffer=occluder_poly->occluder;
+ occluder->aabb_cache=occluder_poly->aabb;
+ occluder->cull_cache=occluder_poly->cull_mode;
+ }
+
+}
+void VisualServerCanvas::canvas_light_occluder_set_transform(RID p_occluder,const Matrix32& p_xform) {
+
+ RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
+ ERR_FAIL_COND(!occluder);
+
+ occluder->xform=p_xform;
+}
+void VisualServerCanvas::canvas_light_occluder_set_light_mask(RID p_occluder,int p_mask) {
+
+ RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
+ ERR_FAIL_COND(!occluder);
+
+ occluder->light_mask=p_mask;
+}
+
+RID VisualServerCanvas::canvas_occluder_polygon_create() {
+
+ LightOccluderPolygon * occluder_poly = memnew( LightOccluderPolygon );
+ occluder_poly->occluder=VSG::storage->canvas_light_occluder_create();
+ return canvas_light_occluder_polygon_owner.make_rid(occluder_poly);
+
+}
+void VisualServerCanvas::canvas_occluder_polygon_set_shape(RID p_occluder_polygon,const DVector<Vector2>& p_shape,bool p_closed) {
+
+ if (p_shape.size()<3) {
+ canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon,p_shape);
+ return;
+ }
+
+ DVector<Vector2> lines;
+ int lc = p_shape.size()*2;
+
+ lines.resize(lc-(p_closed?0:2));
+ {
+ DVector<Vector2>::Write w = lines.write();
+ DVector<Vector2>::Read r = p_shape.read();
+
+ int max=lc/2;
+ if (!p_closed) {
+ max--;
+ }
+ for(int i=0;i<max;i++) {
+
+ Vector2 a = r[i];
+ Vector2 b = r[(i+1)%(lc/2)];
+ w[i*2+0]=a;
+ w[i*2+1]=b;
+ }
+
+ }
+
+ canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon,lines);
+}
+void VisualServerCanvas::canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon,const DVector<Vector2>& p_shape) {
+
+ LightOccluderPolygon * occluder_poly = canvas_light_occluder_polygon_owner.get(p_occluder_polygon);
+ ERR_FAIL_COND(!occluder_poly);
+ ERR_FAIL_COND(p_shape.size()&1);
+
+ int lc = p_shape.size();
+ occluder_poly->aabb=Rect2();
+ {
+ DVector<Vector2>::Read r = p_shape.read();
+ for(int i=0;i<lc;i++) {
+ if (i==0)
+ occluder_poly->aabb.pos=r[i];
+ else
+ occluder_poly->aabb.expand_to(r[i]);
+ }
+ }
+
+ VSG::storage->canvas_light_occluder_set_polylines(occluder_poly->occluder,p_shape);
+ for( Set<RasterizerCanvas::LightOccluderInstance*>::Element *E=occluder_poly->owners.front();E;E=E->next()) {
+ E->get()->aabb_cache=occluder_poly->aabb;
+ }
+}
+
+
+void VisualServerCanvas::canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon,VS::CanvasOccluderPolygonCullMode p_mode) {
+
+ LightOccluderPolygon * occluder_poly = canvas_light_occluder_polygon_owner.get(p_occluder_polygon);
+ ERR_FAIL_COND(!occluder_poly);
+ occluder_poly->cull_mode=p_mode;
+ for( Set<RasterizerCanvas::LightOccluderInstance*>::Element *E=occluder_poly->owners.front();E;E=E->next()) {
+ E->get()->cull_cache=p_mode;
+ }
+}
+
+
+
+bool VisualServerCanvas::free(RID p_rid) {
+
+ if (canvas_owner.owns(p_rid)) {
+
+ Canvas *canvas = canvas_owner.get(p_rid);
+ ERR_FAIL_COND_V(!canvas,false);
+
+ while(canvas->viewports.size()) {
+
+ VisualServerViewport::Viewport *vp = VSG::viewport->viewport_owner.get(canvas->viewports.front()->get());
+ ERR_FAIL_COND_V(!vp,true);
+
+ Map<RID,VisualServerViewport::Viewport::CanvasData>::Element *E=vp->canvas_map.find(p_rid);
+ ERR_FAIL_COND_V(!E,true);
+ vp->canvas_map.erase(p_rid);
+
+ canvas->viewports.erase( canvas->viewports.front() );
+ }
+
+ for (int i=0;i<canvas->child_items.size();i++) {
+
+ canvas->child_items[i].item->parent=RID();
+ }
+
+ for (Set<RasterizerCanvas::Light*>::Element *E=canvas->lights.front();E;E=E->next()) {
+
+ E->get()->canvas=RID();
+ }
+
+ for (Set<RasterizerCanvas::LightOccluderInstance*>::Element *E=canvas->occluders.front();E;E=E->next()) {
+
+ E->get()->canvas=RID();
+ }
+
+ canvas_owner.free( p_rid );
+
+ memdelete( canvas );
+
+ } else if (canvas_item_owner.owns(p_rid)) {
+
+ Item *canvas_item = canvas_item_owner.get(p_rid);
+ ERR_FAIL_COND_V(!canvas_item,true);
+
+ if (canvas_item->parent.is_valid()) {
+
+ if (canvas_owner.owns(canvas_item->parent)) {
+
+ Canvas *canvas = canvas_owner.get(canvas_item->parent);
+ canvas->erase_item(canvas_item);
+ } else if (canvas_item_owner.owns(canvas_item->parent)) {
+
+ Item *item_owner = canvas_item_owner.get(canvas_item->parent);
+ item_owner->child_items.erase(canvas_item);
+
+ }
+ }
+
+ for (int i=0;i<canvas_item->child_items.size();i++) {
+
+ canvas_item->child_items[i]->parent=RID();
+ }
+
+// if (canvas_item->material) {
+// canvas_item->material->owners.erase(canvas_item);
+// }
+
+ canvas_item_owner.free( p_rid );
+
+ memdelete( canvas_item );
+
+ } else if (canvas_light_owner.owns(p_rid)) {
+
+ RasterizerCanvas::Light *canvas_light = canvas_light_owner.get(p_rid);
+ ERR_FAIL_COND_V(!canvas_light,true);
+
+ if (canvas_light->canvas.is_valid()) {
+ Canvas* canvas = canvas_owner.get(canvas_light->canvas);
+ if (canvas)
+ canvas->lights.erase(canvas_light);
+ }
+
+ if (canvas_light->shadow_buffer.is_valid())
+ VSG::storage->free(canvas_light->shadow_buffer);
+
+ VSG::canvas_render->light_internal_free(canvas_light->light_internal);
+
+ canvas_light_owner.free( p_rid );
+ memdelete( canvas_light );
+
+ } else if (canvas_light_occluder_owner.owns(p_rid)) {
+
+ RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_rid);
+ ERR_FAIL_COND_V(!occluder,true);
+
+ if (occluder->polygon.is_valid()) {
+
+ LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(occluder->polygon);
+ if (occluder_poly) {
+ occluder_poly->owners.erase(occluder);
+ }
+
+ }
+
+ if (occluder->canvas.is_valid() && canvas_owner.owns(occluder->canvas)) {
+
+ Canvas *canvas = canvas_owner.get(occluder->canvas);
+ canvas->occluders.erase(occluder);
+
+ }
+
+ canvas_light_occluder_owner.free( p_rid );
+ memdelete(occluder);
+
+ } else if (canvas_light_occluder_polygon_owner.owns(p_rid)) {
+
+ LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_rid);
+ ERR_FAIL_COND_V(!occluder_poly,true);
+ VSG::storage->free(occluder_poly->occluder);
+
+ while(occluder_poly->owners.size()) {
+
+ occluder_poly->owners.front()->get()->polygon=RID();
+ occluder_poly->owners.erase( occluder_poly->owners.front() );
+ }
+
+ canvas_light_occluder_polygon_owner.free( p_rid );
+ memdelete(occluder_poly);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+
+
+VisualServerCanvas::VisualServerCanvas()
+{
+
+}
diff --git a/servers/visual/visual_server_canvas.h b/servers/visual/visual_server_canvas.h
new file mode 100644
index 0000000000..b5412ed608
--- /dev/null
+++ b/servers/visual/visual_server_canvas.h
@@ -0,0 +1,214 @@
+#ifndef VISUALSERVERCANVAS_H
+#define VISUALSERVERCANVAS_H
+
+#include "rasterizer.h"
+#include "visual_server_viewport.h"
+
+class VisualServerCanvas {
+public:
+
+
+ struct Item : public RasterizerCanvas::Item {
+
+
+ RID parent; // canvas it belongs to
+ List<Item*>::Element *E;
+ int z;
+ bool z_relative;
+ bool sort_y;
+ Color modulate;
+ Color self_modulate;
+ bool use_parent_material;
+ int index;
+ bool children_order_dirty;
+
+
+ Vector<Item*> child_items;
+
+
+ Item() {
+ children_order_dirty=true;
+ E=NULL;
+ z=0;
+ modulate=Color(1,1,1,1);
+ self_modulate=Color(1,1,1,1);
+ sort_y=false;
+ use_parent_material=false;
+ z_relative=true;
+ index=0;
+ }
+ };
+
+
+ struct ItemPtrSort {
+
+ _FORCE_INLINE_ bool operator()(const Item* p_left,const Item* p_right) const {
+
+ return p_left->xform.elements[2].y < p_right->xform.elements[2].y;
+ }
+ };
+
+ struct LightOccluderPolygon : RID_Data {
+
+ bool active;
+ Rect2 aabb;
+ VS::CanvasOccluderPolygonCullMode cull_mode;
+ RID occluder;
+ Set<RasterizerCanvas::LightOccluderInstance*> owners;
+
+ LightOccluderPolygon() { active=false; cull_mode=VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; }
+ };
+
+
+ RID_Owner<LightOccluderPolygon> canvas_light_occluder_polygon_owner;
+
+ RID_Owner<RasterizerCanvas::LightOccluderInstance> canvas_light_occluder_owner;
+
+ struct Canvas : public VisualServerViewport::CanvasBase {
+
+ Set<RID> viewports;
+ struct ChildItem {
+
+ Point2 mirror;
+ Item *item;
+ bool operator<(const ChildItem& p_item) const {
+ return item->index < p_item.item->index;
+ }
+ };
+
+
+
+ Set<RasterizerCanvas::Light*> lights;
+
+ Set<RasterizerCanvas::LightOccluderInstance*> occluders;
+
+ bool children_order_dirty;
+ Vector<ChildItem> child_items;
+ Color modulate;
+
+ int find_item(Item *p_item) {
+ for(int i=0;i<child_items.size();i++) {
+ if (child_items[i].item==p_item)
+ return i;
+ }
+ return -1;
+ }
+ void erase_item(Item *p_item) {
+ int idx=find_item(p_item);
+ if (idx>=0)
+ child_items.remove(idx);
+ }
+
+
+ Canvas() { modulate=Color(1,1,1,1); children_order_dirty=true; }
+
+ };
+
+
+ RID_Owner<Canvas> canvas_owner;
+ RID_Owner<Item> canvas_item_owner;
+ RID_Owner<RasterizerCanvas::Light> canvas_light_owner;
+
+private:
+
+ void _render_canvas_item_tree(Item *p_canvas_item, const Matrix32& p_transform, const Rect2& p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights);
+ void _render_canvas_item(Item *p_canvas_item, const Matrix32& p_transform, const Rect2& p_clip_rect, const Color &p_modulate, int p_z, RasterizerCanvas::Item **z_list, RasterizerCanvas::Item **z_last_list, Item *p_canvas_clip, Item *p_material_owner);
+ void _light_mask_canvas_items(int p_z,RasterizerCanvas::Item *p_canvas_item,RasterizerCanvas::Light *p_masked_lights);
+public:
+
+ void render_canvas(Canvas *p_canvas, const Matrix32 &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights,const Rect2& p_clip_rect);
+
+ RID canvas_create();
+ void canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring);
+ void canvas_set_modulate(RID p_canvas,const Color& p_color);
+
+
+ RID canvas_item_create();
+ void canvas_item_set_parent(RID p_item,RID p_parent);
+
+ void canvas_item_set_visible(RID p_item,bool p_visible);
+ void canvas_item_set_light_mask(RID p_item,int p_mask);
+
+ void canvas_item_set_transform(RID p_item, const Matrix32& p_transform);
+ void canvas_item_set_clip(RID p_item, bool p_clip);
+ void canvas_item_set_distance_field_mode(RID p_item, bool p_enable);
+ void canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect=Rect2());
+ void canvas_item_set_modulate(RID p_item, const Color& p_color);
+ void canvas_item_set_self_modulate(RID p_item, const Color& p_color);
+
+ void canvas_item_set_draw_behind_parent(RID p_item, bool p_enable);
+
+
+ void canvas_item_add_line(RID p_item, const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0,bool p_antialiased=false);
+ void canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color);
+ void canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color);
+ void canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile=false,const Color& p_modulate=Color(1,1,1),bool p_transpose=false);
+ void canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1),bool p_transpose=false);
+ void canvas_item_add_nine_patch(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright,VS::NinePatchAxisMode p_x_axis_mode=VS::NINE_PATCH_STRETCH, VS::NinePatchAxisMode p_y_axis_mode=VS::NINE_PATCH_STRETCH,bool p_draw_center=true,const Color& p_modulate=Color(1,1,1));
+ void canvas_item_add_primitive(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width=1.0);
+ void canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), RID p_texture=RID());
+ void canvas_item_add_triangle_array(RID p_item, const Vector<int>& p_indices, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), RID p_texture=RID(), int p_count=-1);
+ void canvas_item_add_mesh(RID p_item, const RID& p_mesh,RID p_skeleton=RID());
+ void canvas_item_add_multimesh(RID p_item, RID p_mesh,RID p_skeleton=RID());
+ void canvas_item_add_set_transform(RID p_item,const Matrix32& p_transform);
+ void canvas_item_add_clip_ignore(RID p_item, bool p_ignore);
+ void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable);
+ void canvas_item_set_z(RID p_item, int p_z);
+ void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable);
+ void canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect);
+
+ void canvas_item_clear(RID p_item);
+ void canvas_item_set_draw_index(RID p_item, int p_index);
+
+ void canvas_item_set_material(RID p_item, RID p_material);
+
+ void canvas_item_set_use_parent_material(RID p_item, bool p_enable);
+
+ RID canvas_light_create();
+ void canvas_light_attach_to_canvas(RID p_light,RID p_canvas);
+ void canvas_light_set_enabled(RID p_light, bool p_enabled);
+ void canvas_light_set_scale(RID p_light, float p_scale);
+ void canvas_light_set_transform(RID p_light, const Matrix32& p_transform);
+ void canvas_light_set_texture(RID p_light, RID p_texture);
+ void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset);
+ void canvas_light_set_color(RID p_light, const Color& p_color);
+ void canvas_light_set_height(RID p_light, float p_height);
+ void canvas_light_set_energy(RID p_light, float p_energy);
+ void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z);
+ void canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer);
+ void canvas_light_set_item_cull_mask(RID p_light, int p_mask);
+ void canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask);
+
+ void canvas_light_set_mode(RID p_light, VS::CanvasLightMode p_mode);
+
+
+ void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled);
+ void canvas_light_set_shadow_buffer_size(RID p_light, int p_size);
+ void canvas_light_set_shadow_gradient_length(RID p_light, float p_length);
+ void canvas_light_set_shadow_filter(RID p_light, VS::CanvasLightShadowFilter p_filter);
+ void canvas_light_set_shadow_color(RID p_light, const Color& p_color);
+
+
+
+ RID canvas_light_occluder_create();
+ void canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas);
+ void canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled);
+ void canvas_light_occluder_set_polygon(RID p_occluder,RID p_polygon);
+ void canvas_light_occluder_set_transform(RID p_occluder,const Matrix32& p_xform);
+ void canvas_light_occluder_set_light_mask(RID p_occluder,int p_mask);
+
+ RID canvas_occluder_polygon_create();
+ void canvas_occluder_polygon_set_shape(RID p_occluder_polygon,const DVector<Vector2>& p_shape,bool p_closed);
+ void canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon,const DVector<Vector2>& p_shape);
+
+
+ void canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon,VS::CanvasOccluderPolygonCullMode p_mode);
+
+
+ bool free(RID p_rid);
+ VisualServerCanvas();
+
+
+};
+
+#endif // VISUALSERVERCANVAS_H
diff --git a/servers/visual/visual_server_global.cpp b/servers/visual/visual_server_global.cpp
new file mode 100644
index 0000000000..32b9710f42
--- /dev/null
+++ b/servers/visual/visual_server_global.cpp
@@ -0,0 +1,10 @@
+#include "visual_server_global.h"
+
+RasterizerStorage *VisualServerGlobals::storage=NULL;
+RasterizerCanvas *VisualServerGlobals::canvas_render=NULL;
+RasterizerScene *VisualServerGlobals::scene_render=NULL;
+Rasterizer *VisualServerGlobals::rasterizer=NULL;
+
+VisualServerCanvas *VisualServerGlobals::canvas=NULL;
+VisualServerViewport *VisualServerGlobals::viewport=NULL;
+VisualServerScene *VisualServerGlobals::scene=NULL;
diff --git a/servers/visual/visual_server_global.h b/servers/visual/visual_server_global.h
new file mode 100644
index 0000000000..d413334ac4
--- /dev/null
+++ b/servers/visual/visual_server_global.h
@@ -0,0 +1,26 @@
+#ifndef VISUALSERVERGLOBAL_H
+#define VISUALSERVERGLOBAL_H
+
+#include "rasterizer.h"
+
+class VisualServerCanvas;
+class VisualServerViewport;
+class VisualServerScene;
+
+class VisualServerGlobals
+{
+public:
+
+ static RasterizerStorage *storage;
+ static RasterizerCanvas *canvas_render;
+ static RasterizerScene *scene_render;
+ static Rasterizer *rasterizer;
+
+ static VisualServerCanvas *canvas;
+ static VisualServerViewport *viewport;
+ static VisualServerScene *scene;
+};
+
+#define VSG VisualServerGlobals
+
+#endif // VISUALSERVERGLOBAL_H
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 8d228ad859..168afac77f 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -32,8 +32,1280 @@
#include "default_mouse_cursor.xpm"
#include "sort.h"
#include "io/marshalls.h"
+#include "visual_server_canvas.h"
+#include "visual_server_global.h"
+
// careful, these may run in different threads than the visual server
+RID VisualServerRaster::texture_create(){
+
+ return VSG::storage->texture_create();
+}
+void VisualServerRaster::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags){
+
+ VSG::storage->texture_allocate(p_texture,p_width,p_height,p_format,p_flags);
+}
+void VisualServerRaster::texture_set_data(RID p_texture,const Image& p_image,CubeMapSide p_cube_side){
+
+ VSG::storage->texture_set_data(p_texture,p_image,p_cube_side);
+}
+Image VisualServerRaster::texture_get_data(RID p_texture,CubeMapSide p_cube_side) const{
+
+ return VSG::storage->texture_get_data(p_texture,p_cube_side);
+}
+void VisualServerRaster::texture_set_flags(RID p_texture,uint32_t p_flags) {
+
+ VSG::storage->texture_set_flags(p_texture,p_flags);
+}
+uint32_t VisualServerRaster::texture_get_flags(RID p_texture) const{
+
+ return VSG::storage->texture_get_flags(p_texture);
+}
+Image::Format VisualServerRaster::texture_get_format(RID p_texture) const{
+
+ return VSG::storage->texture_get_format(p_texture);
+}
+uint32_t VisualServerRaster::texture_get_width(RID p_texture) const{
+
+ return VSG::storage->texture_get_width(p_texture);
+}
+uint32_t VisualServerRaster::texture_get_height(RID p_texture) const{
+
+ return VSG::storage->texture_get_height(p_texture);
+}
+void VisualServerRaster::texture_set_size_override(RID p_texture,int p_width, int p_height){
+ VSG::storage->texture_set_size_override(p_texture,p_width,p_height);
+
+}
+
+void VisualServerRaster::texture_set_path(RID p_texture,const String& p_path){
+
+ VSG::storage->texture_set_path(p_texture,p_path);
+}
+
+String VisualServerRaster::texture_get_path(RID p_texture) const{
+
+ return VSG::storage->texture_get_path(p_texture);
+}
+
+void VisualServerRaster::texture_set_shrink_all_x2_on_set_data(bool p_enable){
+
+ VSG::storage->texture_set_shrink_all_x2_on_set_data(p_enable);
+}
+
+void VisualServerRaster::texture_debug_usage(List<TextureInfo> *r_info){
+
+ VSG::storage->texture_debug_usage(r_info);
+}
+
+
+/* SHADER API */
+
+
+RID VisualServerRaster::shader_create(ShaderMode p_mode){
+
+ return VSG::storage->shader_create(p_mode);
+}
+
+void VisualServerRaster::shader_set_mode(RID p_shader,ShaderMode p_mode){
+
+ VSG::storage->shader_set_mode(p_shader,p_mode);
+}
+VisualServerRaster::ShaderMode VisualServerRaster::shader_get_mode(RID p_shader) const{
+
+ return VSG::storage->shader_get_mode(p_shader);
+}
+
+void VisualServerRaster::shader_set_code(RID p_shader, const String& p_code){
+
+ VSG::storage->shader_set_code(p_shader,p_code);
+}
+String VisualServerRaster::shader_get_code(RID p_shader) const{
+
+ return VSG::storage->shader_get_code(p_shader);
+}
+void VisualServerRaster::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const{
+
+ VSG::storage->shader_get_param_list(p_shader,p_param_list);
+}
+
+void VisualServerRaster::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture){
+
+ VSG::storage->shader_set_default_texture_param(p_shader,p_name,p_texture);
+}
+RID VisualServerRaster::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
+
+ return VSG::storage->shader_get_default_texture_param(p_shader,p_name);
+}
+
+
+/* COMMON MATERIAL API */
+
+RID VisualServerRaster::material_create(){
+
+ return VSG::storage->material_create();
+}
+
+void VisualServerRaster::material_set_shader(RID p_shader_material, RID p_shader){
+
+ VSG::storage->material_set_shader(p_shader_material,p_shader);
+}
+RID VisualServerRaster::material_get_shader(RID p_shader_material) const{
+
+ return VSG::storage->material_get_shader(p_shader_material);
+}
+
+void VisualServerRaster::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value){
+
+ VSG::storage->material_set_param(p_material,p_param,p_value);
+}
+Variant VisualServerRaster::material_get_param(RID p_material, const StringName& p_param) const{
+
+ return VSG::storage->material_get_param(p_material,p_param);
+}
+
+/* MESH API */
+
+RID VisualServerRaster::mesh_create(){
+
+ return VSG::storage->mesh_create();
+}
+
+void VisualServerRaster::mesh_add_surface(RID p_mesh,uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes){
+
+ VSG::storage->mesh_add_surface(p_mesh,p_format,p_primitive,p_array,p_vertex_count,p_index_array,p_index_count,p_blend_shapes);
+}
+
+void VisualServerRaster::mesh_set_morph_target_count(RID p_mesh,int p_amount){
+
+ VSG::storage->mesh_set_morph_target_count(p_mesh,p_amount);
+}
+int VisualServerRaster::mesh_get_morph_target_count(RID p_mesh) const{
+
+ return VSG::storage->mesh_get_morph_target_count(p_mesh);
+}
+
+
+void VisualServerRaster::mesh_set_morph_target_mode(RID p_mesh,MorphTargetMode p_mode){
+
+ VSG::storage->mesh_set_morph_target_mode(p_mesh,p_mode);
+}
+VisualServerRaster::MorphTargetMode VisualServerRaster::mesh_get_morph_target_mode(RID p_mesh) const{
+
+ return VSG::storage->mesh_get_morph_target_mode(p_mesh);
+}
+
+void VisualServerRaster::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material){
+
+ VSG::storage->mesh_surface_set_material(p_mesh,p_surface,p_material);
+}
+RID VisualServerRaster::mesh_surface_get_material(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_material(p_mesh,p_surface);
+}
+
+int VisualServerRaster::mesh_surface_get_array_len(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_array_len(p_mesh,p_surface);
+}
+int VisualServerRaster::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_array_index_len(p_mesh,p_surface);
+}
+
+DVector<uint8_t> VisualServerRaster::mesh_surface_get_array(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_array(p_mesh,p_surface);
+}
+DVector<uint8_t> VisualServerRaster::mesh_surface_get_index_array(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_index_array(p_mesh,p_surface);
+}
+
+
+uint32_t VisualServerRaster::mesh_surface_get_format(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_format(p_mesh,p_surface);
+}
+VisualServerRaster::PrimitiveType VisualServerRaster::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const{
+
+ return VSG::storage->mesh_surface_get_primitive_type(p_mesh,p_surface);
+}
+
+void VisualServerRaster::mesh_remove_surface(RID p_mesh,int p_index){
+
+ VSG::storage->mesh_remove_surface(p_mesh,p_index);
+}
+int VisualServerRaster::mesh_get_surface_count(RID p_mesh) const{
+
+ return VSG::storage->mesh_get_surface_count(p_mesh);
+}
+
+void VisualServerRaster::mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb){
+
+ VSG::storage->mesh_set_custom_aabb(p_mesh,p_aabb);
+}
+AABB VisualServerRaster::mesh_get_custom_aabb(RID p_mesh) const{
+
+ return VSG::storage->mesh_get_custom_aabb(p_mesh);
+}
+
+void VisualServerRaster::mesh_clear(RID p_mesh){
+
+ VSG::storage->mesh_clear(p_mesh);
+}
+
+/* MULTIMESH API */
+
+
+RID VisualServerRaster::multimesh_create() {
+
+ return VSG::storage->multimesh_create();
+}
+
+void VisualServerRaster::multimesh_allocate(RID p_multimesh,int p_instances,MultimeshTransformFormat p_transform_format,MultimeshColorFormat p_color_format,bool p_gen_aabb){
+
+ VSG::storage->multimesh_allocate(p_multimesh,p_instances,p_transform_format,p_color_format,p_gen_aabb);
+}
+int VisualServerRaster::multimesh_get_instance_count(RID p_multimesh) const{
+
+ return VSG::storage->multimesh_get_instance_count(p_multimesh);
+}
+
+void VisualServerRaster::multimesh_set_mesh(RID p_multimesh,RID p_mesh){
+
+ VSG::storage->multimesh_set_mesh(p_multimesh,p_mesh);
+}
+void VisualServerRaster::multimesh_set_custom_aabb(RID p_multimesh,const AABB& p_aabb){
+
+ VSG::storage->multimesh_set_custom_aabb(p_multimesh,p_aabb);
+}
+void VisualServerRaster::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform){
+
+ VSG::storage->multimesh_instance_set_transform(p_multimesh,p_index,p_transform);
+}
+void VisualServerRaster::multimesh_instance_set_transform_2d(RID p_multimesh,int p_index,const Matrix32& p_transform){
+
+ VSG::storage->multimesh_instance_set_transform_2d(p_multimesh,p_index,p_transform);
+}
+void VisualServerRaster::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color){
+
+ VSG::storage->multimesh_instance_set_color(p_multimesh,p_index,p_color);
+}
+
+RID VisualServerRaster::multimesh_get_mesh(RID p_multimesh) const{
+
+ return VSG::storage->multimesh_get_mesh(p_multimesh);
+}
+AABB VisualServerRaster::multimesh_get_custom_aabb(RID p_multimesh,const AABB& p_aabb) const{
+
+ return VSG::storage->multimesh_get_custom_aabb(p_multimesh,p_aabb);
+}
+
+Transform VisualServerRaster::multimesh_instance_get_transform(RID p_multimesh,int p_index) const{
+
+ return VSG::storage->multimesh_instance_get_transform(p_multimesh,p_index);
+}
+Matrix32 VisualServerRaster::multimesh_instance_get_transform_2d(RID p_multimesh,int p_index) const{
+
+ return VSG::storage->multimesh_instance_get_transform_2d(p_multimesh,p_index);
+}
+Color VisualServerRaster::multimesh_instance_get_color(RID p_multimesh,int p_index) const{
+
+ return VSG::storage->multimesh_instance_get_color(p_multimesh,p_index);
+}
+
+void VisualServerRaster::multimesh_set_visible_instances(RID p_multimesh,int p_visible){
+
+ VSG::storage->multimesh_set_visible_instances(p_multimesh,p_visible);
+}
+int VisualServerRaster::multimesh_get_visible_instances(RID p_multimesh) const{
+
+ return VSG::storage->multimesh_get_visible_instances(p_multimesh);
+}
+
+
+/* IMMEDIATE API */
+
+RID VisualServerRaster::immediate_create(){
+
+ return VSG::storage->immediate_create();
+}
+void VisualServerRaster::immediate_begin(RID p_immediate,PrimitiveType p_rimitive,RID p_texture){
+
+ VSG::storage->immediate_begin(p_immediate,p_rimitive,p_texture);
+}
+void VisualServerRaster::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
+
+ VSG::storage->immediate_vertex(p_immediate,p_vertex);
+}
+void VisualServerRaster::immediate_vertex_2d(RID p_immediate,const Vector3& p_vertex){
+
+ VSG::storage->immediate_vertex_2d(p_immediate,p_vertex);
+
+}
+void VisualServerRaster::immediate_normal(RID p_immediate,const Vector3& p_normal){
+
+ VSG::storage->immediate_normal(p_immediate,p_normal);
+
+}
+void VisualServerRaster::immediate_tangent(RID p_immediate,const Plane& p_tangent){
+
+ VSG::storage->immediate_tangent(p_immediate,p_tangent);
+}
+void VisualServerRaster::immediate_color(RID p_immediate,const Color& p_color){
+
+ VSG::storage->immediate_color(p_immediate,p_color);
+
+}
+void VisualServerRaster::immediate_uv(RID p_immediate,const Vector2& tex_uv){
+
+ VSG::storage->immediate_uv(p_immediate,tex_uv);
+
+}
+void VisualServerRaster::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
+
+ VSG::storage->immediate_uv2(p_immediate,tex_uv);
+
+}
+void VisualServerRaster::immediate_end(RID p_immediate){
+
+ VSG::storage->immediate_end(p_immediate);
+
+}
+void VisualServerRaster::immediate_clear(RID p_immediate){
+
+ VSG::storage->immediate_clear(p_immediate);
+
+}
+void VisualServerRaster::immediate_set_material(RID p_immediate,RID p_material){
+
+ VSG::storage->immediate_set_material(p_immediate,p_material);
+
+}
+RID VisualServerRaster::immediate_get_material(RID p_immediate) const{
+
+ return VSG::storage->immediate_get_material(p_immediate);
+}
+
+/* SKELETON API */
+
+RID VisualServerRaster::skeleton_create(){
+
+ return VSG::storage->skeleton_create();
+}
+void VisualServerRaster::skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton){
+
+ VSG::storage->skeleton_allocate(p_skeleton,p_bones,p_2d_skeleton);
+}
+int VisualServerRaster::skeleton_get_bone_count(RID p_skeleton) const{
+
+ return VSG::storage->skeleton_get_bone_count(p_skeleton);
+}
+void VisualServerRaster::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform){
+
+ VSG::storage->skeleton_bone_set_transform(p_skeleton,p_bone,p_transform);
+}
+Transform VisualServerRaster::skeleton_bone_get_transform(RID p_skeleton,int p_bone){
+
+ return VSG::storage->skeleton_bone_get_transform(p_skeleton,p_bone);
+}
+void VisualServerRaster::skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Matrix32& p_transform){
+
+ VSG::storage->skeleton_bone_set_transform_2d(p_skeleton,p_bone,p_transform);
+}
+Matrix32 VisualServerRaster::skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone){
+
+ return VSG::storage->skeleton_bone_get_transform_2d(p_skeleton,p_bone);
+}
+
+/* Light API */
+
+RID VisualServerRaster::light_create(LightType p_type){
+
+ return VSG::storage->light_create(p_type);
+}
+
+void VisualServerRaster::light_set_color(RID p_light,const Color& p_color){
+
+ VSG::storage->light_set_color(p_light,p_color);
+}
+void VisualServerRaster::light_set_param(RID p_light,LightParam p_param,float p_value){
+
+ VSG::storage->light_set_param(p_light,p_param,p_value);
+}
+void VisualServerRaster::light_set_shadow(RID p_light,bool p_enabled){
+
+ VSG::storage->light_set_shadow(p_light,p_enabled);
+}
+void VisualServerRaster::light_set_projector(RID p_light,RID p_texture){
+
+ VSG::storage->light_set_projector(p_light,p_texture);
+}
+void VisualServerRaster::light_set_attenuation_texure(RID p_light,RID p_texture){
+
+ VSG::storage->light_set_attenuation_texure(p_light,p_texture);
+}
+void VisualServerRaster::light_set_negative(RID p_light,bool p_enable){
+
+ VSG::storage->light_set_negative(p_light,p_enable);
+}
+void VisualServerRaster::light_set_cull_mask(RID p_light,uint32_t p_mask){
+
+ VSG::storage->light_set_cull_mask(p_light,p_mask);
+}
+void VisualServerRaster::light_set_shader(RID p_light,RID p_shader){
+
+ VSG::storage->light_set_shader(p_light,p_shader);
+}
+
+
+void VisualServerRaster::light_directional_set_shadow_mode(RID p_light,LightDirectionalShadowMode p_mode){
+
+ VSG::storage->light_directional_set_shadow_mode(p_light,p_mode);
+}
+
+/* PROBE API */
+
+RID VisualServerRaster::reflection_probe_create(){
+
+ return VSG::storage->reflection_probe_create();
+}
+
+void VisualServerRaster::reflection_probe_set_intensity(RID p_probe, float p_intensity){
+
+ VSG::storage->reflection_probe_set_intensity(p_probe,p_intensity);
+}
+void VisualServerRaster::reflection_probe_set_clip(RID p_probe, float p_near, float p_far){
+
+ VSG::storage->reflection_probe_set_clip(p_probe,p_near,p_far);
+}
+void VisualServerRaster::reflection_probe_set_min_blend_distance(RID p_probe, float p_distance){
+
+ VSG::storage->reflection_probe_set_min_blend_distance(p_probe,p_distance);
+}
+void VisualServerRaster::reflection_probe_set_extents(RID p_probe, const Vector3& p_extents){
+
+ VSG::storage->reflection_probe_set_extents(p_probe,p_extents);
+}
+void VisualServerRaster::reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset){
+
+ VSG::storage->reflection_probe_set_origin_offset(p_probe,p_offset);
+}
+void VisualServerRaster::reflection_probe_set_enable_parallax_correction(RID p_probe, bool p_enable){
+
+ VSG::storage->reflection_probe_set_enable_parallax_correction(p_probe,p_enable);
+}
+void VisualServerRaster::reflection_probe_set_resolution(RID p_probe, int p_resolution){
+
+ VSG::storage->reflection_probe_set_resolution(p_probe,p_resolution);
+}
+void VisualServerRaster::reflection_probe_set_hide_skybox(RID p_probe, bool p_hide){
+
+ VSG::storage->reflection_probe_set_hide_skybox(p_probe,p_hide);
+}
+void VisualServerRaster::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers){
+
+ VSG::storage->reflection_probe_set_cull_mask(p_probe,p_layers);
+}
+
+
+/* ROOM API */
+
+RID VisualServerRaster::room_create(){
+
+ return VSG::storage->room_create();
+}
+void VisualServerRaster::room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform){
+
+ VSG::storage->room_add_bounds(p_room,p_convex_polygon,p_height,p_transform);
+}
+void VisualServerRaster::room_clear_bounds(){
+
+ VSG::storage->room_clear_bounds();
+}
+
+/* PORTAL API */
+
+// portals are only (x/y) points, forming a convex shape, which its clockwise
+// order points outside. (z is 0);
+
+RID VisualServerRaster::portal_create(){
+
+ return VSG::storage->portal_create();
+}
+void VisualServerRaster::portal_set_shape(RID p_portal, const Vector<Point2>& p_shape){
+
+ VSG::storage->portal_set_shape(p_portal,p_shape);
+}
+void VisualServerRaster::portal_set_enabled(RID p_portal, bool p_enabled) {
+
+ VSG::storage->portal_set_enabled(p_portal,p_enabled);
+}
+void VisualServerRaster::portal_set_disable_distance(RID p_portal, float p_distance){
+
+ VSG::storage->portal_set_disable_distance(p_portal,p_distance);
+}
+void VisualServerRaster::portal_set_disabled_color(RID p_portal, const Color& p_color){
+
+ VSG::storage->portal_set_disabled_color(p_portal,p_color);
+}
+
+/* CAMERA API */
+
+RID VisualServerRaster::camera_create() {
+
+ return RID();
+}
+void VisualServerRaster::camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far) {
+
+}
+void VisualServerRaster::camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far){
+
+}
+void VisualServerRaster::camera_set_transform(RID p_camera,const Transform& p_transform) {
+
+}
+void VisualServerRaster::camera_set_cull_mask(RID p_camera,uint32_t p_layers){
+
+}
+void VisualServerRaster::camera_set_environment(RID p_camera,RID p_env){
+
+}
+void VisualServerRaster::camera_set_use_vertical_aspect(RID p_camera,bool p_enable){
+
+}
+
+
+/* VIEWPORT TARGET API */
+
+RID VisualServerRaster::viewport_create(){
+
+ return VSG::viewport->viewport_create();
+}
+
+void VisualServerRaster::viewport_set_size(RID p_viewport,int p_width,int p_height){
+
+ VSG::viewport->viewport_set_size(p_viewport,p_width,p_height);
+}
+
+void VisualServerRaster::viewport_set_active(RID p_viewport,bool p_active) {
+
+ VSG::viewport->viewport_set_active(p_viewport,p_active);
+}
+
+void VisualServerRaster::viewport_set_clear_mode(RID p_viewport,ViewportClearMode p_clear_mode) {
+
+ VSG::viewport->viewport_set_clear_mode(p_viewport,p_clear_mode);
+}
+
+void VisualServerRaster::viewport_attach_to_screen(RID p_viewport,const Rect2& p_rect,int p_screen){
+
+ VSG::viewport->viewport_attach_to_screen(p_viewport,p_rect,p_screen);
+
+}
+void VisualServerRaster::viewport_detach(RID p_viewport){
+
+ VSG::viewport->viewport_detach(p_viewport);
+
+}
+
+void VisualServerRaster::viewport_set_update_mode(RID p_viewport,ViewportUpdateMode p_mode){
+
+ VSG::viewport->viewport_set_update_mode(p_viewport,p_mode);
+
+}
+void VisualServerRaster::viewport_set_vflip(RID p_viewport,bool p_enable){
+
+ VSG::viewport->viewport_set_vflip(p_viewport,p_enable);
+
+}
+
+RID VisualServerRaster::viewport_get_texture(RID p_viewport) const{
+
+ return VSG::viewport->viewport_get_texture(p_viewport);
+
+}
+Image VisualServerRaster::viewport_capture(RID p_viewport) const{
+
+ return VSG::viewport->viewport_capture(p_viewport);
+}
+
+void VisualServerRaster::viewport_set_hide_scenario(RID p_viewport,bool p_hide){
+
+ return VSG::viewport->viewport_set_hide_scenario(p_viewport,p_hide);
+}
+void VisualServerRaster::viewport_set_hide_canvas(RID p_viewport,bool p_hide){
+
+ return VSG::viewport->viewport_set_hide_canvas(p_viewport,p_hide);
+
+}
+void VisualServerRaster::viewport_set_disable_environment(RID p_viewport,bool p_disable){
+
+ return VSG::viewport->viewport_set_disable_environment(p_viewport,p_disable);
+
+}
+
+void VisualServerRaster::viewport_attach_camera(RID p_viewport,RID p_camera){
+
+ return VSG::viewport->viewport_attach_camera(p_viewport,p_camera);
+
+}
+void VisualServerRaster::viewport_set_scenario(RID p_viewport,RID p_scenario){
+
+ return VSG::viewport->viewport_set_scenario(p_viewport,p_scenario);
+
+}
+void VisualServerRaster::viewport_attach_canvas(RID p_viewport,RID p_canvas){
+
+ return VSG::viewport->viewport_attach_canvas(p_viewport,p_canvas);
+
+}
+void VisualServerRaster::viewport_remove_canvas(RID p_viewport,RID p_canvas){
+
+ return VSG::viewport->viewport_remove_canvas(p_viewport,p_canvas);
+
+}
+void VisualServerRaster::viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset){
+
+ return VSG::viewport->viewport_set_canvas_transform(p_viewport,p_canvas,p_offset);
+
+}
+void VisualServerRaster::viewport_set_transparent_background(RID p_viewport,bool p_enabled){
+
+ return VSG::viewport->viewport_set_transparent_background(p_viewport,p_enabled);
+
+}
+
+void VisualServerRaster::viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform){
+
+ return VSG::viewport->viewport_set_global_canvas_transform(p_viewport,p_transform);
+
+}
+void VisualServerRaster::viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer){
+
+ return VSG::viewport->viewport_set_canvas_layer(p_viewport,p_canvas,p_layer);
+
+}
+
+
+/* ENVIRONMENT API */
+
+RID VisualServerRaster::environment_create(){
+
+ return RID();
+}
+
+void VisualServerRaster::environment_set_background(RID p_env,EnvironmentBG p_bg){
+
+}
+void VisualServerRaster::environment_set_skybox(RID p_env,RID p_skybox,float p_energy){
+
+}
+void VisualServerRaster::environment_set_bg_color(RID p_env,const Color& p_color){
+
+}
+void VisualServerRaster::environment_set_canvas_max_layer(RID p_env,int p_max_layer){
+
+}
+void VisualServerRaster::environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy){
+
+}
+
+void VisualServerRaster::environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,EnvironmentGlowBlendMode p_blend_mode){
+
+}
+void VisualServerRaster::environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture){
+
+}
+
+void VisualServerRaster::environment_set_tonemap(RID p_env,bool p_enable,float p_exposure,float p_white,float p_min_luminance,float p_max_luminance,float p_auto_exp_speed,EnvironmentToneMapper p_tone_mapper){
+
+}
+void VisualServerRaster::environment_set_brightness(RID p_env,bool p_enable,float p_brightness){
+
+}
+void VisualServerRaster::environment_set_contrast(RID p_env,bool p_enable,float p_contrast){
+
+}
+void VisualServerRaster::environment_set_saturation(RID p_env,bool p_enable,float p_saturation){
+
+}
+void VisualServerRaster::environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp){
+
+}
+
+
+/* SCENARIO API */
+
+
+RID VisualServerRaster::scenario_create() {
+
+ return RID();
+}
+
+void VisualServerRaster::scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode){
+
+}
+void VisualServerRaster::scenario_set_environment(RID p_scenario, RID p_environment){
+
+}
+RID VisualServerRaster::scenario_get_environment(RID p_scenario, RID p_environment) const{
+
+ return RID();
+}
+void VisualServerRaster::scenario_set_fallback_environment(RID p_scenario, RID p_environment){
+
+}
+
+
+/* INSTANCING API */
+// from can be mesh, light, area and portal so far.
+RID VisualServerRaster::instance_create(){
+
+ return RID();
+}
+
+void VisualServerRaster::instance_set_base(RID p_instance, RID p_base){
+
+}
+void VisualServerRaster::instance_set_scenario(RID p_instance, RID p_scenario){
+
+}
+void VisualServerRaster::instance_set_layer_mask(RID p_instance, uint32_t p_mask){
+
+}
+void VisualServerRaster::instance_set_transform(RID p_instance, const Transform& p_transform){
+
+}
+void VisualServerRaster::instance_attach_object_instance_ID(RID p_instance,ObjectID p_ID){
+
+}
+void VisualServerRaster::instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight){
+
+}
+void VisualServerRaster::instance_set_surface_material(RID p_instance,int p_surface, RID p_material){
+
+}
+
+void VisualServerRaster::instance_attach_skeleton(RID p_instance,RID p_skeleton){
+
+}
+void VisualServerRaster::instance_set_exterior( RID p_instance, bool p_enabled ){
+
+}
+void VisualServerRaster::instance_set_room( RID p_instance, RID p_room ){
+
+}
+
+void VisualServerRaster::instance_set_extra_visibility_margin( RID p_instance, real_t p_margin ){
+
+}
+
+// don't use these in a game!
+Vector<ObjectID> VisualServerRaster::instances_cull_aabb(const AABB& p_aabb, RID p_scenario) const{
+
+ return Vector<ObjectID>();
+}
+
+Vector<ObjectID> VisualServerRaster::instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario) const{
+
+ return Vector<ObjectID>();
+}
+Vector<ObjectID> VisualServerRaster::instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario) const {
+
+ return Vector<ObjectID>();
+}
+
+
+void VisualServerRaster::instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled){
+
+}
+void VisualServerRaster::instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting) {
+
+}
+void VisualServerRaster::instance_geometry_set_material_override(RID p_instance, RID p_material){
+
+}
+
+
+void VisualServerRaster::instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max,float p_min_margin,float p_max_margin){
+
+}
+void VisualServerRaster::instance_geometry_set_as_instance_lod(RID p_instance,RID p_as_lod_of_instance){
+
+}
+
+/* CANVAS (2D) */
+
+RID VisualServerRaster::canvas_create(){
+
+ return VSG::canvas->canvas_create();
+
+}
+void VisualServerRaster::canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring){
+
+ VSG::canvas->canvas_set_item_mirroring(p_canvas,p_item,p_mirroring);
+}
+void VisualServerRaster::canvas_set_modulate(RID p_canvas,const Color& p_color){
+
+ VSG::canvas->canvas_set_modulate(p_canvas,p_color);
+}
+
+
+RID VisualServerRaster::canvas_item_create(){
+
+ return VSG::canvas->canvas_item_create();
+}
+void VisualServerRaster::canvas_item_set_parent(RID p_item,RID p_parent){
+
+ VSG::canvas->canvas_item_set_parent(p_item,p_parent);
+
+}
+
+void VisualServerRaster::canvas_item_set_visible(RID p_item,bool p_visible){
+
+ VSG::canvas->canvas_item_set_visible(p_item,p_visible);
+
+}
+void VisualServerRaster::canvas_item_set_light_mask(RID p_item,int p_mask){
+
+ VSG::canvas->canvas_item_set_light_mask(p_item,p_mask);
+
+}
+
+void VisualServerRaster::canvas_item_set_transform(RID p_item, const Matrix32& p_transform){
+
+ VSG::canvas->canvas_item_set_transform(p_item,p_transform);
+
+}
+void VisualServerRaster::canvas_item_set_clip(RID p_item, bool p_clip){
+
+ VSG::canvas->canvas_item_set_clip(p_item,p_clip);
+
+}
+void VisualServerRaster::canvas_item_set_distance_field_mode(RID p_item, bool p_enable){
+
+ VSG::canvas->canvas_item_set_distance_field_mode(p_item,p_enable);
+
+}
+void VisualServerRaster::canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect){
+
+ VSG::canvas->canvas_item_set_custom_rect(p_item,p_custom_rect,p_rect);
+
+}
+void VisualServerRaster::canvas_item_set_modulate(RID p_item, const Color& p_color){
+
+ VSG::canvas->canvas_item_set_modulate(p_item,p_color);
+
+}
+void VisualServerRaster::canvas_item_set_self_modulate(RID p_item, const Color& p_color){
+
+ VSG::canvas->canvas_item_set_self_modulate(p_item,p_color);
+
+}
+
+void VisualServerRaster::canvas_item_set_draw_behind_parent(RID p_item, bool p_enable){
+
+ VSG::canvas->canvas_item_set_draw_behind_parent(p_item,p_enable);
+
+}
+
+
+void VisualServerRaster::canvas_item_add_line(RID p_item, const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width,bool p_antialiased){
+
+ VSG::canvas->canvas_item_add_line(p_item,p_from,p_to,p_color,p_width,p_antialiased);
+
+}
+void VisualServerRaster::canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color){
+
+ VSG::canvas->canvas_item_add_rect(p_item,p_rect,p_color);
+
+}
+void VisualServerRaster::canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color){
+
+ VSG::canvas->canvas_item_add_circle(p_item,p_pos,p_radius,p_color);
+
+}
+void VisualServerRaster::canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile,const Color& p_modulate,bool p_transpose){
+
+ VSG::canvas->canvas_item_add_texture_rect(p_item,p_rect,p_texture,p_tile,p_modulate,p_transpose);
+
+}
+void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate,bool p_transpose){
+
+ VSG::canvas->canvas_item_add_texture_rect_region(p_item,p_rect,p_texture,p_src_rect,p_modulate,p_transpose);
+
+}
+void VisualServerRaster::canvas_item_add_nine_patch(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright,NinePatchAxisMode p_x_axis_mode, NinePatchAxisMode p_y_axis_mode,bool p_draw_center,const Color& p_modulate){
+
+ VSG::canvas->canvas_item_add_nine_patch(p_item,p_rect,p_source,p_texture,p_topleft,p_bottomright,p_x_axis_mode,p_y_axis_mode,p_draw_center,p_modulate);
+
+}
+void VisualServerRaster::canvas_item_add_primitive(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width){
+
+ VSG::canvas->canvas_item_add_primitive(p_item,p_points,p_colors,p_uvs,p_texture,p_width);
+
+}
+void VisualServerRaster::canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture){
+
+ VSG::canvas->canvas_item_add_polygon(p_item,p_points,p_colors,p_uvs,p_texture);
+
+}
+void VisualServerRaster::canvas_item_add_triangle_array(RID p_item, const Vector<int>& p_indices, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture, int p_count){
+
+ VSG::canvas->canvas_item_add_triangle_array(p_item,p_indices,p_points,p_colors,p_uvs,p_texture,p_count);
+
+}
+void VisualServerRaster::canvas_item_add_mesh(RID p_item, const RID& p_mesh,RID p_skeleton){
+
+ VSG::canvas->canvas_item_add_mesh(p_item,p_mesh,p_skeleton);
+
+}
+void VisualServerRaster::canvas_item_add_multimesh(RID p_item, RID p_mesh,RID p_skeleton){
+
+ VSG::canvas->canvas_item_add_multimesh(p_item,p_mesh,p_skeleton);
+
+}
+void VisualServerRaster::canvas_item_add_set_transform(RID p_item,const Matrix32& p_transform){
+
+ VSG::canvas->canvas_item_add_set_transform(p_item,p_transform);
+
+}
+void VisualServerRaster::canvas_item_add_clip_ignore(RID p_item, bool p_ignore){
+
+ VSG::canvas->canvas_item_add_clip_ignore(p_item,p_ignore);
+
+}
+void VisualServerRaster::canvas_item_set_sort_children_by_y(RID p_item, bool p_enable){
+
+ VSG::canvas->canvas_item_set_sort_children_by_y(p_item,p_enable);
+
+}
+void VisualServerRaster::canvas_item_set_z(RID p_item, int p_z){
+
+ VSG::canvas->canvas_item_set_z(p_item,p_z);
+
+}
+void VisualServerRaster::canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable){
+
+ VSG::canvas->canvas_item_set_z_as_relative_to_parent(p_item,p_enable);
+
+}
+void VisualServerRaster::canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect){
+
+ VSG::canvas->canvas_item_set_copy_to_backbuffer(p_item,p_enable,p_rect);
+
+}
+
+void VisualServerRaster::canvas_item_clear(RID p_item){
+
+ VSG::canvas->canvas_item_clear(p_item);
+
+}
+void VisualServerRaster::canvas_item_set_draw_index(RID p_item,int p_index){
+
+ VSG::canvas->canvas_item_set_draw_index(p_item,p_index);
+
+}
+
+void VisualServerRaster::canvas_item_set_material(RID p_item, RID p_material){
+
+ VSG::canvas->canvas_item_set_material(p_item,p_material);
+
+}
+
+void VisualServerRaster::canvas_item_set_use_parent_material(RID p_item, bool p_enable) {
+
+ VSG::canvas->canvas_item_set_use_parent_material(p_item,p_enable);
+}
+
+RID VisualServerRaster::canvas_light_create(){
+
+ return VSG::canvas->canvas_light_create();
+}
+
+void VisualServerRaster::canvas_light_attach_to_canvas(RID p_light,RID p_canvas){
+
+ VSG::canvas->canvas_light_attach_to_canvas(p_light,p_canvas);
+
+}
+void VisualServerRaster::canvas_light_set_enabled(RID p_light, bool p_enabled){
+
+ VSG::canvas->canvas_light_set_enabled(p_light,p_enabled);
+
+}
+void VisualServerRaster::canvas_light_set_scale(RID p_light, float p_scale){
+
+ VSG::canvas->canvas_light_set_scale(p_light,p_scale);
+
+}
+void VisualServerRaster::canvas_light_set_transform(RID p_light, const Matrix32& p_transform){
+
+ VSG::canvas->canvas_light_set_transform(p_light,p_transform);
+
+}
+void VisualServerRaster::canvas_light_set_texture(RID p_light, RID p_texture){
+
+ VSG::canvas->canvas_light_set_texture(p_light,p_texture);
+
+}
+void VisualServerRaster::canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset){
+
+ VSG::canvas->canvas_light_set_texture_offset(p_light,p_offset);
+
+}
+void VisualServerRaster::canvas_light_set_color(RID p_light, const Color& p_color){
+
+ VSG::canvas->canvas_light_set_color(p_light,p_color);
+
+}
+void VisualServerRaster::canvas_light_set_height(RID p_light, float p_height){
+
+ VSG::canvas->canvas_light_set_height(p_light,p_height);
+
+}
+void VisualServerRaster::canvas_light_set_energy(RID p_light, float p_energy){
+
+ VSG::canvas->canvas_light_set_energy(p_light,p_energy);
+
+}
+void VisualServerRaster::canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z){
+
+ VSG::canvas->canvas_light_set_z_range(p_light,p_min_z,p_max_z);
+
+}
+void VisualServerRaster::canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer){
+
+ VSG::canvas->canvas_light_set_layer_range(p_light,p_min_layer,p_max_layer);
+
+}
+void VisualServerRaster::canvas_light_set_item_cull_mask(RID p_light, int p_mask){
+
+ VSG::canvas->canvas_light_set_item_cull_mask(p_light,p_mask);
+
+}
+void VisualServerRaster::canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask){
+
+ VSG::canvas->canvas_light_set_item_shadow_cull_mask(p_light,p_mask);
+
+}
+
+void VisualServerRaster::canvas_light_set_mode(RID p_light, CanvasLightMode p_mode){
+
+ VSG::canvas->canvas_light_set_mode(p_light,p_mode);
+
+}
+
+
+void VisualServerRaster::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled) {
+
+ VSG::canvas->canvas_light_set_shadow_enabled(p_light,p_enabled);
+
+}
+void VisualServerRaster::canvas_light_set_shadow_buffer_size(RID p_light, int p_size) {
+
+ VSG::canvas->canvas_light_set_shadow_buffer_size(p_light,p_size);
+
+}
+void VisualServerRaster::canvas_light_set_shadow_gradient_length(RID p_light, float p_length) {
+
+ VSG::canvas->canvas_light_set_shadow_gradient_length(p_light,p_length);
+
+}
+void VisualServerRaster::canvas_light_set_shadow_filter(RID p_light, CanvasLightShadowFilter p_filter){
+
+ VSG::canvas->canvas_light_set_shadow_filter(p_light,p_filter);
+
+}
+void VisualServerRaster::canvas_light_set_shadow_color(RID p_light, const Color& p_color){
+
+ VSG::canvas->canvas_light_set_shadow_color(p_light,p_color);
+
+}
+
+
+
+RID VisualServerRaster::canvas_light_occluder_create() {
+
+ return VSG::canvas->canvas_light_occluder_create();
+}
+
+void VisualServerRaster::canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas){
+
+ VSG::canvas->canvas_light_occluder_attach_to_canvas(p_occluder,p_canvas);
+
+}
+void VisualServerRaster::canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled) {
+
+ VSG::canvas->canvas_light_occluder_set_enabled(p_occluder,p_enabled);
+
+}
+void VisualServerRaster::canvas_light_occluder_set_polygon(RID p_occluder,RID p_polygon){
+
+ VSG::canvas->canvas_light_occluder_set_polygon(p_occluder,p_polygon);
+
+}
+void VisualServerRaster::canvas_light_occluder_set_transform(RID p_occluder,const Matrix32& p_xform){
+
+ VSG::canvas->canvas_light_occluder_set_transform(p_occluder,p_xform);
+
+}
+void VisualServerRaster::canvas_light_occluder_set_light_mask(RID p_occluder,int p_mask){
+
+ VSG::canvas->canvas_light_occluder_set_light_mask(p_occluder,p_mask);
+
+}
+
+RID VisualServerRaster::canvas_occluder_polygon_create() {
+
+ return VSG::canvas->canvas_occluder_polygon_create();
+}
+void VisualServerRaster::canvas_occluder_polygon_set_shape(RID p_occluder_polygon,const DVector<Vector2>& p_shape,bool p_closed){
+
+ VSG::canvas->canvas_occluder_polygon_set_shape(p_occluder_polygon,p_shape,p_closed);
+}
+void VisualServerRaster::canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon,const DVector<Vector2>& p_shape){
+
+ VSG::canvas->canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon,p_shape);
+
+}
+
+
+void VisualServerRaster::canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon,CanvasOccluderPolygonCullMode p_mode){
+
+ VSG::canvas->canvas_occluder_polygon_set_cull_mode(p_occluder_polygon,p_mode);
+
+}
+
+
+/* CURSOR */
+void VisualServerRaster::cursor_set_rotation(float p_rotation, int p_cursor ){
+
+}
+void VisualServerRaster::cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor, const Rect2 &p_region){
+
+}
+void VisualServerRaster::cursor_set_visible(bool p_visible, int p_cursor ){
+
+}
+void VisualServerRaster::cursor_set_pos(const Point2& p_pos, int p_cursor ){
+
+}
+
+/* BLACK BARS */
+
+
+void VisualServerRaster::black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom){
+
+}
+void VisualServerRaster::black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom){
+
+}
+
+
+/* FREE */
+
+void VisualServerRaster::free( RID p_rid ){
+
+ if (VSG::storage->free(p_rid))
+ return;
+ if (VSG::canvas->free(p_rid))
+ return;
+ if (VSG::viewport->free(p_rid))
+ return;
+
+}
+
+/* EVENT QUEUING */
+
+void VisualServerRaster::draw(){
+
+ //if (changes)
+ // print_line("changes: "+itos(changes));
+
+// changes=0;
+ VSG::rasterizer->begin_frame();
+ VSG::viewport->draw_viewports();
+ //_draw_cursors_and_margins();
+ VSG::rasterizer->end_frame();
+ //draw_extra_frame=VS:rasterizer->needs_to_draw_next_frame();
+}
+void VisualServerRaster::sync(){
+
+}
+bool VisualServerRaster::has_changed() const{
+
+ return false;
+}
+void VisualServerRaster::init(){
+
+ VSG::rasterizer->initialize();
+
+}
+void VisualServerRaster::finish(){
+
+ if (test_cube.is_valid()) {
+ free(test_cube);
+ }
+
+ VSG::rasterizer->finalize();
+}
+
+/* STATUS INFORMATION */
+
+
+int VisualServerRaster::get_render_info(RenderInfo p_info){
+
+ return 0;
+}
+
+
+
+/* TESTING */
+
+
+
+void VisualServerRaster::set_boot_image(const Image& p_image, const Color& p_color,bool p_scale){
+
+}
+void VisualServerRaster::set_default_clear_color(const Color& p_color){
+
+}
+
+bool VisualServerRaster::has_feature(Features p_feature) const {
+
+ return false;
+}
+
+RID VisualServerRaster::get_test_cube() {
+ if (!test_cube.is_valid()) {
+ test_cube=_make_test_cube();
+ }
+ return test_cube;
+}
+
+VisualServerRaster::VisualServerRaster() {
+
+ VSG::canvas = memnew( VisualServerCanvas);
+ VSG::viewport = memnew( VisualServerViewport);
+ VSG::rasterizer = Rasterizer::create();
+ VSG::storage=VSG::rasterizer->get_storage();
+ VSG::canvas_render=VSG::rasterizer->get_canvas();
+ VSG::scene_render=VSG::rasterizer->get_scene();
+
+}
+
+VisualServerRaster::~VisualServerRaster() {
+
+ memdelete(VSG::canvas);
+ memdelete(VSG::viewport);
+ memdelete(VSG::rasterizer);
+}
+
+
+#if 0
+
BalloonAllocator<> *VisualServerRaster::OctreeAllocator::allocator=NULL;
#define VS_CHANGED\
@@ -1146,7 +2418,7 @@ void VisualServerRaster::baked_light_set_octree(RID p_baked_light,const DVector<
if (p_octree.size()==0) {
if (baked_light->data.octree_texture.is_valid())
rasterizer->free(baked_light->data.octree_texture);
- baked_light->data.octree_texture=RID();
+ baked_light->data.octree_texture;
baked_light->octree_aabb=AABB();
baked_light->octree_tex_size=Size2();
} else {
@@ -1203,7 +2475,7 @@ void VisualServerRaster::baked_light_set_octree(RID p_baked_light,const DVector<
if (tex_w!=baked_light->octree_tex_size.x || tex_h!=baked_light->octree_tex_size.y) {
rasterizer->free(baked_light->data.octree_texture);
- baked_light->data.octree_texture=RID();
+ baked_light->data.octree_texture;
baked_light->octree_tex_size.x=0;
baked_light->octree_tex_size.y=0;
}
@@ -1212,7 +2484,7 @@ void VisualServerRaster::baked_light_set_octree(RID p_baked_light,const DVector<
if (baked_light->data.light_texture.is_valid()) {
if (!has_light_tex || light_tex_w!=baked_light->light_tex_size.x || light_tex_h!=baked_light->light_tex_size.y) {
rasterizer->free(baked_light->data.light_texture);
- baked_light->data.light_texture=RID();
+ baked_light->data.light_texture;
baked_light->light_tex_size.x=0;
baked_light->light_tex_size.y=0;
}
@@ -1220,20 +2492,20 @@ void VisualServerRaster::baked_light_set_octree(RID p_baked_light,const DVector<
if (!baked_light->data.octree_texture.is_valid()) {
baked_light->data.octree_texture=rasterizer->texture_create();
- rasterizer->texture_allocate(baked_light->data.octree_texture,tex_w,tex_h,Image::FORMAT_RGBA,TEXTURE_FLAG_FILTER);
+ rasterizer->texture_allocate(baked_light->data.octree_texture,tex_w,tex_h,Image::FORMAT_RGBA8,TEXTURE_FLAG_FILTER);
baked_light->octree_tex_size.x=tex_w;
baked_light->octree_tex_size.y=tex_h;
}
if (!baked_light->data.light_texture.is_valid() && has_light_tex) {
baked_light->data.light_texture=rasterizer->texture_create();
- rasterizer->texture_allocate(baked_light->data.light_texture,light_tex_w,light_tex_h,Image::FORMAT_RGBA,TEXTURE_FLAG_FILTER);
+ rasterizer->texture_allocate(baked_light->data.light_texture,light_tex_w,light_tex_h,Image::FORMAT_RGBA8,TEXTURE_FLAG_FILTER);
baked_light->light_tex_size.x=light_tex_w;
baked_light->light_tex_size.y=light_tex_h;
}
- Image img(tex_w,tex_h,0,Image::FORMAT_RGBA,p_octree);
+ Image img(tex_w,tex_h,0,Image::FORMAT_RGBA8,p_octree);
rasterizer->texture_set_data(baked_light->data.octree_texture,img);
}
@@ -1276,7 +2548,7 @@ void VisualServerRaster::baked_light_set_light(RID p_baked_light,const DVector<u
print_line("w: "+itos(tex_w)+" h: "+itos(tex_h)+" lightsize: "+itos(p_light.size()));
- Image img(tex_w,tex_h,0,Image::FORMAT_RGBA,p_light);
+ Image img(tex_w,tex_h,0,Image::FORMAT_RGBA8,p_light);
rasterizer->texture_set_data(baked_light->data.light_texture,img);
@@ -1611,8 +2883,8 @@ void VisualServerRaster::viewport_set_as_render_target(RID p_viewport,bool p_ena
if (!p_enable) {
rasterizer->free(viewport->render_target);
- viewport->render_target=RID();
- viewport->render_target_texture=RID();
+ viewport->render_target;
+ viewport->render_target_texture;
if (viewport->update_list.in_list())
viewport_update_list.remove(&viewport->update_list);
@@ -1811,7 +3083,7 @@ void VisualServerRaster::viewport_attach_camera(RID p_viewport,RID p_camera) {
// a camera
viewport->camera=p_camera;
} else {
- viewport->camera=RID();
+ viewport->camera;
}
}
@@ -1830,7 +3102,7 @@ void VisualServerRaster::viewport_set_scenario(RID p_viewport,RID p_scenario) {
// a camera
viewport->scenario=p_scenario;
} else {
- viewport->scenario=RID();
+ viewport->scenario;
}
}
@@ -2284,7 +3556,7 @@ void VisualServerRaster::instance_set_base(RID p_instance, RID p_base) {
instance->base_type=INSTANCE_NONE;
- instance->base_rid=RID();
+ instance->base_rid;
if (p_base.is_valid()) {
@@ -3003,7 +4275,7 @@ void VisualServerRaster::instance_geometry_set_baked_light_sampler(RID p_instanc
if (instance->sampled_light) {
instance->sampled_light->baked_light_sampler_info->owned_instances.erase(instance);
- instance->data.sampled_light=RID();
+ instance->data.sampled_light;
}
if(p_baked_light_sampler.is_valid()) {
@@ -3016,7 +4288,7 @@ void VisualServerRaster::instance_geometry_set_baked_light_sampler(RID p_instanc
instance->sampled_light=NULL;
}
- instance->data.sampled_light=RID();
+ instance->data.sampled_light;
}
@@ -3432,7 +4704,7 @@ void VisualServerRaster::canvas_item_set_parent(RID p_item,RID p_parent) {
item_owner->child_items.erase(canvas_item);
}
- canvas_item->parent=RID();
+ canvas_item->parent;
}
@@ -4057,7 +5329,7 @@ void VisualServerRaster::canvas_light_attach_to_canvas(RID p_light,RID p_canvas)
}
if (!canvas_owner.owns(p_canvas))
- p_canvas=RID();
+ p_canvas;
clight->canvas=p_canvas;
if (clight->canvas.is_valid()) {
@@ -4184,7 +5456,7 @@ void VisualServerRaster::canvas_light_set_shadow_enabled(RID p_light, bool p_ena
clight->shadow_buffer=rasterizer->canvas_light_shadow_buffer_create(clight->shadow_buffer_size);
} else {
rasterizer->free(clight->shadow_buffer);
- clight->shadow_buffer=RID();
+ clight->shadow_buffer;
}
@@ -4246,7 +5518,7 @@ void VisualServerRaster::canvas_light_occluder_attach_to_canvas(RID p_occluder,R
}
if (!canvas_owner.owns(p_canvas))
- p_canvas=RID();
+ p_canvas;
occluder->canvas=p_canvas;
@@ -4279,12 +5551,12 @@ void VisualServerRaster::canvas_light_occluder_set_polygon(RID p_occluder,RID p_
}
occluder->polygon=p_polygon;
- occluder->polygon_buffer=RID();
+ occluder->polygon_buffer;
if (occluder->polygon.is_valid()) {
CanvasLightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon);
if (!occluder_poly)
- occluder->polygon=RID();
+ occluder->polygon;
ERR_FAIL_COND(!occluder_poly);
occluder_poly->owners.insert(occluder);
occluder->polygon_buffer=occluder_poly->occluder;
@@ -4558,7 +5830,7 @@ void VisualServerRaster::free( RID p_rid ) {
//detach skeletons
for (Set<Instance*>::Element *F=E->get().front();F;F=F->next()) {
- F->get()->data.skeleton=RID();
+ F->get()->data.skeleton;
}
skeleton_dependency_map.erase(E);
}
@@ -4688,17 +5960,17 @@ void VisualServerRaster::free( RID p_rid ) {
for (int i=0;i<canvas->child_items.size();i++) {
- canvas->child_items[i].item->parent=RID();
+ canvas->child_items[i].item->parent;
}
for (Set<Rasterizer::CanvasLight*>::Element *E=canvas->lights.front();E;E=E->next()) {
- E->get()->canvas=RID();
+ E->get()->canvas;
}
for (Set<Rasterizer::CanvasLightOccluderInstance*>::Element *E=canvas->occluders.front();E;E=E->next()) {
- E->get()->canvas=RID();
+ E->get()->canvas;
}
canvas_owner.free( p_rid );
@@ -4726,7 +5998,7 @@ void VisualServerRaster::free( RID p_rid ) {
for (int i=0;i<canvas_item->child_items.size();i++) {
- canvas_item->child_items[i]->parent=RID();
+ canvas_item->child_items[i]->parent;
}
if (canvas_item->material) {
@@ -4798,7 +6070,7 @@ void VisualServerRaster::free( RID p_rid ) {
while(occluder_poly->owners.size()) {
- occluder_poly->owners.front()->get()->polygon=RID();
+ occluder_poly->owners.front()->get()->polygon;
occluder_poly->owners.erase( occluder_poly->owners.front() );
}
@@ -6417,7 +7689,7 @@ void VisualServerRaster::_process_sampled_light(const Transform& p_camera,Instan
for(Set<Instance*>::Element *F=p_sampled_light->baked_light_sampler_info->owned_instances.front();F;F=F->next()) {
- F->get()->data.sampled_light=RID(); //do not use because nothing close
+ F->get()->data.sampled_light; //do not use because nothing close
}
}
@@ -7679,7 +8951,7 @@ void VisualServerRaster::init() {
Image img;
img.create(default_mouse_cursor_xpm);
- //img.convert(Image::FORMAT_RGB);
+ //img.convert(Image::FORMAT_RGB8);
default_cursor_texture = texture_create_from_image(img, 0);
aabb_random_points.resize( GLOBAL_DEF("render/aabb_random_points",16) );
@@ -7766,3 +9038,4 @@ VisualServerRaster::VisualServerRaster(Rasterizer *p_rasterizer) {
VisualServerRaster::~VisualServerRaster()
{
}
+#endif
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index 496820f4a8..4cad03928b 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -40,6 +40,8 @@
*/
+
+
class VisualServerRaster : public VisualServer {
@@ -57,6 +59,12 @@ class VisualServerRaster : public VisualServer {
};
+ int changes;
+ bool draw_extra_frame;
+ RID test_cube;
+
+
+ #if 0
struct Room {
bool occlude_exterior;
@@ -374,97 +382,6 @@ class VisualServerRaster : public VisualServer {
mutable RID_Owner<Rasterizer::CanvasItemMaterial> canvas_item_material_owner;
- struct CanvasItem : public Rasterizer::CanvasItem {
-
-
- RID parent; // canvas it belongs to
- List<CanvasItem*>::Element *E;
- RID viewport;
- int z;
- bool z_relative;
- bool sort_y;
- float opacity;
- float self_opacity;
- bool use_parent_material;
-
-
- Vector<CanvasItem*> child_items;
-
-
- CanvasItem() {
- E=NULL;
- z=0;
- opacity=1;
- self_opacity=1;
- sort_y=false;
- use_parent_material=false;
- z_relative=true;
- }
- };
-
-
- struct CanvasItemPtrSort {
-
- _FORCE_INLINE_ bool operator()(const CanvasItem* p_left,const CanvasItem* p_right) const {
-
- return p_left->xform.elements[2].y < p_right->xform.elements[2].y;
- }
- };
-
- struct CanvasLightOccluder;
-
- struct CanvasLightOccluderPolygon {
-
- bool active;
- Rect2 aabb;
- CanvasOccluderPolygonCullMode cull_mode;
- RID occluder;
- Set<Rasterizer::CanvasLightOccluderInstance*> owners;
-
- CanvasLightOccluderPolygon() { active=false; cull_mode=CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; }
- };
-
-
- RID_Owner<CanvasLightOccluderPolygon> canvas_light_occluder_polygon_owner;
-
- RID_Owner<Rasterizer::CanvasLightOccluderInstance> canvas_light_occluder_owner;
-
- struct CanvasLight;
-
- struct Canvas {
-
- Set<RID> viewports;
- struct ChildItem {
-
- Point2 mirror;
- CanvasItem *item;
- };
-
- Set<Rasterizer::CanvasLight*> lights;
- Set<Rasterizer::CanvasLightOccluderInstance*> occluders;
-
- Vector<ChildItem> child_items;
- Color modulate;
-
- int find_item(CanvasItem *p_item) {
- for(int i=0;i<child_items.size();i++) {
- if (child_items[i].item==p_item)
- return i;
- }
- return -1;
- }
- void erase_item(CanvasItem *p_item) {
- int idx=find_item(p_item);
- if (idx>=0)
- child_items.remove(idx);
- }
-
- Canvas() { modulate=Color(1,1,1,1); }
-
- };
-
-
- RID_Owner<Rasterizer::CanvasLight> canvas_light_owner;
struct Viewport {
@@ -658,8 +575,14 @@ class VisualServerRaster : public VisualServer {
Rasterizer *rasterizer;
+
+#endif
+
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=TEXTURE_FLAGS_DEFAULT);
virtual void texture_set_data(RID p_texture,const Image& p_image,CubeMapSide p_cube_side=CUBEMAP_LEFT);
@@ -670,29 +593,27 @@ public:
virtual uint32_t texture_get_width(RID p_texture) const;
virtual uint32_t texture_get_height(RID p_texture) const;
virtual void texture_set_size_override(RID p_texture,int p_width, int p_height);
- virtual bool texture_can_stream(RID p_texture) const;
- virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const;
+
+
virtual void texture_set_path(RID p_texture,const String& p_path);
virtual String texture_get_path(RID p_texture) const;
- virtual void texture_debug_usage(List<TextureInfo> *r_info);
-
virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable);
+ virtual void texture_debug_usage(List<TextureInfo> *r_info);
+
/* SHADER API */
- virtual RID shader_create(ShaderMode p_mode=SHADER_MATERIAL);
+
+ virtual RID shader_create(ShaderMode p_mode=SHADER_SPATIAL);
virtual void shader_set_mode(RID p_shader,ShaderMode p_mode);
virtual 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_vertex_code(RID p_shader) const;
- virtual String shader_get_fragment_code(RID p_shader) const;
- virtual String shader_get_light_code(RID p_shader) const;
-
+ virtual void shader_set_code(RID p_shader, const String& p_code);
+ virtual String shader_get_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);
@@ -709,65 +630,29 @@ public:
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, MaterialFlag p_flag,bool p_enabled);
- virtual bool material_get_flag(RID p_material,MaterialFlag p_flag) const;
-
- virtual void material_set_depth_draw_mode(RID p_material, MaterialDepthDrawMode p_mode);
- virtual MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const;
-
- virtual void material_set_blend_mode(RID p_material,MaterialBlendMode p_mode);
- virtual 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, FixedMaterialFlags p_flag, bool p_enabled);
- virtual bool fixed_material_get_flag(RID p_material, FixedMaterialFlags p_flag) const;
+ /* MESH API */
- virtual void fixed_material_set_param(RID p_material, FixedMaterialParam p_parameter, const Variant& p_value);
- virtual Variant fixed_material_get_param(RID p_material,FixedMaterialParam p_parameter) const;
-
- virtual void fixed_material_set_texture(RID p_material,FixedMaterialParam p_parameter, RID p_texture);
- virtual RID fixed_material_get_texture(RID p_material,FixedMaterialParam p_parameter) const;
-
- virtual void fixed_material_set_texcoord_mode(RID p_material,FixedMaterialParam p_parameter, FixedMaterialTexCoordMode p_mode);
- virtual FixedMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material,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_light_shader(RID p_material,FixedMaterialLightShader p_shader);
- virtual FixedMaterialLightShader fixed_material_get_light_shader(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;
-
- /* SURFACE API */
virtual RID mesh_create();
+ virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >());
+
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,MorphTargetMode p_mode);
virtual MorphTargetMode mesh_get_morph_target_mode(RID p_mesh) const;
- virtual void mesh_add_custom_surface(RID p_mesh,const Variant& p_dat); //this is used by each platform in a different way
-
- virtual void mesh_add_surface(RID p_mesh,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_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned=false);
+ virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material);
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 DVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const;
+ virtual DVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const;
+
+
virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const;
virtual PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const;
@@ -781,199 +666,102 @@ public:
/* MULTIMESH API */
+
virtual RID multimesh_create();
- virtual void multimesh_set_instance_count(RID p_multimesh,int p_count);
+
+ virtual void multimesh_allocate(RID p_multimesh,int p_instances,MultimeshTransformFormat p_transform_format,MultimeshColorFormat p_color_format,bool p_gen_aabb=true);
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_set_custom_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_transform_2d(RID p_multimesh,int p_index,const Matrix32& 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 AABB& p_aabb) const;
+ virtual AABB multimesh_get_custom_aabb(RID p_multimesh,const AABB& p_aabb) const;
+
virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const;
+ virtual Matrix32 multimesh_instance_get_transform_2d(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,PrimitiveType p_rimitive,RID p_texture=RID());
virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex);
+ virtual void immediate_vertex_2d(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& p_uv);
+ 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 void immediate_set_material(RID p_immediate,RID p_material);
virtual RID immediate_get_material(RID p_immediate) const;
+ /* SKELETON API */
- /* 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, ParticleVariable p_variable,float p_value);
- virtual float particles_get_variable(RID p_particles, ParticleVariable p_variable) const;
-
- virtual void particles_set_randomness(RID p_particles, ParticleVariable p_variable,float p_randomness);
- virtual float particles_get_randomness(RID p_particles, 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 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;
-
+ virtual RID skeleton_create();
+ virtual void skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton=false);
+ 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);
+ virtual void skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Matrix32& p_transform);
+ virtual Matrix32 skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone);
/* Light API */
virtual RID light_create(LightType p_type);
- virtual LightType light_get_type(RID p_light) const;
-
- virtual void light_set_color(RID p_light,LightColor p_type, const Color& p_color);
- virtual Color light_get_color(RID p_light,LightColor p_type) const;
-
+ virtual void light_set_color(RID p_light,const Color& p_color);
+ virtual void light_set_param(RID p_light,LightParam p_param,float p_value);
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_param(RID p_light, LightParam p_var, float p_value);
- virtual float light_get_param(RID p_light, LightParam p_var) const;
+ virtual void light_set_attenuation_texure(RID p_light,RID p_texture);
+ virtual void light_set_negative(RID p_light,bool p_enable);
+ virtual void light_set_cull_mask(RID p_light,uint32_t p_mask);
+ virtual void light_set_shader(RID p_light,RID p_shader);
- virtual void light_set_operator(RID p_light,LightOp p_op);
- virtual LightOp light_get_operator(RID p_light) const;
-
- virtual void light_omni_set_shadow_mode(RID p_light,LightOmniShadowMode p_mode);
- virtual LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) const;
virtual void light_directional_set_shadow_mode(RID p_light,LightDirectionalShadowMode p_mode);
- virtual LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) const;
- virtual void light_directional_set_shadow_param(RID p_light,LightDirectionalShadowParam p_param, float p_value);
- virtual float light_directional_get_shadow_param(RID p_light,LightDirectionalShadowParam p_param) const;
+ /* PROBE API */
- /* SKELETON API */
+ virtual RID reflection_probe_create();
+
+ virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity);
+ virtual void reflection_probe_set_clip(RID p_probe, float p_near, float p_far);
+ virtual void reflection_probe_set_min_blend_distance(RID p_probe, float p_distance);
+ virtual void reflection_probe_set_extents(RID p_probe, const Vector3& p_extents);
+ virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset);
+ virtual void reflection_probe_set_enable_parallax_correction(RID p_probe, bool p_enable);
+ virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution);
+ virtual void reflection_probe_set_hide_skybox(RID p_probe, bool p_hide);
+ virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
- 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);
/* ROOM API */
virtual RID room_create();
- virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds);
- virtual BSP_Tree room_get_bounds(RID p_room) const;
+ virtual void room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform);
+ virtual void room_clear_bounds();
/* PORTAL API */
+ // portals are only (x/y) points, forming a convex shape, which its clockwise
+ // order points outside. (z is 0);
+
virtual RID portal_create();
virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape);
- virtual Vector<Point2> portal_get_shape(RID p_portal) const;
virtual void portal_set_enabled(RID p_portal, bool p_enabled);
- virtual bool portal_is_enabled(RID p_portal) const;
virtual void portal_set_disable_distance(RID p_portal, float p_distance);
- virtual float portal_get_disable_distance(RID p_portal) const;
virtual void portal_set_disabled_color(RID p_portal, const Color& p_color);
- virtual Color portal_get_disabled_color(RID p_portal) const;
- virtual void portal_set_connect_range(RID p_portal, float p_range);
- virtual float portal_get_connect_range(RID p_portal) const;
-
- /* BAKED LIGHT */
-
- virtual RID baked_light_create();
-
- virtual void baked_light_set_mode(RID p_baked_light,BakedLightMode p_mode);
- virtual BakedLightMode baked_light_get_mode(RID p_baked_light) const;
-
- virtual void baked_light_set_octree(RID p_baked_light,const DVector<uint8_t> p_octree);
- virtual DVector<uint8_t> baked_light_get_octree(RID p_baked_light) const;
-
- virtual void baked_light_set_light(RID p_baked_light,const DVector<uint8_t> p_light);
- virtual DVector<uint8_t> baked_light_get_light(RID p_baked_light) const;
-
- virtual void baked_light_set_sampler_octree(RID p_baked_light,const DVector<int> &p_sampler);
- virtual DVector<int> baked_light_get_sampler_octree(RID p_baked_light) const;
-
- virtual void baked_light_set_lightmap_multiplier(RID p_baked_light,float p_multiplier);
- virtual float baked_light_get_lightmap_multiplier(RID p_baked_light) const;
-
- virtual void baked_light_add_lightmap(RID p_baked_light,const RID p_texture,int p_id);
- virtual void baked_light_clear_lightmaps(RID p_baked_light);
-
- virtual void baked_light_set_realtime_color_enabled(RID p_baked_light, const bool p_enabled);
- virtual bool baked_light_get_realtime_color_enabled(RID p_baked_light) const;
-
- virtual void baked_light_set_realtime_color(RID p_baked_light, const Color& p_color);
- virtual Color baked_light_get_realtime_color(RID p_baked_light) const;
-
- virtual void baked_light_set_realtime_energy(RID p_baked_light, const float p_energy);
- virtual float baked_light_get_realtime_energy(RID p_baked_light) const;
-
- /* BAKED LIGHT SAMPLER */
-
- virtual RID baked_light_sampler_create();
-
- virtual void baked_light_sampler_set_param(RID p_baked_light_sampler,BakedLightSamplerParam p_param,float p_value);
- virtual float baked_light_sampler_get_param(RID p_baked_light_sampler,BakedLightSamplerParam p_param) const;
-
- virtual void baked_light_sampler_set_resolution(RID p_baked_light_sampler,int p_resolution);
- virtual int baked_light_sampler_get_resolution(RID p_baked_light_sampler) const;
/* CAMERA API */
@@ -981,58 +769,44 @@ public:
virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far);
virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far);
virtual void camera_set_transform(RID p_camera,const Transform& p_transform);
-
- virtual void camera_set_visible_layers(RID p_camera,uint32_t p_layers);
- virtual uint32_t camera_get_visible_layers(RID p_camera) const;
-
+ virtual void camera_set_cull_mask(RID p_camera,uint32_t p_layers);
virtual void camera_set_environment(RID p_camera,RID p_env);
- virtual RID camera_get_environment(RID p_camera) const;
-
virtual void camera_set_use_vertical_aspect(RID p_camera,bool p_enable);
- virtual bool camera_is_using_vertical_aspect(RID p_camera,bool p_enable) const;
- /* VIEWPORT API */
+
+ /* VIEWPORT TARGET API */
virtual RID viewport_create();
- virtual void viewport_attach_to_screen(RID p_viewport,int p_screen=0);
- virtual void viewport_detach(RID p_viewport);
+ virtual void viewport_set_size(RID p_viewport,int p_width,int p_height);
+
+ virtual void viewport_set_active(RID p_viewport,bool p_active);
- virtual void viewport_set_as_render_target(RID p_viewport,bool p_enable);
- virtual void viewport_set_render_target_update_mode(RID p_viewport,RenderTargetUpdateMode p_mode);
- virtual RenderTargetUpdateMode viewport_get_render_target_update_mode(RID p_viewport) const;
- virtual RID viewport_get_render_target_texture(RID p_viewport) const;
- virtual void viewport_set_render_target_vflip(RID p_viewport,bool p_enable);
- virtual bool viewport_get_render_target_vflip(RID p_viewport) const;
- virtual void viewport_set_render_target_clear_on_new_frame(RID p_viewport,bool p_enable);
- virtual bool viewport_get_render_target_clear_on_new_frame(RID p_viewport) const;
- virtual void viewport_render_target_clear(RID p_viewport);
- virtual void viewport_set_render_target_to_screen_rect(RID p_viewport,const Rect2& p_rect);
+ virtual void viewport_set_clear_mode(RID p_viewport,ViewportClearMode p_clear_mode);
+ virtual void viewport_attach_to_screen(RID p_viewport,const Rect2& p_rect=Rect2(),int p_screen=0);
+ virtual void viewport_detach(RID p_viewport);
+
+ virtual void viewport_set_update_mode(RID p_viewport,ViewportUpdateMode p_mode);
+ virtual void viewport_set_vflip(RID p_viewport,bool p_enable);
- virtual void viewport_queue_screen_capture(RID p_viewport);
- virtual Image viewport_get_screen_capture(RID p_viewport) const;
- virtual void viewport_set_rect(RID p_viewport,const ViewportRect& p_rect);
- virtual ViewportRect viewport_get_rect(RID p_viewport) const;
+ virtual RID viewport_get_texture(RID p_viewport) const;
+ virtual Image viewport_capture(RID p_viewport) const;
virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide);
virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide);
virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable);
+
virtual void viewport_attach_camera(RID p_viewport,RID p_camera);
virtual void viewport_set_scenario(RID p_viewport,RID p_scenario);
-
- virtual RID viewport_get_attached_camera(RID p_viewport) const;
- virtual RID viewport_get_scenario(RID p_viewport) const;
virtual void viewport_attach_canvas(RID p_viewport,RID p_canvas);
virtual void viewport_remove_canvas(RID p_viewport,RID p_canvas);
virtual void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset);
- virtual Matrix32 viewport_get_canvas_transform(RID p_viewport,RID p_canvas) const;
+ virtual void viewport_set_transparent_background(RID p_viewport,bool p_enabled);
+
virtual void viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform);
- virtual Matrix32 viewport_get_global_canvas_transform(RID p_viewport) const;
virtual void viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer);
- virtual void viewport_set_transparent_background(RID p_viewport,bool p_enabled);
- virtual bool viewport_has_transparent_background(RID p_viewport) const;
/* ENVIRONMENT API */
@@ -1040,21 +814,24 @@ public:
virtual RID environment_create();
virtual void environment_set_background(RID p_env,EnvironmentBG p_bg);
- virtual EnvironmentBG environment_get_background(RID p_env) const;
+ virtual void environment_set_skybox(RID p_env,RID p_skybox,float p_energy=1.0);
+ virtual void environment_set_bg_color(RID p_env,const Color& p_color);
+ virtual void environment_set_canvas_max_layer(RID p_env,int p_max_layer);
+ virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0);
- virtual void environment_set_background_param(RID p_env,EnvironmentBGParam p_param, const Variant& p_value);
- virtual Variant environment_get_background_param(RID p_env,EnvironmentBGParam p_param) const;
+ virtual void environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,EnvironmentGlowBlendMode p_blend_mode);
+ virtual void environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture);
- virtual void environment_set_enable_fx(RID p_env,EnvironmentFx p_effect,bool p_enabled);
- virtual bool environment_is_fx_enabled(RID p_env,EnvironmentFx p_effect) const;
-
-
- virtual void environment_fx_set_param(RID p_env,EnvironmentFxParam p_effect,const Variant& p_param);
- virtual Variant environment_fx_get_param(RID p_env,EnvironmentFxParam p_effect) const;
+ virtual void environment_set_tonemap(RID p_env,bool p_enable,float p_exposure,float p_white,float p_min_luminance,float p_max_luminance,float p_auto_exp_speed,EnvironmentToneMapper p_tone_mapper);
+ virtual void environment_set_brightness(RID p_env,bool p_enable,float p_brightness);
+ virtual void environment_set_contrast(RID p_env,bool p_enable,float p_contrast);
+ virtual void environment_set_saturation(RID p_env,bool p_enable,float p_saturation);
+ virtual void environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp);
/* SCENARIO API */
+
virtual RID scenario_create();
virtual void scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode);
@@ -1063,137 +840,91 @@ public:
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment);
-
/* INSTANCING API */
+ // from can be mesh, light, area and portal so far.
+ virtual RID instance_create(); // from can be mesh, light, poly, area and portal so far.
- virtual RID instance_create();
-
- virtual void instance_set_base(RID p_instance, RID p_base);
- virtual RID instance_get_base(RID p_instance) const;
-
- virtual void instance_set_scenario(RID p_instance, RID p_scenario);
- virtual RID instance_get_scenario(RID p_instance) const;
-
+ virtual void instance_set_base(RID p_instance, RID p_base); // from can be mesh, light, poly, area and portal so far.
+ virtual void instance_set_scenario(RID p_instance, RID p_scenario); // from can be mesh, light, poly, area and portal so far.
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask);
- virtual uint32_t instance_get_layer_mask(RID p_instance) const;
-
- virtual AABB instance_get_base_aabb(RID p_instance) const;
-
- virtual void instance_attach_object_instance_ID(RID p_instance,uint32_t p_ID);
- virtual uint32_t instance_get_object_instance_ID(RID p_instance) const;
-
- virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton);
- virtual RID instance_get_skeleton(RID p_instance) const;
-
+ virtual void instance_set_transform(RID p_instance, const Transform& p_transform);
+ virtual void instance_attach_object_instance_ID(RID p_instance,ObjectID p_ID);
virtual void instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight);
- virtual float instance_get_morph_target_weight(RID p_instance,int p_shape) const;
-
virtual void instance_set_surface_material(RID p_instance,int p_surface, RID p_material);
-
- virtual void instance_set_transform(RID p_instance, const Transform& p_transform);
- virtual Transform instance_get_transform(RID p_instance) const;
-
+ virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton);
virtual void instance_set_exterior( RID p_instance, bool p_enabled );
- virtual bool instance_is_exterior( RID p_instance) const;
-
virtual void instance_set_room( RID p_instance, RID p_room );
- virtual RID instance_get_room( RID p_instance ) const ;
virtual void instance_set_extra_visibility_margin( RID p_instance, real_t p_margin );
- virtual real_t instance_get_extra_visibility_margin( RID p_instance ) const;
- virtual Vector<RID> instances_cull_aabb(const AABB& p_aabb, RID p_scenario=RID()) const;
- virtual Vector<RID> instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario=RID()) const;
- virtual Vector<RID> instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario=RID()) const;
+ // don't use these in a game!
+ virtual Vector<ObjectID> instances_cull_aabb(const AABB& p_aabb, RID p_scenario=RID()) const;
+ virtual Vector<ObjectID> instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario=RID()) const;
+ virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario=RID()) const;
- virtual void instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled);
- virtual bool instance_geometry_get_flag(RID p_instance,InstanceFlags p_flags) const;
-
- virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting);
- virtual VS::ShadowCastingSetting instance_geometry_get_cast_shadows_setting(RID p_instance) const;
+ virtual void instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled);
+ virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting);
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material);
- virtual RID instance_geometry_get_material_override(RID p_instance) const;
-
- virtual void instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max);
- virtual float instance_geometry_get_draw_range_max(RID p_instance) const;
- virtual float instance_geometry_get_draw_range_min(RID p_instance) const;
- virtual void instance_geometry_set_baked_light(RID p_instance,RID p_baked_light);
- virtual RID instance_geometry_get_baked_light(RID p_instance) const;
- virtual void instance_geometry_set_baked_light_sampler(RID p_instance,RID p_baked_light_sampler);
- virtual RID instance_geometry_get_baked_light_sampler(RID p_instance) const;
-
- virtual void instance_geometry_set_baked_light_texture_index(RID p_instance,int p_tex_id);
- virtual int instance_geometry_get_baked_light_texture_index(RID p_instance) const;
-
- virtual void instance_light_set_enabled(RID p_instance,bool p_enabled);
- virtual bool instance_light_is_enabled(RID p_instance) const;
+ virtual void instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max,float p_min_margin,float p_max_margin);
+ virtual void instance_geometry_set_as_instance_lod(RID p_instance,RID p_as_lod_of_instance);
/* CANVAS (2D) */
virtual RID canvas_create();
virtual void canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring);
- virtual Point2 canvas_get_item_mirroring(RID p_canvas,RID p_item) const;
virtual void canvas_set_modulate(RID p_canvas,const Color& p_color);
virtual RID canvas_item_create();
-
- virtual void canvas_item_set_parent(RID p_item,RID p_parent_item);
- virtual RID canvas_item_get_parent(RID p_canvas_item) const;
+ virtual void canvas_item_set_parent(RID p_item,RID p_parent);
virtual void canvas_item_set_visible(RID p_item,bool p_visible);
- virtual bool canvas_item_is_visible(RID p_item) const;
+ virtual void canvas_item_set_light_mask(RID p_item,int p_mask);
- virtual void canvas_item_set_blend_mode(RID p_canvas_item,MaterialBlendMode p_blend);
- virtual void canvas_item_set_light_mask(RID p_canvas_item,int p_mask);
-
-
-
- //virtual void canvas_item_set_rect(RID p_item, const Rect2& p_rect);
virtual void canvas_item_set_transform(RID p_item, const Matrix32& p_transform);
virtual void canvas_item_set_clip(RID p_item, bool p_clip);
virtual void canvas_item_set_distance_field_mode(RID p_item, bool p_enable);
virtual void canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect=Rect2());
- virtual void canvas_item_set_opacity(RID p_item, float p_opacity);
- virtual float canvas_item_get_opacity(RID p_item, float p_opacity) const;
- virtual void canvas_item_set_on_top(RID p_item, bool p_on_top);
- virtual bool canvas_item_is_on_top(RID p_item) const;
+ virtual void canvas_item_set_modulate(RID p_item, const Color& p_color);
+ virtual void canvas_item_set_self_modulate(RID p_item, const Color& p_color);
- virtual void canvas_item_set_self_opacity(RID p_item, float p_self_opacity);
- virtual float canvas_item_get_self_opacity(RID p_item, float p_self_opacity) const;
+ virtual void canvas_item_set_draw_behind_parent(RID p_item, bool p_enable);
- virtual void canvas_item_attach_viewport(RID p_item, RID p_viewport);
- virtual void canvas_item_add_line(RID p_item, const Point2& p_from, const Point2& p_to, const Color& p_color, float p_width=1.0, bool p_antialiased=false);
+ virtual void canvas_item_add_line(RID p_item, const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0,bool p_antialiased=false);
virtual void canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color);
virtual void canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color);
virtual void canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile=false,const Color& p_modulate=Color(1,1,1),bool p_transpose=false);
virtual void canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1),bool p_transpose=false);
- virtual void canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1));
+ virtual void canvas_item_add_nine_patch(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright,NinePatchAxisMode p_x_axis_mode=NINE_PATCH_STRETCH, NinePatchAxisMode p_y_axis_mode=NINE_PATCH_STRETCH,bool p_draw_center=true,const Color& p_modulate=Color(1,1,1));
virtual void canvas_item_add_primitive(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width=1.0);
virtual void canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), RID p_texture=RID());
virtual void canvas_item_add_triangle_array(RID p_item, const Vector<int>& p_indices, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), RID p_texture=RID(), int p_count=-1);
- virtual void canvas_item_add_triangle_array_ptr(RID p_item, int p_count, const int* p_indices, const Point2* p_points, const Color* p_colors,const Point2* p_uvs=NULL, RID p_texture=RID());
+ virtual void canvas_item_add_mesh(RID p_item, const RID& p_mesh,RID p_skeleton=RID());
+ virtual void canvas_item_add_multimesh(RID p_item, RID p_mesh,RID p_skeleton=RID());
virtual void canvas_item_add_set_transform(RID p_item,const Matrix32& p_transform);
- virtual void canvas_item_add_set_blend_mode(RID p_item, MaterialBlendMode p_blend);
virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore);
virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable);
virtual void canvas_item_set_z(RID p_item, int p_z);
virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable);
virtual void canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect);
+ virtual void canvas_item_clear(RID p_item);
+ virtual void canvas_item_set_draw_index(RID p_item,int p_index);
+
virtual void canvas_item_set_material(RID p_item, RID p_material);
+
virtual void canvas_item_set_use_parent_material(RID p_item, bool p_enable);
virtual RID canvas_light_create();
virtual void canvas_light_attach_to_canvas(RID p_light,RID p_canvas);
virtual void canvas_light_set_enabled(RID p_light, bool p_enabled);
- virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform);
virtual void canvas_light_set_scale(RID p_light, float p_scale);
+ virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform);
virtual void canvas_light_set_texture(RID p_light, RID p_texture);
virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset);
virtual void canvas_light_set_color(RID p_light, const Color& p_color);
@@ -1201,13 +932,16 @@ public:
virtual void canvas_light_set_energy(RID p_light, float p_energy);
virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z);
virtual void canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer);
- virtual void canvas_light_set_item_mask(RID p_light, int p_mask);
- virtual void canvas_light_set_item_shadow_mask(RID p_light, int p_mask);
+ virtual void canvas_light_set_item_cull_mask(RID p_light, int p_mask);
+ virtual void canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask);
virtual void canvas_light_set_mode(RID p_light, CanvasLightMode p_mode);
+
+
virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled);
virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size);
- virtual void canvas_light_set_shadow_esm_multiplier(RID p_light, float p_multiplier);
+ virtual void canvas_light_set_shadow_gradient_length(RID p_light, float p_length);
+ virtual void canvas_light_set_shadow_filter(RID p_light, CanvasLightShadowFilter p_filter);
virtual void canvas_light_set_shadow_color(RID p_light, const Color& p_color);
@@ -1219,72 +953,56 @@ public:
virtual void canvas_light_occluder_set_transform(RID p_occluder,const Matrix32& p_xform);
virtual void canvas_light_occluder_set_light_mask(RID p_occluder,int p_mask);
-
virtual RID canvas_occluder_polygon_create();
- virtual void canvas_occluder_polygon_set_shape(RID p_occluder_polygon,const DVector<Vector2>& p_shape,bool p_close);
+ virtual void canvas_occluder_polygon_set_shape(RID p_occluder_polygon,const DVector<Vector2>& p_shape,bool p_closed);
virtual void canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon,const DVector<Vector2>& p_shape);
- virtual void canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon,CanvasOccluderPolygonCullMode p_mode);
-
- virtual void canvas_item_clear(RID p_item);
- virtual void canvas_item_raise(RID p_item);
-
- /* CANVAS ITEM MATERIAL */
-
- virtual RID canvas_item_material_create();
- virtual void canvas_item_material_set_shader(RID p_material, RID p_shader);
- virtual void canvas_item_material_set_shader_param(RID p_material, const StringName& p_param, const Variant& p_value);
- virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const;
- virtual void canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode);
-
+ virtual void canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon,CanvasOccluderPolygonCullMode p_mode);
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0); // radians
- virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor=0, const Rect2 &p_region=Rect2());
+ virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0, const Rect2 &p_region=Rect2());
virtual void cursor_set_visible(bool p_visible, int p_cursor = 0);
virtual void cursor_set_pos(const Point2& p_pos, int p_cursor = 0);
/* BLACK BARS */
+
virtual void black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom);
virtual void black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom);
- /* FREE */
-
- virtual void free( RID p_rid );
- /* CUSTOM SHADE MODEL */
+ /* FREE */
- 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 free( RID p_rid ); ///< free RIDs associated with the visual server
/* EVENT QUEUING */
virtual void draw();
virtual void sync();
-
+ virtual bool has_changed() const;
virtual void init();
virtual void finish();
- virtual bool has_changed() const;
+ /* STATUS INFORMATION */
- /* RENDER INFO */
virtual int get_render_info(RenderInfo p_info);
- virtual bool has_feature(Features p_feature) const;
- RID get_test_cube();
+ virtual RID get_test_cube();
+
+
+ /* TESTING */
- virtual void set_boot_image(const Image& p_image, const Color& p_color, bool p_scale);
+ virtual void set_boot_image(const Image& p_image, const Color& p_color,bool p_scale);
virtual void set_default_clear_color(const Color& p_color);
- VisualServerRaster(Rasterizer *p_rasterizer);
+ virtual bool has_feature(Features p_feature) const;
+
+
+ VisualServerRaster();
~VisualServerRaster();
};
diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp
new file mode 100644
index 0000000000..b30a57a5b8
--- /dev/null
+++ b/servers/visual/visual_server_viewport.cpp
@@ -0,0 +1,489 @@
+#include "visual_server_viewport.h"
+#include "visual_server_global.h"
+#include "visual_server_canvas.h"
+
+void VisualServerViewport::_draw_viewport(Viewport *p_viewport) {
+
+ /* Camera should always be BEFORE any other 3D */
+#if 0
+ bool scenario_draw_canvas_bg=false;
+ int scenario_canvas_max_layer=0;
+
+ if (!p_viewport->hide_canvas && !p_viewport->disable_environment && scenario_owner.owns(p_viewport->scenario)) {
+
+ Scenario *scenario=scenario_owner.get(p_viewport->scenario);
+ if (scenario->environment.is_valid()) {
+ if (rasterizer->is_environment(scenario->environment)) {
+ scenario_draw_canvas_bg=rasterizer->environment_get_background(scenario->environment)==VS::ENV_BG_CANVAS;
+ scenario_canvas_max_layer=rasterizer->environment_get_background_param(scenario->environment,VS::ENV_BG_PARAM_CANVAS_MAX_LAYER);
+ }
+ }
+ }
+
+ bool can_draw_3d=!p_viewport->hide_scenario && camera_owner.owns(p_viewport->camera) && scenario_owner.owns(p_viewport->scenario);
+
+
+ if (scenario_draw_canvas_bg) {
+
+ rasterizer->begin_canvas_bg();
+ }
+
+ if (!scenario_draw_canvas_bg && can_draw_3d) {
+
+ _draw_viewport_camera(p_viewport,false);
+
+ } else if (true /*|| !p_viewport->canvas_list.empty()*/){
+
+ //clear the viewport black because of no camera? i seriously should..
+ if (p_viewport->render_target_clear_on_new_frame || p_viewport->render_target_clear) {
+ if (p_viewport->transparent_bg) {
+ rasterizer->clear_viewport(Color(0,0,0,0));
+ }
+ else {
+ Color cc=clear_color;
+ if (scenario_draw_canvas_bg)
+ cc.a=0;
+ rasterizer->clear_viewport(cc);
+ }
+ p_viewport->render_target_clear=false;
+ }
+ }
+#endif
+
+ VSG::rasterizer->clear_render_target(Color(0.5,0.5,0.5,1.0));
+
+ if (!p_viewport->hide_canvas) {
+ int i=0;
+
+ Map<Viewport::CanvasKey,Viewport::CanvasData*> canvas_map;
+
+ Rect2 clip_rect(0,0,p_viewport->size.x,p_viewport->size.y);
+ RasterizerCanvas::Light *lights=NULL;
+ RasterizerCanvas::Light *lights_with_shadow=NULL;
+ RasterizerCanvas::Light *lights_with_mask=NULL;
+ Rect2 shadow_rect;
+
+ int light_count=0;
+
+ for (Map<RID,Viewport::CanvasData>::Element *E=p_viewport->canvas_map.front();E;E=E->next()) {
+
+ Matrix32 xf = p_viewport->global_transform * E->get().transform;
+
+ VisualServerCanvas::Canvas *canvas = static_cast<VisualServerCanvas::Canvas*>(E->get().canvas);
+
+ //find lights in canvas
+
+
+ for(Set<RasterizerCanvas::Light*>::Element *F=canvas->lights.front();F;F=F->next()) {
+
+
+ RasterizerCanvas::Light* cl=F->get();
+ if (cl->enabled && cl->texture.is_valid()) {
+ //not super efficient..
+ Size2 tsize(VSG::storage->texture_get_width(cl->texture),VSG::storage->texture_get_height(cl->texture));
+ tsize*=cl->scale;
+
+ Vector2 offset=tsize/2.0;
+ cl->rect_cache=Rect2(-offset+cl->texture_offset,tsize);
+ cl->xform_cache=xf * cl->xform;
+
+
+ if (clip_rect.intersects_transformed(cl->xform_cache,cl->rect_cache)) {
+
+ cl->filter_next_ptr=lights;
+ lights=cl;
+ cl->texture_cache=NULL;
+ Matrix32 scale;
+ scale.scale(cl->rect_cache.size);
+ scale.elements[2]=cl->rect_cache.pos;
+ cl->light_shader_xform = (cl->xform_cache * scale).affine_inverse();
+ cl->light_shader_pos=cl->xform_cache[2];
+ if (cl->shadow_buffer.is_valid()) {
+
+ cl->shadows_next_ptr=lights_with_shadow;
+ if (lights_with_shadow==NULL) {
+ shadow_rect = cl->xform_cache.xform(cl->rect_cache);
+ } else {
+ shadow_rect=shadow_rect.merge( cl->xform_cache.xform(cl->rect_cache) );
+ }
+ lights_with_shadow=cl;
+ cl->radius_cache=cl->rect_cache.size.length();
+
+ }
+ if (cl->mode==VS::CANVAS_LIGHT_MODE_MASK) {
+ cl->mask_next_ptr=lights_with_mask;
+ lights_with_mask=cl;
+ }
+
+ light_count++;
+ }
+
+ VSG::canvas_render->light_internal_update(cl->light_internal,cl);
+
+ }
+ }
+
+ //print_line("lights: "+itos(light_count));
+ canvas_map[ Viewport::CanvasKey( E->key(), E->get().layer) ]=&E->get();
+
+ }
+
+ if (lights_with_shadow) {
+ //update shadows if any
+
+ RasterizerCanvas::LightOccluderInstance * occluders=NULL;
+
+ //make list of occluders
+ for (Map<RID,Viewport::CanvasData>::Element *E=p_viewport->canvas_map.front();E;E=E->next()) {
+
+ VisualServerCanvas::Canvas *canvas = static_cast<VisualServerCanvas::Canvas*>(E->get().canvas);
+ Matrix32 xf = p_viewport->global_transform * E->get().transform;
+
+
+ for(Set<RasterizerCanvas::LightOccluderInstance*>::Element *F=canvas->occluders.front();F;F=F->next()) {
+
+ if (!F->get()->enabled)
+ continue;
+ F->get()->xform_cache = xf * F->get()->xform;
+ if (shadow_rect.intersects_transformed(F->get()->xform_cache,F->get()->aabb_cache)) {
+
+ F->get()->next=occluders;
+ occluders=F->get();
+
+ }
+ }
+ }
+ //update the light shadowmaps with them
+ RasterizerCanvas::Light *light=lights_with_shadow;
+ while(light) {
+
+ VSG::canvas_render->canvas_light_shadow_buffer_update(light->shadow_buffer,light->xform_cache.affine_inverse(),light->item_mask,light->radius_cache/1000.0,light->radius_cache*1.1,occluders,&light->shadow_matrix_cache);
+ light=light->shadows_next_ptr;
+ }
+
+ VSG::rasterizer->restore_render_target();
+ // VSG::canvas_render->reset_canvas();
+ }
+
+
+
+#if 0
+ if (scenario_draw_canvas_bg && canvas_map.front() && canvas_map.front()->key().layer>scenario_canvas_max_layer) {
+
+ _draw_viewport_camera(p_viewport,!can_draw_3d);
+ scenario_draw_canvas_bg=false;
+
+ }
+#endif
+ for (Map<Viewport::CanvasKey,Viewport::CanvasData*>::Element *E=canvas_map.front();E;E=E->next()) {
+
+ VisualServerCanvas::Canvas *canvas = static_cast<VisualServerCanvas::Canvas*>(E->get()->canvas);
+
+ // print_line("canvas "+itos(i)+" size: "+itos(I->get()->canvas->child_items.size()));
+ //print_line("GT "+p_viewport->global_transform+". CT: "+E->get()->transform);
+ Matrix32 xform = p_viewport->global_transform * E->get()->transform;
+
+ RasterizerCanvas::Light *canvas_lights=NULL;
+
+ RasterizerCanvas::Light *ptr=lights;
+ while(ptr) {
+ if (E->get()->layer>=ptr->layer_min && E->get()->layer<=ptr->layer_max) {
+ ptr->next_ptr=canvas_lights;
+ canvas_lights=ptr;
+ }
+ ptr=ptr->filter_next_ptr;
+ }
+
+ VSG::canvas->render_canvas( canvas,xform,canvas_lights,lights_with_mask,clip_rect );
+ i++;
+#if 0
+ if (scenario_draw_canvas_bg && E->key().layer>=scenario_canvas_max_layer) {
+ _draw_viewport_camera(p_viewport,!can_draw_3d);
+ scenario_draw_canvas_bg=false;
+ }
+#endif
+
+
+ }
+#if 0
+ if (scenario_draw_canvas_bg) {
+ _draw_viewport_camera(p_viewport,!can_draw_3d);
+ scenario_draw_canvas_bg=false;
+ }
+#endif
+
+ //VSG::canvas_render->canvas_debug_viewport_shadows(lights_with_shadow);
+ }
+
+
+
+}
+
+void VisualServerViewport::draw_viewports() {
+
+ //sort viewports
+
+
+ //draw viewports
+
+
+ for(int i=0;i<active_viewports.size();i++) {
+
+ Viewport *vp = active_viewports[i];
+
+ if (vp->update_mode==VS::VIEWPORT_UPDATE_DISABLED)
+ continue;
+
+ ERR_CONTINUE( !vp->render_target.is_valid() );
+
+ VSG::rasterizer->set_current_render_target(vp->render_target);
+ _draw_viewport(vp);
+
+ if (vp->viewport_to_screen_rect!=Rect2()) {
+ //copy to screen if set as such
+ VSG::rasterizer->set_current_render_target(RID());
+ VSG::rasterizer->blit_render_target_to_screen(vp->render_target,vp->viewport_to_screen_rect,vp->viewport_to_screen);
+ }
+
+ if (vp->update_mode==VS::VIEWPORT_UPDATE_ONCE) {
+ vp->update_mode=VS::VIEWPORT_UPDATE_DISABLED;
+ }
+ }
+}
+
+
+RID VisualServerViewport::viewport_create() {
+
+ Viewport * viewport = memnew( Viewport );
+
+ RID rid = viewport_owner.make_rid(viewport);
+
+ viewport->self=rid;
+ viewport->hide_scenario=false;
+ viewport->hide_canvas=false;
+ viewport->render_target=VSG::storage->render_target_create();
+
+ return rid;
+
+}
+
+void VisualServerViewport::viewport_set_size(RID p_viewport,int p_width,int p_height){
+
+ ERR_FAIL_COND(p_width<0 && p_height<0);
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+
+
+ viewport->size=Size2(p_width,p_height);
+ VSG::storage->render_target_set_size(viewport->render_target,p_width,p_height);
+
+
+}
+
+void VisualServerViewport::viewport_set_active(RID p_viewport,bool p_active) {
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ if (p_active) {
+ ERR_FAIL_COND(active_viewports.find(viewport)!=-1);//already active
+ active_viewports.push_back(viewport);
+ } else {
+ active_viewports.erase(viewport);
+ }
+
+
+}
+
+void VisualServerViewport::viewport_set_clear_mode(RID p_viewport,VS::ViewportClearMode p_clear_mode) {
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->clear_mode=p_clear_mode;
+
+}
+
+
+void VisualServerViewport::viewport_attach_to_screen(RID p_viewport,const Rect2& p_rect,int p_screen){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->viewport_to_screen_rect=p_rect;
+ viewport->viewport_to_screen=p_screen;
+}
+void VisualServerViewport::viewport_detach(RID p_viewport){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->viewport_to_screen_rect=Rect2();
+ viewport->viewport_to_screen=0;
+
+}
+
+void VisualServerViewport::viewport_set_update_mode(RID p_viewport,VS::ViewportUpdateMode p_mode){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->update_mode=p_mode;
+
+}
+void VisualServerViewport::viewport_set_vflip(RID p_viewport,bool p_enable){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ VSG::storage->render_target_set_flag(viewport->render_target,RasterizerStorage::RENDER_TARGET_VFLIP,p_enable);
+
+}
+
+RID VisualServerViewport::viewport_get_texture(RID p_viewport) const{
+
+ const Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND_V(!viewport,RID());
+
+ return VSG::storage->render_target_get_texture(viewport->render_target);
+
+}
+Image VisualServerViewport::viewport_capture(RID p_viewport) const{
+
+ const Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND_V(!viewport,Image());
+ return VSG::storage->render_target_get_image(viewport->render_target);
+
+}
+
+void VisualServerViewport::viewport_set_hide_scenario(RID p_viewport,bool p_hide){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->hide_scenario=p_hide;
+}
+void VisualServerViewport::viewport_set_hide_canvas(RID p_viewport,bool p_hide){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->hide_canvas=p_hide;
+}
+void VisualServerViewport::viewport_set_disable_environment(RID p_viewport,bool p_disable){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+
+ viewport->disable_environment=p_disable;
+}
+
+void VisualServerViewport::viewport_attach_camera(RID p_viewport,RID p_camera){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->camera=p_camera;
+}
+void VisualServerViewport::viewport_set_scenario(RID p_viewport,RID p_scenario){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->scenario=p_scenario;
+}
+void VisualServerViewport::viewport_attach_canvas(RID p_viewport,RID p_canvas){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ ERR_FAIL_COND(viewport->canvas_map.has(p_canvas));
+ VisualServerCanvas::Canvas *canvas = VSG::canvas->canvas_owner.getornull(p_canvas);
+ ERR_FAIL_COND(!canvas);
+
+ canvas->viewports.insert(p_viewport);
+ viewport->canvas_map[p_canvas]=Viewport::CanvasData();
+ viewport->canvas_map[p_canvas].layer=0;
+ viewport->canvas_map[p_canvas].canvas=canvas;
+
+}
+
+void VisualServerViewport::viewport_remove_canvas(RID p_viewport,RID p_canvas){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ VisualServerCanvas::Canvas *canvas = VSG::canvas->canvas_owner.getornull(p_canvas);
+ ERR_FAIL_COND(!canvas);
+
+ viewport->canvas_map.erase(p_canvas);
+ canvas->viewports.erase(p_viewport);
+
+}
+void VisualServerViewport::viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ ERR_FAIL_COND(!viewport->canvas_map.has(p_canvas));
+ viewport->canvas_map[p_canvas].transform=p_offset;
+
+}
+void VisualServerViewport::viewport_set_transparent_background(RID p_viewport,bool p_enabled){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ VSG::storage->render_target_set_flag(viewport->render_target,RasterizerStorage::RENDER_TARGET_TRANSPARENT,p_enabled);
+
+}
+
+void VisualServerViewport::viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ viewport->global_transform=p_transform;
+
+}
+void VisualServerViewport::viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer){
+
+ Viewport * viewport = viewport_owner.getornull(p_viewport);
+ ERR_FAIL_COND(!viewport);
+
+ ERR_FAIL_COND(!viewport->canvas_map.has(p_canvas));
+ viewport->canvas_map[p_canvas].layer=p_layer;
+
+}
+
+bool VisualServerViewport::free(RID p_rid) {
+
+ Viewport * viewport = viewport_owner.getornull(p_rid);
+ if (!viewport)
+ return false;
+
+
+ VSG::storage->free( viewport->render_target );
+
+ while(viewport->canvas_map.front()) {
+ viewport_remove_canvas(p_rid,viewport->canvas_map.front()->key());
+ }
+
+ viewport_set_scenario(p_rid,RID());
+ active_viewports.erase(viewport);
+
+ viewport_owner.free(p_rid);
+ memdelete(viewport);
+
+
+ return true;
+
+}
+
+VisualServerViewport::VisualServerViewport()
+{
+
+}
diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h
new file mode 100644
index 0000000000..e5c888fbcb
--- /dev/null
+++ b/servers/visual/visual_server_viewport.h
@@ -0,0 +1,118 @@
+#ifndef VISUALSERVERVIEWPORT_H
+#define VISUALSERVERVIEWPORT_H
+
+#include "servers/visual_server.h"
+#include "rasterizer.h"
+#include "self_list.h"
+
+class VisualServerViewport {
+public:
+
+ struct CanvasBase : public RID_Data {
+
+
+ };
+
+ struct Viewport : public RID_Data {
+
+ RID self;
+ RID parent;
+
+ Size2i size;
+ RID camera;
+ RID scenario;
+
+ VS::ViewportUpdateMode update_mode;
+ RID render_target;
+ RID render_target_texture;
+
+ int viewport_to_screen;
+ Rect2 viewport_to_screen_rect;
+
+ bool hide_scenario;
+ bool hide_canvas;
+ bool disable_environment;
+
+ Image capture;
+
+ VS::ViewportClearMode clear_mode;
+
+ bool rendered_in_prev_frame;
+
+ struct CanvasKey {
+
+ int layer;
+ RID canvas;
+ bool operator<(const CanvasKey& p_canvas) const { if (layer==p_canvas.layer) return canvas < p_canvas.canvas; return layer<p_canvas.layer; }
+ CanvasKey() { layer=0; }
+ CanvasKey(const RID& p_canvas, int p_layer) { canvas=p_canvas; layer=p_layer; }
+ };
+
+ struct CanvasData {
+
+ CanvasBase *canvas;
+ Matrix32 transform;
+ int layer;
+ };
+
+ Matrix32 global_transform;
+
+ Map<RID,CanvasData> canvas_map;
+
+ Viewport() {
+ update_mode=VS::VIEWPORT_UPDATE_WHEN_VISIBLE;
+ clear_mode=VS::VIEWPORT_CLEAR_ALWAYS;
+ rendered_in_prev_frame=false;
+ disable_environment=false;
+ viewport_to_screen=0;
+
+ }
+ };
+
+ mutable RID_Owner<Viewport> viewport_owner;
+ Vector<Viewport*> active_viewports;
+private:
+ void _draw_viewport(Viewport *p_viewport);
+public:
+
+
+ RID viewport_create();
+
+ void viewport_set_size(RID p_viewport,int p_width,int p_height);
+
+ void viewport_attach_to_screen(RID p_viewport,const Rect2& p_rect=Rect2(),int p_screen=0);
+ void viewport_detach(RID p_viewport);
+
+ void viewport_set_active(RID p_viewport,bool p_active);
+
+ void viewport_set_update_mode(RID p_viewport,VS::ViewportUpdateMode p_mode);
+ void viewport_set_vflip(RID p_viewport,bool p_enable);
+
+
+ void viewport_set_clear_mode(RID p_viewport,VS::ViewportClearMode p_clear_mode);
+
+ RID viewport_get_texture(RID p_viewport) const;
+ Image viewport_capture(RID p_viewport) const;
+
+ void viewport_set_hide_scenario(RID p_viewport,bool p_hide);
+ void viewport_set_hide_canvas(RID p_viewport,bool p_hide);
+ void viewport_set_disable_environment(RID p_viewport,bool p_disable);
+
+ void viewport_attach_camera(RID p_viewport,RID p_camera);
+ void viewport_set_scenario(RID p_viewport,RID p_scenario);
+ void viewport_attach_canvas(RID p_viewport,RID p_canvas);
+ void viewport_remove_canvas(RID p_viewport,RID p_canvas);
+ void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset);
+ void viewport_set_transparent_background(RID p_viewport,bool p_enabled);
+
+ void viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform);
+ void viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer);
+
+ void draw_viewports();
+
+ bool free(RID p_rid);
+
+ VisualServerViewport();
+};
+
+#endif // VISUALSERVERVIEWPORT_H
diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp
deleted file mode 100644
index 5ea4145342..0000000000
--- a/servers/visual/visual_server_wrap_mt.cpp
+++ /dev/null
@@ -1,212 +0,0 @@
-/*************************************************************************/
-/* visual_server_wrap_mt.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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. */
-/*************************************************************************/
-#include "visual_server_wrap_mt.h"
-#include "os/os.h"
-#include "globals.h"
-void VisualServerWrapMT::thread_exit() {
-
- exit=true;
-}
-
-void VisualServerWrapMT::thread_draw() {
-
-
- draw_mutex->lock();
-
- draw_pending--;
- bool draw=(draw_pending==0);// only draw when no more flushes are pending
-
- draw_mutex->unlock();
-
- if (draw) {
-
- visual_server->draw();
- }
-
-}
-
-void VisualServerWrapMT::thread_flush() {
-
-
- draw_mutex->lock();
-
- draw_pending--;
-
- draw_mutex->unlock();
-
-}
-
-
-
-void VisualServerWrapMT::_thread_callback(void *_instance) {
-
- VisualServerWrapMT *vsmt = reinterpret_cast<VisualServerWrapMT*>(_instance);
-
-
- vsmt->thread_loop();
-}
-
-void VisualServerWrapMT::thread_loop() {
-
- server_thread=Thread::get_caller_ID();
-
- OS::get_singleton()->make_rendering_thread();
-
- visual_server->init();
-
- exit=false;
- draw_thread_up=true;
- while(!exit) {
- // flush commands one by one, until exit is requested
- command_queue.wait_and_flush_one();
- }
-
- command_queue.flush_all(); // flush all
-
- visual_server->finish();
-
-}
-
-
-/* EVENT QUEUING */
-
-void VisualServerWrapMT::sync() {
-
- if (create_thread) {
-
- /* TODO: sync with the thread */
-
- /*
- ERR_FAIL_COND(!draw_mutex);
- draw_mutex->lock();
- draw_pending++; //cambiar por un saferefcount
- draw_mutex->unlock();
- */
- //command_queue.push( this, &VisualServerWrapMT::thread_flush);
- } else {
-
- command_queue.flush_all(); //flush all pending from other threads
- }
-
-}
-
-void VisualServerWrapMT::draw() {
-
-
- if (create_thread) {
-
- /* TODO: Make it draw
- ERR_FAIL_COND(!draw_mutex);
- draw_mutex->lock();
- draw_pending++; //cambiar por un saferefcount
- draw_mutex->unlock();
-
- command_queue.push( this, &VisualServerWrapMT::thread_draw);
- */
- } else {
-
- visual_server->draw();
- }
-}
-
-
-void VisualServerWrapMT::init() {
-
- if (create_thread) {
-
- draw_mutex = Mutex::create();
- print_line("CREATING RENDER THREAD");
- OS::get_singleton()->release_rendering_thread();
- if (create_thread) {
- thread = Thread::create( _thread_callback, this );
- print_line("STARTING RENDER THREAD");
- }
- while(!draw_thread_up) {
- OS::get_singleton()->delay_usec(1000);
- }
- print_line("DONE RENDER THREAD");
- } else {
-
- visual_server->init();
- }
-
-}
-
-void VisualServerWrapMT::finish() {
-
-
- if (thread) {
-
- command_queue.push( this, &VisualServerWrapMT::thread_exit);
- Thread::wait_to_finish( thread );
- memdelete(thread);
-
-
- texture_free_cached_ids();
- mesh_free_cached_ids();
-
- thread=NULL;
- } else {
- visual_server->finish();
- }
-
- if (draw_mutex)
- memdelete(draw_mutex);
-
-}
-
-
-VisualServerWrapMT::VisualServerWrapMT(VisualServer* p_contained,bool p_create_thread) : command_queue(p_create_thread) {
-
- visual_server=p_contained;
- create_thread=p_create_thread;
- thread=NULL;
- draw_mutex=NULL;
- draw_pending=0;
- draw_thread_up=false;
- alloc_mutex=Mutex::create();
- texture_pool_max_size=GLOBAL_DEF("render/thread_textures_prealloc",5);
- mesh_pool_max_size=GLOBAL_DEF("core/rid_pool_prealloc",20);
- if (!p_create_thread) {
- server_thread=Thread::get_caller_ID();
- } else {
- server_thread=0;
- }
-}
-
-
-VisualServerWrapMT::~VisualServerWrapMT() {
-
- memdelete(visual_server);
- memdelete(alloc_mutex);
- //finish();
-
-}
-
-
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
deleted file mode 100644
index b4e374dd6f..0000000000
--- a/servers/visual/visual_server_wrap_mt.h
+++ /dev/null
@@ -1,739 +0,0 @@
-/*************************************************************************/
-/* visual_server_wrap_mt.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 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 VISUAL_SERVER_WRAP_MT_H
-#define VISUAL_SERVER_WRAP_MT_H
-
-
-#include "servers/visual_server.h"
-#include "command_queue_mt.h"
-#include "os/thread.h"
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-class VisualServerWrapMT : public VisualServer {
-
- // the real visual server
- mutable VisualServer *visual_server;
-
- mutable CommandQueueMT command_queue;
-
- static void _thread_callback(void *_instance);
- void thread_loop();
-
- Thread::ID server_thread;
- volatile bool exit;
- Thread *thread;
- volatile bool draw_thread_up;
- bool create_thread;
-
- Mutex *draw_mutex;
- int draw_pending;
- void thread_draw();
- void thread_flush();
-
- void thread_exit();
-
- Mutex*alloc_mutex;
-
-
- int texture_pool_max_size;
- List<RID> texture_id_pool;
-
- int mesh_pool_max_size;
- List<RID> mesh_id_pool;
-
-//#define DEBUG_SYNC
-
-#ifdef DEBUG_SYNC
-#define SYNC_DEBUG print_line("sync on: "+String(__FUNCTION__));
-#else
-#define SYNC_DEBUG
-#endif
-
-public:
-
-#define ServerName VisualServer
-#define ServerNameWrapMT VisualServerWrapMT
-#define server_name visual_server
-#include "servers/server_wrap_mt_common.h"
-
- //FUNC0R(RID,texture_create);
- FUNCRID(texture);
- FUNC5(texture_allocate,RID,int,int,Image::Format,uint32_t);
- FUNC3(texture_set_data,RID,const Image&,CubeMapSide);
- FUNC2RC(Image,texture_get_data,RID,CubeMapSide);
- FUNC2(texture_set_flags,RID,uint32_t);
- FUNC1RC(Image::Format,texture_get_format,RID);
- FUNC1RC(uint32_t,texture_get_flags,RID);
- FUNC1RC(uint32_t,texture_get_width,RID);
- FUNC1RC(uint32_t,texture_get_height,RID);
- FUNC3(texture_set_size_override,RID,int,int);
- FUNC1RC(bool,texture_can_stream,RID);
- FUNC3C(texture_set_reload_hook,RID,ObjectID,const StringName&);
-
- FUNC2(texture_set_path,RID,const String&);
- FUNC1RC(String,texture_get_path,RID);
-
- FUNC1(texture_set_shrink_all_x2_on_set_data,bool);
-
- virtual void texture_debug_usage(List<TextureInfo> *r_info) {
- //pass directly, should lock the server anyway
- visual_server->texture_debug_usage(r_info);
- }
-
-
- /* SHADER API */
-
- FUNC1R(RID,shader_create,ShaderMode);
- FUNC2(shader_set_mode,RID,ShaderMode);
- FUNC1RC(ShaderMode,shader_get_mode,RID);
- FUNC7(shader_set_code,RID,const String&,const String&,const String&,int,int,int);
- FUNC1RC(String,shader_get_vertex_code,RID);
- FUNC1RC(String,shader_get_fragment_code,RID);
- FUNC1RC(String,shader_get_light_code,RID);
- FUNC2SC(shader_get_param_list,RID,List<PropertyInfo>*);
-
- FUNC3(shader_set_default_texture_param,RID,const StringName&,RID);
- FUNC2RC(RID,shader_get_default_texture_param,RID,const StringName&);
-
-
- /*virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) {
- if (Thread::get_caller_ID()!=server_thread) {
- command_queue.push_and_sync( visual_server, &VisualServer::shader_get_param_list,p_shader,p_param_list);
- } else {
- visual_server->m_type(p1, p2, p3, p4, p5);
- }
- }*/
-
-// virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list);
-
-
- /* COMMON MATERIAL API */
-
- FUNC0R(RID,material_create);
- FUNC2(material_set_shader,RID,RID);
- FUNC1RC(RID,material_get_shader,RID);
-
- FUNC3(material_set_param,RID,const StringName&,const Variant&);
- FUNC2RC(Variant,material_get_param,RID,const StringName&);
-
- FUNC3(material_set_flag,RID,MaterialFlag,bool);
- FUNC2RC(bool,material_get_flag,RID,MaterialFlag);
-
- FUNC2(material_set_depth_draw_mode,RID,MaterialDepthDrawMode);
- FUNC1RC(MaterialDepthDrawMode,material_get_depth_draw_mode,RID);
-
- FUNC2(material_set_blend_mode,RID,MaterialBlendMode);
- FUNC1RC(MaterialBlendMode,material_get_blend_mode,RID);
-
- FUNC2(material_set_line_width,RID,float);
- FUNC1RC(float,material_get_line_width,RID);
-
- /* FIXED MATERIAL */
-
-
- FUNC0R(RID,fixed_material_create);
-
- FUNC3(fixed_material_set_flag,RID, FixedMaterialFlags , bool );
- FUNC2RC(bool, fixed_material_get_flag,RID, FixedMaterialFlags);
-
- FUNC3(fixed_material_set_param,RID, FixedMaterialParam, const Variant& );
- FUNC2RC(Variant, fixed_material_get_param,RID ,FixedMaterialParam);
-
- FUNC3(fixed_material_set_texture,RID ,FixedMaterialParam, RID );
- FUNC2RC(RID, fixed_material_get_texture,RID,FixedMaterialParam);
-
-
-
- FUNC3(fixed_material_set_texcoord_mode,RID,FixedMaterialParam, FixedMaterialTexCoordMode );
- FUNC2RC(FixedMaterialTexCoordMode, fixed_material_get_texcoord_mode,RID,FixedMaterialParam);
-
- FUNC2(fixed_material_set_light_shader,RID,FixedMaterialLightShader);
- FUNC1RC(FixedMaterialLightShader, fixed_material_get_light_shader,RID);
-
- FUNC2(fixed_material_set_uv_transform,RID,const Transform&);
- FUNC1RC(Transform, fixed_material_get_uv_transform,RID);
-
- FUNC2(fixed_material_set_point_size,RID ,float);
- FUNC1RC(float,fixed_material_get_point_size,RID);
-
- /* SURFACE API */
- FUNCRID(mesh);
-
- FUNC2(mesh_set_morph_target_count,RID,int);
- FUNC1RC(int,mesh_get_morph_target_count,RID);
-
-
- FUNC2(mesh_set_morph_target_mode,RID,MorphTargetMode);
- FUNC1RC(MorphTargetMode,mesh_get_morph_target_mode,RID);
-
- FUNC2(mesh_add_custom_surface,RID,const Variant&); //this is used by each platform in a different way
-
- FUNC5(mesh_add_surface,RID,PrimitiveType,const Array&,const Array&,bool);
- FUNC2RC(Array,mesh_get_surface_arrays,RID,int);
- FUNC2RC(Array,mesh_get_surface_morph_arrays,RID,int);
-
- FUNC4(mesh_surface_set_material,RID, int, RID,bool);
- FUNC2RC(RID,mesh_surface_get_material,RID, int);
-
- FUNC2RC(int,mesh_surface_get_array_len,RID, int);
- FUNC2RC(int,mesh_surface_get_array_index_len,RID, int);
- FUNC2RC(uint32_t,mesh_surface_get_format,RID, int);
- FUNC2RC(PrimitiveType,mesh_surface_get_primitive_type,RID, int);
-
- FUNC2(mesh_remove_surface,RID,int);
- FUNC1RC(int,mesh_get_surface_count,RID);
- FUNC1(mesh_clear,RID);
-
-
- FUNC2(mesh_set_custom_aabb,RID,const AABB&);
- FUNC1RC(AABB,mesh_get_custom_aabb,RID);
-
-
- /* MULTIMESH API */
-
- FUNC0R(RID,multimesh_create);
- FUNC2(multimesh_set_instance_count,RID,int);
- FUNC1RC(int,multimesh_get_instance_count,RID);
-
- FUNC2(multimesh_set_mesh,RID,RID);
- FUNC2(multimesh_set_aabb,RID,const AABB&);
- FUNC3(multimesh_instance_set_transform,RID,int,const Transform&);
- FUNC3(multimesh_instance_set_color,RID,int,const Color&);
-
- FUNC1RC(RID,multimesh_get_mesh,RID);
- FUNC2RC(AABB,multimesh_get_aabb,RID,const AABB&);
- FUNC2RC(Transform,multimesh_instance_get_transform,RID,int);
- FUNC2RC(Color,multimesh_instance_get_color,RID,int);
-
- FUNC2(multimesh_set_visible_instances,RID,int);
- FUNC1RC(int,multimesh_get_visible_instances,RID);
-
- /* IMMEDIATE API */
-
-
- FUNC0R(RID,immediate_create);
- FUNC3(immediate_begin,RID,PrimitiveType,RID);
- FUNC2(immediate_vertex,RID,const Vector3&);
- FUNC2(immediate_normal,RID,const Vector3&);
- FUNC2(immediate_tangent,RID,const Plane&);
- FUNC2(immediate_color,RID,const Color&);
- FUNC2(immediate_uv,RID,const Vector2&);
- FUNC2(immediate_uv2,RID,const Vector2&);
- FUNC1(immediate_end,RID);
- FUNC1(immediate_clear,RID);
- FUNC2(immediate_set_material,RID,RID);
- FUNC1RC(RID,immediate_get_material,RID);
-
-
- /* PARTICLES API */
-
- FUNC0R(RID,particles_create);
-
- FUNC2(particles_set_amount,RID, int );
- FUNC1RC(int,particles_get_amount,RID);
-
- FUNC2(particles_set_emitting,RID, bool );
- FUNC1RC(bool,particles_is_emitting,RID);
-
- FUNC2(particles_set_visibility_aabb,RID, const AABB&);
- FUNC1RC(AABB,particles_get_visibility_aabb,RID);
-
- FUNC2(particles_set_emission_half_extents,RID, const Vector3&);
- FUNC1RC(Vector3,particles_get_emission_half_extents,RID);
-
- FUNC2(particles_set_emission_base_velocity,RID, const Vector3&);
- FUNC1RC(Vector3,particles_get_emission_base_velocity,RID);
-
- FUNC2(particles_set_emission_points,RID, const DVector<Vector3>& );
- FUNC1RC(DVector<Vector3>,particles_get_emission_points,RID);
-
- FUNC2(particles_set_gravity_normal,RID, const Vector3& );
- FUNC1RC(Vector3,particles_get_gravity_normal,RID);
-
- FUNC3(particles_set_variable,RID, ParticleVariable ,float);
- FUNC2RC(float,particles_get_variable,RID, ParticleVariable );
-
- FUNC3(particles_set_randomness,RID, ParticleVariable ,float);
- FUNC2RC(float,particles_get_randomness,RID, ParticleVariable );
-
- FUNC3(particles_set_color_phase_pos,RID, int , float);
- FUNC2RC(float,particles_get_color_phase_pos,RID, int );
-
- FUNC2(particles_set_color_phases,RID, int );
- FUNC1RC(int,particles_get_color_phases,RID);
-
- FUNC3(particles_set_color_phase_color,RID, int , const Color& );
- FUNC2RC(Color,particles_get_color_phase_color,RID, int );
-
- FUNC2(particles_set_attractors,RID, int);
- FUNC1RC(int,particles_get_attractors,RID);
-
- FUNC3(particles_set_attractor_pos,RID, int, const Vector3&);
- FUNC2RC(Vector3,particles_get_attractor_pos,RID,int);
-
- FUNC3(particles_set_attractor_strength,RID, int, float);
- FUNC2RC(float,particles_get_attractor_strength,RID,int);
-
- FUNC3(particles_set_material,RID, RID,bool);
- FUNC1RC(RID,particles_get_material,RID);
-
- FUNC2(particles_set_height_from_velocity,RID, bool);
- FUNC1RC(bool,particles_has_height_from_velocity,RID);
-
- FUNC2(particles_set_use_local_coordinates,RID, bool);
- FUNC1RC(bool,particles_is_using_local_coordinates,RID);
-
-
- /* Light API */
-
- FUNC1R(RID,light_create,LightType);
- FUNC1RC(LightType,light_get_type,RID);
-
- FUNC3(light_set_color,RID,LightColor , const Color& );
- FUNC2RC(Color,light_get_color,RID,LightColor );
-
-
- FUNC2(light_set_shadow,RID,bool );
- FUNC1RC(bool,light_has_shadow,RID);
-
- FUNC2(light_set_volumetric,RID,bool );
- FUNC1RC(bool,light_is_volumetric,RID);
-
- FUNC2(light_set_projector,RID,RID );
- FUNC1RC(RID,light_get_projector,RID);
-
- FUNC3(light_set_param,RID, LightParam , float );
- FUNC2RC(float,light_get_param,RID, LightParam );
-
- FUNC2(light_set_operator,RID,LightOp);
- FUNC1RC(LightOp,light_get_operator,RID);
-
- FUNC2(light_omni_set_shadow_mode,RID,LightOmniShadowMode);
- FUNC1RC(LightOmniShadowMode,light_omni_get_shadow_mode,RID);
-
- FUNC2(light_directional_set_shadow_mode,RID,LightDirectionalShadowMode);
- FUNC1RC(LightDirectionalShadowMode,light_directional_get_shadow_mode,RID);
- FUNC3(light_directional_set_shadow_param,RID,LightDirectionalShadowParam, float );
- FUNC2RC(float,light_directional_get_shadow_param,RID,LightDirectionalShadowParam );
-
-
- /* SKELETON API */
-
- FUNC0R(RID,skeleton_create);
- FUNC2(skeleton_resize,RID,int );
- FUNC1RC(int,skeleton_get_bone_count,RID) ;
- FUNC3(skeleton_bone_set_transform,RID,int, const Transform&);
- FUNC2R(Transform,skeleton_bone_get_transform,RID,int );
-
- /* ROOM API */
-
- FUNC0R(RID,room_create);
- FUNC2(room_set_bounds,RID, const BSP_Tree&);
- FUNC1RC(BSP_Tree,room_get_bounds,RID);
-
- /* PORTAL API */
-
- FUNC0R(RID,portal_create);
- FUNC2(portal_set_shape,RID,const Vector<Point2>&);
- FUNC1RC(Vector<Point2>,portal_get_shape,RID);
- FUNC2(portal_set_enabled,RID, bool);
- FUNC1RC(bool,portal_is_enabled,RID);
- FUNC2(portal_set_disable_distance,RID, float);
- FUNC1RC(float,portal_get_disable_distance,RID);
- FUNC2(portal_set_disabled_color,RID, const Color&);
- FUNC1RC(Color,portal_get_disabled_color,RID);
- FUNC2(portal_set_connect_range,RID, float);
- FUNC1RC(float,portal_get_connect_range,RID);
-
-
- FUNC0R(RID,baked_light_create);
- FUNC2(baked_light_set_mode,RID,BakedLightMode);
- FUNC1RC(BakedLightMode,baked_light_get_mode,RID);
-
- FUNC2(baked_light_set_octree,RID,DVector<uint8_t>);
- FUNC1RC(DVector<uint8_t>,baked_light_get_octree,RID);
-
- FUNC2(baked_light_set_light,RID,DVector<uint8_t>);
- FUNC1RC(DVector<uint8_t>,baked_light_get_light,RID);
-
- FUNC2(baked_light_set_sampler_octree,RID,const DVector<int>&);
- FUNC1RC(DVector<int>,baked_light_get_sampler_octree,RID);
-
- FUNC2(baked_light_set_lightmap_multiplier,RID,float);
- FUNC1RC(float,baked_light_get_lightmap_multiplier,RID);
-
- FUNC3(baked_light_add_lightmap,RID,RID,int);
- FUNC1(baked_light_clear_lightmaps,RID);
-
- FUNC2(baked_light_set_realtime_color_enabled, RID, const bool);
- FUNC1RC(bool, baked_light_get_realtime_color_enabled, RID);
-
- FUNC2(baked_light_set_realtime_color, RID, const Color&);
- FUNC1RC(Color, baked_light_get_realtime_color, RID);
-
- FUNC2(baked_light_set_realtime_energy, RID, const float);
- FUNC1RC(float, baked_light_get_realtime_energy, RID);
-
- FUNC0R(RID,baked_light_sampler_create);
-
- FUNC3(baked_light_sampler_set_param,RID, BakedLightSamplerParam , float );
- FUNC2RC(float,baked_light_sampler_get_param,RID, BakedLightSamplerParam );
-
- FUNC2(baked_light_sampler_set_resolution,RID,int);
- FUNC1RC(int,baked_light_sampler_get_resolution,RID);
-
- /* CAMERA API */
-
- FUNC0R(RID,camera_create);
- FUNC4(camera_set_perspective,RID,float , float , float );
- FUNC4(camera_set_orthogonal,RID,float, float , float );
- FUNC2(camera_set_transform,RID,const Transform& );
-
- FUNC2(camera_set_visible_layers,RID,uint32_t);
- FUNC1RC(uint32_t,camera_get_visible_layers,RID);
-
- FUNC2(camera_set_environment,RID,RID);
- FUNC1RC(RID,camera_get_environment,RID);
-
-
- FUNC2(camera_set_use_vertical_aspect,RID,bool);
- FUNC2RC(bool,camera_is_using_vertical_aspect,RID,bool);
-
-
- /* VIEWPORT API */
-
- FUNC0R(RID,viewport_create);
-
- FUNC2(viewport_attach_to_screen,RID,int );
- FUNC1(viewport_detach,RID);
-
- FUNC2(viewport_set_as_render_target,RID,bool);
- FUNC2(viewport_set_render_target_update_mode,RID,RenderTargetUpdateMode);
- FUNC1RC(RenderTargetUpdateMode,viewport_get_render_target_update_mode,RID);
- FUNC1RC(RID,viewport_get_render_target_texture,RID);
-
- FUNC2(viewport_set_render_target_vflip,RID,bool);
- FUNC1RC(bool,viewport_get_render_target_vflip,RID);
- FUNC2(viewport_set_render_target_to_screen_rect,RID,const Rect2&);
-
- FUNC2(viewport_set_render_target_clear_on_new_frame,RID,bool);
- FUNC1RC(bool,viewport_get_render_target_clear_on_new_frame,RID);
- FUNC1(viewport_render_target_clear,RID);
-
- FUNC1(viewport_queue_screen_capture,RID);
- FUNC1RC(Image,viewport_get_screen_capture,RID);
-
- FUNC2(viewport_set_rect,RID,const ViewportRect&);
- FUNC1RC(ViewportRect,viewport_get_rect,RID);
-
- FUNC2(viewport_set_hide_scenario,RID,bool );
- FUNC2(viewport_set_hide_canvas,RID,bool );
- FUNC2(viewport_attach_camera,RID,RID );
- FUNC2(viewport_set_scenario,RID,RID );
- FUNC2(viewport_set_disable_environment,RID,bool );
-
- FUNC1RC(RID,viewport_get_attached_camera,RID);
- FUNC1RC(RID,viewport_get_scenario,RID );
- FUNC2(viewport_attach_canvas,RID,RID);
- FUNC2(viewport_remove_canvas,RID,RID);
- FUNC3(viewport_set_canvas_transform,RID,RID,const Matrix32&);
- FUNC2RC(Matrix32,viewport_get_canvas_transform,RID,RID);
- FUNC2(viewport_set_global_canvas_transform,RID,const Matrix32&);
- FUNC1RC(Matrix32,viewport_get_global_canvas_transform,RID);
- FUNC3(viewport_set_canvas_layer,RID,RID ,int);
- FUNC2(viewport_set_transparent_background,RID,bool);
- FUNC1RC(bool,viewport_has_transparent_background,RID);
-
-
- /* ENVIRONMENT API */
-
- FUNC0R(RID,environment_create);
-
- FUNC2(environment_set_background,RID,EnvironmentBG);
- FUNC1RC(EnvironmentBG,environment_get_background,RID);
-
- FUNC3(environment_set_background_param,RID,EnvironmentBGParam, const Variant&);
- FUNC2RC(Variant,environment_get_background_param,RID,EnvironmentBGParam );
-
- FUNC3(environment_set_enable_fx,RID,EnvironmentFx,bool);
- FUNC2RC(bool,environment_is_fx_enabled,RID,EnvironmentFx);
-
-
- FUNC3(environment_fx_set_param,RID,EnvironmentFxParam,const Variant&);
- FUNC2RC(Variant,environment_fx_get_param,RID,EnvironmentFxParam);
-
-
- /* SCENARIO API */
-
- FUNC0R(RID,scenario_create);
-
- FUNC2(scenario_set_debug,RID,ScenarioDebugMode);
- FUNC2(scenario_set_environment,RID, RID);
- FUNC2RC(RID,scenario_get_environment,RID, RID);
- FUNC2(scenario_set_fallback_environment,RID, RID);
-
-
- /* INSTANCING API */
-
- FUNC0R(RID,instance_create);
-
- FUNC2(instance_set_base,RID, RID);
- FUNC1RC(RID,instance_get_base,RID);
-
- FUNC2(instance_set_scenario,RID, RID);
- FUNC1RC(RID,instance_get_scenario,RID);
-
- FUNC2(instance_set_layer_mask,RID, uint32_t);
- FUNC1RC(uint32_t,instance_get_layer_mask,RID);
-
- FUNC1RC(AABB,instance_get_base_aabb,RID);
-
- FUNC2(instance_attach_object_instance_ID,RID,uint32_t);
- FUNC1RC(uint32_t,instance_get_object_instance_ID,RID);
-
- FUNC2(instance_attach_skeleton,RID,RID);
- FUNC1RC(RID,instance_get_skeleton,RID);
-
- FUNC3(instance_set_morph_target_weight,RID,int, float);
- FUNC2RC(float,instance_get_morph_target_weight,RID,int);
-
- FUNC3(instance_set_surface_material,RID,int, RID);
-
- FUNC2(instance_set_transform,RID, const Transform&);
- FUNC1RC(Transform,instance_get_transform,RID);
-
- FUNC2(instance_set_exterior,RID, bool );
- FUNC1RC(bool,instance_is_exterior,RID);
-
- FUNC2(instance_set_room,RID, RID );
- FUNC1RC(RID,instance_get_room,RID ) ;
-
- FUNC2(instance_set_extra_visibility_margin,RID, real_t );
- FUNC1RC(real_t,instance_get_extra_visibility_margin,RID );
-
- FUNC2RC(Vector<RID>,instances_cull_aabb,const AABB& , RID );
- FUNC3RC(Vector<RID>,instances_cull_ray,const Vector3& ,const Vector3&, RID );
- FUNC2RC(Vector<RID>,instances_cull_convex,const Vector<Plane>& , RID );
-
- FUNC3(instance_geometry_set_flag,RID,InstanceFlags ,bool );
- FUNC2RC(bool,instance_geometry_get_flag,RID,InstanceFlags );
-
- FUNC2(instance_geometry_set_cast_shadows_setting, RID, ShadowCastingSetting);
- FUNC1RC(ShadowCastingSetting, instance_geometry_get_cast_shadows_setting, RID);
-
- FUNC2(instance_geometry_set_material_override,RID, RID );
- FUNC1RC(RID,instance_geometry_get_material_override,RID);
-
- FUNC3(instance_geometry_set_draw_range,RID,float ,float);
- FUNC1RC(float,instance_geometry_get_draw_range_max,RID);
- FUNC1RC(float,instance_geometry_get_draw_range_min,RID);
-
- FUNC2(instance_geometry_set_baked_light,RID, RID );
- FUNC1RC(RID,instance_geometry_get_baked_light,RID);
-
- FUNC2(instance_geometry_set_baked_light_sampler,RID, RID );
- FUNC1RC(RID,instance_geometry_get_baked_light_sampler,RID);
-
- FUNC2(instance_geometry_set_baked_light_texture_index,RID, int);
- FUNC1RC(int,instance_geometry_get_baked_light_texture_index,RID);
-
- FUNC2(instance_light_set_enabled,RID,bool);
- FUNC1RC(bool,instance_light_is_enabled,RID);
-
- /* CANVAS (2D) */
-
- FUNC0R(RID,canvas_create);
- FUNC3(canvas_set_item_mirroring,RID,RID,const Point2&);
- FUNC2RC(Point2,canvas_get_item_mirroring,RID,RID);
- FUNC2(canvas_set_modulate,RID,const Color&);
-
-
- FUNC0R(RID,canvas_item_create);
-
- FUNC2(canvas_item_set_parent,RID,RID );
- FUNC1RC(RID,canvas_item_get_parent,RID);
-
- FUNC2(canvas_item_set_visible,RID,bool );
- FUNC1RC(bool,canvas_item_is_visible,RID);
-
- FUNC2(canvas_item_set_blend_mode,RID,MaterialBlendMode );
- FUNC2(canvas_item_set_light_mask,RID,int );
-
- //FUNC(canvas_item_set_rect,RID, const Rect2& p_rect);
- FUNC2(canvas_item_set_transform,RID, const Matrix32& );
- FUNC2(canvas_item_set_clip,RID, bool );
- FUNC2(canvas_item_set_distance_field_mode,RID, bool );
- FUNC3(canvas_item_set_custom_rect,RID, bool ,const Rect2&);
- FUNC2(canvas_item_set_opacity,RID, float );
- FUNC2RC(float,canvas_item_get_opacity,RID, float );
- FUNC2(canvas_item_set_on_top,RID, bool );
- FUNC1RC(bool,canvas_item_is_on_top,RID);
-
- FUNC2(canvas_item_set_self_opacity,RID, float );
- FUNC2RC(float,canvas_item_get_self_opacity,RID, float );
-
- FUNC2(canvas_item_attach_viewport,RID, RID );
-
- FUNC6(canvas_item_add_line,RID, const Point2& , const Point2& ,const Color& ,float,bool);
- FUNC3(canvas_item_add_rect,RID, const Rect2& , const Color& );
- FUNC4(canvas_item_add_circle,RID, const Point2& , float ,const Color& );
- FUNC6(canvas_item_add_texture_rect,RID, const Rect2& , RID ,bool ,const Color&,bool );
- FUNC6(canvas_item_add_texture_rect_region,RID, const Rect2& , RID ,const Rect2& ,const Color&,bool );
- FUNC8(canvas_item_add_style_box,RID, const Rect2& , const Rect2&, RID ,const Vector2& ,const Vector2&, bool ,const Color& );
- FUNC6(canvas_item_add_primitive,RID, const Vector<Point2>& , const Vector<Color>& ,const Vector<Point2>& , RID ,float );
- FUNC5(canvas_item_add_polygon,RID, const Vector<Point2>& , const Vector<Color>& ,const Vector<Point2>& , RID );
- FUNC7(canvas_item_add_triangle_array,RID, const Vector<int>& , const Vector<Point2>& , const Vector<Color>& ,const Vector<Point2>& , RID , int );
- FUNC7(canvas_item_add_triangle_array_ptr,RID, int , const int* , const Point2* , const Color* ,const Point2* , RID );
-
-
- FUNC2(canvas_item_add_set_transform,RID,const Matrix32& );
- FUNC2(canvas_item_add_set_blend_mode,RID, MaterialBlendMode );
- FUNC2(canvas_item_add_clip_ignore,RID, bool );
-
- FUNC2(canvas_item_set_sort_children_by_y,RID,bool);
- FUNC2(canvas_item_set_z,RID,int);
- FUNC2(canvas_item_set_z_as_relative_to_parent,RID,bool);
- FUNC3(canvas_item_set_copy_to_backbuffer,RID,bool,const Rect2&);
-
-
- FUNC2(canvas_item_set_material,RID, RID );
-
- FUNC2(canvas_item_set_use_parent_material,RID, bool );
-
- FUNC1(canvas_item_clear,RID);
- FUNC1(canvas_item_raise,RID);
-
- /* CANVAS LIGHT */
- FUNC0R(RID,canvas_light_create);
- FUNC2(canvas_light_attach_to_canvas,RID,RID);
- FUNC2(canvas_light_set_enabled,RID,bool);
- FUNC2(canvas_light_set_transform,RID,const Matrix32&);
- FUNC2(canvas_light_set_scale,RID,float);
- FUNC2(canvas_light_set_texture,RID,RID);
- FUNC2(canvas_light_set_texture_offset,RID,const Vector2&);
- FUNC2(canvas_light_set_color,RID,const Color&);
- FUNC2(canvas_light_set_height,RID,float);
- FUNC2(canvas_light_set_energy,RID,float);
- FUNC3(canvas_light_set_layer_range,RID,int,int);
- FUNC3(canvas_light_set_z_range,RID,int,int);
- FUNC2(canvas_light_set_item_mask,RID,int);
- FUNC2(canvas_light_set_item_shadow_mask,RID,int);
-
- FUNC2(canvas_light_set_mode,RID,CanvasLightMode);
- FUNC2(canvas_light_set_shadow_enabled,RID,bool);
- FUNC2(canvas_light_set_shadow_buffer_size,RID,int);
- FUNC2(canvas_light_set_shadow_esm_multiplier,RID,float);
- FUNC2(canvas_light_set_shadow_color,RID,const Color&);
-
-
-
- /* CANVAS OCCLUDER */
-
- FUNC0R(RID,canvas_light_occluder_create);
- FUNC2(canvas_light_occluder_attach_to_canvas,RID,RID);
- FUNC2(canvas_light_occluder_set_enabled,RID,bool);
- FUNC2(canvas_light_occluder_set_polygon,RID,RID);
- FUNC2(canvas_light_occluder_set_transform,RID,const Matrix32&);
- FUNC2(canvas_light_occluder_set_light_mask,RID,int);
-
-
- FUNC0R(RID,canvas_occluder_polygon_create);
- FUNC3(canvas_occluder_polygon_set_shape,RID,const DVector<Vector2>&,bool);
- FUNC2(canvas_occluder_polygon_set_shape_as_lines,RID,const DVector<Vector2>&);
- FUNC2(canvas_occluder_polygon_set_cull_mode,RID,CanvasOccluderPolygonCullMode);
-
- /* CANVAS MATERIAL */
-
- FUNC0R(RID,canvas_item_material_create);
- FUNC2(canvas_item_material_set_shader,RID,RID);
- FUNC3(canvas_item_material_set_shader_param,RID,const StringName&,const Variant&);
- FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&);
- FUNC2(canvas_item_material_set_shading_mode,RID,CanvasItemShadingMode);
-
- /* CURSOR */
- FUNC2(cursor_set_rotation,float , int ); // radians
- FUNC4(cursor_set_texture,RID , const Point2 &, int, const Rect2 &);
- FUNC2(cursor_set_visible,bool , int );
- FUNC2(cursor_set_pos,const Point2& , int );
-
- /* BLACK BARS */
-
- FUNC4(black_bars_set_margins,int , int , int , int );
- FUNC4(black_bars_set_images,RID , RID , RID , RID );
-
- /* FREE */
-
- FUNC1(free,RID);
-
- /* CUSTOM SHADE MODEL */
-
- FUNC2(custom_shade_model_set_shader,int , RID );
- FUNC1RC(RID,custom_shade_model_get_shader,int );
- FUNC2(custom_shade_model_set_name,int , const String& );
- FUNC1RC(String,custom_shade_model_get_name,int );
- FUNC2(custom_shade_model_set_param_info,int , const List<PropertyInfo>& );
- FUNC2SC(custom_shade_model_get_param_info,int , List<PropertyInfo>* );
-
- /* EVENT QUEUING */
-
-
- virtual void init();
- virtual void finish();
- virtual void draw();
- virtual void sync();
- FUNC0RC(bool,has_changed);
-
- /* RENDER INFO */
-
- FUNC1R(int,get_render_info,RenderInfo );
- virtual bool has_feature(Features p_feature) const { return visual_server->has_feature(p_feature); }
-
- FUNC3(set_boot_image,const Image& , const Color&,bool );
- FUNC1(set_default_clear_color,const Color& );
-
- FUNC0R(RID,get_test_cube );
-
-
- VisualServerWrapMT(VisualServer* p_contained,bool p_create_thread);
- ~VisualServerWrapMT();
-
-#undef ServerName
-#undef ServerNameWrapMT
-#undef server_name
-
-};
-
-#ifdef DEBUG_SYNC
-#undef DEBUG_SYNC
-#endif
-#undef SYNC_DEBUG
-
-#endif
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index f69580254c..175dfd47d1 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -39,16 +39,6 @@ VisualServer *VisualServer::get_singleton() {
}
-void VisualServer::set_mipmap_policy(MipMapPolicy p_policy) {
-
- mm_policy=p_policy;
-}
-
-VisualServer::MipMapPolicy VisualServer::get_mipmap_policy() const {
-
- return (VisualServer::MipMapPolicy)mm_policy;
-}
-
DVector<String> VisualServer::_shader_get_param_list(RID p_shader) const {
@@ -93,38 +83,48 @@ RID VisualServer::texture_create_from_image(const Image& p_image,uint32_t p_flag
RID VisualServer::get_test_texture() {
- if (test_texture) {
+ if (test_texture.is_valid()) {
return test_texture;
};
#define TEST_TEXTURE_SIZE 256
- Image data(TEST_TEXTURE_SIZE,TEST_TEXTURE_SIZE,0,Image::FORMAT_RGB);
- for (int x=0;x<TEST_TEXTURE_SIZE;x++) {
+ DVector<uint8_t> test_data;
+ test_data.resize(TEST_TEXTURE_SIZE*TEST_TEXTURE_SIZE*3);
- for (int y=0;y<TEST_TEXTURE_SIZE;y++) {
+ {
+ DVector<uint8_t>::Write w=test_data.write();
- Color c;
- int r=255-(x+y)/2;
+ for (int x=0;x<TEST_TEXTURE_SIZE;x++) {
- if ((x%(TEST_TEXTURE_SIZE/8))<2 ||(y%(TEST_TEXTURE_SIZE/8))<2) {
+ for (int y=0;y<TEST_TEXTURE_SIZE;y++) {
- c.r=y;
- c.g=r;
- c.b=x;
+ Color c;
+ int r=255-(x+y)/2;
- } else {
+ if ((x%(TEST_TEXTURE_SIZE/8))<2 ||(y%(TEST_TEXTURE_SIZE/8))<2) {
- c.r=r;
- c.g=x;
- c.b=y;
- }
+ c.r=y;
+ c.g=r;
+ c.b=x;
+
+ } else {
+
+ c.r=r;
+ c.g=x;
+ c.b=y;
+ }
- data.put_pixel(x, y, c);
+ w[(y*TEST_TEXTURE_SIZE+x)*3+0]=uint8_t(CLAMP(c.r*255,0,255));
+ w[(y*TEST_TEXTURE_SIZE+x)*3+1]=uint8_t(CLAMP(c.g*255,0,255));
+ w[(y*TEST_TEXTURE_SIZE+x)*3+2]=uint8_t(CLAMP(c.b*255,0,255));
+ }
}
}
+ Image data(TEST_TEXTURE_SIZE,TEST_TEXTURE_SIZE,false,Image::FORMAT_RGB8,test_data);
+
test_texture = texture_create_from_image(data);
return test_texture;
@@ -217,10 +217,10 @@ RID VisualServer::_make_test_cube() {
indices.set(i,i);
d[VisualServer::ARRAY_INDEX]=indices;
- mesh_add_surface( test_cube, PRIMITIVE_TRIANGLES,d );
-
+ mesh_add_surface_from_arrays( test_cube, PRIMITIVE_TRIANGLES,d );
+/*
test_material = fixed_material_create();
//material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
fixed_material_set_texture( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
@@ -229,7 +229,7 @@ RID VisualServer::_make_test_cube() {
fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
-
+*/
mesh_surface_set_material(test_cube, 0, test_material );
return test_cube;
@@ -289,7 +289,7 @@ RID VisualServer::make_sphere_mesh(int p_lats,int p_lons,float p_radius) {
d[ARRAY_VERTEX]=vertices;
d[ARRAY_NORMAL]=normals;
- mesh_add_surface(mesh,PRIMITIVE_TRIANGLES,d);
+ mesh_add_surface_from_arrays(mesh,PRIMITIVE_TRIANGLES,d);
return mesh;
}
@@ -311,7 +311,7 @@ RID VisualServer::material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_
//not valid, make
- material_2d[version]=fixed_material_create();
+/* material_2d[version]=fixed_material_create();
fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_ALPHA,p_transparent);
fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_DISCARD_ALPHA,p_cut_alpha);
@@ -319,7 +319,8 @@ RID VisualServer::material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_
material_set_flag(material_2d[version],MATERIAL_FLAG_DOUBLE_SIDED,true);
material_set_depth_draw_mode(material_2d[version],p_opaque_prepass?MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA:MATERIAL_DEPTH_DRAW_OPAQUE_ONLY);
fixed_material_set_texture(material_2d[version],FIXED_MATERIAL_PARAM_DIFFUSE,get_white_texture());
- //material cut alpha?
+ //material cut alpha?*/
+
return material_2d[version];
}
@@ -335,14 +336,20 @@ RID VisualServer::get_white_texture() {
for(int i=0;i<16*3;i++)
w[i]=255;
}
- Image white(4,4,0,Image::FORMAT_RGB,wt);
+ Image white(4,4,0,Image::FORMAT_RGB8,wt);
white_texture=texture_create();
- texture_allocate(white_texture,4,4,Image::FORMAT_RGB);
+ texture_allocate(white_texture,4,4,Image::FORMAT_RGB8);
texture_set_data(white_texture,white);
return white_texture;
}
+
+void VisualServer::mesh_add_surface_from_arrays(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,uint32_t p_compress_format) {
+
+
+}
+
void VisualServer::_bind_methods() {
@@ -358,349 +365,7 @@ void VisualServer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("texture_set_shrink_all_x2_on_set_data","shrink"),&VisualServer::texture_set_shrink_all_x2_on_set_data );
-#ifndef _3D_DISABLED
-
-
- ObjectTypeDB::bind_method(_MD("shader_create","mode"),&VisualServer::shader_create,DEFVAL(SHADER_MATERIAL));
- ObjectTypeDB::bind_method(_MD("shader_set_mode","shader","mode"),&VisualServer::shader_set_mode);
-
-
-
- ObjectTypeDB::bind_method(_MD("material_create"),&VisualServer::material_create);
-
- ObjectTypeDB::bind_method(_MD("material_set_shader","shader"),&VisualServer::material_set_shader);
- ObjectTypeDB::bind_method(_MD("material_get_shader"),&VisualServer::material_get_shader);
-
- ObjectTypeDB::bind_method(_MD("material_set_param"),&VisualServer::material_set_param);
- ObjectTypeDB::bind_method(_MD("material_get_param"),&VisualServer::material_get_param);
- ObjectTypeDB::bind_method(_MD("material_set_flag"),&VisualServer::material_set_flag);
- ObjectTypeDB::bind_method(_MD("material_get_flag"),&VisualServer::material_get_flag);
- ObjectTypeDB::bind_method(_MD("material_set_blend_mode"),&VisualServer::material_set_blend_mode);
- ObjectTypeDB::bind_method(_MD("material_get_blend_mode"),&VisualServer::material_get_blend_mode);
- ObjectTypeDB::bind_method(_MD("material_set_line_width"),&VisualServer::material_set_line_width);
- ObjectTypeDB::bind_method(_MD("material_get_line_width"),&VisualServer::material_get_line_width);
-
-
- ObjectTypeDB::bind_method(_MD("mesh_create"),&VisualServer::mesh_create);
- ObjectTypeDB::bind_method(_MD("mesh_add_surface"),&VisualServer::mesh_add_surface, DEFVAL(NO_INDEX_ARRAY));
- ObjectTypeDB::bind_method(_MD("mesh_surface_set_material"),&VisualServer::mesh_surface_set_material,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("mesh_surface_get_material"),&VisualServer::mesh_surface_get_material);
-
- ObjectTypeDB::bind_method(_MD("mesh_surface_get_array_len"),&VisualServer::mesh_surface_get_array_len);
- ObjectTypeDB::bind_method(_MD("mesh_surface_get_array_index_len"),&VisualServer::mesh_surface_get_array_index_len);
- ObjectTypeDB::bind_method(_MD("mesh_surface_get_format"),&VisualServer::mesh_surface_get_format);
- ObjectTypeDB::bind_method(_MD("mesh_surface_get_primitive_type"),&VisualServer::mesh_surface_get_primitive_type);
-
- ObjectTypeDB::bind_method(_MD("mesh_remove_surface"),&VisualServer::mesh_remove_surface);
- ObjectTypeDB::bind_method(_MD("mesh_get_surface_count"),&VisualServer::mesh_get_surface_count);
-
-
- ObjectTypeDB::bind_method(_MD("multimesh_create"),&VisualServer::multimesh_create);
- ObjectTypeDB::bind_method(_MD("multimesh_set_mesh"),&VisualServer::multimesh_set_mesh);
- ObjectTypeDB::bind_method(_MD("multimesh_set_aabb"),&VisualServer::multimesh_set_aabb);
- ObjectTypeDB::bind_method(_MD("multimesh_instance_set_transform"),&VisualServer::multimesh_instance_set_transform);
- ObjectTypeDB::bind_method(_MD("multimesh_instance_set_color"),&VisualServer::multimesh_instance_set_color);
- ObjectTypeDB::bind_method(_MD("multimesh_get_mesh"),&VisualServer::multimesh_get_mesh);
- ObjectTypeDB::bind_method(_MD("multimesh_get_aabb"),&VisualServer::multimesh_get_aabb);
- ObjectTypeDB::bind_method(_MD("multimesh_instance_get_transform"),&VisualServer::multimesh_instance_get_transform);
- ObjectTypeDB::bind_method(_MD("multimesh_instance_get_color"),&VisualServer::multimesh_instance_get_color);
-
-
-
- ObjectTypeDB::bind_method(_MD("particles_create"),&VisualServer::particles_create);
- ObjectTypeDB::bind_method(_MD("particles_set_amount"),&VisualServer::particles_set_amount);
- ObjectTypeDB::bind_method(_MD("particles_get_amount"),&VisualServer::particles_get_amount);
- ObjectTypeDB::bind_method(_MD("particles_set_emitting"),&VisualServer::particles_set_emitting);
- ObjectTypeDB::bind_method(_MD("particles_is_emitting"),&VisualServer::particles_is_emitting);
- ObjectTypeDB::bind_method(_MD("particles_set_visibility_aabb"),&VisualServer::particles_set_visibility_aabb);
- ObjectTypeDB::bind_method(_MD("particles_get_visibility_aabb"),&VisualServer::particles_get_visibility_aabb);
- ObjectTypeDB::bind_method(_MD("particles_set_variable"),&VisualServer::particles_set_variable);
- ObjectTypeDB::bind_method(_MD("particles_get_variable"),&VisualServer::particles_get_variable);
- ObjectTypeDB::bind_method(_MD("particles_set_randomness"),&VisualServer::particles_set_randomness);
- ObjectTypeDB::bind_method(_MD("particles_get_randomness"),&VisualServer::particles_get_randomness);
- ObjectTypeDB::bind_method(_MD("particles_set_color_phases"),&VisualServer::particles_set_color_phases);
- ObjectTypeDB::bind_method(_MD("particles_get_color_phases"),&VisualServer::particles_get_color_phases);
- ObjectTypeDB::bind_method(_MD("particles_set_color_phase_pos"),&VisualServer::particles_set_color_phase_pos);
- ObjectTypeDB::bind_method(_MD("particles_get_color_phase_pos"),&VisualServer::particles_get_color_phase_pos);
- ObjectTypeDB::bind_method(_MD("particles_set_color_phase_color"),&VisualServer::particles_set_color_phase_color);
- ObjectTypeDB::bind_method(_MD("particles_get_color_phase_color"),&VisualServer::particles_get_color_phase_color);
- ObjectTypeDB::bind_method(_MD("particles_set_attractors"),&VisualServer::particles_set_attractors);
- ObjectTypeDB::bind_method(_MD("particles_get_attractors"),&VisualServer::particles_get_attractors);
- ObjectTypeDB::bind_method(_MD("particles_set_attractor_pos"),&VisualServer::particles_set_attractor_pos);
- ObjectTypeDB::bind_method(_MD("particles_get_attractor_pos"),&VisualServer::particles_get_attractor_pos);
- ObjectTypeDB::bind_method(_MD("particles_set_attractor_strength"),&VisualServer::particles_set_attractor_strength);
- ObjectTypeDB::bind_method(_MD("particles_get_attractor_strength"),&VisualServer::particles_get_attractor_strength);
- ObjectTypeDB::bind_method(_MD("particles_set_material"),&VisualServer::particles_set_material,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("particles_set_height_from_velocity"),&VisualServer::particles_set_height_from_velocity);
- ObjectTypeDB::bind_method(_MD("particles_has_height_from_velocity"),&VisualServer::particles_has_height_from_velocity);
-
-
-
- ObjectTypeDB::bind_method(_MD("light_create"),&VisualServer::light_create);
- ObjectTypeDB::bind_method(_MD("light_get_type"),&VisualServer::light_get_type);
- ObjectTypeDB::bind_method(_MD("light_set_color"),&VisualServer::light_set_color);
- ObjectTypeDB::bind_method(_MD("light_get_color"),&VisualServer::light_get_color);
- ObjectTypeDB::bind_method(_MD("light_set_shadow"),&VisualServer::light_set_shadow);
- ObjectTypeDB::bind_method(_MD("light_has_shadow"),&VisualServer::light_has_shadow);
- ObjectTypeDB::bind_method(_MD("light_set_volumetric"),&VisualServer::light_set_volumetric);
- ObjectTypeDB::bind_method(_MD("light_is_volumetric"),&VisualServer::light_is_volumetric);
- ObjectTypeDB::bind_method(_MD("light_set_projector"),&VisualServer::light_set_projector);
- ObjectTypeDB::bind_method(_MD("light_get_projector"),&VisualServer::light_get_projector);
- ObjectTypeDB::bind_method(_MD("light_set_var"),&VisualServer::light_set_param);
- ObjectTypeDB::bind_method(_MD("light_get_var"),&VisualServer::light_get_param);
-
- ObjectTypeDB::bind_method(_MD("skeleton_create"),&VisualServer::skeleton_create);
- ObjectTypeDB::bind_method(_MD("skeleton_resize"),&VisualServer::skeleton_resize);
- ObjectTypeDB::bind_method(_MD("skeleton_get_bone_count"),&VisualServer::skeleton_get_bone_count);
- ObjectTypeDB::bind_method(_MD("skeleton_bone_set_transform"),&VisualServer::skeleton_bone_set_transform);
- ObjectTypeDB::bind_method(_MD("skeleton_bone_get_transform"),&VisualServer::skeleton_bone_get_transform);
-
-
-
- ObjectTypeDB::bind_method(_MD("room_create"),&VisualServer::room_create);
- ObjectTypeDB::bind_method(_MD("room_set_bounds"),&VisualServer::room_set_bounds);
- ObjectTypeDB::bind_method(_MD("room_get_bounds"),&VisualServer::room_get_bounds);
-
- ObjectTypeDB::bind_method(_MD("portal_create"),&VisualServer::portal_create);
- ObjectTypeDB::bind_method(_MD("portal_set_shape"),&VisualServer::portal_set_shape);
- ObjectTypeDB::bind_method(_MD("portal_get_shape"),&VisualServer::portal_get_shape);
- ObjectTypeDB::bind_method(_MD("portal_set_enabled"),&VisualServer::portal_set_enabled);
- ObjectTypeDB::bind_method(_MD("portal_is_enabled"),&VisualServer::portal_is_enabled);
- ObjectTypeDB::bind_method(_MD("portal_set_disable_distance"),&VisualServer::portal_set_disable_distance);
- ObjectTypeDB::bind_method(_MD("portal_get_disable_distance"),&VisualServer::portal_get_disable_distance);
- ObjectTypeDB::bind_method(_MD("portal_set_disabled_color"),&VisualServer::portal_set_disabled_color);
- ObjectTypeDB::bind_method(_MD("portal_get_disabled_color"),&VisualServer::portal_get_disabled_color);
-
-
- ObjectTypeDB::bind_method(_MD("camera_create"),&VisualServer::camera_create);
- ObjectTypeDB::bind_method(_MD("camera_set_perspective"),&VisualServer::camera_set_perspective);
- ObjectTypeDB::bind_method(_MD("camera_set_orthogonal"),&VisualServer::_camera_set_orthogonal);
- ObjectTypeDB::bind_method(_MD("camera_set_transform"),&VisualServer::camera_set_transform);
-
-
- ObjectTypeDB::bind_method(_MD("viewport_create"),&VisualServer::viewport_create);
- ObjectTypeDB::bind_method(_MD("viewport_set_rect"),&VisualServer::_viewport_set_rect);
- ObjectTypeDB::bind_method(_MD("viewport_get_rect"),&VisualServer::_viewport_get_rect);
- ObjectTypeDB::bind_method(_MD("viewport_attach_camera"),&VisualServer::viewport_attach_camera,DEFVAL(RID()));
- ObjectTypeDB::bind_method(_MD("viewport_get_attached_camera"),&VisualServer::viewport_get_attached_camera);
- ObjectTypeDB::bind_method(_MD("viewport_get_scenario"),&VisualServer::viewport_get_scenario);
- ObjectTypeDB::bind_method(_MD("viewport_attach_canvas"),&VisualServer::viewport_attach_canvas);
- ObjectTypeDB::bind_method(_MD("viewport_remove_canvas"),&VisualServer::viewport_remove_canvas);
- ObjectTypeDB::bind_method(_MD("viewport_set_global_canvas_transform"),&VisualServer::viewport_set_global_canvas_transform);
-
- ObjectTypeDB::bind_method(_MD("scenario_create"),&VisualServer::scenario_create);
- ObjectTypeDB::bind_method(_MD("scenario_set_debug"),&VisualServer::scenario_set_debug);
-
-
- ObjectTypeDB::bind_method(_MD("instance_create"),&VisualServer::instance_create,DEFVAL(RID()));
- ObjectTypeDB::bind_method(_MD("instance_get_base"),&VisualServer::instance_get_base);
- ObjectTypeDB::bind_method(_MD("instance_get_base_aabb"),&VisualServer::instance_get_base);
- ObjectTypeDB::bind_method(_MD("instance_set_transform"),&VisualServer::instance_set_transform);
- ObjectTypeDB::bind_method(_MD("instance_get_transform"),&VisualServer::instance_get_transform);
- ObjectTypeDB::bind_method(_MD("instance_attach_object_instance_ID"),&VisualServer::instance_attach_object_instance_ID);
- ObjectTypeDB::bind_method(_MD("instance_get_object_instance_ID"),&VisualServer::instance_get_object_instance_ID);
- ObjectTypeDB::bind_method(_MD("instance_attach_skeleton"),&VisualServer::instance_attach_skeleton);
- ObjectTypeDB::bind_method(_MD("instance_get_skeleton"),&VisualServer::instance_get_skeleton);
- ObjectTypeDB::bind_method(_MD("instance_set_room"),&VisualServer::instance_set_room);
- ObjectTypeDB::bind_method(_MD("instance_get_room"),&VisualServer::instance_get_room);
-
- ObjectTypeDB::bind_method(_MD("instance_set_exterior"),&VisualServer::instance_set_exterior);
- ObjectTypeDB::bind_method(_MD("instance_is_exterior"),&VisualServer::instance_is_exterior);
-
- ObjectTypeDB::bind_method(_MD("instances_cull_aabb"),&VisualServer::instances_cull_aabb);
- ObjectTypeDB::bind_method(_MD("instances_cull_ray"),&VisualServer::instances_cull_ray);
- ObjectTypeDB::bind_method(_MD("instances_cull_convex"),&VisualServer::instances_cull_convex);
-
-
-
- ObjectTypeDB::bind_method(_MD("instance_geometry_override_material_param"),&VisualServer::instance_get_room);
- ObjectTypeDB::bind_method(_MD("instance_geometry_get_material_param"),&VisualServer::instance_get_room);
-
- ObjectTypeDB::bind_method(_MD("get_test_cube"),&VisualServer::get_test_cube);
-#endif
- ObjectTypeDB::bind_method(_MD("canvas_create"),&VisualServer::canvas_create);
- ObjectTypeDB::bind_method(_MD("canvas_item_create"),&VisualServer::canvas_item_create);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_parent"),&VisualServer::canvas_item_set_parent);
- ObjectTypeDB::bind_method(_MD("canvas_item_get_parent"),&VisualServer::canvas_item_get_parent);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_transform"),&VisualServer::canvas_item_set_transform);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_custom_rect"),&VisualServer::canvas_item_set_custom_rect);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_clip"),&VisualServer::canvas_item_set_clip);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_opacity"),&VisualServer::canvas_item_set_opacity);
- ObjectTypeDB::bind_method(_MD("canvas_item_get_opacity"),&VisualServer::canvas_item_get_opacity);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_self_opacity"),&VisualServer::canvas_item_set_self_opacity);
- ObjectTypeDB::bind_method(_MD("canvas_item_get_self_opacity"),&VisualServer::canvas_item_get_self_opacity);
- ObjectTypeDB::bind_method(_MD("canvas_item_set_z"),&VisualServer::canvas_item_set_z);
-
- ObjectTypeDB::bind_method(_MD("canvas_item_add_line"),&VisualServer::canvas_item_add_line, DEFVAL(1.0), DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("canvas_item_add_rect"),&VisualServer::canvas_item_add_rect);
- ObjectTypeDB::bind_method(_MD("canvas_item_add_texture_rect"),&VisualServer::canvas_item_add_texture_rect, DEFVAL(Color(1,1,1)), DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("canvas_item_add_texture_rect_region"),&VisualServer::canvas_item_add_texture_rect_region, DEFVAL(Color(1,1,1)), DEFVAL(false));
-
- ObjectTypeDB::bind_method(_MD("canvas_item_add_style_box"),&VisualServer::_canvas_item_add_style_box, DEFVAL(Color(1,1,1)));
-// ObjectTypeDB::bind_method(_MD("canvas_item_add_primitive"),&VisualServer::canvas_item_add_primitive,DEFVAL(Vector<Vector2>()),DEFVAL(RID()));
- ObjectTypeDB::bind_method(_MD("canvas_item_add_circle"),&VisualServer::canvas_item_add_circle);
-
- ObjectTypeDB::bind_method(_MD("viewport_set_canvas_transform"),&VisualServer::viewport_set_canvas_transform);
-
- ObjectTypeDB::bind_method(_MD("canvas_item_clear"),&VisualServer::canvas_item_clear);
- ObjectTypeDB::bind_method(_MD("canvas_item_raise"),&VisualServer::canvas_item_raise);
-
-
- ObjectTypeDB::bind_method(_MD("cursor_set_rotation"),&VisualServer::cursor_set_rotation);
- ObjectTypeDB::bind_method(_MD("cursor_set_texture"),&VisualServer::cursor_set_texture);
- ObjectTypeDB::bind_method(_MD("cursor_set_visible"),&VisualServer::cursor_set_visible);
- ObjectTypeDB::bind_method(_MD("cursor_set_pos"),&VisualServer::cursor_set_pos);
-
- ObjectTypeDB::bind_method(_MD("black_bars_set_margins","left","top","right","bottom"),&VisualServer::black_bars_set_margins);
- ObjectTypeDB::bind_method(_MD("black_bars_set_images","left","top","right","bottom"),&VisualServer::black_bars_set_images);
-
- ObjectTypeDB::bind_method(_MD("make_sphere_mesh"),&VisualServer::make_sphere_mesh);
- ObjectTypeDB::bind_method(_MD("mesh_add_surface_from_planes"),&VisualServer::mesh_add_surface_from_planes);
-
- ObjectTypeDB::bind_method(_MD("draw"),&VisualServer::draw);
- ObjectTypeDB::bind_method(_MD("sync"),&VisualServer::sync);
- ObjectTypeDB::bind_method(_MD("free_rid"),&VisualServer::free);
-
- ObjectTypeDB::bind_method(_MD("set_default_clear_color"),&VisualServer::set_default_clear_color);
-
- ObjectTypeDB::bind_method(_MD("get_render_info"),&VisualServer::get_render_info);
-
- BIND_CONSTANT( NO_INDEX_ARRAY );
- BIND_CONSTANT( CUSTOM_ARRAY_SIZE );
- BIND_CONSTANT( ARRAY_WEIGHTS_SIZE );
- BIND_CONSTANT( MAX_PARTICLE_COLOR_PHASES );
- BIND_CONSTANT( MAX_PARTICLE_ATTRACTORS );
- BIND_CONSTANT( MAX_CURSORS );
-
- BIND_CONSTANT( TEXTURE_FLAG_MIPMAPS );
- BIND_CONSTANT( TEXTURE_FLAG_REPEAT );
- BIND_CONSTANT( TEXTURE_FLAG_FILTER );
- BIND_CONSTANT( TEXTURE_FLAG_CUBEMAP );
- BIND_CONSTANT( TEXTURE_FLAGS_DEFAULT );
-
- BIND_CONSTANT( CUBEMAP_LEFT );
- BIND_CONSTANT( CUBEMAP_RIGHT );
- BIND_CONSTANT( CUBEMAP_BOTTOM );
- BIND_CONSTANT( CUBEMAP_TOP );
- BIND_CONSTANT( CUBEMAP_FRONT );
- BIND_CONSTANT( CUBEMAP_BACK );
-
- BIND_CONSTANT( SHADER_MATERIAL ); ///< param 0: name
- BIND_CONSTANT( SHADER_POST_PROCESS ); ///< param 0: name
-
- BIND_CONSTANT( MATERIAL_FLAG_VISIBLE );
- BIND_CONSTANT( MATERIAL_FLAG_DOUBLE_SIDED );
- BIND_CONSTANT( MATERIAL_FLAG_INVERT_FACES );
- BIND_CONSTANT( MATERIAL_FLAG_UNSHADED );
- BIND_CONSTANT( MATERIAL_FLAG_ONTOP );
- BIND_CONSTANT( MATERIAL_FLAG_MAX );
-
- BIND_CONSTANT( MATERIAL_BLEND_MODE_MIX );
- BIND_CONSTANT( MATERIAL_BLEND_MODE_ADD );
- BIND_CONSTANT( MATERIAL_BLEND_MODE_SUB );
- BIND_CONSTANT( MATERIAL_BLEND_MODE_MUL );
-
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_DIFFUSE );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_DETAIL );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_SPECULAR );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_EMISSION );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_SPECULAR_EXP );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_GLOW );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_NORMAL );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_SHADE_PARAM );
- BIND_CONSTANT( FIXED_MATERIAL_PARAM_MAX );
-
-
-
- BIND_CONSTANT( FIXED_MATERIAL_TEXCOORD_SPHERE );
- BIND_CONSTANT( FIXED_MATERIAL_TEXCOORD_UV );
- BIND_CONSTANT( FIXED_MATERIAL_TEXCOORD_UV_TRANSFORM );
- BIND_CONSTANT( FIXED_MATERIAL_TEXCOORD_UV2 );
-
-
- BIND_CONSTANT( ARRAY_VERTEX );
- BIND_CONSTANT( ARRAY_NORMAL );
- BIND_CONSTANT( ARRAY_TANGENT );
- BIND_CONSTANT( ARRAY_COLOR );
- BIND_CONSTANT( ARRAY_TEX_UV );
- BIND_CONSTANT( ARRAY_BONES );
- BIND_CONSTANT( ARRAY_WEIGHTS );
- BIND_CONSTANT( ARRAY_INDEX );
- BIND_CONSTANT( ARRAY_MAX );
-
- BIND_CONSTANT( ARRAY_FORMAT_VERTEX );
- BIND_CONSTANT( ARRAY_FORMAT_NORMAL );
- BIND_CONSTANT( ARRAY_FORMAT_TANGENT );
- BIND_CONSTANT( ARRAY_FORMAT_COLOR );
- BIND_CONSTANT( ARRAY_FORMAT_TEX_UV );
- BIND_CONSTANT( ARRAY_FORMAT_BONES );
- BIND_CONSTANT( ARRAY_FORMAT_WEIGHTS );
- BIND_CONSTANT( ARRAY_FORMAT_INDEX );
-
- BIND_CONSTANT( PRIMITIVE_POINTS );
- BIND_CONSTANT( PRIMITIVE_LINES );
- BIND_CONSTANT( PRIMITIVE_LINE_STRIP );
- BIND_CONSTANT( PRIMITIVE_LINE_LOOP );
- BIND_CONSTANT( PRIMITIVE_TRIANGLES );
- BIND_CONSTANT( PRIMITIVE_TRIANGLE_STRIP );
- BIND_CONSTANT( PRIMITIVE_TRIANGLE_FAN );
- BIND_CONSTANT( PRIMITIVE_MAX );
-
- BIND_CONSTANT( PARTICLE_LIFETIME );
- BIND_CONSTANT( PARTICLE_SPREAD );
- BIND_CONSTANT( PARTICLE_GRAVITY );
- BIND_CONSTANT( PARTICLE_LINEAR_VELOCITY );
- BIND_CONSTANT( PARTICLE_ANGULAR_VELOCITY );
- BIND_CONSTANT( PARTICLE_LINEAR_ACCELERATION );
- BIND_CONSTANT( PARTICLE_RADIAL_ACCELERATION );
- BIND_CONSTANT( PARTICLE_TANGENTIAL_ACCELERATION );
- BIND_CONSTANT( PARTICLE_INITIAL_SIZE );
- BIND_CONSTANT( PARTICLE_FINAL_SIZE );
- BIND_CONSTANT( PARTICLE_INITIAL_ANGLE );
- BIND_CONSTANT( PARTICLE_HEIGHT );
- BIND_CONSTANT( PARTICLE_HEIGHT_SPEED_SCALE );
- BIND_CONSTANT( PARTICLE_VAR_MAX );
-
- BIND_CONSTANT( LIGHT_DIRECTIONAL );
- BIND_CONSTANT( LIGHT_OMNI );
- BIND_CONSTANT( LIGHT_SPOT );
-
-
- BIND_CONSTANT( LIGHT_COLOR_DIFFUSE );
- BIND_CONSTANT( LIGHT_COLOR_SPECULAR );
-
- BIND_CONSTANT( LIGHT_PARAM_SPOT_ATTENUATION );
- BIND_CONSTANT( LIGHT_PARAM_SPOT_ANGLE );
- BIND_CONSTANT( LIGHT_PARAM_RADIUS );
- BIND_CONSTANT( LIGHT_PARAM_ENERGY );
- BIND_CONSTANT( LIGHT_PARAM_ATTENUATION );
- BIND_CONSTANT( LIGHT_PARAM_MAX );
-
- BIND_CONSTANT( SCENARIO_DEBUG_DISABLED );
- BIND_CONSTANT( SCENARIO_DEBUG_WIREFRAME );
- BIND_CONSTANT( SCENARIO_DEBUG_OVERDRAW );
-
- BIND_CONSTANT( INSTANCE_MESH );
- BIND_CONSTANT( INSTANCE_MULTIMESH );
-
- BIND_CONSTANT( INSTANCE_PARTICLES );
- BIND_CONSTANT( INSTANCE_LIGHT );
- BIND_CONSTANT( INSTANCE_ROOM );
- BIND_CONSTANT( INSTANCE_PORTAL );
- BIND_CONSTANT( INSTANCE_GEOMETRY_MASK );
-
-
- BIND_CONSTANT( INFO_OBJECTS_IN_FRAME );
- BIND_CONSTANT( INFO_VERTICES_IN_FRAME );
- BIND_CONSTANT( INFO_MATERIAL_CHANGES_IN_FRAME );
- BIND_CONSTANT( INFO_SHADER_CHANGES_IN_FRAME );
- BIND_CONSTANT( INFO_SURFACE_CHANGES_IN_FRAME );
- BIND_CONSTANT( INFO_DRAW_CALLS_IN_FRAME );
- BIND_CONSTANT( INFO_USAGE_VIDEO_MEM_TOTAL );
- BIND_CONSTANT( INFO_VIDEO_MEM_USED );
- BIND_CONSTANT( INFO_TEXTURE_MEM_USED );
- BIND_CONSTANT( INFO_VERTEX_MEM_USED );
}
@@ -708,7 +373,7 @@ void VisualServer::_bind_methods() {
void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector<float>& p_margins, const Color& p_modulate) {
ERR_FAIL_COND(p_margins.size()!=4);
- canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate);
+ //canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate);
}
void VisualServer::_camera_set_orthogonal(RID p_camera,float p_size,float p_z_near,float p_z_far) {
@@ -716,21 +381,6 @@ void VisualServer::_camera_set_orthogonal(RID p_camera,float p_size,float p_z_ne
camera_set_orthogonal(p_camera,p_size,p_z_near,p_z_far);
}
-void VisualServer::_viewport_set_rect(RID p_viewport,const Rect2& p_rect) {
-
- ViewportRect r;
- r.x=p_rect.pos.x;
- r.y=p_rect.pos.y;
- r.width=p_rect.size.x;
- r.height=p_rect.size.y;
- viewport_set_rect(p_viewport,r);
-}
-Rect2 VisualServer::_viewport_get_rect(RID p_viewport) const {
-
- ViewportRect r=viewport_get_rect(p_viewport);
- return Rect2(r.x,r.y,r.width,r.height);
-}
-
@@ -761,7 +411,7 @@ void VisualServer::mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry::
d.resize(VS::ARRAY_MAX);
d[ARRAY_VERTEX]=vertices;
d[ARRAY_NORMAL]=normals;
- mesh_add_surface(p_mesh,PRIMITIVE_TRIANGLES, d);
+ mesh_add_surface_from_arrays(p_mesh,PRIMITIVE_TRIANGLES, d);
#else
@@ -810,9 +460,6 @@ VisualServer::VisualServer() {
// ERR_FAIL_COND(singleton);
singleton=this;
- mm_policy=GLOBAL_DEF("render/mipmap_policy",0);
- if (mm_policy<0 || mm_policy>2)
- mm_policy=0;
}
diff --git a/servers/visual_server.h b/servers/visual_server.h
index 2f3d8371f6..918b0b102e 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -50,8 +50,6 @@ class VisualServer : public Object {
DVector<String> _shader_get_param_list(RID p_shader) const;
void _camera_set_orthogonal(RID p_camera,float p_size,float p_z_near,float p_z_far);
- void _viewport_set_rect(RID p_viewport,const Rect2& p_rect);
- Rect2 _viewport_get_rect(RID p_viewport) const;
void _canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector<float>& p_margins, const Color& p_modulate=Color(1,1,1));
protected:
RID _make_test_cube();
@@ -68,26 +66,12 @@ public:
static VisualServer *get_singleton();
static VisualServer *create();
- enum MipMapPolicy {
-
- MIPMAPS_ENABLED,
- MIPMAPS_ENABLED_FOR_PO2,
- MIPMAPS_DISABLED
- };
-
-
- virtual void set_mipmap_policy(MipMapPolicy p_policy);
- virtual MipMapPolicy get_mipmap_policy() const;
-
enum {
NO_INDEX_ARRAY=-1,
- CUSTOM_ARRAY_SIZE=8,
ARRAY_WEIGHTS_SIZE=4,
- MAX_PARTICLE_COLOR_PHASES=4,
- MAX_PARTICLE_ATTRACTORS=4,
CANVAS_ITEM_Z_MIN=-4096,
CANVAS_ITEM_Z_MAX=4096,
@@ -106,7 +90,7 @@ public:
TEXTURE_FLAG_CONVERT_TO_LINEAR=16,
TEXTURE_FLAG_MIRRORED_REPEAT=32, /// Repeat texture, with alternate sections mirrored
TEXTURE_FLAG_CUBEMAP=2048,
- TEXTURE_FLAG_VIDEO_SURFACE=4096,
+ TEXTURE_FLAG_USED_FOR_STREAMING=4096,
TEXTURE_FLAGS_DEFAULT=TEXTURE_FLAG_REPEAT|TEXTURE_FLAG_MIPMAPS|TEXTURE_FLAG_FILTER
};
@@ -132,8 +116,6 @@ public:
virtual uint32_t texture_get_width(RID p_texture) const=0;
virtual uint32_t texture_get_height(RID p_texture) const=0;
virtual void texture_set_size_override(RID p_texture,int p_width, int p_height)=0;
- virtual bool texture_can_stream(RID p_texture) const=0;
- virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const=0;
virtual void texture_set_path(RID p_texture,const String& p_path)=0;
virtual String texture_get_path(RID p_texture) const=0;
@@ -155,21 +137,19 @@ public:
enum ShaderMode {
- SHADER_MATERIAL,
+ SHADER_SPATIAL,
SHADER_CANVAS_ITEM,
- SHADER_POST_PROCESS,
+ SHADER_LIGHT,
};
- virtual RID shader_create(ShaderMode p_mode=SHADER_MATERIAL)=0;
+ virtual RID shader_create(ShaderMode p_mode=SHADER_SPATIAL)=0;
virtual void shader_set_mode(RID p_shader,ShaderMode p_mode)=0;
virtual ShaderMode shader_get_mode(RID p_shader) const=0;
- 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)=0;
- virtual String shader_get_fragment_code(RID p_shader) const=0;
- virtual String shader_get_vertex_code(RID p_shader) const=0;
- virtual String shader_get_light_code(RID p_shader) const=0;
+ virtual void shader_set_code(RID p_shader, const String& p_code)=0;
+ virtual String shader_get_code(RID p_shader) const=0;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const=0;
virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0;
@@ -186,114 +166,6 @@ public:
virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value)=0;
virtual Variant material_get_param(RID p_material, const StringName& p_param) const=0;
- enum MaterialFlag {
- MATERIAL_FLAG_VISIBLE,
- MATERIAL_FLAG_DOUBLE_SIDED,
- MATERIAL_FLAG_INVERT_FACES, ///< Invert front/back of the object
- MATERIAL_FLAG_UNSHADED,
- MATERIAL_FLAG_ONTOP,
- MATERIAL_FLAG_LIGHTMAP_ON_UV2,
- MATERIAL_FLAG_COLOR_ARRAY_SRGB,
- MATERIAL_FLAG_MAX,
- };
-
- virtual void material_set_flag(RID p_material, MaterialFlag p_flag,bool p_enabled)=0;
- virtual bool material_get_flag(RID p_material,MaterialFlag p_flag) const=0;
-
- enum MaterialDepthDrawMode {
- MATERIAL_DEPTH_DRAW_ALWAYS,
- MATERIAL_DEPTH_DRAW_OPAQUE_ONLY,
- MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA,
- MATERIAL_DEPTH_DRAW_NEVER
- };
-
- virtual void material_set_depth_draw_mode(RID p_material, MaterialDepthDrawMode p_mode)=0;
- virtual MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const=0;
-
- enum MaterialBlendMode {
- MATERIAL_BLEND_MODE_MIX, //default
- MATERIAL_BLEND_MODE_ADD,
- MATERIAL_BLEND_MODE_SUB,
- MATERIAL_BLEND_MODE_MUL,
- MATERIAL_BLEND_MODE_PREMULT_ALPHA
- };
-
-
- virtual void material_set_blend_mode(RID p_material,MaterialBlendMode p_mode)=0;
- virtual MaterialBlendMode material_get_blend_mode(RID p_material) const=0;
-
- virtual void material_set_line_width(RID p_material,float p_line_width)=0;
- virtual float material_get_line_width(RID p_material) const=0;
-
-
- //fixed material api
-
- virtual RID fixed_material_create()=0;
-
- enum FixedMaterialParam {
-
- FIXED_MATERIAL_PARAM_DIFFUSE,
- FIXED_MATERIAL_PARAM_DETAIL,
- FIXED_MATERIAL_PARAM_SPECULAR,
- FIXED_MATERIAL_PARAM_EMISSION,
- FIXED_MATERIAL_PARAM_SPECULAR_EXP,
- FIXED_MATERIAL_PARAM_GLOW,
- FIXED_MATERIAL_PARAM_NORMAL,
- FIXED_MATERIAL_PARAM_SHADE_PARAM,
- FIXED_MATERIAL_PARAM_MAX
- };
-
- enum FixedMaterialTexCoordMode {
-
- FIXED_MATERIAL_TEXCOORD_UV,
- FIXED_MATERIAL_TEXCOORD_UV_TRANSFORM,
- FIXED_MATERIAL_TEXCOORD_UV2,
- FIXED_MATERIAL_TEXCOORD_SPHERE
- };
-
- enum FixedMaterialFlags {
-
- FIXED_MATERIAL_FLAG_USE_ALPHA,
- FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,
- FIXED_MATERIAL_FLAG_USE_POINT_SIZE,
- FIXED_MATERIAL_FLAG_DISCARD_ALPHA,
- FIXED_MATERIAL_FLAG_USE_XY_NORMALMAP,
- FIXED_MATERIAL_FLAG_MAX,
- };
-
-
- virtual void fixed_material_set_flag(RID p_material, FixedMaterialFlags p_flag, bool p_enabled)=0;
- virtual bool fixed_material_get_flag(RID p_material, FixedMaterialFlags p_flag) const=0;
-
- virtual void fixed_material_set_param(RID p_material, FixedMaterialParam p_parameter, const Variant& p_value)=0;
- virtual Variant fixed_material_get_param(RID p_material,FixedMaterialParam p_parameter) const=0;
-
- virtual void fixed_material_set_texture(RID p_material,FixedMaterialParam p_parameter, RID p_texture)=0;
- virtual RID fixed_material_get_texture(RID p_material,FixedMaterialParam p_parameter) const=0;
-
-
- enum FixedMaterialLightShader {
-
- FIXED_MATERIAL_LIGHT_SHADER_LAMBERT,
- FIXED_MATERIAL_LIGHT_SHADER_WRAP,
- FIXED_MATERIAL_LIGHT_SHADER_VELVET,
- FIXED_MATERIAL_LIGHT_SHADER_TOON,
-
- };
-
-
- virtual void fixed_material_set_light_shader(RID p_material,FixedMaterialLightShader p_shader)=0;
- virtual FixedMaterialLightShader fixed_material_get_light_shader(RID p_material) const=0;
-
- virtual void fixed_material_set_texcoord_mode(RID p_material,FixedMaterialParam p_parameter, FixedMaterialTexCoordMode p_mode)=0;
- virtual FixedMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material,FixedMaterialParam p_parameter) const=0;
-
- virtual void fixed_material_set_uv_transform(RID p_material,const Transform& p_transform)=0;
- virtual Transform fixed_material_get_uv_transform(RID p_material) const=0;
-
- virtual void fixed_material_set_point_size(RID p_material,float p_size)=0;
- virtual float fixed_material_get_point_size(RID p_material) const=0;
-
/* MESH API */
enum ArrayType {
@@ -321,8 +193,25 @@ public:
ARRAY_FORMAT_BONES=1<<ARRAY_BONES,
ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS,
ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX,
+
+ ARRAY_COMPRESS_BASE=(ARRAY_INDEX+1),
+ ARRAY_COMPRESS_VERTEX=1<<(ARRAY_VERTEX+ARRAY_COMPRESS_BASE), // mandatory
+ ARRAY_COMPRESS_NORMAL=1<<(ARRAY_NORMAL+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_TANGENT=1<<(ARRAY_TANGENT+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_COLOR=1<<(ARRAY_COLOR+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_TEX_UV=1<<(ARRAY_TEX_UV+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_TEX_UV2=1<<(ARRAY_TEX_UV2+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_BONES=1<<(ARRAY_BONES+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_WEIGHTS=1<<(ARRAY_WEIGHTS+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_INDEX=1<<(ARRAY_INDEX+ARRAY_COMPRESS_BASE),
+
+ ARRAY_FLAG_USE_2D_VERTICES=ARRAY_COMPRESS_INDEX<<1,
+
+ ARRAY_COMPRESS_DEFAULT=ARRAY_COMPRESS_VERTEX|ARRAY_COMPRESS_NORMAL|ARRAY_COMPRESS_TANGENT|ARRAY_COMPRESS_COLOR|ARRAY_COMPRESS_TEX_UV|ARRAY_COMPRESS_TEX_UV2|ARRAY_COMPRESS_BONES|ARRAY_COMPRESS_WEIGHTS|ARRAY_COMPRESS_INDEX
+
};
+
enum PrimitiveType {
PRIMITIVE_POINTS=0,
PRIMITIVE_LINES=1,
@@ -336,12 +225,10 @@ public:
virtual RID mesh_create()=0;
- virtual void mesh_add_surface(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false)=0;
- virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const=0;
- virtual Array mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const=0;
+ virtual void mesh_add_surface_from_arrays(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),uint32_t p_compress_format=ARRAY_COMPRESS_DEFAULT);
+ virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >())=0;
- virtual void mesh_add_custom_surface(RID p_mesh,const Variant& p_dat)=0; //this is used by each platform in a different way
virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount)=0;
virtual int mesh_get_morph_target_count(RID p_mesh) const=0;
@@ -353,11 +240,16 @@ public:
virtual void mesh_set_morph_target_mode(RID p_mesh,MorphTargetMode p_mode)=0;
virtual MorphTargetMode mesh_get_morph_target_mode(RID p_mesh) const=0;
- virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned=false)=0;
+ virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material)=0;
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const=0;
virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const=0;
virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const=0;
+
+ virtual DVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const=0;
+ virtual DVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const=0;
+
+
virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const=0;
virtual PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const=0;
@@ -371,30 +263,47 @@ public:
/* MULTIMESH API */
+
virtual RID multimesh_create()=0;
- virtual void multimesh_set_instance_count(RID p_multimesh,int p_count)=0;
+ enum MultimeshTransformFormat {
+ MULTIMESH_TRANSFORM_NONE,
+ MULTIMESH_TRANSFORM_2D,
+ MULTIMESH_TRANSFORM_3D,
+ };
+
+ enum MultimeshColorFormat {
+ MULTIMESH_COLOR_NONE,
+ MULTIMESH_COLOR_8BIT,
+ MULTIMESH_COLOR_FLOAT,
+ };
+
+ virtual void multimesh_allocate(RID p_multimesh,int p_instances,MultimeshTransformFormat p_transform_format,MultimeshColorFormat p_color_format,bool p_gen_aabb=true)=0;
virtual int multimesh_get_instance_count(RID p_multimesh) const=0;
virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh)=0;
- virtual void multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb)=0;
+ virtual void multimesh_set_custom_aabb(RID p_multimesh,const AABB& p_aabb)=0;
virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform)=0;
+ virtual void multimesh_instance_set_transform_2d(RID p_multimesh,int p_index,const Matrix32& p_transform)=0;
virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color)=0;
virtual RID multimesh_get_mesh(RID p_multimesh) const=0;
- virtual AABB multimesh_get_aabb(RID p_multimesh,const AABB& p_aabb) const=0;;
+ virtual AABB multimesh_get_custom_aabb(RID p_multimesh,const AABB& p_aabb) const=0;
virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const=0;
+ virtual Matrix32 multimesh_instance_get_transform_2d(RID p_multimesh,int p_index) const=0;
virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const=0;
virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible)=0;
virtual int multimesh_get_visible_instances(RID p_multimesh) const=0;
+
/* IMMEDIATE API */
virtual RID immediate_create()=0;
virtual void immediate_begin(RID p_immediate,PrimitiveType p_rimitive,RID p_texture=RID())=0;
virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex)=0;
+ virtual void immediate_vertex_2d(RID p_immediate,const Vector3& p_vertex)=0;
virtual void immediate_normal(RID p_immediate,const Vector3& p_normal)=0;
virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent)=0;
virtual void immediate_color(RID p_immediate,const Color& p_color)=0;
@@ -405,82 +314,15 @@ public:
virtual void immediate_set_material(RID p_immediate,RID p_material)=0;
virtual RID immediate_get_material(RID p_immediate) const=0;
+ /* SKELETON API */
- /* PARTICLES API */
-
- virtual RID particles_create()=0;
-
- enum ParticleVariable {
- PARTICLE_LIFETIME,
- PARTICLE_SPREAD,
- PARTICLE_GRAVITY,
- PARTICLE_LINEAR_VELOCITY,
- PARTICLE_ANGULAR_VELOCITY,
- PARTICLE_LINEAR_ACCELERATION,
- PARTICLE_RADIAL_ACCELERATION,
- PARTICLE_TANGENTIAL_ACCELERATION,
- PARTICLE_DAMPING,
- PARTICLE_INITIAL_SIZE,
- PARTICLE_FINAL_SIZE,
- PARTICLE_INITIAL_ANGLE,
- PARTICLE_HEIGHT,
- PARTICLE_HEIGHT_SPEED_SCALE,
- PARTICLE_VAR_MAX
- };
-
- virtual void particles_set_amount(RID p_particles, int p_amount)=0;
- virtual int particles_get_amount(RID p_particles) const=0;
-
- virtual void particles_set_emitting(RID p_particles, bool p_emitting)=0;
- virtual bool particles_is_emitting(RID p_particles) const=0;
-
- virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility)=0;
- virtual AABB particles_get_visibility_aabb(RID p_particles) const=0;
-
- virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents)=0;
- virtual Vector3 particles_get_emission_half_extents(RID p_particles) const=0;
-
- virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity)=0;
- virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const=0;
-
- virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points)=0;
- virtual DVector<Vector3> particles_get_emission_points(RID p_particles) const=0;
-
- virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal)=0;
- virtual Vector3 particles_get_gravity_normal(RID p_particles) const=0;
-
- virtual void particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value)=0;
- virtual float particles_get_variable(RID p_particles, ParticleVariable p_variable) const=0;
-
- virtual void particles_set_randomness(RID p_particles, ParticleVariable p_variable,float p_randomness)=0;
- virtual float particles_get_randomness(RID p_particles, ParticleVariable p_variable) const=0;
-
- virtual void particles_set_color_phases(RID p_particles, int p_phases)=0;
- virtual int particles_get_color_phases(RID p_particles) const=0;
-
- virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos)=0;
- virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const=0;
-
- virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color)=0;
- virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const=0;
-
- virtual void particles_set_attractors(RID p_particles, int p_attractors)=0;
- virtual int particles_get_attractors(RID p_particles) const=0;
-
- virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos)=0;
- virtual Vector3 particles_get_attractor_pos(RID p_particles,int p_attractor) const=0;
-
- virtual void particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force)=0;
- virtual float particles_get_attractor_strength(RID p_particles,int p_attractor) const=0;
-
- virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false)=0;
- virtual RID particles_get_material(RID p_particles) const=0;
-
- virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable)=0;
- virtual bool particles_has_height_from_velocity(RID p_particles) const=0;
-
- virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable)=0;
- virtual bool particles_is_using_local_coordinates(RID p_particles) const=0;
+ virtual RID skeleton_create()=0;
+ virtual void skeleton_allocate(RID p_skeleton,int p_bones,bool p_2d_skeleton=false)=0;
+ virtual int skeleton_get_bone_count(RID p_skeleton) const=0;
+ virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0;
+ virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0;
+ virtual void skeleton_bone_set_transform_2d(RID p_skeleton,int p_bone, const Matrix32& p_transform)=0;
+ virtual Matrix32 skeleton_bone_get_transform_2d(RID p_skeleton,int p_bone)=0;
/* Light API */
@@ -490,62 +332,36 @@ public:
LIGHT_SPOT
};
- enum LightColor {
- LIGHT_COLOR_DIFFUSE,
- LIGHT_COLOR_SPECULAR
- };
-
enum LightParam {
- LIGHT_PARAM_SPOT_ATTENUATION,
- LIGHT_PARAM_SPOT_ANGLE,
- LIGHT_PARAM_RADIUS,
LIGHT_PARAM_ENERGY,
- LIGHT_PARAM_ATTENUATION,
- LIGHT_PARAM_SHADOW_DARKENING,
- LIGHT_PARAM_SHADOW_Z_OFFSET,
- LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE,
- LIGHT_PARAM_SHADOW_ESM_MULTIPLIER,
- LIGHT_PARAM_SHADOW_BLUR_PASSES,
+ LIGHT_PARAM_SPECULAR,
+ LIGHT_PARAM_RANGE,
+ LIGHT_PARAM_SPOT_ANGLE,
+ LIGHT_PARAM_SHADOW_MAX_DISTANCE,
+ LIGHT_PARAM_SHADOW_DARKNESS,
+ LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET,
+ LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET,
+ LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET,
+ LIGHT_PARAM_SHADOW_SPLIT_4_OFFSET,
+ LIGHT_PARAM_SHADOW_NORMAL_BIAS,
+ LIGHT_PARAM_SHADOW_BIAS_1,
+ LIGHT_PARAM_SHADOW_BIAS_2,
+ LIGHT_PARAM_SHADOW_BIAS_3,
+ LIGHT_PARAM_SHADOW_BIAS_4,
LIGHT_PARAM_MAX
};
virtual RID light_create(LightType p_type)=0;
- virtual LightType light_get_type(RID p_light) const=0;
-
- virtual void light_set_color(RID p_light,LightColor p_type, const Color& p_color)=0;
- virtual Color light_get_color(RID p_light,LightColor p_type) const=0;
+ virtual void light_set_color(RID p_light,const Color& p_color)=0;
+ virtual void light_set_param(RID p_light,LightParam p_param,float p_value)=0;
virtual void light_set_shadow(RID p_light,bool p_enabled)=0;
- virtual bool light_has_shadow(RID p_light) const=0;
-
- virtual void light_set_volumetric(RID p_light,bool p_enabled)=0;
- virtual bool light_is_volumetric(RID p_light) const=0;
-
virtual void light_set_projector(RID p_light,RID p_texture)=0;
- virtual RID light_get_projector(RID p_light) const=0;
-
- virtual void light_set_param(RID p_light, LightParam p_var, float p_value)=0;
- virtual float light_get_param(RID p_light, LightParam p_var) const=0;
-
- enum LightOp {
-
- LIGHT_OPERATOR_ADD,
- LIGHT_OPERATOR_SUB
- };
-
- virtual void light_set_operator(RID p_light,LightOp p_op)=0;
- virtual LightOp light_get_operator(RID p_light) const=0;
-
- // omni light
- enum LightOmniShadowMode {
- LIGHT_OMNI_SHADOW_DEFAULT,
- LIGHT_OMNI_SHADOW_DUAL_PARABOLOID,
- LIGHT_OMNI_SHADOW_CUBEMAP
- };
-
- virtual void light_omni_set_shadow_mode(RID p_light,LightOmniShadowMode p_mode)=0;
- virtual LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) const=0;
+ virtual void light_set_attenuation_texure(RID p_light,RID p_texture)=0;
+ virtual void light_set_negative(RID p_light,bool p_enable)=0;
+ virtual void light_set_cull_mask(RID p_light,uint32_t p_mask)=0;
+ virtual void light_set_shader(RID p_light,RID p_shader)=0;
// directional light
enum LightDirectionalShadowMode {
@@ -556,33 +372,27 @@ public:
};
virtual void light_directional_set_shadow_mode(RID p_light,LightDirectionalShadowMode p_mode)=0;
- virtual LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) const=0;
-
- enum LightDirectionalShadowParam {
-
- LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE,
- LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_SPLIT_WEIGHT,
- LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_ZOFFSET_SCALE,
- };
- virtual void light_directional_set_shadow_param(RID p_light,LightDirectionalShadowParam p_param, float p_value)=0;
- virtual float light_directional_get_shadow_param(RID p_light,LightDirectionalShadowParam p_param) const=0;
+ /* PROBE API */
- //@TODO fallof model and all that stuff
+ virtual RID reflection_probe_create()=0;
- /* SKELETON API */
+ virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity)=0;
+ virtual void reflection_probe_set_clip(RID p_probe, float p_near, float p_far)=0;
+ virtual void reflection_probe_set_min_blend_distance(RID p_probe, float p_distance)=0;
+ virtual void reflection_probe_set_extents(RID p_probe, const Vector3& p_extents)=0;
+ virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3& p_offset)=0;
+ virtual void reflection_probe_set_enable_parallax_correction(RID p_probe, bool p_enable)=0;
+ virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution)=0;
+ virtual void reflection_probe_set_hide_skybox(RID p_probe, bool p_hide)=0;
+ virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers)=0;
- virtual RID skeleton_create()=0;
- virtual void skeleton_resize(RID p_skeleton,int p_bones)=0;
- virtual int skeleton_get_bone_count(RID p_skeleton) const=0;
- virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0;
- virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0;
/* ROOM API */
virtual RID room_create()=0;
- virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds)=0;
- virtual BSP_Tree room_get_bounds(RID p_room) const=0;
+ virtual void room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform)=0;
+ virtual void room_clear_bounds()=0;
/* PORTAL API */
@@ -591,144 +401,55 @@ public:
virtual RID portal_create()=0;
virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape)=0;
- virtual Vector<Point2> portal_get_shape(RID p_portal) const=0;
virtual void portal_set_enabled(RID p_portal, bool p_enabled)=0;
- virtual bool portal_is_enabled(RID p_portal) const=0;
virtual void portal_set_disable_distance(RID p_portal, float p_distance)=0;
- virtual float portal_get_disable_distance(RID p_portal) const=0;
virtual void portal_set_disabled_color(RID p_portal, const Color& p_color)=0;
- virtual Color portal_get_disabled_color(RID p_portal) const=0;
- virtual void portal_set_connect_range(RID p_portal, float p_range) =0;
- virtual float portal_get_connect_range(RID p_portal) const =0;
-
/* BAKED LIGHT API */
- virtual RID baked_light_create()=0;
- enum BakedLightMode {
- BAKED_LIGHT_OCTREE,
- BAKED_LIGHT_LIGHTMAPS
- };
-
- virtual void baked_light_set_mode(RID p_baked_light,BakedLightMode p_mode)=0;
- virtual BakedLightMode baked_light_get_mode(RID p_baked_light) const=0;
-
- virtual void baked_light_set_octree(RID p_baked_light,const DVector<uint8_t> p_octree)=0;
- virtual DVector<uint8_t> baked_light_get_octree(RID p_baked_light) const=0;
-
- virtual void baked_light_set_light(RID p_baked_light,const DVector<uint8_t> p_light)=0;
- virtual DVector<uint8_t> baked_light_get_light(RID p_baked_light) const=0;
-
- virtual void baked_light_set_sampler_octree(RID p_baked_light,const DVector<int> &p_sampler)=0;
- virtual DVector<int> baked_light_get_sampler_octree(RID p_baked_light) const=0;
-
- virtual void baked_light_set_lightmap_multiplier(RID p_baked_light,float p_multiplier)=0;
- virtual float baked_light_get_lightmap_multiplier(RID p_baked_light) const=0;
-
- virtual void baked_light_add_lightmap(RID p_baked_light,const RID p_texture,int p_id)=0;
- virtual void baked_light_clear_lightmaps(RID p_baked_light)=0;
-
- virtual void baked_light_set_realtime_color_enabled(RID p_baked_light, const bool p_enabled)=0;
- virtual bool baked_light_get_realtime_color_enabled(RID p_baked_light) const=0;
-
- virtual void baked_light_set_realtime_color(RID p_baked_light, const Color& p_color)=0;
- virtual Color baked_light_get_realtime_color(RID p_baked_light) const=0;
-
- virtual void baked_light_set_realtime_energy(RID p_baked_light, const float p_energy) = 0;
- virtual float baked_light_get_realtime_energy(RID p_baked_light) const = 0;
-
- /* BAKED LIGHT SAMPLER */
-
- virtual RID baked_light_sampler_create()=0;
-
- enum BakedLightSamplerParam {
- BAKED_LIGHT_SAMPLER_RADIUS,
- BAKED_LIGHT_SAMPLER_STRENGTH,
- BAKED_LIGHT_SAMPLER_ATTENUATION,
- BAKED_LIGHT_SAMPLER_DETAIL_RATIO,
- BAKED_LIGHT_SAMPLER_MAX
- };
-
- virtual void baked_light_sampler_set_param(RID p_baked_light_sampler,BakedLightSamplerParam p_param,float p_value)=0;
- virtual float baked_light_sampler_get_param(RID p_baked_light_sampler,BakedLightSamplerParam p_param) const=0;
-
- virtual void baked_light_sampler_set_resolution(RID p_baked_light_sampler,int p_resolution)=0;
- virtual int baked_light_sampler_get_resolution(RID p_baked_light_sampler) const=0;
-
/* CAMERA API */
virtual RID camera_create()=0;
virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far)=0;
virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far)=0;
virtual void camera_set_transform(RID p_camera,const Transform& p_transform)=0;
-
- virtual void camera_set_visible_layers(RID p_camera,uint32_t p_layers)=0;
- virtual uint32_t camera_get_visible_layers(RID p_camera) const=0;
-
+ virtual void camera_set_cull_mask(RID p_camera,uint32_t p_layers)=0;
virtual void camera_set_environment(RID p_camera,RID p_env)=0;
- virtual RID camera_get_environment(RID p_camera) const=0;
-
virtual void camera_set_use_vertical_aspect(RID p_camera,bool p_enable)=0;
- virtual bool camera_is_using_vertical_aspect(RID p_camera,bool p_enable) const=0;
-/*
- virtual void camera_add_layer(RID p_camera);
- virtual void camera_layer_move_up(RID p_camera,int p_layer);
- virtual void camera_layer_move_down(RID p_camera,int p_layer);
- virtual void camera_layer_set_mask(RID p_camera,int p_layer,int p_mask);
- virtual int camera_layer_get_mask(RID p_camera,int p_layer) const;
- enum CameraLayerFlag {
-
- FLAG_CLEAR_DEPTH,
- FLAG_CLEAR_COLOR,
- FLAG_IGNORE_FOG,
- };
- virtual void camera_layer_set_flag(RID p_camera,int p_layer,bool p_enable);
- virtual bool camera_layer_get_flag(RID p_camera,int p_layer) const;
-
-*/
-
-
- /* VIEWPORT API */
+ /* VIEWPORT TARGET API */
virtual RID viewport_create()=0;
- virtual void viewport_attach_to_screen(RID p_viewport,int p_screen=0)=0;
+ virtual void viewport_set_size(RID p_viewport,int p_width,int p_height)=0;
+ virtual void viewport_set_active(RID p_viewport,bool p_active)=0;
+
+ virtual void viewport_attach_to_screen(RID p_viewport,const Rect2& p_rect=Rect2(),int p_screen=0)=0;
virtual void viewport_detach(RID p_viewport)=0;
- virtual void viewport_set_render_target_to_screen_rect(RID p_viewport,const Rect2& p_rect)=0;
- enum RenderTargetUpdateMode {
- RENDER_TARGET_UPDATE_DISABLED,
- RENDER_TARGET_UPDATE_ONCE, //then goes to disabled
- RENDER_TARGET_UPDATE_WHEN_VISIBLE, // default
- RENDER_TARGET_UPDATE_ALWAYS
+ enum ViewportUpdateMode {
+ VIEWPORT_UPDATE_DISABLED,
+ VIEWPORT_UPDATE_ONCE, //then goes to disabled, must be manually updated
+ VIEWPORT_UPDATE_WHEN_VISIBLE, // default
+ VIEWPORT_UPDATE_ALWAYS
};
- virtual void viewport_set_as_render_target(RID p_viewport,bool p_enable)=0;
- virtual void viewport_set_render_target_update_mode(RID p_viewport,RenderTargetUpdateMode p_mode)=0;
- virtual RenderTargetUpdateMode viewport_get_render_target_update_mode(RID p_viewport) const=0;
- virtual RID viewport_get_render_target_texture(RID p_viewport) const=0;
- virtual void viewport_set_render_target_vflip(RID p_viewport,bool p_enable)=0;
- virtual bool viewport_get_render_target_vflip(RID p_viewport) const=0;
- virtual void viewport_set_render_target_clear_on_new_frame(RID p_viewport,bool p_enable)=0;
- virtual bool viewport_get_render_target_clear_on_new_frame(RID p_viewport) const=0;
- virtual void viewport_render_target_clear(RID p_viewport)=0;
-
- virtual void viewport_queue_screen_capture(RID p_viewport)=0;
- virtual Image viewport_get_screen_capture(RID p_viewport) const=0;
-
+ virtual void viewport_set_update_mode(RID p_viewport,ViewportUpdateMode p_mode)=0;
+ virtual void viewport_set_vflip(RID p_viewport,bool p_enable)=0;
+ enum ViewportClearMode {
- struct ViewportRect {
-
- int x,y,width,height;
- ViewportRect() { x=y=width=height=0; }
+ VIEWPORT_CLEAR_ALWAYS,
+ VIWEPORT_CLEAR_NEVER,
+ VIEWPORT_CLEAR_ONLY_NEXT_FRAME
};
- virtual void viewport_set_rect(RID p_viewport,const ViewportRect& p_rect)=0;
- virtual ViewportRect viewport_get_rect(RID p_viewport) const=0;
+ virtual void viewport_set_clear_mode(RID p_viewport,ViewportClearMode p_clear_mode)=0;
+
+ virtual RID viewport_get_texture(RID p_viewport) const=0;
+ virtual Image viewport_capture(RID p_viewport) const=0;
virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide)=0;
virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide)=0;
@@ -736,22 +457,15 @@ public:
virtual void viewport_attach_camera(RID p_viewport,RID p_camera)=0;
virtual void viewport_set_scenario(RID p_viewport,RID p_scenario)=0;
- virtual RID viewport_get_attached_camera(RID p_viewport) const=0;
- virtual RID viewport_get_scenario(RID p_viewport) const=0;
virtual void viewport_attach_canvas(RID p_viewport,RID p_canvas)=0;
virtual void viewport_remove_canvas(RID p_viewport,RID p_canvas)=0;
virtual void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset)=0;
- virtual Matrix32 viewport_get_canvas_transform(RID p_viewport,RID p_canvas) const=0;
virtual void viewport_set_transparent_background(RID p_viewport,bool p_enabled)=0;
- virtual bool viewport_has_transparent_background(RID p_viewport) const=0;
-
virtual void viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform)=0;
- virtual Matrix32 viewport_get_global_canvas_transform(RID p_viewport) const=0;
virtual void viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer)=0;
-
/* ENVIRONMENT API */
virtual RID environment_create()=0;
@@ -759,103 +473,48 @@ public:
enum EnvironmentBG {
ENV_BG_KEEP,
- ENV_BG_DEFAULT_COLOR,
ENV_BG_COLOR,
- ENV_BG_TEXTURE,
- ENV_BG_CUBEMAP,
+ ENV_BG_SKYBOX,
ENV_BG_CANVAS,
ENV_BG_MAX
};
virtual void environment_set_background(RID p_env,EnvironmentBG p_bg)=0;
- virtual EnvironmentBG environment_get_background(RID p_env) const=0;
-
- enum EnvironmentBGParam {
-
- ENV_BG_PARAM_CANVAS_MAX_LAYER,
- ENV_BG_PARAM_COLOR,
- ENV_BG_PARAM_TEXTURE,
- ENV_BG_PARAM_CUBEMAP,
- ENV_BG_PARAM_ENERGY,
- ENV_BG_PARAM_SCALE,
- ENV_BG_PARAM_GLOW,
- ENV_BG_PARAM_MAX
- };
+ virtual void environment_set_skybox(RID p_env,RID p_skybox,float p_energy=1.0)=0;
+ virtual void environment_set_bg_color(RID p_env,const Color& p_color)=0;
+ virtual void environment_set_canvas_max_layer(RID p_env,int p_max_layer)=0;
+ virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0)=0;
+ //set default SSAO options
+ //set default SSR options
+ //set default SSSSS options
- virtual void environment_set_background_param(RID p_env,EnvironmentBGParam p_param, const Variant& p_value)=0;
- virtual Variant environment_get_background_param(RID p_env,EnvironmentBGParam p_param) const=0;
-
- enum EnvironmentFx {
- ENV_FX_AMBIENT_LIGHT,
- ENV_FX_FXAA,
- ENV_FX_GLOW,
- ENV_FX_DOF_BLUR,
- ENV_FX_HDR,
- ENV_FX_FOG,
- ENV_FX_BCS,
- ENV_FX_SRGB,
- ENV_FX_MAX
- };
-
-
-
- virtual void environment_set_enable_fx(RID p_env,EnvironmentFx p_effect,bool p_enabled)=0;
- virtual bool environment_is_fx_enabled(RID p_env,EnvironmentFx p_mode) const=0;
-
- enum EnvironmentFxBlurBlendMode {
- ENV_FX_BLUR_BLEND_MODE_ADDITIVE,
- ENV_FX_BLUR_BLEND_MODE_SCREEN,
- ENV_FX_BLUR_BLEND_MODE_SOFTLIGHT,
+ enum EnvironmentGlowBlendMode {
+ GLOW_BLEND_MODE_ADDITIVE,
+ GLOW_BLEND_MODE_SCREEN,
+ GLOW_BLEND_MODE_SOFTLIGHT,
+ GLOW_BLEND_MODE_DISABLED,
};
+ virtual void environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,EnvironmentGlowBlendMode p_blend_mode)=0;
+ virtual void environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture)=0;
- enum EnvironmentFxHDRToneMapper {
- ENV_FX_HDR_TONE_MAPPER_LINEAR,
- ENV_FX_HDR_TONE_MAPPER_LOG,
- ENV_FX_HDR_TONE_MAPPER_REINHARDT,
- ENV_FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE,
- };
- enum EnvironmentFxParam {
- ENV_FX_PARAM_AMBIENT_LIGHT_COLOR,
- ENV_FX_PARAM_AMBIENT_LIGHT_ENERGY,
- ENV_FX_PARAM_GLOW_BLUR_PASSES,
- ENV_FX_PARAM_GLOW_BLUR_SCALE,
- ENV_FX_PARAM_GLOW_BLUR_STRENGTH,
- ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE,
- ENV_FX_PARAM_GLOW_BLOOM,
- ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD,
- ENV_FX_PARAM_DOF_BLUR_PASSES,
- ENV_FX_PARAM_DOF_BLUR_BEGIN,
- ENV_FX_PARAM_DOF_BLUR_RANGE,
- ENV_FX_PARAM_HDR_TONEMAPPER,
- ENV_FX_PARAM_HDR_EXPOSURE,
- ENV_FX_PARAM_HDR_WHITE,
- ENV_FX_PARAM_HDR_GLOW_TRESHOLD,
- ENV_FX_PARAM_HDR_GLOW_SCALE,
- ENV_FX_PARAM_HDR_MIN_LUMINANCE,
- ENV_FX_PARAM_HDR_MAX_LUMINANCE,
- ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED,
- ENV_FX_PARAM_FOG_BEGIN,
- ENV_FX_PARAM_FOG_BEGIN_COLOR,
- ENV_FX_PARAM_FOG_END_COLOR,
- ENV_FX_PARAM_FOG_ATTENUATION,
- ENV_FX_PARAM_FOG_BG,
- ENV_FX_PARAM_BCS_BRIGHTNESS,
- ENV_FX_PARAM_BCS_CONTRAST,
- ENV_FX_PARAM_BCS_SATURATION,
- ENV_FX_PARAM_MAX
+ enum EnvironmentToneMapper {
+ ENV_TONE_MAPPER_LINEAR,
+ ENV_TONE_MAPPER_REINHARDT,
+ ENV_TONE_MAPPER_FILMIC
};
- virtual void environment_fx_set_param(RID p_env,EnvironmentFxParam p_effect,const Variant& p_param)=0;
- virtual Variant environment_fx_get_param(RID p_env,EnvironmentFxParam p_effect) const=0;
+ virtual void environment_set_tonemap(RID p_env,bool p_enable,float p_exposure,float p_white,float p_min_luminance,float p_max_luminance,float p_auto_exp_speed,EnvironmentToneMapper p_tone_mapper)=0;
+ virtual void environment_set_brightness(RID p_env,bool p_enable,float p_brightness)=0;
+ virtual void environment_set_contrast(RID p_env,bool p_enable,float p_contrast)=0;
+ virtual void environment_set_saturation(RID p_env,bool p_enable,float p_saturation)=0;
+ virtual void environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp)=0;
/* SCENARIO API */
-
-
virtual RID scenario_create()=0;
enum ScenarioDebugMode {
@@ -881,14 +540,14 @@ public:
INSTANCE_MESH,
INSTANCE_MULTIMESH,
INSTANCE_IMMEDIATE,
- INSTANCE_PARTICLES,
INSTANCE_LIGHT,
+ INSTANCE_REFLECTION_PROBE,
INSTANCE_ROOM,
INSTANCE_PORTAL,
- INSTANCE_BAKED_LIGHT,
- INSTANCE_BAKED_LIGHT_SAMPLER,
+ /*INSTANCE_BAKED_LIGHT,
+ INSTANCE_BAKED_LIGHT_SAMPLER,*/
- INSTANCE_GEOMETRY_MASK=(1<<INSTANCE_MESH)|(1<<INSTANCE_MULTIMESH)|(1<<INSTANCE_IMMEDIATE)|(1<<INSTANCE_PARTICLES)
+ INSTANCE_GEOMETRY_MASK=(1<<INSTANCE_MESH)|(1<<INSTANCE_MULTIMESH)|(1<<INSTANCE_IMMEDIATE)
};
@@ -899,51 +558,29 @@ public:
virtual RID instance_create()=0; // from can be mesh, light, poly, area and portal so far.
virtual void instance_set_base(RID p_instance, RID p_base)=0; // from can be mesh, light, poly, area and portal so far.
- virtual RID instance_get_base(RID p_instance) const=0;
-
virtual void instance_set_scenario(RID p_instance, RID p_scenario)=0; // from can be mesh, light, poly, area and portal so far.
- virtual RID instance_get_scenario(RID p_instance) const=0;
-
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask)=0;
- virtual uint32_t instance_get_layer_mask(RID p_instance) const=0;
-
- virtual AABB instance_get_base_aabb(RID p_instance) const=0;
-
virtual void instance_set_transform(RID p_instance, const Transform& p_transform)=0;
- virtual Transform instance_get_transform(RID p_instance) const=0;
-
-
- virtual void instance_attach_object_instance_ID(RID p_instance,uint32_t p_ID)=0;
- virtual uint32_t instance_get_object_instance_ID(RID p_instance) const=0;
-
+ virtual void instance_attach_object_instance_ID(RID p_instance,ObjectID p_ID)=0;
virtual void instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight)=0;
- virtual float instance_get_morph_target_weight(RID p_instance,int p_shape) const=0;
-
virtual void instance_set_surface_material(RID p_instance,int p_surface, RID p_material)=0;
virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton)=0;
- virtual RID instance_get_skeleton(RID p_instance) const=0;
-
virtual void instance_set_exterior( RID p_instance, bool p_enabled )=0;
- virtual bool instance_is_exterior( RID p_instance) const=0;
-
virtual void instance_set_room( RID p_instance, RID p_room )=0;
- virtual RID instance_get_room( RID p_instance ) const =0;
virtual void instance_set_extra_visibility_margin( RID p_instance, real_t p_margin )=0;
- virtual real_t instance_get_extra_visibility_margin( RID p_instance ) const =0;
// don't use these in a game!
- virtual Vector<RID> instances_cull_aabb(const AABB& p_aabb, RID p_scenario=RID()) const=0;
- virtual Vector<RID> instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario=RID()) const=0;
- virtual Vector<RID> instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario=RID()) const=0;
+ virtual Vector<ObjectID> instances_cull_aabb(const AABB& p_aabb, RID p_scenario=RID()) const=0;
+ virtual Vector<ObjectID> instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario=RID()) const=0;
+ virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario=RID()) const=0;
enum InstanceFlags {
INSTANCE_FLAG_VISIBLE,
INSTANCE_FLAG_BILLBOARD,
INSTANCE_FLAG_BILLBOARD_FIX_Y,
INSTANCE_FLAG_CAST_SHADOW,
- INSTANCE_FLAG_RECEIVE_SHADOWS,
INSTANCE_FLAG_DEPH_SCALE,
INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,
INSTANCE_FLAG_USE_BAKED_LIGHT,
@@ -958,80 +595,53 @@ public:
};
virtual void instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled)=0;
- virtual bool instance_geometry_get_flag(RID p_instance,InstanceFlags p_flags) const=0;
-
virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting) = 0;
- virtual ShadowCastingSetting instance_geometry_get_cast_shadows_setting(RID p_instance) const = 0;
-
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material)=0;
- virtual RID instance_geometry_get_material_override(RID p_instance) const=0;
-
- virtual void instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max)=0;
- virtual float instance_geometry_get_draw_range_max(RID p_instance) const=0;
- virtual float instance_geometry_get_draw_range_min(RID p_instance) const=0;
-
- virtual void instance_geometry_set_baked_light(RID p_instance,RID p_baked_light)=0;
- virtual RID instance_geometry_get_baked_light(RID p_instance) const=0;
- virtual void instance_geometry_set_baked_light_sampler(RID p_instance,RID p_baked_light_sampler)=0;
- virtual RID instance_geometry_get_baked_light_sampler(RID p_instance) const=0;
- virtual void instance_geometry_set_baked_light_texture_index(RID p_instance,int p_tex_id)=0;
- virtual int instance_geometry_get_baked_light_texture_index(RID p_instance) const=0;
-
-
- virtual void instance_light_set_enabled(RID p_instance,bool p_enabled)=0;
- virtual bool instance_light_is_enabled(RID p_instance) const=0;
+ virtual void instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max,float p_min_margin,float p_max_margin)=0;
+ virtual void instance_geometry_set_as_instance_lod(RID p_instance,RID p_as_lod_of_instance)=0;
/* CANVAS (2D) */
virtual RID canvas_create()=0;
virtual void canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring)=0;
- virtual Point2 canvas_get_item_mirroring(RID p_canvas,RID p_item) const=0;
virtual void canvas_set_modulate(RID p_canvas,const Color& p_color)=0;
-
virtual RID canvas_item_create()=0;
virtual void canvas_item_set_parent(RID p_item,RID p_parent)=0;
- virtual RID canvas_item_get_parent(RID p_canvas_item) const=0;
virtual void canvas_item_set_visible(RID p_item,bool p_visible)=0;
- virtual bool canvas_item_is_visible(RID p_item) const=0;
-
virtual void canvas_item_set_light_mask(RID p_item,int p_mask)=0;
- virtual void canvas_item_set_blend_mode(RID p_canvas_item,MaterialBlendMode p_blend)=0;
-
- virtual void canvas_item_attach_viewport(RID p_item, RID p_viewport)=0;
-
- //virtual void canvas_item_set_rect(RID p_item, const Rect2& p_rect)=0;
-
virtual void canvas_item_set_transform(RID p_item, const Matrix32& p_transform)=0;
virtual void canvas_item_set_clip(RID p_item, bool p_clip)=0;
virtual void canvas_item_set_distance_field_mode(RID p_item, bool p_enable)=0;
virtual void canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect=Rect2())=0;
- virtual void canvas_item_set_opacity(RID p_item, float p_opacity)=0;
- virtual float canvas_item_get_opacity(RID p_item, float p_opacity) const=0;
+ virtual void canvas_item_set_modulate(RID p_item, const Color& p_color)=0;
+ virtual void canvas_item_set_self_modulate(RID p_item, const Color& p_color)=0;
- virtual void canvas_item_set_self_opacity(RID p_item, float p_self_opacity)=0;
- virtual float canvas_item_get_self_opacity(RID p_item, float p_self_opacity) const=0;
+ virtual void canvas_item_set_draw_behind_parent(RID p_item, bool p_enable)=0;
- virtual void canvas_item_set_on_top(RID p_item, bool p_on_top)=0;
- virtual bool canvas_item_is_on_top(RID p_item) const=0;
+ enum NinePatchAxisMode {
+ NINE_PATCH_STRETCH,
+ NINE_PATCH_TILE,
+ NINE_PATCH_TILE_FIT,
+ };
virtual void canvas_item_add_line(RID p_item, const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0,bool p_antialiased=false)=0;
virtual void canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color)=0;
virtual void canvas_item_add_circle(RID p_item, const Point2& p_pos, float p_radius,const Color& p_color)=0;
virtual void canvas_item_add_texture_rect(RID p_item, const Rect2& p_rect, RID p_texture,bool p_tile=false,const Color& p_modulate=Color(1,1,1),bool p_transpose=false)=0;
virtual void canvas_item_add_texture_rect_region(RID p_item, const Rect2& p_rect, RID p_texture,const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1),bool p_transpose=false)=0;
- virtual void canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0;
+ virtual void canvas_item_add_nine_patch(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright,NinePatchAxisMode p_x_axis_mode=NINE_PATCH_STRETCH, NinePatchAxisMode p_y_axis_mode=NINE_PATCH_STRETCH,bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0;
virtual void canvas_item_add_primitive(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width=1.0)=0;
virtual void canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), RID p_texture=RID())=0;
virtual void canvas_item_add_triangle_array(RID p_item, const Vector<int>& p_indices, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), RID p_texture=RID(), int p_count=-1)=0;
- virtual void canvas_item_add_triangle_array_ptr(RID p_item, int p_count, const int* p_indices, const Point2* p_points, const Color* p_colors,const Point2* p_uvs=NULL, RID p_texture=RID())=0;
+ virtual void canvas_item_add_mesh(RID p_item, const RID& p_mesh,RID p_skeleton=RID())=0;
+ virtual void canvas_item_add_multimesh(RID p_item, RID p_mesh,RID p_skeleton=RID())=0;
virtual void canvas_item_add_set_transform(RID p_item,const Matrix32& p_transform)=0;
- virtual void canvas_item_add_set_blend_mode(RID p_item, MaterialBlendMode p_blend)=0;
virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore)=0;
virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable)=0;
virtual void canvas_item_set_z(RID p_item, int p_z)=0;
@@ -1039,7 +649,7 @@ public:
virtual void canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect)=0;
virtual void canvas_item_clear(RID p_item)=0;
- virtual void canvas_item_raise(RID p_item)=0;
+ virtual void canvas_item_set_draw_index(RID p_item,int p_index)=0;
virtual void canvas_item_set_material(RID p_item, RID p_material)=0;
@@ -1057,8 +667,8 @@ public:
virtual void canvas_light_set_energy(RID p_light, float p_energy)=0;
virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z)=0;
virtual void canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer)=0;
- virtual void canvas_light_set_item_mask(RID p_light, int p_mask)=0;
- virtual void canvas_light_set_item_shadow_mask(RID p_light, int p_mask)=0;
+ virtual void canvas_light_set_item_cull_mask(RID p_light, int p_mask)=0;
+ virtual void canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask)=0;
enum CanvasLightMode {
CANVAS_LIGHT_MODE_ADD,
@@ -1068,9 +678,20 @@ public:
};
virtual void canvas_light_set_mode(RID p_light, CanvasLightMode p_mode)=0;
+
+
+ enum CanvasLightShadowFilter {
+ CANVAS_LIGHT_FILTER_NONE,
+ CANVAS_LIGHT_FILTER_PCF3,
+ CANVAS_LIGHT_FILTER_PCF5,
+ CANVAS_LIGHT_FILTER_PCF9,
+ CANVAS_LIGHT_FILTER_PCF13,
+ };
+
virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled)=0;
virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size)=0;
- virtual void canvas_light_set_shadow_esm_multiplier(RID p_light, float p_multiplier)=0;
+ virtual void canvas_light_set_shadow_gradient_length(RID p_light, float p_length)=0;
+ virtual void canvas_light_set_shadow_filter(RID p_light, CanvasLightShadowFilter p_filter)=0;
virtual void canvas_light_set_shadow_color(RID p_light, const Color& p_color)=0;
@@ -1085,6 +706,7 @@ public:
virtual RID canvas_occluder_polygon_create()=0;
virtual void canvas_occluder_polygon_set_shape(RID p_occluder_polygon,const DVector<Vector2>& p_shape,bool p_closed)=0;
virtual void canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon,const DVector<Vector2>& p_shape)=0;
+
enum CanvasOccluderPolygonCullMode {
CANVAS_OCCLUDER_POLYGON_CULL_DISABLED,
CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE,
@@ -1092,21 +714,6 @@ public:
};
virtual void canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon,CanvasOccluderPolygonCullMode p_mode)=0;
- /* CANVAS ITEM MATERIAL */
-
- virtual RID canvas_item_material_create()=0;
- virtual void canvas_item_material_set_shader(RID p_material, RID p_shader)=0;
- virtual void canvas_item_material_set_shader_param(RID p_material, const StringName& p_param, const Variant& p_value)=0;
- virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const=0;
-
-
- enum CanvasItemShadingMode {
- CANVAS_ITEM_SHADING_NORMAL,
- CANVAS_ITEM_SHADING_UNSHADED,
- CANVAS_ITEM_SHADING_ONLY_LIGHT,
- };
-
- virtual void canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode)=0;
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0)=0; // radians
@@ -1125,15 +732,6 @@ public:
virtual void free( RID p_rid )=0; ///< free RIDs associated with the visual server
- /* CUSTOM SHADING */
-
- virtual void custom_shade_model_set_shader(int p_model, RID p_shader)=0;
- virtual RID custom_shade_model_get_shader(int p_model) const=0;
- virtual void custom_shade_model_set_name(int p_model, const String& p_name)=0;
- virtual String custom_shade_model_get_name(int p_model) const=0;
- virtual void custom_shade_model_set_param_info(int p_model, const List<PropertyInfo>& p_info)=0;
- virtual void custom_shade_model_get_param_info(int p_model, List<PropertyInfo>* p_info) const=0;
-
/* EVENT QUEUING */
virtual void draw()=0;
@@ -1166,7 +764,6 @@ public:
RID material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_alpha,bool p_opaque_prepass);
-
/* TESTING */
virtual RID get_test_cube()=0;
@@ -1185,7 +782,6 @@ public:
enum Features {
FEATURE_SHADERS,
FEATURE_MULTITHREADED,
- FEATURE_NEEDS_RELOAD_HOOK,
};
virtual bool has_feature(Features p_feature) const=0;
@@ -1200,19 +796,15 @@ public:
VARIANT_ENUM_CAST( VisualServer::CubeMapSide );
VARIANT_ENUM_CAST( VisualServer::TextureFlags );
VARIANT_ENUM_CAST( VisualServer::ShaderMode );
-VARIANT_ENUM_CAST( VisualServer::MaterialFlag );
-VARIANT_ENUM_CAST( VisualServer::MaterialBlendMode );
-VARIANT_ENUM_CAST( VisualServer::ParticleVariable );
VARIANT_ENUM_CAST( VisualServer::ArrayType );
VARIANT_ENUM_CAST( VisualServer::ArrayFormat );
VARIANT_ENUM_CAST( VisualServer::PrimitiveType );
VARIANT_ENUM_CAST( VisualServer::LightType );
-VARIANT_ENUM_CAST( VisualServer::LightColor );
VARIANT_ENUM_CAST( VisualServer::LightParam );
VARIANT_ENUM_CAST( VisualServer::ScenarioDebugMode );
VARIANT_ENUM_CAST( VisualServer::InstanceType );
VARIANT_ENUM_CAST( VisualServer::RenderInfo );
-VARIANT_ENUM_CAST( VisualServer::MipMapPolicy );
+
//typedef VisualServer VS; // makes it easier to use
#define VS VisualServer
diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp
index 9240e3527c..6fb796ae6a 100644
--- a/tools/editor/code_editor.cpp
+++ b/tools/editor/code_editor.cpp
@@ -895,7 +895,7 @@ void FindReplaceDialog::_bind_methods() {
FindReplaceDialog::FindReplaceDialog() {
- set_self_opacity(0.8);
+ set_self_modulate(Color(1,1,1,0.8));
VBoxContainer *vb = memnew( VBoxContainer );
add_child(vb);
diff --git a/tools/editor/editor_autoload_settings.cpp b/tools/editor/editor_autoload_settings.cpp
index 97062b1480..bf8a891247 100644
--- a/tools/editor/editor_autoload_settings.cpp
+++ b/tools/editor/editor_autoload_settings.cpp
@@ -399,7 +399,7 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2& p_point, Control
for (int i = 0; i < max_size; i++) {
Label *label = memnew( Label(autoloads[i]) );
- label->set_self_opacity(Math::lerp(1, 0, float(i)/PREVIEW_LIST_MAX_SIZE));
+ label->set_self_modulate(Color(1,1,1,Math::lerp(1, 0, float(i)/PREVIEW_LIST_MAX_SIZE)));
preview->add_child(label);
}
diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp
index 4f83dc2f66..628870c70f 100644
--- a/tools/editor/editor_help.cpp
+++ b/tools/editor/editor_help.cpp
@@ -1710,7 +1710,7 @@ EditorHelp::EditorHelp() {
search_dialog->get_ok()->set_text(TTR("Find"));
search_dialog->connect("confirmed",this,"_search_cbk");
search_dialog->set_hide_on_ok(false);
- search_dialog->set_self_opacity(0.8);
+ search_dialog->set_self_modulate(Color(1,1,1,0.8));
/*class_search = memnew( EditorHelpSearch(editor) );
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 8274272a7e..7f02624107 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -907,10 +907,11 @@ void EditorNode::_save_scene_with_preview(String p_file) {
_editor_select(is2d?EDITOR_2D:EDITOR_3D);
- VS::get_singleton()->viewport_queue_screen_capture(viewport);
+
save.step(TTR("Creating Thumbnail"),2);
save.step(TTR("Creating Thumbnail"),3);
- Image img = VS::get_singleton()->viewport_get_screen_capture(viewport);
+#if 0
+ Image img = VS::get_singleton()->viewport_texture(scree_capture(viewport);
int preview_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");;
preview_size*=EDSCALE;
int width,height;
@@ -928,7 +929,7 @@ void EditorNode::_save_scene_with_preview(String p_file) {
height=img.get_height();
}
- img.convert(Image::FORMAT_RGB);
+ img.convert(Image::FORMAT_RGB8);
img.resize(width,height);
String pfile = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/last_scene_preview.png");
@@ -940,7 +941,7 @@ void EditorNode::_save_scene_with_preview(String p_file) {
if (editor_data.get_edited_scene_import_metadata().is_null())
editor_data.set_edited_scene_import_metadata(Ref<ResourceImportMetadata>( memnew( ResourceImportMetadata ) ) );
editor_data.get_edited_scene_import_metadata()->set_option("thumbnail",imgdata);
-
+#endif
//tamanio tel thumbnail
if (screen!=-1) {
_editor_select(screen);
@@ -1243,7 +1244,7 @@ void EditorNode::_dialog_action(String p_file) {
ml = Ref<MeshLibrary>( memnew( MeshLibrary ));
}
- MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(),ml,true);
+// MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(),ml,true);
Error err = ResourceSaver::save(p_file,ml);
if (err) {
@@ -4145,7 +4146,7 @@ void EditorNode::register_editor_types() {
ObjectTypeDB::register_type<EditorFileDialog>();
//ObjectTypeDB::register_type<EditorImportExport>();
ObjectTypeDB::register_type<EditorSettings>();
- ObjectTypeDB::register_type<EditorSpatialGizmo>();
+// ObjectTypeDB::register_type<EditorSpatialGizmo>();
ObjectTypeDB::register_type<EditorResourcePreview>();
ObjectTypeDB::register_type<EditorResourcePreviewGenerator>();
ObjectTypeDB::register_type<EditorFileSystem>();
@@ -6537,10 +6538,10 @@ EditorNode::EditorNode() {
//more visually meaningful to have this later
raise_bottom_panel_item(AnimationPlayerEditor::singleton);
- add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,true) ) );
+/* add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,true) ) );
add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,false) ) );
add_editor_plugin( memnew( ShaderEditorPlugin(this,true) ) );
- add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) );
+ add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) );*/
add_editor_plugin( memnew( CameraEditorPlugin(this) ) );
add_editor_plugin( memnew( SampleEditorPlugin(this) ) );
add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) );
@@ -6549,14 +6550,14 @@ EditorNode::EditorNode() {
add_editor_plugin( memnew( MeshInstanceEditorPlugin(this) ) );
add_editor_plugin( memnew( AnimationTreeEditorPlugin(this) ) );
//add_editor_plugin( memnew( SamplePlayerEditorPlugin(this) ) ); - this is kind of useless at this point
- add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) );
+// add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) );
//add_editor_plugin( memnew( StreamEditorPlugin(this) ) );
add_editor_plugin( memnew( StyleBoxEditorPlugin(this) ) );
- add_editor_plugin( memnew( ParticlesEditorPlugin(this) ) );
+ //add_editor_plugin( memnew( ParticlesEditorPlugin(this) ) );
add_editor_plugin( memnew( ResourcePreloaderEditorPlugin(this) ) );
add_editor_plugin( memnew( ItemListEditorPlugin(this) ) );
//add_editor_plugin( memnew( RichTextEditorPlugin(this) ) );
- add_editor_plugin( memnew( CollisionPolygonEditorPlugin(this) ) );
+// add_editor_plugin( memnew( CollisionPolygonEditorPlugin(this) ) );
add_editor_plugin( memnew( CollisionPolygon2DEditorPlugin(this) ) );
add_editor_plugin( memnew( TileSetEditorPlugin(this) ) );
add_editor_plugin( memnew( TileMapEditorPlugin(this) ) );
@@ -6564,16 +6565,16 @@ EditorNode::EditorNode() {
add_editor_plugin( memnew( TextureRegionEditorPlugin(this) ) );
add_editor_plugin( memnew( Particles2DEditorPlugin(this) ) );
add_editor_plugin( memnew( Path2DEditorPlugin(this) ) );
- add_editor_plugin( memnew( PathEditorPlugin(this) ) );
- add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) );
+// add_editor_plugin( memnew( PathEditorPlugin(this) ) );
+ //add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) );
add_editor_plugin( memnew( Polygon2DEditorPlugin(this) ) );
add_editor_plugin( memnew( LightOccluder2DEditorPlugin(this) ) );
add_editor_plugin( memnew( NavigationPolygonEditorPlugin(this) ) );
add_editor_plugin( memnew( ColorRampEditorPlugin(this) ) );
add_editor_plugin( memnew( CollisionShape2DEditorPlugin(this) ) );
add_editor_plugin( memnew( TextureEditorPlugin(this) ) );
- add_editor_plugin( memnew( MaterialEditorPlugin(this) ) );
- add_editor_plugin( memnew( MeshEditorPlugin(this) ) );
+// add_editor_plugin( memnew( MaterialEditorPlugin(this) ) );
+// add_editor_plugin( memnew( MeshEditorPlugin(this) ) );
for(int i=0;i<EditorPlugins::get_plugin_count();i++)
add_editor_plugin( EditorPlugins::create(i,this) );
@@ -6582,14 +6583,14 @@ EditorNode::EditorNode() {
plugin_init_callbacks[i]();
}
- resource_preview->add_preview_generator( Ref<EditorTexturePreviewPlugin>( memnew(EditorTexturePreviewPlugin )));
+ /*resource_preview->add_preview_generator( Ref<EditorTexturePreviewPlugin>( memnew(EditorTexturePreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorPackedScenePreviewPlugin>( memnew(EditorPackedScenePreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorMaterialPreviewPlugin>( memnew(EditorMaterialPreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorScriptPreviewPlugin>( memnew(EditorScriptPreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorMeshPreviewPlugin>( memnew(EditorMeshPreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorBitmapPreviewPlugin>( memnew(EditorBitmapPreviewPlugin )));
-
+*/
circle_step_msec=OS::get_singleton()->get_ticks_msec();
diff --git a/tools/editor/editor_profiler.cpp b/tools/editor/editor_profiler.cpp
index 13327f0be9..435ad78b89 100644
--- a/tools/editor/editor_profiler.cpp
+++ b/tools/editor/editor_profiler.cpp
@@ -338,7 +338,7 @@ void EditorProfiler::_update_plot() {
wr = DVector<uint8_t>::Write();
- Image img(w,h,0,Image::FORMAT_RGBA,graph_image);
+ Image img(w,h,0,Image::FORMAT_RGBA8,graph_image);
if (reset_texture) {
diff --git a/tools/editor/icons/SCsub b/tools/editor/icons/SCsub
index 44e28f49e6..e9054f30d9 100644
--- a/tools/editor/icons/SCsub
+++ b/tools/editor/icons/SCsub
@@ -63,7 +63,7 @@ def make_editor_icons_action(target, source, env):
s.write("\tRef<ImageTexture> texture( memnew( ImageTexture ) );\n")
s.write("\tbool use_hidpi_image=(editor_get_scale()>1.0&&p_hidpi_png);\n")
s.write("\tImage img(use_hidpi_image?p_hidpi_png:p_png);\n")
- s.write("\tif (editor_get_scale()>1.0 && !p_hidpi_png) { img.convert(Image::FORMAT_RGBA); img.expand_x2_hq2x(); use_hidpi_image=true;}\n")
+ s.write("\tif (editor_get_scale()>1.0 && !p_hidpi_png) { img.convert(Image::FORMAT_RGBA8); img.expand_x2_hq2x(); use_hidpi_image=true;}\n")
s.write("\timg.resize(img.get_width()*EDSCALE/(use_hidpi_image?2:1),img.get_height()*EDSCALE/(use_hidpi_image?2:1));\n")
s.write("\ttexture->create_from_image( img,ImageTexture::FLAG_FILTER );\n")
s.write("\treturn texture;\n")
diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp
index df3741f0d4..0a3b0d4917 100644
--- a/tools/editor/io_plugins/editor_font_import_plugin.cpp
+++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp
@@ -1330,7 +1330,7 @@ Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMe
if (err==OK) {
for(int i=0;i<height;i++){
- color[i]=img.get_pixel(0,i*img.get_height()/height);
+ //color[i]=img.get_pixel(0,i*img.get_height()/height);
}
} else {
@@ -1514,7 +1514,7 @@ Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMe
w=DVector<uint8_t>::Write();
- Image img(s.width,s.height,0,Image::FORMAT_RGBA,pixels);
+ Image img(s.width,s.height,0,Image::FORMAT_RGBA8,pixels);
font_data_list[i]->blit=img;
font_data_list[i]->blit_ofs=o;
@@ -1537,7 +1537,7 @@ Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMe
res_size.y=nearest_power_of_2(res_size.y);
print_line("Atlas size: "+res_size);
- Image atlas(res_size.x,res_size.y,0,Image::FORMAT_RGBA);
+ Image atlas(res_size.x,res_size.y,0,Image::FORMAT_RGBA8);
for(int i=0;i<font_data_list.size();i++) {
@@ -1565,12 +1565,12 @@ Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMe
}
}
- atlas=Image(res_size.x,res_size.y,0,Image::FORMAT_RGBA,data);
+ atlas=Image(res_size.x,res_size.y,0,Image::FORMAT_RGBA8,data);
}
if (from->has_option("color/monochrome") && bool(from->get_option("color/monochrome"))) {
- atlas.convert(Image::FORMAT_GRAYSCALE_ALPHA);
+ atlas.convert(Image::FORMAT_LA8);
}
diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp
index 1130e2be30..6b1873d49a 100644
--- a/tools/editor/io_plugins/editor_import_collada.cpp
+++ b/tools/editor/io_plugins/editor_import_collada.cpp
@@ -237,8 +237,8 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
//well, it's an ambient light..
Light *l = memnew( DirectionalLight );
// l->set_color(Light::COLOR_AMBIENT,ld.color);
- l->set_color(Light::COLOR_DIFFUSE,Color(0,0,0));
- l->set_color(Light::COLOR_SPECULAR,Color(0,0,0));
+// l->set_color(Light::COLOR_DIFFUSE,Color(0,0,0));
+// l->set_color(Light::COLOR_SPECULAR,Color(0,0,0));
node = l;
} else if (ld.mode==Collada::LightData::MODE_DIRECTIONAL) {
@@ -248,8 +248,8 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
//if (found_ambient) //use it here
// l->set_color(Light::COLOR_AMBIENT,ambient);
- l->set_color(Light::COLOR_DIFFUSE,ld.color);
- l->set_color(Light::COLOR_SPECULAR,Color(1,1,1));
+// l->set_color(Light::COLOR_DIFFUSE,ld.color);
+// l->set_color(Light::COLOR_SPECULAR,Color(1,1,1));
node = l;
} else {
@@ -259,14 +259,14 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
l=memnew( OmniLight );
else {
l=memnew( SpotLight );
- l->set_parameter(Light::PARAM_SPOT_ANGLE,ld.spot_angle);
- l->set_parameter(Light::PARAM_SPOT_ATTENUATION,ld.spot_exp);
+// l->set_parameter(Light::PARAM_SPOT_ANGLE,ld.spot_angle);
+// l->set_parameter(Light::PARAM_SPOT_ATTENUATION,ld.spot_exp);
}
//
- l->set_color(Light::COLOR_DIFFUSE,ld.color);
- l->set_color(Light::COLOR_SPECULAR,Color(1,1,1));
- l->approximate_opengl_attenuation(ld.constant_att,ld.linear_att,ld.quad_att);
+// l->set_color(Light::COLOR_DIFFUSE,ld.color);
+// l->set_color(Light::COLOR_SPECULAR,Color(1,1,1));
+// l->approximate_opengl_attenuation(ld.constant_att,ld.linear_att,ld.quad_att);
node=l;
}
@@ -394,14 +394,14 @@ Error ColladaImport::_create_material(const String& p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile,"Texture");
if (texture.is_valid()) {
- material->set_texture(FixedMaterial::PARAM_DIFFUSE,texture);
- material->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1,1));
+// material->set_texture(FixedMaterial::PARAM_DIFFUSE,texture);
+// material->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1,1));
} else {
missing_textures.push_back(texfile.get_file());
}
}
} else {
- material->set_parameter(FixedMaterial::PARAM_DIFFUSE,effect.diffuse.color);
+// material->set_parameter(FixedMaterial::PARAM_DIFFUSE,effect.diffuse.color);
}
// SPECULAR
@@ -414,15 +414,15 @@ Error ColladaImport::_create_material(const String& p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile,"Texture");
if (texture.is_valid()) {
- material->set_texture(FixedMaterial::PARAM_SPECULAR,texture);
- material->set_parameter(FixedMaterial::PARAM_SPECULAR,Color(1,1,1,1));
+// material->set_texture(FixedMaterial::PARAM_SPECULAR,texture);
+// material->set_parameter(FixedMaterial::PARAM_SPECULAR,Color(1,1,1,1));
} else {
missing_textures.push_back(texfile.get_file());
}
}
} else {
- material->set_parameter(FixedMaterial::PARAM_SPECULAR,effect.specular.color);
+// material->set_parameter(FixedMaterial::PARAM_SPECULAR,effect.specular.color);
}
// EMISSION
@@ -435,15 +435,15 @@ Error ColladaImport::_create_material(const String& p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile,"Texture");
if (texture.is_valid()) {
- material->set_texture(FixedMaterial::PARAM_EMISSION,texture);
- material->set_parameter(FixedMaterial::PARAM_EMISSION,Color(1,1,1,1));
+// material->set_texture(FixedMaterial::PARAM_EMISSION,texture);
+// material->set_parameter(FixedMaterial::PARAM_EMISSION,Color(1,1,1,1));
}else {
- missing_textures.push_back(texfile.get_file());
+// missing_textures.push_back(texfile.get_file());
}
}
} else {
- material->set_parameter(FixedMaterial::PARAM_EMISSION,effect.emission.color);
+// material->set_parameter(FixedMaterial::PARAM_EMISSION,effect.emission.color);
}
// NORMAL
@@ -456,18 +456,18 @@ Error ColladaImport::_create_material(const String& p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile,"Texture");
if (texture.is_valid()) {
- material->set_texture(FixedMaterial::PARAM_NORMAL,texture);
+ // material->set_texture(FixedMaterial::PARAM_NORMAL,texture);
}else {
- missing_textures.push_back(texfile.get_file());
+// missing_textures.push_back(texfile.get_file());
}
}
}
- material->set_parameter(FixedMaterial::PARAM_SPECULAR_EXP,effect.shininess);
- material->set_flag(Material::FLAG_DOUBLE_SIDED,effect.double_sided);
- material->set_flag(Material::FLAG_UNSHADED,effect.unshaded);
+// material->set_parameter(FixedMaterial::PARAM_SPECULAR_EXP,effect.shininess);
+// material->set_flag(Material::FLAG_DOUBLE_SIDED,effect.double_sided);
+// material->set_flag(Material::FLAG_UNSHADED,effect.unshaded);
@@ -1196,7 +1196,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,con
tarrayw = DVector<real_t>::Write();
final_tangent_array=tarray;
- } else if (final_normal_array.size() && primitive==Mesh::PRIMITIVE_TRIANGLES && final_uv_array.size() && (force_make_tangents || (material.is_valid() && material->get_texture(FixedMaterial::PARAM_NORMAL).is_valid()))){
+ } else if (final_normal_array.size() && primitive==Mesh::PRIMITIVE_TRIANGLES && final_uv_array.size() && (force_make_tangents || (material.is_valid()))){
//if this uses triangles, there are uvs and the material is using a normalmap, generate tangents and binormals, because they WILL be needed
//generate binormals/tangents
_generate_tangents_and_binormals(index_array,final_vertex_array,final_uv_array,final_normal_array,final_tangent_array);
diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp
index 190b56faba..9d68807c46 100644
--- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp
+++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp
@@ -1406,9 +1406,9 @@ void EditorSceneImportPlugin::_find_resources(const Variant& p_var, Map<Ref<Imag
if (tex.is_valid()) {
image_map.insert(tex,TEXTURE_ROLE_NORMALMAP);
- if (p_flags&SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY)
- res->cast_to<FixedMaterial>()->set_fixed_flag(FixedMaterial::FLAG_USE_XY_NORMALMAP,true);
- }
+ //if (p_flags&SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY)
+ // res->cast_to<FixedMaterial>()->set_fixed_flag(FixedMaterial::FLAG_USE_XY_NORMALMAP,true);
+ }//
} else {
@@ -1516,10 +1516,10 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
Ref<FixedMaterial> fm = m->surface_get_material(i);
if (fm.is_valid()) {
- fm->set_flag(Material::FLAG_UNSHADED,true);
- fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
- fm->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
+ // fm->set_flag(Material::FLAG_UNSHADED,true);
+ // fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
+ // fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
+ // fm->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
}
}
}
@@ -1543,17 +1543,17 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
if (p_flags&SCENE_FLAG_DETECT_ALPHA && _teststr(mat->get_name(),"alpha")) {
- mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
- mat->set_name(_fixstr(mat->get_name(),"alpha"));
+ // mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
+ // mat->set_name(_fixstr(mat->get_name(),"alpha"));
}
if (p_flags&SCENE_FLAG_DETECT_VCOLOR && _teststr(mat->get_name(),"vcol")) {
- mat->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true);
- mat->set_name(_fixstr(mat->get_name(),"vcol"));
+ //mat->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true);
+ //mat->set_name(_fixstr(mat->get_name(),"vcol"));
}
if (p_flags&SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS && m->surface_get_format(i)&Mesh::ARRAY_FORMAT_TEX_UV2) {
- mat->set_flag(Material::FLAG_LIGHTMAP_ON_UV2,true);
+ //mat->set_flag(Material::FLAG_LIGHTMAP_ON_UV2,true);
}
}
@@ -1612,11 +1612,11 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
float dist = d.to_double();
mi->set_flag(GeometryInstance::FLAG_BILLBOARD,true);
mi->set_flag(GeometryInstance::FLAG_BILLBOARD_FIX_Y,true);
- mi->set_draw_range_begin(dist);
- mi->set_draw_range_end(100000);
+ //mi->set_draw_range_begin(dist);
+ //mi->set_draw_range_end(100000);
- mip->set_draw_range_begin(0);
- mip->set_draw_range_end(dist);
+ //mip->set_draw_range_begin(0);
+ //mip->set_draw_range_end(dist);
if (mi->get_mesh().is_valid()) {
@@ -1625,10 +1625,10 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
Ref<FixedMaterial> fm = m->surface_get_material(i);
if (fm.is_valid()) {
- fm->set_flag(Material::FLAG_UNSHADED,true);
- fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
- fm->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
+ // fm->set_flag(Material::FLAG_UNSHADED,true);
+ // fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
+ // fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
+ // fm->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
}
}
}
@@ -1660,11 +1660,11 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
d=d.substr(1,d.length());
if (d.length() && d[0]>='0' && d[0]<='9') {
float dist = d.to_double();
- mi->set_draw_range_begin(dist);
- mi->set_draw_range_end(100000);
+ /// mi->set_draw_range_begin(dist);
+ // mi->set_draw_range_end(100000);
- mip->set_draw_range_begin(0);
- mip->set_draw_range_end(dist);
+ // mip->set_draw_range_begin(0);
+ // mip->set_draw_range_end(dist);
/*if (mi->get_mesh().is_valid()) {
@@ -1888,8 +1888,8 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
BSP_Tree bsptree(faces);
Ref<RoomBounds> area = memnew( RoomBounds );
- area->set_bounds(faces);
- area->set_geometry_hint(faces);
+ //area->set_bounds(faces);
+ //area->set_geometry_hint(faces);
Room * room = memnew( Room );
@@ -1917,7 +1917,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
memdelete(p_node);
p_node=room;
- room->compute_room_from_subtree();
+ //room->compute_room_from_subtree();
} else if (p_flags&SCENE_FLAG_CREATE_PORTALS &&_teststr(name,"portal") && p_node->cast_to<MeshInstance>()) {
@@ -2047,7 +2047,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
Ref<FixedMaterial> fm = mesh->surface_get_material(i);
if (fm.is_valid()) {
String name = fm->get_name();
- if (_teststr(name,"alpha")) {
+ /* if (_teststr(name,"alpha")) {
fm->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
name=_fixstr(name,"alpha");
}
@@ -2055,7 +2055,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
if (_teststr(name,"vcol")) {
fm->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true);
name=_fixstr(name,"vcol");
- }
+ }*/
fm->set_name(name);
}
}
diff --git a/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp b/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp
index ac3c4637c2..f117182365 100644
--- a/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp
+++ b/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp
@@ -33,7 +33,7 @@
#include "scene/3d/mesh_instance.h"
#include "scene/animation/animation_player.h"
-
+#if 0
String EditorSceneImporterFBXConv::_id(const String& p_id) const {
return p_id.replace(":","_").replace("/","_");
@@ -1132,3 +1132,4 @@ EditorSceneImporterFBXConv::EditorSceneImporterFBXConv() {
#endif
}
+#endif
diff --git a/tools/editor/io_plugins/editor_scene_importer_fbxconv.h b/tools/editor/io_plugins/editor_scene_importer_fbxconv.h
index b0cbc07ba3..e23c0e2faa 100644
--- a/tools/editor/io_plugins/editor_scene_importer_fbxconv.h
+++ b/tools/editor/io_plugins/editor_scene_importer_fbxconv.h
@@ -32,6 +32,7 @@
#include "tools/editor/io_plugins/editor_scene_import_plugin.h"
#include "scene/3d/skeleton.h"
+#if 0
class EditorSceneImporterFBXConv : public EditorSceneImporter {
@@ -107,3 +108,4 @@ public:
};
#endif // EDITOR_SCENE_IMPORTER_FBXCONV_H
+#endif
diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp
index 2935ea8fe2..4397956be7 100644
--- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp
+++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp
@@ -843,33 +843,27 @@ void EditorTextureImportPlugin::compress_image(EditorExportPlatform::ImageCompre
//do absolutely nothing
- } break;
- case EditorExportPlatform::IMAGE_COMPRESSION_INDEXED: {
-
- //quantize
- image.quantize();
-
- } break;
+ } break;
case EditorExportPlatform::IMAGE_COMPRESSION_BC: {
// for maximum compatibility, BC shall always use mipmaps and be PO2
image.resize_to_po2();
- if (image.get_mipmaps()==0)
+ if (!image.has_mipmaps())
image.generate_mipmaps();
- image.compress(Image::COMPRESS_BC);
+ image.compress(Image::COMPRESS_S3TC);
/*
if (has_alpha) {
if (flags&IMAGE_FLAG_ALPHA_BIT) {
- image.convert(Image::FORMAT_BC3);
+ image.convert(Image::FORMAT_DXT5);
} else {
- image.convert(Image::FORMAT_BC2);
+ image.convert(Image::FORMAT_DXT3);
}
} else {
- image.convert(Image::FORMAT_BC1);
+ image.convert(Image::FORMAT_DXT1);
}*/
@@ -880,24 +874,24 @@ void EditorTextureImportPlugin::compress_image(EditorExportPlatform::ImageCompre
// for maximum compatibility (hi apple!), PVRT shall always
// use mipmaps, be PO2 and square
- if (image.get_mipmaps()==0)
+ if (!image.has_mipmaps())
image.generate_mipmaps();
image.resize_to_po2(true);
if (p_smaller) {
image.compress(Image::COMPRESS_PVRTC2);
- //image.convert(has_alpha ? Image::FORMAT_PVRTC2_ALPHA : Image::FORMAT_PVRTC2);
+ //image.convert(has_alpha ? Image::FORMAT_PVRTC2A : Image::FORMAT_PVRTC2);
} else {
image.compress(Image::COMPRESS_PVRTC4);
- //image.convert(has_alpha ? Image::FORMAT_PVRTC4_ALPHA : Image::FORMAT_PVRTC4);
+ //image.convert(has_alpha ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4);
}
} break;
case EditorExportPlatform::IMAGE_COMPRESSION_ETC1: {
image.resize_to_po2(); //square or not?
- if (image.get_mipmaps()==0)
+ if (!image.has_mipmaps())
image.generate_mipmaps();
if (!image.detect_alpha()) {
//ETC1 is only opaque
@@ -930,18 +924,18 @@ Error EditorTextureImportPlugin::_process_texture_data(Ref<ImageTexture> &textur
ERR_FAIL_COND_V(image.empty(),ERR_INVALID_DATA);
bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA) {
+ if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
image.fix_alpha_edges();
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_PREMULT_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
image.premultiply_alpha();
}
@@ -950,7 +944,7 @@ Error EditorTextureImportPlugin::_process_texture_data(Ref<ImageTexture> &textur
image.normalmap_to_xy();
}
- //if ((image.get_format()==Image::FORMAT_RGB || image.get_format()==Image::FORMAT_RGBA) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
+ //if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
// image.srgb_to_linear();
//}
@@ -989,18 +983,18 @@ Error EditorTextureImportPlugin::_process_texture_data(Ref<ImageTexture> &textur
bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA) {
+ if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
image.fix_alpha_edges();
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_PREMULT_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
image.premultiply_alpha();
}
@@ -1009,7 +1003,7 @@ Error EditorTextureImportPlugin::_process_texture_data(Ref<ImageTexture> &textur
image.normalmap_to_xy();
}
- //if ((image.get_format()==Image::FORMAT_RGB || image.get_format()==Image::FORMAT_RGBA) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
+ //if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
//
// print_line("CONVERT BECAUSE: "+itos(flags));
// image.srgb_to_linear();
@@ -1200,9 +1194,9 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
Image src = tsources[i];
if (alpha) {
- src.convert(Image::FORMAT_RGBA);
+ src.convert(Image::FORMAT_RGBA8);
} else {
- src.convert(Image::FORMAT_RGB);
+ src.convert(Image::FORMAT_RGB8);
}
DVector<uint8_t> data = src.get_data();
@@ -1280,7 +1274,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
atlas_h=nearest_power_of_2(dst_size.height);
}
Image atlas;
- atlas.create(atlas_w,atlas_h,0,alpha?Image::FORMAT_RGBA:Image::FORMAT_RGB);
+ atlas.create(atlas_w,atlas_h,0,alpha?Image::FORMAT_RGBA8:Image::FORMAT_RGB8);
atlases.resize(from->get_source_count());
@@ -1411,18 +1405,18 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
ERR_FAIL_COND_V(image.empty(),ERR_INVALID_DATA);
bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA) {
+ if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
image.fix_alpha_edges();
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_PREMULT_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
image.premultiply_alpha();
}
@@ -1431,7 +1425,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
image.normalmap_to_xy();
}
- //if ((image.get_format()==Image::FORMAT_RGB || image.get_format()==Image::FORMAT_RGBA) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
+ //if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
// image.srgb_to_linear();
//}
@@ -1470,18 +1464,18 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA) {
+ if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
- image.convert(Image::FORMAT_RGB);
+ image.convert(Image::FORMAT_RGB8);
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
image.fix_alpha_edges();
}
- if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_PREMULT_ALPHA) {
+ if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
image.premultiply_alpha();
}
@@ -1490,7 +1484,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
image.normalmap_to_xy();
}
- //if ((image.get_format()==Image::FORMAT_RGB || image.get_format()==Image::FORMAT_RGBA) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
+ //if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
//
// print_line("CONVERT BECAUSE: "+itos(flags));
// image.srgb_to_linear();
diff --git a/tools/editor/plugins/baked_light_baker.cpp b/tools/editor/plugins/baked_light_baker.cpp
index f43bec1cd3..5cdae6aff3 100644
--- a/tools/editor/plugins/baked_light_baker.cpp
+++ b/tools/editor/plugins/baked_light_baker.cpp
@@ -33,7 +33,7 @@
#include "tools/editor/editor_node.h"
#include "tools/editor/editor_settings.h"
-
+#if 0
void baked_light_baker_add_64f(double *dst,double value);
void baked_light_baker_add_64i(int64_t *dst,int64_t value);
@@ -91,15 +91,15 @@ BakedLightBaker::MeshTexture* BakedLightBaker::_get_mat_tex(const Ref<Texture>&
if (image.empty())
return NULL;
- if (image.get_format()!=Image::FORMAT_RGBA) {
+ if (image.get_format()!=Image::FORMAT_RGBA8) {
if (image.get_format()>Image::FORMAT_INDEXED_ALPHA) {
Error err = image.decompress();
if (err)
return NULL;
}
- if (image.get_format()!=Image::FORMAT_RGBA)
- image.convert(Image::FORMAT_RGBA);
+ if (image.get_format()!=Image::FORMAT_RGBA8)
+ image.convert(Image::FORMAT_RGBA8);
}
if (imgtex->get_flags()&Texture::FLAG_CONVERT_TO_LINEAR) {
@@ -2619,7 +2619,7 @@ Error BakedLightBaker::transfer_to_lightmaps() {
copymem(w.ptr(),baked_textures[i].data.ptr(),baked_textures[i].data.size());
}
- Image img(baked_textures[i].width,baked_textures[i].height,0,Image::FORMAT_RGBA,dv);
+ Image img(baked_textures[i].width,baked_textures[i].height,0,Image::FORMAT_RGBA8,dv);
Ref<ImageTexture> tex = memnew( ImageTexture );
tex->create_from_image(img);
baked_light->set_lightmap_texture(i,tex);
@@ -2720,3 +2720,4 @@ BakedLightBaker::~BakedLightBaker() {
clear();
}
+#endif
diff --git a/tools/editor/plugins/baked_light_baker.h b/tools/editor/plugins/baked_light_baker.h
index d0fddf5563..99340fcbe8 100644
--- a/tools/editor/plugins/baked_light_baker.h
+++ b/tools/editor/plugins/baked_light_baker.h
@@ -34,6 +34,8 @@
#include "scene/3d/mesh_instance.h"
#include "os/thread.h"
+#if 0
+
class BakedLightBaker {
public:
@@ -375,3 +377,4 @@ public:
};
#endif // BAKED_LIGHT_BAKER_H
+#endif
diff --git a/tools/editor/plugins/baked_light_editor_plugin.cpp b/tools/editor/plugins/baked_light_editor_plugin.cpp
index a58a0c25e2..ed5aafeba0 100644
--- a/tools/editor/plugins/baked_light_editor_plugin.cpp
+++ b/tools/editor/plugins/baked_light_editor_plugin.cpp
@@ -33,7 +33,7 @@
#include "io/resource_saver.h"
-
+#if 0
void BakedLightEditor::_end_baking() {
@@ -145,7 +145,7 @@ void BakedLightEditor::_notification(int p_option) {
#if 1
//debug
- Image img(baker->baked_octree_texture_w,baker->baked_octree_texture_h,0,Image::FORMAT_RGBA,octree_texture);
+ Image img(baker->baked_octree_texture_w,baker->baked_octree_texture_h,0,Image::FORMAT_RGBA8,octree_texture);
Ref<ImageTexture> it = memnew( ImageTexture );
it->create_from_image(img);
ResourceSaver::save("baked_octree.png",it);
@@ -373,3 +373,4 @@ BakedLightEditorPlugin::~BakedLightEditorPlugin()
}
+#endif
diff --git a/tools/editor/plugins/baked_light_editor_plugin.h b/tools/editor/plugins/baked_light_editor_plugin.h
index 4985d7513e..a556bd447a 100644
--- a/tools/editor/plugins/baked_light_editor_plugin.h
+++ b/tools/editor/plugins/baked_light_editor_plugin.h
@@ -40,7 +40,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
+#if 0
class MeshInstance;
@@ -116,5 +116,5 @@ public:
};
#endif // MULTIMESH_EDITOR_PLUGIN_H
-
+#endif
diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_editor_plugin.cpp
index 0b06b3ba21..ccec7eaed1 100644
--- a/tools/editor/plugins/collision_polygon_editor_plugin.cpp
+++ b/tools/editor/plugins/collision_polygon_editor_plugin.cpp
@@ -33,6 +33,8 @@
#include "scene/3d/camera.h"
#include "canvas_item_editor_plugin.h"
+#if 0
+
void CollisionPolygonEditor::_notification(int p_what) {
switch(p_what) {
@@ -642,3 +644,4 @@ CollisionPolygonEditorPlugin::~CollisionPolygonEditorPlugin()
{
}
+#endif
diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.h b/tools/editor/plugins/collision_polygon_editor_plugin.h
index 45e287ef00..4c1f45eca9 100644
--- a/tools/editor/plugins/collision_polygon_editor_plugin.h
+++ b/tools/editor/plugins/collision_polygon_editor_plugin.h
@@ -40,6 +40,8 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
+#if 0
class CanvasItemEditor;
class CollisionPolygonEditor : public HBoxContainer {
@@ -117,5 +119,5 @@ public:
~CollisionPolygonEditorPlugin();
};
-
+#endif
#endif // COLLISION_POLYGON_EDITOR_PLUGIN_H
diff --git a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp
index b6f3db73f7..9bc624ef65 100644
--- a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp
+++ b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp
@@ -28,6 +28,7 @@
/*************************************************************************/
#include "cube_grid_theme_editor_plugin.h"
+#if 0
#include "scene/3d/mesh_instance.h"
#include "scene/3d/physics_body.h"
#include "scene/main/viewport.h"
@@ -353,4 +354,4 @@ MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) {
theme_editor->hide();
}
-
+#endif
diff --git a/tools/editor/plugins/cube_grid_theme_editor_plugin.h b/tools/editor/plugins/cube_grid_theme_editor_plugin.h
index 72ee171e19..a2875d24c2 100644
--- a/tools/editor/plugins/cube_grid_theme_editor_plugin.h
+++ b/tools/editor/plugins/cube_grid_theme_editor_plugin.h
@@ -32,7 +32,7 @@
#include "scene/resources/mesh_library.h"
#include "tools/editor/editor_node.h"
-
+#if 0
class MeshLibraryEditor : public Control {
OBJ_TYPE( MeshLibraryEditor, Control );
@@ -93,3 +93,4 @@ public:
#endif // CUBE_GRID_THEME_EDITOR_PLUGIN_H
+#endif
diff --git a/tools/editor/plugins/editor_preview_plugins.cpp b/tools/editor/plugins/editor_preview_plugins.cpp
index b1bce60484..66f766a0be 100644
--- a/tools/editor/plugins/editor_preview_plugins.cpp
+++ b/tools/editor/plugins/editor_preview_plugins.cpp
@@ -37,6 +37,7 @@
#include "scene/resources/bit_mask.h"
#include "tools/editor/editor_scale.h"
+#if 0
bool EditorTexturePreviewPlugin::handles(const String& p_type) const {
return (ObjectTypeDB::is_type(p_type,"ImageTexture") || ObjectTypeDB::is_type(p_type, "AtlasTexture"));
@@ -69,8 +70,8 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES& p_from) {
if (img.is_compressed()) {
if (img.decompress()!=OK)
return Ref<Texture>();
- } else if (img.get_format()!=Image::FORMAT_RGB && img.get_format()!=Image::FORMAT_RGBA) {
- img.convert(Image::FORMAT_RGBA);
+ } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) {
+ img.convert(Image::FORMAT_RGBA8);
}
int width,height;
@@ -138,15 +139,15 @@ Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES& p_from) {
}
- Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_GRAYSCALE,data);
+ Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_L8,data);
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
thumbnail_size*=EDSCALE;
if (img.is_compressed()) {
if (img.decompress()!=OK)
return Ref<Texture>();
- } else if (img.get_format()!=Image::FORMAT_RGB && img.get_format()!=Image::FORMAT_RGBA) {
- img.convert(Image::FORMAT_RGBA);
+ } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) {
+ img.convert(Image::FORMAT_RGBA8);
}
int width,height;
@@ -434,7 +435,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES& p_from) {
int col=0;
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
thumbnail_size*=EDSCALE;
- Image img(thumbnail_size,thumbnail_size,0,Image::FORMAT_RGBA);
+ Image img(thumbnail_size,thumbnail_size,0,Image::FORMAT_RGBA8);
@@ -778,7 +779,7 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
imgdata = DVector<uint8_t>::Write();
Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture));
- ptex->create_from_image(Image(w,h,0,Image::FORMAT_RGB,img),0);
+ ptex->create_from_image(Image(w,h,0,Image::FORMAT_RGB8,img),0);
return ptex;
}
@@ -888,6 +889,7 @@ EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() {
}
+
EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() {
//VS::get_singleton()->free(sphere);
@@ -901,3 +903,4 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() {
VS::get_singleton()->free(scenario);
}
+#endif
diff --git a/tools/editor/plugins/editor_preview_plugins.h b/tools/editor/plugins/editor_preview_plugins.h
index b33aefaa23..9807d835a2 100644
--- a/tools/editor/plugins/editor_preview_plugins.h
+++ b/tools/editor/plugins/editor_preview_plugins.h
@@ -31,6 +31,7 @@
#include "tools/editor/editor_resource_preview.h"
+#if 0
class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator {
public:
@@ -123,5 +124,5 @@ public:
~EditorMeshPreviewPlugin();
};
-
+#endif
#endif // EDITORPREVIEWPLUGINS_H
diff --git a/tools/editor/plugins/material_editor_plugin.cpp b/tools/editor/plugins/material_editor_plugin.cpp
index 876fab0d6e..1036016194 100644
--- a/tools/editor/plugins/material_editor_plugin.cpp
+++ b/tools/editor/plugins/material_editor_plugin.cpp
@@ -1,6 +1,8 @@
#include "material_editor_plugin.h"
#include "scene/main/viewport.h"
+#if 0
+
void MaterialEditor::_input_event(InputEvent p_event) {
@@ -379,3 +381,4 @@ MaterialEditorPlugin::~MaterialEditorPlugin()
}
+#endif
diff --git a/tools/editor/plugins/material_editor_plugin.h b/tools/editor/plugins/material_editor_plugin.h
index 49e92493b3..68b3b3b1a7 100644
--- a/tools/editor/plugins/material_editor_plugin.h
+++ b/tools/editor/plugins/material_editor_plugin.h
@@ -8,7 +8,7 @@
#include "scene/3d/mesh_instance.h"
#include "scene/3d/camera.h"
-
+#if 0
class MaterialEditor : public Control {
OBJ_TYPE(MaterialEditor, Control);
@@ -69,3 +69,4 @@ public:
};
#endif // MATERIAL_EDITOR_PLUGIN_H
+#endif
diff --git a/tools/editor/plugins/mesh_editor_plugin.cpp b/tools/editor/plugins/mesh_editor_plugin.cpp
index b70cbad25f..cd7860bcab 100644
--- a/tools/editor/plugins/mesh_editor_plugin.cpp
+++ b/tools/editor/plugins/mesh_editor_plugin.cpp
@@ -28,6 +28,7 @@
/*************************************************************************/
#include "mesh_editor_plugin.h"
+#if 0
void MeshEditor::_input_event(InputEvent p_event) {
@@ -241,3 +242,4 @@ MeshEditorPlugin::MeshEditorPlugin(EditorNode *p_node) {
MeshEditorPlugin::~MeshEditorPlugin()
{
}
+#endif
diff --git a/tools/editor/plugins/mesh_editor_plugin.h b/tools/editor/plugins/mesh_editor_plugin.h
index 0715a96e74..97fd9ae771 100644
--- a/tools/editor/plugins/mesh_editor_plugin.h
+++ b/tools/editor/plugins/mesh_editor_plugin.h
@@ -29,6 +29,8 @@
#ifndef MESH_EDITOR_PLUGIN_H
#define MESH_EDITOR_PLUGIN_H
+#if 0
+
#include "tools/editor/editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "scene/resources/material.h"
@@ -93,3 +95,4 @@ public:
};
#endif // MESH_EDITOR_PLUGIN_H
+#endif
diff --git a/tools/editor/plugins/particles_2d_editor_plugin.cpp b/tools/editor/plugins/particles_2d_editor_plugin.cpp
index ce25f34c1f..4d93f2019e 100644
--- a/tools/editor/plugins/particles_2d_editor_plugin.cpp
+++ b/tools/editor/plugins/particles_2d_editor_plugin.cpp
@@ -69,8 +69,8 @@ void Particles2DEditorPlugin::_file_selected(const String& p_file) {
ERR_EXPLAIN(TTR("Error loading image:")+" "+p_file);
ERR_FAIL_COND(err!=OK);
- img.convert(Image::FORMAT_GRAYSCALE_ALPHA);
- ERR_FAIL_COND(img.get_format()!=Image::FORMAT_GRAYSCALE_ALPHA);
+ img.convert(Image::FORMAT_LA8);
+ ERR_FAIL_COND(img.get_format()!=Image::FORMAT_LA8);
Size2i s = Size2(img.get_width(),img.get_height());
ERR_FAIL_COND(s.width==0 || s.height==0);
diff --git a/tools/editor/plugins/particles_editor_plugin.cpp b/tools/editor/plugins/particles_editor_plugin.cpp
index 7e20cc3f54..d8330c4b0c 100644
--- a/tools/editor/plugins/particles_editor_plugin.cpp
+++ b/tools/editor/plugins/particles_editor_plugin.cpp
@@ -26,6 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
+#if 0
#include "particles_editor_plugin.h"
#include "io/resource_loader.h"
#include "servers/visual/particle_system_sw.h"
@@ -456,3 +458,4 @@ ParticlesEditorPlugin::~ParticlesEditorPlugin()
}
+#endif
diff --git a/tools/editor/plugins/particles_editor_plugin.h b/tools/editor/plugins/particles_editor_plugin.h
index ff80bffc29..eec01d03a1 100644
--- a/tools/editor/plugins/particles_editor_plugin.h
+++ b/tools/editor/plugins/particles_editor_plugin.h
@@ -37,7 +37,7 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
+#if 0
class ParticlesEditor : public Control {
OBJ_TYPE(ParticlesEditor, Control );
@@ -113,3 +113,4 @@ public:
};
#endif // PARTICLES_EDITOR_PLUGIN_H
+#endif
diff --git a/tools/editor/plugins/path_editor_plugin.cpp b/tools/editor/plugins/path_editor_plugin.cpp
index 33ef71efab..aa7071298a 100644
--- a/tools/editor/plugins/path_editor_plugin.cpp
+++ b/tools/editor/plugins/path_editor_plugin.cpp
@@ -31,6 +31,7 @@
#include "scene/resources/curve.h"
#include "os/keyboard.h"
+#if 0
String PathSpatialGizmo::get_handle_name(int p_idx) const {
Ref<Curve3D> c = path->get_curve();
@@ -593,3 +594,4 @@ PathEditorPlugin::~PathEditorPlugin()
{
}
+#endif
diff --git a/tools/editor/plugins/path_editor_plugin.h b/tools/editor/plugins/path_editor_plugin.h
index 0afd957af7..ee2196b47f 100644
--- a/tools/editor/plugins/path_editor_plugin.h
+++ b/tools/editor/plugins/path_editor_plugin.h
@@ -32,6 +32,7 @@
#include "tools/editor/spatial_editor_gizmos.h"
#include "scene/3d/path.h"
+# if 0
class PathSpatialGizmo : public EditorSpatialGizmo {
OBJ_TYPE(PathSpatialGizmo,EditorSpatialGizmo);
@@ -95,5 +96,5 @@ public:
};
-
+#endif
#endif // PATH_EDITOR_PLUGIN_H
diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.cpp b/tools/editor/plugins/polygon_2d_editor_plugin.cpp
index 19d1ccc06f..cd19a908a8 100644
--- a/tools/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/tools/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -850,7 +850,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
uv_edit = memnew( AcceptDialog );
add_child(uv_edit);
uv_edit->set_title(TTR("Polygon 2D UV Editor"));
- uv_edit->set_self_opacity(0.9);
+ uv_edit->set_self_modulate(Color(1,1,1,0.9));
VBoxContainer *uv_main_vb = memnew( VBoxContainer );
uv_edit->add_child(uv_main_vb);
diff --git a/tools/editor/plugins/sample_editor_plugin.cpp b/tools/editor/plugins/sample_editor_plugin.cpp
index 7965fa54ae..5bdd7c4e61 100644
--- a/tools/editor/plugins/sample_editor_plugin.cpp
+++ b/tools/editor/plugins/sample_editor_plugin.cpp
@@ -311,7 +311,7 @@ void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<Imag
imgdata = DVector<uint8_t>::Write();
- p_texture->set_data(Image(w,h,0,Image::FORMAT_RGB,img));
+ p_texture->set_data(Image(w,h,0,Image::FORMAT_RGB8,img));
}
@@ -392,7 +392,7 @@ SampleEditor::SampleEditor() {
add_child(stop);
peakdisplay=Ref<ImageTexture>( memnew( ImageTexture) );
- peakdisplay->create( EDITOR_DEF("audio/sample_editor_preview_width",512),EDITOR_DEF("audio/sample_editor_preview_height",128),Image::FORMAT_RGB);
+ peakdisplay->create( EDITOR_DEF("audio/sample_editor_preview_width",512),EDITOR_DEF("audio/sample_editor_preview_height",128),Image::FORMAT_RGB8);
sample_texframe->set_expand(true);
sample_texframe->set_texture(peakdisplay);
diff --git a/tools/editor/plugins/sample_library_editor_plugin.cpp b/tools/editor/plugins/sample_library_editor_plugin.cpp
index 2a6940332c..ade0c475e1 100644
--- a/tools/editor/plugins/sample_library_editor_plugin.cpp
+++ b/tools/editor/plugins/sample_library_editor_plugin.cpp
@@ -236,7 +236,7 @@ void SampleLibraryEditor::_update_library() {
// Preview/edit
Ref<ImageTexture> preview( memnew( ImageTexture ));
- preview->create(128,16,Image::FORMAT_RGB);
+ preview->create(128,16,Image::FORMAT_RGB8);
SampleEditor::generate_preview_texture(smp,preview);
ti->set_cell_mode(1,TreeItem::CELL_MODE_ICON);
ti->set_selectable(1,false);
diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp
index b3317e8313..5541ae987f 100644
--- a/tools/editor/plugins/shader_editor_plugin.cpp
+++ b/tools/editor/plugins/shader_editor_plugin.cpp
@@ -38,7 +38,7 @@
#include "tools/editor/property_editor.h"
#include "os/os.h"
-
+#if 0
/*** SETTINGS EDITOR ****/
@@ -654,3 +654,4 @@ ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node, bool p_2d) {
ShaderEditorPlugin::~ShaderEditorPlugin() {
}
+#endif
diff --git a/tools/editor/plugins/shader_editor_plugin.h b/tools/editor/plugins/shader_editor_plugin.h
index 9219a1fbc2..ef7cc6772e 100644
--- a/tools/editor/plugins/shader_editor_plugin.h
+++ b/tools/editor/plugins/shader_editor_plugin.h
@@ -38,7 +38,7 @@
#include "scene/resources/shader.h"
#include "servers/visual/shader_language.h"
-
+#if 0
class ShaderTextEditor : public CodeTextEditor {
OBJ_TYPE( ShaderTextEditor, CodeTextEditor );
@@ -154,4 +154,6 @@ public:
~ShaderEditorPlugin();
};
+
+#endif
#endif
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp
index 3ab906f84e..f864c6885f 100644
--- a/tools/editor/plugins/shader_graph_editor_plugin.cpp
+++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp
@@ -28,6 +28,7 @@
/*************************************************************************/
#include "shader_graph_editor_plugin.h"
+#if 0
#include "scene/gui/check_box.h"
#include "scene/gui/menu_button.h"
@@ -1377,7 +1378,7 @@ ToolButton *ShaderGraphView::make_editor(String text,GraphNode* gn,int p_id,int
edit->set_icon(ped_popup->get_icon("Matrix", "EditorIcons"));
break;
case Variant::COLOR: {
- Image icon_color = Image(15,15,false,Image::FORMAT_RGB);
+ Image icon_color = Image(15,15,false,Image::FORMAT_RGB8);
Color c = graph->default_get_value(type,p_id,param);
for (int x=1;x<14;x++)
for (int y=1;y<14;y++)
@@ -2945,3 +2946,4 @@ ShaderGraphEditorPlugin::~ShaderGraphEditorPlugin()
+#endif
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h
index 67ee5e2d45..dafafdd1c8 100644
--- a/tools/editor/plugins/shader_graph_editor_plugin.h
+++ b/tools/editor/plugins/shader_graph_editor_plugin.h
@@ -43,7 +43,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-
+#if 0
class GraphColorRampEdit : public Control {
OBJ_TYPE(GraphColorRampEdit,Control);
@@ -239,4 +239,4 @@ public:
};
#endif
-
+#endif
diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp
index 9701b8030d..afea6f93dd 100644
--- a/tools/editor/plugins/spatial_editor_plugin.cpp
+++ b/tools/editor/plugins/spatial_editor_plugin.cpp
@@ -274,7 +274,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b
Vector3 ray=_get_ray(p_pos);
Vector3 pos=_get_ray_pos(p_pos);
- Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() );
+ Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() );
Set<Ref<SpatialEditorGizmo> > found_gizmos;
//uint32_t closest=0;
@@ -286,8 +286,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b
for (int i=0;i<instances.size();i++) {
- uint32_t id=VisualServer::get_singleton()->instance_get_object_instance_ID(instances[i]);
- Object *obj=ObjectDB::get_instance(id);
+ Object *obj=ObjectDB::get_instance(instances[i]);
if (!obj)
continue;
@@ -405,15 +404,15 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2& p_pos,bool &r_inclu
Vector3 ray=_get_ray(p_pos);
Vector3 pos=_get_ray_pos(p_pos);
- Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() );
+ Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() );
Set<Ref<SpatialEditorGizmo> > found_gizmos;
r_includes_current=false;
for (int i=0;i<instances.size();i++) {
- uint32_t id=VisualServer::get_singleton()->instance_get_object_instance_ID(instances[i]);
- Object *obj=ObjectDB::get_instance(id);
+ Object *obj=ObjectDB::get_instance(instances[i]);
+
if (!obj)
continue;
@@ -534,14 +533,12 @@ void SpatialEditorViewport::_select_region() {
frustum.push_back( far );
- Vector<RID> instances=VisualServer::get_singleton()->instances_cull_convex(frustum,get_tree()->get_root()->get_world()->get_scenario());
+ Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_convex(frustum,get_tree()->get_root()->get_world()->get_scenario());
for (int i=0;i<instances.size();i++) {
- uint32_t id=VisualServer::get_singleton()->instance_get_object_instance_ID(instances[i]);
-
- Object *obj=ObjectDB::get_instance(id);
+ Object *obj=ObjectDB::get_instance(instances[i]);
if (!obj)
continue;
Spatial *sp = obj->cast_to<Spatial>();
@@ -877,7 +874,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
if (b.mod.control) {
- Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(ray_origin,ray_dir,get_tree()->get_root()->get_world()->get_scenario() );
+ Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(ray_origin,ray_dir,get_tree()->get_root()->get_world()->get_scenario() );
Plane p(ray_origin,_get_camera_normal());
@@ -886,8 +883,9 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
for (int i=0;i<instances.size();i++) {
- uint32_t id=VisualServer::get_singleton()->instance_get_object_instance_ID(instances[i]);
- Object *obj=ObjectDB::get_instance(id);
+
+ Object *obj=ObjectDB::get_instance(instances[i]);
+
if (!obj)
continue;
@@ -2061,9 +2059,9 @@ void SpatialEditorViewport::_menu_option(int p_option) {
bool current = view_menu->get_popup()->is_item_checked( idx );
current=!current;
if (current)
- camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_EDIT_LAYER)|(1<<GIZMO_GRID_LAYER) );
+ camera->set_cull_mask( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_EDIT_LAYER)|(1<<GIZMO_GRID_LAYER) );
else
- camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_GRID_LAYER) );
+ camera->set_cull_mask( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_GRID_LAYER) );
view_menu->get_popup()->set_item_checked( idx, current );
} break;
@@ -2361,7 +2359,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
surface->set_area_as_parent_rect();
camera = memnew(Camera);
camera->set_disable_gizmo(true);
- camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+p_index))|(1<<GIZMO_EDIT_LAYER)|(1<<GIZMO_GRID_LAYER) );
+ camera->set_cull_mask( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+p_index))|(1<<GIZMO_EDIT_LAYER)|(1<<GIZMO_GRID_LAYER) );
//camera->set_environment(SpatialEditor::get_singleton()->get_viewport_environment());
viewport->add_child(camera);
camera->make_current();
@@ -2370,7 +2368,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
view_menu = memnew( MenuButton );
surface->add_child(view_menu);
view_menu->set_pos( Point2(4,4));
- view_menu->set_self_opacity(0.5);
+ view_menu->set_self_modulate(Color(1,1,1,0.5));
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/top_view"), VIEW_TOP);
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/bottom_view"), VIEW_BOTTOM);
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/left_view"), VIEW_LEFT);
@@ -2550,10 +2548,10 @@ void SpatialEditor::_generate_selection_box() {
}
Ref<FixedMaterial> mat = memnew( FixedMaterial );
- mat->set_flag(Material::FLAG_UNSHADED,true);
+ /*mat->set_flag(Material::FLAG_UNSHADED,true);
mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1));
mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true);
- mat->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true);
+ mat->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true);*/
st->set_material(mat);
selection_box = st->commit();
}
@@ -2685,14 +2683,14 @@ void SpatialEditor::set_state(const Dictionary& p_state) {
}
if (d.has("ambient_light_color")) {
settings_ambient_color->set_color(d["ambient_light_color"]);
- viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,d["ambient_light_color"]);
+ //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,d["ambient_light_color"]);
}
if (d.has("default_srgb")) {
bool use = d["default_srgb"];
- viewport_environment->set_enable_fx(Environment::FX_SRGB,use);
- view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB), use );
+ //viewport_environment->set_enable_fx(Environment::FX_SRGB,use);
+ //view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB), use );
}
if (d.has("show_grid")) {
bool use = d["show_grid"];
@@ -2892,9 +2890,9 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
bool is_checked = view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(p_option) );
if (is_checked) {
- viewport_environment->set_enable_fx(Environment::FX_SRGB,false);
+ //viewport_environment->set_enable_fx(Environment::FX_SRGB,false);
} else {
- viewport_environment->set_enable_fx(Environment::FX_SRGB,true);
+ //viewport_environment->set_enable_fx(Environment::FX_SRGB,true);
}
is_checked = ! is_checked;
@@ -3140,11 +3138,11 @@ void SpatialEditor::_init_indicators() {
{
- indicator_mat = VisualServer::get_singleton()->fixed_material_create();
- VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_UNSHADED, true );
+ indicator_mat = VisualServer::get_singleton()->material_create();
+ /*VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_UNSHADED, true );
VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_ONTOP, false );
VisualServer::get_singleton()->fixed_material_set_flag(indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA,true);
- VisualServer::get_singleton()->fixed_material_set_flag(indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
+ VisualServer::get_singleton()->fixed_material_set_flag(indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);*/
DVector<Color> grid_colors[3];
DVector<Vector3> grid_points[3];
@@ -3186,7 +3184,7 @@ void SpatialEditor::_init_indicators() {
d.resize(VS::ARRAY_MAX);
d[VisualServer::ARRAY_VERTEX]=grid_points[i];
d[VisualServer::ARRAY_COLOR]=grid_colors[i];
- VisualServer::get_singleton()->mesh_add_surface(grid[i],VisualServer::PRIMITIVE_LINES,d);
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i],VisualServer::PRIMITIVE_LINES,d);
VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat);
grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i],get_tree()->get_root()->get_world()->get_scenario());
@@ -3205,7 +3203,7 @@ void SpatialEditor::_init_indicators() {
d[VisualServer::ARRAY_VERTEX]=origin_points;
d[VisualServer::ARRAY_COLOR]=origin_colors;
- VisualServer::get_singleton()->mesh_add_surface(origin,VisualServer::PRIMITIVE_LINES,d);
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(origin,VisualServer::PRIMITIVE_LINES,d);
VisualServer::get_singleton()->mesh_surface_set_material(origin,0,indicator_mat);
@@ -3237,16 +3235,16 @@ void SpatialEditor::_init_indicators() {
cursor_points.push_back(Vector3(0,-cs,0));
cursor_points.push_back(Vector3(0,0,+cs));
cursor_points.push_back(Vector3(0,0,-cs));
- cursor_material=VisualServer::get_singleton()->fixed_material_create();
- VisualServer::get_singleton()->fixed_material_set_param(cursor_material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0,1,1));
+ cursor_material=VisualServer::get_singleton()->material_create();
+ /*VisualServer::get_singleton()->fixed_material_set_param(cursor_material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0,1,1));
VisualServer::get_singleton()->material_set_flag( cursor_material, VisualServer::MATERIAL_FLAG_UNSHADED, true );
VisualServer::get_singleton()->fixed_material_set_flag(cursor_material, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA,true);
- VisualServer::get_singleton()->fixed_material_set_flag(cursor_material, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
+ VisualServer::get_singleton()->fixed_material_set_flag(cursor_material, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);*/
Array d;
d.resize(VS::ARRAY_MAX);
d[VS::ARRAY_VERTEX]=cursor_points;
- VisualServer::get_singleton()->mesh_add_surface(cursor_mesh,VS::PRIMITIVE_LINES,d);
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(cursor_mesh,VS::PRIMITIVE_LINES,d);
VisualServer::get_singleton()->mesh_surface_set_material(cursor_mesh,0,cursor_material);
cursor_instance = VisualServer::get_singleton()->instance_create2(cursor_mesh,get_tree()->get_root()->get_world()->get_scenario());
@@ -3266,10 +3264,10 @@ void SpatialEditor::_init_indicators() {
float gizmo_alph = EditorSettings::get_singleton()->get("3d_editor/manipulator_gizmo_opacity");
gizmo_hl = Ref<FixedMaterial>( memnew( FixedMaterial ) );
- gizmo_hl->set_flag(Material::FLAG_UNSHADED, true);
+ /* gizmo_hl->set_flag(Material::FLAG_UNSHADED, true);
gizmo_hl->set_flag(Material::FLAG_ONTOP, true);
gizmo_hl->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true);
- gizmo_hl->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1,gizmo_alph+0.2f));
+ gizmo_hl->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1,gizmo_alph+0.2f));*/
for(int i=0;i<3;i++) {
@@ -3278,13 +3276,13 @@ void SpatialEditor::_init_indicators() {
Ref<FixedMaterial> mat = memnew( FixedMaterial );
- mat->set_flag(Material::FLAG_UNSHADED, true);
+ /* mat->set_flag(Material::FLAG_UNSHADED, true);
mat->set_flag(Material::FLAG_ONTOP, true);
mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true);
Color col;
col[i]=1.0;
col.a= gizmo_alph;
- mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,col);
+ mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,col);*/
gizmo_color[i]=mat;
@@ -3548,7 +3546,7 @@ void SpatialEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
- gizmos = memnew( SpatialEditorGizmos );
+ //gizmos = memnew( SpatialEditorGizmos );
_init_indicators();
_update_default_light_angle();
}
@@ -3556,7 +3554,7 @@ void SpatialEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_EXIT_TREE) {
_finish_indicators();
- memdelete( gizmos );
+// memdelete( gizmos );
}
}
@@ -3602,7 +3600,7 @@ void SpatialEditor::_request_gizmo(Object* p_obj) {
}
if (!seg.is_valid()) {
- seg = gizmos->get_gizmo(sp);
+ // seg = gizmos->get_gizmo(sp);
}
if (seg.is_valid()) {
@@ -3724,7 +3722,7 @@ void SpatialEditor::clear() {
settings_default_light_rot_x=Math_PI*0.3;
settings_default_light_rot_y=Math_PI*0.2;
- viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15));
+ //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15));
settings_ambient_color->set_color(Color(0.15,0.15,0.15));
if (!light_instance.is_valid())
_menu_item_pressed(MENU_VIEW_USE_DEFAULT_LIGHT);
@@ -3737,7 +3735,7 @@ void SpatialEditor::clear() {
void SpatialEditor::_update_ambient_light_color(const Color& p_color) {
- viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color());
+// viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color());
}
@@ -4006,8 +4004,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
settings_vbc->add_margin_child(TTR("Ambient Light Color:"),settings_ambient_color);
settings_ambient_color->connect("color_changed",this,"_update_ambient_light_color");
- viewport_environment->set_enable_fx(Environment::FX_AMBIENT_LIGHT,true);
- viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15));
+// viewport_environment->set_enable_fx(Environment::FX_AMBIENT_LIGHT,true);
+// viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15));
settings_ambient_color->set_color(Color(0.15,0.15,0.15));
diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h
index 975092a01d..2a52eab777 100644
--- a/tools/editor/plugins/spatial_editor_plugin.h
+++ b/tools/editor/plugins/spatial_editor_plugin.h
@@ -467,7 +467,7 @@ private:
static SpatialEditor *singleton;
void _node_removed(Node* p_node);
- SpatialEditorGizmos *gizmos;
+ //SpatialEditorGizmos *gizmos;
SpatialEditor();
void _update_ambient_light_color(const Color& p_color);
diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp
index 18a4e845a0..4f6f624b1e 100644
--- a/tools/editor/project_manager.cpp
+++ b/tools/editor/project_manager.cpp
@@ -870,7 +870,7 @@ void ProjectManager::_load_recent_projects() {
TextureButton *favorite = memnew( TextureButton );
favorite->set_normal_texture(favorite_icon);
if (!is_favorite)
- favorite->set_opacity(0.2);
+ favorite->set_modulate(Color(1,1,1,0.2));
favorite->set_v_size_flags(SIZE_EXPAND);
favorite->connect("pressed",this,"_favorite_pressed",varray(hb));
favorite_box->add_child(favorite);
@@ -891,7 +891,7 @@ void ProjectManager::_load_recent_projects() {
vb->add_child(title);
Label *fpath = memnew( Label(path) );
vb->add_child(fpath);
- fpath->set_opacity(0.5);
+ fpath->set_modulate(Color(1,1,1,0.5));
fpath->add_color_override("font_color",font_color);
scroll_childs->add_child(hb);
diff --git a/tools/editor/pvrtc_compress.cpp b/tools/editor/pvrtc_compress.cpp
index 75b5c69bc2..bda06e1706 100644
--- a/tools/editor/pvrtc_compress.cpp
+++ b/tools/editor/pvrtc_compress.cpp
@@ -85,7 +85,7 @@ static void _compress_image(Image::CompressMode p_mode,Image *p_image) {
if (EditorSettings::get_singleton()->get("PVRTC/fast_conversion").operator bool()) {
args.push_back("-pvrtcfast");
}
- if (p_image->get_mipmaps()>0)
+ if (p_image->has_mipmaps())
args.push_back("-m");
Ref<ImageTexture> t = memnew( ImageTexture );
diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp
index 53bfe8cc57..fdcced2fa6 100644
--- a/tools/editor/scene_tree_editor.cpp
+++ b/tools/editor/scene_tree_editor.cpp
@@ -953,7 +953,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2& p_point,Control* p_from)
Label *label = memnew( Label( selected[i]->get_name() ) );
hb->add_child(label);
vb->add_child(hb);
- hb->set_opacity(opacity_item);
+ hb->set_modulate(Color(1,1,1,opacity_item));
opacity_item -= opacity_step;
}
NodePath p = selected[i]->get_path();
diff --git a/tools/editor/spatial_editor_gizmos.cpp b/tools/editor/spatial_editor_gizmos.cpp
index 84803eb6db..716b03b7b7 100644
--- a/tools/editor/spatial_editor_gizmos.cpp
+++ b/tools/editor/spatial_editor_gizmos.cpp
@@ -41,6 +41,8 @@
// Keep small children away from this file.
// It's so ugly it will eat them alive
+#if 0
+
#define HANDLE_HALF_SIZE 0.05
void EditorSpatialGizmo::clear() {
@@ -3198,3 +3200,4 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
}
+#endif
diff --git a/tools/editor/spatial_editor_gizmos.h b/tools/editor/spatial_editor_gizmos.h
index 3d7272f522..a7a6af4b18 100644
--- a/tools/editor/spatial_editor_gizmos.h
+++ b/tools/editor/spatial_editor_gizmos.h
@@ -52,7 +52,7 @@
class Camera;
-
+#if 0
class EditorSpatialGizmo : public SpatialEditorGizmo {
OBJ_TYPE(EditorSpatialGizmo,SpatialGizmo);
@@ -505,5 +505,5 @@ public:
SpatialEditorGizmos();
};
-
+#endif
#endif // SPATIAL_EDITOR_GIZMOS_H