Commit: 9f1165c8aa5a83be6b0651838a513f56be38566a
Author: Lukas Tönne
Date:   Tue Dec 22 13:30:17 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB9f1165c8aa5a83be6b0651838a513f56be38566a

New opaque type 'DUPLIS' for storing a dupli list.

This works just like the MESH type, but wraps a ListBase instead of
a DerivedMesh. Using this type the duplis can be generated internally
and returned as a result.

All such data types should be handled in a generalized way eventually.

===================================================================

M       source/blender/blenvm/BVM_types.h
M       source/blender/blenvm/bvm/bvm_eval.cc
M       source/blender/blenvm/bvm/bvm_eval_common.h
M       source/blender/blenvm/bvm/bvm_opcode.h
M       source/blender/blenvm/compile/bvm_codegen.cc
M       source/blender/blenvm/compile/bvm_nodegraph.cc
M       source/blender/blenvm/util/bvm_util_typedesc.h
M       source/blender/makesrna/intern/rna_blenvm.c

===================================================================

diff --git a/source/blender/blenvm/BVM_types.h 
b/source/blender/blenvm/BVM_types.h
index 1291c71..cdafc5a 100644
--- a/source/blender/blenvm/BVM_types.h
+++ b/source/blender/blenvm/BVM_types.h
@@ -45,6 +45,7 @@ typedef enum BVMType {
        BVM_STRING,
        BVM_POINTER,
        BVM_MESH,
+       BVM_DUPLIS,
 } BVMType;
 
 typedef enum BVMBufferType {
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc 
b/source/blender/blenvm/bvm/bvm_eval.cc
index da7d2a9..2c31475 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -140,6 +140,15 @@ static void eval_op_value_mesh(float *stack, StackIndex 
offset)
        stack_store_mesh(stack, offset, CDDM_new(0, 0, 0, 0, 0));
 }
 
+/* Note: dupli data is not explicitly stored on the stack,
+ * this function always creates simply an empty dupli list.
+ */
+static void eval_op_value_duplis(float *stack, StackIndex offset)
+{
+       static ListBase lb = {0};
+       stack_store_duplis(stack, offset, &lb);
+}
+
 static void eval_op_float_to_int(float *stack, StackIndex offset_from, 
StackIndex offset_to)
 {
        float f = stack_load_float(stack, offset_from);
@@ -198,6 +207,20 @@ static void eval_op_release_mesh_ptr(float *stack, 
StackIndex offset)
        stack_store_mesh_ptr(stack, offset, p);
 }
 
