diff options
Diffstat (limited to 'servers/visual')
-rw-r--r-- | servers/visual/rasterizer.h | 6 | ||||
-rw-r--r-- | servers/visual/rasterizer_dummy.cpp | 3 | ||||
-rw-r--r-- | servers/visual/rasterizer_dummy.h | 2 | ||||
-rw-r--r-- | servers/visual/shader_compiler.cpp | 30 | ||||
-rw-r--r-- | servers/visual/shader_compiler.h | 142 | ||||
-rw-r--r-- | servers/visual/shader_graph.cpp | 455 | ||||
-rw-r--r-- | servers/visual/shader_graph.h | 109 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 41 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.h | 16 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.h | 4 |
10 files changed, 55 insertions, 753 deletions
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index e3d1b14835..50ec6792cc 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -542,6 +542,7 @@ public: RID skeleton; RID material_override; RID sampled_light; + Vector<RID> materials; Vector<RID> light_instances; Vector<float> morph_values; BakedLightData *baked_light; @@ -701,6 +702,7 @@ public: struct CommandStyle : public Command { Rect2 rect; + Rect2 source; RID texture; float margin[4]; bool draw_center; @@ -943,12 +945,12 @@ public: virtual void canvas_disable_blending()=0; virtual void canvas_set_opacity(float p_opacity)=0; virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode)=0; - virtual void canvas_begin_rect(const Matrix32& p_transform)=0;; + virtual void canvas_begin_rect(const Matrix32& p_transform)=0; virtual void canvas_set_clip(bool p_clip, const Rect2& p_rect)=0; virtual void canvas_end_rect()=0; virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width)=0; virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate)=0; - virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1))=0; + 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))=0; 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)=0; 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; diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp index 3b12b503dd..0e71d224d5 100644 --- a/servers/visual/rasterizer_dummy.cpp +++ b/servers/visual/rasterizer_dummy.cpp @@ -1627,7 +1627,7 @@ void RasterizerDummy::canvas_draw_rect(const Rect2& p_rect, int p_flags, const R } -void RasterizerDummy::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margin, bool p_draw_center,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) { } @@ -1959,4 +1959,3 @@ RasterizerDummy::RasterizerDummy() { RasterizerDummy::~RasterizerDummy() { }; - diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h index 674c165966..ac320e55f9 100644 --- a/servers/visual/rasterizer_dummy.h +++ b/servers/visual/rasterizer_dummy.h @@ -708,7 +708,7 @@ public: virtual void canvas_end_rect(); virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width); virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate); - virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); + virtual void canvas_draw_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); diff --git a/servers/visual/shader_compiler.cpp b/servers/visual/shader_compiler.cpp deleted file mode 100644 index ee5dae5ae2..0000000000 --- a/servers/visual/shader_compiler.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************/ -/* shader_compiler.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_compiler.h" - diff --git a/servers/visual/shader_compiler.h b/servers/visual/shader_compiler.h deleted file mode 100644 index 29561b2145..0000000000 --- a/servers/visual/shader_compiler.h +++ /dev/null @@ -1,142 +0,0 @@ -/*************************************************************************/ -/* shader_compiler.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_COMPILER_H -#define SHADER_COMPILER_H - -#include "map.h" -#include "list.h" -#include "vector.h" -#if 0 -class ShaderSyntax { -public: - - - enum DataType { - TYPE_BOOL, - TYPE_FLOAT, - TYPE_VEC3, - TYPE_TRANSFORM, - TYPE_TEXTURE - }; - - enum Operator { - OP_ASSIGN, - OP_ADD, - OP_SUB, - OP_MUL, - OP_DIV, - OP_NEG, - OP_CMP_EQ, - OP_CMP_NEQ, - OP_CMP_LEQ, - OP_CMP_GEQ, - OP_CMP_OR, - OP_CMP_AND, - OP_CALL - }; - - struct Node { - - enum Type { - TYPE_PROGRAM, - TYPE_FUNCTION, - TYPE_BLOCK, - TYPE_VARIABLE, - TYPE_OPERATOR, - TYPE_IF, - }; - - Node * parent; - Type type; - - virtual ~Node() {} - }; - - - struct OperatorNode : public Node { - - Operator op; - Vector<Node*> arguments; - OperatorNode() { type=TYPE_OPERATOR; } - }; - - struct VariableNode : public Node { - - StringName variable; - VariableNode() { type=TYPE_VARIABLE; } - }; - - struct BlockNode : public Node { - - Map<StringName,DataType> variables; - List<Node*> subnodes; - BlockNode() { type=TYPE_BLOCK; } - }; - - struct ConditionalNode : public Node { - - Node *test; - Node *do_if; - Node *do_else; - ConditionalNode() { type=TYPE_CONDITIONAL; } - }; - - - struct FunctionNode : public Node { - - struct Argument { - - StringName name; - DataType type; - }; - - Vector<Argument> arguments; - Node *body; - - FunctionNode() { type=TYPE_FUNCTION; } - - }; - - - struct ProgramNode : public Node { - - Vector<FunctionNode*> functions; - Node *body; - - ProgramNode() { type=TYPE_PROGRAM; } - }; - - - - - ShaderCompiler(); -}; - -#endif // SHADER_COMPILER_H -#endif diff --git a/servers/visual/shader_graph.cpp b/servers/visual/shader_graph.cpp deleted file mode 100644 index 7fe949bec3..0000000000 --- a/servers/visual/shader_graph.cpp +++ /dev/null @@ -1,455 +0,0 @@ -/*************************************************************************/ -/* shader_graph.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_graph.h" - -#if 0 - - -struct _ConnectionKey { - - int node; - int slot; - - _FORCE_INLINE_ _ConnectionKey(int p_node=0,int p_slot=0) { node=p_node; slot=p_slot; } - - _FORCE_INLINE_ bool operator<(const _ConnectionKey& p_other) const { - - if (node<p_other.node) - return true; - else if (node>p_other.node) - return false; - else - return slot<p_other.slot; - } -}; - -Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { - - Map<int,Node>::Element *E = node_map.front(); - int i=0; - while(E) { - - E->get().order=i++; - E->get().out_valid=false; - E->get().in_valid=false; - E=E->next(); - } - - int worst_case=connections.size() * connections.size(); // worst bubble case - int iterations=0; - int swaps; - - do { - swaps=0; - const List<Connection>::Element *E=connections.front(); - - while(E) { - - const Connection &c = E->get(); - - const Node *src = &node_map[c.src_id]; - const Node *dst = &node_map[c.dst_id]; - - if (src->order > dst->order) { - - SWAP(src->order, dst->order); - swaps++; - } - - E=E->next(); - } - - - iterations++; - - } while (iterations<=worst_case && swaps>0); - - ERR_FAIL_COND_V( swaps != 0 , ERR_CYCLIC_LINK ); - - //node array - Vector<const Node*> nodes; - nodes.resize(node_map.size()); - - E = node_map.front(); - while(E) { - - ERR_FAIL_INDEX_V( E->get().order, nodes.size(), ERR_BUG); - nodes[E->get().order]=&E->get(); - E=E->next(); - } - - //connection set - - Map<_ConnectionKey,int> in_connection_map; - Map<_ConnectionKey,List<int> > out_connection_map; - Map<_ConnectionKey,int> in_node_map; - Map<_ConnectionKey,List<int> > out_node_map; - - const List<Connection>::Element *CE=connections.front(); - i=0; - while(CE) { - const Connection &c = CE->get(); - - _ConnectionKey in_k; - in_k.node=node_map[c.dst_id].order; - in_k.slot=c.dst_slot; - in_connection_map[in_k]=i; - in_node_map[in_k]=node_map[c.src_id].order; - - _ConnectionKey out_k; - out_k.node=node_map[c.src_id].order; - out_k.slot=c.src_slot; - if (!out_connection_map.has(out_k)) - out_connection_map[out_k]=List<int>(); - out_connection_map[out_k].push_back(i); - if(!out_node_map.has(out_k)) - out_node_map[out_k]=List<int>(); - out_node_map[out_k].push_back(node_map[c.dst_id].order); - - i++; - CE=CE->next(); - } - - // validate nodes if they are connected to an output - - for(int i=nodes.size()-1;i>=0;i--) { - - if (VisualServer::shader_get_output_count(nodes[i]->type)==0) { - // an actual graph output - - _ConnectionKey in_k; - in_k.node=nodes[i]->order; - in_k.slot=0; - - if (in_node_map.has(in_k)) { - nodes[i]->out_valid=true; - } - } else { - // regular node - - bool valid=false; - for(int j=0;j<VS::shader_get_output_count(nodes[i]->type);j++) { - - _ConnectionKey key(nodes[i]->order,j); - - if (out_node_map.has(key)) { - for(List<int>::Element *CE=out_node_map[key].front();CE;CE=CE->next()) { - - int to_node=CE->get(); - ERR_CONTINUE(to_node<0 || to_node >=nodes.size()); - if (nodes[to_node]->out_valid) { - valid=true; - break; - } - - - } - } - if (valid) - break; - - } - - nodes[i]->out_valid=valid; - } - } - - // validate nodes if they are connected to an input - - for(int i=0;i<nodes.size();i++) { - - if (VisualServer::shader_get_input_count(nodes[i]->type)==0) { - // an actual graph input - - int out_count=VisualServer::shader_get_output_count(nodes[i]->type); - - - for(int j=0;j<out_count;j++) { - - _ConnectionKey out_k; - out_k.node=nodes[i]->order; - out_k.slot=j; - if (out_node_map.has(out_k)) { - nodes[i]->in_valid=true; - break; - } - } - - } else { - // regular node - // this is very important.. for a node to be valid, all its inputs need to be valid - bool valid=true; - for(int j=0;j<VS::shader_get_input_count(nodes[i]->type);j++) { - - - bool in_valid=false; - _ConnectionKey key(nodes[i]->order,j); - if (in_node_map.has(key)) { - - int from_node=in_node_map[key]; - ERR_CONTINUE(from_node<0 || from_node>=nodes.size()); - if (nodes[from_node]->in_valid) - in_valid=true; - - } - - if (!in_valid) { - valid=false; - break; - } - - } - - nodes[i]->in_valid=valid; - } - } - - // write code - - p_generator->begin(); - - for(int i=0;i<nodes.size();i++) { - - - if (!nodes[i]->out_valid || !nodes[i]->in_valid) // valid in both ways - continue; // skip node - - Vector<int> in_indices; - in_indices.resize(VS::shader_get_input_count(nodes[i]->type)); - Vector<int> out_indices; - Vector<int> out_slot_indices; - - for(int j=0;j<in_indices.size();j++) { - - _ConnectionKey key(nodes[i]->order,j); - if (in_connection_map.has(key)) - in_indices[j]=in_connection_map[key]; - else - in_indices[j]=-1; - } - - for(int j=0;j<VS::shader_get_output_count(nodes[i]->type);j++) { - - _ConnectionKey key(nodes[i]->order,j); - if (out_connection_map.has(key)) { - for(List<int>::Element *CE=out_connection_map[key].front();CE;CE=CE->next()) { - - out_indices.push_back(CE->get()); - out_slot_indices.push_back(j); - } - } - } - - Error err = p_generator->add_node(nodes[i]->type,i,nodes[i]->id,nodes[i]->param,in_indices,out_indices,out_slot_indices); - ERR_FAIL_COND_V( err, err ); - } - - p_generator->end(); - - - return OK; -} - -void ShaderGraph::node_add(VS::ShaderNodeType p_type,int p_id) { - - - ERR_FAIL_COND( node_map.has(p_id ) ); - ERR_FAIL_INDEX( p_type, VS::NODE_TYPE_MAX ); - Node node; - - node.type=p_type; - node.id=p_id; - node.x=0; - node.y=0; - - node_map[p_id]=node; - -} - -void ShaderGraph::node_set_pos(int p_id, int p_x,int p_y) { - - ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id].x=p_x; - node_map[p_id].y=p_y; -} -int ShaderGraph::node_get_pos_x(int p_id) const { - - ERR_FAIL_COND_V(!node_map.has(p_id),-1); - return node_map[p_id].x; -} -int ShaderGraph::node_get_pos_y(int p_id) const { - - ERR_FAIL_COND_V(!node_map.has(p_id),-1); - return node_map[p_id].y; -} - -void ShaderGraph::node_remove(int p_id) { - - ERR_FAIL_COND(!node_map.has(p_id)); - - //erase connections associated with node - List<Connection>::Element *N,*E=connections.front(); - while(E) { - N=E->next(); - const Connection &c = E->get(); - if (c.src_id==p_id || c.dst_id==p_id) { - - connections.erase(E); - } - E=N; - } - - node_map.erase(p_id); -} - -void ShaderGraph::node_change_type(int p_id, VS::ShaderNodeType p_type) { - - ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id].type=p_type; - node_map[p_id].param=Variant(); - -} - -void ShaderGraph::node_set_param(int p_id, const Variant& p_value) { - - ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id].param=p_value; -} - -void ShaderGraph::get_node_list(List<int> *p_node_list) const { - - Map<int,Node>::Element *E = node_map.front(); - - while(E) { - - p_node_list->push_back(E->key()); - E=E->next(); - } -} - - -VS::ShaderNodeType ShaderGraph::node_get_type(int p_id) const { - - ERR_FAIL_COND_V(!node_map.has(p_id),VS::NODE_TYPE_MAX); - return node_map[p_id].type; -} - -Variant ShaderGraph::node_get_param(int p_id) const { - - ERR_FAIL_COND_V(!node_map.has(p_id),Variant()); - return node_map[p_id].param; -} - - -Error ShaderGraph::connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) { - - ERR_FAIL_COND_V(p_src_id==p_dst_id, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(!node_map.has(p_src_id), ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(!node_map.has(p_dst_id), ERR_INVALID_PARAMETER); - VisualServer::ShaderNodeType type_src=node_map[p_src_id].type; - VisualServer::ShaderNodeType type_dst=node_map[p_dst_id].type; - ERR_FAIL_INDEX_V( p_src_slot, VisualServer::shader_get_output_count(type_src), ERR_INVALID_PARAMETER ); - ERR_FAIL_INDEX_V( p_dst_slot, VisualServer::shader_get_input_count(type_dst), ERR_INVALID_PARAMETER ); - ERR_FAIL_COND_V(VisualServer::shader_is_output_vector(type_src,p_src_slot) != VisualServer::shader_is_input_vector(type_dst,p_dst_slot), ERR_INVALID_PARAMETER ); - - - List<Connection>::Element *E=connections.front(); - while(E) { - const Connection &c = E->get(); - ERR_FAIL_COND_V(c.dst_slot==p_dst_slot && c.dst_id == p_dst_id, ERR_ALREADY_EXISTS); - - E=E->next(); - } - - Connection c; - c.src_slot=p_src_slot; - c.src_id=p_src_id; - c.dst_slot=p_dst_slot; - c.dst_id=p_dst_id; - - connections.push_back(c); - - return OK; -} - -bool ShaderGraph::is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const { - - const List<Connection>::Element *E=connections.front(); - while(E) { - const Connection &c = E->get(); - if (c.dst_slot==p_dst_slot && c.dst_id == p_dst_id && c.src_slot==p_src_slot && c.src_id == p_src_id) - return true; - - E=E->next(); - } - - return false; -} - -void ShaderGraph::disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) { - - List<Connection>::Element *N,*E=connections.front(); - while(E) { - N=E->next(); - const Connection &c = E->get(); - if (c.src_slot==p_src_slot && c.src_id==p_src_id && c.dst_slot==p_dst_slot && c.dst_id == p_dst_id) { - - connections.erase(E); - } - E=N; - } - - -} - - -void ShaderGraph::clear() { - - connections.clear(); - node_map.clear(); -} - -List<ShaderGraph::Connection> ShaderGraph::get_connection_list() const { - - return connections; - -} - -ShaderGraph::ShaderGraph() { - - -} - - -ShaderGraph::~ShaderGraph() { - -} - - -#endif diff --git a/servers/visual/shader_graph.h b/servers/visual/shader_graph.h deleted file mode 100644 index 41df0f60f1..0000000000 --- a/servers/visual/shader_graph.h +++ /dev/null @@ -1,109 +0,0 @@ -/*************************************************************************/ -/* shader_graph.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. */ -/*************************************************************************/ - -#if 0 - -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - -#include "servers/visual_server.h" -#include "map.h" - - -class ShaderCodeGenerator { -public: - - virtual void begin()=0; - virtual Error add_node(VS::ShaderNodeType p_type,int p_node_pos,int p_id,const Variant& p_param,const Vector<int>& p_in_connections,const Vector<int>& p_out_connections,const Vector<int>& p_out_connection_outputs)=0; - virtual void end()=0; - - virtual ~ShaderCodeGenerator() {} -}; - -class ShaderGraph { -public: - - - struct Connection { - - int src_id; - int src_slot; - int dst_id; - int dst_slot; - }; - -private: - struct Node { - - int16_t x,y; - VS::ShaderNodeType type; - Variant param; - int id; - mutable int order; // used for sorting - mutable bool out_valid; - mutable bool in_valid; - }; - - Map<int,Node> node_map; - - List<Connection> connections; - -public: - - Error generate(ShaderCodeGenerator * p_generator) const; - - void node_add(VS::ShaderNodeType p_type,int p_id); - void node_remove(int p_id); - void node_change_type(int p_id, VS::ShaderNodeType p_type); - void node_set_param(int p_id, const Variant& p_value); - - void node_set_pos(int p_id, int p_x,int p_y); - int node_get_pos_x(int p_id) const; - int node_get_pos_y(int p_id) const; - - void get_node_list(List<int> *p_node_list) const; - void get_sorted_node_list(List<int> *p_node_list) const; - VS::ShaderNodeType node_get_type(int p_id) const; - Variant node_get_param(int p_id) const; - - Error connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); - bool is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const; - void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); - - void clear(); - - List<Connection> get_connection_list() const; - - - ShaderGraph(); - ~ShaderGraph(); - -}; -#endif diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index ad85ecc7c0..532247d94c 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -398,7 +398,7 @@ void VisualServerRaster::mesh_add_custom_surface(RID p_mesh,const Variant& p_dat void VisualServerRaster::mesh_add_surface(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,bool p_alpha_sort) { VS_CHANGED; - _dependency_queue_update(p_mesh,true); + _dependency_queue_update(p_mesh,true,true); rasterizer->mesh_add_surface(p_mesh,p_primitive,p_arrays,p_blend_shapes,p_alpha_sort); } @@ -452,6 +452,7 @@ VisualServer::PrimitiveType VisualServerRaster::mesh_surface_get_primitive_type( void VisualServerRaster::mesh_remove_surface(RID p_mesh,int p_surface){ rasterizer->mesh_remove_surface(p_mesh,p_surface); + _dependency_queue_update(p_mesh,true,true); } int VisualServerRaster::mesh_get_surface_count(RID p_mesh) const{ @@ -480,6 +481,8 @@ void VisualServerRaster::mesh_clear(RID p_mesh) { while(rasterizer->mesh_get_surface_count(p_mesh)) { rasterizer->mesh_remove_surface(p_mesh,0); } + + _dependency_queue_update(p_mesh,true,true); } @@ -2038,7 +2041,7 @@ Variant VisualServerRaster::environment_fx_get_param(RID p_env,EnvironmentFxPara /* SCENARIO API */ -void VisualServerRaster::_dependency_queue_update(RID p_rid,bool p_update_aabb) { +void VisualServerRaster::_dependency_queue_update(RID p_rid,bool p_update_aabb,bool p_update_materials) { Map< RID, Set<RID> >::Element * E = instance_dependency_map.find( p_rid ); @@ -2051,17 +2054,19 @@ void VisualServerRaster::_dependency_queue_update(RID p_rid,bool p_update_aabb) while(I) { Instance *ins = instance_owner.get( I->get() ); - _instance_queue_update( ins , p_update_aabb ); + _instance_queue_update( ins , p_update_aabb, p_update_materials ); I = I->next(); } } -void VisualServerRaster::_instance_queue_update(Instance *p_instance,bool p_update_aabb) { +void VisualServerRaster::_instance_queue_update(Instance *p_instance,bool p_update_aabb,bool p_update_materials) { if (p_update_aabb) p_instance->update_aabb=true; + if (p_update_materials) + p_instance->update_materials=true; if (p_instance->update) return; @@ -2273,6 +2278,7 @@ void VisualServerRaster::instance_set_base(RID p_instance, RID p_base) { } instance->data.morph_values.clear(); + instance->data.materials.clear(); } @@ -2286,6 +2292,7 @@ void VisualServerRaster::instance_set_base(RID p_instance, RID p_base) { if (rasterizer->is_mesh(p_base)) { instance->base_type=INSTANCE_MESH; instance->data.morph_values.resize( rasterizer->mesh_get_morph_target_count(p_base)); + instance->data.materials.resize( rasterizer->mesh_get_surface_count(p_base)); } else if (rasterizer->is_multimesh(p_base)) { instance->base_type=INSTANCE_MULTIMESH; } else if (rasterizer->is_immediate(p_base)) { @@ -2510,6 +2517,16 @@ float VisualServerRaster::instance_get_morph_target_weight(RID p_instance,int p_ return instance->data.morph_values[p_shape]; } +void VisualServerRaster::instance_set_surface_material(RID p_instance,int p_surface, RID p_material) { + + VS_CHANGED; + Instance *instance = instance_owner.get( p_instance ); + ERR_FAIL_COND( !instance); + ERR_FAIL_INDEX( p_surface, instance->data.materials.size() ); + instance->data.materials[p_surface]=p_material; +} + + void VisualServerRaster::instance_set_transform(RID p_instance, const Transform& p_transform) { VS_CHANGED; Instance *instance = instance_owner.get( p_instance ); @@ -3046,6 +3063,7 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { } + if (p_instance->aabb.has_no_surface()) return; @@ -3301,10 +3319,17 @@ void VisualServerRaster::_update_instances() { if (instance->update_aabb) _update_instance_aabb(instance); + if (instance->update_materials) { + if (instance->base_type==INSTANCE_MESH) { + instance->data.materials.resize(rasterizer->mesh_get_surface_count(instance->base_rid)); + } + } + _update_instance(instance); instance->update=false; instance->update_aabb=false; + instance->update_materials=false; instance->update_next=0; } } @@ -3661,8 +3686,11 @@ void VisualServerRaster::canvas_item_add_texture_rect(RID p_item, const Rect2& p rect->modulate=p_modulate; rect->rect=p_rect; rect->flags=0; - if (p_tile) + if (p_tile) { rect->flags|=Rasterizer::CANVAS_RECT_TILE; + rect->flags|=Rasterizer::CANVAS_RECT_REGION; + rect->source=Rect2(0,0,p_rect.size.width,p_rect.size.height); + } if (p_rect.size.x<0) { @@ -3717,7 +3745,7 @@ void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const R } -void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center,const Color& p_modulate) { +void VisualServerRaster::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,const Color& p_modulate) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); @@ -3727,6 +3755,7 @@ void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_re 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; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index cb9e96e284..0480d9f5cb 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -32,7 +32,7 @@ #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" -#include "balloon_allocator.h" +#include "allocators.h" #include "octree.h" /** @@ -160,6 +160,7 @@ class VisualServerRaster : public VisualServer { Scenario *scenario; bool update; bool update_aabb; + bool update_materials; Instance *update_next; InstanceType base_type; @@ -317,6 +318,8 @@ class VisualServerRaster : public VisualServer { draw_range_end=0; extra_margin=0; visible_in_all_rooms=false; + update_aabb=false; + update_materials=false; baked_light=NULL; baked_light_info=NULL; @@ -583,8 +586,8 @@ class VisualServerRaster : public VisualServer { void _portal_disconnect(Instance *p_portal,bool p_cleanup=false); void _portal_attempt_connect(Instance *p_portal); - void _dependency_queue_update(RID p_rid,bool p_update_aabb=false); - _FORCE_INLINE_ void _instance_queue_update(Instance *p_instance,bool p_update_aabb=false); + void _dependency_queue_update(RID p_rid, bool p_update_aabb=false, bool p_update_materials=false); + _FORCE_INLINE_ void _instance_queue_update(Instance *p_instance,bool p_update_aabb=false,bool p_update_materials=false); void _update_instances(); void _update_instance_aabb(Instance *p_instance); void _update_instance(Instance *p_instance); @@ -657,7 +660,7 @@ public: 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); + virtual void texture_set_data(RID p_texture,const Image& p_image,CubeMapSide p_cube_side=CUBEMAP_LEFT); virtual Image texture_get_data(RID p_texture,CubeMapSide p_cube_side=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; @@ -1083,6 +1086,9 @@ public: 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; @@ -1165,7 +1171,7 @@ public: 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, 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_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_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); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 6a42fcc8a6..a97b232c03 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -525,6 +525,8 @@ public: 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); @@ -605,7 +607,7 @@ public: 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 ); - FUNC7(canvas_item_add_style_box,RID, const Rect2& , RID ,const Vector2& ,const Vector2&, bool ,const Color& ); + 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 ); |