[Bf-blender-cvs] [3692460] object_nodes: Added a float4 type for rgba colors mostly.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:43:33 CET 2015
Commit: 3692460b5c643e54a408889dd0588c6d5a54f02b
Author: Lukas Tönne
Date: Tue Oct 27 12:32:34 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB3692460b5c643e54a408889dd0588c6d5a54f02b
Added a float4 type for rgba colors mostly.
===================================================================
M source/blender/blenvm/BVM_types.h
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_expression.h
M source/blender/blenvm/bvm/bvm_opcode.h
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_codegen.h
M source/blender/blenvm/util/bvm_util_typedesc.h
===================================================================
diff --git a/source/blender/blenvm/BVM_types.h b/source/blender/blenvm/BVM_types.h
index 784f67a..7a2ecbe 100644
--- a/source/blender/blenvm/BVM_types.h
+++ b/source/blender/blenvm/BVM_types.h
@@ -39,6 +39,7 @@ extern "C" {
typedef enum BVMType {
BVM_FLOAT,
BVM_FLOAT3,
+ BVM_FLOAT4,
BVM_INT,
BVM_MATRIX44,
} BVMType;
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index c838e23..f104db3 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -63,6 +63,11 @@ inline static float3 stack_load_float3(float *stack, StackIndex offset)
return *(float3 *)(&stack[offset]);
}
+inline static float4 stack_load_float4(float *stack, StackIndex offset)
+{
+ return *(float4 *)(&stack[offset]);
+}
+
inline static int stack_load_int(float *stack, StackIndex offset)
{
return *(int *)(&stack[offset]);
@@ -83,6 +88,11 @@ inline static void stack_store_float3(float *stack, StackIndex offset, float3 f)
*(float3 *)(&stack[offset]) = f;
}
+inline static void stack_store_float4(float *stack, StackIndex offset, float4 f)
+{
+ *(float4 *)(&stack[offset]) = f;
+}
+
inline static void stack_store_int(float *stack, StackIndex offset, int i)
{
*(int *)(&stack[offset]) = i;
@@ -105,11 +115,21 @@ static void eval_op_value_float3(float *stack, float3 value, StackIndex offset)
stack_store_float3(stack, offset, value);
}
+static void eval_op_value_float4(float *stack, float4 value, StackIndex offset)
+{
+ stack_store_float4(stack, offset, value);
+}
+
static void eval_op_value_int(float *stack, int value, StackIndex offset)
{
stack_store_int(stack, offset, value);
}
+static void eval_op_value_matrix44(float *stack, matrix44 value, StackIndex offset)
+{
+ stack_store_matrix44(stack, offset, value);
+}
+
static void eval_op_pass_float(float *stack, StackIndex offset_from, StackIndex offset_to)
{
float f = stack_load_float(stack, offset_from);
@@ -130,6 +150,16 @@ static void eval_op_set_float3(float *stack, StackIndex offset_x, StackIndex off
stack_store_float3(stack, offset_to, float3(x, y, z));
}
+static void eval_op_set_float4(float *stack, StackIndex offset_x, StackIndex offset_y,
+ StackIndex offset_z, StackIndex offset_w, StackIndex offset_to)
+{
+ float x = stack_load_float(stack, offset_x);
+ float y = stack_load_float(stack, offset_y);
+ float z = stack_load_float(stack, offset_z);
+ float w = stack_load_float(stack, offset_w);
+ stack_store_float4(stack, offset_to, float4(x, y, z, w));
+}
+
static void eval_op_get_elem_float3(float *stack, int index, StackIndex offset_from, StackIndex offset_to)
{
assert(index >= 0 && index < 3);
@@ -137,6 +167,13 @@ static void eval_op_get_elem_float3(float *stack, int index, StackIndex offset_f
stack_store_float(stack, offset_to, f[index]);
}
+static void eval_op_get_elem_float4(float *stack, int index, StackIndex offset_from, StackIndex offset_to)
+{
+ assert(index >= 0 && index < 4);
+ float4 f = stack_load_float4(stack, offset_from);
+ stack_store_float(stack, offset_to, f[index]);
+}
+
static void eval_op_point_position(const EvalData *data, float *stack, StackIndex offset)
{
stack_store_float3(stack, offset, data->effector.position);
@@ -388,12 +425,24 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_value_float3(stack, value, offset);
break;
}
+ case OP_VALUE_FLOAT4: {
+ float4 value = expr->read_float4(&instr);
+ StackIndex offset = expr->read_stack_index(&instr);
+ eval_op_value_float4(stack, value, offset);
+ break;
+ }
case OP_VALUE_INT: {
int value = expr->read_int(&instr);
StackIndex offset = expr->read_stack_index(&instr);
eval_op_value_int(stack, value, offset);
break;
}
+ case OP_VALUE_MATRIX44: {
+ matrix44 value = expr->read_matrix44(&instr);
+ StackIndex offset = expr->read_stack_index(&instr);
+ eval_op_value_matrix44(stack, value, offset);
+ break;
+ }
case OP_PASS_FLOAT: {
StackIndex offset_from = expr->read_stack_index(&instr);
StackIndex offset_to = expr->read_stack_index(&instr);
@@ -421,6 +470,22 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_get_elem_float3(stack, index, offset_from, offset_to);
break;
}
+ case OP_SET_FLOAT4: {
+ StackIndex offset_x = expr->read_stack_index(&instr);
+ StackIndex offset_y = expr->read_stack_index(&instr);
+ StackIndex offset_z = expr->read_stack_index(&instr);
+ StackIndex offset_w = expr->read_stack_index(&instr);
+ StackIndex offset_to = expr->read_stack_index(&instr);
+ eval_op_set_float4(stack, offset_x, offset_y, offset_z, offset_w, offset_to);
+ break;
+ }
+ case OP_GET_ELEM_FLOAT4: {
+ int index = expr->read_int(&instr);
+ StackIndex offset_from = expr->read_stack_index(&instr);
+ StackIndex offset_to = expr->read_stack_index(&instr);
+ eval_op_get_elem_float4(stack, index, offset_from, offset_to);
+ break;
+ }
case OP_POINT_POSITION: {
StackIndex offset = expr->read_stack_index(&instr);
eval_op_point_position(data, stack, offset);
diff --git a/source/blender/blenvm/bvm/bvm_expression.h b/source/blender/blenvm/bvm/bvm_expression.h
index 00a5220..f4010bd 100644
--- a/source/blender/blenvm/bvm/bvm_expression.h
+++ b/source/blender/blenvm/bvm/bvm_expression.h
@@ -123,6 +123,17 @@ struct Expression {
return f;
}
+ float4 read_float4(int *instr) const
+ {
+ float4 f;
+ f.x = instruction_to_float(instructions[*instr + 0]);
+ f.y = instruction_to_float(instructions[*instr + 1]);
+ f.z = instruction_to_float(instructions[*instr + 2]);
+ f.w = instruction_to_float(instructions[*instr + 3]);
+ (*instr) += 4;
+ return f;
+ }
+
int read_int(int *instr) const
{
int i = instruction_to_int(instructions[*instr]);
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 0ae6409..423f2d8 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -38,11 +38,15 @@ enum OpCode {
OP_NOOP = 0,
OP_VALUE_FLOAT,
OP_VALUE_FLOAT3,
+ OP_VALUE_FLOAT4,
OP_VALUE_INT,
+ OP_VALUE_MATRIX44,
OP_PASS_FLOAT,
OP_PASS_FLOAT3,
OP_SET_FLOAT3,
OP_GET_ELEM_FLOAT3,
+ OP_SET_FLOAT4,
+ OP_GET_ELEM_FLOAT4,
OP_POINT_POSITION,
OP_POINT_VELOCITY,
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 1dff16a..2211ef4 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -104,6 +104,14 @@ void BVMCompiler::push_float3(float3 f)
expr->add_instruction(float_to_instruction(f.z));
}
+void BVMCompiler::push_float4(float4 f)
+{
+ expr->add_instruction(float_to_instruction(f.x));
+ expr->add_instruction(float_to_instruction(f.y));
+ expr->add_instruction(float_to_instruction(f.z));
+ expr->add_instruction(float_to_instruction(f.w));
+}
+
void BVMCompiler::push_int(int i)
{
expr->add_instruction(int_to_instruction(i));
@@ -152,6 +160,15 @@ StackIndex BVMCompiler::codegen_value(const Value *value)
push_stack_index(offset);
break;
}
+ case BVM_FLOAT4: {
+ float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
+ value->get(&f);
+
+ push_opcode(OP_VALUE_FLOAT4);
+ push_float4(f);
+ push_stack_index(offset);
+ break;
+ }
case BVM_INT: {
int i = 0;
value->get(&i);
@@ -161,6 +178,15 @@ StackIndex BVMCompiler::codegen_value(const Value *value)
push_stack_index(offset);
break;
}
+ case BVM_MATRIX44: {
+ matrix44 m = matrix44::identity();
+ value->get(&m);
+
+ push_opcode(OP_VALUE_MATRIX44);
+ push_matrix44(m);
+ push_stack_index(offset);
+ break;
+ }
}
return offset;
@@ -183,6 +209,13 @@ void BVMCompiler::codegen_constant(const Value *value)
push_float3(f);
break;
}
+ case BVM_FLOAT4: {
+ float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
+ value->get(&f);
+
+ push_float4(f);
+ break;
+ }
case BVM_INT: {
int i = 0;
value->get(&i);
@@ -190,6 +223,13 @@ void BVMCompiler::codegen_constant(const Value *value)
push_int(i);
break;
}
+ case BVM_MATRIX44: {
+ matrix44 m = matrix44::identity();
+ value->get(&m);
+
+ push_matrix44(m);
+ break;
+ }
}
}
diff --git a/source/blender/blenvm/compile/bvm_codegen.h b/source/blender/blenvm/compile/bvm_codegen.h
index a374c09..981f6df 100644
--- a/source/blender/blenvm/compile/bvm_codegen.h
+++ b/source/blender/blenvm/compile/bvm_codegen.h
@@ -59,6 +59,7 @@ struct BVMCompiler {
void push_stack_index(StackIndex arg);
void push_float(float f);
void push_float3(float3 f);
+ void push_float4(float4 f);
void push_int(int i);
void push_matrix44(matrix44 m);
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h b/source/blender/blenvm/util/bvm_util_typedesc.h
index 7dceb9a..ec00c34 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -63,6 +63,29 @@ struct float3 {
float z;
};
+struct float4 {
+ float4()
+ {}
+
+ float4(float x, float y, float z, float w) :
+ x(x), y(y), z(z), w(w)
+ {}
+
+ float& operator[] (int index)
+ {
+ return ((float*)(&x))[index];
+ }
+ float operator[] (int index) const
+ {
+ return ((float*)(&x))[index];
+ }
+
+ float x;
+ float y;
+ float z;
+ float w;
+};
+
struct matrix44 {
enum Layout {
COL_MAJOR,
@@ -143,6 +166,18 @@ struct BaseTypeTraits<BVM_FLOAT3> {
};
template <>
+struct BaseTypeTraits<BVM_FLOAT4> {
+ typedef float4 POD;
+
+ enum eStackSize { stack_size = 4 };
+
+ static inline void copy(POD *to, const POD *from)
+ {
+ *to = *from;
+ }
+};
+
+template <>
struct BaseTypeTraits<BVM_INT> {
typedef int POD;
@@ -246,6 +281,7 @@ Value *Value::create(BVMType type, T data)
switch (type) {
case BVM_FLOAT: return new ValueType<BVM_FLOAT>(data);
case BVM_FLOAT3: return new ValueType<BVM_FLOAT3>(data);
+ case BVM_FLOAT4: return new ValueType<BVM_FLOAT4>(data);
case BVM_INT: return new ValueType<BVM_INT>(data);
case BVM_MATRIX44: return new ValueType<BVM_MATRIX44>(data);
}
@@ -258,6 +294
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list