+static void eval_op_init_duplis_ptr(float *stack, StackIndex offset, int 
use_count)
+{
+       duplis_ptr p(NULL);
+       p.set_use_count(use_count);
+       stack_store_duplis_ptr(stack, offset, p);
+}
+
+static void eval_op_release_duplis_ptr(float *stack, StackIndex offset)
+{
+       duplis_ptr p = stack_load_duplis_ptr(stack, offset);
+       p.decrement_use_count();
+       stack_store_duplis_ptr(stack, offset, p);
+}
+
 static void eval_op_mix_rgb(float *stack, int mode, StackIndex offset_col_a, 
StackIndex offset_col_b, StackIndex offset_fac, StackIndex offset_r)
 {
        float4 a = stack_load_float4(stack, offset_col_a);
@@ -340,6 +363,11 @@ void EvalContext::eval_instructions(const EvalGlobals 
*globals, const Function *
                                eval_op_value_mesh(stack, offset);
                                break;
                        }
+                       case OP_VALUE_DUPLIS: {
+                               StackIndex offset = 
fn->read_stack_index(&instr);
+                               eval_op_value_duplis(stack, offset);
+                               break;
+                       }
                        case OP_FLOAT_TO_INT: {
                                StackIndex offset_from = 
fn->read_stack_index(&instr);
                                StackIndex offset_to = 
fn->read_stack_index(&instr);
@@ -394,6 +422,17 @@ void EvalContext::eval_instructions(const EvalGlobals 
*globals, const Function *
                                eval_op_release_mesh_ptr(stack, offset);
                                break;
                        }
+                       case OP_INIT_DUPLIS_PTR: {
+                               StackIndex offset = 
fn->read_stack_index(&instr);
+                               int use_count = fn->read_int(&instr);
+                               eval_op_init_duplis_ptr(stack, offset, 
use_count);
+                               break;
+                       }
+                       case OP_RELEASE_DUPLIS_PTR: {
+                               StackIndex offset = 
fn->read_stack_index(&instr);
+                               eval_op_release_duplis_ptr(stack, offset);
+                               break;
+                       }
                        case OP_ADD_FLOAT: {
                                StackIndex offset_a = 
fn->read_stack_index(&instr);
                                StackIndex offset_b = 
fn->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval_common.h 
b/source/blender/blenvm/bvm/bvm_eval_common.h
index 03d6c63..c0ea48f 100644
--- a/source/blender/blenvm/bvm/bvm_eval_common.h
+++ b/source/blender/blenvm/bvm/bvm_eval_common.h
@@ -69,6 +69,11 @@ inline static matrix44 stack_load_matrix44(float *stack, 
StackIndex offset)
        return *(matrix44 *)(&stack[offset]);
 }
 
+inline static const char *stack_load_string(float *stack, StackIndex offset)
+{
+       return *(const char **)(&stack[offset]);
+}
+
 inline static PointerRNA stack_load_pointer(float *stack, StackIndex offset)
 {
        return *(PointerRNA *)(&stack[offset]);
@@ -84,11 +89,18 @@ inline static DerivedMesh *stack_load_mesh(float *stack, 
StackIndex offset)
        return ((mesh_ptr *)(&stack[offset]))->get();
 }
 
-inline static const char *stack_load_string(float *stack, StackIndex offset)
+inline static duplis_ptr stack_load_duplis_ptr(float *stack, StackIndex offset)
 {
-       return *(const char **)(&stack[offset]);
+       return *(duplis_ptr *)(&stack[offset]);
 }
 
+inline static ListBase *stack_load_duplis(float *stack, StackIndex offset)
+{
+       return ((duplis_ptr *)(&stack[offset]))->get();
+}
+
+/* ------------------------------------------------------------------------- */
+
 inline static void stack_store_float(float *stack, StackIndex offset, float f)
 {
        *(float *)(&stack[offset]) = f;
@@ -114,6 +126,11 @@ inline static void stack_store_matrix44(float *stack, 
StackIndex offset, matrix4
        *(matrix44 *)(&stack[offset]) = m;
 }
 
+inline static void stack_store_string(float *stack, StackIndex offset, const 
char *s)
+{
+       *(const char **)(&stack[offset]) = s;
+}
+
 inline static void stack_store_pointer(float *stack, StackIndex offset, 
PointerRNA p)
 {
        *(PointerRNA *)(&stack[offset]) = p;
@@ -129,9 +146,14 @@ inline static void stack_store_mesh(float *stack, 
StackIndex offset, DerivedMesh
        ((mesh_ptr *)(&stack[offset]))->set(dm);
 }
 
-inline static void stack_store_string(float *stack, StackIndex offset, const 
char *s)
+inline static void stack_store_duplis_ptr(float *stack, StackIndex offset, 
duplis_ptr p)
 {
-       *(const char **)(&stack[offset]) = s;
+       *(duplis_ptr *)(&stack[offset]) = p;
+}
+
+inline static void stack_store_duplis(float *stack, StackIndex offset, 
ListBase *lb)
+{
+       ((duplis_ptr *)(&stack[offset]))->set(lb);
 }
 
 } /* namespace bvm */
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h 
b/source/blender/blenvm/bvm/bvm_opcode.h
index 33042ea..fc65540 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -44,6 +44,7 @@ enum OpCode {
        OP_VALUE_STRING,
        OP_VALUE_POINTER,
        OP_VALUE_MESH,
+       OP_VALUE_DUPLIS,
        
        OP_FLOAT_TO_INT,
        OP_INT_TO_FLOAT,
@@ -62,6 +63,8 @@ enum OpCode {
        
        OP_INIT_MESH_PTR,
        OP_RELEASE_MESH_PTR,
+       OP_INIT_DUPLIS_PTR,
+       OP_RELEASE_DUPLIS_PTR,
        
        OP_ADD_FLOAT,
        OP_SUB_FLOAT,
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc 
b/source/blender/blenvm/compile/bvm_codegen.cc
index 1855370..7c18b0e 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -349,6 +349,10 @@ void BVMCompiler::push_constant(const Value *value) const
                        /* MESH type can not be stored as a constant */
                        break;
                }
+               case BVM_DUPLIS: {
+                       /* DUPLIS type can not be stored as a constant */
+                       break;
+               }
        }
 }
 
@@ -420,6 +424,11 @@ void BVMCompiler::codegen_value(const Value *value, 
StackIndex offset) const
                        push_stack_index(offset);
                        break;
                }
+               case BVM_DUPLIS: {
+                       push_opcode(OP_VALUE_DUPLIS);
+                       push_stack_index(offset);
+                       break;
+               }
        }
 }
 
@@ -437,6 +446,8 @@ static OpCode ptr_init_opcode(const TypeDesc &typedesc)
                
                case BVM_MESH:
                        return OP_INIT_MESH_PTR;
+               case BVM_DUPLIS:
+                       return OP_INIT_DUPLIS_PTR;
        }
        return OP_NOOP;
 }
@@ -455,6 +466,8 @@ static OpCode ptr_release_opcode(const TypeDesc &typedesc)
                
                case BVM_MESH:
                        return OP_RELEASE_MESH_PTR;
+               case BVM_DUPLIS:
+                       return OP_RELEASE_DUPLIS_PTR;
        }
        return OP_NOOP;
 }
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc 
b/source/blender/blenvm/compile/bvm_nodegraph.cc
index ae0b9ca..3df64f2 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -605,6 +605,7 @@ SocketPair NodeGraph::add_proxy(const TypeDesc &typedesc, 
Value *default_value)
                                case BVM_STRING: node = 
add_node("PASS_STRING"); break;
                                case BVM_POINTER: node = 
add_node("PASS_POINTER"); break;
                                case BVM_MESH: node = add_node("PASS_MESH"); 
break;
+                               case BVM_DUPLIS: node = 
add_node("PASS_DUPLIS"); break;
                        }
                        break;
                case BVM_BUFFER_ARRAY:
@@ -617,6 +618,7 @@ SocketPair NodeGraph::add_proxy(const TypeDesc &typedesc, 
Value *default_value)
                                case BVM_STRING: node = 
add_node("PASS_STRING_ARRAY"); break;
                                case BVM_POINTER: node = 
add_node("PASS_POINTER_ARRAY"); break;
                                case BVM_MESH: node = 
add_node("PASS_MESH_ARRAY"); break;
+                               case BVM_DUPLIS: node = 
add_node("PASS_DUPLIS_ARRAY"); break;
                        }
                        break;
        }
@@ -637,6 +639,7 @@ SocketPair NodeGraph::add_value_node(Value *value)
                case BVM_STRING: node = add_node("VALUE_STRING"); break;
                case BVM_POINTER: node = add_node("VALUE_POINTER"); break;
                case BVM_MESH: node = add_node("VALUE_MESH"); break;
+               case BVM_DUPLIS: node = add_node("VALUE_DUPLIS"); break;
        }
        if (node)
                node->set_input_value("value", value);
@@ -655,6 +658,7 @@ SocketPair NodeGraph::add_argument_node(const TypeDesc 
&typedesc)
                case BVM_STRING: node = add_node("ARG_STRING"); break;
                case BVM_POINTER: node = add_node("ARG_POINTER"); break;
                case BVM_MESH: node = add_node("ARG_MESH"); break;
+               case BVM_DUPLIS: node = add_node("ARG_DUPLIS"); break;
        }
        return SocketPair(node, "value");
 }
@@ -794,6 +798,7 @@ OpCode get_opcode_from_node_type(const string &node)
        NODETYPE(VALUE_STRING);
        NODETYPE(VALUE_POINTER);
        NODETYPE(VALUE_MESH);
+       NODETYPE(VALUE_DUPLIS);
        
        NODETYPE(FLOAT_TO_INT);
        NODETYPE(INT_TO_FLOAT);
@@ -885,6 +890,8 @@ OpCode get_opcode_from_node_type(const string &node)
 }
 
 static mesh_ptr __empty_mesh__;
+static ListBase __empty_listbase__ = {0};
+static duplis_ptr __empty_duplis__ = duplis_ptr(&__empty_listbase__);
 
 static void register_opcode_node_types()
 {
@@ -930,6 +937,10 @@ static void register_opcode_node_types()
        nt->add_input("value", TYPE_MESH, __empty_mesh__);
        nt->add_output("value", TYPE_MESH);
        
+       nt = NodeGraph::add_pass_node_type("PASS_DUPLIS");
+       nt->add_input("value", TYPE_MESH, __empty_duplis__);
+       nt->add_output("value", TYPE_MESH);
+       
        nt = NodeGraph::add_pass_node_type("PASS_FLOAT_ARRAY");
        nt->add_input("value", TYPE_FLOAT_ARRAY, array<BVM_FLOAT>());
        nt->add_output("value", TYPE_FLOAT_ARRAY);
@@ -962,6 +973,10 @@ static void register_opcode_node_types()
        nt->add_input("value", TYPE_MESH_ARRAY, array<BVM_MESH>());
        nt->add_output("value", TYPE_MESH_ARRAY);
        
+       nt = NodeGraph::add_pass_node_type("PASS_DUPLIS_ARRAY");
+       nt->add_input("value", TYPE_DUPLIS_ARRAY, array<BVM_DUPLIS>());
+       nt->add_output("value", TYPE_DUPLIS_ARRAY);
+       
        nt = NodeGraph::add_function_node_type("ARG_FLOAT");
        nt->add_output("value", TYPE_FLOAT);
        
@@ -986,6 +1001,9 @@ static void register_opcode_node_types()
        nt = NodeGraph::add_function_node_typ

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to